Re: [hackers] [farbfeld] Makefile: target should depend on its object

From: Quentin Rameau <quinq_AT_fifth.space>
Date: Thu, 30 Mar 2017 15:57:15 +0200

From 94d6e290f97b78de4c36da820f38a9b10822bda3 Mon Sep 17 00:00:00 2001
From: Quentin Rameau <quinq_AT_fifth.space>
Date: Thu, 30 Mar 2017 15:51:28 +0200
Subject: [PATCH] Makefile: target should depend on its object

---
 Makefile | 29 +++++++++++++++++++----------
 1 file changed, 19 insertions(+), 10 deletions(-)
diff --git a/Makefile b/Makefile
index 1f7446f..75b24ab 100644
--- a/Makefile
+++ b/Makefile
_AT_@ -4,8 +4,8 @@
 
 include config.mk
 
-REQ = util
-HDR = arg.h
+REQ = util.o
+HDR = arg.h $(REQ:.o=.h)
 BIN = png2ff ff2png jpg2ff ff2jpg ff2pam ff2ppm
 SCR = 2ff
 MAN1 = 2ff.1 $(BIN:=.1)
_AT_@ -13,21 +13,30 @@ MAN5 = farbfeld.5
 
 all: $(BIN)
 
-$(BIN): $(REQ:=.o)
-
-$(BIN:=.o): config.mk $(HDR) $(REQ:=.h)
-
-.o: $(REQ:=.o)
-	$(CC) $(LDFLAGS) $($*-LDFLAGS) -o $_AT_ $< $(REQ:=.o)
+png2ff: png2ff.o $(REQ)
+	$(CC) $(LDFLAGS) $($_AT_-LDFLAGS) -o $@ $(@:=.o) $(REQ)
+ff2png: ff2png.o $(REQ)
+	$(CC) $(LDFLAGS) $($_AT_-LDFLAGS) -o $@ $(@:=.o) $(REQ)
+jpg2ff: jpg2ff.o $(REQ)
+	$(CC) $(LDFLAGS) $($_AT_-LDFLAGS) -o $@ $(@:=.o) $(REQ)
+ff2jpg: ff2jpg.o $(REQ)
+	$(CC) $(LDFLAGS) $($_AT_-LDFLAGS) -o $@ $(@:=.o) $(REQ)
+ff2pam: ff2pam.o $(REQ)
+	$(CC) $(LDFLAGS) $($_AT_-LDFLAGS) -o $@ $(@:=.o) $(REQ)
+ff2ppm: ff2ppm.o $(REQ)
+	$(CC) $(LDFLAGS) $($_AT_-LDFLAGS) -o $@ $(@:=.o) $(REQ)
+
+.c.o: config.mk $(HDR)
+	$(CC) $(CFLAGS) -c $*.c
 
 clean:
-	rm -f $(BIN) $(BIN:=.o) $(REQ:=.o)
+	rm -f $(BIN) $(BIN:=.o) $(REQ)
 
 dist:
 	rm -rf "farbfeld-$(VERSION)"
 	mkdir -p "farbfeld-$(VERSION)"
 	cp -R FORMAT LICENSE Makefile README TODO config.mk $(SCR) \
-	      $(HDR) $(BIN:=.c) $(REQ:=.c) $(REQ:=.h) \
+	      $(HDR) $(BIN:=.c) $(REQ:.o=.c) $(REQ:.o=.h) \
 	      $(MAN1) $(MAN5) "farbfeld-$(VERSION)"
 	tar -cf - "farbfeld-$(VERSION)" | gzip -c > "farbfeld-$(VERSION).tar.gz"
 	rm -rf "farbfeld-$(VERSION)"
-- 
2.12.1
Received on Thu Mar 30 2017 - 15:57:15 CEST

This archive was generated by hypermail 2.3.0 : Thu Mar 30 2017 - 16:00:20 CEST