xref: /haiku/build/jam/KernelRules (revision 87f4776937505e3014251c9c3434be78ae29d7d0)
1rule SetupKernel
2{
3	# Usage SetupKernel <sources_or_objects> : <extra_cc_flags> : <include_private_headers> ;
4	#
5	# <sources_or_objects> - Ideally sources, otherwise HDRSEARCH can not be
6	#                        set for the sources and the sources some header
7	#                        dependencies might be missing.
8
9	local sources = [ FGristFiles $(1) ] ;
10	local objects = $(sources:S=$(SUFOBJ)) ;
11
12	# add private kernel headers
13	if $(3) != false {
14		SourceSysHdrs $(sources) : $(TARGET_PRIVATE_KERNEL_HEADERS) ;
15	}
16
17	local object ;
18	for object in $(objects) {
19		# add kernel flags for the object
20		ObjectCcFlags $(object) : $(TARGET_KERNEL_CCFLAGS) $(2) ;
21		ObjectC++Flags $(object) : $(TARGET_KERNEL_C++FLAGS) $(2) ;
22		ObjectDefines $(object) : $(TARGET_KERNEL_DEFINES) ;
23
24		# override regular CCFLAGS/C++FLAGS, as we don't want them
25		TARGET_CCFLAGS_$(TARGET_PACKAGING_ARCH) on $(object) = ;
26		TARGET_C++FLAGS_$(TARGET_PACKAGING_ARCH) on $(object) = ;
27
28		# override warning flags
29		TARGET_WARNING_CCFLAGS_$(TARGET_PACKAGING_ARCH) on $(object)
30			= $(TARGET_KERNEL_WARNING_CCFLAGS) ;
31		TARGET_WARNING_C++FLAGS_$(TARGET_PACKAGING_ARCH) on $(object)
32			= $(TARGET_KERNEL_WARNING_C++FLAGS) ;
33	}
34}
35
36rule KernelObjects
37{
38	SetupKernel $(1) : $(2) ;
39	Objects $(1) ;
40}
41
42rule KernelLd
43{
44	# KernelLd <name> : <objs> : <linkerscript> : <args> ;
45
46	LINK on $(1) = $(TARGET_LD_$(TARGET_PACKAGING_ARCH)) ;
47
48	LINKFLAGS on $(1) = $(4) ;
49	if $(3) {
50		LINKFLAGS on $(1) += --script=$(3) ;
51		Depends $(1) : $(3) ;
52	}
53
54	# Remove any preset LINKLIBS, but link against libgcc.a. Linking against
55	# libsupc++ is opt-out.
56	local libs ;
57	if ! [ on $(1) return $(HAIKU_NO_LIBSUPC++) ] {
58		libs += [ TargetKernelLibsupc++ true ] ;
59		Depends $(1) : [ TargetKernelLibsupc++ ] ;
60	}
61	LINKLIBS on $(1) = $(libs) [ TargetKernelLibgcc true ] ;
62	Depends $(1) : [ TargetKernelLibgcc ] ;
63
64	HAIKU_TARGET_IS_EXECUTABLE on $(1) = 1 ;
65
66	# TODO: Do we really want to invoke SetupKernel here? The objects should
67	# have been compiled with KernelObjects anyway, so we're doing that twice.
68	SetupKernel $(2) ;
69
70	# Show that we depend on the libraries we need
71	LocalClean clean : $(1) ;
72	LocalDepends all : $(1) ;
73	Depends $(1) : $(2) ;
74
75	MakeLocateDebug $(1) ;
76
77	on $(1) XRes $(1) : $(RESFILES) ;
78	if ! [ on $(1) return $(DONT_USE_BEOS_RULES) ] {
79		SetType $(1) ;
80		MimeSet $(1) ;
81		SetVersion $(1) ;
82	}
83}
84
85actions KernelLd bind VERSION_SCRIPT
86{
87	$(LINK) $(LINKFLAGS) -o "$(1)" "$(2)" $(LINKLIBS) \
88		--version-script=$(VERSION_SCRIPT)
89}
90
91rule KernelSo target : source
92{
93	# KernelSo <target> : <source>
94
95	Depends $(target) : <build>copyattr $(source) ;
96
97	MakeLocateDebug $(1) ;
98	KernelSo1 $(target) : <build>copyattr $(source) ;
99}
100
101actions KernelSo1
102{
103	export $(HOST_ADD_BUILD_COMPATIBILITY_LIB_DIR)
104
105	$(2[1]) --data $(2[2]) $(1) &&
106	$(HAIKU_ELFEDIT_$(TARGET_PACKAGING_ARCH)) --output-type dyn $(1)
107}
108
109rule KernelAddon
110{
111	# KernelAddon <name> : <sources> : <static-libraries> : <res> ;
112	#
113	local target = $(1) ;
114	local sources = $(2) ;
115	local libs = $(3) ;
116	AddResources $(1) : $(4) ;
117
118	local kernel ;
119	local beginGlue ;
120	local endGlue ;
121	on $(target) {
122		# platform supported?
123		if ! $(PLATFORM) in $(SUPPORTED_PLATFORMS) {
124			return ;
125		}
126
127		# determine which kernel and glue code to link against
128		if $(PLATFORM) = haiku {
129			kernel = <nogrist>kernel.so ;
130			beginGlue = $(HAIKU_KERNEL_ADDON_BEGIN_GLUE_CODE) ;
131			endGlue
132				= [ TargetKernelLibgcc ] $(HAIKU_KERNEL_ADDON_END_GLUE_CODE) ;
133		} else if $(PLATFORM) = haiku_host {
134			kernel = /boot/develop/lib/x86/kernel.so ;
135			beginGlue = $(HAIKU_KERNEL_ADDON_BEGIN_GLUE_CODE) ;
136			endGlue = $(HAIKU_KERNEL_ADDON_END_GLUE_CODE) ;
137		} else {
138			kernel = /boot/develop/lib/x86/_KERNEL_ ;
139		}
140	}
141
142	# add glue code
143	LINK_BEGIN_GLUE on $(target) = $(beginGlue) ;
144	LINK_END_GLUE on $(target) = $(endGlue) ;
145	Depends $(target) : $(beginGlue) $(endGlue) ;
146
147	# compile and link
148	SetupKernel $(sources) : : false ;
149	local linkFlags = -shared -nostdlib -Xlinker --no-undefined
150		-Xlinker -soname=\"$(target:G=)\" $(TARGET_KERNEL_ADDON_LINKFLAGS) ;
151	LINKFLAGS on $(target) = [ on $(target) return $(LINKFLAGS) ] $(linkFlags) ;
152	Main $(target) : $(sources) ;
153	LinkAgainst $(target) : $(libs) $(kernel) ;
154}
155
156rule KernelMergeObject
157{
158	# KernelMergeObject <name> : <sources> : <extra CFLAGS> : <other objects> ;
159	# Compiles source files and merges the object files to an object file.
160	# <name>: Name of the object file to create. No grist will be added.
161	# <sources>: Sources to be compiled. Grist will be added.
162	# <extra CFLAGS>: Additional flags for compilation.
163	# <other objects>: Object files or static libraries to be merged. No grist
164	#                  will be added.
165	#
166
167	SetupKernel $(2) : $(3) ;
168	Objects $(2) ;
169	MergeObjectFromObjects $(1) : $(2:S=$(SUFOBJ)) : $(4) ;
170}
171
172rule KernelStaticLibrary
173{
174	# Usage KernelStaticLibrary <name> : <sources> : <extra cc flags> ;
175	# This is designed to take a set of sources and libraries and create
176	# a static library.
177
178	SetupKernel $(2) : $(3) : false ;
179	Library $(1) : $(2) ;
180}
181
182rule KernelStaticLibraryObjects
183{
184	# Usage KernelStaticLibrary <name> : <sources> ;
185	# This is designed to take a set of sources and libraries and create
186	# a file called <name>
187
188	# Show that we depend on the libraries we need
189	SetupKernel $(2) ;
190	LocalClean clean : $(1) ;
191	LocalDepends all : $(1) ;
192	Depends $(1) : $(2) ;
193
194	MakeLocateDebug $(1) ;
195}
196
197actions KernelStaticLibraryObjects
198{
199	# Force recreation of the archive to avoid build errors caused by
200	# stale dependencies after renaming or deleting object files.
201	$(RM) "$(1)"
202	$(HAIKU_AR_$(TARGET_PACKAGING_ARCH)) -r "$(1)" "$(2)" ;
203}
204