xref: /haiku/build/jam/BootRules (revision 57ab322d674a58ddfa2c04fc8aa45b8171b2bf08)
1rule MultiBootSubDirSetup bootTargets
2{
3	local result ;
4	local bootTarget ;
5	bootTargets ?= $(HAIKU_BOOT_TARGETS) ;
6	for bootTarget in $(bootTargets) {
7		local bootTargetObject = $(bootTarget:G=<boot-target-object>) ;
8		result += $(bootTargetObject) ;
9
10		TARGET_BOOT_PLATFORM on $(bootTargetObject) = $(bootTarget) ;
11
12		SOURCE_GRIST on $(bootTargetObject)
13			= $(SOURCE_GRIST:E=)!$(bootTarget) ;
14
15		HDRGRIST on $(bootTargetObject)
16			= $(HDRGRIST:E=)!$(bootTarget) ;
17
18		local var ;
19		for var in TARGET_ARCH {
20			$(var) on $(architectureObject) = $($(var)_$(architecture)) ;
21		}
22
23		# Clone the current config variable values and the variables SubDir
24		# resets.
25		for var in $(AUTO_SET_UP_CONFIG_VARIABLES) SUBDIR$(SUBDIRRESET) {
26			$(var) on $(architectureObject) = $($(var)) ;
27		}
28
29		local hostTarget = HOST TARGET ;
30		local objectDirVars =
31			COMMON_ARCH COMMON_DEBUG DEBUG_$(HAIKU_DEBUG_LEVELS)
32			;
33		objectDirVars =
34			COMMON_PLATFORM_LOCATE_TARGET
35			$(hostTarget)_$(objectDirVars)_LOCATE_TARGET
36			LOCATE_TARGET
37			LOCATE_SOURCE
38			SEARCH_SOURCE
39			;
40
41		for var in $(objectDirVars) {
42			$(var) on $(bootTargetObject) = ;
43		}
44
45		on $(bootTargetObject) {
46			SetupObjectsDir ;
47			SetupFeatureObjectsDir $(bootTarget) ;
48
49			for var in $(objectDirVars) {
50				$(var) on $(bootTargetObject) = $($(var)) ;
51			}
52		}
53	}
54
55	return $(result) ;
56}
57
58rule MultiBootGristFiles files
59{
60	return $(files:G=$(TARGET_BOOT_PLATFORM)) ;
61}
62
63rule SetupBoot
64{
65	# Usage SetupBoot <sources_or_objects> : <extra_cc_flags> : <include_private_headers> ;
66	#
67	# <sources_or_objects> - Ideally sources, otherwise HDRSEARCH can not be
68	#						 set for the sources and the sources some header
69	#						 dependencies might be missing.
70
71	local sources = [ FGristFiles $(1) ] ;
72	local objects = $(sources:S=$(SUFOBJ)) ;
73
74	# add private kernel headers
75	if $(3) != false {
76		SourceSysHdrs $(sources) : $(TARGET_PRIVATE_KERNEL_HEADERS) ;
77	}
78
79	if $(HAIKU_BOOT_C++_HEADERS_DIR_$(TARGET_PACKAGING_ARCH)) {
80		SourceSysHdrs $(sources) :
81			$(HAIKU_BOOT_C++_HEADERS_DIR_$(TARGET_PACKAGING_ARCH)) ;
82	}
83
84	# MultiBootSubDirSetup sets the target boot platform on the target object,
85	# so this will be correct here in SetupBoot.
86	# This does mean, however, that MultiBootSubDirSetup needs to be used in
87	# all Jamfiles for things to work correctly.
88	# Also means ArchitectureRules need to use platform specific variables,
89	# rather than the previously generic TARGET_BOOT_CCFLAGS and friends.
90	local platform = $(TARGET_BOOT_PLATFORM:U) ;
91	local object ;
92	for object in $(objects) {
93		# add boot flags for the object
94		ObjectCcFlags $(object) : $(HAIKU_BOOT_CCFLAGS) $(HAIKU_BOOT_$(platform)_CCFLAGS) $(2) ;
95		ObjectC++Flags $(object) : $(HAIKU_BOOT_C++FLAGS) $(HAIKU_BOOT_$(platform)_C++FLAGS) $(2) ;
96		ObjectDefines $(object) : $(TARGET_KERNEL_DEFINES) ;
97		ASFLAGS on $(object) = $(HAIKU_BOOT_CCFLAGS) $(HAIKU_BOOT_$(platform)_CCFLAGS) ;
98
99		# override warning flags
100		TARGET_WARNING_CCFLAGS_$(TARGET_PACKAGING_ARCH) on $(object)
101			= $(TARGET_KERNEL_WARNING_CCFLAGS) ;
102		TARGET_WARNING_C++FLAGS_$(TARGET_PACKAGING_ARCH) on $(object)
103			= $(TARGET_KERNEL_WARNING_C++FLAGS) ;
104	 }
105}
106
107rule BootObjects
108{
109	SetupBoot $(1) : $(2) ;
110	Objects $(1) ;
111}
112
113rule BootLd
114{
115	# BootLd <name> : <objs> : <linkerscript> : <args> ;
116
117	LINK on $(1) = $(TARGET_LD_$(TARGET_PACKAGING_ARCH)) ;
118
119	LINKFLAGS on $(1) = $(HAIKU_BOOT_$(TARGET_BOOT_PLATFORM:U)_LDFLAGS) $(4) ;
120	if $(3) { LINKFLAGS on $(1) += --script=$(3) ; }
121
122	# Remove any preset LINKLIBS, but link against libgcc.a. Linking against
123	# libsupc++ is opt-out.
124	if $(TARGET_BOOT_PLATFORM) != efi {
125		local libs ;
126		if ! [ on $(1) return $(HAIKU_NO_LIBSUPC++) ] {
127			libs += [ TargetBootLibsupc++ true ] ;
128			Depends $(1) : [ TargetBootLibsupc++ ] ;
129		}
130		LINKLIBS on $(1) = $(libs) [ TargetBootLibgcc true ] ;
131		Depends $(1) : [ TargetBootLibgcc ] ;
132	}
133
134	# TODO: Do we really want to invoke SetupBoot here? The objects should
135	# have been compiled with BootObjects anyway, so we're doing that twice.
136	SetupBoot $(2) ;
137
138	# Show that we depend on the libraries we need
139	LocalClean clean : $(1) ;
140	LocalDepends all : $(1) ;
141	Depends $(1) : $(2) ;
142
143	MakeLocateDebug $(1) ;
144
145	on $(1) XRes $(1) : $(RESFILES) ;
146	if ! [ on $(1) return $(DONT_USE_BEOS_RULES) ] {
147		SetType $(1) ;
148		MimeSet $(1) ;
149		SetVersion $(1) ;
150	}
151}
152
153actions BootLd bind VERSION_SCRIPT
154{
155	$(LINK) $(LINKFLAGS) -o "$(1)" "$(2)" $(LINKLIBS) \
156		--version-script=$(VERSION_SCRIPT)
157}
158
159rule BootMergeObject
160{
161	# BootMergeObject <name> : <sources> : <extra CFLAGS> : <other objects> ;
162	# Compiles source files and merges the object files to an object file.
163	# <name>: Name of the object file to create. No grist will be added.
164	# <sources>: Sources to be compiled. Grist will be added.
165	# <extra CFLAGS>: Additional flags for compilation.
166	# <other objects>: Object files or static libraries to be merged. No grist
167	#				   will be added.
168	#
169
170	SetupBoot $(2) : $(3) ;
171	Objects $(2) ;
172	MergeObjectFromObjects $(1) : $(2:S=$(SUFOBJ)) : $(4) ;
173	LINKFLAGS on $(1) += $(HAIKU_BOOT_$(TARGET_BOOT_PLATFORM:U)_LDFLAGS) ;
174}
175
176rule BootStaticLibrary
177{
178	# Usage BootStaticLibrary <name> : <sources> : <extra cc flags> ;
179	# This is designed to take a set of sources and libraries and create
180	# a file called lib<name>.a
181
182	SetupBoot $(2) : $(3) : false ;
183	Library $(1) : $(2) ;
184}
185
186rule BootStaticLibraryObjects
187{
188	# Usage BootStaticLibrary <name> : <sources> ;
189	# This is designed to take a set of sources and libraries and create
190	# a file called <name>
191
192	# Show that we depend on the libraries we need
193	SetupBoot $(2) ;
194	LocalClean clean : $(1) ;
195	LocalDepends all : $(1) ;
196	Depends $(1) : $(2) ;
197
198	MakeLocateDebug $(1) ;
199}
200
201actions BootStaticLibraryObjects
202{
203	# Force recreation of the archive to avoid build errors caused by
204	# stale dependencies after renaming or deleting object files.
205	$(RM) "$(1)"
206	$(HAIKU_AR_$(TARGET_PACKAGING_ARCH)) -r "$(1)" "$(2)" ;
207}
208
209rule BuildMBR binary : source
210{
211	SEARCH on $(source) = $(SUBDIR) ;
212	MakeLocateDebug $(binary) ;
213	Depends $(binary) : $(source) ;
214}
215
216actions BuildMBR
217{
218	$(RM) $(1)
219	$(HAIKU_CC_$(HAIKU_PACKAGING_ARCH)) $(2) -o $(1) $(MBRFLAGS) -nostdlib -Xlinker --oformat=binary -Xlinker -S -Xlinker -N -Xlinker --entry=start -Xlinker -Ttext=0x600
220}
221