-
Notifications
You must be signed in to change notification settings - Fork 5
/
Makefile
1610 lines (1451 loc) · 50.4 KB
/
Makefile
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
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#
# Master 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.
#
#
# Arguments:
# make arguments
#
# Environment variables:
# OS
# MSYSTEM
# TEMP
# VERBOSE
# PLATFORM
# SUBPLATFORM
# RTS
# NOBUILD
# PROBEVARIABLE
#
################################################################################
# #
# Setup initialization. #
# #
################################################################################
.POSIX:
.NOTPARALLEL:
.DEFAULT_GOAL := help
MAKEFILE_MASTER_INCLUDED := Y
NULL :=
SPACE := $(NULL) $(NULL)
TAB := $(NULL) $(NULL)
export NULL SPACE TAB
KERNEL_BASENAME := kernel
# verbose output, "Y/y/1" = enabled
VERBOSE ?=
override VERBOSE := $(subst y,Y,$(subst 1,y,$(VERBOSE)))
export VERBOSE
################################################################################
# #
# Main setup. #
# #
################################################################################
# detect OS type
# detected OS names: "cmd"/"msys"/"darwin"/"linux"
ifeq ($(OS),Windows_NT)
ifneq ($(MSYSTEM),)
OSTYPE := msys
else
OSTYPE := cmd
endif
else
OSTYPE_UNAME := $(shell uname -s 2> /dev/null)
ifeq ($(OSTYPE_UNAME),Darwin)
OSTYPE := darwin
else ifeq ($(OSTYPE_UNAME),Linux)
OSTYPE := linux
else
$(error Error: no valid OSTYPE)
endif
endif
export OSTYPE
# workarounds for some environments
ifeq ($(OSTYPE),cmd)
SHELL := cmd.exe
endif
# executable and script extensions
SCREXT_cmd := .bat
SCREXT_unx := .sh
ifeq ($(OSTYPE),cmd)
EXEEXT := .exe
SCREXT := $(SCREXT_cmd)
SHELL_EXEC := $(SHELL) /C
else
ifeq ($(OSTYPE),msys)
EXEEXT := .exe
else
EXEEXT :=
endif
SCREXT := $(SCREXT_unx)
SHELL_EXEC := $(SHELL)
endif
export EXEEXT SCREXT_cmd SCREXT_unx SCREXT SHELL_EXEC
# define a minimum set of variables that are required for functions and
# various utilities
ifeq ($(OSTYPE),cmd)
ECHO := ECHO
REM := REM
else
ECHO := printf "%s\n"
REM := \#
endif
SED := sed$(EXEEXT)
export ECHO REM SED
# TMPDIR handling
ifeq ($(OSTYPE),cmd)
TMPDIR := $(TEMP)
else ifeq ($(OSTYPE),msys)
TMPDIR := $(TEMP)
else
TMPDIR ?= /tmp
endif
export TMPDIR
################################################################################
# #
# Partitioning of Makefile goals. #
# #
################################################################################
#
# List of recognized goals:
#
# libutils-elftool L S NP
# libutils-gcc-wrapper L S NP
# libutils-gnat-wrapper L S NP
# infodump I NP
# probevariable I NP
# clean C NP
# distclean C NP
# createkernelcfg S NP
# freeze S NP
# help S NP
# rts R NP
# configure P
# $(KERNEL_BASENAME) P
# all P
# kernel_info P
# kernel_libinfo P
# postbuild P
# session-start P
# session-end P
# run P
# debug P
#
# libutils goals
LIBUTILS_GOALS := libutils-elftool \
libutils-gcc-wrapper \
libutils-gnat-wrapper
# info goals
INFO_GOALS := infodump \
probevariable
# clean/distclean goals
CLEANING_GOALS := clean \
distclean
# general service goals
SERVICE_GOALS := createkernelcfg \
freeze \
help \
$(LIBUTILS_GOALS)
# not-platform-related goals
NOT_PLATFORM_GOALS := $(SERVICE_GOALS) \
$(INFO_GOALS) \
$(CLEANING_GOALS) \
rts
# platform-related goals
PLATFORM_GOALS := configure \
$(KERNEL_BASENAME) \
all \
kernel_info \
kernel_libinfo \
postbuild \
session-start \
session-end \
run \
debug
# all goals
ALL_GOALS := $(NOT_PLATFORM_GOALS) \
$(PLATFORM_GOALS)
# special set of goals for detection of all informations
INFOCONFIG_GOALS := $(INFO_GOALS) \
configure
# check Makefile target
NOT_MAKEFILE_GOALS := $(filter-out $(ALL_GOALS),$(MAKECMDGOALS))
ifneq ($(NOT_MAKEFILE_GOALS),)
$(error Error: $(NOT_MAKEFILE_GOALS): no known Makefile target, try "make help")
endif
################################################################################
# #
# Setup directories and utilities. #
# #
################################################################################
# generate SWEETADA_PATH
MAKEFILEDIR := $(abspath $(dir $(lastword $(MAKEFILE_LIST))))
SWEETADA_PATH ?= $(MAKEFILEDIR)
export SWEETADA_PATH
# include the utilities
LIBUTILS_DIRECTORY := libutils
export LIBUTILS_DIRECTORY
# add LIBUTILS_DIRECTORY to PATH
ifeq ($(OSTYPE),cmd)
PATH := $(SWEETADA_PATH)\$(LIBUTILS_DIRECTORY);$(PATH)
else ifeq ($(OSTYPE),msys)
PATH := $(PATH):$(SWEETADA_PATH)/$(LIBUTILS_DIRECTORY)
else
PATH := $(SWEETADA_PATH)/$(LIBUTILS_DIRECTORY):$(PATH)
endif
export PATH
# detect Make version
ifneq ($(filter $(INFOCONFIG_GOALS),$(MAKECMDGOALS)),)
ifeq ($(OSTYPE),cmd)
MAKE_VERSION := $(shell SET "PATH=$(PATH)" && "$(MAKE)" --version 2>nul| $(SED) -e "2,$$d")
else
MAKE_VERSION := $(shell PATH="$(PATH)" "$(MAKE)" --version 2> /dev/null | $(SED) -e "2,\$$d")
endif
endif
# define every other OS command
ifeq ($(OSTYPE),cmd)
CHDIR := CD
CP := COPY /B /Y 1>nul
LS := DIR /B
MKDIR := MKDIR
MV := MOVE /Y 1>nul
RM := DEL /F /Q 2>nul
RMDIR := RMDIR /Q /S 2>nul
else
# POSIX
CHDIR := cd
CP := cp -f
LS := ls -A
MKDIR := mkdir -p
MV := mv -f
RM := rm -f
RMDIR := $(RM) -r
endif
ifeq ($(OSTYPE),msys)
CP += --preserve=all
endif
ifeq ($(VERBOSE),Y)
ifeq ($(OSTYPE),cmd)
# no verbosity
else
CP += -v
MV += -v
RM += -v
endif
else
ifeq ($(filter $(MAKECMDGOALS),$(LIBUTILS_GOALS)),)
MAKEFLAGS += s
endif
GNUMAKEFLAGS += --no-print-directory
endif
export CHDIR CP LS MKDIR MV RM RMDIR
# include build system utilities
include Makefile.ut.in
# load complex functions
include Makefile.fn.in
################################################################################
# #
# Setup finalization. #
# #
################################################################################
# check for RTS build
ifeq ($(MAKECMDGOALS),rts)
# before loading configuration.in (which defines the RTS type used by the
# platform), save the RTS variable from the environment in order to correctly
# build the RTS specified when issuing the "rts" target
RTS_BUILD := $(RTS)
endif
# default system parameters
TOOLCHAIN_PREFIX :=
GPRBUILD_PREFIX :=
BUILD_MODE := GNATMAKE
RTS :=
PROFILE :=
ADA_MODE := ADA22
USE_LIBGCC :=
USE_LIBM :=
USE_LIBADA :=
USE_CLIBRARY :=
USE_APPLICATION := dummy
OPTIMIZATION_LEVEL :=
STACK_LIMIT := 4096
POSTBUILD_ROMFILE :=
IMPLICIT_ALI_UNITS :=
EXTERNAL_OBJECTS :=
# initialize configuration dependencies
CONFIGURE_DEPS := Makefile.fn.in Makefile.lb.in Makefile.tc.in Makefile.ut.in
GPRBUILD_DEPS :=
CONFIGURE_FILES_PLATFORM :=
# read the master configuration file
include configuration.in
CONFIGURE_DEPS += configuration.in
ifneq ($(filter rts $(PLATFORM_GOALS),$(MAKECMDGOALS)),)
ifeq ($(TOOLCHAIN_PREFIX),)
$(error Error: no valid TOOLCHAIN_PREFIX)
endif
endif
# add TOOLCHAIN_PREFIX to PATH
ifneq ($(TOOLCHAIN_PREFIX),)
ifeq ($(OSTYPE),cmd)
PATH := $(TOOLCHAIN_PREFIX)\bin;$(PATH)
else ifeq ($(OSTYPE),msys)
TOOLCHAIN_PREFIX_MSYS := $(shell cygpath.exe -u "$(TOOLCHAIN_PREFIX)" 2> /dev/null)
PATH := $(TOOLCHAIN_PREFIX_MSYS)/bin:$(PATH)
else
PATH := $(TOOLCHAIN_PREFIX)/bin:$(PATH)
endif
endif
# add GPRBUILD_PREFIX to PATH
ifeq ($(BUILD_MODE),GPRbuild)
ifneq ($(GPRBUILD_PREFIX),)
ifeq ($(OSTYPE),cmd)
PATH := $(GPRBUILD_PREFIX)\bin;$(PATH)
else ifeq ($(OSTYPE),msys)
GPRBUILD_PREFIX_MSYS := $(shell cygpath.exe -u "$(GPRBUILD_PREFIX)" 2> /dev/null)
PATH := $(GPRBUILD_PREFIX_MSYS)/bin:$(PATH)
else
PATH := $(GPRBUILD_PREFIX)/bin:$(PATH)
endif
endif
endif
# export PATH so that we can use everything
export PATH
# check basic utilities
ifeq ($(TOOLS_CHECK),Y)
-include Makefile.ck.in
endif
################################################################################
# #
# Physical geometry of the build system. #
# #
################################################################################
# hierarchies
PLATFORM_BASE_DIRECTORY := platforms
CPU_BASE_DIRECTORY := cpus
APPLICATION_DIRECTORY := application
CLIBRARY_DIRECTORY := clibrary
CORE_DIRECTORY := core
DRIVERS_DIRECTORY := drivers
MODULES_DIRECTORY := modules
LIBRARY_DIRECTORY := lib
OBJECT_DIRECTORY := obj
RTS_DIRECTORY := rts
SHARE_DIRECTORY := share
# PLATFORMS and CPUs
ifeq ($(OSTYPE),cmd)
PLATFORMS := $(shell $(CHDIR) $(PLATFORM_BASE_DIRECTORY) && $(call ls-dirs) 2>nul)
CPUS := $(shell $(CHDIR) $(CPU_BASE_DIRECTORY) && $(call ls-dirs) 2>nul)
else
PLATFORMS := $(shell ($(CHDIR) $(PLATFORM_BASE_DIRECTORY) && $(call ls-dirs)) 2> /dev/null)
CPUS := $(shell ($(CHDIR) $(CPU_BASE_DIRECTORY) && $(call ls-dirs)) 2> /dev/null)
endif
# RTS_BASE_PATH: where all RTSes live
RTS_BASE_PATH := $(SWEETADA_PATH)/$(RTS_DIRECTORY)
# RTSes
RTS_SRC_NO_DIRS := common targets
ifeq ($(OSTYPE),cmd)
RTS_SRC_ALL_DIRS := $(shell $(CHDIR) $(RTS_DIRECTORY)\src && $(call ls-dirs) 2>nul)
else
RTS_SRC_ALL_DIRS := $(shell ($(CHDIR) $(RTS_DIRECTORY)/src && $(call ls-dirs)) 2> /dev/null)
endif
RTSES := $(filter-out $(RTS_SRC_NO_DIRS),$(RTS_SRC_ALL_DIRS))
# build flag and version control
DOTSWEETADA := .sweetada
# default kernel filenames
KERNEL_CFGFILE := $(KERNEL_BASENAME).cfg
KERNEL_DEPFILE := $(KERNEL_BASENAME).d
KERNEL_OBJFILE := $(KERNEL_BASENAME).obj
KERNEL_OUTFILE := $(KERNEL_BASENAME).o
KERNEL_ROMFILE := $(KERNEL_BASENAME).rom
# GNAT .adc filename
GNATADC_FILENAME := gnat.adc
# GPRbuild filenames
KERNEL_GPRFILE := sweetada.gpr
CONFIGUREGPR_FILENAME := configure.gpr
# default linker script name
LD_SCRIPT := linker.lds
# cleaning
CLEAN_OBJECTS_COMMON := *.a *.aout *.bin *.d *.dwo *.elf *.hex *.log *.lst \
*.map *.o *.out* *.srec *.td *.tmp
DISTCLEAN_OBJECTS_COMMON := $(GNATADC_FILENAME) \
$(CONFIGUREGPR_FILENAME)
################################################################################
# #
# Initialize toolchain variables. #
# #
################################################################################
#
# TOOLCHAIN_NAME: initialized by configuration.
# TOOLCHAIN_PROGRAM_PREFIX: synthesized from TOOLCHAIN_NAME.
# GCC_VERSION: is the GCC version string; if empty, the toolchain is believed
# to be non-existent.
# LIBGCC_FILENAME: is the filename of the "multilib" LibGCC determined by
# compiler configuration switches.
# RTS_ROOT_PATH: RTS path of a specific toolchain, which contains all its
# various "multilib" RTSes, arranged in a classic LibGCC-hierarchy fashion.
# RTS_PATH: is the specific path of a well-defined "multilib" RTS (e.g., the
# multilib subdirectory used by the build system), determined by compiler
# configuration switches.
# PLATFORM_DIRECTORY: directory of the configured platform
# CPU_DIRECTORY: directory of the configured CPU
#
TOOLCHAIN_NAME :=
TOOLCHAIN_PROGRAM_PREFIX :=
GCC_VERSION :=
LIBGCC_FILENAME :=
RTS_ROOT_PATH :=
RTS_PATH :=
PLATFORM_DIRECTORY :=
CPU_DIRECTORY :=
CPU_MODEL_DIRECTORY :=
#
# Initialize toolchain default switches.
#
AS_SWITCHES_DEFAULT :=
ADAC_SWITCHES_DEFAULT :=
CPP_SWITCHES_DEFAULT :=
CC_SWITCHES_DEFAULT :=
CXXC_SWITCHES_DEFAULT :=
GNATPREP_SWITCHES_DEFAULT :=
GNATMAKE_SWITCHES_DEFAULT :=
GNATBIND_SWITCHES_DEFAULT :=
GNATLINK_SWITCHES_DEFAULT :=
GNATLS_SWITCHES_DEFAULT :=
GPRBUILD_SWITCHES_DEFAULT :=
AR_SWITCHES_DEFAULT :=
LD_SWITCHES_DEFAULT :=
NM_SWITCHES_DEFAULT :=
OBJCOPY_SWITCHES_DEFAULT :=
OBJDUMP_SWITCHES_DEFAULT :=
RANLIB_SWITCHES_DEFAULT :=
READELF_SWITCHES_DEFAULT :=
SIZE_SWITCHES_DEFAULT :=
STRIP_SWITCHES_DEFAULT :=
#
# Initialize warning/style toolchain switches.
#
AS_SWITCHES_WARNING :=
ADAC_SWITCHES_WARNING :=
ADAC_SWITCHES_STYLE :=
CPP_SWITCHES_WARNING :=
CC_SWITCHES_WARNING :=
CXXC_SWITCHES_WARNING :=
#
# Initialize platform-dependent toolchain switches.
#
AS_SWITCHES_PLATFORM :=
GCC_SWITCHES_PLATFORM :=
LOWLEVEL_FILES_PLATFORM :=
GCC_SWITCHES_LOWLEVEL_PLATFORM :=
LD_SWITCHES_PLATFORM :=
OBJCOPY_SWITCHES_PLATFORM :=
OBJDUMP_SWITCHES_PLATFORM :=
#
# Initialize RTS-imported toolchain switches.
#
ADAC_SWITCHES_RTS :=
CC_SWITCHES_RTS :=
#
# Initialize include directories and implicit units.
#
INCLUDE_DIRECTORIES :=
CPU_INCLUDE_DIRECTORIES :=
IMPLICIT_CORE_UNITS :=
IMPLICIT_CLIBRARY_UNITS :=
#
# Various features.
#
GNATBIND_SECSTACK :=
ENABLE_SPLIT_DWARF :=
################################################################################
# #
# Global PLATFORM/CPU configuration logic. #
# #
################################################################################
ifneq ($(filter createkernelcfg,$(MAKECMDGOALS)),createkernelcfg)
-include $(KERNEL_CFGFILE)
endif
ifneq ($(MAKECMDGOALS),)
# PLATFORM processing
ifneq ($(filter $(CLEANING_GOALS) $(INFO_GOALS) rts $(PLATFORM_GOALS),$(MAKECMDGOALS)),)
ifneq ($(PLATFORM),)
# PLATFORM defined
ifeq ($(filter $(PLATFORM),$(PLATFORMS)),)
$(error Error: no valid PLATFORM)
endif
PLATFORM_DIRECTORY := $(PLATFORM_BASE_DIRECTORY)/$(PLATFORM)
ifeq ($(OSTYPE),cmd)
PLATFORM_DIRECTORY_CMD := $(PLATFORM_BASE_DIRECTORY)\$(PLATFORM)
endif
ifeq ($(filter distclean,$(MAKECMDGOALS)),distclean)
-include $(PLATFORM_DIRECTORY)/configuration.in
else
include $(PLATFORM_DIRECTORY)/configuration.in
endif
CONFIGURE_DEPS += $(PLATFORM_DIRECTORY)/configuration.in
else
# PLATFORM unknown
ifneq ($(filter $(PLATFORM_GOALS),$(MAKECMDGOALS)),)
$(error Error: no valid PLATFORM)
endif
endif
endif
# CPU processing
ifneq ($(CPU),)
# CPU defined
ifneq ($(filter $(INFO_GOALS) rts $(PLATFORM_GOALS),$(MAKECMDGOALS)),)
ifeq ($(filter $(CPU),$(CPUS)),)
$(error Error: no valid CPU)
else
CPU_DIRECTORY := $(CPU_BASE_DIRECTORY)/$(CPU)
include $(CPU_DIRECTORY)/configuration.in
CONFIGURE_DEPS += $(CPU_DIRECTORY)/configuration.in
endif
endif
else
# CPU must be known for the RTS goal
ifeq ($(filter rts,$(MAKECMDGOALS)),rts)
$(error Error: no valid CPU)
endif
endif
# standard components
include $(APPLICATION_DIRECTORY)/configuration.in
CONFIGURE_DEPS += $(APPLICATION_DIRECTORY)/configuration.in
ifeq ($(USE_CLIBRARY),Y)
include $(CLIBRARY_DIRECTORY)/configuration.in
CONFIGURE_DEPS += $(CLIBRARY_DIRECTORY)/configuration.in
endif
include $(CORE_DIRECTORY)/configuration.in
CONFIGURE_DEPS += $(CORE_DIRECTORY)/configuration.in
include $(DRIVERS_DIRECTORY)/configuration.in
CONFIGURE_DEPS += $(DRIVERS_DIRECTORY)/configuration.in
include $(MODULES_DIRECTORY)/configuration.in
CONFIGURE_DEPS += $(MODULES_DIRECTORY)/configuration.in
endif
################################################################################
# #
# Post-configuration finalization. #
# #
################################################################################
#
# Now that the complete configuration is known, do a finalization on some
# sensible parameters.
#
ifneq ($(filter $(PLATFORM_GOALS),$(MAKECMDGOALS)),)
ifeq ($(filter GNATMAKE GPRbuild,$(BUILD_MODE)),)
$(warning *** Warning: no valid BUILD_MODE.)
endif
endif
# if RTS_BUILD is null, use the one read from configuration files
ifeq ($(RTS_BUILD),)
RTS_BUILD := $(RTS)
endif
# high-precedence include directories
ifneq ($(PLATFORM),)
ifneq ($(CPU),)
# head-insert CPU directory
INCLUDE_DIRECTORIES := $(CPU_DIRECTORY) $(INCLUDE_DIRECTORIES)
# head-insert optional directories
ifneq ($(CPU_INCLUDE_DIRECTORIES),)
INCLUDE_DIRECTORIES := $(CPU_INCLUDE_DIRECTORIES) $(INCLUDE_DIRECTORIES)
endif
# head-insert CPU_MODEL directory
ifneq ($(CPU_MODEL_DIRECTORY),)
INCLUDE_DIRECTORIES := $(CPU_MODEL_DIRECTORY) $(INCLUDE_DIRECTORIES)
endif
endif
# head-insert PLATFORM directory
INCLUDE_DIRECTORIES := $(PLATFORM_DIRECTORY) $(INCLUDE_DIRECTORIES)
endif
# import implicit units
IMPLICIT_ALI_UNITS += $(IMPLICIT_CORE_UNITS) \
$(IMPLICIT_CLIBRARY_UNITS)
# GPRbuild configuration dependencies
ifeq ($(BUILD_MODE),GPRbuild)
ifneq ($(filter $(PLATFORM_GOALS),$(MAKECMDGOALS)),)
ifeq ($(OSTYPE),cmd)
GPRBUILD_DEPS += $(sort $(shell \
SET "PATH=$(PATH)" && \
SET "SWEETADA_PATH=$(SWEETADA_PATH)" && \
SET "LIBUTILS_DIRECTORY=$(LIBUTILS_DIRECTORY)" && \
$(GPRDEPS) $(KERNEL_GPRFILE) \
2>nul))
else
GPRBUILD_DEPS += $(sort $(shell \
PATH="$(PATH)" && \
SWEETADA_PATH="$(SWEETADA_PATH)" && \
LIBUTILS_DIRECTORY="$(LIBUTILS_DIRECTORY)" && \
$(GPRDEPS) $(KERNEL_GPRFILE) \
2> /dev/null))
endif
endif
endif
# toolchain specifications
include Makefile.tc.in
################################################################################
# #
# Compilation debugging. #
# #
################################################################################
-include Makefile.db.in
################################################################################
# #
# Export variables to environment and sub-makefiles. #
# #
################################################################################
# beautify some variables
INCLUDE_DIRECTORIES := $(filter-out ,$(INCLUDE_DIRECTORIES))
IMPLICIT_CORE_UNITS := $(filter-out ,$(IMPLICIT_CORE_UNITS))
ifeq ($(USE_CLIBRARY),Y)
IMPLICIT_CLIBRARY_UNITS := $(filter-out ,$(IMPLICIT_CLIBRARY_UNITS))
endif
IMPLICIT_ALI_UNITS := $(filter-out ,$(IMPLICIT_ALI_UNITS))
ifeq ($(BUILD_MODE),GPRbuild)
GPR_CORE_CPU := $(filter-out ,$(GPR_CORE_CPU))
endif
# build system
export \
MAKE \
KERNEL_BASENAME \
KERNEL_CFGFILE \
KERNEL_DEPFILE \
KERNEL_OUTFILE \
KERNEL_ROMFILE \
PLATFORM_BASE_DIRECTORY \
PLATFORM_DIRECTORY \
PLATFORM_DIRECTORY_CMD \
CPUS \
CPU_BASE_DIRECTORY \
CPU_DIRECTORY \
CPU_MODEL_DIRECTORY \
APPLICATION_DIRECTORY \
CLIBRARY_DIRECTORY \
CORE_DIRECTORY \
DRIVERS_DIRECTORY \
MODULES_DIRECTORY \
LIBRARY_DIRECTORY \
OBJECT_DIRECTORY \
RTSES \
RTS_DIRECTORY \
RTS_BASE_PATH \
SHARE_DIRECTORY \
GNATADC_FILENAME \
INCLUDE_DIRECTORIES \
IMPLICIT_CORE_UNITS \
IMPLICIT_CLIBRARY_UNITS \
IMPLICIT_ALI_UNITS \
CLEAN_OBJECTS_COMMON \
DISTCLEAN_OBJECTS_COMMON \
CONFIGURE_DEPS
# toolchain
export \
TOOLCHAIN_PREFIX \
GPRBUILD_PREFIX \
TOOLCHAIN_NAME_AArch64 \
TOOLCHAIN_NAME_ARM \
TOOLCHAIN_NAME_AVR \
TOOLCHAIN_NAME_M68k \
TOOLCHAIN_NAME_MIPS \
TOOLCHAIN_NAME_MIPS64 \
TOOLCHAIN_NAME_MicroBlaze \
TOOLCHAIN_NAME_NiosII \
TOOLCHAIN_NAME_OpenRISC \
TOOLCHAIN_NAME_PowerPC \
TOOLCHAIN_NAME_RISCV \
TOOLCHAIN_NAME_SPARC \
TOOLCHAIN_NAME_SPARC64 \
TOOLCHAIN_NAME_SuperH \
TOOLCHAIN_NAME_SH4 \
TOOLCHAIN_NAME_System390 \
TOOLCHAIN_NAME_x86 \
TOOLCHAIN_NAME_x86_64 \
TOOLCHAIN_NAME \
TOOLCHAIN_PROGRAM_PREFIX \
TOOLCHAIN_GCC \
TOOLCHAIN_ADAC \
TOOLCHAIN_AR \
TOOLCHAIN_AS \
TOOLCHAIN_CC \
TOOLCHAIN_GDB \
TOOLCHAIN_LD \
TOOLCHAIN_OBJDUMP \
TOOLCHAIN_RANLIB \
GCC_VERSION \
RTS_ROOT_PATH \
RTS_PATH \
ADAC \
ADAC_SWITCHES_WARNING \
ADAC_SWITCHES_STYLE \
AR \
AS \
CC \
CPP \
GDB \
GNATBIND \
GNATCHOP \
GNATLINK \
GNATLS \
GNATMAKE \
GNATMAKE_DEPEND \
GNATPREP \
GNATXREF \
GPRBUILD \
LD \
NM \
OBJCOPY \
OBJDUMP \
RANLIB \
READELF \
SIZE \
STRIP
# configuration
export \
PLATFORM \
SUBPLATFORM \
CPU \
CPU_MODEL \
FPU_MODEL \
BUILD_MODE \
OPTIMIZATION_LEVEL \
RTS \
PROFILE \
ADA_MODE \
USE_LIBGCC \
USE_LIBM \
USE_LIBADA \
USE_CLIBRARY \
USE_APPLICATION \
CONFIGURE_FILES_PLATFORM \
GCC_SWITCHES_PLATFORM \
LOWLEVEL_FILES_PLATFORM \
GCC_SWITCHES_LOWLEVEL_PLATFORM \
EXTERNAL_OBJECTS \
STACK_LIMIT \
GNATBIND_SECSTACK \
POSTBUILD_COMMAND
export USE_ELFTOOL
ifeq ($(USE_ELFTOOL),Y)
export ELFTOOL
endif
ifneq ($(PYTHON),)
export PYTHON
endif
ifneq ($(TCLSH),)
export TCLSH
endif
################################################################################
# #
# Private non-global definitions and variables. #
# #
################################################################################
KERNEL_PARENT_PATH := .
MAKE_APPLICATION := SHELL="$(SHELL)" KERNEL_PARENT_PATH=.. -C $(APPLICATION_DIRECTORY)
MAKE_CLIBRARY := SHELL="$(SHELL)" KERNEL_PARENT_PATH=.. -C $(CLIBRARY_DIRECTORY)
MAKE_CORE := SHELL="$(SHELL)" KERNEL_PARENT_PATH=.. -C $(CORE_DIRECTORY)
MAKE_CPUS := SHELL="$(SHELL)" KERNEL_PARENT_PATH=../.. -C $(CPU_BASE_DIRECTORY)
MAKE_CPU := $(MAKE_CPUS)/$(CPU)
MAKE_DRIVERS := SHELL="$(SHELL)" KERNEL_PARENT_PATH=.. -C $(DRIVERS_DIRECTORY)
MAKE_MODULES := SHELL="$(SHELL)" KERNEL_PARENT_PATH=.. -C $(MODULES_DIRECTORY)
MAKE_PLATFORMS := SHELL="$(SHELL)" KERNEL_PARENT_PATH=../.. -C $(PLATFORM_BASE_DIRECTORY)
MAKE_PLATFORM := $(MAKE_PLATFORMS)/$(PLATFORM)
MAKE_RTS := SHELL="$(SHELL)" KERNEL_PARENT_PATH=.. -C $(RTS_DIRECTORY)
CLEAN_OBJECTS := $(KERNEL_OBJFILE) \
$(KERNEL_OUTFILE) \
$(KERNEL_ROMFILE) \
$(CLEAN_OBJECTS_COMMON)
DISTCLEAN_OBJECTS := $(KERNEL_CFGFILE) \
$(DISTCLEAN_OBJECTS_COMMON)
################################################################################
# #
# Library selection. #
# #
################################################################################
ifeq ($(USE_LIBGCC),Y)
LIBGCC_OBJECT := "$(LIBGCC_FILENAME)"
else
LIBGCC_OBJECT :=
endif
ifeq ($(USE_LIBM),Y)
LIBM_OBJECT := "$(LIBM_FILENAME)"
else
LIBM_OBJECT :=
endif
ifneq ($(RTS),zfp)
USE_LIBADA := Y
endif
ifeq ($(USE_LIBADA),Y)
ifeq ($(OSTYPE),msys)
LIBGNAT_OBJECT := "$(shell cygpath.exe -m "$(RTS_PATH)")"/adalib/libgnat.a
LIBGNARL_OBJECT := "$(shell cygpath.exe -m "$(RTS_PATH)")"/adalib/libgnarl.a
else
LIBGNAT_OBJECT := "$(RTS_PATH)"/adalib/libgnat.a
LIBGNARL_OBJECT := "$(RTS_PATH)"/adalib/libgnarl.a
endif
LIBADA_OBJECTS := $(LIBGNAT_OBJECT) $(LIBGNARL_OBJECT)
else
LIBADA_OBJECTS :=
endif
ifeq ($(USE_CLIBRARY),Y)
CLIBRARY_OBJECT := $(OBJECT_DIRECTORY)/libclibrary.a
else
CLIBRARY_OBJECT :=
endif
################################################################################
# #
# Targets. #
# #
################################################################################
#
# Default target.
#
.PHONY: help
help:
@$(call echo-print,"make help (default)")
@$(call echo-print," Display an help about make targets.")
@$(call echo-print,"make [RTS=<rts>] [CPU=<cpu>] [CPU_MODEL=<cpu_model>] \
[TOOLCHAIN_NAME=<toolchain_name>] rts")
@$(call echo-print," Build RTS <rts> for CPU <cpu> [CPU model <cpu_model>] \
using toolchain <toolchain_name>.")
@$(call echo-print,"make PLATFORM=<platform> [SUBPLATFORM=<subplatform>] createkernelcfg")
@$(call echo-print," Create the '$(KERNEL_CFGFILE)' main configuration file.")
@$(call echo-print,"make configure")
@$(call echo-print," Create configuration/support files for this platform.")
@$(call echo-print,"make all")
@$(call echo-print," Perform the same as 'make $(KERNEL_BASENAME)'.")
@$(call echo-print,"make $(KERNEL_BASENAME)")
@$(call echo-print," Build the kernel target-output file '$(KERNEL_OUTFILE)'.")
@$(call echo-print,"make postbuild")
@$(call echo-print," Perform platform-specific finalizations \
and build a customized binary file '$(KERNEL_ROMFILE)'.")
@$(call echo-print,"make session-start")
@$(call echo-print," Perform session start activities.")
@$(call echo-print,"make session-end activities")
@$(call echo-print," Perform session end activities.")
@$(call echo-print,"make run")
@$(call echo-print," Run the kernel.")
@$(call echo-print,"make debug")
@$(call echo-print," Run the kernel with debugger active.")
@$(call echo-print,"make infodump")
@$(call echo-print," Dump essential informations.")
@$(call echo-print,"make kernel_libinfo")
@$(call echo-print," Generate library informations.")
@$(call echo-print,"make kernel_info")
@$(call echo-print," Generate kernel informations.")
@$(call echo-print,"make clean")
@$(call echo-print," Clean object files.")
@$(call echo-print,"make distclean")
@$(call echo-print," Clean object files and all configuration/support files.")
@$(call echo-print,"make libutils-elftool")
@$(call echo-print," Build ELFtool.")
@$(call echo-print,"make libutils-gcc-wrapper")
@$(call echo-print," Build GCC-wrapper.")
@$(call echo-print,"make libutils-gnat-wrapper")
@$(call echo-print," Build GNAT-wrapper.")
@$(call echo-print,"make PROBEVARIABLE=<variablename> probevariable")
@$(call echo-print," Obtain the value of a variable.")
@$(call echo-print,"")
@$(call echo-print,"Available CPUs: $(CPUS)")
@$(call echo-print,"")
@$(call echo-print,"Available RTSes: $(RTSES)")
@$(call echo-print,"")
@$(call echo-print,"Available Platforms: $(PLATFORMS)")
@$(call echo-print,"")
ifneq ($(PLATFORM),)
@$(call echo-print,"Current PLATFORM: $(PLATFORM)")
@$(call echo-print,"")
ifneq ($(SUBPLATFORM),)
@$(call echo-print,"Current SUBPLATFORM: $(SUBPLATFORM)")
@$(call echo-print,"")
endif
endif
#
# Compile phase.
#
.PHONY: FORCE
FORCE:
$(OBJECT_DIRECTORY)/libplatform.a: FORCE
$(MAKE) $(MAKE_PLATFORM) all
$(OBJECT_DIRECTORY)/libcpu.a: FORCE
$(MAKE) $(MAKE_CPU) all
$(OBJECT_DIRECTORY)/libcore.a: FORCE
$(MAKE) $(MAKE_CORE) all
$(CLIBRARY_OBJECT): FORCE
ifeq ($(USE_CLIBRARY),Y)
$(MAKE) $(MAKE_CLIBRARY) all
endif
$(GCC_GNAT_WRAPPER_TIMESTAMP_FILENAME): FORCE
ifeq ($(BUILD_MODE),GNATMAKE)
@$(REM) GNATMAKE-driven procedure
$(call brief-command, \
$(GNATMAKE) \
-c \
-gnatec=$(GNATADC_FILENAME) \
-D $(OBJECT_DIRECTORY) \
$(foreach \
d,$(INCLUDE_DIRECTORIES), \
-I$(d) \
) \
main.adb \
,[GNATMAKE],main.adb)