blind

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

blind.mk (3551B)


      1 .POSIX:
      2 
      3 CONFIGFILE = config.mk
      4 
      5 SCRIPTS    = $(SH_SCRIPTS) $(KSH_SCRIPTS)
      6 MAN1       = $(BIN:=.1) $(SCRIPTS:=.1)
      7 MAN7       = blind.7
      8 BOBJ       = $(BIN:=.bo)
      9 OBJ        = $(BIN:=.o) $(COMMON_OBJ)
     10 
     11 DIST_MAN   = $(MAN1) $(MAN7)
     12 DIST_MISC  = $(HDR) $(SRC) $(SCRIPTS) $(MISCFILES) $(EXAMPLEFILES)
     13 
     14 DEPS       = build/common-files.mk blind.mk $(CONFIGFILE)
     15 MCB_DEPS   = build/files.mk $(DEPS)
     16 
     17 include $(CONFIGFILE)
     18 include build/files.mk
     19 include build/common-files.mk
     20 
     21 all: $(BIN)
     22 mcb: blind-mcb
     23 
     24 $(BIN): $(@:=.o) $(COMMON_OBJ) $(DEPS)
     25 .o:
     26 	$(CC) -o $@ $< $(COMMON_OBJ) $(LDFLAGS)
     27 
     28 $(OBJ): src/$(@:.o=:c) $(HDR) build/platform.h $(DEPS)
     29 $(OBJ):
     30 	$(CC) $(CFLAGS) -c -o $$$$.$@ src/$*.c && mv $$$$.$@ $@
     31 
     32 build/blind-mcb.o: $(MCB_DEPS)
     33 .c.o:
     34 	$(CC) $(CFLAGS) -c -o $@ $<
     35 
     36 $(BOBJ): src/$(@:.bo=:c) $(HDR) build/platform.h $(DEPS)
     37 $(BOBJ):
     38 	$(CC) $(CFLAGS) -Dmain="$$(printf 'main_%s\n' $* | tr -- - _)" -c -o $@ src/$*.c
     39 
     40 build/blind-mcb.c: $(MCB_DEPS)
     41 	mkdir -p $(@D)
     42 	printf '#include <%s.h>\n' stdio string > $@
     43 	printf 'int main_%s(int argc, char *argv[]);\n' $(BIN) | tr -- - _ >> $@
     44 	printf 'int main(int argc, char *argv[]) {\n' >> $@
     45 	printf 'char *cmd = strrchr(*argv, '"'/'"');\n' >> $@
     46 	printf 'cmd = cmd ? &cmd[1] : *argv;\n' >> $@
     47 	set -e && for c in $(BIN); do \
     48 		printf 'if (!strcmp(cmd, "%s"))\n\treturn main_%s(argc, argv);\n' "$$c" "$$c" | \
     49 			sed '/^\t/s/-/_/g'; \
     50 	done >> $@
     51 	printf 'fprintf(stderr, "Invalid command: %%s\\n", cmd);\n' >> $@
     52 	printf 'return 1;\n' >> $@
     53 	printf '}\n' >> $@
     54 
     55 blind-mcb: build/blind-mcb.o $(BOBJ) $(COMMON_OBJ) $(MCB_DEPS)
     56 	$(CC) -o $@ build/blind-mcb.o $(BOBJ) $(COMMON_OBJ) $(LDFLAGS)
     57 
     58 build/generate-macros: src/generate-macros.c $(DEPS)
     59 	@mkdir -p -- $(@D)
     60 	$(CC) $(CFLAGS) -o $@.$$$$ src/generate-macros.c $(LDFLAGS) && mv $@.$$$$ $@
     61 
     62 src/../build/platform.h: build/platform.h
     63 build/platform.h: build/generate-macros $(DEPS)
     64 	@mkdir -p -- $(@D)
     65 	build/generate-macros > $@.$$$$ && mv $@.$$$$ $@
     66 
     67 install: all install-common
     68 	cp -f -- $(BIN) "$(DESTDIR)$(PREFIX)/bin"
     69 	cd -- "$(DESTDIR)$(PREFIX)/bin" && chmod 755 $(BIN)
     70 
     71 install-mcb: mcb install-common
     72 	for c in $(BIN); do \
     73 		$(LN) -f -- blind-single-colour "$(DESTDIR)$(PREFIX)/bin/$$c"; done
     74 	rm -f -- "$(DESTDIR)$(PREFIX)/bin/blind-single-colour"
     75 	cp -f -- blind-mcb "$(DESTDIR)$(PREFIX)/bin/blind-single-colour"
     76 	cd -- "$(DESTDIR)$(PREFIX)/bin" && chmod 755 -- blind-single-colour
     77 
     78 install-common:
     79 	mkdir -p -- "$(DESTDIR)$(PREFIX)/bin"
     80 	mkdir -p -- "$(DESTDIR)$(MANPREFIX)/man1"
     81 	mkdir -p -- "$(DESTDIR)$(MANPREFIX)/man7"
     82 	cp -f -- $(SCRIPTS) "$(DESTDIR)$(PREFIX)/bin"
     83 	cd -- "$(DESTDIR)$(PREFIX)/bin" && sed -i '1s:bash$$:$(KORN_SHELL):' $(KSH_SCRIPTS)
     84 	cd -- "$(DESTDIR)$(PREFIX)/bin" && chmod 755 -- $(SCRIPTS)
     85 	set -e && for m in $(MAN); do \
     86 		sed '1s/ blind$$/ " blind $(VERSION)"/g' \
     87 		< "man/$$(basename $$m)" > "$(DESTDIR)$(MANPREFIX)/$$m"; \
     88 	done
     89 	cd -- "$(DESTDIR)$(MANPREFIX)" && chmod 644 $(MAN)
     90 
     91 uninstall:
     92 	cd -- "$(DESTDIR)$(PREFIX)/bin" && rm -f $(BIN) $(SCRIPTS)
     93 	cd -- "$(DESTDIR)$(MANPREFIX)" && rm -f $(MAN)
     94 
     95 dist:
     96 	-rm -rf "blind-$(VERSION)"
     97 	mkdir -p "blind-$(VERSION)"
     98 	cd "blind-$(VERSION)" && mkdir -p src/util man $(EXAMPLEDIRS)
     99 	cd man && cp $(DIST_MAN) "../blind-$(VERSION)/man"
    100 	set -e && for s in $(DIST_MISC); do cp "$$s" "../blind-$(VERSION)/$$s"; done
    101 	tar -cf "blind-$(VERSION).tar" "blind-$(VERSION)"
    102 	gzip -9 "blind-$(VERSION).tar"
    103 	rm -rf "blind-$(VERSION)"
    104 
    105 .SUFFIXES:
    106 .SUFFIXES: .o .bo .c
    107 
    108 .PHONY: all mcb install install-mcb install-common uninstall dist
    109 .PRECIOUS: $(COMMON_OBJ) build/platform.h