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