-
Notifications
You must be signed in to change notification settings - Fork 2
/
common.mk
218 lines (166 loc) · 5.79 KB
/
common.mk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
## Copyright 2008-2013, 2018 Guillaume Roguez
##
## This file is part of Helios.
##
## Helios is free software: you can redistribute it and/or modify
## it under the terms of the GNU Lesser General Public License as published by
## the Free Software Foundation, either version 3 of the License, or
## (at your option) any later version.
##
## Helios is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU Lesser General Public License for more details.
##
## You should have received a copy of the GNU Lesser General Public License
## along with Helios. If not, see <https://www.gnu.org/licenses/>.
##
##
## Common part used by all project Makefile's.
##
export
unexport SUBDIRS
# Mercurial stuff
SCM_REV := $(shell git describe --always --long --dirty)
# Paths stuff
LIBS_DIR := $(PRJROOT)/libs
DEVS_DIR := $(PRJROOT)/devs
CLS_DIR := $(PRJROOT)/classes/Helios
VPATH := $(PRJROOT):$(PRJROOT)/include:$(PRJROOT)/lib:$(LIBS_DIR):$(DEVS_DIR):$(CLS_DIR):.
OS := $(shell uname)
CP := cp -av
ECHO := echo -e
NODEPS := $(filter clean distclean,$(MAKECMDGOALS))
INCDIRS := . $(PRJROOT)/include $(PRJROOT)/src/common
ifeq ("$(OS)", "MorphOS")
TMPDIR := RAM:t
else
TMPDIR := /tmp
endif
RELVERSION = 0
RELREVISION = 0
RELVER = $(RELVERSION).$(RELREVISION)-$(SCM_REV)
RELARC_NAME = Helios_$(RELVER)
RELARC_DIR = $(TMPDIR)/Helios
RELARC_CLS_DIR = $(RELARC_DIR)/Classes/Helios
RELARC_C = $(RELARC_DIR)/C
#--- MorphOS dev tools framework ---
# GCC/Binutils
CC := ppc-morphos-gcc
LD := ppc-morphos-ld
AR := ppc-morphos-ar
NM := ppc-morphos-nm
STRIP := ppc-morphos-strip
ARFLAGS = rcs
OPT = -O2 -mmultiple -mstring -fno-strict-aliasing
DEFINES := $(CCDEFINES) \
-DUSE_INLINE_STDARG \
-DAROS_ALMOST_COMPATIBLE \
-DSCM_REV='"$(SCM_REV)"' \
-DBUILD_DATE='"$(shell /bin/date +%d.%m.%y)"'
CCWARNS = -Wall -Wextra -Wno-unused-parameter -Wno-implicit-fallthrough -Wno-unused-function
CFLAGS = -noixemul -g
CPPFLAGS = $(CFLAGS) $(OPT) $(CCWARNS) $(INCDIRS:%=-I%) $(DEFINES)
LIBS = -L$(PRJROOT)/lib -lhelios -ldebug -lauto
CCLDFLAGS = -noixemul -g -Wl,--traditional-format -Wl,--cref -Wl,--stats -Wl,-Map=$@.map -L$(PRJROOT)/lib
LDFLAGS = --traditional-format --cref --stats -fl libnix -Map=mapfile.txt -L$(PRJROOT)/lib
LDLIBS = -labox -ldebug -lc
ifneq ("$(OS)", "MorphOS")
LDLIBS += -lmath
endif
# Other build stuff
CVINCLUDE := cvinclude.pl
# Automatic variables
ifneq ("$LIBRARY_OBJS", "")
LIBRARY_OBJS := $(patsubst %.s, %.o, $(patsubst %.c, %.o, $(LIBRARY_SRCS)))
ALL_SRCS += $(LIBRARY_SRCS)
endif
#--- Echo beautifull stuff ---
COLOR_EMPHASIZE = "\033[37m"
COLOR_HIGHLIGHT1 = "\033[33m"
COLOR_HIGHLIGHT2 = "\033[32m"
COLOR_BOLD = "\033[0m\033[1m"
COLOR_NORMAL = "\033[0m"
ifeq ("$(OS)", "MorphOS")
FLUSH := FlushLib quiet
else
FLUSH := true
endif
#--- Build help targets ---
.DEFAULT: all
.PHONY: all clean distclean common-clean common-distclean mkdeps
.PHONY: local-clean local-distclean local-release
.SUFFIXES:
.SUFFIXES: .c .h .s .o .a .d .db .device .library .class .sym
all: mkdeps
debug:;
sdk:
$(addsuffix -%,$(SUBDIRS)):
$(MAKE) -C $(patsubst %-$*,%,$@) $*
common-clean:
rm -vf *.[ao] mapfile.txt *.map *.sym *.db
common-distclean: $(common_clean)
rm -vf *.d *~ *.tmp
clean: common-clean local-clean
@for dir in $(SUBDIRS); do \
$(ECHO) $(COLOR_BOLD)"++ "$(COLOR_HIGHLIGHT1)"Clean in"$(COLOR_BOLD)": "$(COLOR_HIGHLIGHT2)"$$dir"$(COLOR_NORMAL); \
(cd $$dir && $(MAKE) $(MFLAGS) --no-print-directory clean); \
done;
distclean: clean common-distclean local-distclean
@for dir in $(SUBDIRS); do \
$(ECHO) $(COLOR_BOLD)"++ "$(COLOR_HIGHLIGHT1)"Distclean in"$(COLOR_BOLD)": "$(COLOR_HIGHLIGHT2)"$$dir"$(COLOR_NORMAL); \
(cd $$dir && $(MAKE) $(MFLAGS) --no-print-directory distclean); \
done;
mkdeps: sdk $(ALL_SRCS:.c=.d)
.c.o:
@$(ECHO) $(COLOR_BOLD)">> "$(COLOR_HIGHLIGHT1)"$@"$(COLOR_NORMAL)
$(CC) -c $(CPPFLAGS) $< -o $@
.s.o:
@$(ECHO) $(COLOR_BOLD)">> "$(COLOR_HIGHLIGHT1)"$@"$(COLOR_NORMAL)
$(CC) -c $(CPPFLAGS) $< -o $@
.c.d:
@$(ECHO) $(COLOR_BOLD)">> "$(COLOR_HIGHLIGHT1)"$@"$(COLOR_NORMAL)
$(SHELL) -ec '$(CC) -MM $(CPPFLAGS) $< | sed -e '\''s%\($(notdir $*)\)\.o[ :]*%\1.o $@ : %g'\'' > $@; [ -s $@ ] || rm -fv $@'
%.db: $(LIBRARY_OBJS)
@$(ECHO) $(COLOR_BOLD)">> Linking: "$(COLOR_HIGHLIGHT2)"$@"$(COLOR_NORMAL)
$(LD) $(LDFLAGS) $^ -o $@ $(LDLIBS)
$(NM) -n $^ > $@.sym
.PRECIOUS: %.db
%.library: %.library.db
@$(ECHO) $(COLOR_BOLD)">> Making library: "$(COLOR_HIGHLIGHT2)"$(@F)"$(COLOR_NORMAL)
$(STRIP) -R.comment -o $@ $<
-$(FLUSH) $(notdir $@)
%.device: %.device.db
@$(ECHO) $(COLOR_BOLD)">> Making device: "$(COLOR_HIGHLIGHT2)"$(@F)"$(COLOR_NORMAL)
$(STRIP) -R.comment -o $@ $<
-$(FLUSH) $(notdir $@)
%.class: %.class.db
@$(ECHO) $(COLOR_BOLD)">> Making class: "$(COLOR_HIGHLIGHT2)"$(@F)"$(COLOR_NORMAL)
$(STRIP) -R.comment -o $@ $<
-$(FLUSH) $(notdir $@)
#--- Archive and Release help targets ---
.PHONY: rel-lha rel-tbz release
rel-lha:
-delete force $(RELARC_DIR)//$(RELARC_NAME).lha
(cd $(RELARC_DIR)/..; lha -eraxFY3 r $(RELARC_NAME).lha $(notdir $(RELARC_DIR)))
rel-tbz:
rm -vf $(RELARC_DIR)/../$(RELARC_NAME).tar
(cd $(RELARC_DIR)/..; tar --show-stored-names -vcf $(RELARC_NAME).tar $(notdir $(RELARC_DIR)) && bzip2 -vz9f $(RELARC_NAME).tar)
local-release:
release: local-release
ifeq ("$(OS)", "MorphOS")
release: rel-lha
else
release: rel-tbz
endif
astyle:
astyle --options=$(PRJROOT)/.astylerc -RQ $(PRJROOT)/src/*.c $(PRJROOT)/src/*.h $(PRJROOT)/include/*.h
#--- Dependencies section ---
# ALL_SRCS : user defined, all .c files
ifneq ("$(strip $(ALL_SRCS))", "")
ifeq ("$(NODEPS)", "")
ifeq ("$(shell test -f $(PRJROOT)/include/proto/helios.h && echo -n yes)","yes")
-include $(patsubst %.c, %.d, $(filter %.c, $(ALL_SRCS)))
endif
endif
endif