X-Git-Url: http://git.archive.openwrt.org/?p=project%2Fuci.git;a=blobdiff_plain;f=Makefile;h=edbdc4effcccc8e8bb42475432cbb818048b9c88;hp=1e0fce371d132da92cec2d35ef4d34bf2327c1a8;hb=406d259cd1faab6de1ee2b817970c9f71d7945a2;hpb=23a794e9c2e3bf39550e46c0bafe544cf6c617e8 diff --git a/Makefile b/Makefile index 1e0fce3..edbdc4e 100644 --- a/Makefile +++ b/Makefile @@ -1,21 +1,81 @@ -COPTS=-g -O2 -CFLAGS=$(COPTS) -fPIC -Wall -pedantic -std=gnu99 -Wno-unused -Werror +VERSION=0.3 + +# optional features +PLUGIN_SUPPORT=1 +DEBUG=0 +DEBUG_TYPECAST=0 + +COPTS=-O2 +WOPTS=-pedantic -Wno-unused -Werror +FPIC=-fPIC +CFLAGS=$(COPTS) $(WOPTS) -Wall -std=gnu99 AR=ar +LD=ld CC=gcc +LIBS=-lc RANLIB=ranlib -all: uci +ifeq ($(DEBUG),1) + COPTS = -O0 + CFLAGS += -g3 +endif +OS=$(shell uname) +ifeq ($(OS),Darwin) + LINK=$(LD) + SHLIB_EXT=dylib + SHLIB_FLAGS=-dylib +else + LINK=$(CC) + SHLIB_EXT=so + SHLIB_FLAGS=-shared -Wl,-soname,$(SHLIB_FILE) +endif +SHLIB_FILE=libuci.$(SHLIB_EXT).$(VERSION) + +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 uci_config.h -cli.o: cli.c uci.h -uci: cli.o libuci.a +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 + +uci-static: cli.o libuci.a $(CC) $(CFLAGS) -o $@ $^ -libuci.o: libuci.c parse.c uci.h list.c err.h -libuci.a: libuci.o +libuci-static.o: libuci.c $(LIBUCI_DEPS) + $(CC) $(CFLAGS) -c -o $@ $< + +libuci-shared.o: libuci.c $(LIBUCI_DEPS) + $(CC) $(CFLAGS) $(FPIC) -c -o $@ $< + +libuci.a: libuci-static.o rm -f $@ $(AR) rc $@ $^ $(RANLIB) $@ +libuci.$(SHLIB_EXT): libuci-shared.o + $(LINK) $(SHLIB_FLAGS) -o $(SHLIB_FILE) $^ $(LIBS) + ln -sf $(SHLIB_FILE) $@ + clean: - rm -f uci *.[oa] + rm -f uci uci-static *.[oa] *.so* *.dylib* uci_config.h + +FORCE: ; +.PHONY: FORCE