DESTDIR ?= /usr/local SHAREDIR ?= $(DESTDIR)/share CGIDIR ?= $(SHAREDIR)/captrap BINDIR ?= $(DESTDIR)/bin SBINDIR ?= $(DESTDIR)/sbin LIBDIR ?= $(DESTDIR)/lib SITEDIR ?= $(LIBDIR)/site_perl ETCDIR ?= /etc/captrap MANDIR ?= $(SHAREDIR)/man MAN1DIR ?= $(MANDIR)/man1 MAN3DIR ?= $(MANDIR)/man3 MAN8DIR ?= $(MANDIR)/man8 # The Debian package build script installs to a temporary location and sets # this variable to the target location. FINAL_CGIDIR ?= $(CGIDIR) export FINAL_CGIDIR TRANS ?= util/trans.pl # programs to be installed cgi_progs = grapher.pl main.pl viewer.pl captrap.css bin_progs = captrap_graph captrap_main captrap_recurse captrap_view sbin_progs = captrap_mac captrap_mkconfig captrap_mkdb # directories of each program to install cgi_dir = cgi-bin bin_dir = bin sbin_dir = sbin # paths to files to be installed cgi_files = $(addprefix $(cgi_dir)/, $(cgi_progs)) bin_files = $(addprefix $(bin_dir)/, $(bin_progs)) sbin_files = $(addprefix $(sbin_dir)/, $(sbin_progs)) # library stuff main_libs = Captrap DBCache lib_dir = lib main_lib_files = $(addsuffix .pm, $(addprefix $(lib_dir)/, $(main_libs))) sub_libs = Graph Main View sub_lib_dir = Captrap sub_lib_files = $(addsuffix .pm, $(addprefix $(lib_dir)/$(sub_lib_dir)/, $(sub_libs))) # doc stuff man_dir = man sub_man_dir = $(man_dir)/$(sub_lib_dir) man1_targets = $(addsuffix .1pm, $(bin_progs)) man8_targets = $(addsuffix .8pm, $(sbin_progs)) man3_main = $(addsuffix .3pm, $(main_libs)) man3_sub = $(addsuffix .3pm, $(addprefix $(sub_lib_dir)/, $(sub_libs))) man3_targets = $(man3_main) $(man3_sub) man_targets = $(man1_targets) $(man8_targets) $(man3_targets) # what to build build_dir = build all_dirs = $(cgi_dir) $(bin_dir) $(sbin_dir) $(lib_dir) \ $(lib_dir)/$(sub_lib_dir) $(man_dir) $(sub_man_dir) all_files = $(cgi_files) $(bin_files) $(sbin_files) $(main_lib_files) \ $(sub_lib_files) # make sure this is always the first target default: build man @echo @echo "Done preparing files for install. If you haven't already done" @echo "so, run 'make test' to check dependencies. Then you can run" @echo "'make install' to install Captrap. Alternatively, you can" @echo "run the scripts without installing them (see the README)." build_dir: mkdir -p $(addprefix $(build_dir)/, $(all_dirs)) build: build_dir $(addprefix $(build_dir)/, $(all_files)) man: build_dir $(addprefix $(build_dir)/$(man_dir)/, $(man_targets)) test: util/check_deps.pl validate: build_dir mkdir -p $(build_dir)/validate $(bin_dir)/captrap_recurse -validate $(build_dir)/validate "" crontest: clean build_dir validate ln -s validate $(build_dir)/crontest $(bin_dir)/captrap_recurse -cron-write $(build_dir) $(build_dir)/crontest hour gitpush: git push ssh://git.fatooh.org/srv/git/captrap.git git pull release: clean build_dir util/release.sh $(build_dir)/release # this target just makes it so the caller doesn't have to do the following # addprefix() mess install_sub_man: $(addprefix install_sub_man_, $(sub_libs)) # Make doesn't support targets/dependencies with ':' in them, so we leave that # until the very end. Man pages are built in a directory hierarchy and then # installed with the "::" filename. install_sub_man_%: build # lib man page install -m 444 $(build_dir)/$(sub_man_dir)/$*.3pm $(MAN3DIR)/$(sub_lib_dir)::$*.3pm install_dirs: # directories install -d "$(CGIDIR)" "$(BINDIR)" "$(SBINDIR)" "$(ETCDIR)" install -d "$(SITEDIR)" "$(SITEDIR)/$(sub_lib_dir)" install -d "$(MAN1DIR)" "$(MAN3DIR)" "$(MAN8DIR)" install: build man install_dirs install_sub_man # programs install -m 755 $(addprefix $(build_dir)/, $(cgi_files)) "$(CGIDIR)" install -m 755 $(addprefix $(build_dir)/, $(bin_files)) "$(BINDIR)" install -m 755 $(addprefix $(build_dir)/, $(sbin_files)) "$(SBINDIR)" # libraries install -m 755 $(addprefix $(build_dir)/, $(main_lib_files)) "$(SITEDIR)" install -m 755 $(addprefix $(build_dir)/, $(sub_lib_files)) \ "$(SITEDIR)/$(sub_lib_dir)" # man pages install -m 444 $(addprefix $(build_dir)/$(man_dir)/, $(man1_targets)) \ "$(MAN1DIR)" install -m 444 $(addprefix $(build_dir)/$(man_dir)/, $(man8_targets)) \ "$(MAN8DIR)" install -m 444 $(addprefix $(build_dir)/$(man_dir)/, $(man3_main)) \ "$(MAN3DIR)" uninstall: # man pages rm -f $(addprefix "$(MAN1DIR)"/, $(man1_targets)) rm -f $(addprefix "$(MAN8DIR)"/, $(man8_targets)) rm -f $(addprefix "$(MAN3DIR)"/, $(man3_main)) rm -f $(addprefix "$(MAN3DIR)"/$(sub_lib_dir)::, $(addsuffix .3pm, $(sub_libs))) # programs rm -f $(addprefix "$(CGIDIR)"/, $(cgi_progs)) rm -f $(addprefix "$(BINDIR)"/, $(bin_progs)) rm -f $(addprefix "$(SBINDIR)"/, $(sbin_progs)) # libraries rm -f $(addprefix "$(SITEDIR)"/, $(addsuffix .pm, $(main_libs))) rm -f $(addprefix "$(SITEDIR)/$(sub_lib_dir)"/, \ $(addsuffix .pm, $(sub_libs))) # directories - rmdir --ignore-fail-on-non-empty "$(ETCDIR)" rmdir --ignore-fail-on-non-empty \ "$(SITEDIR)/$(sub_lib_dir)" "$(SITEDIR)" \ "$(MAN1DIR)" "$(MAN3DIR)" "$(MAN8DIR)" \ "$(MANDIR)" "$(CGIDIR)" \ "$(BINDIR)" "$(LIBDIR)" "$(SBINDIR)" "$(SHAREDIR)" \ "$(DESTDIR)" @echo "uninstallation of Captrap is complete" clean: rm -rf $(build_dir) distclean: clean .PHONY: default build_dir build man .PHONY: validate crontest gitpush release .PHONY: test install uninstall clean distclean .PHONY: install_dirs install_sub_man install_sub_man_% # non-phony targets below here $(build_dir)/$(man_dir)/%.3pm: $(lib_dir)/%.pm pod2man $< $@ $(build_dir)/$(man_dir)/$(sub_lib_dir)/%.3pm: $(lib_dir)/$(sub_lib_dir)/%.pm pod2man $< $@ $(build_dir)/$(man_dir)/%.1pm: $(bin_dir)/% pod2man $< $@ $(build_dir)/$(man_dir)/%.8pm: $(sbin_dir)/% pod2man $< $@ build/%: % $(TRANS) $< $@