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