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