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