Skip to content

Commit 446c2bc

Browse files
committed
Trigger rebuild on configuration change
Pass configuration macros via an autogenerated header file instead of compiler command line options. So now dependecies tracking could trigger rebuild on configuration option change. This should facilitate packaging for such distro as OpenWrt, which keeps unpacked sources and compiled object files and so needs for rebuild trigger on configuration change.
1 parent 031de17 commit 446c2bc

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
atheepmgr
22
*.d
33
*.o
4+
.__config
5+
config.h

Makefile

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,30 @@ DEPFLAGS=-MMD -MP
6161

6262
all: $(TARGET)
6363

64-
$(TARGET): $(OBJ)
65-
$(CC) $^ $(LDFLAGS) -o $@
64+
FORCE:
65+
66+
$(TARGET): config.h $(OBJ)
67+
$(CC) $(OBJ) $(LDFLAGS) -o $@
6668

6769
%.o: %.c
68-
$(CC) $(DEPFLAGS) $(CFLAGS) $(DEFS) -c $< -o $@
70+
$(CC) $(DEPFLAGS) $(CFLAGS) -include config.h -c $< -o $@
71+
72+
.__config: FORCE
73+
@echo "$(DEFS)" | tr ' ' '\n' | grep -v '^$$' > $@.tmp
74+
@diff $@ $@.tmp > /dev/null 2>&1 && rm -f $@.tmp || mv $@.tmp $@
75+
76+
config.h: .__config
77+
@echo "Generate config.h"
78+
@echo '/* Automatically generated. DO NOT EDIT. */' > $@.tmp
79+
@echo '#ifndef _CONFIG_H_' >> $@.tmp
80+
@echo '#define _CONFIG_H_' >> $@.tmp
81+
@sed -re 's/-D([A-Z0-9_]+)/#define \1/' $^ >> $@.tmp
82+
@echo '#endif' >> $@.tmp
83+
@mv $@.tmp $@
6984

7085
clean:
7186
rm -rf $(TARGET)
87+
rm -rf .__config config.h
7288
rm -rf $(OBJ)
7389
rm -rf $(DEP)
7490

0 commit comments

Comments
 (0)