Stefan Schuermans commited on 2017-09-24 09:06:03
Showing 5 changed files, with 39 additions and 32 deletions.
... | ... |
@@ -21,9 +21,6 @@ VER_MIN := 2 |
21 | 21 |
VER_REV := 0 |
22 | 22 |
VERSION := $(VER_MAJ).$(VER_MIN).$(VER_REV) |
23 | 23 |
|
24 |
-SRCS := $(wildcard src/*.c) |
|
25 |
-EX_SRCS := $(wildcard examples/src/*.c) |
|
26 |
- |
|
27 | 24 |
CFLAGS := -Wall -Wextra -Werror -O3 |
28 | 25 |
DEFINES := -DETP_VER_MAJ=$(VER_MAJ) -DETP_VER_MIN=$(VER_MIN) \ |
29 | 26 |
-DETP_VER_REV=$(VER_REV) |
... | ... |
@@ -99,13 +96,16 @@ ifeq ($(OS),) |
99 | 96 |
$(error unsupported operating system $(OS_RAW)) |
100 | 97 |
endif |
101 | 98 |
|
102 |
-SRCS_BASE := $(patsubst %.c,%,$(SRCS)) |
|
103 |
-DEPS := $(addsuffix .d,$(SRCS_BASE)) |
|
104 |
-OBJS := $(addsuffix .o,$(SRCS_BASE)) |
|
105 |
-EX_SRCS_BASE := $(patsubst %.c,%,$(EX_SRCS)) |
|
106 |
-EX_DEPS := $(addsuffix .d,$(EX_SRCS_BASE)) |
|
107 |
-EX_OBJS := $(addsuffix .o,$(EX_SRCS_BASE)) |
|
108 |
-EX_TARGETS := $(addsuffix $(BSUF),$(EX_SRCS_BASE)) |
|
99 |
+SRCS := $(wildcard src/*.c) |
|
100 |
+SRCS_BASE := $(notdir $(patsubst %.c,%,$(SRCS))) |
|
101 |
+DEPS := $(addprefix obj/,$(addsuffix .d,$(SRCS_BASE))) |
|
102 |
+OBJS := $(addprefix obj/,$(addsuffix .o,$(SRCS_BASE))) |
|
103 |
+ |
|
104 |
+EX_SRCS := $(wildcard examples/src/*.c) |
|
105 |
+EX_SRCS_BASE := $(notdir $(patsubst %.c,%,$(EX_SRCS))) |
|
106 |
+EX_DEPS := $(addprefix examples/obj/,$(addsuffix .d,$(EX_SRCS_BASE))) |
|
107 |
+EX_OBJS := $(addprefix examples/obj/,$(addsuffix .o,$(EX_SRCS_BASE))) |
|
108 |
+EX_TARGETS := $(addprefix examples/bin/,$(addsuffix $(BSUF),$(EX_SRCS_BASE))) |
|
109 | 109 |
|
110 | 110 |
TARGET := lib/$(LIBTARGET).a |
111 | 111 |
SH_TARGET := lib/$(LIBTARGET).$(LEXT)$(LEXTSUF) |
... | ... |
@@ -126,23 +126,23 @@ endif |
126 | 126 |
.SECONDARY: |
127 | 127 |
.SUFFIXES: |
128 | 128 |
|
129 |
-all: $(DEPS) $(TARGET) $(SH_TARGET) $(EX_TARGETS) |
|
129 |
+all: $(DEPS) $(TARGET) $(SH_TARGET) $(EX_DEPS) $(EX_TARGETS) |
|
130 | 130 |
|
131 | 131 |
ifneq ($(MAKECMDGOALS),clean) |
132 | 132 |
-include $(DEPS) |
133 | 133 |
endif |
134 | 134 |
|
135 |
-%.d: %.c |
|
136 |
- $(CC) $(CFLAGS) $(DEFINES) $(INCLUDES) -MM -MF $@ -MT $(@:.d=.o) $< |
|
135 |
+obj: |
|
136 |
+ mkdir -p $@ |
|
137 | 137 |
|
138 |
-%.o: %.c |
|
139 |
- $(CC) $(CFLAGS) $(DEFINES) $(INCLUDES) -c -o $@ $< |
|
138 |
+lib: |
|
139 |
+ mkdir -p $@ |
|
140 | 140 |
|
141 |
-%$(BSUF): %.o $(TARGET) $(SH_TARGET) |
|
142 |
- $(CC) $(EX_LDFLAGS) -o $@ $< $(EX_LIBS) |
|
141 |
+obj/%.d: src/%.c | obj |
|
142 |
+ $(CC) $(CFLAGS) $(DEFINES) $(INCLUDES) -MM -MF $@ -MT $(@:.d=.o) $< |
|
143 | 143 |
|
144 |
-lib: |
|
145 |
- mkdir -p lib |
|
144 |
+obj/%.o: src/%.c | obj |
|
145 |
+ $(CC) $(CFLAGS) $(DEFINES) $(INCLUDES) -c -o $@ $< |
|
146 | 146 |
|
147 | 147 |
$(TARGET): $(OBJS) | lib |
148 | 148 |
$(AR) cr $@ $(filter-out lib,$+) |
... | ... |
@@ -162,9 +162,23 @@ ifeq ($(OS),linux) |
162 | 162 |
$(patsubst %.$(VER_MAJ).$(VER_MIN).$(VER_REV),%,$(notdir $@)) |
163 | 163 |
endif |
164 | 164 |
|
165 |
+examples/obj: |
|
166 |
+ mkdir -p $@ |
|
167 |
+ |
|
168 |
+examples/bin: |
|
169 |
+ mkdir -p $@ |
|
170 |
+ |
|
171 |
+examples/obj/%.d: examples/src/%.c | examples/obj |
|
172 |
+ $(CC) $(CFLAGS) $(DEFINES) $(INCLUDES) -MM -MF $@ -MT $(@:.d=.o) $< |
|
173 |
+ |
|
174 |
+examples/obj/%.o: examples/src/%.c | examples/obj |
|
175 |
+ $(CC) $(CFLAGS) $(DEFINES) $(INCLUDES) -c -o $@ $< |
|
176 |
+ |
|
177 |
+examples/bin/%$(BSUF): examples/obj/%.o $(TARGET) $(SH_TARGET) | examples/bin |
|
178 |
+ $(CC) $(EX_LDFLAGS) -o $@ $< $(EX_LIBS) |
|
179 |
+ |
|
165 | 180 |
clean: |
166 |
- rm -rf $(DEPS) $(OBJS) lib \ |
|
167 |
- $(EX_DEPS) $(EX_OBJS) $(EX_TARGETS) |
|
181 |
+ rm -rf obj lib examples/obj examples/bin |
|
168 | 182 |
|
169 | 183 |
install: all |
170 | 184 |
$(INSTALL) -d $(PREFIX)/include/etherpix |