]> git.sur5r.net Git - cc65/blob - src/Makefile
Replace only actually changed archive members.
[cc65] / src / Makefile
1 PROGS = ar65  \
2         ca65  \
3         cc65  \
4         cl65  \
5         co65  \
6         da65  \
7         grc65 \
8         ld65  \
9         od65  \
10         sp65
11
12 CA65_INC := $(abspath ../asminc)
13 CC65_INC := $(abspath ../include)
14 LD65_LIB := $(abspath ../lib)
15 LD65_OBJ := $(abspath ../lib)
16 LD65_CFG := $(abspath ../cfg)
17
18 CFLAGS += -MMD -MP -O -std=c89 -I common \
19           -Wall -Wextra -Wno-char-subscripts -Werror \
20           -DCA65_INC=$(CA65_INC) -DCC65_INC=$(CC65_INC) \
21           -DLD65_LIB=$(LD65_LIB) -DLD65_OBJ=$(LD65_OBJ) -DLD65_CFG=$(LD65_CFG)
22
23 LDLIBS += -lm
24
25 all: $(PROGS)
26
27 mostlyclean:
28         $(RM) -r ../wrk
29
30 clean: mostlyclean
31         $(RM) -r ../bin
32
33 install: all
34         $(foreach prog,$(PROGS),$(INSTALL_recipe))
35
36 uninstall:
37         $(foreach prog,$(PROGS),$(UNINSTALL_recipe))
38
39 .PHONY: all $(PROGS) mostlyclean clean install uninstall
40
41 ##########
42
43 define INSTALL_recipe
44
45 ln -s $(abspath ../bin/$(prog)) /usr/local/bin/$(prog)
46
47 endef
48
49 ##########
50
51 define UNINSTALL_recipe
52
53 $(RM) /usr/local/bin/$(prog)
54
55 endef
56
57 ##########
58
59 define OBJS_template
60
61 $(1)_OBJS := $$(addprefix ../wrk/,$$(addsuffix .o,$$(basename $$(wildcard $(1)/*.c))))
62
63 $$($(1)_OBJS): | ../wrk/$(1)
64
65 ../wrk/$(1):
66         mkdir -p $$@
67
68 DEPS += $$($(1)_OBJS:.o=.d)
69
70 endef
71
72 ##########
73
74 define PROG_template
75
76 $$(eval $$(call OBJS_template,$(1)))
77
78 ../bin/$(1): $$($(1)_OBJS) ../wrk/common/common.a | ../bin
79         $$(CC) $$(LDFLAGS) $$(LDLIBS) -o $$@ $$^
80
81 $(1): ../bin/$(1)
82
83 endef
84
85 ##########
86
87 ../wrk/%.o: %.c
88         @echo $(CC) $<
89         @$(CC) -c $(CFLAGS) -o $@ $<
90
91 ../bin:
92         mkdir $@
93
94 $(eval $(call OBJS_template,common))
95 ../wrk/common/common.a: $(common_OBJS)
96         $(AR) r $@ $?
97
98 $(foreach prog,$(PROGS),$(eval $(call PROG_template,$(prog))))
99
100 -include $(DEPS)