blind

suckless command-line video editing utility
git clone git://git.suckless.org/blind
Log | Files | Refs | README | LICENSE

commit 881f7b4aa699291ae22db304dc9e259cb8331b58
parent 7ee326b71e1846c3b79be5aea9d9bfd94ef5aa38
Author: Mattias Andrée <maandree@kth.se>
Date:   Thu,  7 Dec 2017 17:16:12 +0100

Improve makefile

Almost fully (to the greatest extent possible) portable.
Do not rebuild everything everytime a .c file is added.
However, there is some minor oddities to allow use of -j.

Signed-off-by: Mattias Andrée <maandree@kth.se>

Diffstat:
M.gitignore | 7+++----
MMakefile | 303+++++++++++++++++--------------------------------------------------------------
Ablind.mk | 109+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mconfig.mk | 2+-
Afiles.mk | 104+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Msrc/common.h | 2+-
6 files changed, 284 insertions(+), 243 deletions(-)

diff --git a/.gitignore b/.gitignore @@ -1,15 +1,14 @@ -\#*\#* -.\#* *~ +*\#* *.bak *.orig *.swo *.swp +*.a *.o *.bo *.out -/platform.h -/generate-macros +/build/ /blind-* !/blind-rotate-90 !/blind-rotate-180 diff --git a/Makefile b/Makefile @@ -1,112 +1,9 @@ +.POSIX: + CONFIGFILE = config.mk +include files.mk include $(CONFIGFILE) - -BIN =\ - blind-affine-colour\ - blind-apply-kernel\ - blind-apply-palette\ - blind-arithm\ - blind-cat-cols\ - blind-cat-rows\ - blind-chroma-key\ - blind-colour-ciexyz\ - blind-colour-matrix\ - blind-colour-srgb\ - blind-compress\ - blind-concat\ - blind-cone-gradient\ - blind-convert\ - blind-coordinate-field\ - blind-crop\ - blind-cross-product\ - blind-cut\ - blind-decompress\ - blind-disperse\ - blind-dissolve\ - blind-dot-product\ - blind-double-sine-wave\ - blind-dual-key\ - blind-extend\ - blind-extract-alpha\ - blind-find-rectangle\ - blind-flip\ - blind-flop\ - blind-from-image\ - blind-from-named\ - blind-from-portable\ - blind-from-text\ - blind-from-video\ - blind-gauss-blur\ - blind-get-colours\ - blind-hexagon-tessellation\ - blind-interleave\ - blind-invert-luma\ - blind-invert-matrix\ - blind-kernel\ - blind-linear-gradient\ - blind-make-kernel\ - blind-matrix-orthoproject\ - blind-matrix-reflect\ - blind-matrix-rotate\ - blind-matrix-scale\ - blind-matrix-shear\ - blind-matrix-translate\ - blind-matrix-transpose\ - blind-mean\ - blind-mosaic\ - blind-mosaic-corners\ - blind-mosaic-edges\ - blind-multiply-matrices\ - blind-next-frame\ - blind-norm\ - blind-peek-head\ - blind-premultiply\ - blind-quaternion-product\ - blind-radial-gradient\ - blind-read-head\ - blind-rectangle-tessellation\ - blind-repeat\ - blind-repeat-tessellation\ - blind-reverse\ - blind-rewrite-head\ - blind-round-wave\ - blind-sawtooth-wave\ - blind-set-alpha\ - blind-set-luma\ - blind-set-saturation\ - blind-single-colour\ - blind-sinc-wave\ - blind-sine-wave\ - blind-skip-pattern\ - blind-spatial-arithm\ - blind-spatial-mean\ - blind-spectrum\ - blind-spiral-gradient\ - blind-split\ - blind-split-chans\ - blind-split-cols\ - blind-split-rows\ - blind-square-gradient\ - blind-stack\ - blind-tee\ - blind-temporal-arithm\ - blind-temporal-mean\ - blind-time-blur\ - blind-to-image\ - blind-to-named\ - blind-to-portable\ - blind-to-text\ - blind-to-video\ - blind-transition\ - blind-translate\ - blind-transpose\ - blind-triangle-tessellation\ - blind-triangular-wave\ - blind-unpremultiply\ - blind-vector-projection\ - blind-write-head - SH_SCRIPTS =\ blind-rotate-90\ blind-rotate-180\ @@ -120,150 +17,82 @@ COMMON_OBJ =\ stream.o HDR =\ - src/arg.h\ - src/common.h\ - src/define-functions.h\ - src/stream.h\ - src/util.h\ - src/util/to.h\ - src/util/jobs.h\ - src/util/emalloc.h\ - src/util/eopen.h\ - src/util/endian.h\ - src/util/colour.h\ - src/util/io.h\ - src/util/efflush.h\ - src/util/efunc.h\ - src/util/eprintf.h\ - src/util/fshut.h\ - src/video-math.h + arg.h\ + common.h\ + define-functions.h\ + stream.h\ + util.h\ + util/to.h\ + util/jobs.h\ + util/emalloc.h\ + util/eopen.h\ + util/endian.h\ + util/colour.h\ + util/io.h\ + util/efflush.h\ + util/efunc.h\ + util/eprintf.h\ + util/fshut.h\ + video-math.h MISCFILES =\ Makefile\ config.mk\ + blind.mk\ + rules.mk\ LICENSE\ README\ - TODO - -EXAMPLEDIRS =\ - inplace-flop\ - reverse\ - split + TODO\ + src/generate-macros.c EXAMPLEFILES =\ inplace-flop/Makefile\ reverse/Makefile\ split/Makefile -COMMON_SRC = $(COMMON_OBJ:.o=.c) -SRC = $(BIN:=.c) $(COMMON_SRC) -SCRIPTS = $(SH_SCRIPTS) $(KSH_SCRIPTS) -MAN1 = $(BIN:=.1) $(SCRIPTS:=.1) -MAN7 = blind.7 - - -all: $(BIN) -mcb: blind-mcb - -%: %.o $(COMMON_OBJ) - $(CC) -o $@ $^ $(LDFLAGS) - -%.o: src/%.c $(HDR) platform.h - $(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $< - -%.bo: src/%.c $(HDR) platform.h - $(CC) $(CFLAGS) $(CPPFLAGS) -Dmain="$$(printf 'main_%s\n' $* | tr -- - _)" -c -o $@ $< - -blind-mcb.c: Makefile - printf '#include <%s.h>\n' stdio string > blind-mcb.c - printf 'int main_%s(int argc, char *argv[]);\n' $(BIN) | tr -- - _ >> blind-mcb.c - printf 'int main(int argc, char *argv[]) {\n' >> blind-mcb.c - printf 'char *cmd = strrchr(*argv, '"'/'"');\n' >> blind-mcb.c - printf 'cmd = cmd ? cmd + 1 : *argv;\n' >> blind-mcb.c - for c in $(BIN); do \ - printf 'if (!strcmp(cmd, "%s"))\n\treturn main_%s(argc, argv);\n' "$$c" "$$c" | \ - sed '/^\t/s/-/_/g'; \ - done >> blind-mcb.c - printf 'fprintf(stderr, "Invalid command: %%s\\n", cmd);\n' >> blind-mcb.c - printf 'return 1;\n' >> blind-mcb.c - printf '}\n' >> blind-mcb.c - -blind-mcb: blind-mcb.o $(BIN:=.bo) $(COMMON_OBJ) - $(CC) -o $@ $^ $(LDFLAGS) - -generate-macros: src/generate-macros.c - $(CC) $(CFLAGS) $(CPPFLAGS) -o $@ $< $(LDFLAGS) - -platform.h: generate-macros - ./generate-macros > platform.h - -install: all - mkdir -p -- "$(DESTDIR)$(PREFIX)/bin" - cp -f -- $(BIN) $(SCRIPTS) "$(DESTDIR)$(PREFIX)/bin" - cd "$(DESTDIR)$(PREFIX)/bin" && sed -i '1s:bash$$:$(KORN_SHELL):' $(KSH_SCRIPTS) - cd -- "$(DESTDIR)$(PREFIX)/bin" && chmod 755 $(BIN) $(SCRIPTS) - mkdir -p -- "$(DESTDIR)$(MANPREFIX)/man1" - set -e && for m in $(MAN1); do \ - sed '1s/ blind$$/ " blind $(VERSION)"/g' \ - < "man/$$m" > "$(DESTDIR)$(MANPREFIX)/man1/$$m"; \ - done - cd -- "$(DESTDIR)$(MANPREFIX)/man1" && chmod 644 $(MAN1) - mkdir -p -- "$(DESTDIR)$(MANPREFIX)/man7" - set -e && for m in $(MAN7); do \ - sed '1s/ blind$$/ " blind $(VERSION)"/g' \ - < "man/$$m" > "$(DESTDIR)$(MANPREFIX)/man7/$$m"; \ - done - cd -- "$(DESTDIR)$(MANPREFIX)/man7" && chmod 644 $(MAN7) - -install-mcb: mcb - mkdir -p -- "$(DESTDIR)$(PREFIX)/bin" - for c in $(BIN); do \ - $(LN) -f -- blind-single-colour "$(DESTDIR)$(PREFIX)/bin/$$c"; done - rm -f -- "$(DESTDIR)$(PREFIX)/bin/blind-single-colour" - cp -f -- blind-mcb "$(DESTDIR)$(PREFIX)/bin/blind-single-colour" - cp -f -- $(SCRIPTS) "$(DESTDIR)$(PREFIX)/bin" - cd "$(DESTDIR)$(PREFIX)/bin" && sed -i '1s:bash$$:$(KORN_SHELL):' $(KSH_SCRIPTS) - cd -- "$(DESTDIR)$(PREFIX)/bin" && chmod 755 -- blind-single-colour $(SCRIPTS) - mkdir -p -- "$(DESTDIR)$(MANPREFIX)/man1" - set -e && for m in $(MAN1); do \ - sed '1s/ blind$$/ " blind $(VERSION)"/g' \ - < "man/$$m" > "$(DESTDIR)$(MANPREFIX)/man1/$$m"; \ - done - cd -- "$(DESTDIR)$(MANPREFIX)/man1" && chmod 644 $(MAN1) - mkdir -p -- "$(DESTDIR)$(MANPREFIX)/man7" - set -e && for m in $(MAN7); do \ - sed '1s/ blind$$/ " blind $(VERSION)"/g' \ - < "man/$$m" > "$(DESTDIR)$(MANPREFIX)/man7/$$m"; \ - done - cd -- "$(DESTDIR)$(MANPREFIX)/man7" && chmod 644 $(MAN7) - -uninstall: - cd -- "$(DESTDIR)$(PREFIX)/bin" && rm -f $(BIN) $(SCRIPTS) - cd -- "$(DESTDIR)$(MANPREFIX)/man1" && rm -f $(MAN1) - cd -- "$(DESTDIR)$(MANPREFIX)/man7" && rm -f $(MAN7) - -dist: - -rm -rf "blind-$(VERSION)" - mkdir -p "blind-$(VERSION)/src/util" "blind-$(VERSION)/man" - cp $(MISCFILES) $(SCRIPTS) "blind-$(VERSION)" - cd man && cp $(MAN1) $(MAN7) "../blind-$(VERSION)/man" - set -e && cd src && for s in $(SRC); do \ - cp "$$s" "../blind-$(VERSION)/src/$$s"; done - set -e && for s in $(HDR); do \ - cp "$$s" "../blind-$(VERSION)/$$s"; done - set -e && for e in $(EXAMPLEDIRS); do \ - mkdir -p "blind-$(VERSION)/examples/$$e"; done - set -e && cd examples && for e in $(EXAMPLEFILES); \ - do cp "$$e" "../blind-$(VERSION)/examples/$$e"; done - tar -cf "blind-$(VERSION).tar" "blind-$(VERSION)" - gzip -9 "blind-$(VERSION).tar" - rm -rf "blind-$(VERSION)" +MAN7 =\ + blind + +all: build/files.mk build/common-files.mk + @make -f blind.mk $@ + +build/files.mk: files.mk + mkdir -p -- $(@D) + ( printf 'BIN =' && \ + printf '\\\n\t%s' $(BIN) && \ + printf '\n\nSRC =' && \ + printf '\\\n\tsrc/%s' $(BIN:=.c) $(COMMON_OBJ:.o=.c) && \ + printf '\n\nEXAMPLEDIRS =' && \ + printf '\\\n\texamples/%s' $(EXAMPLEFILES) | sed 's|/[^/\\]*\(\\*\)$$|\1|' | uniq && \ + printf '\n\nEXAMPLEFILES =' && \ + printf '\\\n\texamples/%s' $(EXAMPLEFILES) && \ + printf '\n\nMISCFILES =' && \ + printf '\\\n\t%s' $(MISCFILES) && \ + printf '\n\nSH_SCRIPTS =' && \ + printf '\\\n\t%s' $(SH_SCRIPTS) && \ + printf '\n\nKSH_SCRIPTS =' && \ + printf '\\\n\t%s' $(KSH_SCRIPTS) && \ + printf '\n\nMAN =' && \ + printf '\\\n\tman1/%s.1' $(BIN) $(SH_SCRIPTS) $(KSH_SCRIPTS) && \ + printf '\\\n\tman7/%s.7' $(MAN7) && \ + printf '\n' \ + ) > $@.$$$$ && mv $@.$$$$ $@ + +build/common-files.mk: Makefile + mkdir -p -- $(@D) + ( printf 'HDR =' && \ + printf '\\\n\tsrc/%s' $(HDR) && \ + printf '\n\nCOMMON_OBJ =' && \ + printf '\\\n\t%s' $(COMMON_OBJ) && \ + printf '\n' \ + ) > $@.$$$$ && mv $@.$$$$ $@ clean: - -rm -f -- $(BIN) *.o blind-$(VERSION).tar.gz platform.h generate-macros - -rm -f -- blind-mcb.c blind-mcb *.bo - -rm -rf -- "blind-$(VERSION)" + -rm -rf -- $(BIN) build *.o *.a *.bo blind-mcb + -rm -rf -- blind-$(VERSION).tar.gz "blind-$(VERSION)" +.DEFAULT: + @make build/files.mk build/common-files.mk + @make -f blind.mk $@ -.PHONY: all mcb install install-mcb uninstall dist clean -.PRECIOUS: $(COMMON_OBJ) platform.h +.PHONY: all clean diff --git a/blind.mk b/blind.mk @@ -0,0 +1,109 @@ +.POSIX: + +CONFIGFILE = config.mk + +SCRIPTS = $(SH_SCRIPTS) $(KSH_SCRIPTS) +MAN1 = $(BIN:=.1) $(SCRIPTS:=.1) +MAN7 = blind.7 +BOBJ = $(BIN:=.bo) +OBJ = $(BIN:=.o) $(COMMON_OBJ) + +DIST_MAN = $(MAN1) $(MAN7) +DIST_MISC = $(HDR) $(SRC) $(SCRIPTS) $(MISCFILES) $(EXAMPLEFILES) + +DEPS = build/common-files.mk blind.mk $(CONFIGFILE) +MCB_DEPS = build/files.mk $(DEPS) + +include $(CONFIGFILE) +include build/files.mk +include build/common-files.mk + +all: $(BIN) +mcb: blind-mcb + +$(BIN): $(@:=.o) $(COMMON_OBJ) $(DEPS) +.o: + $(CC) -o $@ $< $(COMMON_OBJ) $(LDFLAGS) + +$(OBJ): src/$(@:.o=:c) $(HDR) build/platform.h $(DEPS) +$(OBJ): + $(CC) $(CFLAGS) -c -o $$$$.$@ src/$*.c && mv $$$$.$@ $@ + +build/blind-mcb.o: $(MCB_DEPS) +.c.o: + $(CC) $(CFLAGS) -c -o $@ $< + +$(BOBJ): src/$(@:.bo=:c) $(HDR) build/platform.h $(DEPS) +$(BOBJ): + $(CC) $(CFLAGS) -Dmain="$$(printf 'main_%s\n' $* | tr -- - _)" -c -o $@ src/$*.c + +build/blind-mcb.c: $(MCB_DEPS) + mkdir -p $(@D) + printf '#include <%s.h>\n' stdio string > $@ + printf 'int main_%s(int argc, char *argv[]);\n' $(BIN) | tr -- - _ >> $@ + printf 'int main(int argc, char *argv[]) {\n' >> $@ + printf 'char *cmd = strrchr(*argv, '"'/'"');\n' >> $@ + printf 'cmd = cmd ? &cmd[1] : *argv;\n' >> $@ + set -e && for c in $(BIN); do \ + printf 'if (!strcmp(cmd, "%s"))\n\treturn main_%s(argc, argv);\n' "$$c" "$$c" | \ + sed '/^\t/s/-/_/g'; \ + done >> $@ + printf 'fprintf(stderr, "Invalid command: %%s\\n", cmd);\n' >> $@ + printf 'return 1;\n' >> $@ + printf '}\n' >> $@ + +blind-mcb: build/blind-mcb.o $(BOBJ) $(COMMON_OBJ) $(MCB_DEPS) + $(CC) -o $@ build/blind-mcb.o $(BOBJ) $(COMMON_OBJ) $(LDFLAGS) + +build/generate-macros: src/generate-macros.c $(DEPS) + @mkdir -p -- $(@D) + $(CC) $(CFLAGS) -o $@.$$$$ src/generate-macros.c $(LDFLAGS) && mv $@.$$$$ $@ + +src/../build/platform.h: build/platform.h +build/platform.h: build/generate-macros $(DEPS) + @mkdir -p -- $(@D) + build/generate-macros > $@.$$$$ && mv $@.$$$$ $@ + +install: all install-common + cp -f -- $(BIN) "$(DESTDIR)$(PREFIX)/bin" + cd -- "$(DESTDIR)$(PREFIX)/bin" && chmod 755 $(BIN) + +install-mcb: mcb install-common + for c in $(BIN); do \ + $(LN) -f -- blind-single-colour "$(DESTDIR)$(PREFIX)/bin/$$c"; done + rm -f -- "$(DESTDIR)$(PREFIX)/bin/blind-single-colour" + cp -f -- blind-mcb "$(DESTDIR)$(PREFIX)/bin/blind-single-colour" + cd -- "$(DESTDIR)$(PREFIX)/bin" && chmod 755 -- blind-single-colour + +install-common: + mkdir -p -- "$(DESTDIR)$(PREFIX)/bin" + mkdir -p -- "$(DESTDIR)$(MANPREFIX)/man1" + mkdir -p -- "$(DESTDIR)$(MANPREFIX)/man7" + cp -f -- $(SCRIPTS) "$(DESTDIR)$(PREFIX)/bin" + cd -- "$(DESTDIR)$(PREFIX)/bin" && sed -i '1s:bash$$:$(KORN_SHELL):' $(KSH_SCRIPTS) + cd -- "$(DESTDIR)$(PREFIX)/bin" && chmod 755 -- $(SCRIPTS) + set -e && for m in $(MAN); do \ + sed '1s/ blind$$/ " blind $(VERSION)"/g' \ + < "man/$$(basename $$m)" > "$(DESTDIR)$(MANPREFIX)/$$m"; \ + done + cd -- "$(DESTDIR)$(MANPREFIX)" && chmod 644 $(MAN) + +uninstall: + cd -- "$(DESTDIR)$(PREFIX)/bin" && rm -f $(BIN) $(SCRIPTS) + cd -- "$(DESTDIR)$(MANPREFIX)" && rm -f $(MAN) + +dist: + -rm -rf "blind-$(VERSION)" + mkdir -p "blind-$(VERSION)" + cd "blind-$(VERSION)" && mkdir -p src/util man $(EXAMPLEDIRS) + cd man && cp $(DIST_MAN) "../blind-$(VERSION)/man" + set -e && for s in $(DIST_MISC); do cp "$$s" "../blind-$(VERSION)/$$s"; done + tar -cf "blind-$(VERSION).tar" "blind-$(VERSION)" + gzip -9 "blind-$(VERSION).tar" + rm -rf "blind-$(VERSION)" + +.SUFFIXES: +.SUFFIXES: .o .bo .c + +.PHONY: all mcb install install-mcb install-common uninstall dist +.PRECIOUS: $(COMMON_OBJ) build/platform.h diff --git a/config.mk b/config.mk @@ -15,7 +15,7 @@ LN = ln -s # You may want to remove -DHAVE_PRCTL, -DHAVE_EPOLL, -DHAVE_TEE, # and -DHAVE_SENDFILE from CPPFLAGS if you are not using Linux. -CFLAGS = -std=c11 -Wall -pedantic -O2 CPPFLAGS = -D_DEFAULT_SOURCE -D_BSD_SOURCE -D_XOPEN_SOURCE=700 -D_GNU_SOURCE \ -D_FILE_OFFSET_BITS=64 -DHAVE_PRCTL -DHAVE_EPOLL -DHAVE_TEE -DHAVE_SENDFILE +CFLAGS = -std=c11 -Wall -pedantic -O2 $(CPPFLAGS) LDFLAGS = -lm -s diff --git a/files.mk b/files.mk @@ -0,0 +1,104 @@ +BIN =\ + blind-affine-colour\ + blind-apply-kernel\ + blind-apply-palette\ + blind-arithm\ + blind-cat-cols\ + blind-cat-rows\ + blind-chroma-key\ + blind-colour-ciexyz\ + blind-colour-matrix\ + blind-colour-srgb\ + blind-compress\ + blind-concat\ + blind-cone-gradient\ + blind-convert\ + blind-coordinate-field\ + blind-crop\ + blind-cross-product\ + blind-cut\ + blind-decompress\ + blind-disperse\ + blind-dissolve\ + blind-dot-product\ + blind-double-sine-wave\ + blind-dual-key\ + blind-extend\ + blind-extract-alpha\ + blind-find-rectangle\ + blind-flip\ + blind-flop\ + blind-from-image\ + blind-from-named\ + blind-from-portable\ + blind-from-text\ + blind-from-video\ + blind-gauss-blur\ + blind-get-colours\ + blind-hexagon-tessellation\ + blind-interleave\ + blind-invert-luma\ + blind-invert-matrix\ + blind-kernel\ + blind-linear-gradient\ + blind-make-kernel\ + blind-matrix-orthoproject\ + blind-matrix-reflect\ + blind-matrix-rotate\ + blind-matrix-scale\ + blind-matrix-shear\ + blind-matrix-translate\ + blind-matrix-transpose\ + blind-mean\ + blind-mosaic\ + blind-mosaic-corners\ + blind-mosaic-edges\ + blind-multiply-matrices\ + blind-next-frame\ + blind-norm\ + blind-peek-head\ + blind-premultiply\ + blind-quaternion-product\ + blind-radial-gradient\ + blind-read-head\ + blind-rectangle-tessellation\ + blind-repeat\ + blind-repeat-tessellation\ + blind-reverse\ + blind-rewrite-head\ + blind-round-wave\ + blind-sawtooth-wave\ + blind-set-alpha\ + blind-set-luma\ + blind-set-saturation\ + blind-single-colour\ + blind-sinc-wave\ + blind-sine-wave\ + blind-skip-pattern\ + blind-spatial-arithm\ + blind-spatial-mean\ + blind-spectrum\ + blind-spiral-gradient\ + blind-split\ + blind-split-chans\ + blind-split-cols\ + blind-split-rows\ + blind-square-gradient\ + blind-stack\ + blind-tee\ + blind-temporal-arithm\ + blind-temporal-mean\ + blind-time-blur\ + blind-to-image\ + blind-to-named\ + blind-to-portable\ + blind-to-text\ + blind-to-video\ + blind-transition\ + blind-translate\ + blind-transpose\ + blind-triangle-tessellation\ + blind-triangular-wave\ + blind-unpremultiply\ + blind-vector-projection\ + blind-write-head diff --git a/src/common.h b/src/common.h @@ -17,7 +17,7 @@ # pragma GCC diagnostic ignored "-Wfloat-conversion" #endif -#include "../platform.h" +#include "../build/platform.h" #include "stream.h" #include "util.h" #include "video-math.h"