| 1 | ### -*-makefile-*- |
| 2 | |
| 3 | all: |
| 4 | clean:: |
| 5 | .PHONY: all clean |
| 6 | |
| 7 | CLEANFILES += $(TARGETS) |
| 8 | |
| 9 | .SECONDEXPANSION: # sorry |
| 10 | |
| 11 | prefix = $(HOME) |
| 12 | exec_prefix = $(prefix) |
| 13 | bindir = $(exec_prefix)/bin |
| 14 | |
| 15 | V = 0 |
| 16 | V_AT = $(V_AT_$V) |
| 17 | V_AT_0 = @ |
| 18 | v-tag = $(call v-tag_$V,$1) |
| 19 | v-tag_0 = @printf " %-8s %s\n" "$1" "$@"; |
| 20 | |
| 21 | CC = gcc |
| 22 | CFLAGS = -O2 -g -pedantic -Wall -Werror |
| 23 | |
| 24 | LD = gcc |
| 25 | LDFLAGS = |
| 26 | |
| 27 | PROGS += dvd-sector-copy |
| 28 | dvd-sector-copy_SRCS = dvd-sector-copy.c |
| 29 | dvd-sector-copy_LIBS = -ldvdread -lm |
| 30 | |
| 31 | SCRIPTS += dvdrip |
| 32 | SCRIPTS += dvdrip-upload |
| 33 | |
| 34 | %.o: %.c |
| 35 | $(call v-tag,CC)$(CC) -c $(CFLAGS) -o$@ -MD -MF $*.dep $< |
| 36 | CLEANFILES += *.o *.dep |
| 37 | |
| 38 | objects = $(addsuffix $(or $2,.o),$(basename $(filter %.c %.s %.S,$1))) |
| 39 | |
| 40 | TARGETS += $(PROGS) |
| 41 | program-objects = $(call objects,$($1_SRCS),$2) |
| 42 | $(PROGS): %: $$(call program-objects,$$*) $$($$*_DEPS) |
| 43 | $(call v-tag,LD)$(LD) $(LDFLAGS) -o$@ \ |
| 44 | $(call program-objects,$*) $($*_LIBS) |
| 45 | |
| 46 | INSTALL_bin = $(addprefix inst/,$(PROGS) $(SCRIPTS)) |
| 47 | install: $(INSTALL_bin) |
| 48 | $(INSTALL_bin): inst/%: % |
| 49 | $(V_AT)mkdir -p $(bindir) |
| 50 | $(call v-tag,INST)install -m755 $* $(bindir)/ |
| 51 | |
| 52 | p:; : $p |
| 53 | |
| 54 | all: $(TARGETS) |
| 55 | clean::; rm -f $(CLEANFILES) |
| 56 | |
| 57 | -include $(foreach p,$(PROGS), $(call program-objects,$p,.dep)) |