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