#!/usr/bin/make -f #******************************************************************************# # Include variables and message subsystem # #******************************************************************************# include Makefile.vars Makefile.msg # Check if we're a git repository ISGIT := $(shell test -e .git && echo y) #******************************************************************************# # General targets # #******************************************************************************# # Make it all all: all-bins $(if $(INSTALL_MANPAGES),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 qcmd,$(RM) Makefile.cfg) $(call qcmd,$(RM) $(NAME)-*) # Remake it all re: clean all # Install it all install: install-bins $(if $(INSTALL_MANPAGES),install-doc) # Uninstall it all uninstall: uninstall-bins uninstall-doc # Reinstall it all reinstall: uninstall install # Make dist dist: mrproper $(if $(ISGIT),reinit-gitmodules) $(call bcmd,mkdir,$(NAME)-$(VERSION),\ $(MD) .dist) $(call bcmd,cp,* $(NAME)-$(VERSION),\ cp -R * .dist) $(call qcmd,\ mv .dist $(NAME)-$(VERSION)) $(call bcmd,tarball,$(NAME)-$(VERSION),\ tar czf $(NAME)-$(VERSION).tar.gz \ --exclude .git $(NAME)-$(VERSION)) $(call qcmd,$(RM) -r $(NAME)-$(VERSION)) .PHONY: all mostlyclean mclean clean fclean mrproper re .PHONY: dist install uninstall reinstall #******************************************************************************# # Git submodules # #******************************************************************************# # Main rule. reinit-gitmodules: $(call qcmd,git submodule deinit -- \ $(shell grep path .gitmodules | sed 's/.*= //')) $(call qcmd,git submodule update --init --recursive) # Initialize one module ifeq ($(ISGIT),y) define check-gitmodule -$(call qcmd,git submodule update --init --quiet $1) endef else define check-gitmodule @true endef endif .PHONY: reinit-gitmodules #******************************************************************************# # 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. getmaintainer: @echo "$(MAINTAINER_NAME) <$(MAINTAINER_MAIL)>" .PHONY: getname getmaintainer getversion #******************************************************************************# # Binaries-specific targets # #******************************************************************************# # Make the binaries. all-bins: $(CHECKCFG) $(DEFAULT_BINARIES:%=all-%) # Make a binary object directory. $(BINARIES:%=$(OBJDIR)/%): $(call bcmd,mkdir,$@,$(MD) $@) # Make an object out of a source file/directory. define make-binaryobj-rule ifeq ($(shell test -f $(SRCDIR)/$1/$2.c && echo y),y) # - Out of a C source file $(OBJDIR)/$1/$2.o: $(SRCDIR)/$1/$2.c | $(OBJDIR)/$1 $(call bcmd,cc,$$@,$(CC) -c -o $$@ $$< $(CFLAGS_$1)) else # - Out of an update.exe project $(SRCDIR)/$1/$2.exe/$2.exe.bin:| $(SRCDIR)/$1/$2.exe $(call check-gitmodule,$(SRCDIR)/$1/$2.exe) $(if $(shell test -f $(SRCDIR)/$1/$2.exe/configure \ && test -x $(SRCDIR)/$1/$2.exe/configure && echo y), \ $(call qcmd,cd $(SRCDIR)/$1/$2.exe && ./configure 1>/dev/null)) $(call bcmd,make,$2.exe,$(MAKE) -C $(SRCDIR)/$1/$2.exe $2.exe.bin \ | sed -e 's/^/ /') $(OBJDIR)/$1/$2.o: $(SRCDIR)/$1/$2.exe/$2.exe.bin | $(OBJDIR)/$1 $(call bcmd,ld -r,$$@,cd $(SRCDIR)/$1/$2.exe && \ $(LDR) -o ../../../$$@ -b binary $2.exe.bin) endif endef $(foreach bin,$(BINARIES),\ $(foreach obj,$(SRC_$(bin)),\ $(eval $(call make-binaryobj-rule,$(bin),$(obj))))) # Make a binary define make-binary-rules $1$(if $(FOR_WINDOWS),.exe): $(SRC_$1:%=$(OBJDIR)/$1/%.o) | $(OBJDIR)/$1 $(call bcmd,ld,$$@,$(LD) -o $$@ $$^ $(LDFLAGS_$1)) all-$1: $1$(if $(FOR_WINDOWS),.exe) clean-$1: $(call rmsg,Removing $1 and its objects directory.) $(call qcmd,$(RM) -r $(OBJDIR)/$1) $(call qcmd,$(RM) $1$(if $(FOR_WINDOWS),.exe)) re-$1: clean-$1 all-$1 endef $(foreach bin,$(BINARIES),\ $(eval $(call make-binary-rules,$(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:%=%*)) # Remake binaries re-bins: clean-bins all-bins # Install a binary define make-installbinary-rule install-$1: $(CHECKCFG) all-$1 $(call imsg,Installing $1$(if $(FOR_WINDOWS),.exe).) $(call qcmd,$(INSTALL) -m 755 -d "$(IBINDIR)") $(call qcmd,$(INSTALL) -m 755 -t "$(IBINDIR)" $1$(if $(FOR_WINDOWS),.exe)) endef $(foreach bin,$(BINARIES),\ $(eval $(call make-installbinary-rule,$(bin)))) # Install binaries install-bins: $(DEFAULT_BINARIES:%=install-%) # Uninstall binaries uninstall-bins: $(CHECKCFG) $(call rmsg,Uninstalling binaries.) $(call qcmd,$(RM) $(patsubst %,"$(IBINDIR)/%",\ $(BINARIES) $(BINARIES:%=%.exe))) .PHONY: all-bins mostlyclean-bins mclean-bins clean-bins re-bins .PHONY: $(foreach b,$(BINARIES),all-$(b) clean-$(b) re-$(b) install-$(b)) .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 qcmd,$(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,$(INSTALL) -m 755 -d "$(IMANDIR)/man$1") $(call qcmd,$(INSTALL) -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.