Integrate with Debian packaging
[gpl/argeo-freed.git] / Makefile
diff --git a/Makefile b/Makefile
new file mode 100644 (file)
index 0000000..474c896
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,57 @@
+# GNU coding standards
+prefix ?= /usr/local
+exec_prefix ?= $(prefix)
+bindir ?= $(exec_prefix)/bin
+sbindir ?= $(exec_prefix)/sbin
+libdir ?= $(exec_prefix)/lib
+libexecdir ?= $(exec_prefix)/libexec
+sysconfdir ?= $(prefix)/etc
+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:
+       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:
+       $(RM) -r $(BUILD_BASE)
+#      $(MAKE) -C sjbin clean
+
+distclean: clean
+
+install:
+       mkdir -p $(DESTDIR)$(sysconfdir) $(DESTDIR)$(bindir) $(DESTDIR)$(libdir) $(DESTDIR)$(libexecdir)
+# 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);)