From: Mark Wooding Date: Wed, 6 Jun 2018 20:48:53 +0000 (+0100) Subject: Makefile: Factor out common build arrangements for hacks. X-Git-Tag: 1.2.0~15 X-Git-Url: https://git.distorted.org.uk/~mdw/preload-hacks/commitdiff_plain/bc432a485b7a78bdd62239a18804a3d1f92024f7 Makefile: Factor out common build arrangements for hacks. * Name the `..._SOURCES' variable literally after the hack, so that it can be recovered mechanically. * Accumulate all of the sources together, into an `ALL_SOURCES' and dump that into `DISTFILES', rather than marking them separately for distribution. * Replace the separate linker rules with a single static-pattern rule. This unfortunately needs `.SECONDEXPANSION' to work properly. --- diff --git a/Makefile b/Makefile index 5cd1144..25e5d14 100644 --- a/Makefile +++ b/Makefile @@ -26,6 +26,8 @@ PACKAGE = preload-hacks VERSION := $(shell ./auto-version) +.SECONDEXPANSION: #sorry + ###-------------------------------------------------------------------------- ### Configuration. @@ -84,13 +86,15 @@ REAL_LDFLAGS = $(LDFLAGS) -shared ## noip HACKS += noip -NOIP_SOURCES = noip.c -DISTFILES += $(NOIP_SOURCES) +noip_SOURCES = noip.c ## uopen HACKS += uopen -UOPEN_SOURCES = uopen.c -DISTFILES += $(UOPEN_SOURCES) +uopen_SOURCES = uopen.c + +## Sources. +ALL_SOURCES = $(foreach h,$(HACKS),$($h_SOURCES)) +DISTFILES += $(ALL_SOURCES) ## Libraries. LIBS += $(addsuffix .so, $(HACKS)) @@ -146,9 +150,7 @@ clean: $(V_CC) -c $(REAL_CFLAGS) $< -o $@ ## Constructing preload hacks. -noip.so: $(patsubst %.c, %.o, $(NOIP_SOURCES)) - $(V_LD) $(REAL_LDFLAGS) $< $(LDLIBS) -o $@ -uopen.so: $(patsubst %.c, %.o, $(UOPEN_SOURCES)) +$(addsuffix .so,$(HACKS)): %.so: $$(patsubst %.c,%.o,$$($$*_SOURCES)) $(V_LD) $(REAL_LDFLAGS) $< $(LDLIBS) -o $@ ## Constructing the scripts.