Initial commit.
[dvdrip] / Makefile
CommitLineData
7fbe0fb9
MW
1### -*-makefile-*-
2
3all:
4clean::
5
6.SECONDEXPANSION: # sorry
7
8bindir = ../bin
9
10V = 0
11V_AT = $(V_AT_$V)
12V_AT_0 = @
13v-tag = $(call v-tag_$V,$1)
14v-tag_0 = @printf " %-12s %s\n" "$1" "$@";
15
16CC = gcc
17CFLAGS = -O2 -g -pedantic -Wall -Werror
18
19LD = gcc
20LDFLAGS =
21
22ARCH += i686
23CFLAGS_i386 = -m32
24
25ARCH += x86_64
26CFLAGS_amd64 = -m64
27
28PROGS += dvd-sector-copy
29dvd-sector-copy_SRCS = dvd-sector-copy.c
30dvd-sector-copy_LIBS = -ldvdread -lm
31
32SCRIPTS += dvdrip
33SCRIPTS += dvdrip-upload
34
35define setup-arch
36obj.$1/%.o: %.c
37 $$(V_AT)mkdir -p $$(dir $$@)
38 $$(call v-tag,CC [$1])$$(CC) -c $$(CFLAGS) $$(CFLAGS_$1) -o$$@ -MD -MF obj.$1/$$*.dep $$<
39clean::; rm -rf obj.$1
40endef
41$(foreach a,$(ARCH), $(eval $(call setup-arch,$a)))
42
43objects = $(addsuffix $(or $2,.o),$(basename $(filter %.c %.s %.S,$1)))
44
45ALL_PROGS += $(foreach a,$(ARCH), \
46 $(foreach p,$(PROGS), $(bindir)/$p.$a))
47TARGETS += $(ALL_PROGS)
48program-name = $(basename $1)
49program-arch = $(patsubst .%,%,$(suffix $1))
50program-sources = $($(call program-name,$1)_SRCS) \
51 $($(call program-name,$1)_SRCS_$(call program-arch,$1))
52program-objects = $(addprefix obj.$(call program-arch,$1)/, \
53 $(call objects,$(call program-sources,$1),$2))
54$(ALL_PROGS): $(bindir)/%: $$(call program-objects,$$*) $$($$(call program-name,$$*)_DEPS)
55 $(call v-tag,LD [$(call program-arch,$*)])$(LD) \
56 $(LDFLAGS) $(LDFLAGS_$(call program-arch,$*)) -o$@ \
57 $(call program-objects,$*) \
58 $($(call program-name,$*)_LIBS) \
59 $($(call program-name,$*)_LIBS_$(call program-arch,$*))
60
61ALL_SCRIPTS = $(addprefix $(bindir)/, $(SCRIPTS))
62TARGETS += $(ALL_SCRIPTS)
63$(ALL_SCRIPTS): $(bindir)/%: %
64 $(call v-tag,SCRIPT)install $* $@
65
66p:; : $p
67
68all: $(TARGETS)
69clean::; rm -f $(TARGETS)
70
71-include $(foreach p,$(notdir $(ALL_PROGS)), $(call program-objects,$p,.dep))