summaryrefslogtreecommitdiffstats
path: root/automake/compile.am
blob: b618e0cb12a8e631369cc81e55abf764ced5af85 (plain) (blame)
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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
##
## $Id$
##

## -------------------------------------------------------------------------
## NOTE: This file is rather immature and has to be considered to be 
## almost experimental.
##
## Expect frequent changes -- It deserves to be cleaned up :(
## -------------------------------------------------------------------------

## The section below is based on make/compilers/gcc-target-default.cfg
## used in former versions of RTEMS.

## 
## Set up the flags for the toolchains:
##
## We are considering 3 different building schemes here:
## * Using gcc's being able to accept -specs (aka gcc-2.8 building scheme)
## * Using gcc's not being able to accept -specs (aka gcc-2.7.2 building
##   scheme)
## * Using third party toolchains (aka non-gcc building scheme)
##
## Automake conditionals in use:
## RTEMS_USE_GCC     .. if we are using GCC
## RTEMS_USE_GCC272  .. if using gcc and if requested not to apply
##                      gcc <= 2.7.2 incompatible rules

## NOTES: 
## * The gcc-2.8 building scheme is the nominal building scheme and
##   is actively supported.
## * The gcc-2.7.2 building scheme is not supported by all BSPs and
##   is not extensively tested.
## * The non-gcc building scheme requires manually setting up environment 
##   variables and is hardly tested at all

## CFLAGS_OPTIMIZE_V, CFLAGS_DEBUG_V, CFLAGS_PROFILE_V are the values we
## would want the corresponding macros to be set to.
##
## CFLAGS_OPTIMIZE, CFLAGS_DEBUG, CFLAGS_PROFILE are set by the 
## 'VARIANT=<OPTIMIZE|DEBUG|PROFILE>' targets to their _V values.

## XCPPFLAGS, XCFLAGS, XCXXFLAGS, XASFLAGS 
## are used to add flags from the shell
## cf. make.info ("Implicit rules/variables" for details)

if RTEMS_USE_GCC
## All the stuff below is specific to gcc

CFLAGS_DEFAULT=-g -Wall -ansi -fasm

if RTEMS_USE_GCC272
## gcc <= 2.7.2
RTEMS_CPPFLAGS = -isystem $(PROJECT_INCLUDE)

# default location of Standard C Library
LIBC_LIBC = $(shell $(CC) $(CPU_CFLAGS) -print-file-name=libc.a $(GCCSED))
LIBC_LIBM = $(shell $(CC) $(CPU_CFLAGS) -print-file-name=libm.a $(GCCSED))
LIBC_LIBGCC = $(shell $(CC) $(CPU_CFLAGS) -print-libgcc-file-name $(GCCSED))

### FIXME: False if using multilibbed RTEMS
LINK_LIBS_RTEMS = $(PROJECT_RELEASE)/lib/librtemsall$(LIBSUFFIX_VA)

LINK_LIBS_GCC272 = $(LINK_LIBS_RTEMS) $(LIBC_LIBC) $(LIBC_LIBGCC)
else
## gcc >= 2.8.x
if RTEMS_CONFIG_PER_BSP
BSP_SPECS = -specs bsp_specs -qrtems
endif

GCCSPECS = -B$(PROJECT_RELEASE)/lib/ $(BSP_SPECS)
endif
else
## fall back to the old style compilers/*.cfg
## CONFIG.CC is supposed to be provided by <BSP>.cfg
include $(CONFIG.CC)
endif # RTEMS_USE_GCC

DEFS = @DEFS@

CPPFLAGS += $(CPU_DEFINES) $(CPU_CFLAGS) \
   $(DEFINES) $(XCPPFLAGS) $(CPPFLAGS_GCC)
CFLAGS   = $(CFLAGS_DEFAULT) $(XCFLAGS)
CXXFLAGS = $(CFLAGS_DEFAULT) $(XCXXFLAGS)
ASFLAGS  = $(CPU_ASFLAGS) $(XASFLAGS)

LINK_LIBS = $(LINK_LIBS_GCC272) $(LD_LIBS)

## FIXME: This doesn't seem to be correct
# when debugging, optimize flag: typically empty
# some compilers do allow optimization with their "-g"
CFLAGS_DEBUG_OPTIMIZE_V=-g
CXXFLAGS_DEBUG_OPTIMIZE_V=-g
LDFLAGS_DEBUG_V =

# profile flag; use gprof(1)
CFLAGS_PROFILE_V=-pg
CXXFLAGS_PROFILE_V=-pg
LDFLAGS_PROFILE_V =

# List of library paths without -L
LD_PATHS= $(PROJECT_RELEASE)/lib

# ld flag for incomplete link
LDFLAGS_INCOMPLETE = -r

# ld flags for profiling, debugging
LDFLAGS=$(LDFLAGS_PROFILE) $(LDFLAGS_DEBUG) $(LD_PATHS:%=-L %)

#
# Client compiler and support tools
#

## HACK: specific to gcc
## FIXME: Do we call the correct CPP, why aren't
## CPPFLAGS and CFLAGS part of this call?
# CPP command to write file to standard output
CPP=$(CC) -E -ansi -w -Wp,-$$

ARFLAGS=ruv

#
# How to compile stuff into ${ARCH} subdirectory
#

${ARCH}/%.o: %.c
	${COMPILE.c} $(AM_CPPFLAGS) $(AM_CFLAGS) -o $@ $<

${ARCH}/%.o: %.cc
	${COMPILE.cc} $(AM_CPPFLAGS) $(AM_CXXFLAGS) -o $@ $<

${ARCH}/%.o: %.cpp
	${COMPILE.cc} $(AM_CPPFLAGS) $(AM_CXXFLAGS) -o $@ $<

${ARCH}/%.o: %.cxx
	${COMPILE.cc} $(AM_CPPFLAGS) $(AM_CXXFLAGS) -o $@ $<

${ARCH}/%.o: %.C
	${COMPILE.cc} $(AM_CPPFLAGS) $(AM_CXXFLAGS) -o $@ $<

${ARCH}/%.o: %.S
	${COMPILE.S} $(AM_CPPFLAGS) -DASM -o $@ $<

# Make foo.rel from foo.o
${ARCH}/%.rel: ${ARCH}/%.o
	${make-rel}

# create $(ARCH)/pgm from pgm.sh
${ARCH}/%: %.sh
	$(RM) $@
	$(CP) $< $@
	$(CHMOD) +x $@

# Dependency files for use by gmake
# NOTE: we don't put them into $(ARCH)
#       so that 'make clean' doesn't blow it away

DEPEND=Depends-${ARCH}

CLEAN_DEPEND=$(DEPEND).tmp
CLOBBER_DEPEND=$(DEPEND)

# We deliberately don't have anything depend on the
# $(DEPEND) file; otherwise it will get rebuilt even
# on 'make clean'
#

## HACK: Specific to gcc
## FIXME: The approach below is known to be conceptionally broken.
depend-am: $(C_FILES) $(CC_FILES) $(S_FILES)
##       Use gcc -M to generate dependencies
##       Replace foo.o with $(ARCH)/foo.o
##       Replace $(ARCH) value with string $(ARCH)
##           so that it will for debug and profile cases
	$(COMPILE.c) $(AM_CPPFLAGS) $(AM_CFLAGS) -M   $^    |  \
	sed -e 's?^\(.*\)\.o[ ]*:?$$(ARCH)/\1.o:?' \
	    -e 's?$(ARCH)/?$$(ARCH)/?'   >$(DEPEND).tmp
	mv $(DEPEND).tmp $(DEPEND)
depend: depend-am

# pull in dependencies if they exist  
ifeq (${DEPEND},$(wildcard ${DEPEND}))
include ${DEPEND}
@ENDIF@


# spell out all the LINK_FILE's, rather than using -lbsp, so
#  that $(LINK_FILES) can be a dependency

LINK_OBJS = \
    $(OBJS) \
    $(MANAGERS_NOT_WANTED:%=$(PROJECT_RELEASE)/lib/no-%$(LIB_VARIANT).rel)

LINK_FILES =\
    $(START_FILE) \
    $(OBJS) \
    $(MANAGERS_NOT_WANTED:%=$(PROJECT_RELEASE)/lib/no-%$(LIB_VARIANT).rel) \
    $(PROJECT_RELEASE)/lib/librtemsall$(LIBSUFFIX_VA)

if RTEMS_USE_GCC
if RTEMS_USE_GCC272
define make-rel
	$(LD) $(LDFLAGS_INCOMPLETE) $(XLDFLAGS) -o $@ $^
endef
else
## gcc >= 2.8
define make-rel
	$(LINK.c) $(AM_CFLAGS) $(AM_LDFLAGS) \
	  -qnolinkcmds -nostdlib -Wl,-r $(XLDFLAGS) -o $@ $^
endef
endif
else
## non-gcc
define make-rel
	$(LINK.c) $(AM_CFLAGS) $(AM_LDFLAGS) \
	  $(XLDFLAGS) -o $@ $^
endef
endif

## -------------------------------------------------------------------------

## translate VARIANT into VARIANT_V
VARIANT = OPTIMIZE

VARIANT_OPTIMIZE_V = OPTIMIZE
VARIANT_DEBUG_V = DEBUG
VARIANT_PROFILE_V = PROFILE
VARIANT_optimize_V = OPTIMIZE
VARIANT_debug_V = DEBUG
VARIANT_profile_V = PROFILE

VARIANT_V = $(VARIANT_$(VARIANT)_V)

## Setup the variant build subdirectory
ARCH_OPTIMIZE_V = o-optimize
ARCH_DEBUG_V = o-debug
ARCH_PROFILE_V = o-profile

ARCH__V = $(ARCH_OPTIMIZE_V)
ARCH = $(ARCH_$(VARIANT_V)_V)

## Setup the library suffix
LIBSUFFIX_OPTIMIZE_V =
LIBSUFFIX_DEBUG_V = _g
LIBSUFFIX_PROFILE_V = _p
LIBSUFFIX__V = $(LIBSUFFIX_OPTIMIZE_V)

LIB_VARIANT = $(LIBSUFFIX_$(VARIANT_V)_V)
LIBSUFFIX_VA = $(LIB_VARIANT).a

## These are supposed to be set in make/custom/<bsp>.cfg
## CFLAGS_OPTIMIZE_V = 
## CFLAGS_DEBUG_V =
## CFLAGS_PROFILE_V =
CFLAGS__V = $(CFLAGS_OPTIMIZE_V)

## ------------------------------------------------------------------------
## Setup hard-coded flags
if RTEMS_USE_GCC
if RTEMS_USE_GCC272
## gcc < gcc-2.8
RTEMS_CFLAGS_OPTIMIZE_V =
RTEMS_CFLAGS_DEBUG_V = -Wno-unused
RTEMS_CFLAGS_PROFILE_V =
else
## gcc >= gcc-2.8
RTEMS_CFLAGS_OPTIMIZE_V =
RTEMS_CFLAGS_DEBUG_V = -qrtems_debug -Wno-unused
RTEMS_CFLAGS_PROFILE_V =
endif
## non-gcc
## We can't guess what flags might be required here.
## Pass the values from the environment if you want to apply them.
endif
RTEMS_CFLAGS__V = $(RTEMS_CFLAGS_OPTIMIZE_V)

## -------------------------------------------------------------------------

CC = @CC@ $(GCCSPECS)
CXX = @CXX@ $(GCCSPECS)
LD = @LD@
OBJCOPY = @OBJCOPY@
NM = @NM@
SIZE = @SIZE@
STRIP = @STRIP@

##
## FIXME: DEFS and INCLUDES should not be passed as AM_CPPFLAGS
AM_CPPFLAGS += $(DEFS) $(INCLUDES) $(RTEMS_CPPFLAGS)

AM_CFLAGS += $(RTEMS_CFLAGS_$(VARIANT_V)_V) $(CFLAGS_$(VARIANT_V)_V)
AM_CXXFLAGS += $(RTEMS_CFLAGS_$(VARIANT_V)_V) $(CFLAGS_$(VARIANT_V)_V)