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