Makefile: Factor out common build arrangements for hacks.
authorMark Wooding <mdw@distorted.org.uk>
Wed, 6 Jun 2018 20:48:53 +0000 (21:48 +0100)
committerMark Wooding <mdw@distorted.org.uk>
Wed, 6 Jun 2018 23:54:08 +0000 (00:54 +0100)
  * 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.

Makefile

index 5cd1144..25e5d14 100644 (file)
--- 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.