fix wrong buffer allocation
[project/uci.git] / Makefile
1 VERSION=0.5
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)
20
21 cli.o: cli.c uci.h uci_config.h
22
23 uci_config.h: FORCE
24 @rm -f "$@.tmp"
25 $(call add_feature,PLUGIN_SUPPORT)
26 $(call add_feature,DEBUG)
27 $(call add_feature,DEBUG_TYPECAST)
28 @if [ \! -f "$@" ] || ! cmp "$@.tmp" "$@" >/dev/null; then \
29 mv "$@.tmp" "$@"; \
30 else \
31 rm -f "$@.tmp"; \
32 fi
33
34 uci: cli.o libuci.$(SHLIB_EXT)
35 $(CC) -o $@ $< -L. -luci
36
37 uci-static: cli.o libuci.a
38 $(CC) $(CFLAGS) -o $@ $^
39
40 libuci-static.o: libuci.c $(LIBUCI_DEPS)
41 $(CC) $(CFLAGS) -c -o $@ $<
42
43 libuci-shared.o: libuci.c $(LIBUCI_DEPS)
44 $(CC) $(CFLAGS) $(FPIC) -c -o $@ $<
45
46 libuci.a: libuci-static.o
47 rm -f $@
48 $(AR) rc $@ $^
49 $(RANLIB) $@
50
51 libuci.$(SHLIB_EXT): libuci-shared.o
52 $(LINK) $(SHLIB_FLAGS) -o $(SHLIB_FILE) $^ $(LIBS)
53 ln -sf $(SHLIB_FILE) $@
54
55 clean:
56 rm -f uci uci-static *.[oa] *.so* *.dylib* uci_config.h
57
58 install: all
59 $(INSTALL) -m0644 libuci.a $(DESTDIR)$(prefix)/lib/
60 $(INSTALL) -m0755 $(SHLIB_FILE) $(DESTDIR)$(prefix)/lib/
61 ln -sf $(SHLIB_FILE) $(DESTDIR)$(prefix)/lib/libuci.$(SHLIB_EXT)
62 $(INSTALL) -m0755 uci $(DESTDIR)/usr/bin/
63
64 FORCE: ;
65 .PHONY: FORCE