]> git.sur5r.net Git - cc65/blob - src/Makefile
Allow to build just the binaries or just the libraries from the top level Makefile.
[cc65] / src / Makefile
1 ifeq ($(shell echo),)
2
3 PROGS = ar65  \
4         ca65  \
5         cc65  \
6         cl65  \
7         co65  \
8         da65  \
9         grc65 \
10         ld65  \
11         od65  \
12         sp65
13
14 CA65_INC := $(abspath ../asminc)
15 CC65_INC := $(abspath ../include)
16 LD65_LIB := $(abspath ../lib)
17 LD65_OBJ := $(abspath ../lib)
18 LD65_CFG := $(abspath ../cfg)
19
20 CFLAGS += -MMD -MP -O -std=c89 -I common \
21           -Wall -Wextra -Wno-char-subscripts -Werror \
22           -DCA65_INC=$(CA65_INC) -DCC65_INC=$(CC65_INC) \
23           -DLD65_LIB=$(LD65_LIB) -DLD65_OBJ=$(LD65_OBJ) -DLD65_CFG=$(LD65_CFG)
24
25 LDLIBS += -lm
26
27 .SUFFIXES:
28
29 .PHONY: all bin $(PROGS) mostlyclean clean install uninstall
30
31 all bin: $(PROGS)
32
33 mostlyclean:
34         $(RM) -r ../wrk
35
36 clean:
37         $(RM) -r ../wrk ../bin
38
39 install: all
40         $(foreach prog,$(PROGS),$(INSTALL_recipe))
41
42 uninstall:
43         $(foreach prog,$(PROGS),$(UNINSTALL_recipe))
44
45 ##########
46
47 define INSTALL_recipe
48
49 ln -s $(abspath ../bin/$(prog)) /usr/local/bin/$(prog)
50
51 endef
52
53 ##########
54
55 define UNINSTALL_recipe
56
57 $(RM) /usr/local/bin/$(prog)
58
59 endef
60
61 ##########
62
63 define OBJS_template
64
65 $1_OBJS := $$(patsubst %.c,../wrk/%.o,$$(wildcard $1/*.c))
66
67 $$($1_OBJS): | ../wrk/$1
68
69 ../wrk/$1:
70         @mkdir -p $$@
71
72 DEPS += $$($1_OBJS:.o=.d)
73
74 endef
75
76 ##########
77
78 define PROG_template
79
80 $$(eval $$(call OBJS_template,$1))
81
82 ../bin/$1: $$($1_OBJS) ../wrk/common/common.a | ../bin
83         $$(CC) $$(LDFLAGS) -o $$@ $$^ $$(LDLIBS)
84
85 $1: ../bin/$1
86
87 endef
88
89 ##########
90
91 ../wrk/%.o: %.c
92         @echo $<
93         @$(CC) -c $(CFLAGS) -o $@ $<
94
95 ../bin:
96         @mkdir $@
97
98 $(eval $(call OBJS_template,common))
99 ../wrk/common/common.a: $(common_OBJS)
100         $(AR) r $@ $?
101
102 $(foreach prog,$(PROGS),$(eval $(call PROG_template,$(prog))))
103
104 -include $(DEPS)
105
106 else # cmd.exe
107
108 .SUFFIXES:
109
110 .PHONY: all bin mostlyclean clean
111
112 all bin:
113         msbuild cc65.sln /p:configuration=release /consoleloggerparameters:disableconsolecolor
114
115 mostlyclean:
116         $(if $(wildcard ../wrk),rmdir /s /q ..\wrk)
117
118 clean:
119         msbuild cc65.sln /p:configuration=release /consoleloggerparameters:disableconsolecolor /target:$@
120
121 endif # cmd.exe