Improve Makefile.
authorStefan Schantl <stefan.schantl@ipfire.org>
Mon, 27 Jun 2016 10:21:40 +0000 (12:21 +0200)
committerStefan Schantl <stefan.schantl@ipfire.org>
Mon, 27 Jun 2016 10:21:40 +0000 (12:21 +0200)
The Makefile now contains the version details which will
be substitued in the guardian.in and guardinctrl.in.

The Makefile now also supports commands for make clean and
to create a distribute-able tarball.

All installations path now can be adjusted by overwriting the
corresponding variables.

Signed-off-by: Stefan Schantl <stefan.schantl@ipfire.org>
Makefile

index 56ebe17..8e8fb66 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,14 +1,64 @@
-NAME = Guardian
+NAME = guardian
+VERSION = 2.0
+
+PACKAGE_NAME = $(NAME)-$(VERSION)
+PACKAGE_VERSION = $(VERSION)
 
 DESTDIR =
+PREFIX = /usr
+BINDIR = $(PREFIX)/bin
+SBINDIR = $(PREFIX)/sbin
+SYSCONFDIR = $(PREFIX)/etc
+
 PERL_VER := $(shell eval "$$(perl -V:version)"; echo $${version};)
 PERL_SITELIB_DIR := $(shell eval "$$(perl -V:installsitelib)"; echo $${installsitelib};)
 
 PERL_DIR = $(DESTDIR)$(PERL_SITELIB_DIR)/$(NAME)/
 
-all:
+SED = sed
+
+substitutions = \
+       '|PACKAGE_NAME=$(PACKAGE_NAME)|' \
+       '|PACKAGE_VERSION=$(PACKAGE_VERSION)|'
+
+SED_PROCESS = \
+       $(SED) $(subst '|,-e 's|@,$(subst =,\@|,$(subst |',|g',$(substitutions)))) \
+               < $< > $@
+
+all: guardian guardianctrl
+
+guardian: guardian.in Makefile
+       $(SED_PROCESS)
+
+guardianctrl: guardianctrl.in Makefile
+       $(SED_PROCESS)
 
 install:
+       # Create directory and copy perl modules
        -mkdir -pv $(PERL_DIR)
        cp -rvf modules/* $(PERL_DIR)
-       install -v -m 755 guardian $(DESTDIR)/usr/sbin
+       # Create sbindir and install guardian daemon
+       -mkdir -pv $(DESTDIR)/$(SBINDIR)
+       install -v -m 755 guardian $(DESTDIR)/$(SBINDIR)
+       # Create bindir and install guardianctrl
+       -mkdir -pv $(DESTDIR)$(BINDIR)
+       install -v -m 755 guardianctrl $(DESTDIR)/$(BINDIR)
+
+clean:
+       rm -vf guardian
+       rm -vf guardianctrl
+
+dist:
+       # Create temporary dist directory.
+       -mkdir $(PACKAGE_NAME)
+       # Copy all required files to the directory.
+       cp -af \
+               Makefile \
+               *.in \
+               modules \
+               README \
+               COPYING $(PACKAGE_NAME)
+       # Create dist tarball.
+       tar -czf $(PACKAGE_NAME).tar.gz $(PACKAGE_NAME)
+       # Remove temporary directory again.
+       rm -rf $(PACKAGE_NAME)