xref: /haiku/build/jam/KernelRules (revision 1d9d47fc72028bb71b5f232a877231e59cfe2438)
1
2rule SetupKernel
3{
4	# Usage SetupKernel <sources_or_objects> : <extra_cc_flags>;
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	SourceSysHdrs $(sources) : $(TARGET_PRIVATE_KERNEL_HEADERS) ;
15
16	local object ;
17	for object in $(objects) {
18		# add kernel flags for the object
19		ObjectCcFlags $(object) : $(TARGET_KERNEL_CCFLAGS) $(2) ;
20		ObjectC++Flags $(object) : $(TARGET_KERNEL_C++FLAGS) $(2) ;
21
22		# override warning flags
23		TARGET_WARNING_CCFLAGS on $(object) = $(TARGET_KERNEL_WARNING_CCFLAGS) ;
24		TARGET_WARNING_C++FLAGS on $(object)
25			= $(TARGET_KERNEL_WARNING_C++FLAGS) ;
26	}
27}
28
29rule KernelObjects
30{
31	SetupKernel $(1) : $(2) ;
32	Objects $(1) ;
33}
34
35rule KernelLd
36{
37	# KernelLd <name> : <objs> : <linkerscript> : <args> ;
38
39	LINK on $(1) = $(TARGET_LD) ;
40
41	LINKFLAGS on $(1) = $(4) ;
42	if $(3) { LINKFLAGS on $(1) += --script=$(3) ; }
43
44	# Remove any preset LINKLIBS, but link against libgcc.a
45	LINKLIBS on $(1) = $(TARGET_STATIC_LIBSUPC++) $(TARGET_GCC_LIBGCC) ;
46
47	# TODO: Do we really want to invoke SetupKernel here? The objects should
48	# have been compiled with KernelObjects anyway, so we're doing that twice.
49	SetupKernel $(2) ;
50
51	# Show that we depend on the libraries we need
52	LocalClean clean : $(1) ;
53	LocalDepends all : $(1) ;
54	Depends $(1) : $(2) ;
55
56	MakeLocateDebug $(1) ;
57
58	on $(1) XRes $(1) : $(RESFILES) ;
59	if ! [ on $(1) return $(DONT_USE_BEOS_RULES) ] {
60		SetType $(1) ;
61		MimeSet $(1) ;
62		SetVersion $(1) ;
63	}
64}
65
66actions KernelLd
67{
68	$(LINK) $(LINKFLAGS) -o "$(1)" "$(2)" $(LINKLIBS) ;
69}
70
71rule KernelAddon
72{
73	# KernelAddon <name> : <relpath> : <sources> : <static-libraries> ;
74	#
75# TODO: <relpath> no longer needed!
76	local target = $(1) ;
77	local sources = $(3) ;
78	local libs = $(4) ;
79
80	local kernel ;
81	local beginGlue ;
82	local endGlue ;
83	on $(target) {
84		# platform supported?
85		if ! $(PLATFORM) in $(SUPPORTED_PLATFORMS) {
86			return ;
87		}
88
89		# determine which kernel and glue code to link against
90		if $(PLATFORM) = haiku {
91			kernel = <nogrist>kernel.so ;
92			beginGlue = $(HAIKU_KERNEL_ADDON_BEGIN_GLUE_CODE) ;
93			endGlue = $(HAIKU_KERNEL_ADDON_END_GLUE_CODE) ;
94		} else {
95			kernel = /boot/develop/lib/x86/_KERNEL_ ;
96		}
97	}
98
99	# add glue code
100	LINK_BEGIN_GLUE on $(target) = $(beginGlue) ;
101	LINK_END_GLUE on $(target) = $(endGlue) ;
102	Depends $(target) : $(beginGlue) $(endGlue) ;
103
104	# compile and link
105	SetupKernel $(sources) : $(TARGET_KERNEL_PIC_FLAGS) ;
106	local linkFlags = -nostdlib -Xlinker -soname=\"$(target)\" ;
107	LINKFLAGS on $(target) = [ on $(target) return $(LINKFLAGS) ] $(linkFlags) ;
108	Main $(target) : $(sources) ;
109	LinkAgainst $(target) : $(libs) $(kernel) ;
110}
111
112rule KernelMergeObject
113{
114	# KernelMergeObject <name> : <sources> : <extra CFLAGS> : <other objects> ;
115	# Compiles source files and merges the object files to an object file.
116	# <name>: Name of the object file to create. No grist will be added.
117	# <sources>: Sources to be compiled. Grist will be added.
118	# <extra CFLAGS>: Additional flags for compilation.
119	# <other objects>: Object files or static libraries to be merged. No grist
120	#                  will be added.
121	#
122
123	SetupKernel $(2) : $(3) ;
124	Objects $(2) ;
125	MergeObjectFromObjects $(1) : $(2:S=$(SUFOBJ)) : $(4) ;
126}
127
128rule KernelStaticLibrary
129{
130	# Usage KernelStaticLibrary <name> : <sources> : <extra cc flags>  ;
131	# This is designed to take a set of sources and libraries and create
132	# a file called lib<name>.a
133
134	SetupKernel $(2) : $(3) ;
135	Library $(1) : $(2) ;
136}
137
138rule KernelStaticLibraryObjects
139{
140	# Usage KernelStaticLibrary <name> : <sources> ;
141	# This is designed to take a set of sources and libraries and create
142	# a file called <name>
143
144	# Show that we depend on the libraries we need
145	SetupKernel $(2) ;
146	LocalClean clean : $(1) ;
147	LocalDepends all : $(1) ;
148	Depends $(1) : $(2) ;
149
150	MakeLocateDebug $(1) ;
151}
152
153actions KernelStaticLibraryObjects
154{
155	$(HAIKU_AR) -r "$(1)" "$(2)" ;
156}
157