-
Notifications
You must be signed in to change notification settings - Fork 5
/
Makefile.tc.in
425 lines (351 loc) · 15.5 KB
/
Makefile.tc.in
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
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
#
# Toolchain sub-Makefile
#
# Copyright (C) 2020-2024 Gabriele Galeotti
#
# This work is licensed under the terms of the MIT License.
# Please consult the LICENSE.txt file located in the top-level directory.
#
#
# Environment variables:
# OSTYPE
# PATH
# EXEEXT
# SCREXT
# VERBOSE
# PLATFORM_GOALS
# MAKECMDGOALS
# INFOCONFIG_GOALS
# SWEETADA_PATH
# TOOLCHAIN_PREFIX
# TOOLCHAIN_NAME
# RTS_DIRECTORY
# RTS_BASE_PATH
# RTS
# ADA_MODE
# STACK_LIMIT
# BUILD_MODE
# OPTIMIZATION_LEVEL
# OBJECT_DIRECTORY
# KERNEL_BASENAME
# GNATADC_FILENAME
# GCC_WRAPPER
# GNAT_WRAPPER
# ENABLE_SPLIT_DWARF
# CONFIGURE_DEPS
#
################################################################################
# #
# Toolchain initialization. #
# #
################################################################################
ifneq ($(TOOLCHAIN_NAME),)
TOOLCHAIN_PROGRAM_PREFIX := $(TOOLCHAIN_NAME)-
endif
# raw compiler executable used for 1) retrieve informations, and 2) back-end
# in the GNATMAKE wrapper
# NOTE: this is not the same as TOOLCHAIN_CC, which is possibly used to
# compile C source files
TOOLCHAIN_GCC := $(TOOLCHAIN_PROGRAM_PREFIX)gcc$(EXEEXT)
# detect GCC compiler
ifeq ($(OSTYPE),cmd)
GCC_VERSION := $(shell SET "PATH=$(PATH)" && $(TOOLCHAIN_GCC) -dumpversion 2>nul)
else
GCC_VERSION := $(shell PATH="$(PATH)" $(TOOLCHAIN_GCC) -dumpversion 2> /dev/null)
endif
ifneq ($(filter rts $(PLATFORM_GOALS),$(MAKECMDGOALS)),)
ifeq ($(GCC_VERSION),)
# no valid toolchain found, output a warning message
$(warning *** Warning: no valid toolchain.)
endif
endif
# these must be computed after configuration variables are set; different
# options could lead to different multilib library directories
# GCC_MULTIDIR is the multilib directory inside the library search directory
# NOTE: this is different from "-print-multi-lib", which prints all multilibs
ifeq ($(OSTYPE),cmd)
GCC_MULTILIBS := $(shell SET "PATH=$(PATH)" && $(TOOLCHAIN_GCC) -print-multi-lib 2>nul)
GCC_MULTIDIR := $(shell SET "PATH=$(PATH)" && $(TOOLCHAIN_GCC) $(GCC_SWITCHES_PLATFORM) -print-multi-directory 2>nul)
LIBGCC_FILENAME := $(shell SET "PATH=$(PATH)" && $(TOOLCHAIN_GCC) $(GCC_SWITCHES_PLATFORM) -print-libgcc-file-name 2>nul)
else
GCC_MULTILIBS := $(shell PATH="$(PATH)" $(TOOLCHAIN_GCC) -print-multi-lib 2> /dev/null)
GCC_MULTIDIR := $(shell PATH="$(PATH)" $(TOOLCHAIN_GCC) $(GCC_SWITCHES_PLATFORM) -print-multi-directory 2> /dev/null)
LIBGCC_FILENAME := $(shell PATH="$(PATH)" $(TOOLCHAIN_GCC) $(GCC_SWITCHES_PLATFORM) -print-libgcc-file-name 2> /dev/null)
endif
# libm
LIBM_FILENAME := $(TOOLCHAIN_PREFIX)/$(TOOLCHAIN_NAME)/lib/$(GCC_MULTIDIR)/libm.a
# RTS
RTS_ROOT_PATH := $(RTS_BASE_PATH)/$(RTS)/$(TOOLCHAIN_NAME)
RTS_PATH := $(RTS_ROOT_PATH)/$(GCC_MULTIDIR)
ifeq ($(OSTYPE),cmd)
RTS_INSTALLED := $(shell \
SETLOCAL ENABLEDELAYEDEXPANSION && \
SET "RTS_PATH=$(RTS_PATH)" && \
SET "RTS_PATH_CMD=!RTS_PATH:/=\!" && \
IF EXIST "!RTS_PATH_CMD!"\adainclude\system.ads \
(ECHO Y) ELSE (ECHO N) \
)
else
RTS_INSTALLED := $(shell \
if [ -e "$(RTS_PATH)"/adainclude/system.ads ] ; then \
printf "%s\n" "Y" ; \
else \
printf "%s\n" "N" ; \
fi \
)
endif
################################################################################
# #
# Define toolchain components. #
# #
################################################################################
# basic toolchain executables
TOOLCHAIN_AS := $(TOOLCHAIN_PROGRAM_PREFIX)as$(EXEEXT)
TOOLCHAIN_ADAC := $(TOOLCHAIN_PROGRAM_PREFIX)gcc$(EXEEXT)
TOOLCHAIN_CC := $(TOOLCHAIN_PROGRAM_PREFIX)gcc$(EXEEXT)
TOOLCHAIN_CPP := $(TOOLCHAIN_PROGRAM_PREFIX)cpp$(EXEEXT)
TOOLCHAIN_GNATCHOP := $(TOOLCHAIN_PROGRAM_PREFIX)gnatchop$(EXEEXT)
TOOLCHAIN_GNATBIND := $(TOOLCHAIN_PROGRAM_PREFIX)gnatbind$(EXEEXT)
TOOLCHAIN_GNATLINK := $(TOOLCHAIN_PROGRAM_PREFIX)gnatlink$(EXEEXT)
TOOLCHAIN_GNATLS := $(TOOLCHAIN_PROGRAM_PREFIX)gnatls$(EXEEXT)
TOOLCHAIN_GNATPREP := $(TOOLCHAIN_PROGRAM_PREFIX)gnatprep$(EXEEXT)
TOOLCHAIN_GNATXREF := $(TOOLCHAIN_PROGRAM_PREFIX)gnatxref$(EXEEXT)
TOOLCHAIN_AR := $(TOOLCHAIN_PROGRAM_PREFIX)ar$(EXEEXT)
TOOLCHAIN_GDB := $(TOOLCHAIN_PROGRAM_PREFIX)gdb$(EXEEXT)
TOOLCHAIN_LD := $(TOOLCHAIN_PROGRAM_PREFIX)ld$(EXEEXT)
TOOLCHAIN_NM := $(TOOLCHAIN_PROGRAM_PREFIX)nm$(EXEEXT)
TOOLCHAIN_OBJCOPY := $(TOOLCHAIN_PROGRAM_PREFIX)objcopy$(EXEEXT)
TOOLCHAIN_OBJDUMP := $(TOOLCHAIN_PROGRAM_PREFIX)objdump$(EXEEXT)
TOOLCHAIN_RANLIB := $(TOOLCHAIN_PROGRAM_PREFIX)ranlib$(EXEEXT)
TOOLCHAIN_READELF := $(TOOLCHAIN_PROGRAM_PREFIX)readelf$(EXEEXT)
TOOLCHAIN_SIZE := $(TOOLCHAIN_PROGRAM_PREFIX)size$(EXEEXT)
TOOLCHAIN_STRIP := $(TOOLCHAIN_PROGRAM_PREFIX)strip$(EXEEXT)
ifneq ($(filter $(INFOCONFIG_GOALS),$(MAKECMDGOALS)),)
ifeq ($(OSTYPE),cmd)
AS_VERSION := $(shell SET "PATH=$(PATH)" && $(TOOLCHAIN_AS) --version 2>nul| $(SED) -e "2,$$d")
LD_VERSION := $(shell SET "PATH=$(PATH)" && $(TOOLCHAIN_LD) --version 2>nul| $(SED) -e "2,$$d")
else
AS_VERSION := $(shell PATH="$(PATH)" $(TOOLCHAIN_AS) --version 2> /dev/null | $(SED) -e "2,\$$d")
LD_VERSION := $(shell PATH="$(PATH)" $(TOOLCHAIN_LD) --version 2> /dev/null | $(SED) -e "2,\$$d")
endif
endif
# nature of compilers
TOOLCHAIN_ADAC += -x ada
# C compiler has no system libraries
TOOLCHAIN_CC += -ffreestanding
ifeq ($(ADA_MODE),ADA95)
TOOLCHAIN_ADAC += -gnat95
else ifeq ($(ADA_MODE),ADA05)
TOOLCHAIN_ADAC += -gnat2005
else ifeq ($(ADA_MODE),ADA12)
TOOLCHAIN_ADAC += -gnat2012
else ifeq ($(ADA_MODE),ADA22)
TOOLCHAIN_ADAC += -gnat2022
else
$(warning *** Warning: no valid ADA_MODE.)
endif
################################################################################
# #
# Basic toolchain commands and default switches. #
# #
################################################################################
AS := $(TOOLCHAIN_AS)
ADAC := $(TOOLCHAIN_ADAC)
CC := $(TOOLCHAIN_CC)
CPP := $(TOOLCHAIN_CPP)
GNATBIND := $(TOOLCHAIN_GNATBIND)
GNATCHOP := $(TOOLCHAIN_GNATCHOP)
GNATLINK := $(TOOLCHAIN_GNATLINK)
GNATLS := $(TOOLCHAIN_GNATLS)
GNATPREP := $(TOOLCHAIN_GNATPREP)
GNATXREF := $(TOOLCHAIN_GNATXREF)
AR := $(TOOLCHAIN_AR)
GDB := $(TOOLCHAIN_GDB)
LD := $(TOOLCHAIN_LD)
NM := $(TOOLCHAIN_NM)
OBJCOPY := $(TOOLCHAIN_OBJCOPY)
OBJDUMP := $(TOOLCHAIN_OBJDUMP)
RANLIB := $(TOOLCHAIN_RANLIB)
READELF := $(TOOLCHAIN_READELF)
SIZE := $(TOOLCHAIN_SIZE)
STRIP := $(TOOLCHAIN_STRIP)
# add RTS and import switches
ADAC += --RTS="$(RTS_PATH)"
GNATLS += --RTS="$(RTS_PATH)"
GNATBIND += --RTS="$(RTS_PATH)"
-include $(RTS_DIRECTORY)/$(RTS)/$(TOOLCHAIN_NAME)/rts.cs.in
export ADAC_SWITCHES_RTS
export CC_SWITCHES_RTS
# AS
AS_SWITCHES_DEFAULT +=
# ADAC
ADAC_SWITCHES_DEFAULT += $(ADAC_SWITCHES_RTS)
# CC
CC_SWITCHES_DEFAULT += $(CC_SWITCHES_RTS)
# CPP
CPP_SWITCHES_DEFAULT +=
# GNATBIND
GNATBIND_SWITCHES_DEFAULT += -nostdinc -nostdlib
# GNATCHOP
GNATCHOP_SWITCHES_DEFAULT +=
# GNATLINK
GNATLINK_SWITCHES_DEFAULT +=
# GNATLS
GNATLS_SWITCHES_DEFAULT +=
# GNATPREP
# retain all lines in the output source
GNATPREP_SWITCHES_DEFAULT += -c
# GNATXREF
GNATXREF_SWITCHES_DEFAULT +=
# AR
AR_SWITCHES_DEFAULT +=
# LD
LD_SWITCHES_DEFAULT += -Map $(KERNEL_BASENAME).map
LD_SWITCHES_DEFAULT += --cref
LD_SWITCHES_DEFAULT += --warn-common
LD_SWITCHES_DEFAULT += --warn-section-align
#LD_SWITCHES_DEFAULT += --no-warn-rwx-segments
LD_SWITCHES_DEFAULT += --print-memory-usage
LD_SWITCHES_DEFAULT += --gc-sections
LD_SWITCHES_DEFAULT += -g
# NM
NM_SWITCHES_DEFAULT +=
# OBJCOPY
OBJCOPY_SWITCHES_DEFAULT +=
# OBJDUMP
OBJDUMP_SWITCHES_DEFAULT += --demangle=gnat
# RANLIB
RANLIB_SWITCHES_DEFAULT +=
# READELF
# Allow output width to exceed 80 characters
READELF_SWITCHES_DEFAULT += --wide
# display the section details
#READELF_SWITCHES_DEFAULT += -t
# Equivalent to: -h -l -S -s -r -d -V -A -I
READELF_SWITCHES_DEFAULT += --all
# SIZE
SIZE_SWITCHES_DEFAULT += --format=sysv
SIZE_SWITCHES_DEFAULT += --radix=16
# STRIP
STRIP_SWITCHES_DEFAULT +=
################################################################################
# #
# GNATMAKE mode: import all settings. #
# GPRbuild mode: only define the executable to build the system. #
# #
################################################################################
ifeq ($(BUILD_MODE),GNATMAKE)
include gnatmake.tc.in
CONFIGURE_DEPS += gnatmake.tc.in
ifneq ($(filter $(INFOCONFIG_GOALS),$(MAKECMDGOALS)),)
ifeq ($(OSTYPE),cmd)
GNATMAKE_VERSION := $(shell SET "PATH=$(PATH)" && $(TOOLCHAIN_GNATMAKE) --version 2>nul| $(SED) -e "2,$$d")
else
GNATMAKE_VERSION := $(shell PATH="$(PATH)" $(TOOLCHAIN_GNATMAKE) --version 2> /dev/null | $(SED) -e "2,\$$d")
endif
endif
else ifeq ($(BUILD_MODE),GPRbuild)
GPRBUILD := gprbuild$(EXEEXT)
ifneq ($(filter $(INFOCONFIG_GOALS),$(MAKECMDGOALS)),)
ifeq ($(OSTYPE),cmd)
GPRBUILD_VERSION := $(shell SET "PATH=$(PATH)" && $(GPRBUILD) --version 2>nul| $(SED) -e "2,$$d")
else
GPRBUILD_VERSION := $(shell PATH="$(PATH)" $(GPRBUILD) --version 2> /dev/null | $(SED) -e "2,\$$d")
endif
endif
endif
################################################################################
# #
# Synthesize toolchain command lines with theirs own options/switches. #
# #
################################################################################
ADAC += $(ADAC_SWITCHES_DEFAULT) $(GCC_SWITCHES_PLATFORM)
AR += $(AR_SWITCHES_DEFAULT)
AS += $(AS_SWITCHES_DEFAULT) $(AS_SWITCHES_PLATFORM)
CC += $(CC_SWITCHES_DEFAULT) $(GCC_SWITCHES_PLATFORM)
CPP += $(CPP_SWITCHES_DEFAULT) $(GCC_SWITCHES_PLATFORM)
GNATBIND += $(GNATBIND_SWITCHES_DEFAULT)
GNATCHOP += $(GNATCHOP_SWITCHES_DEFAULT)
GNATLINK += $(GNATLINK_SWITCHES_DEFAULT)
GNATLS += $(GNATLS_SWITCHES_DEFAULT)
ifeq ($(BUILD_MODE),GNATMAKE)
GNATMAKE += $(ADAC_SWITCHES_DEFAULT)
GNATMAKE += $(GNATMAKE_SWITCHES_DEFAULT) $(GCC_SWITCHES_PLATFORM)
endif
GNATPREP += $(GNATPREP_SWITCHES_DEFAULT)
GNATXREF += $(GNATXREF_SWITCHES_DEFAULT)
LD += $(LD_SWITCHES_DEFAULT) $(LD_SWITCHES_PLATFORM)
NM += $(NM_SWITCHES_DEFAULT)
OBJCOPY += $(OBJCOPY_SWITCHES_DEFAULT) $(OBJCOPY_SWITCHES_PLATFORM)
OBJDUMP += $(OBJDUMP_SWITCHES_DEFAULT) $(OBJDUMP_SWITCHES_PLATFORM)
RANLIB += $(RANLIB_SWITCHES_DEFAULT)
READELF += $(READELF_SWITCHES_DEFAULT)
SIZE += $(SIZE_SWITCHES_DEFAULT)
STRIP += $(STRIP_SWITCHES_DEFAULT)
################################################################################
# #
# GCC-wrapper. #
# Required for output of assembler listings, expanded Ada code and Makefile #
# timestamps to trigger Ada binding. #
# #
################################################################################
# enable verbose assembler output in GCC wrapper (should begin with "-a")
GCC_WRAPPER_ASSEMBLER_OUTPUT := -adghlmns
export GCC_WRAPPER_ASSEMBLER_OUTPUT
################################################################################
# #
# GNAT-wrapper. #
# Required for "brief-mode" echoed commands and Makefile timestamps to trigger #
# Ada binding. #
# #
################################################################################
# brief command name label (see brief-command function in Makefile.fn.in)
GNAT_WRAPPER_GCC_BRIEFTEXT := $(call substring,[GCC-WRAP]$(BRIEFTEXT_SPACES),1,$(BRIEFTEXT_NSPACE)) (+)
export GNAT_WRAPPER_GCC_BRIEFTEXT
# VERBOSE for GNAT-wrapper
GNAT_WRAPPER_VERBOSE := $(VERBOSE)
export GNAT_WRAPPER_VERBOSE
# GNAT-wrapper is not toolchain-specific, it needs to know the GCC executable
GNAT_WRAPPER_GCC_EXECUTABLE := $(TOOLCHAIN_PREFIX)/bin/$(TOOLCHAIN_GCC)
export GNAT_WRAPPER_GCC_EXECUTABLE
################################################################################
# #
# Filenames to check for compile or bind phase triggering (generated by the #
# GCC- or GNAT-wrapper). They end up nearly the same, but the object directory #
# is not implicitly prefixed when processing files in MAKEFILE/GNATMAKE mode. #
# #
################################################################################
ifeq ($(BUILD_MODE),GNATMAKE)
GCC_WRAPPER_TIMESTAMP_FILENAME :=
GNAT_WRAPPER_TIMESTAMP_FILENAME := $(OBJECT_DIRECTORY)/gnatmake.tmp
GCC_GNAT_WRAPPER_TIMESTAMP_FILENAME := $(GNAT_WRAPPER_TIMESTAMP_FILENAME)
else ifeq ($(BUILD_MODE),GPRbuild)
GCC_WRAPPER_TIMESTAMP_FILENAME := gccmake.tmp
GNAT_WRAPPER_TIMESTAMP_FILENAME :=
GCC_GNAT_WRAPPER_TIMESTAMP_FILENAME := $(OBJECT_DIRECTORY)/$(GCC_WRAPPER_TIMESTAMP_FILENAME)
endif
export GCC_WRAPPER_TIMESTAMP_FILENAME
export GNAT_WRAPPER_TIMESTAMP_FILENAME
ADAC += -wrapper $(GCC_WRAPPER)
CC += -wrapper $(GCC_WRAPPER)
ifeq ($(BUILD_MODE),GNATMAKE)
GNATMAKE += --GCC=$(GNAT_WRAPPER) -cargs -wrapper $(GCC_WRAPPER) -margs
endif
################################################################################
# #
# Final toolchain setup. #
# #
################################################################################
# beautify compiler command lines
ADAC := $(filter-out ,$(ADAC))
CC := $(filter-out ,$(CC))
ifeq ($(BUILD_MODE),GNATMAKE)
GNATMAKE := $(filter-out ,$(GNATMAKE))
endif
# special back-end compiler for GNATBIND-generated Ada files without output of
# spurious warnings
ADAC_GNATBIND := $(filter-out $(ADAC_SWITCHES_STYLE),$(ADAC))
# avoid extraneous informations in .d files during VERBOSE mode
ifeq ($(BUILD_MODE),GNATMAKE)
GNATMAKE_DEPEND := $(filter-out -v,$(GNATMAKE))
endif