Makefile: Refactor the silent-rules machinery.
[preload-hacks] / Makefile
index b3360da..f8dadc5 100644 (file)
--- a/Makefile
+++ b/Makefile
 ### the Free Software Foundation; either version 2 of the License, or (at
 ### your option) any later version.
 ###
-### Preload-hacks distributed in the hope that it will be useful, but WITHOUT
-### ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-### FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
-### more details.
+### Preload-hacks are distributed in the hope that it will be useful, but
+### WITHOUT ANY WARRANTY; without even the implied warranty of
+### MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
+### Public License for more details.
 ###
 ### You should have received a copy of the GNU General Public License along
-### with mLib; if not, write to the Free Software Foundation, Inc., 59 Temple
-### Place - Suite 330, Boston, MA 02111-1307, USA.
+### with preload-hacks; if not, write to the Free Software Foundation, Inc.,
+### 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
 PACKAGE                         = preload-hacks
 VERSION                        := $(shell ./auto-version)
 
+.SECONDEXPANSION: #sorry
+
 ###--------------------------------------------------------------------------
 ### Configuration.
 
@@ -42,6 +44,16 @@ man1dir                       = ${mandir}/man1
 DESTDIR                         =
 
 ###--------------------------------------------------------------------------
+### Quiet building.
+
+## Verbosity.
+V                      ?= 0
+v_tag                   = $(call v_tag_$V,$1)
+v_tag_0                         = @printf "  %-8s %s\n" "$1" "$@";
+V_AT                    = $(V_AT_$V)
+V_AT_0                  = @
+
+###--------------------------------------------------------------------------
 ### Build parameters.
 
 ## Mess with these if you like.
@@ -58,7 +70,7 @@ INST_BIN               = $(INSTALL) -c -m755
 MKDIRS                  = $(INSTALL) -d -m755
 
 ## Probably best if you leave these alone.
-REAL_CFLAGS             = $(CFLAGS) -fPIC
+REAL_CFLAGS             = $(CFLAGS) -fPIC -MD
 REAL_LDFLAGS            = $(LDFLAGS) -shared
 
 ###--------------------------------------------------------------------------
@@ -66,13 +78,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))
@@ -107,7 +121,8 @@ DISTFILES           += COPYING
 ## Debian.
 debpkg                  = noip uopen
 DISTFILES              += debian/changelog debian/copyright
-DISTFILES              += debian/control debian/rules
+DISTFILES              += debian/control debian/rules debian/compat
+DISTFILES              += debian/source/format
 DISTFILES              += $(patsubst %, debian/%.install, $(debpkg))
 DISTFILES              += $(patsubst %, debian/%.lintian-overrides, \
                                $(debpkg))
@@ -115,30 +130,29 @@ DISTFILES         += $(patsubst %, debian/%.lintian-overrides, \
 ###--------------------------------------------------------------------------
 ### Building.
 
-all: $(TARGETS)
+all:: $(TARGETS)
 .PHONY: ALL
 
-clean:
-       rm -f *.o $(TARGETS)
+CLEAN                  += $(TARGETS)
+CLEAN                  += *.o *.d
+clean::
+       rm -f $(CLEAN)
 .PHONY: clean
 
 ## Building sources.
 %.o: %.c
-       $(CC) -c $(REAL_CFLAGS) $< -o $@
+       $(call v_tag,CC)$(CC) -c $(REAL_CFLAGS) $< -o $@
 
 ## Constructing preload hacks.
-noip.so: $(patsubst %.c, %.o, $(NOIP_SOURCES))
-       $(LD) $(REAL_LDFLAGS) $< $(LDLIBS) -o $@
-uopen.so: $(patsubst %.c, %.o, $(UOPEN_SOURCES))
-       $(LD) $(REAL_LDFLAGS) $< $(LDLIBS) -o $@
+$(addsuffix .so,$(HACKS)): %.so: $$(patsubst %.c,%.o,$$($$*_SOURCES))
+       $(call v_tag,LD)$(LD) $(REAL_LDFLAGS) $< $(LDLIBS) -o $@
 
 ## Constructing the scripts.
-$(SCRIPTS): withlib.in
-       for i in $(SCRIPTS); do \
-         sed "s/@lib@/$$i/" withlib.in >$$i.new || exit 1; \
-         chmod +x $$i.new || exit 1; \
-         mv $$i.new $$i || exit 1; \
-       done
+$(SCRIPTS): %: withlib.in
+       $(call v_tag,GEN)sed "s/@lib@/$@/" withlib.in >$@.new && \
+               chmod +x $@.new && mv $@.new $@
+
+-include $(patsubst %.c,%d,$(ALL_SOURCES))
 
 ###--------------------------------------------------------------------------
 ### Installation.