cake
/
p7utils
Archived
1
0
Fork 0
This repository has been archived on 2024-03-16. You can view files and clone it, but cannot push or open issues or pull requests.
p7utils/Makefile

239 lines
7.5 KiB
Makefile
Executable File

#!/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
# 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
# Uninstall it all
uninstall: uninstall-bins
# 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.
$(DIRS):
$(call bcmd,mkdir,$@,$(MD) $@)
# Make an object out of a source file/directory.
define make-binaryobj-rules
# Out of a C source file
$(OBJDIR)/$1%.c.o: $(SRCDIR)/$1%.c | $(OBJDIR)/$1
$(call bcmd,cc,$$@,$(CC) -c -o $$@ $$< $(CFLAGS_$2))
endef
$(foreach bin,$(BINARIES),\
$(foreach d,$(sort $(dir $(SRC_$(bin):%=$(bin)/%))),\
$(eval $(call make-binaryobj-rules,$(d),$(bin)))))
$(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 all-$1.exe: $(CHECKCFG) $1$(if $(FOR_WINDOWS),.exe) \
$(if $(INSTALL_MANPAGES),all-doc-$1)
clean-$1 clean-$1.exe:
$(call rmsg,Removing $1 and its objects directory.)
$(call qcmd,$(RM) -r $(OBJDIR)/$1)
$(call qcmd,$(RM) $1$(if $(FOR_WINDOWS),.exe))
re-$1 re-$1.exe: 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 install-$1.exe: $(CHECKCFG) \
all-$1 $(if $(INSTALL_MANPAGES),install-doc-$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))
uninstall-$1 uninstall-$1.exe: $(CHECKCFG) uninstall-doc-$1
$(call rmsg,Uninstalling $1)
$(call qcmd,$(RM) "$(IBINDIR)/$1" "$(IBINDIR)/$1.exe")
endef
$(foreach bin,$(BINARIES),\
$(eval $(call make-installbinary-rule,$(bin))))
# Install binaries
install-bins: $(DEFAULT_BINARIES:%=install-%)
# Uninstall binaries
uninstall-bins: $(BINARIES:%=uninstall-%)
.PHONY: all-bins mostlyclean-bins mclean-bins clean-bins re-bins
.PHONY: install-bins uninstall-bins
.PHONY: $(foreach b,$(BINARIES),all-$(b) all-$(b).exe \
clean-$(b) clean-$(b).exe re-$(b) re-$(b).exe \
install-$(b) install-$(b).exe uninstall-$(b) uninstall-$(b).exe)
#******************************************************************************#
# Documentation-related #
#******************************************************************************#
# Make manpages directories
$(MANDIR)/man1:
$(call bcmd,mkdir,$@,$(MD) $@)
# Check if binaries have a manpage
define check-manpage
BINMAN_$1 := $(shell test -f $(DOCDIR)/$1.1.txt && echo y)
endef
$(foreach bin,$(BINARIES),\
$(eval $(call check-manpage,$(bin))))
# Binary manpages related rules
define make-manpage-rule
$(MANDIR)/man1/$1.%: $(DOCDIR)/$1.1.txt | $(MANDIR)/man1
$(call bcmd,a2x,$$<,$(A2X) -f manpage -D $$| $$< 2>/dev/null)
all-doc-$1: $(if $(BINMAN_$1),$(MANDIR)/man1/$1.1)
install-doc-$1: all-doc-$1
$(if $(BINMAN_$1),\
$(call imsg,Installing $1 manpage))
$(if $(BINMAN_$1),\
$(call qcmd,$(INSTALL) -m 755 -d "$(IMANDIR)/man1"))
$(if $(BINMAN_$1),$(call qcmd,$(INSTALL) -m 644 -t "$(IMANDIR)/man1" \
$(MANDIR)/man1/$1.1))
$(if $(BINMAN_$1),\
$(call qcmd,$(GZIP) "$(IMANDIR)/man1/$1.1"))
uninstall-doc-$1:
$(if $(BINMAN_$1),\
$(call rmsg,Removing $1 manpage))
$(if $(BINMAN_$1),\
$(call qcmd,$(RM) "$(IMANDIR)/man1/$1.1*"))
endef
$(foreach bin,$(BINARIES),\
$(eval $(call make-manpage-rule,$(bin))))
# Remove all manpages
clean-doc:
$(call rmsg,Removing manpages directory.)
$(call qcmd,$(RM) -r $(MANDIR))
.PHONY: $(foreach bin,$(BINARIES),all-doc-$(bin)) clean-doc
.PHONY: $(foreach bin,$(BINARIES),install-doc-$(bin) uninstall-doc-$(bin))
# End of file.