commit 416f39e3d68a6b12a05751930a609cfbbde483ff parent 2ae075c04cff633eddefd3c07363d60bd05a3129 Author: Laslo Hunhold <dev@frign.de> Date: Wed, 29 Mar 2017 17:51:41 +0200 Overhaul Build-system I didn't like the current Makefiles. They were too crufted and not elegant. Additionally, given I'm planning to put some utility functions into a util.{c|h}-prerequisite, I wrote this new Makefile with PREREQs in mind. Diffstat:
M | Makefile | | | 60 | +++++++++++++++++++++++++++++------------------------------- |
M | config.mk | | | 30 | +++++------------------------- |
2 files changed, 34 insertions(+), 56 deletions(-)
diff --git a/Makefile b/Makefile @@ -2,51 +2,49 @@ # See LICENSE file for copyright and license details include config.mk +PREREQ = +HDR = arg.h BIN = png2ff ff2png jpg2ff ff2jpg ff2pam ff2ppm SCRIPTS = 2ff -SRC = ${BIN:=.c} -HDR = arg.h -MAN1 = 2ff.1 ${BIN:=.1} +MAN1 = 2ff.1 $(BIN:=.1) MAN5 = farbfeld.5 -all: ${BIN} - -${BIN}: ${@:=.o} - -OBJ = ${SRC:.c=.o} +all: $(BIN) -${OBJ}: config.mk ${HDR} +$(BIN): % : %.o $(PREREQ:=.o) + $(CC) $^ $(LDFLAGS) -o $@ -.o: - ${CC} ${CFLAGS} ${$*-LDFLAGS} -o $@ $< +$(BIN:=.o): $(HDR) $(PREREQ:=.h) -.c.o: - ${CC} ${CFLAGS} ${$*-CFLAGS} ${CPPFLAGS} -c $< +%.o: %.c config.mk + $(CC) $(CPPFLAGS) $(CFLAGS) -c $< clean: - rm -f ${BIN} ${OBJ} + rm -f $(BIN) $(BIN:=.o) $(PREREQ:=.o) dist: - rm -rf "farbfeld-${VERSION}" - mkdir -p "farbfeld-${VERSION}" - cp -R FORMAT LICENSE Makefile README TODO config.mk ${SCRIPTS} ${HDR} ${SRC} ${MAN1} ${MAN5} "farbfeld-${VERSION}" - tar -cf - "farbfeld-${VERSION}" | gzip -c > "farbfeld-${VERSION}.tar.gz" - rm -rf "farbfeld-${VERSION}" + rm -rf "farbfeld-$(VERSION)" + mkdir -p "farbfeld-$(VERSION)" + cp -R FORMAT LICENSE Makefile README TODO config.mk $(SCRIPTS) \ + $(HDR) $(BIN:=.c) $(PREREQ:=.c) $(PREREQ:=.h) \ + $(MAN1) $(MAN5) "farbfeld-$(VERSION)" + tar -cf - "farbfeld-$(VERSION)" | gzip -c > "farbfeld-$(VERSION).tar.gz" + rm -rf "farbfeld-$(VERSION)" install: all - mkdir -p "${DESTDIR}${PREFIX}/bin" - cp -f ${SCRIPTS} ${BIN} "${DESTDIR}${PREFIX}/bin" - for f in $(BIN) $(SCRIPTS); do chmod 755 "${DESTDIR}${PREFIX}/bin/$$f"; done - mkdir -p "${DESTDIR}${MANPREFIX}/man1" - cp -f ${MAN1} "${DESTDIR}${MANPREFIX}/man1" - for m in $(MAN1); do chmod 644 "${DESTDIR}${MANPREFIX}/man1/$$m"; done - mkdir -p "${DESTDIR}${MANPREFIX}/man5" - cp -f ${MAN5} "${DESTDIR}${MANPREFIX}/man5" - for m in $(MAN5); do chmod 644 "${DESTDIR}${MANPREFIX}/man5/$$m"; done + mkdir -p "$(DESTDIR)$(PREFIX)/bin" + cp -f $(SCRIPTS) $(BIN) "$(DESTDIR)$(PREFIX)/bin" + for f in $(BIN) $(SCRIPTS); do chmod 755 "$(DESTDIR)$(PREFIX)/bin/$$f"; done + mkdir -p "$(DESTDIR)$(MANPREFIX)/man1" + cp -f $(MAN1) "$(DESTDIR)$(MANPREFIX)/man1" + for m in $(MAN1); do chmod 644 "$(DESTDIR)$(MANPREFIX)/man1/$$m"; done + mkdir -p "$(DESTDIR)$(MANPREFIX)/man5" + cp -f $(MAN5) "$(DESTDIR)$(MANPREFIX)/man5" + for m in $(MAN5); do chmod 644 "$(DESTDIR)$(MANPREFIX)/man5/$$m"; done uninstall: - for f in $(BIN) $(SCRIPTS); do rm -f "${DESTDIR}${PREFIX}/bin/$$f"; done - for m in $(MAN1); do rm -f "${DESTDIR}${MANPREFIX}/man1/$$m"; done - for m in $(MAN5); do rm -f "${DESTDIR}${MANPREFIX}/man5/$$m"; done + for f in $(BIN) $(SCRIPTS); do rm -f "$(DESTDIR)$(PREFIX)/bin/$$f"; done + for m in $(MAN1); do rm -f "$(DESTDIR)$(MANPREFIX)/man1/$$m"; done + for m in $(MAN5); do rm -f "$(DESTDIR)$(MANPREFIX)/man5/$$m"; done .PHONY: all clean dist install uninstall diff --git a/config.mk b/config.mk @@ -7,33 +7,13 @@ VERSION = 2 PREFIX = /usr/local MANPREFIX = ${PREFIX}/man -PNGLIB = /usr/local/lib -PNGINC = /usr/local/include - -JPGLIB = /usr/local/lib -JPGINC = /usr/local/include - -INCS = -LIBS = - # flags CPPFLAGS = -D_DEFAULT_SOURCE -CFLAGS = -std=c99 -pedantic -Wall -Os ${INCS} -LDFLAGS = -s ${LIBS} +CFLAGS = -std=c89 -pedantic -Wall -Os +LDFLAGS = -s + +png2ff ff2png: LDFLAGS += -lpng +jpg2ff ff2jpg: LDFLAGS += -ljpeg # compiler and linker CC = cc - -# flags per tool. - -png2ff-CFLAGS := -I${PNGINC} -png2ff-LDFLAGS := -L${PNGLIB} -lpng - -ff2png-CFLAGS := -I${PNGINC} -ff2png-LDFLAGS := -L${PNGLIB} -lpng - -jpg2ff-CFLAGS := -I${JPGINC} -jpg2ff-LDFLAGS := -L${JPGLIB} -ljpeg - -ff2jpg-CFLAGS := -I${JPGINC} -ff2jpg-LDFLAGS := -L${JPGLIB} -ljpeg