浏览代码

Patch Makefiles to honor CFLAGS and CPPFLAGS

Makefiles must honor the CFLAGS, CPPFLAGS and LDFLAGS flags passed by
the user. This is needed in order to pass extra flags when building
uthash for Debian.
Ilias Tsitsimpis 10 年之前
父节点
当前提交
747bb968e9
共有 5 个文件被更改,包括 24 次插入22 次删除
  1. 4 4
      libut/Makefile
  2. 4 4
      libut/tests/Makefile
  3. 9 7
      tests/Makefile
  4. 5 5
      tests/lru_cache/Makefile
  5. 2 2
      tests/threads/Makefile

+ 4 - 4
libut/Makefile

@@ -1,7 +1,7 @@
 OBJS=libut.a
 OBJS=libut.a
 all: $(OBJS) 
 all: $(OBJS) 
 INCDIR=./include
 INCDIR=./include
-CFLAGS=-I$(INCDIR)
+CFLAGS+=-I$(INCDIR)
 CFLAGS+=-Wall -Wextra
 CFLAGS+=-Wall -Wextra
 CFLAGS+=-g
 CFLAGS+=-g
 
 
@@ -9,13 +9,13 @@ libut.a: libut.o utvector.o utmm.o
 	ar r $@ $^
 	ar r $@ $^
 
 
 libut.o: src/libut.c $(INCDIR)/libut.h
 libut.o: src/libut.c $(INCDIR)/libut.h
-	$(CC) $(CFLAGS) -c $<
+	$(CC) $(CFLAGS) $(CPPFLAGS) -c $<
 
 
 utvector.o: src/utvector.c $(INCDIR)/utvector.h
 utvector.o: src/utvector.c $(INCDIR)/utvector.h
-	$(CC) $(CFLAGS) -c $<
+	$(CC) $(CFLAGS) $(CPPFLAGS) -c $<
 
 
 utmm.o: src/utmm.c $(INCDIR)/utmm.h
 utmm.o: src/utmm.c $(INCDIR)/utmm.h
-	$(CC) $(CFLAGS) -c $<
+	$(CC) $(CFLAGS) $(CPPFLAGS) -c $<
 
 
 .PHONY: clean tests install
 .PHONY: clean tests install
 
 

+ 4 - 4
libut/tests/Makefile

@@ -2,10 +2,10 @@ PROGS=test1 test2 test3 test4 test5 test6 test7 test8 test9 test10 test11 test12
       test13 test14 test15 test16
       test13 test14 test15 test16
 OBJS=$(patsubst %,%.o,$(PROGS))
 OBJS=$(patsubst %,%.o,$(PROGS))
 
 
-CFLAGS = -I../include
+CFLAGS += -I../include
 CFLAGS += -g
 CFLAGS += -g
 CFLAGS += -Wall -Wextra
 CFLAGS += -Wall -Wextra
-LDFLAGS=-L.. -lut 
+LDFLAGS += -L.. -lut
 
 
 TEST_TARGET=run_tests
 TEST_TARGET=run_tests
 TESTS=./do_tests
 TESTS=./do_tests
@@ -15,10 +15,10 @@ all: $(OBJS) $(PROGS) $(TEST_TARGET)
 # static pattern rule: multiple targets 
 # static pattern rule: multiple targets 
 
 
 $(OBJS): %.o: %.c
 $(OBJS): %.o: %.c
-	$(CC) -c $(CFLAGS) $< 
+	$(CC) -c $(CPPFLAGS) $(CFLAGS) $<
 
 
 $(PROGS): %: %.o
 $(PROGS): %: %.o
-	$(CC) -o $@ $(CFLAGS) $< $(LDFLAGS)
+	$(CC) -o $@ $(CPPFLAGS) $(CFLAGS) $< $(LDFLAGS)
 
 
 
 
 run_tests: $(PROGS)
 run_tests: $(PROGS)

+ 9 - 7
tests/Makefile

@@ -14,7 +14,7 @@ PROGS = test1 test2 test3 test4 test5 test6 test7 test8 test9   \
         test66 test67 test68 test69 test70 test71 test72 test73 \
         test66 test67 test68 test69 test70 test71 test72 test73 \
         test74 test75 test76 test77 test78 test79 test80 test81 \
         test74 test75 test76 test77 test78 test79 test80 test81 \
         test82 test83 test84 test85
         test82 test83 test84 test85
-CFLAGS = -I$(HASHDIR) 
+CFLAGS += -I$(HASHDIR)
 #CFLAGS += -DHASH_BLOOM=16
 #CFLAGS += -DHASH_BLOOM=16
 #CFLAGS += -O2
 #CFLAGS += -O2
 CFLAGS += -g
 CFLAGS += -g
@@ -81,22 +81,24 @@ cplusplus:
 	CC=$(CXX) $(MAKE) all 
 	CC=$(CXX) $(MAKE) all 
 
 
 example: example.c $(HASHDIR)/uthash.h
 example: example.c $(HASHDIR)/uthash.h
-	$(CC) $(CFLAGS) -o $@ $(@).c 
+	$(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -o $@ $(@).c
 
 
 $(PROGS) $(UTILS) : $(HASHDIR)/uthash.h
 $(PROGS) $(UTILS) : $(HASHDIR)/uthash.h
-	$(CC) $(CFLAGS) -o $@ $(@).c 
+	$(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -o $@ $(@).c
 
 
 hashscan : $(HASHDIR)/uthash.h
 hashscan : $(HASHDIR)/uthash.h
-	$(CC) $(CFLAGS) $(MUR_CFLAGS) -o $@ $(@).c 
+	$(CC) $(CPPFLAGS) $(CFLAGS) $(MUR_CFLAGS) $(LDFLAGS) -o $@ $(@).c
 
 
 sleep_test : $(HASHDIR)/uthash.h 
 sleep_test : $(HASHDIR)/uthash.h 
-	$(CC) $(CFLAGS) -DHASH_BLOOM=16 -o $@ $(@).c 
+	$(CC) $(CPPFLAGS) $(CFLAGS) -DHASH_BLOOM=16 $(LDFLAGS) -o $@ $(@).c
 
 
 $(FUNCS) : $(HASHDIR)/uthash.h
 $(FUNCS) : $(HASHDIR)/uthash.h
-	$(CC) $(CFLAGS) -DHASH_FUNCTION=HASH_$@ -o keystat.$@ keystat.c 
+	$(CC) $(CPPFLAGS) $(CFLAGS) -DHASH_FUNCTION=HASH_$@ \
+		$(LDFLAGS) -o keystat.$@ keystat.c
 
 
 $(SPECIAL_FUNCS) : $(HASHDIR)/uthash.h
 $(SPECIAL_FUNCS) : $(HASHDIR)/uthash.h
-	$(CC) $(CFLAGS) $(MUR_CFLAGS) -DHASH_FUNCTION=HASH_$@ -o keystat.$@ keystat.c 
+	$(CC) $(CPPFLAGS) $(CFLAGS) $(MUR_CFLAGS) -DHASH_FUNCTION=HASH_$@ \
+		$(LDFLAGS) -o keystat.$@ keystat.c
 
 
 run_tests: $(PROGS)
 run_tests: $(PROGS)
 	perl $(TESTS)
 	perl $(TESTS)

+ 5 - 5
tests/lru_cache/Makefile

@@ -1,21 +1,21 @@
 CC=gcc
 CC=gcc
 
 
-CFLAGS=-W -Werror -Wall -Wextra -std=c99 \
+CFLAGS+=-W -Werror -Wall -Wextra -std=c99 \
 	-D_FORTIFY_SOURCE=2 -fstack-protector -g \
 	-D_FORTIFY_SOURCE=2 -fstack-protector -g \
 	-Wformat=2 -pedantic -pedantic-errors \
 	-Wformat=2 -pedantic -pedantic-errors \
 	-D_GNU_SOURCE=1 -D_BSD_SOURCE=1 \
 	-D_GNU_SOURCE=1 -D_BSD_SOURCE=1 \
 	-I../../src
 	-I../../src
 
 
-LDFLAGS=-pthread
+LDFLAGS+=-pthread
 
 
 cache: main.o cache.o
 cache: main.o cache.o
-	$(CC) $(CFLAGS) $(LDFLAGS) main.o cache.o -o cache
+	$(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) main.o cache.o -o cache
 
 
 main.o: main.c
 main.o: main.c
-	$(CC) $(CFLAGS) -c main.c -o main.o
+	$(CC) $(CPPFLAGS) $(CFLAGS) -c main.c -o main.o
 
 
 cache.o: cache.c
 cache.o: cache.c
-	$(CC) $(CFLAGS) -c cache.c -o cache.o
+	$(CC) $(CPPFLAGS) $(CFLAGS) -c cache.c -o cache.o
 
 
 clean:
 clean:
 	rm -f cache *.o
 	rm -f cache *.o

+ 2 - 2
tests/threads/Makefile

@@ -4,7 +4,7 @@ PROGS = test1 test2
 # Thread support requires compiler-specific options
 # Thread support requires compiler-specific options
 # ----------------------------------------------------------------------------
 # ----------------------------------------------------------------------------
 # GNU 
 # GNU 
-CFLAGS = -I$(HASHDIR) -g -pthread
+CFLAGS += -I$(HASHDIR) -g -pthread
 # Solaris (Studio 11) 
 # Solaris (Studio 11) 
 #CFLAGS = -I$(HASHDIR) -g -mt
 #CFLAGS = -I$(HASHDIR) -g -mt
 # ----------------------------------------------------------------------------
 # ----------------------------------------------------------------------------
@@ -16,7 +16,7 @@ endif
 all: $(PROGS) run_tests
 all: $(PROGS) run_tests
 
 
 $(PROGS) : $(HASHDIR)/uthash.h
 $(PROGS) : $(HASHDIR)/uthash.h
-	$(CC) $(CFLAGS) -o $@ $(@).c 
+	$(CC) $(CPPLFAGS) $(CFLAGS) $(LDFLAGS) -o $@ $(@).c
 
 
 debug:
 debug:
 	$(MAKE) all HASH_DEBUG=1
 	$(MAKE) all HASH_DEBUG=1