+include Makefile.inc
+
+LIBS=-lc -ldl
+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
+ucimap.o: ucimap.c uci.h uci_config.h ucimap.h uci_list.h
+
+uci_config.h: FORCE
+ @rm -f "$@.tmp"
+ @echo "#define UCI_PREFIX \"$(prefix)\"" > "$@.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 $(LIBS)
+
+uci-static: cli.o libuci.a
+ $(CC) $(CFLAGS) -o $@ $^ $(LIBS)
+
+libuci-static.o: libuci.c $(LIBUCI_DEPS)
+ $(CC) $(CFLAGS) -c -o $@ $<
+
+libuci-shared.o: libuci.c $(LIBUCI_DEPS)
+ $(CC) $(CFLAGS) $(FPIC) -c -o $@ $<
+
+ucimap-static.o: ucimap.c $(LIBUCI_DEPS)
+ $(CC) $(CFLAGS) -c -o $@ $<
+
+ucimap-shared.o: ucimap.c $(LIBUCI_DEPS)
+ $(CC) $(CFLAGS) $(FPIC) -c -o $@ $<
+
+libuci.a: libuci-static.o ucimap-static.o
+ rm -f $@
+ $(AR) rc $@ $^
+ $(RANLIB) $@
+
+libuci.$(SHLIB_EXT): libuci-shared.o ucimap-shared.o
+ $(LINK) $(SHLIB_FLAGS) -o $(SHLIB_FILE) $^ $(LIBS)
+ ln -sf $(SHLIB_FILE) $@
+
+ucimap-example: ucimap-example.c libuci.a
+ $(CC) $(CFLAGS) -I. -o $@ $^ $(LIBS)