Makefile 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. VERSION=0.3
  2. # optional features
  3. PLUGIN_SUPPORT=1
  4. DEBUG=0
  5. DEBUG_TYPECAST=0
  6. COPTS=-O2
  7. WOPTS=-pedantic -Wno-unused -Werror
  8. FPIC=-fPIC
  9. CFLAGS=$(COPTS) $(WOPTS) -Wall -std=gnu99
  10. AR=ar
  11. LD=ld
  12. CC=gcc
  13. LIBS=-lc
  14. RANLIB=ranlib
  15. ifeq ($(DEBUG),1)
  16. COPTS = -O0
  17. CFLAGS += -g3
  18. endif
  19. OS=$(shell uname)
  20. ifeq ($(OS),Darwin)
  21. LINK=$(LD)
  22. SHLIB_EXT=dylib
  23. SHLIB_FLAGS=-dylib
  24. else
  25. LINK=$(CC)
  26. SHLIB_EXT=so
  27. SHLIB_FLAGS=-shared -Wl,-soname,$(SHLIB_FILE)
  28. endif
  29. SHLIB_FILE=libuci.$(SHLIB_EXT).$(VERSION)
  30. define add_feature
  31. @echo "$(if $(findstring 1,$($(1))),#define UCI_$(1) 1,#undef UCI_$(1))" >> $@.tmp
  32. endef
  33. LIBUCI_DEPS=file.c history.c list.c util.c uci.h uci_config.h uci_internal.h
  34. all: uci-static uci libuci.$(SHLIB_EXT)
  35. cli.o: cli.c uci.h uci_config.h
  36. uci_config.h: FORCE
  37. @rm -f "$@.tmp"
  38. $(call add_feature,PLUGIN_SUPPORT)
  39. $(call add_feature,DEBUG)
  40. $(call add_feature,DEBUG_TYPECAST)
  41. @if [ \! -f "$@" ] || ! cmp "$@.tmp" "$@" >/dev/null; then \
  42. mv "$@.tmp" "$@"; \
  43. else \
  44. rm -f "$@.tmp"; \
  45. fi
  46. uci: cli.o libuci.$(SHLIB_EXT)
  47. $(CC) -o $@ $< -L. -luci
  48. uci-static: cli.o libuci.a
  49. $(CC) $(CFLAGS) -o $@ $^
  50. libuci-static.o: libuci.c $(LIBUCI_DEPS)
  51. $(CC) $(CFLAGS) -c -o $@ $<
  52. libuci-shared.o: libuci.c $(LIBUCI_DEPS)
  53. $(CC) $(CFLAGS) $(FPIC) -c -o $@ $<
  54. libuci.a: libuci-static.o
  55. rm -f $@
  56. $(AR) rc $@ $^
  57. $(RANLIB) $@
  58. libuci.$(SHLIB_EXT): libuci-shared.o
  59. $(LINK) $(SHLIB_FLAGS) -o $(SHLIB_FILE) $^ $(LIBS)
  60. ln -sf $(SHLIB_FILE) $@
  61. clean:
  62. rm -f uci uci-static *.[oa] *.so* *.dylib* uci_config.h
  63. FORCE: ;
  64. .PHONY: FORCE