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