From: Andre Noll Date: Wed, 15 May 2024 00:59:58 +0000 (+0200) Subject: build: Avoid lots of duplications in Makefile. X-Git-Tag: v1.0.0~4 X-Git-Url: http://git.tue.mpg.de/?a=commitdiff_plain;h=85c234dfd7f80150700ec1086fcacafcc08edfc1;p=micoforia.git build: Avoid lots of duplications in Makefile. We define a number of make variables, each of which becomes a cpp define as well as an m4 macro via suitable -D var=val options for cpp and m4. With the current approach we repeat the name of each variables twice. Example: URL := http://people.tuebingen.mpg.de/maan/$(PACKAGE)/ M4 += -D "URL=$(URL)" XCPPFLAGS += -DURL='"$(URL)"' This is tedious and error-prone. Be a bit smarter by introducing the DEFINES make variable which gets expanded twice to create the command line options for m4 and cpp. --- diff --git a/Makefile b/Makefile index 52998ba..c0e2f51 100644 --- a/Makefile +++ b/Makefile @@ -10,6 +10,26 @@ else SAY = @echo '$(strip $(1))' endif +PACKAGE := micoforia +DEFINES = \ + $(call DEFINE,PACKAGE,$(PACKAGE)) \ + $(call DEFINE,AUTHOR,Andre Noll) \ + $(call DEFINE,COPYRIGHT_YEAR,2019) \ + $(call DEFINE,SLOGAN,Minimal Containers for Instant Access) \ + $(call DEFINE,EMAIL,maan@tuebingen.mpg.de) \ + $(call DEFINE,URL,http://people.tuebingen.mpg.de/maan/$(PACKAGE)/) \ + $(call DEFINE,CLONE_URL,git://git.tuebingen.mpg.de/$(PACKAGE)) \ + $(call DEFINE,GITWEB_URL,http://git.tuebingen.mpg.de/$(PACKAGE).git) \ + $(call DEFINE,HOME_URL,http://people.tuebingen.mpg.de/maan/) \ + $(call DEFINE,LICENSE,GNU GPL version 3) \ + $(call DEFINE,LICENSE_URL,https://www.gnu.org/licenses/gpl-3.0-standalone.html) +DEFINE = -D$(1)='"$(2)"' +# LOGLEVELS is special because it is defined unquoted +LOGLEVELS := LL_DEBUG,LL_INFO,LL_NOTICE,LL_WARNING,LL_ERROR,LL_CRIT,LL_EMERG +CPP_DEFINES := $(DEFINES) -DLOGLEVELS='$(LOGLEVELS)' +DEFINE = -D "$(1)=$(2)" +M4_DEFINES := $(DEFINES) + .ONESHELL: .SHELLFLAGS := -ec PREFIX ?= /usr/local @@ -21,19 +41,6 @@ B := build all := micoforia micoforia.8 all: $(all) -PACKAGE := micoforia -SLOGAN := Minimal Containers for Instant Access -AUTHOR := Andre Noll -EMAIL := maan@tuebingen.mpg.de -COPYRIGHT_YEAR := 2019 -URL := http://people.tuebingen.mpg.de/maan/$(PACKAGE)/ -CLONE_URL := git://git.tuebingen.mpg.de/$(PACKAGE) -GITWEB_URL := http://git.tuebingen.mpg.de/$(PACKAGE).git -HOME_URL := http://people.tuebingen.mpg.de/maan/ -LICENSE := GNU GPL version 3 -LICENSE_URL := https://www.gnu.org/licenses/gpl-3.0-standalone.html -LOGLEVELS := LL_DEBUG,LL_INFO,LL_NOTICE,LL_WARNING,LL_ERROR,LL_CRIT,LL_EMERG - units := micoforia util version micoforia.lsg deps := $(addprefix $(B)/, $(addsuffix .d, $(units))) objs := $(addprefix $(B)/, $(addsuffix .o, $(units))) @@ -43,34 +50,9 @@ ifeq ($(findstring clean, $(MAKECMDGOALS)),) -include $(B)/config.mak endif -M4 += \ - -D "AUTHOR=$(AUTHOR)" \ - -D "COPYRIGHT_YEAR=$(COPYRIGHT_YEAR)" \ - -D "PACKAGE=$(PACKAGE)" \ - -D "SLOGAN=$(SLOGAN)" \ - -D "EMAIL=$(EMAIL)" \ - -D "URL=$(URL)" \ - -D "CLONE_URL=$(CLONE_URL)" \ - -D "GITWEB_URL=$(GITWEB_URL)" \ - -D "HOME_URL=$(HOME_URL)" \ - -D "LICENSE=$(LICENSE)" \ - -D "LICENSE_URL=$(LICENSE_URL)" \ - defs.m4 - -XCPPFLAGS := -XCPPFLAGS += -I$(B) -XCPPFLAGS += -Wunused-macros -XCPPFLAGS += -DCOPYRIGHT_YEAR='"$(COPYRIGHT_YEAR)"' -XCPPFLAGS += -DPACKAGE='"$(PACKAGE)"' -XCPPFLAGS += -DAUTHOR='"$(AUTHOR)"' -XCPPFLAGS += -DEMAIL='"$(EMAIL)"' -XCPPFLAGS += -DURL='"$(URL)"' -XCPPFLAGS += -DCLONE_URL='"$(CLONE_URL)"' -XCPPFLAGS += -DGITWEB_URL='"$(GITWEB_URL)"' -XCPPFLAGS += -DHOME_URL='"$(HOME_URL)"' -XCPPFLAGS += -DLOGLEVELS='$(LOGLEVELS)' -XCPPFLAGS += -DLICENSE='"$(LICENSE)"' -XCPPFLAGS += -DLICENSE_URL='"$(LICENSE_URL)"' +M4 += $(M4_DEFINES) defs.m4 + +XCPPFLAGS := $(CPP_DEFINES) -I$(B) -Wunused-macros XCFLAGS := XCFLAGS += -fno-strict-aliasing