Improve Makefile.
[people/stevee/guardian.git] / Makefile
1 NAME = guardian
2 VERSION = 2.0
3
4 PACKAGE_NAME = $(NAME)-$(VERSION)
5 PACKAGE_VERSION = $(VERSION)
6
7 DESTDIR =
8 PREFIX = /usr
9 BINDIR = $(PREFIX)/bin
10 SBINDIR = $(PREFIX)/sbin
11 SYSCONFDIR = $(PREFIX)/etc
12
13 PERL_VER := $(shell eval "$$(perl -V:version)"; echo $${version};)
14 PERL_SITELIB_DIR := $(shell eval "$$(perl -V:installsitelib)"; echo $${installsitelib};)
15
16 PERL_DIR = $(DESTDIR)$(PERL_SITELIB_DIR)/$(NAME)/
17
18 SED = sed
19
20 substitutions = \
21         '|PACKAGE_NAME=$(PACKAGE_NAME)|' \
22         '|PACKAGE_VERSION=$(PACKAGE_VERSION)|'
23
24 SED_PROCESS = \
25         $(SED) $(subst '|,-e 's|@,$(subst =,\@|,$(subst |',|g',$(substitutions)))) \
26                 < $< > $@
27
28 all: guardian guardianctrl
29
30 guardian: guardian.in Makefile
31         $(SED_PROCESS)
32
33 guardianctrl: guardianctrl.in Makefile
34         $(SED_PROCESS)
35
36 install:
37         # Create directory and copy perl modules
38         -mkdir -pv $(PERL_DIR)
39         cp -rvf modules/* $(PERL_DIR)
40         # Create sbindir and install guardian daemon
41         -mkdir -pv $(DESTDIR)/$(SBINDIR)
42         install -v -m 755 guardian $(DESTDIR)/$(SBINDIR)
43         # Create bindir and install guardianctrl
44         -mkdir -pv $(DESTDIR)$(BINDIR)
45         install -v -m 755 guardianctrl $(DESTDIR)/$(BINDIR)
46
47 clean:
48         rm -vf guardian
49         rm -vf guardianctrl
50
51 dist:
52         # Create temporary dist directory.
53         -mkdir $(PACKAGE_NAME)
54         # Copy all required files to the directory.
55         cp -af \
56                 Makefile \
57                 *.in \
58                 modules \
59                 README \
60                 COPYING $(PACKAGE_NAME)
61         # Create dist tarball.
62         tar -czf $(PACKAGE_NAME).tar.gz $(PACKAGE_NAME)
63         # Remove temporary directory again.
64         rm -rf $(PACKAGE_NAME)