git » nmdb » commit 1b42da5

Allow CFLAGS override in the Makefiles.

author Alberto Bertogli
2007-05-12 02:34:09 UTC
committer Alberto Bertogli
2007-05-12 02:34:09 UTC
parent 76b830154d6ad8a2441d86b25b6139041655a119

Allow CFLAGS override in the Makefiles.

This patch allows the CFLAGS variable to be overriden by the user when
calling make, for instance "make CFLAGS=-Os".

Previously, that would have broken the build because the needed CFLAGS
were not included (-D_XOPEN_SOURCE=500, for instance, is mandatory and
the user would have to include that in its CFLAGS).

Signed-off-by: Alberto Bertogli <albertito@gmail.com>

libnmdb/Makefile +13 -12
nmdb/Makefile +7 -6

diff --git a/libnmdb/Makefile b/libnmdb/Makefile
index 39a5d5d..a60d09f 100644
--- a/libnmdb/Makefile
+++ b/libnmdb/Makefile
@@ -1,12 +1,13 @@
 
-CFLAGS += -std=c99 -Wall -D_XOPEN_SOURCE=500 -O3 -fPIC
+CFLAGS += -std=c99 -Wall -O3
+ALL_CFLAGS = -D_XOPEN_SOURCE=500 -fPIC $(CFLAGS)
 
 ifdef DEBUG
-CFLAGS += -g -pg -fprofile-arcs -ftest-coverage
+ALL_CFLAGS += -g -pg -fprofile-arcs -ftest-coverage
 endif
 
 ifdef STRICT
-CFLAGS += -ansi -pedantic
+ALL_CFLAGS += -ansi -pedantic
 endif
 
 # prefix for installing the binaries
@@ -24,7 +25,7 @@ all: libs
 libs: libnmdb.so libnmdb.a
 
 libnmdb.so: libnmdb.o
-	$(CC) $(CFLAGS) libnmdb.o -shared -fPIC -o libnmdb.so
+	$(CC) $(ALL_CFLAGS) -shared -fPIC libnmdb.o -o libnmdb.so
 
 libnmdb.a: libnmdb.o
 	$(AR) cr libnmdb.a libnmdb.o
@@ -33,22 +34,22 @@ libnmdb.a: libnmdb.o
 tests: test1c test1d test2c test2cm test2d test2dm
 
 test1c: test1c.o libnmdb.a
-	$(CC) $(CFLAGS) test1c.o libnmdb.a -o test1c
+	$(CC) $(ALL_CFLAGS) test1c.o libnmdb.a -o test1c
 
 test1d: test1d.o libnmdb.a
-	$(CC) $(CFLAGS) test1d.o libnmdb.a -o test1d
+	$(CC) $(ALL_CFLAGS) test1d.o libnmdb.a -o test1d
 
 test2c: test2c.o libnmdb.a
-	$(CC) $(CFLAGS) test2c.o libnmdb.a -o test2c
+	$(CC) $(ALL_CFLAGS) test2c.o libnmdb.a -o test2c
 
 test2cm: test2cm.o libnmdb.a
-	$(CC) $(CFLAGS) test2cm.o libnmdb.a -o test2cm
+	$(CC) $(ALL_CFLAGS) test2cm.o libnmdb.a -o test2cm
 
 test2d: test2d.o libnmdb.a
-	$(CC) $(CFLAGS) test2d.o libnmdb.a -o test2d
+	$(CC) $(ALL_CFLAGS) test2d.o libnmdb.a -o test2d
 
 test2dm: test2dm.o libnmdb.a
-	$(CC) $(CFLAGS) test2dm.o libnmdb.a -o test2dm
+	$(CC) $(ALL_CFLAGS) test2dm.o libnmdb.a -o test2dm
 
 
 install: libs
@@ -65,12 +66,12 @@ install: libs
 
 
 .c.o:
-	$(CC) $(CFLAGS) -c $< -o $@
+	$(CC) $(ALL_CFLAGS) -c $< -o $@
 
 clean:
 	rm -f $(OBJS) libnmdb.so libnmdb.a
 	rm -f test1c test1d test2c test2cm test2d test2dm
-	rm -f *.bb *.bbg *.da *.gcov gmon.out
+	rm -f *.bb *.bbg *.da *.gcov *.gcda *.gcno gmon.out
 
 .PHONY: default all libs tests install clean
 
diff --git a/nmdb/Makefile b/nmdb/Makefile
index fe76217..6a6952c 100644
--- a/nmdb/Makefile
+++ b/nmdb/Makefile
@@ -1,12 +1,13 @@
 
-CFLAGS += -std=c99 -Wall -D_XOPEN_SOURCE=500 -O3
+CFLAGS += -std=c99 -Wall -O3
+ALL_CFLAGS = -D_XOPEN_SOURCE=500 $(CFLAGS)
 
 ifdef DEBUG
-CFLAGS += -g -pg -fprofile-arcs -ftest-coverage
+ALL_CFLAGS += -g -pg -fprofile-arcs -ftest-coverage
 endif
 
 ifdef STRICT
-CFLAGS += -ansi -pedantic
+ALL_CFLAGS += -ansi -pedantic
 endif
 
 # prefix for installing the binaries
@@ -20,10 +21,10 @@ default: all
 all: nmdb
 
 nmdb: $(OBJS)
-	$(CC) $(CFLAGS) $(OBJS) -levent -lpthread -lrt -lqdbm -o nmdb
+	$(CC) $(ALL_CFLAGS) $(OBJS) -levent -lpthread -lrt -lqdbm -o nmdb
 
 .c.o:
-	$(CC) $(CFLAGS) -c $< -o $@
+	$(CC) $(ALL_CFLAGS) -c $< -o $@
 
 install: all
 	install -d $(PREFIX)/bin
@@ -33,7 +34,7 @@ install: all
 
 clean:
 	rm -f $(OBJS) nmdb
-	rm -f *.bb *.bbg *.da *.gcov gmon.out
+	rm -f *.bb *.bbg *.da *.gcov *.gcda *.gcno gmon.out
 
 .PHONY: default all clean