Refactor installation

- Avoid installing files that are already installed
- Use the .ext conventions for the variables names
- Only create install targets for things to install
- Create a new `INSTALLABLE` variable

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
This commit is contained in:
Christophe de Dinechin 2021-02-12 07:41:44 +01:00
parent de73b3c76e
commit 085a0856ee
6 changed files with 91 additions and 101 deletions

View File

@ -1,6 +1,8 @@
This software was brought to you by: This software was brought to you by:
- Ben Porter <freedomben@protonmail.com>
- Christophe de Dinechin <christophe@dinechin.org> - Christophe de Dinechin <christophe@dinechin.org>
- Christophe de Dinechin <ddd@bsd11-turbo>
- Christophe de Dinechin <dinechin@redhat.com> - Christophe de Dinechin <dinechin@redhat.com>
Thank you! Thank you!

View File

@ -36,21 +36,19 @@
# Package description # Package description
PACKAGE_NAME=make-it-quick PACKAGE_NAME=make-it-quick
PACKAGE_VERSION=0.2.7 PACKAGE_VERSION=0.3.0
PACKAGE_DESCRIPTION=A simple auto-configuring build system for C and C++ programs PACKAGE_DESCRIPTION=A simple auto-configuring build system for C and C++ programs
PACKAGE_URL=http://github.com/c3d/make-it-quick PACKAGE_URL=http://github.com/c3d/make-it-quick
# Things to install # Things to install
HDR_INSTALL= \ HEADERS= \
rules.mk \ rules.mk \
config.mk \ config.mk \
$(wildcard config.*.mk) \ $(wildcard config.*.mk) \
$(MIQ_OBJDIR)config.system-setup.mk $(MIQ_OBJDIR)config.system-setup.mk
PREFIX.config=$(PREFIX.share)$(PACKAGE_DIR)config/ WARE.config=$(wildcard config/check*.c)
PACKAGE_INSTALL.lib=$(DESTDIR)$(PREFIX.config) WARE.doc= README.md AUTHORS NEWS
LIB_INSTALL=$(wildcard config/check*.c)
DOC_INSTALL= README.md AUTHORS NEWS
TESTS=example/ TESTS=example/
# Make sure we generate the config.system # Make sure we generate the config.system
@ -61,22 +59,13 @@ MIQ=./
include $(MIQ)rules.mk include $(MIQ)rules.mk
# Install the check*.c files as data # Install the check*.c files as data
INSTALL.lib=$(INSTALL.data) INSTALL.config=$(INSTALL.data)
# Generation of the system setup file # Generation of the system setup file
SYSTEM_SETUP= \ SYSTEM_SETUP= \
$(SYSCONFIG:%=SYSCONFIG?="$(SYSCONFIG)") \ $(SYSCONFIG:%=SYSCONFIG?="$(SYSCONFIG)") \
$(PREFIX:%=PREFIX?="$(PREFIX)") \ $(PREFIX:%=PREFIX?="$(PREFIX)") \
$(PREFIX.bin:%=PREFIX.bin?="$(PREFIX.bin)") \ $(foreach i,$(INSTALLABLE),$(PREFIX.$i:%=PREFIX.$i?=$(PREFIX.$i))) \
$(PREFIX.sbin:%=PREFIX.sbin?="$(PREFIX.sbin)") \
$(PREFIX.hdr:%=PREFIX.hdr?="$(PREFIX.hdr)") \
$(PREFIX.share:%=PREFIX.share?="$(PREFIX.share)") \
$(PREFIX.lib:%=PREFIX.lib?="$(PREFIX.lib)") \
$(PREFIX.dll:%=PREFIX.dll?="$(PREFIX.dll)") \
$(PREFIX.libexec:%=PREFIX.libexec?="$(PREFIX.libexec)") \
$(PREFIX.man:%=PREFIX.man?="$(PREFIX.man)") \
$(PREFIX.doc:%=PREFIX.doc?="$(PREFIX.doc)") \
$(PREFIX.var:%=PREFIX.var?="$(PREFIX.var)") \
CONFIG_SOURCES="$(PREFIX.config)" CONFIG_SOURCES="$(PREFIX.config)"
$(MIQ_OBJDIR)config.system-setup.mk: $(MIQ_OBJDIR)config.system-setup.mk:

View File

@ -47,7 +47,7 @@ EXT.obj= .obj
# Because of the above, we need to put the number before the extesion # Because of the above, we need to put the number before the extesion
# e.g. where Linux would have libfoo.so.1.3.2, cygwin has libfoo.1.3.2.dll # e.g. where Linux would have libfoo.so.1.3.2, cygwin has libfoo.1.3.2.dll
MIQ_DLLBASE= $(@:%.install_dll=%) MIQ_DLLBASE= $(@:%.install.dll=%)
MIQ_DLLNAME= $(MIQ_DLLBASE:%$(EXT.dll)=%$(PRODUCTS_VERSION:%=.$(MIQ_V_VERSION))$(EXT.dll)) MIQ_DLLNAME= $(MIQ_DLLBASE:%$(EXT.dll)=%$(PRODUCTS_VERSION:%=.$(MIQ_V_VERSION))$(EXT.dll))
MIQ_SONAME= $(MIQ_SOBASE:%$(EXT.dll)=%)$(MIQ_V_MAJOR:%=.%)$(EXT.dll) MIQ_SONAME= $(MIQ_SOBASE:%$(EXT.dll)=%)$(MIQ_V_MAJOR:%=.%)$(EXT.dll)
MIQ_SONAME_OPT= $(PRODUCTS_VERSION:%=-Wl,-soname -Wl,$(MIQ_SONAME)) MIQ_SONAME_OPT= $(PRODUCTS_VERSION:%=-Wl,-soname -Wl,$(MIQ_SONAME))

View File

@ -73,12 +73,13 @@ GEN_AUTHORS= (echo "This software was brought to you by:"; \
sed -e 's/^/- /g'; \ sed -e 's/^/- /g'; \
echo ""; \ echo ""; \
echo "Thank you!") echo "Thank you!")
GEN_NEWS= grep '^$(shell git tag -n1 `git describe`)' $@ || \ GEN_NEWS_TAG= $(shell git tag -n1 `git describe`)
(touch $@; \ GEN_NEWS= $(GEN_NEWS_TAG:%=grep '^$(GEN_NEWS_TAG' $@ || \
(touch $@; \
(git tag -l $(shell git describe) -n999 ; \ (git tag -l $(shell git describe) -n999 ; \
echo ""; \ echo ""; \
cat $@) \ cat $@) \
> $@.latest && mv $@.latest $@) > $@.latest && mv $@.latest $@))
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------

View File

@ -64,8 +64,36 @@ LAST_LOG?=$(LOGS)make.log
# Stuff to clean # Stuff to clean
TO_CLEAN= *~ *.bak TO_CLEAN= *~ *.bak
# Stuff to install # Kinds of installable stuff
TO_INSTALL= INSTALLABLE= exe \
lib \
dll \
header \
share \
license \
man \
doc \
var \
etc \
config \
sysconfig \
pkgconfig
# Stuff to install, with one of the suffixes above
WARE.exe?= $(MIQ_OUTEXE)
WARE.lib?= $(MIQ_OUTLIB)
WARE.dll?= $(MIQ_OUTDLL)
WARE.man?= $(MANPAGES)
WARE.header?= $(HEADERS)
WARE.doc?= $(wildcard README*)
WARE.license?= $(wildcard COPYING* LICENSE*)
WARE.pkgconfig?=$(PACKAGE_NAME:%=%.pc)
# Where we pick up the stuff to install (default is source)
WARE_DIR.pkgconfig?=$(MIQ_OBJDIR)
# Where to put system configuration files
SYSCONFIG?=$(PREFIX.etc)
# Buildenv for recursive builds # Buildenv for recursive builds
RECURSE_BUILDENV=$(BUILDENV) RECURSE_BUILDENV=$(BUILDENV)
@ -98,7 +126,7 @@ PACKAGE_DLLS=$(MIQ_PRODDLL)
CONFIG_SOURCES?=$(MIQ)config/ CONFIG_SOURCES?=$(MIQ)config/
# Sources to reformat # Sources to reformat
CLANG_FORMAT_SOURCES=$(SOURCES) $(HDR_INSTALL) CLANG_FORMAT_SOURCES=$(SOURCES) $(WARE.header)
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
@ -106,32 +134,34 @@ CLANG_FORMAT_SOURCES=$(SOURCES) $(HDR_INSTALL)
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
# Variables typically provided by configure scripts # Variables typically provided by configure scripts
SYSCONFIG?=/etc/
PREFIX?=/usr/local/ PREFIX?=/usr/local/
PREFIX.bin?=$(PREFIX)bin/ PREFIX.bin?=$(PREFIX)bin/
PREFIX.sbin?=$(PREFIX)sbin/ PREFIX.sbin?=$(PREFIX)sbin/
PREFIX.lib?=$(PREFIX)lib/
PREFIX.libexec?=$(PREFIX)libexec/ PREFIX.libexec?=$(PREFIX)libexec/
PREFIX.exe?=$(PREFIX.bin)
PREFIX.lib?=$(PREFIX)lib/
PREFIX.dll?=$(PREFIX.lib) PREFIX.dll?=$(PREFIX.lib)
PREFIX.h?=$(PREFIX)include/ PREFIX.header?=$(PREFIX)include/
PREFIX.share?=$(PREFIX)share/ PREFIX.share?=$(PREFIX)share/
PREFIX.man?=$(PREFIX.share)man/ PREFIX.man?=$(PREFIX.share)man/
PREFIX.doc?=$(PREFIX.share)doc/ PREFIX.doc?=$(PREFIX.share)doc/
PREFIX.license?=$(PREFIX.doc)
PREFIX.config?=$(PREFIX.share)config/
PREFIX.var?=$(PREFIX)var/ PREFIX.var?=$(PREFIX)var/
PREFIX.etc?=/etc/
PREFIX.sysconfig=$(SYSCONFIG)
PREFIX.pkgconfig=$(PREFIX.share)pkgconfig/
# Package configuration directories by default # Package configuration directories by default
# The defaut is to install binaries and shared libraries in the prefix # The defaut is to install binaries and shared libraries in the prefix
# but to install headers and data items under a directory named after project # but to install headers and data items under a directory named after project
PACKAGE_INSTALL?=$(DESTDIR)$(PREFIX) define package-install
PACKAGE_INSTALL.bin?=$(DESTDIR)$(PREFIX.bin)
PACKAGE_INSTALL.lib?=$(DESTDIR)$(PREFIX.lib) PACKAGE_INSTALL.$1?=$$(DESTDIR)$$(PREFIX.$1)
PACKAGE_INSTALL.dll?=$(DESTDIR)$(PREFIX.dll)
PACKAGE_INSTALL.h?=$(DESTDIR)$(PREFIX.h)$(PACKAGE_DIR) endef
PACKAGE_INSTALL.share?=$(DESTDIR)$(PREFIX.share)$(PACKAGE_DIR) $(eval $(foreach i,$(INSTALLABLE),$(call package-install,$i)))
PACKAGE_INSTALL.man?=$(DESTDIR)$(PREFIX.man)
PACKAGE_INSTALL.doc?=$(DESTDIR)$(PREFIX.doc)$(PACKAGE_DIR)
PACKAGE_INSTALL.pkgconfig?=$(DESTDIR)$(PREFIX.share)pkgconfig/
PACKAGE_INSTALL.sysconfig?=$(DESTDIR)$(SYSCONFIG)$(PACKAGE_DIR)
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------

View File

@ -88,21 +88,8 @@ MIQ_LDFLAGS= $(LDFLAGS) \
MIQ_PACKAGE= $(PACKAGE_NAME:%=$(MIQ_OBJDIR)%.pc) MIQ_PACKAGE= $(PACKAGE_NAME:%=$(MIQ_OBJDIR)%.pc)
MIQ_INSTALL= $(TO_INSTALL:%=%.$(DO_INSTALL)) \ MIQ_DOINSTALL= $(foreach i,$(INSTALLABLE),$(WARE.$i:%=%.$(DO_INSTALL).$i))
$(MIQ_OUTEXE:%=%.$(DO_INSTALL)_exe) \ MIQ_INSTALL= $(DO_INSTALL:%=$(MIQ_DOINSTALL))
$(MIQ_OUTLIB:%=%.$(DO_INSTALL)_lib) \
$(MIQ_OUTDLL:%=%.$(DO_INSTALL)_dll) \
$(EXE_INSTALL:%=%.$(DO_INSTALL)_exe) \
$(LIB_INSTALL:%=%.$(DO_INSTALL)_lib) \
$(DLL_INSTALL:%=%.$(DO_INSTALL)_dll) \
$(HEADERS:%=%.$(DO_INSTALL)_hdr) \
$(HDR_INSTALL:%=%.$(DO_INSTALL)_hdr) \
$(SHR_INSTALL:%=%.$(DO_INSTALL)_shr) \
$(DOC_INSTALL:%=%.$(DO_INSTALL)_doc) \
$(MANPAGES:%=%.gz.$(DO_INSTALL)_man) \
$(MAN_INSTALL:%=%.gz.$(DO_INSTALL)_man) \
$(ETC_INSTALL:%=%.$(DO_INSTALL)_etc) \
$(MIQ_PACKAGE:%=%.$(DO_INSTALL)_pc)
MIQ_SOURCES= $(SOURCES) \ MIQ_SOURCES= $(SOURCES) \
$(SOURCES_BUILDENV_$(BUILDENV)) \ $(SOURCES_BUILDENV_$(BUILDENV)) \
@ -212,6 +199,7 @@ rebuild: re-$(TARGET)
# Installation # Installation
install: install-$(TARGET) install: install-$(TARGET)
uninstall: uninstall-$(TARGET) uninstall: uninstall-$(TARGET)
reinstall: reinstall-$(TARGET)
clean: $(SUBDIRS:%=%.clean) $(VARIANTS:%=%.variant-clean) clean: $(SUBDIRS:%=%.clean) $(VARIANTS:%=%.variant-clean)
-$(PRINT_CLEAN) rm -f $(TO_CLEAN) $(MIQ_OBJECTS) $(DEPENDENCIES) $(MIQ_OUTPRODS) $(MIQ_TOLINK) config.h -$(PRINT_CLEAN) rm -f $(TO_CLEAN) $(MIQ_OBJECTS) $(DEPENDENCIES) $(MIQ_OUTPRODS) $(MIQ_TOLINK) config.h
@ -280,7 +268,7 @@ endif
.objects: $(MIQ_OBJDIR:%=%.mkdir) .objects: $(MIQ_OBJDIR:%=%.mkdir)
.product: $(MIQ_OUTPRODS) .product: $(MIQ_OUTPRODS)
.postbuild: .product .install .postbuild: .product .install
.install: $(DO_INSTALL:%=$(MIQ_INSTALL)) .install: $(MIQ_INSTALL)
.tests: $(TESTS:%=%.test) .tests: $(TESTS:%=%.test)
.goodbye: .postbuild .goodbye: .postbuild
@ -328,6 +316,8 @@ install-%:
$(PRINT_COMMAND) $(MAKE) $* DO_INSTALL=install $(PRINT_COMMAND) $(MAKE) $* DO_INSTALL=install
uninstall-%: uninstall-%:
$(PRINT_COMMAND) $(MAKE) TARGET=$* DO_INSTALL=uninstall .install $(PRINT_COMMAND) $(MAKE) TARGET=$* DO_INSTALL=uninstall .install
reinstall-%:
$(PRINT_COMMAND) $(MAKE) TARGET=$* DO_INSTALL=reinstall .install
# Deep build (re-check all libraries instead of just resulting .a) # Deep build (re-check all libraries instead of just resulting .a)
deep-%: deep-%:
@ -392,7 +382,7 @@ PRINT_COMPILE= $(PRINT_COMMAND) $(INFO) "[COMPILE$(MIQ_PRINTCOUNT)] " $<;
PRINT_LINK= $(PRINT_COMMAND) $(INFO) "[LINK]" $(shell basename $@); PRINT_LINK= $(PRINT_COMMAND) $(INFO) "[LINK]" $(shell basename $@);
PRINT_GENERATE= $(PRINT_COMMAND) $(INFO) "[GENERATE]" "$(shell basename "$@")" $(COLORIZE); PRINT_GENERATE= $(PRINT_COMMAND) $(INFO) "[GENERATE]" "$(shell basename "$@")" $(COLORIZE);
PRINT_VARIANT= $(PRINT_COMMAND) $(INFO) "[VARIANT]" "$*"; PRINT_VARIANT= $(PRINT_COMMAND) $(INFO) "[VARIANT]" "$*";
PRINT_INSTALL= $(PRINT_COMMAND) $(INFO) "[INSTALL]" "$(*F) in $(<D)" $(COLORIZE); PRINT_INSTALL= $(PRINT_COMMAND) $(INFO) "[INSTALL]" "$(@F) => $(@D)/" $(COLORIZE);
PRINT_UNINSTALL=$(PRINT_COMMAND) $(INFO) "[UNINSTALL] " "$(*F)" $(COLORIZE); PRINT_UNINSTALL=$(PRINT_COMMAND) $(INFO) "[UNINSTALL] " "$(*F)" $(COLORIZE);
PRINT_CLEAN= $(PRINT_COMMAND) $(INFO) "[CLEAN] " "$@ $(MIQ_PRETTYDIR)" $(COLORIZE); PRINT_CLEAN= $(PRINT_COMMAND) $(INFO) "[CLEAN] " "$@ $(MIQ_PRETTYDIR)" $(COLORIZE);
PRINT_COPY= $(PRINT_COMMAND) $(INFO) "[COPY]" "$< '=>' $@" ; PRINT_COPY= $(PRINT_COMMAND) $(INFO) "[COPY]" "$< '=>' $@" ;
@ -637,50 +627,28 @@ benchmark: $(BENCHMARKS:%=%.benchmark)
# Install targets # Install targets
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
# Installing the product: always need to build it first # Helper macro:
%.install: $(PACKAGE_INSTALL).mkdir-only % # $1: install pattern
$(PRINT_INSTALL) $(INSTALL.data) $* $(PACKAGE_INSTALL) # $2: what to install
%.install_exe: $(PACKAGE_INSTALL.bin).mkdir-only % define install-rules
$(PRINT_INSTALL) $(INSTALL.bin) $* $(PACKAGE_INSTALL.bin)
%.install_lib: $(PACKAGE_INSTALL.lib).mkdir-only %
$(PRINT_INSTALL) $(INSTALL.lib) $* $(PACKAGE_INSTALL.lib)
%.install_dll: $(PACKAGE_INSTALL.dll).mkdir-only %
$(PRINT_INSTALL) $(INSTALL.dll)
%.install_hdr: $(PACKAGE_INSTALL.h).mkdir-only %
$(PRINT_INSTALL) $(INSTALL.h) $* $(PACKAGE_INSTALL.h)
%.install_shr: $(PACKAGE_INSTALL.share).mkdir-only %
$(PRINT_INSTALL) $(INSTALL.share) $* $(PACKAGE_INSTALL.share)
%.install_man: $(PACKAGE_INSTALL.man).mkdir-only %
$(PRINT_COMMAND) $(MKDIR) -p $(MIQ_MANDIR)
$(PRINT_INSTALL) $(INSTALL.man) $* $(MIQ_MANDIR)
%.install_doc: $(PACKAGE_INSTALL.doc).mkdir-only %
$(PRINT_INSTALL) $(INSTALL.doc) $* $(PACKAGE_INSTALL.doc)
%.install_etc: $(PACKAGE_INSTALL.sysconfig).mkdir-only %
$(PRINT_INSTALL) $(INSTALL.etc) $* $(PACKAGE_INSTALL.sysconfig)
%.install_pc: $(PACKAGE_INSTALL.pkgconfig).mkdir-only %
$(PRINT_INSTALL) $(INSTALL.data) $* $(PACKAGE_INSTALL.pkgconfig)
# Uninstalling the product $2.install.$1: $$(PACKAGE_INSTALL.$1)$(notdir $2)
%.uninstall: $$(PACKAGE_INSTALL.$1)$(notdir $2): $$(WARE_DIR.$1)$2 | .install-directories
$(PRINT_UNINSTALL) $(UNINSTALL) $(*F:%=$(PACKAGE_INSTALL)%) ; $(UNINSTALL.dir) $(PACKAGE_INSTALL) $(UNINSTALL.ok) $$(PRINT_INSTALL) $$(firstword $$(INSTALL.$1) $$(INSTALL)) $$(WARE_DIR.$1)$2 $$(PACKAGE_INSTALL.$1)
%.uninstall_exe:
$(PRINT_UNINSTALL) $(UNINSTALL) $(*F:%=$(PACKAGE_INSTALL.bin)%) ; $(UNINSTALL.dir) $(PACKAGE_INSTALL.bin) $(UNINSTALL.ok) $2.uninstall.$1:
%.uninstall_lib: $$(PRINT_UNINSTALL) $$(firstword $$(UNINSTALL.$1) $$(UNINSTALL)) $$(PACKAGE_INSTALL.$1)$2; $$(UNINSTALL.dir) $$(PACKAGE_INSTALL.$1) $$(UNINSTALL.ok)
$(PRINT_UNINSTALL) $(UNINSTALL) $(*F:%=$(PACKAGE_INSTALL.lib)%) ; $(UNINSTALL.dir) $(PACKAGE_INSTALL.lib) $(UNINSTALL.ok)
%.uninstall_dll: $2.reinstall: $2 $$(PACKAGE_INSTALL.$1).mkdir-only
$(PRINT_UNINSTALL) $(UNINSTALL) $(*F:%=$(PACKAGE_INSTALL.dll)%) ; $(UNINSTALL.dir) $(PACKAGE_INSTALL.dll) $(UNINSTALL.ok) $$(PRINT_INSTALL) $$(firstword $$(INSTALL.$1) $$(INSTALL)) $2 $$(PACKAGE_INSTALL.$1)
%.uninstall_hdr:
$(PRINT_UNINSTALL) $(UNINSTALL) $(*F:%=$(PACKAGE_INSTALL.h)%) ; $(UNINSTALL.dir) $(PACKAGE_INSTALL.h) $(UNINSTALL.ok) .install-directories: $$(PACKAGE_INSTALL.$1).mkdir-only
%.uninstall_shr:
$(PRINT_UNINSTALL) $(UNINSTALL) $(*F:%=$(PACKAGE_INSTALL.share)%) ; $(UNINSTALL.dir) $(PACKAGE_INSTALL.share) $(UNINSTALL.ok) endef
%.uninstall_doc:
$(PRINT_UNINSTALL) $(UNINSTALL) $(*F:%=$(PACKAGE_INSTALL.doc)%) ; $(UNINSTALL.dir) $(PACKAGE_INSTALL.doc) $(UNINSTALL.ok) # Generate rules for all the installable stuff
%.uninstall_man: $(eval $(foreach i,$(INSTALLABLE),$(foreach w,$(WARE.$i),$(call install-rules,$i,$w))))
$(PRINT_UNINSTALL) $(UNINSTALL) $(*F:%=$(PACKAGE_INSTALL.man)%) .install: .install-directories
%.uninstall_etc:
$(PRINT_UNINSTALL) $(UNINSTALL) $(*F:%=$(PACKAGE_INSTALL.sysconfig)%)
%.uninstall_pc:
$(PRINT_UNINSTALL) $(UNINSTALL) $(*F:%=$(PACKAGE_INSTALL.pkgconfig)%) ; $(UNINSTALL.dir) $(PACKAGE_INSTALL.pkgconfig) $(UNINSTALL.ok)
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
@ -698,7 +666,7 @@ MIQ_GENPC= \
(echo 'prefix=$(PREFIX.bin)' ;\ (echo 'prefix=$(PREFIX.bin)' ;\
echo 'exec_prefix=$${prefix}' ;\ echo 'exec_prefix=$${prefix}' ;\
echo 'libdir=$(PREFIX.lib)' ;\ echo 'libdir=$(PREFIX.lib)' ;\
echo 'includedir=$(PREFIX.h)' ;\ echo 'includedir=$(PREFIX.header)' ;\
echo 'Name: $(PACKAGE_NAME)' ;\ echo 'Name: $(PACKAGE_NAME)' ;\
echo 'Description: $(PACKAGE_DESCRIPTION)' ;\ echo 'Description: $(PACKAGE_DESCRIPTION)' ;\
echo 'Version: $(PACKAGE_VERSION)' ;\ echo 'Version: $(PACKAGE_VERSION)' ;\