]> git.sur5r.net Git - cc65/blob - src/Makefile
e62886c737543fc7007c79336425ef0064140ccf
[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 .SUFFIXES:
42
43 ##########
44
45 define INSTALL_recipe
46
47 ln -s $(abspath ../bin/$(prog)) /usr/local/bin/$(prog)
48
49 endef
50
51 ##########
52
53 define UNINSTALL_recipe
54
55 $(RM) /usr/local/bin/$(prog)
56
57 endef
58
59 ##########
60
61 define OBJS_template
62
63 $1_OBJS := $$(patsubst %.c,../wrk/%.o,$$(wildcard $1/*.c))
64
65 $$($1_OBJS): | ../wrk/$1
66
67 ../wrk/$1:
68         mkdir -p $$@
69
70 DEPS += $$($1_OBJS:.o=.d)
71
72 endef
73
74 ##########
75
76 define PROG_template
77
78 $$(eval $$(call OBJS_template,$1))
79
80 ../bin/$1: $$($1_OBJS) ../wrk/common/common.a | ../bin
81         $$(CC) $$(LDFLAGS) -o $$@ $$^ $$(LDLIBS)
82
83 $1: ../bin/$1
84
85 endef
86
87 ##########
88
89 ../wrk/%.o: %.c
90         @echo $(CC) $<
91         @$(CC) -c $(CFLAGS) -o $@ $<
92
93 ../bin:
94         mkdir $@
95
96 $(eval $(call OBJS_template,common))
97 ../wrk/common/common.a: $(common_OBJS)
98         $(AR) r $@ $?
99
100 $(foreach prog,$(PROGS),$(eval $(call PROG_template,$(prog))))
101
102 -include $(DEPS)