-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
126 lines (91 loc) · 2.47 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#
# Makefile
#
# Copyright (C) 2010 Creytiv.com
#
# Master version number
VER_MAJOR := 0
VER_MINOR := 4
VER_PATCH := 0
PROJECT := rew
VERSION := 0.4.0
OPT_SPEED := 1
LIBRE_MK := $(shell [ -f ../re/mk/re.mk ] && \
echo "../re/mk/re.mk")
ifeq ($(LIBRE_MK),)
LIBRE_MK := $(shell [ -f /usr/share/re/re.mk ] && \
echo "/usr/share/re/re.mk")
endif
ifeq ($(LIBRE_MK),)
LIBRE_MK := $(shell [ -f /usr/local/share/re/re.mk ] && \
echo "/usr/local/share/re/re.mk")
endif
include $(LIBRE_MK)
# List of modules
MODULES += shim
MODULES += trice
MODULES += pcp
LIBS += -lm
INSTALL := install
ifeq ($(DESTDIR),)
PREFIX := /usr/local
else
PREFIX := /usr
endif
ifeq ($(LIBDIR),)
LIBDIR := $(PREFIX)/lib
endif
INCDIR := $(PREFIX)/include/rew
CFLAGS += -I$(LIBRE_INC) -Iinclude
MODMKS := $(patsubst %,src/%/mod.mk,$(MODULES))
SHARED := librew$(LIB_SUFFIX)
STATIC := librew.a
include $(MODMKS)
OBJS ?= $(patsubst %.c,$(BUILD)/%.o,$(filter %.c,$(SRCS)))
OBJS += $(patsubst %.S,$(BUILD)/%.o,$(filter %.S,$(SRCS)))
all: $(SHARED) $(STATIC)
-include $(OBJS:.o=.d)
$(SHARED): $(OBJS)
@echo " LD $@"
@$(LD) $(LFLAGS) $(SH_LFLAGS) $^ -L$(LIBRE_SO) -lre $(LIBS) -o $@
$(STATIC): $(OBJS)
@echo " AR $@"
@$(AR) $(AFLAGS) $@ $^
ifneq ($(RANLIB),)
@$(RANLIB) $@
endif
$(BUILD)/%.o: src/%.c $(BUILD) Makefile $(MK) $(MODMKS)
@echo " CC $@"
@$(CC) $(CFLAGS) -c $< -o $@ $(DFLAGS)
$(BUILD)/%.o: src/%.S $(BUILD) Makefile $(MK) $(MODMKS)
@echo " AS $@"
@$(CC) $(CFLAGS) -c $< -o $@ $(DFLAGS)
$(BUILD): Makefile $(MK) $(MODMKS)
@mkdir -p $(patsubst %,$(BUILD)/%,$(sort $(dir $(SRCS))))
@touch $@
.PHONY: clean
clean:
@rm -rf $(SHARED) $(STATIC) test.d test.o test $(BUILD)
install: $(SHARED) $(STATIC)
@mkdir -p $(DESTDIR)$(LIBDIR) $(DESTDIR)$(INCDIR)
$(INSTALL) -m 0644 $(shell find include -name "*.h") \
$(DESTDIR)$(INCDIR)
$(INSTALL) -m 0755 $(SHARED) $(DESTDIR)$(LIBDIR)
$(INSTALL) -m 0755 $(STATIC) $(DESTDIR)$(LIBDIR)
install-static: $(STATIC)
@mkdir -p $(DESTDIR)$(LIBDIR) $(DESTDIR)$(INCDIR)
$(INSTALL) -m 0644 $(shell find include -name "*.h") \
$(DESTDIR)$(INCDIR)
$(INSTALL) -m 0755 $(STATIC) $(DESTDIR)$(LIBDIR)
.PHONY: uninstall
uninstall:
@rm -rf $(DESTDIR)$(INCDIR)
@rm -f $(DESTDIR)$(LIBDIR)/$(SHARED)
@rm -f $(DESTDIR)$(LIBDIR)/$(STATIC)
-include test.d
test.o: test.c
@echo " CC $@"
@$(CC) $(CFLAGS) -c $< -o $@ $(DFLAGS)
test$(BIN_SUFFIX): test.o $(SHARED) $(STATIC)
@echo " LD $@"
@$(LD) $(LFLAGS) $< -L. -lrew -lre $(LIBS) -o $@