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