On Wed, Mar 29, 2017 at 05:52:57PM +0200, git_AT_suckless.org wrote:
> commit 416f39e3d68a6b12a05751930a609cfbbde483ff
> Author: Laslo Hunhold <dev_AT_frign.de>
> AuthorDate: Wed Mar 29 17:51:41 2017 +0200
> Commit: Laslo Hunhold <dev_AT_frign.de>
> CommitDate: Wed Mar 29 17:51:41 2017 +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.
>
> diff --git a/Makefile b/Makefile
> index 72a5e3c..a764133 100644
> --- a/Makefile
> +++ b/Makefile
> _AT_@ -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}: ${_AT_:=.o}
> -
> -OBJ = ${SRC:.c=.o}
> +all: $(BIN)
>
> -${OBJ}: config.mk ${HDR}
> +$(BIN): % : %.o $(PREREQ:=.o)
> + $(CC) $^ $(LDFLAGS) -o $_AT_
>
> -.o:
> - ${CC} ${CFLAGS} ${$*-LDFLAGS} -o $_AT_ $<
> +$(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
> index 5fde97e..93988c4 100644
> --- a/config.mk
> +++ b/config.mk
> _AT_@ -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
> -
Personally I think it's useful to have these separated. It is also useful
to specify PNGINC, JPGINC etc separately for building in different
environments.
> -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
>
This is invalid and breaks on OpenBSD (and other non-GNU make probably).
> # 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
>
I didn't see an issue with the previous Makefile and don't share the
criticism. Just my 0.69 cents.
--
Kind regards,
Hiltjo
Received on Wed Mar 29 2017 - 23:24:33 CEST