add libucimap
[project/uci.git] / Makefile
1 VERSION=0.6
2
3 # optional features
4 PLUGIN_SUPPORT=1
5 DEBUG=0
6 DEBUG_TYPECAST=0
7
8 include Makefile.inc
9
10 LIBS=-lc
11 SHLIB_FILE=libuci.$(SHLIB_EXT).$(VERSION)
12
13 define add_feature
14 @echo "$(if $(findstring 1,$($(1))),#define UCI_$(1) 1,#undef UCI_$(1))" >> $@.tmp
15 endef
16
17 LIBUCI_DEPS=file.c history.c list.c util.c uci.h uci_config.h uci_internal.h
18
19 all: uci-static uci libuci.$(SHLIB_EXT) libucimap.a
20
21 cli.o: cli.c uci.h uci_config.h
22 ucimap.o: ucimap.c uci.h uci_config.h ucimap.h uci_list.h
23
24 uci_config.h: FORCE
25 @rm -f "$@.tmp"
26 $(call add_feature,PLUGIN_SUPPORT)
27 $(call add_feature,DEBUG)
28 $(call add_feature,DEBUG_TYPECAST)
29 @if [ \! -f "$@" ] || ! cmp "$@.tmp" "$@" >/dev/null; then \
30 mv "$@.tmp" "$@"; \
31 else \
32 rm -f "$@.tmp"; \
33 fi
34
35 uci: cli.o libuci.$(SHLIB_EXT)
36 $(CC) -o $@ $< -L. -luci
37
38 uci-static: cli.o libuci.a
39 $(CC) $(CFLAGS) -o $@ $^
40
41 libuci-static.o: libuci.c $(LIBUCI_DEPS)
42 $(CC) $(CFLAGS) -c -o $@ $<
43
44 libuci-shared.o: libuci.c $(LIBUCI_DEPS)
45 $(CC) $(CFLAGS) $(FPIC) -c -o $@ $<
46
47 libuci.a: libuci-static.o
48 rm -f $@
49 $(AR) rc $@ $^
50 $(RANLIB) $@
51
52 libucimap.a: ucimap.o
53 rm -f $@
54 $(AR) rc $@ $^
55 $(RANLIB) $@
56
57 libuci.$(SHLIB_EXT): libuci-shared.o
58 $(LINK) $(SHLIB_FLAGS) -o $(SHLIB_FILE) $^ $(LIBS)
59 ln -sf $(SHLIB_FILE) $@
60
61 clean:
62 rm -f uci uci-static *.[oa] *.so* *.dylib* uci_config.h
63
64 install: install-bin install-dev
65
66 install-dev: all
67 $(MKDIR) -p $(DESTDIR)$(prefix)/lib
68 $(MKDIR) -p $(DESTDIR)$(prefix)/include
69 $(INSTALL) -m0644 libuci.a libucimap.a $(DESTDIR)$(prefix)/lib/
70 $(INSTALL) -m0644 uci_config.h uci.h uci_list.h ucimap.h $(DESTDIR)$(prefix)/include/
71
72 install-bin: all
73 $(INSTALL) -m0755 $(SHLIB_FILE) $(DESTDIR)$(prefix)/lib/
74 ln -sf $(SHLIB_FILE) $(DESTDIR)$(prefix)/lib/libuci.$(SHLIB_EXT)
75 $(MKDIR) -p $(DESTDIR)$(prefix)/bin
76 $(INSTALL) -m0755 uci $(DESTDIR)$(prefix)/bin/
77
78 test: all
79 make -C test
80
81 FORCE: ;
82 .PHONY: FORCE