]> pilppa.com Git - uci.git/commitdiff
add feature flags for the build process, improve automatic rebuild
authorFelix Fietkau <nbd@openwrt.org>
Tue, 12 Feb 2008 11:43:14 +0000 (12:43 +0100)
committerFelix Fietkau <nbd@openwrt.org>
Tue, 12 Feb 2008 11:43:14 +0000 (12:43 +0100)
.gitignore
Makefile
uci.h

index 67a25641d564d3321065586c2b06c3fc73534f32..c84f7d68e7e5e7b2cc41badc22d06c37d10c09c0 100644 (file)
@@ -5,3 +5,4 @@ uci-static
 *.dylib*
 .*.swp
 .gdb*
+uci_config.h
index 7ac23850950c47cf9fd9f504ed79fc0e62f63184..edbdc4effcccc8e8bb42475432cbb818048b9c88 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,5 +1,10 @@
 VERSION=0.3
 
+# optional features
+PLUGIN_SUPPORT=1
+DEBUG=0
+DEBUG_TYPECAST=0
+
 COPTS=-O2
 WOPTS=-pedantic -Wno-unused -Werror
 FPIC=-fPIC
@@ -11,9 +16,9 @@ CC=gcc
 LIBS=-lc
 RANLIB=ranlib
 
-ifneq ($(DEBUG),)
+ifeq ($(DEBUG),1)
   COPTS = -O0
-  CFLAGS += -g3 -DDEBUG_ALL
+  CFLAGS += -g3
 endif
 OS=$(shell uname)
 ifeq ($(OS),Darwin)
@@ -27,11 +32,26 @@ else
 endif
 SHLIB_FILE=libuci.$(SHLIB_EXT).$(VERSION)
 
-LIBUCI_DEPS=file.c history.c list.c util.c uci.h uci_internal.h
+define add_feature
+       @echo "$(if $(findstring 1,$($(1))),#define UCI_$(1) 1,#undef UCI_$(1))" >> $@.tmp
+endef
+
+LIBUCI_DEPS=file.c history.c list.c util.c uci.h uci_config.h uci_internal.h
 
 all: uci-static uci libuci.$(SHLIB_EXT)
 
-cli.o: cli.c uci.h
+cli.o: cli.c uci.h uci_config.h
+
+uci_config.h: FORCE
+       @rm -f "$@.tmp"
+       $(call add_feature,PLUGIN_SUPPORT)
+       $(call add_feature,DEBUG)
+       $(call add_feature,DEBUG_TYPECAST)
+       @if [ \! -f "$@" ] || ! cmp "$@.tmp" "$@" >/dev/null; then \
+               mv "$@.tmp" "$@"; \
+       else \
+               rm -f "$@.tmp"; \
+       fi
 
 uci: cli.o libuci.$(SHLIB_EXT)
        $(CC) -o $@ $< -L. -luci
@@ -55,4 +75,7 @@ libuci.$(SHLIB_EXT): libuci-shared.o
        ln -sf $(SHLIB_FILE) $@
 
 clean:
-       rm -f uci uci-static *.[oa] *.so* *.dylib*
+       rm -f uci uci-static *.[oa] *.so* *.dylib* uci_config.h
+
+FORCE: ;
+.PHONY: FORCE
diff --git a/uci.h b/uci.h
index 29cd07d0410e7e8c75d79717b87a402dfb2b844a..674981c8f369685ecc894ef843a34e91c02fc1a6 100644 (file)
--- a/uci.h
+++ b/uci.h
@@ -15,6 +15,8 @@
 #ifndef __LIBUCI_H
 #define __LIBUCI_H
 
+#include "uci_config.h"
+
 /*
  * you can use these defines to enable debugging behavior for
  * apps compiled against libuci:
  *
  */
 
-#ifdef DEBUG_ALL
-#define UCI_DEBUG
-#define UCI_DEBUG_TYPECAST
-#endif
-
 #include <stdbool.h>
 #include <setjmp.h>
 #include <stdio.h>