Makefile build for freed
[gpl/argeo-freed.git] / local.mk
index c97b72e8a851dac8e70455d90c905afe9ebcc2cd..dabffac00cb7e2f4e2bb3a4ff7deacd7a77534bb 100644 (file)
--- a/local.mk
+++ b/local.mk
@@ -6,21 +6,49 @@ sbindir ?= $(exec_prefix)/sbin
 libdir ?= $(exec_prefix)/lib
 libexecdir ?= $(exec_prefix)/libexec
 sysconfdir ?= $(prefix)/etc
-srcdir ?= src
+srcdir ?= $(prefix)/src
 datarootdir ?= $(prefix)/share
 
+## Utilities
+# Install to a target directory without executable bit
+INSTALL=install -m644 -D --target-directory
+# Always try copy-on-write
 COPY=cp --reflink=auto
 
+# TODO use argeo-build
+BUILD_BASE = output/argeo-freed
 all:
-       $(MAKE) -C sjbin all
+       mkdir -p $(BUILD_BASE)$(sysconfdir) $(BUILD_BASE)$(bindir) $(BUILD_BASE)$(libdir) $(BUILD_BASE)$(libexecdir)
+       $(COPY) -r etc/* $(BUILD_BASE)$(sysconfdir)
+       $(COPY) -r bin/* $(BUILD_BASE)$(bindir)
+       $(COPY) -r lib/* $(BUILD_BASE)$(libdir)
+       $(COPY) -r libexec/* $(BUILD_BASE)$(libexecdir)
+       sed -i 's|/usr/local/etc|$(sysconfdir)|' $(BUILD_BASE)$(libdir)/systemd/*/argeo*.service
+       sed -i 's|/usr/local/lib|$(libdir)|' $(BUILD_BASE)$(libdir)/systemd/*/argeo*.service
+       sed -i 's|/usr/local/share|$(datarootdir)|' $(BUILD_BASE)$(libdir)/systemd/*/argeo*.service
+       sed -i 's|/usr/local/share|$(datarootdir)|' $(BUILD_BASE)$(bindir)/*
+       sed -i 's|/usr/local/lib|$(libdir)|' $(BUILD_BASE)$(libdir)/sysj/jvm.args
+#      $(MAKE) -C sjbin all
 
 clean:
-       $(MAKE) -C sjbin clean
+       $(RM) -r $(BUILD_BASE)
+#      $(MAKE) -C sjbin clean
 
 install:
-       $(COPY) -r etc/* $(DESTDIR)$(sysconfdir)
-       $(COPY) -r usr/bin/* $(DESTDIR)$(bindir)
-       $(COPY) -r usr/share/* $(DESTDIR)$(datarootdir)
-       $(COPY) -r usr/lib/* $(DESTDIR)$(libdir)
-       $(COPY) -r usr/libexec/* $(DESTDIR)$(libexecdir)
-       $(MAKE) -C sjbin install
+# TODO use install and wildcard ?
+       $(COPY) -v -r --no-clobber $(BUILD_BASE)$(sysconfdir)/* $(DESTDIR)$(sysconfdir)
+       $(COPY) -v -r $(BUILD_BASE)$(libdir)/* $(DESTDIR)$(libdir)
+       install -m755 -D --target-directory $(DESTDIR)$(bindir) $(BUILD_BASE)$(bindir)/* 
+       install -m755 -D --target-directory $(DESTDIR)$(libexecdir)/ipsec $(BUILD_BASE)$(libexecdir)/ipsec/*
+#      systemctl daemon-reload
+
+uninstall:
+# TODO fix warning when directory does not exist
+       $(foreach f, $(shell cd $(BUILD_BASE)$(bindir) && find . -type f), $(RM) $(DESTDIR)$(bindir)/$(f);)
+       $(foreach f, $(shell cd $(BUILD_BASE)$(libdir) && find . -type f), $(RM) $(DESTDIR)$(libdir)/$(f);)
+       $(foreach f, $(shell cd $(BUILD_BASE)$(libexecdir) && find . -type f), $(RM) $(DESTDIR)$(libexecdir)/$(f);)
+# TODO remove empty directories
+#      @if [ -d $(A2_INSTALL_TARGET) ]; then find $(A2_INSTALL_TARGET) -empty -type d -delete; fi
+
+purge: uninstall       
+       $(foreach f, $(shell cd $(BUILD_BASE)$(sysconfdir) && find . -type f), $(RM) $(DESTDIR)$(sysconfdir)/$(f);)