#!/usr/bin/make -f #******************************************************************************# # Include variables and message subsystem # #******************************************************************************# include Makefile.vars Makefile.msg #******************************************************************************# # General targets # #******************************************************************************# # Make it all all: all-bins all-doc # Mostly clean mostlyclean: mostlyclean-bins mclean: mostlyclean # Clean it all clean: clean-bins clean-doc fclean: clean # Clean it entirely mrproper: clean $(call rmsg,Removing configuration.) $(call rcmd,Makefile.cfg,$(RM) Makefile.cfg) # Remake it all re: clean all # Install it all install: install-bins install-doc # Uninstall it all uninstall: uninstall-bins uninstall-doc # Reinstall it all reinstall: uninstall install .PHONY: all mostlyclean mclean clean fclean mrproper re .PHONY: install uninstall reinstall #******************************************************************************# # Configuration (version) checking dependencies # #******************************************************************************# # Define the dependencies. CHECKCFG := $(if $(shell test -f Makefile.cfg || echo y),check-config, \ $(if $(shell [ "$(VERSION)" = "$(CONFIG_VERSION)" ] || echo y), \ check-config-version)) # Define the rules. check-config: @printf "\033[1;31mNo configuration file found!\n" @printf "You should configure before re-running this target.\033[0m\n" @false check-config-version: @printf "\033[1;31mConfiguration version is incorrect!\n" @printf "You should re-configure before re-running this target.\033[0m\n" @false .PHONY: check-config check-config-version #******************************************************************************# # Information getting from the Makefile variables # #******************************************************************************# # Get the project name. getname: @echo "$(NAME)" # Get the project version. getversion: @echo "$(VERSION)" # Get the project author. getauthor: @echo "$(AUTHOR_NAME) <$(AUTHOR_MAIL)>" getauthor_name: @echo "$(AUTHOR_NAME)" .PHONY: getname getauthor getauthor_name getversion #******************************************************************************# # Binaries-specific targets # #******************************************************************************# # Make the binaries. all-bins: $(CHECKCFG) $(BINARIES:%=%$(if $(FOR_WINDOWS),.exe)) # Make a binary object directory. $(BINARIES:%=$(OBJDIR)/%): $(call bcmd,mkdir,$@,$(MD) $@) # Make an object out of a C source file. define make-binaryobj-rule $(OBJDIR)/$1/%.o: $(SRCDIR)/$1/%.c | $(OBJDIR)/$1 $(call bcmd,cc,$$@,$(CC) -c -o $$@ $$< $(CFLAGS)) endef $(foreach bin,$(BINARIES),\ $(eval $(call make-binaryobj-rule,$(bin)))) # Make a binary define make-binary-rule $1$(if $(FOR_WINDOWS),.exe): $(SRC_$1:%=$(OBJDIR)/$1/%.o) | $(OBJDIR)/$1 $(call bcmd,ld,$$@,$(LD) -o $$@ $$^ $(LDFLAGS)) endef $(foreach bin,$(BINARIES),\ $(eval $(call make-binary-rule,$(bin)))) # Remove object files. mostlyclean-bins: $(call rmsg,Removing objects directory.) $(call qcmd,$(RM) -r $(OBJDIR)) mclean-bins: mostlyclean-bins # Clean and remove binaries. clean-bins: mostlyclean-bins $(call rmsg,Removing binaries.) $(call qcmd,$(RM) $(BINARIES:%=%*)) # Install binaries install-bins: all-bins $(call imsg,Installing binaries.) $(call qcmd,$(INSTALL) -m 755 -d "$(IBINDIR)") $(call qcmd,$(INSTALL) -m 755 -t "$(IBINDIR)" \ $(BINARIES:%=%$(if $(FOR_WINDOWS),.exe))) # Uninstall binaries uninstall-bins: $(CHECKCFG) $(call rmsg,Uninstalling binaries.) $(call qcmd,$(RM) $(BINARIES) $(BINARIES:%=%.exe)) .PHONY: all-bins mostlyclean-bins mclean-bins clean-bins re-bins .PHONY: install-bins uninstall-bins #******************************************************************************# # Documentation-related # #******************************************************************************# # Make all manpages all-doc: $(foreach s,$(MAN_SECTIONS), $(MAN_$(s):%=$(MANDIR)/man$(s)/%.$(s))) # Make manpages directories $(MAN_SECTIONS:%=$(MANDIR)/man%): $(call bcmd,mkdir,$@,$(MD) $@) # Make-A-Manpage define make-manpage-rule $(MANDIR)/man$1/%.$1: $(DOCDIR)/%.$1.txt | $(MANDIR)/man$1 $(call bcmd,a2x,$$<,$(A2X) -f manpage -D $$| $$< 2>/dev/null) endef $(foreach section, $(MAN_SECTIONS), \ $(eval $(call make-manpage-rule,$(section)))) # Remove all manpages clean-doc: $(call rmsg,Removing manpages directory.) $(call rcmd,$(MANDIR),$(RM) -r $(MANDIR)) # Remake all manpages re-doc: clean-doc all-doc # Install a manpage section. define make-installmansection-rule install-doc-$1: $(MAN_$1:%=$(MANDIR)/man$1/%.$1) $(call imsg,Installing manpages section $1.) $(call qcmd,$(INST) -m 755 -d "$(IMANDIR)/man$1") $(foreach i,$(MAN_$1),$(call icmd,man$1/$(i).$1)) $(call qcmd,$(INST) -m 644 -t "$(IMANDIR)/man$1" \ $(MAN_$1:%=$(MANDIR)/man$1/%.$1)) $(call qcmd,$(GZIP) $(MAN_$1:%="$(IMANDIR)/man$1/%.$1")) endef $(foreach section, $(MAN_SECTIONS), \ $(eval $(call make-installmansection-rule,$(section)))) # Install manpages install-doc: $(CHECKCFG) $(if $(INSTALL_MANPAGES),\ $(MAN_SECTIONS:%=install-doc-%)) # Uninstall manpages uninstall-doc: $(CHECKCFG) $(call rmsg,Removing manpages.) $(call qcmd,$(RM) $(foreach s,$(MAN_SECTIONS),\ $(patsubst %,"$(IMANDIR)"/man$(s)/%.$(s)*,$(MAN_$(s))))) .PHONY: all-doc clean-doc re-doc install-doc uninstall-doc .PHONY: $(MAN_SECTIONS:%=install-doc-%) # End of file.