Makefile build for freed
[gpl/argeo-freed.git] / local.mk
index 7284143be85264e4b23cef32918f22c3c2c9ce92..dabffac00cb7e2f4e2bb3a4ff7deacd7a77534bb 100644 (file)
--- a/local.mk
+++ b/local.mk
@@ -6,35 +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:
 # TODO use install and wildcard ?
-       $(COPY) -v -r --no-clobber etc/* $(DESTDIR)$(sysconfdir)
-       $(COPY) -v -r usr/bin/* $(DESTDIR)$(bindir)
-#      $(COPY) -v -r usr/share/* $(DESTDIR)$(datarootdir)
-       $(COPY) -v -r usr/lib/* $(DESTDIR)$(libdir)
-       sed -i 's|/usr/local|$(prefix)|' $(DESTDIR)$(libdir)/systemd/system/argeo*.service
-       sed -i 's|/usr/local|$(prefix)|' $(DESTDIR)$(libdir)/systemd/user/argeo*.service
-       sed -i 's|/usr/local|$(prefix)|' $(DESTDIR)$(libdir)/argeo/*.args
-       $(COPY) -v -r usr/libexec/* $(DESTDIR)$(libexecdir)
-#      $(MAKE) -C sjbin install
-       systemctl daemon-reload
+       $(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:
-       $(foreach f, $(shell cd usr/bin/ && find . -type f), $(RM) $(DESTDIR)$(bindir)/$(f);)
-#      $(foreach f, $(shell find usr/share/ -type f), $(RM) $(DESTDIR)$(datarootdir)/$(f);)
-       $(foreach f, $(shell cd usr/lib/ && find . -type f), $(RM) $(DESTDIR)$(libdir)/$(f);)
-       $(foreach f, $(shell cd usr/libexec/ && find . -type f), $(RM) $(DESTDIR)$(libexecdir)/$(f);)
+# 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 etc/ && find . -type f), $(RM) $(DESTDIR)$(sysconfdir)/$(f);)
+       $(foreach f, $(shell cd $(BUILD_BASE)$(sysconfdir) && find . -type f), $(RM) $(DESTDIR)$(sysconfdir)/$(f);)