]> git.sur5r.net Git - cc65/blob - src/Makefile
81f28dee5ae3f2d5db0aab885313468e623ae3c7
[cc65] / src / Makefile
1 ifneq ($(shell echo),)
2   CMD_EXE = 1
3 endif
4
5 PROGS = ar65  \
6         ca65  \
7         cc65  \
8         cl65  \
9         co65  \
10         da65  \
11         grc65 \
12         ld65  \
13         od65  \
14         sim65 \
15         sp65
16
17 .PHONY: all mostlyclean clean install zip avail unavail bin $(PROGS)
18
19 .SUFFIXES:
20
21 bindir  := $(prefix)/bin
22 datadir := $(if $(prefix),$(prefix)/share/cc65,$(abspath ..))
23
24 CA65_INC = $(datadir)/asminc
25 CC65_INC = $(datadir)/include
26 LD65_LIB = $(datadir)/lib
27 LD65_OBJ = $(datadir)/lib
28 LD65_CFG = $(datadir)/cfg
29
30 CC = $(CROSS_COMPILE)gcc
31 AR = $(CROSS_COMPILE)ar
32
33 CFLAGS += -MMD -MP -O -I common $(USER_CFLAGS) \
34           -Wall -Wextra -Wno-char-subscripts \
35           -DCA65_INC=$(CA65_INC) -DCC65_INC=$(CC65_INC) \
36           -DLD65_LIB=$(LD65_LIB) -DLD65_OBJ=$(LD65_OBJ) -DLD65_CFG=$(LD65_CFG)
37
38 CFLAGS += $(if $(TRAVIS),-Werror)
39
40 LDLIBS += -lm
41
42 ifdef CMD_EXE
43   EXE_SUFFIX=.exe
44 endif
45
46 ifdef CROSS_COMPILE
47   EXE_SUFFIX=.exe
48 endif
49
50 ifdef CMD_EXE
51   DIRLIST = $(strip $(foreach dir,$1,$(wildcard $(dir))))
52   MKDIR = mkdir $(subst /,\,$1)
53   RMDIR = $(if $(DIRLIST),rmdir /s /q $(subst /,\,$(DIRLIST)))
54 else
55   MKDIR = mkdir -p $1
56   RMDIR = $(RM) -r $1
57 endif
58
59 all bin: $(PROGS)
60
61 mostlyclean:
62         $(call RMDIR,../wrk)
63
64 clean:
65         $(call RMDIR,../wrk ../bin)
66
67 ifdef CMD_EXE
68
69 install avail unavail:
70
71 else # CMD_EXE
72
73 INSTALL = install
74
75 define AVAIL_recipe
76
77 ln -s $(abspath ../bin/$(prog)) /usr/local/bin/$(prog)
78
79 endef # AVAIL_recipe
80
81 define UNAVAIL_recipe
82
83 $(RM) /usr/local/bin/$(prog)
84
85 endef # UNAVAIL_recipe
86
87 install:
88         $(if $(prefix),,$(error variable `prefix' must be set))
89         $(INSTALL) -d $(DESTDIR)$(bindir)
90         $(INSTALL) ../bin/* $(DESTDIR)$(bindir)
91
92 avail:
93         $(foreach prog,$(PROGS),$(AVAIL_recipe))
94
95 unavail:
96         $(foreach prog,$(PROGS),$(UNAVAIL_recipe))
97
98 endif # CMD_EXE
99
100 zip:
101         @cd .. && zip cc65 bin/*
102
103 define OBJS_template
104
105 $1_OBJS := $$(patsubst %.c,../wrk/%.o,$$(wildcard $1/*.c))
106
107 $$($1_OBJS): | ../wrk/$1
108
109 ../wrk/$1:
110         @$$(call MKDIR,$$@)
111
112 DEPS += $$($1_OBJS:.o=.d)
113
114 endef # OBJS_template
115
116 define PROG_template
117
118 $$(eval $$(call OBJS_template,$1))
119
120 ../bin/$1$(EXE_SUFFIX): $$($1_OBJS) ../wrk/common/common.a | ../bin
121         $$(CC) $$(LDFLAGS) -o $$@ $$^ $$(LDLIBS)
122
123 $1: ../bin/$1$(EXE_SUFFIX)
124
125 endef # PROG_template
126
127 ../wrk/%.o: %.c
128         @echo $<
129         @$(CC) -c $(CFLAGS) -o $@ $<
130
131 ../bin:
132         @$(call MKDIR,$@)
133
134 $(eval $(call OBJS_template,common))
135
136 ../wrk/common/common.a: $(common_OBJS)
137         $(AR) r $@ $?
138
139 $(foreach prog,$(PROGS),$(eval $(call PROG_template,$(prog))))
140
141 -include $(DEPS)