xref: /haiku/Jamrules (revision 089a06291664995b4dbc64cc3946835c774e1098)
19eea4522SIngo Weinhold# Vanilla Jam compatibility
29eea4522SIngo Weinholdif ! $(INVOCATION_SUBDIR_SET) {
39eea4522SIngo Weinhold
49eea4522SIngo Weinhold	rule FIsPrefix
59eea4522SIngo Weinhold	{
69eea4522SIngo Weinhold		# FIsPrefix <a> : <b> ;
79eea4522SIngo Weinhold		# Returns true, if list <a> is a prefix (a proper one or equal) of
89eea4522SIngo Weinhold		# list <b>, an empty list otherwise.
99eea4522SIngo Weinhold		local a = $(1) ;
109eea4522SIngo Weinhold		local b = $(2) ;
119eea4522SIngo Weinhold		while $(a) && $(a[1]) = $(b[1]) {
129eea4522SIngo Weinhold			a = $(a[2-]) ;
139eea4522SIngo Weinhold			b = $(b[2-]) ;
149eea4522SIngo Weinhold		}
159eea4522SIngo Weinhold
169eea4522SIngo Weinhold		if $(a) {
179eea4522SIngo Weinhold			return ;
189eea4522SIngo Weinhold		} else {
199eea4522SIngo Weinhold			return true ;
209eea4522SIngo Weinhold		}
219eea4522SIngo Weinhold	}
229eea4522SIngo Weinhold
239eea4522SIngo Weinhold	rule LocalClean { Clean $(1) : $(2) ; }
249eea4522SIngo Weinhold
259eea4522SIngo Weinhold	rule LocalDepends { Depends $(1) : $(2) ; }
269eea4522SIngo Weinhold
279eea4522SIngo Weinhold} # vanilla Jam compatibility
289eea4522SIngo Weinhold
299eea4522SIngo Weinhold
3052a38012Sejakowatz# Include BuildConfig
3152a38012Sejakowatz{
3252a38012Sejakowatz	local buildConfig = [ GLOB $(OBOS_TOP) : BuildConfig ] ;
3352a38012Sejakowatz	if ! $(buildConfig)
3452a38012Sejakowatz	{
3552a38012Sejakowatz		EXIT "No BuildConfig!"
3652a38012Sejakowatz			 "Run ./configure in the source tree's root directory first!" ;
3752a38012Sejakowatz	}
3852a38012Sejakowatz	include $(buildConfig) ;
3952a38012Sejakowatz}
4052a38012Sejakowatz
41a6c008e1Sbeveloper# We do not include any local BeOS system headers by default
42a6c008e1SbeveloperCCFLAGS += " -nostdinc" ;
43a6c008e1SbeveloperC++FLAGS += " -nostdinc" ;
44a6c008e1Sbeveloper
4552a38012Sejakowatz# Determine if we're building on PPC or x86
4652a38012Sejakowatz# Determine mimetype of executable
4752a38012Sejakowatz# Cross compiling can come later
4852a38012Sejakowatz
4952a38012Sejakowatzif $(METROWERKS) {
5078599cf0SIngo Weinhold	OBOS_TARGET ?= "ppc.R1" ;
5152a38012Sejakowatz	OBOS_TARGET_TYPE ?= "application/x-be-executable" ;
5252a38012Sejakowatz	OBOS_ARCH ?= "ppc" ;
5352a38012Sejakowatz	OBOS_TARGET_DEFINE ?= "ARCH_ppc" ;
5452a38012Sejakowatz} else {
5578599cf0SIngo Weinhold	OBOS_TARGET ?= "x86.R1" ;
5652a38012Sejakowatz	OBOS_TARGET_TYPE ?= "application/x-vnd.Be-elfexecutable" ;
5752a38012Sejakowatz	OBOS_ARCH ?= "x86" ;
5852a38012Sejakowatz	OBOS_TARGET_DEFINE ?= "ARCH_x86" ;
5952a38012Sejakowatz	OBOS_TARGET_DIR ?= "x86" ;
6052a38012Sejakowatz}
6152a38012Sejakowatz
62e5dc2d93Sbeveloper# Enable warnings only if WARNINGS is defined
63e5dc2d93Sbeveloper# Should be enabled by default later
6496d27465SIngo Weinhold#
65e5dc2d93Sbeveloperif $(WARNINGS) {
66e5dc2d93Sbeveloper	# For an explanation of the different warning options, see:
67e5dc2d93Sbeveloper	# http://gcc.gnu.org/onlinedocs/gcc-2.95.3/gcc_2.html
68e5dc2d93Sbeveloper	# to get even more warnings, add:
69e5dc2d93Sbeveloper	# -Wwrite-strings  	(doesn't work well with some Be headers)
70e5dc2d93Sbeveloper	# -Wundef			(dito)
71e5dc2d93Sbeveloper	# -Wconversion		(gets you many warnings about implicit conversions)
72e5dc2d93Sbeveloper	# -W				(gets you even more warnigs)
73a6c008e1Sbeveloper	CCFLAGS += "-Wall -Wno-multichar -Wmissing-prototypes" ;
74e5dc2d93Sbeveloper	CCFLAGS += "-Wpointer-arith -Wcast-align -Wsign-compare" ;
75a6c008e1Sbeveloper	C++FLAGS += "-Wall -Wno-multichar -Wmissing-prototypes -Wno-ctor-dtor-privacy -Woverloaded-virtual" ;
76e5dc2d93Sbeveloper	C++FLAGS += "-Wpointer-arith -Wcast-align -Wsign-compare" ;
77e5dc2d93Sbeveloper}
78e5dc2d93Sbeveloper
799eea4522SIngo Weinhold# We might later want to introduce debug levels or handle the whole issue
809eea4522SIngo Weinhold# differently. For now there's only on or off.
819eea4522SIngo Weinhold#
829eea4522SIngo Weinholdif $(DEBUG) {
839eea4522SIngo Weinhold	OPTIM ?= -O0 ;
849eea4522SIngo Weinhold	CCFLAGS += -g ;
859eea4522SIngo Weinhold	C++FLAGS += -g ;
869eea4522SIngo Weinhold	LINKFLAGS += -g ;
879eea4522SIngo Weinhold} else {
889eea4522SIngo Weinhold	OPTIM ?= -O2 ;
899eea4522SIngo Weinhold}
9096d27465SIngo Weinhold#
9196d27465SIngo Weinhold# To disable for the tests OPTIM and DEBUG are overridden, set the environment
9296d27465SIngo Weinhold# variable NO_TEST_DEBUG.
939eea4522SIngo Weinhold
9452a38012SejakowatzKERNEL_CCFLAGS ?= "-Wall -Wno-multichar -Wmissing-prototypes -finline -nostdinc" ;
9552a38012SejakowatzKERNEL_CCFLAGS += "-fno-builtin -D$(OBOS_TARGET_DEFINE) " ;
96405439beSbeveloperKERNEL_CCFLAGS += "-DBOCHS_DEBUG_HACK=$(BOCHS_DEBUG_HACK) " ;
9752a38012Sejakowatz
9816fa4445SIngo Weinhold# Instructs the Library rule to not make its object files temporary.
9916fa4445SIngo Weinhold# This is need as some objects are used in a static library and for an
10016fa4445SIngo Weinhold# executable.
10116fa4445SIngo WeinholdKEEPOBJS = true ;
10216fa4445SIngo Weinhold
10352a38012SejakowatzAR = ar r ;
10452a38012Sejakowatz
10552a38012Sejakowatz# If no OBOS_OBJECT_TARGET is not defined yet, use our default directory and
10652a38012Sejakowatz# include our "OBOS_TARGET" as subdirectory in there (to prevent different
10752a38012Sejakowatz# builds mixing objects from different targets).
10852a38012Sejakowatzif ! $(OBOS_OBJECT_TARGET) {
10952a38012Sejakowatz	OBOS_OBJECT_TARGET ?= [ FDirName $(OBOS_TOP) objects $(OBOS_TARGET) ] ;
11052a38012Sejakowatz}
11152a38012Sejakowatz
11252a38012Sejakowatz# If no OBOS_DISTRO_TARGET is not defined yet, use our default directory and
11352a38012Sejakowatz# include our "OBOS_TARGET" as subdirectory in there (to prevent different
11452a38012Sejakowatz# builds mixing executables from different targets).
11552a38012Sejakowatzif ! $(OBOS_DISTRO_TARGET) {
11652a38012Sejakowatz	OBOS_DISTRO_TARGET ?= [ FDirName $(OBOS_TOP) distro $(OBOS_TARGET) ] ;
11752a38012Sejakowatz}
11852a38012Sejakowatz
11952a38012Sejakowatz# Set our version number if not already set and mark it as a developer build
12052a38012Sejakowatzif ! $(OBOS_BUILD_VERSION) {
12152a38012Sejakowatz	OBOS_BUILD_VERSION ?= "1 0 0 a 1" ;
12252a38012Sejakowatz	OBOS_BUILD_DESCRIPTION ?= "Developer Build" ;
12352a38012Sejakowatz}
12452a38012Sejakowatz
12552a38012Sejakowatz# If OBOS_BUILD_VERSION is set, but OBOS_BUILD_DESCRIPTION isn't, mark it as
12652a38012Sejakowatz# an unknown build.
12752a38012Sejakowatzif ! $(OBOS_BUILD_DESCRIPTION) {
12852a38012Sejakowatz	OBOS_BUILD_DESCRIPTION ?= "Unknown Build" ;
12952a38012Sejakowatz}
13052a38012Sejakowatz
13152a38012Sejakowatz# Relative subdirs for distro dir (these are for *INTERNAL* use by the following rules only!)
1325f281ed5SejakowatzOBOS_APPS_DIR   ?= [ FDirName $(OBOS_DISTRO_TARGET) beos apps ] ;
133f06de7f3SIngo WeinholdOBOS_BIN_DIR    ?= [ FDirName $(OBOS_DISTRO_TARGET) beos bin ] ;
13452a38012SejakowatzOBOS_PREFS_DIR  ?= [ FDirName $(OBOS_DISTRO_TARGET) beos preferences ] ;
13552a38012SejakowatzOBOS_SERVER_DIR ?= [ FDirName $(OBOS_DISTRO_TARGET) beos system servers ] ;
13652a38012SejakowatzOBOS_ADDON_DIR  ?= [ FDirName $(OBOS_DISTRO_TARGET) beos system add-ons ] ;
13752a38012SejakowatzOBOS_SHLIB_DIR  ?= [ FDirName $(OBOS_DISTRO_TARGET) beos system lib ] ;
13852a38012SejakowatzOBOS_STLIB_DIR  ?= [ FDirName $(OBOS_DISTRO_TARGET) beos system lib ] ;
13952a38012SejakowatzOBOS_KERNEL_DIR ?= [ FDirName $(OBOS_DISTRO_TARGET) beos system ] ;
14052a38012SejakowatzOBOS_TEST_DIR   ?= [ FDirName $(OBOS_TOP) tests ] ;
14152a38012Sejakowatz
14252a38012SejakowatzOBOS_KERNEL_CONFIG = config.$(OBOS_ARCH).ini ;
14352a38012SejakowatzOBOS_KERNEL = kernel.$(OBOS_ARCH) ;
14452a38012SejakowatzOBOS_FLOPPY = floppy.$(OBOS_ARCH) ;
14552a38012Sejakowatz
14652a38012Sejakowatzrule SetupIncludes
14752a38012Sejakowatz{
148a6c008e1Sbeveloper	# XXX add "mail" and "opengl" later
14928d2a30eSDaniel Reinhold	local os_includes = add-ons add-ons/file_system add-ons/graphics add-ons/input_server add-ons/screen_saver add-ons/tracker app device drivers game interface kernel media midi midi2 net storage support translation ;
150a6c008e1Sbeveloper
15128d2a30eSDaniel Reinhold	# Overwrite any exiting content when changing HDRS. This rule may be invoked multiple times.
152a6c008e1Sbeveloper
153a6c008e1Sbeveloper	# Use headers directory, to allow to do things like include <posix/string.h>
15428d2a30eSDaniel Reinhold	HDRS = [ FDirName $(OBOS_TOP) headers ] ;
155a6c008e1Sbeveloper
156a6c008e1Sbeveloper	# Use posix headers directory
15728d2a30eSDaniel Reinhold	HDRS += [ FDirName $(OBOS_TOP) headers posix ] ;
158a6c008e1Sbeveloper
159a6c008e1Sbeveloper	# Use public OS header directories
16028d2a30eSDaniel Reinhold	HDRS += [ PublicHeaders $(os_includes) ] ;
161a6c008e1Sbeveloper
162a6c008e1Sbeveloper	# Used as a fallback, the R5 header directories (we should remove this as soon as possible)
16328d2a30eSDaniel Reinhold	HDRS += /boot/develop/headers/posix /boot/develop/headers/cpp ;
16452a38012Sejakowatz}
16552a38012Sejakowatz
16652a38012Sejakowatz#-------------------------------------------------------------------------------
16752a38012Sejakowatz# Things Jam needs in order to work :)
16852a38012Sejakowatz#-------------------------------------------------------------------------------
16952a38012Sejakowatz
17052a38012Sejakowatzrule UserObject
17152a38012Sejakowatz{
17252a38012Sejakowatz	switch $(2)
17352a38012Sejakowatz	{
17452a38012Sejakowatz	case *.S    : assemble $(1) : $(2) ;
17508125d07SIngo Weinhold	case *.o    : return ;
17652a38012Sejakowatz	case *      : ECHO "unknown suffix on" $(2) ;
17752a38012Sejakowatz	}
17852a38012Sejakowatz}
17952a38012Sejakowatz
18052a38012Sejakowatz# Override the default to give "prettier" command lines.
18152a38012Sejakowatzactions Cc
18252a38012Sejakowatz{
1830931b8f9SIngo Weinhold	$(CC) -c "$(2)" $(CCFLAGS) $(CCDEFS) $(CCHDRS) -o "$(1)" ;
18452a38012Sejakowatz}
18552a38012Sejakowatz
18652a38012Sejakowatzactions C++
18752a38012Sejakowatz{
1880931b8f9SIngo Weinhold	$(C++) -c "$(2)" $(C++FLAGS) $(CCDEFS) $(CCHDRS) -o "$(1)" ;
18952a38012Sejakowatz}
19052a38012Sejakowatz
19152a38012Sejakowatz
19252a38012Sejakowatz#-------------------------------------------------------------------------------
19352a38012Sejakowatz# General High-level OBOS target rules
19452a38012Sejakowatz#-------------------------------------------------------------------------------
19552a38012Sejakowatz
1965f281ed5Sejakowatzrule App
1975f281ed5Sejakowatz{
1985f281ed5Sejakowatz	# App <name> : <sources> ;
199a6c008e1Sbeveloper	SetupIncludes ;
2005f281ed5Sejakowatz	SetupObjectsDir ;
2015f281ed5Sejakowatz	Main $(<) : $(>) ;
2025f281ed5Sejakowatz	MakeLocate $(<) : $(OBOS_APPS_DIR) ;
2035f281ed5Sejakowatz}
2045f281ed5Sejakowatz
205f06de7f3SIngo Weinholdrule BinCommand
206f06de7f3SIngo Weinhold{
207f06de7f3SIngo Weinhold	# BinCommand <name> : <sources> : <libraries> ;
208a6c008e1Sbeveloper	SetupIncludes ;
209f06de7f3SIngo Weinhold	SetupObjectsDir ;
210f06de7f3SIngo Weinhold	Main $(1) : $(2) ;
211f06de7f3SIngo Weinhold	MakeLocate $(1) : $(OBOS_BIN_DIR) ;
212f06de7f3SIngo Weinhold	LinkSharedOSLibs $(1) : $(3) ;
213f06de7f3SIngo Weinhold}
214f06de7f3SIngo Weinhold
215f06de7f3SIngo Weinholdrule StdBinCommands
216f06de7f3SIngo Weinhold{
217f06de7f3SIngo Weinhold	# StdBinCommands <sources> : <libs> ;
218a6c008e1Sbeveloper	SetupIncludes ;
219a6c008e1Sbeveloper	SetupObjectsDir ;
220f06de7f3SIngo Weinhold	local libs = $(2) ;
2219342c27aSIngo Weinhold	local source ;
222f06de7f3SIngo Weinhold	for source in $(1)
223f06de7f3SIngo Weinhold	{
224f06de7f3SIngo Weinhold		local target = $(source:S=) ;
225f06de7f3SIngo Weinhold		target = [ FGristFiles $(target) ] ;
226a6c008e1Sbeveloper
2273b4190abSbeveloper		BinCommand $(target) : $(source) : $(libs) ;
228f06de7f3SIngo Weinhold	}
229f06de7f3SIngo Weinhold}
230f06de7f3SIngo Weinhold
23152a38012Sejakowatzrule Preference
23252a38012Sejakowatz{
23352a38012Sejakowatz	# Preference <name> : <sources> ;
234a6c008e1Sbeveloper	SetupIncludes ;
23552a38012Sejakowatz	SetupObjectsDir ;
23652a38012Sejakowatz	Main $(<) : $(>) ;
23752a38012Sejakowatz	MakeLocate $(<) : $(OBOS_PREFS_DIR) ;
23852a38012Sejakowatz}
23952a38012Sejakowatz
24052a38012Sejakowatzrule Server
24152a38012Sejakowatz{
24252a38012Sejakowatz	# Server <name> : <sources> ;
24352a38012Sejakowatz
244a6c008e1Sbeveloper	SetupIncludes ;
24552a38012Sejakowatz	SetupObjectsDir ;
24652a38012Sejakowatz	Main $(<) : $(>) ;
24752a38012Sejakowatz	MakeLocate $(<) : $(OBOS_SERVER_DIR) ;
24852a38012Sejakowatz}
24952a38012Sejakowatz
25052a38012Sejakowatz# test pseudo targets
25152a38012SejakowatzNOTFILE obostests ;
25252a38012SejakowatzNOTFILE r5tests ;
25352a38012Sejakowatz
254d1f6c38fSTyler Dauwalderrule CommonTestLib
255d1f6c38fSTyler Dauwalder{
256c5ff4aa6STyler Dauwalder	# CommonTestLib <target> : <sources> : <obos libraries>
2579285de51STyler Dauwalder	#	: <r5 libraries> : <test libraries> : <public headers>;
258d1f6c38fSTyler Dauwalder	# Builds a unit test for both OBOS and R5 modules.
259d1f6c38fSTyler Dauwalder	# <target> The name of the target.
260d1f6c38fSTyler Dauwalder	# <sources> The list of sources.
261d1f6c38fSTyler Dauwalder	# <obos libraries> A list of link libraries for the OBOS tests (as passed
262d1f6c38fSTyler Dauwalder	# to LinkSharedOSLibs).
263d1f6c38fSTyler Dauwalder	# <r5 libraries> A list of link libraries for the R5 tests (as passed
264d1f6c38fSTyler Dauwalder	# to LinkSharedOSLibs).
2659285de51STyler Dauwalder	# <test libraries> A list of link libraries for both OBOS tests and R5 tests
2669285de51STyler Dauwalder	# that have a common name (i.e. specify libx.so and the OBOS tests will link
2679285de51STyler Dauwalder	# to libx.so and the R5 tests will link to libx_r5.so).
268d1f6c38fSTyler Dauwalder	# <public headers> A list of public header dirs (as passed to
269d1f6c38fSTyler Dauwalder	# UsePublicHeaders).
270d1f6c38fSTyler Dauwalder
271c5ff4aa6STyler Dauwalder	TestLib $(1) : $(2) : [ FDirName $(OBOS_TEST_DIR) unittester lib ] : $(3) $(5) : $(6) ;
272c5ff4aa6STyler Dauwalder	R5TestLib $(1) : $(2) : [ FDirName $(OBOS_TEST_DIR) unittester_r5 lib ] : $(4) [ R5SharedLibraryNames $(5) ] ;
273d1f6c38fSTyler Dauwalder}
274d1f6c38fSTyler Dauwalder
275d1f6c38fSTyler Dauwalderrule TestLib
276d1f6c38fSTyler Dauwalder{
277d1f6c38fSTyler Dauwalder	# TestLib <target> : <sources> : <dest> : <libraries> : <public headers>
278d1f6c38fSTyler Dauwalder	# Builds a unit test library for an OBOS module.
279d1f6c38fSTyler Dauwalder	# <target> The name of the target.
280d1f6c38fSTyler Dauwalder	# <sources> The list of sources.
281d1f6c38fSTyler Dauwalder	# <dest> The directory for the target (as passed to FDirName).
282d1f6c38fSTyler Dauwalder	# <libraries> A list of link libraries (as passed to LinkSharedOSLibs).
283d1f6c38fSTyler Dauwalder	# <public headers> A list of public header dirs (as passed to
284d1f6c38fSTyler Dauwalder	# UsePublicHeaders).
285d1f6c38fSTyler Dauwalder
286d1f6c38fSTyler Dauwalder	local target = $(1) ;
287d1f6c38fSTyler Dauwalder	local sources = $(2) ;
288d1f6c38fSTyler Dauwalder	local dest = $(3) ;
289d1f6c38fSTyler Dauwalder	local libraries = $(4) ;
290d1f6c38fSTyler Dauwalder	local headerDirs = $(5) ;
2919342c27aSIngo Weinhold	local objects = [ FGristFiles $(sources:S=$(SUFOBJ)) ] ;
292d1f6c38fSTyler Dauwalder
29328d2a30eSDaniel Reinhold	SetupIncludes ;
29428d2a30eSDaniel Reinhold
2959342c27aSIngo Weinhold	# Our Main replacement.
2969342c27aSIngo Weinhold	MainFromObjects $(target) : $(objects) ;
2979342c27aSIngo Weinhold	TestObjects $(sources) : $(headerDirs) ;
298d1f6c38fSTyler Dauwalder
299d1f6c38fSTyler Dauwalder	MakeLocate $(target) : $(dest) ;
3000d1cdd94SIngo Weinhold	Depends $(target) : libcppunit.so ;
3010d1cdd94SIngo Weinhold	Depends obostests : $(target) ;
302d1f6c38fSTyler Dauwalder	LinkSharedOSLibs $(target) : libcppunit.so $(libraries) ;
303d1f6c38fSTyler Dauwalder	LINKFLAGS on $(target) = $(LINKFLAGS) -nostart -Xlinker -soname=\"$(target)\" ;
304d1f6c38fSTyler Dauwalder}
305d1f6c38fSTyler Dauwalder
306d1f6c38fSTyler Dauwalderrule R5TestLib
307d1f6c38fSTyler Dauwalder{
308c5ff4aa6STyler Dauwalder	# R5TestLib <target> : <sources> : <dest> : <libraries>
309d1f6c38fSTyler Dauwalder	# Builds a unit test for an R5 module. "_r5" is appended to the object
310d1f6c38fSTyler Dauwalder	# and the target name.
311d1f6c38fSTyler Dauwalder	# <target> The name of the target.
312d1f6c38fSTyler Dauwalder	# <sources> The list of sources.
313d1f6c38fSTyler Dauwalder	# <dest> The directory for the target (as passed to FDirName).
314d1f6c38fSTyler Dauwalder	# <libraries> A list of link libraries (as passed to LinkSharedOSLibs).
315d1f6c38fSTyler Dauwalder
316d1f6c38fSTyler Dauwalder	local target = $(1:B)_r5$(1:S) ;
317d1f6c38fSTyler Dauwalder	local sources = $(2) ;
318c5ff4aa6STyler Dauwalder	local dest = $(3) ;
319d1f6c38fSTyler Dauwalder	local libraries = $(4) ;
320d1f6c38fSTyler Dauwalder	local objects = [ R5ObjectNames $(sources) ] ;
321d1f6c38fSTyler Dauwalder
32228d2a30eSDaniel Reinhold	SetupIncludes ;
32328d2a30eSDaniel Reinhold
324d1f6c38fSTyler Dauwalder	# Our Main replacement.
325d1f6c38fSTyler Dauwalder	MainFromObjects $(target) : $(objects) ;
3269342c27aSIngo Weinhold	TestObjects $(sources) : : true ;
327d1f6c38fSTyler Dauwalder
328d1f6c38fSTyler Dauwalder	MakeLocate $(target) : $(dest) ;
3290d1cdd94SIngo Weinhold	Depends $(target) : libcppunit.so ;
3300d1cdd94SIngo Weinhold	Depends r5tests : $(target) ;
331d1f6c38fSTyler Dauwalder	LinkSharedOSLibs $(target) : libcppunit.so $(libraries) ;
332d1f6c38fSTyler Dauwalder	LINKFLAGS on $(target) = $(LINKFLAGS) -nostart -Xlinker -soname=\"$(target)\" ;
333d1f6c38fSTyler Dauwalder}
334d1f6c38fSTyler Dauwalder
33552a38012Sejakowatzrule CommonUnitTest
33652a38012Sejakowatz{
33752a38012Sejakowatz	# CommonUnitTest <target> : <sources> : <dest> : <obos libraries>
33852a38012Sejakowatz	#	: <r5 libraries> : <public headers>;
33952a38012Sejakowatz	# Builds a unit test for both OBOS and R5 modules.
34052a38012Sejakowatz	# <target> The name of the target.
34152a38012Sejakowatz	# <sources> The list of sources.
34252a38012Sejakowatz	# <dest> The directory for the target (as passed to FDirName).
34352a38012Sejakowatz	# <obos libraries> A list of link libraries for the OBOS tests (as passed
34452a38012Sejakowatz	# to LinkSharedOSLibs).
34552a38012Sejakowatz	# <r5 libraries> A list of link libraries for the R5 tests (as passed
34652a38012Sejakowatz	# to LinkSharedOSLibs).
34752a38012Sejakowatz	# <public headers> A list of public header dirs (as passed to
34852a38012Sejakowatz	# UsePublicHeaders).
34952a38012Sejakowatz
35052a38012Sejakowatz	UnitTest $(1) : $(2) : $(3) : $(4) : $(6) ;
35152a38012Sejakowatz	R5UnitTest $(1) : $(2) : $(3) : $(5) ;
35252a38012Sejakowatz}
35352a38012Sejakowatz
35452a38012Sejakowatzrule UnitTest
35552a38012Sejakowatz{
35652a38012Sejakowatz	# UnitTest <target> : <sources> : <dest> : <libraries> : <public headers>
35752a38012Sejakowatz	# Builds a unit test for an OBOS module.
35852a38012Sejakowatz	# <target> The name of the target.
35952a38012Sejakowatz	# <sources> The list of sources.
36052a38012Sejakowatz	# <dest> The directory for the target (as passed to FDirName).
36152a38012Sejakowatz	# <libraries> A list of link libraries (as passed to LinkSharedOSLibs).
36252a38012Sejakowatz	# <public headers> A list of public header dirs (as passed to
36352a38012Sejakowatz	# UsePublicHeaders).
36452a38012Sejakowatz
36552a38012Sejakowatz	local target = $(1) ;
36652a38012Sejakowatz	local sources = $(2) ;
36752a38012Sejakowatz	local dest = $(3) ;
36852a38012Sejakowatz	local libraries = $(4) ;
36952a38012Sejakowatz	local headerDirs = $(5) ;
3709342c27aSIngo Weinhold	local objects = [ FGristFiles $(sources:S=$(SUFOBJ)) ] ;
37152a38012Sejakowatz
37228d2a30eSDaniel Reinhold	SetupIncludes ;
37328d2a30eSDaniel Reinhold
3749342c27aSIngo Weinhold	# Our Main replacement.
3759342c27aSIngo Weinhold	MainFromObjects $(target) : $(objects) ;
3769342c27aSIngo Weinhold	TestObjects $(sources) : $(headerDirs) ;
3773b9eae39SIngo Weinhold
37852a38012Sejakowatz	MakeLocate $(target) : [ FDirName $(OBOS_TEST_DIR) $(dest) ] ;
3799eea4522SIngo Weinhold	Depends $(target) : libcppunit.so ;
3809eea4522SIngo Weinhold	Depends obostests : $(target) ;
38152a38012Sejakowatz	LinkSharedOSLibs $(target) : libcppunit.so $(libraries) ;
38252a38012Sejakowatz}
38352a38012Sejakowatz
38452a38012Sejakowatzrule R5UnitTest
38552a38012Sejakowatz{
38652a38012Sejakowatz	# R5UnitTest <target> : <sources> : <dest> : <libraries>
38752a38012Sejakowatz	# Builds a unit test for an R5 module. "_r5" is appended to the object
38852a38012Sejakowatz	# and the target name.
38952a38012Sejakowatz	# <target> The name of the target.
39052a38012Sejakowatz	# <sources> The list of sources.
39152a38012Sejakowatz	# <dest> The directory for the target (as passed to FDirName).
39252a38012Sejakowatz	# <libraries> A list of link libraries (as passed to LinkSharedOSLibs).
39352a38012Sejakowatz
39452a38012Sejakowatz	local target = $(1)_r5 ;
39552a38012Sejakowatz	local sources = $(2) ;
39652a38012Sejakowatz	local dest = $(3) ;
39752a38012Sejakowatz	local libraries = $(4) ;
39852a38012Sejakowatz	local objects = [ R5ObjectNames $(sources) ] ;
39952a38012Sejakowatz
40028d2a30eSDaniel Reinhold	SetupIncludes ;
40128d2a30eSDaniel Reinhold
40252a38012Sejakowatz	# Our Main replacement.
40352a38012Sejakowatz	MainFromObjects $(target) : $(objects) ;
4049342c27aSIngo Weinhold	TestObjects $(sources) : : true ;
40552a38012Sejakowatz
40652a38012Sejakowatz	MakeLocate $(target) : [ FDirName $(OBOS_TEST_DIR) $(dest) ] ;
4079eea4522SIngo Weinhold	Depends $(target) : libcppunit.so ;
4089eea4522SIngo Weinhold	Depends r5tests : $(target) ;
40952a38012Sejakowatz	LinkSharedOSLibs $(target) : libcppunit.so $(libraries) ;
41052a38012Sejakowatz}
41152a38012Sejakowatz
41252a38012Sejakowatzrule R5ObjectNames
41352a38012Sejakowatz{
41452a38012Sejakowatz	# R5ObjectNames <sources> ;
41552a38012Sejakowatz	# Returns a list of gristed object names given a list of source file names.
41652a38012Sejakowatz	# Moreover each object names gets "_r5" inserted before the object suffix.
41752a38012Sejakowatz	local objects = $(1:S=)_r5 ;
41852a38012Sejakowatz	return [ FGristFiles $(objects:S=$(SUFOBJ)) ] ;
41952a38012Sejakowatz}
42052a38012Sejakowatz
4219342c27aSIngo Weinholdrule R5Objects
4229342c27aSIngo Weinhold{
4239342c27aSIngo Weinhold	# R5Objects <sources>
4249342c27aSIngo Weinhold	# Similar to Objects, but appends "_r5" to the object file names.
4259342c27aSIngo Weinhold	# <sources> The source files.
4269342c27aSIngo Weinhold
4279342c27aSIngo Weinhold	local sources = $(1) ;
4289342c27aSIngo Weinhold	local source ;
4299342c27aSIngo Weinhold	for source in [ FGristFiles $(sources) ]
4309342c27aSIngo Weinhold	{
4319342c27aSIngo Weinhold		local object = [ R5ObjectNames $(source) ] ;
4329342c27aSIngo Weinhold		Object $(object) : $(source) ;
4339342c27aSIngo Weinhold		LocalDepends obj : $(object) ;
4349342c27aSIngo Weinhold	}
4359342c27aSIngo Weinhold}
4369342c27aSIngo Weinhold
4379342c27aSIngo Weinholdrule TestObjects
4389342c27aSIngo Weinhold{
4399342c27aSIngo Weinhold	# TestLib <sources> : <public headers> : <r5>
4409342c27aSIngo Weinhold	# Compiles objects for tests.
4419342c27aSIngo Weinhold	# <sources> The list of sources.
4429342c27aSIngo Weinhold	# <public headers> A list of public header dirs (as passed to
4439342c27aSIngo Weinhold	# UsePublicHeaders).
4449342c27aSIngo Weinhold	# <r5> If set, "_r5" is appended to the object file names and
4459342c27aSIngo Weinhold	# <public headers> is ignored. Furthermore the pre-processor macro
4469342c27aSIngo Weinhold	# TEST_R5 is defined, TEST_OBOS otherwise.
4479342c27aSIngo Weinhold
4489342c27aSIngo Weinhold	local sources = $(1) ;
4499342c27aSIngo Weinhold	local headerDirs = $(2) ;
4509342c27aSIngo Weinhold	local r5 = $(3) ;
4519342c27aSIngo Weinhold	local objects ;
4529342c27aSIngo Weinhold
4539342c27aSIngo Weinhold	# Turn optimization off.
45496d27465SIngo Weinhold	if ! $(NO_TEST_DEBUG) {
4559342c27aSIngo Weinhold		local optim = $(OPTIM) ;
4569342c27aSIngo Weinhold		OPTIM = ;
45796d27465SIngo Weinhold	}
4589342c27aSIngo Weinhold
45928d2a30eSDaniel Reinhold	SetupIncludes ;
4609342c27aSIngo Weinhold	SetupObjectsDir ;
4619342c27aSIngo Weinhold
4629342c27aSIngo Weinhold	# compile
4639342c27aSIngo Weinhold	if $(r5) {
4649342c27aSIngo Weinhold		objects = [ R5ObjectNames $(sources) ] ;
4659342c27aSIngo Weinhold		R5Objects $(sources) ;
4669342c27aSIngo Weinhold	} else {
4679342c27aSIngo Weinhold		objects = [ FGristFiles $(sources:S=$(SUFOBJ)) ] ;
4689342c27aSIngo Weinhold		Objects $(sources) ;
4699342c27aSIngo Weinhold	}
4709342c27aSIngo Weinhold
4719342c27aSIngo Weinhold	# set headers/defines
4729342c27aSIngo Weinhold	UseCppUnitObjectHeaders $(objects) ;
4739342c27aSIngo Weinhold	if $(r5) {
4749342c27aSIngo Weinhold		ObjectDefines $(objects) : TEST_R5 ;
4759342c27aSIngo Weinhold	} else {
4769342c27aSIngo Weinhold		UsePublicObjectHeaders $(objects) : $(headerDirs) ;
4779342c27aSIngo Weinhold		ObjectDefines $(objects) : TEST_OBOS ;
4789342c27aSIngo Weinhold	}
4799342c27aSIngo Weinhold
48096d27465SIngo Weinhold	if ! $(NO_TEST_DEBUG) {
4819342c27aSIngo Weinhold		# Turn debugging on. That is usually desired for test code.
4829342c27aSIngo Weinhold		ObjectCcFlags $(objects) : "-g" ;
4839342c27aSIngo Weinhold		ObjectC++Flags $(objects) : "-g" ;
4849342c27aSIngo Weinhold
4859342c27aSIngo Weinhold		# Turn optimization on again.
4869342c27aSIngo Weinhold		OPTIM = $(optim) ;
4879342c27aSIngo Weinhold	}
48896d27465SIngo Weinhold}
4899342c27aSIngo Weinhold
4909285de51STyler Dauwalderrule R5SharedLibraryNames
4919285de51STyler Dauwalder{
4929285de51STyler Dauwalder	# R5SharedLibraryNames <sources> ;
4939285de51STyler Dauwalder	# Returns a list of shared library names given a list of file names. NO
4949285de51STyler Dauwalder	# GRISTING IS PERFORMED :-) However, each library names gets "_r5" inserted
4959285de51STyler Dauwalder	# before the shared lib suffix.
4969285de51STyler Dauwalder	return $(1:S=)_r5.so ;
4979285de51STyler Dauwalder}
4989285de51STyler Dauwalder
4999fc6b2e1SIngo Weinholdrule SimpleTest
5009fc6b2e1SIngo Weinhold{
5019fc6b2e1SIngo Weinhold	# UnitTest <target> : <sources> : <libraries>
5029fc6b2e1SIngo Weinhold	# Builds a unit test for an OBOS module.
5039fc6b2e1SIngo Weinhold	# <target> The name of the target.
5049fc6b2e1SIngo Weinhold	# <sources> The list of sources.
5059fc6b2e1SIngo Weinhold	# <dest> The directory for the target (as passed to FDirName).
5069fc6b2e1SIngo Weinhold	# <libraries> A list of link libraries (as passed to LinkSharedOSLibs).
5079fc6b2e1SIngo Weinhold	# <public headers> A list of public header dirs (as passed to
5089fc6b2e1SIngo Weinhold	# UsePublicHeaders).
5099fc6b2e1SIngo Weinhold
5109fc6b2e1SIngo Weinhold	local target = $(1) ;
5119fc6b2e1SIngo Weinhold	local sources = $(2) ;
5129fc6b2e1SIngo Weinhold	local libraries = $(3) ;
5139fc6b2e1SIngo Weinhold	local relPath = [ FRelPath src tests : $(SUBDIR_TOKENS) ] ;
5149fc6b2e1SIngo Weinhold
5159fc6b2e1SIngo Weinhold	# Turn optimization off.
51696d27465SIngo Weinhold	if ! $(NO_TEST_DEBUG) {
5179fc6b2e1SIngo Weinhold		local optim = $(OPTIM) ;
5189fc6b2e1SIngo Weinhold		OPTIM = ;
51996d27465SIngo Weinhold	}
5209fc6b2e1SIngo Weinhold
521a6c008e1Sbeveloper	SetupIncludes ;
5229fc6b2e1SIngo Weinhold	SetupObjectsDir ;
5239fc6b2e1SIngo Weinhold	MakeLocateObjects $(sources) ;
5249fc6b2e1SIngo Weinhold	Main $(target) : $(sources) ;
5259fc6b2e1SIngo Weinhold	MakeLocate $(target) : [ FDirName $(OBOS_TEST_DIR) $(relPath) ] ;
5269eea4522SIngo Weinhold	Depends obostests : $(target) ;
5279fc6b2e1SIngo Weinhold	LinkSharedOSLibs $(target) : $(libraries) ;
5289fc6b2e1SIngo Weinhold	ObjectDefines $(sources) : TEST_OBOS ;
5299fc6b2e1SIngo Weinhold
53096d27465SIngo Weinhold	if ! $(NO_TEST_DEBUG) {
5319fc6b2e1SIngo Weinhold		# Turn debugging on. That is usually desired for test code.
5329fc6b2e1SIngo Weinhold		ObjectCcFlags $(sources) : "-g" ;
5339fc6b2e1SIngo Weinhold		ObjectC++Flags $(sources) : "-g" ;
5349fc6b2e1SIngo Weinhold
5359fc6b2e1SIngo Weinhold		# Turn optimization on again.
5369fc6b2e1SIngo Weinhold		OPTIM = $(optim) ;
5379fc6b2e1SIngo Weinhold	}
53896d27465SIngo Weinhold}
5399fc6b2e1SIngo Weinhold
54052a38012Sejakowatzrule Addon
54152a38012Sejakowatz{
5427a384fdeSIngo Weinhold	# Addon <name> : <relpath> : <sources> : <is executable> ;
5437a384fdeSIngo Weinhold	# <name>: Name of the add-on.
5447a384fdeSIngo Weinhold	# <relpath>: Path where the add-on shall live relative to the add-on dir.
5457a384fdeSIngo Weinhold	# <sources>: Source files.
5467a384fdeSIngo Weinhold	# <is executable>: true, if the target shall be executable as well
5477a384fdeSIngo Weinhold
5487a384fdeSIngo Weinhold	local isExecutable = $(4) ;
54952a38012Sejakowatz
550a6c008e1Sbeveloper	SetupIncludes ;
55152a38012Sejakowatz	SetupObjectsDir ;
55252a38012Sejakowatz	Main $(1) : $(3) ;
55352a38012Sejakowatz
55452a38012Sejakowatz	# Create output dir path for addon
55552a38012Sejakowatz	local targetdir;
55652a38012Sejakowatz	targetdir = [ FDirName $(OBOS_ADDON_DIR) $(2) ] ;
55752a38012Sejakowatz
55852a38012Sejakowatz	MakeLocate $(1) : $(targetdir) ;
5597a384fdeSIngo Weinhold
5607a384fdeSIngo Weinhold	local linkFlags = -Xlinker -soname=\"$(1)\" ;
5617a384fdeSIngo Weinhold	if $(isExecutable) != true {
5627a384fdeSIngo Weinhold		linkFlags = -nostart $(linkFlags) ;
5637a384fdeSIngo Weinhold	}
5647a384fdeSIngo Weinhold	LINKFLAGS on $(1) = [ on $(1) return $(LINKFLAGS) ] $(linkFlags) ;
565af28904fSIngo Weinhold}
566af28904fSIngo Weinhold
56758efc9d8SIngo Weinholdrule R5KernelAddon
568af28904fSIngo Weinhold{
56958efc9d8SIngo Weinhold	# R5KernelAddon <name> : <relpath> : <sources> ;
570af28904fSIngo Weinhold
571af28904fSIngo Weinhold	local sources = $(3) ;
572af28904fSIngo Weinhold
573af28904fSIngo Weinhold	Addon $(1) : $(2) : $(3) ;
574af28904fSIngo Weinhold	ObjectCcFlags $(sources) : -D_KERNEL_MODE=1 -no-fpic ;
575af28904fSIngo Weinhold	ObjectC++Flags $(sources) : -D_KERNEL_MODE=1 -no-fpic
576af28904fSIngo Weinhold								-fno-exceptions -fno-rtti ;
5779eea4522SIngo Weinhold	LINKFLAGS on $(1) = [ on $(1) return $(LINKFLAGS) ] -nostdlib ;
578af28904fSIngo Weinhold	LinkSharedOSLibs $(1) : /boot/develop/lib/x86/_KERNEL_ ;
57952a38012Sejakowatz}
58052a38012Sejakowatz
5814fb5add0SMatthew Wilberrule Translator
5824fb5add0SMatthew Wilber{
5834fb5add0SMatthew Wilber	# Translator <name> : <sources> ;
584a6c008e1Sbeveloper	SetupIncludes ;
5854fb5add0SMatthew Wilber	SetupObjectsDir ;
5864fb5add0SMatthew Wilber	Main $(1) : $(2) ;
5874fb5add0SMatthew Wilber
5884fb5add0SMatthew Wilber	# Create output dir path for translator
5894fb5add0SMatthew Wilber	local targetdir;
5904fb5add0SMatthew Wilber	targetdir = [ FDirName $(OBOS_ADDON_DIR) translators ] ;
5914fb5add0SMatthew Wilber	MakeLocate $(1) : $(targetdir) ;
5924fb5add0SMatthew Wilber}
5934fb5add0SMatthew Wilber
59452a38012Sejakowatz rule MakeLocateObjects
59552a38012Sejakowatz{
59621df5945SIngo Weinhold	# MakeLocateObjects <sources_or_objects> ;
59752a38012Sejakowatz
59821df5945SIngo Weinhold	local _objs = [ FGristFiles $(1:S=$(SUFOBJ)) ] ;
59952a38012Sejakowatz
60052a38012Sejakowatz	for o in $(_objs)
60152a38012Sejakowatz	{
60252a38012Sejakowatz		local dir = $(o:D) ;
60352a38012Sejakowatz		if $(dir) {
60452a38012Sejakowatz			MakeLocate $(o) : [ FDirName $(LOCATE_TARGET) $(dir) ] ;
60552a38012Sejakowatz		} else {
60652a38012Sejakowatz			MakeLocate $(o) : $(LOCATE_TARGET) ;
60752a38012Sejakowatz		}
60852a38012Sejakowatz	}
60952a38012Sejakowatz}
61052a38012Sejakowatz
61152a38012Sejakowatzrule StaticLibrary
61252a38012Sejakowatz{
61352a38012Sejakowatz	# StaticLibrary <name> : <sources> ;
61452a38012Sejakowatz
615a6c008e1Sbeveloper	SetupIncludes ;
61652a38012Sejakowatz	SetupObjectsDir ;
61752a38012Sejakowatz	MakeLocateObjects $(2) ;
61852a38012Sejakowatz	Library lib$(<).a : $(>) ;
61952a38012Sejakowatz	MakeLocate lib$(<).a : $(OBOS_STLIB_DIR) ;
62052a38012Sejakowatz}
62152a38012Sejakowatz
62221df5945SIngo Weinholdrule SharedLibraryFromObjects
62352a38012Sejakowatz{
62421df5945SIngo Weinhold	# SharedLibraryFromObjects <name> : <objects> ;
62552a38012Sejakowatz	local _lib = lib$(1).so ;
62621df5945SIngo Weinhold	MainFromObjects $(_lib) : $(2) ;
62752a38012Sejakowatz	MakeLocate $(_lib) : $(OBOS_SHLIB_DIR) ;
6289eea4522SIngo Weinhold	LINKFLAGS on $(_lib) = [ on $(_lib) return $(LINKFLAGS) ]
6299eea4522SIngo Weinhold						   -nostart -Xlinker -soname=\"$(_lib)\" ;
63052a38012Sejakowatz}
63152a38012Sejakowatz
63221df5945SIngo Weinholdrule SharedLibrary
63321df5945SIngo Weinhold{
63421df5945SIngo Weinhold	# SharedLibrary <name> : <sources> ;
635a6c008e1Sbeveloper	SetupIncludes ;
63621df5945SIngo Weinhold	SetupObjectsDir ;
63721df5945SIngo Weinhold	MakeLocateObjects $(2) ;
63821df5945SIngo Weinhold	Objects $(2) ;
63921df5945SIngo Weinhold	SharedLibraryFromObjects $(1) : $(2:S=$(SUFOBJ)) ;
64021df5945SIngo Weinhold}
64121df5945SIngo Weinhold
64252a38012Sejakowatzrule LinkSharedOSLibs
64352a38012Sejakowatz{
64452a38012Sejakowatz	# LinkSharedOSLibs <name> : <libs> ;
64552a38012Sejakowatz	# Valid elements for <libs> are e.g. "be" or "libopenbeos.so" or
6464236d490SIngo Weinhold	# "/boot/.../libfoo.so". If the basename starts with "lib" or the thingy
6474236d490SIngo Weinhold	# has a dirname or grist, it is added to the NEEDLIBS variable (i.e. the
6484236d490SIngo Weinhold	# file will be bound!), otherwise it is prefixed "-l" and added to
6494236d490SIngo Weinhold	# LINKLIBS.
65052a38012Sejakowatz
65152a38012Sejakowatz	for i in $(>)
65252a38012Sejakowatz	{
6534236d490SIngo Weinhold		local isfile = ;
6544236d490SIngo Weinhold		if $(i:D) || $(i:G) {
6554236d490SIngo Weinhold			isfile = true ;
6564236d490SIngo Weinhold		} else {
65752a38012Sejakowatz			switch $(i:B)
65852a38012Sejakowatz			{
6594236d490SIngo Weinhold				case lib*	: isfile = true ;
6604236d490SIngo Weinhold				case *		: isfile = ;
6614236d490SIngo Weinhold			}
6624236d490SIngo Weinhold		}
6634236d490SIngo Weinhold		if $(isfile) {
6649eea4522SIngo Weinhold			NEEDLIBS on $(1) = [ on $(1) return $(NEEDLIBS) ] $(i) ;
6659eea4522SIngo Weinhold			Depends $(1) : $(i) ;
6664236d490SIngo Weinhold		} else {
6679eea4522SIngo Weinhold			LINKLIBS on $(1) = [ on $(1) return $(LINKLIBS) ] -l$(i) ;
66852a38012Sejakowatz		}
66952a38012Sejakowatz	}
67052a38012Sejakowatz}
67152a38012Sejakowatz
67252a38012Sejakowatzrule LinkStaticOSLibs
67352a38012Sejakowatz{
67452a38012Sejakowatz	# LinkStaticOSLibs <name> : <libs> ;
67552a38012Sejakowatz
67652a38012Sejakowatz	for i in $(>)
67752a38012Sejakowatz	{
67852a38012Sejakowatz		LINKLIBS on $(<) = $(LINKLIBS) -l $(i) ;
67952a38012Sejakowatz	}
68052a38012Sejakowatz}
68152a38012Sejakowatz
68252a38012Sejakowatzrule AddResources
68352a38012Sejakowatz{
68452a38012Sejakowatz	# AddResources <name> : <resourcefiles> ;
68552a38012Sejakowatz
6869fc6b2e1SIngo Weinhold	SEARCH on $(2) += $(SEARCH_SOURCE) ;
68778599cf0SIngo Weinhold	RESFILES on $(1) += $(2) ;
68852a38012Sejakowatz}
68952a38012Sejakowatz
6907d7f280eSIngo Weinholdrule PublicHeaders
69152a38012Sejakowatz{
6927d7f280eSIngo Weinhold	# PublicHeaders <group list>
69352a38012Sejakowatz	#
6947d7f280eSIngo Weinhold	# Returns the directory names for the public header dirs identified by
6957d7f280eSIngo Weinhold	# <group list>.
69652a38012Sejakowatz
69752a38012Sejakowatz	local list = $(1) ;
698b005dbe3SAxel Dörfler	local dirs = [ FDirName $(OBOS_TOP) headers os ] ;
699b005dbe3SAxel Dörfler
70052a38012Sejakowatz	for i in $(list) {
7017d7f280eSIngo Weinhold		dirs += [ FDirName $(OBOS_TOP) headers os $(i) ] ;
7027d7f280eSIngo Weinhold	}
7037d7f280eSIngo Weinhold	return $(dirs) ;
70452a38012Sejakowatz}
70552a38012Sejakowatz
7067d7f280eSIngo Weinholdrule PrivateHeaders
7077d7f280eSIngo Weinhold{
7087d7f280eSIngo Weinhold	# PrivateHeaders <group list>
7097d7f280eSIngo Weinhold	#
7107d7f280eSIngo Weinhold	# Returns the directory names for the private header dirs identified by
7117d7f280eSIngo Weinhold	# <group list>.
7127d7f280eSIngo Weinhold
7137d7f280eSIngo Weinhold	local list = $(1) ;
7147d7f280eSIngo Weinhold	local dirs ;
7157d7f280eSIngo Weinhold	for i in $(list) {
7167d7f280eSIngo Weinhold		dirs += [ FDirName $(OBOS_TOP) headers private $(i) ] ;
7177d7f280eSIngo Weinhold	}
7187d7f280eSIngo Weinhold	return $(dirs) ;
7197d7f280eSIngo Weinhold}
7207d7f280eSIngo Weinhold
7217d7f280eSIngo Weinholdrule ArchHeaders
7227d7f280eSIngo Weinhold{
7237d7f280eSIngo Weinhold	# usage: ArchHeaders <arch> ;
7247d7f280eSIngo Weinhold	#
7257d7f280eSIngo Weinhold	# <arch> specifies the architecture (e.g. x86).
7267d7f280eSIngo Weinhold
7277d7f280eSIngo Weinhold	return [ FDirName $(OBOS_TOP) headers private kernel arch $(1) ] ;
7287d7f280eSIngo Weinhold}
7297d7f280eSIngo Weinhold
7307d7f280eSIngo Weinholdrule UsePublicHeaders
7317d7f280eSIngo Weinhold{
732a6c008e1Sbeveloper	# XXX changed to do nothing
7337d7f280eSIngo Weinhold}
7347d7f280eSIngo Weinhold
7357d7f280eSIngo Weinholdrule UsePublicObjectHeaders
7367d7f280eSIngo Weinhold{
7377d7f280eSIngo Weinhold	# UsePublicObjectHeaders <sources_or_objects> : <group list> ;
7387d7f280eSIngo Weinhold	#
7397d7f280eSIngo Weinhold	# Adds the public C header dirs given by <group list> to the header search
7407d7f280eSIngo Weinhold	# dirs of <sources_or_objects>.
7417d7f280eSIngo Weinhold	# NOTE: This rule must be invoked *after* the rule that builds the objects.
7427d7f280eSIngo Weinhold
7437d7f280eSIngo Weinhold	ObjectHdrs $(1) : [ PublicHeaders $(2) ] ;
74452a38012Sejakowatz}
74552a38012Sejakowatz
74652a38012Sejakowatzrule UsePrivateHeaders
74752a38012Sejakowatz{
7487d7f280eSIngo Weinhold	# UsePrivateHeaders <group list> ;
74952a38012Sejakowatz	#
75052a38012Sejakowatz	# Adds the private C header dirs given by <group list> to the header search
7517d7f280eSIngo Weinhold	# dirs of the subdirectory.
7527d7f280eSIngo Weinhold	# NOTE: This rule must be invoked *before* the rule that builds the objects.
75352a38012Sejakowatz
7547d7f280eSIngo Weinhold	UseHeaders [ PrivateHeaders $(1) ] ;
75552a38012Sejakowatz}
75652a38012Sejakowatz
7577d7f280eSIngo Weinholdrule UsePrivateObjectHeaders
7587d7f280eSIngo Weinhold{
7597d7f280eSIngo Weinhold	# UsePrivateObjectHeaders <sources_or_objects> : <group list> ;
7607d7f280eSIngo Weinhold	#
7617d7f280eSIngo Weinhold	# Adds the private C header dirs given by <group list> to the header search
7627d7f280eSIngo Weinhold	# dirs of <sources_or_objects>.
7637d7f280eSIngo Weinhold	# NOTE: This rule must be invoked *after* the rule that builds the objects.
7647d7f280eSIngo Weinhold
7657d7f280eSIngo Weinhold	ObjectHdrs $(1) : [ PrivateHeaders $(2) ] ;
76652a38012Sejakowatz}
76752a38012Sejakowatz
76852a38012Sejakowatzrule UseHeaders
76952a38012Sejakowatz{
7707d7f280eSIngo Weinhold	# UseHeaders <headers> ;
77152a38012Sejakowatz	#
77252a38012Sejakowatz	# Adds the C header dirs <headers> to the header search
7737d7f280eSIngo Weinhold	# dirs of the subdirectory.
7747d7f280eSIngo Weinhold	# NOTE: This rule must be invoked *before* the rule that builds the objects.
77552a38012Sejakowatz
7767d7f280eSIngo Weinhold	local header ;
7777d7f280eSIngo Weinhold	for header in $(1) {
77852a38012Sejakowatz		SubDirHdrs $(header) ;
77952a38012Sejakowatz	}
78052a38012Sejakowatz}
78152a38012Sejakowatz
78252a38012Sejakowatzrule UseCppUnitHeaders
78352a38012Sejakowatz{
7847d7f280eSIngo Weinhold	SubDirHdrs [ FDirName $(OBOS_TOP) headers tools cppunit ] ;
78552a38012Sejakowatz}
78652a38012Sejakowatz
787be5af1baSIngo Weinholdrule UseCppUnitObjectHeaders
788be5af1baSIngo Weinhold{
789be5af1baSIngo Weinhold	ObjectHdrs $(1) : [ FDirName $(OBOS_TOP) headers tools cppunit ] ;
790be5af1baSIngo Weinhold}
791be5af1baSIngo Weinhold
79252a38012Sejakowatzrule UseArchHeaders
79352a38012Sejakowatz{
7947d7f280eSIngo Weinhold	# usage: UseArchHeaders <arch> ;
7957d7f280eSIngo Weinhold	#
79652a38012Sejakowatz	# <arch> specifies the architecture (e.g. x86).
7977d7f280eSIngo Weinhold	# NOTE: This rule must be invoked *before* the rule that builds the objects.
7987d7f280eSIngo Weinhold
7997d7f280eSIngo Weinhold	local headers = [ ArchHeaders $(1) ] ;
80052a38012Sejakowatz	local opt = -D$(OBOS_TARGET_DEFINE) ;
801c633961aSIngo Weinhold
80252a38012Sejakowatz	SubDirCcFlags $(opt)  ;
80352a38012Sejakowatz	SubDirC++Flags $(opt)  ;
804*089a0629Sbeveloper	HDRS += $(headers) ;
805c633961aSIngo Weinhold}
806c633961aSIngo Weinhold
8077d7f280eSIngo Weinholdrule UseArchObjectHeaders
8087d7f280eSIngo Weinhold{
8097d7f280eSIngo Weinhold	# usage: UseArchObjectHeaders <sources_or_objects> : <arch> ;
8107d7f280eSIngo Weinhold	#
8117d7f280eSIngo Weinhold	# <arch> specifies the architecture (e.g. x86).
8127d7f280eSIngo Weinhold	# <sources_or_objects> Source or object files.
8137d7f280eSIngo Weinhold	# NOTE: This rule must be invoked *after* the rule that builds the objects.
8147d7f280eSIngo Weinhold
8157d7f280eSIngo Weinhold	local targets = $(1) ;
8167d7f280eSIngo Weinhold	local headers = [ ArchHeaders $(2) ] ;
8177d7f280eSIngo Weinhold	local opt = -D$(OBOS_TARGET_DEFINE) ;
8187d7f280eSIngo Weinhold
8197d7f280eSIngo Weinhold	ObjectCcFlags $(targets) : $(opt)  ;
8207d7f280eSIngo Weinhold	ObjectC++Flags $(targets) : $(opt)  ;
8217d7f280eSIngo Weinhold	ObjectHdrs $(targets) : $(headers) ;
82252a38012Sejakowatz}
82352a38012Sejakowatz
824d25a77b4SIngo Weinholdrule UsePosixHeaders
825d25a77b4SIngo Weinhold{
826a6c008e1Sbeveloper	# XXX changed to do nothing
827d25a77b4SIngo Weinhold}
828d25a77b4SIngo Weinhold
829d25a77b4SIngo Weinholdrule UsePosixObjectHeaders
830d25a77b4SIngo Weinhold{
831d25a77b4SIngo Weinhold	# UsePosixObjectHeaders <sources_or_objects> ;
832d25a77b4SIngo Weinhold	#
833d25a77b4SIngo Weinhold	# Adds the POSIX header dir to the header search
834d25a77b4SIngo Weinhold	# dirs of <sources_or_objects>.
835d25a77b4SIngo Weinhold	# NOTE: This rule must be invoked *after* the rule that builds the objects.
836d25a77b4SIngo Weinhold
837d25a77b4SIngo Weinhold	ObjectHdrs $(1) : [ FDirName $(OBOS_TOP) headers posix ] ;
838d25a77b4SIngo Weinhold}
839d25a77b4SIngo Weinhold
8403b9eae39SIngo Weinholdrule SplitPath
8413b9eae39SIngo Weinhold{
8423b9eae39SIngo Weinhold	# SplitPath <path> ;
8433b9eae39SIngo Weinhold	# Decomposes a path into its components.
8443b9eae39SIngo Weinhold	local path = $(1:G=) ;
8453b9eae39SIngo Weinhold	local components ;
8468c27f58dSIngo Weinhold	# $(path:D) for "/" is "/". Therefore the second condition.
8478c27f58dSIngo Weinhold	while $(path:D) && $(path:D) != $(path)
8483b9eae39SIngo Weinhold	{
8493b9eae39SIngo Weinhold		# Note: $(path:B) returns "." for "..", but $(path:D=) is fine.
8503b9eae39SIngo Weinhold		components = $(path:D=) $(components) ;
8513b9eae39SIngo Weinhold		path = $(path:D) ;
8523b9eae39SIngo Weinhold	}
8533b9eae39SIngo Weinhold	components = $(path) $(components) ;
8543b9eae39SIngo Weinhold	return $(components) ;
8553b9eae39SIngo Weinhold}
8563b9eae39SIngo Weinhold
8579fc6b2e1SIngo Weinholdrule PrependObjectHdrs
8589fc6b2e1SIngo Weinhold{
8599fc6b2e1SIngo Weinhold	# PrependObjectHdrs <objects_or_sources> : <dirs> ;
8609fc6b2e1SIngo Weinhold	# Prepends <dirs> to the list of header search dirs of the objects
8619fc6b2e1SIngo Weinhold	# specified by <objects_or_sources>. The HDRS variable will not be
8629fc6b2e1SIngo Weinhold	# changed, only CCHDRS.
8639fc6b2e1SIngo Weinhold	# Note: A subsequent ObjectHdrs invocation will therefore undo the
8649fc6b2e1SIngo Weinhold	# effect of this rule.
8659fc6b2e1SIngo Weinhold	# NOTE: This is a hack.
8669fc6b2e1SIngo Weinhold
8679fc6b2e1SIngo Weinhold	local objects = [ FGristFiles $(1:S=$(SUFOBJ)) ] ;
8689fc6b2e1SIngo Weinhold	local dirs = $(2) ;
8699fc6b2e1SIngo Weinhold	for object in $(objects) {
8709fc6b2e1SIngo Weinhold		# Don't change HDRS to avoid screwing up the header scanning.
8719fc6b2e1SIngo Weinhold		PREPENDED_HDRS on $(object)
8729fc6b2e1SIngo Weinhold			= $(dirs) [ on $(object) return $(PREPENDED_HDRS) ] ;
8739fc6b2e1SIngo Weinhold		CCHDRS on $(object)
8749fc6b2e1SIngo Weinhold			= [ FIncludes [ on $(object) return $(PREPENDED_HDRS) $(HDRS) ] ] ;
8759fc6b2e1SIngo Weinhold	}
8769fc6b2e1SIngo Weinhold}
8779fc6b2e1SIngo Weinhold
8783b9eae39SIngo Weinholdrule SymLink
8793b9eae39SIngo Weinhold{
8803b9eae39SIngo Weinhold	# SymLink <target> : <source> ;
8813b9eae39SIngo Weinhold	# Links <target> to <source>.
8823b9eae39SIngo Weinhold	# <source> is the exact link contents. No binding is done.
8833b9eae39SIngo Weinhold	LINKCONTENTS on $(1) = $(2) ;
8843b9eae39SIngo Weinhold	SymLink1 $(1) ;
8859eea4522SIngo Weinhold	LocalDepends all : $(target) ;
8863b9eae39SIngo Weinhold}
8873b9eae39SIngo Weinhold
8883b9eae39SIngo Weinholdactions SymLink1
8893b9eae39SIngo Weinhold{
8900931b8f9SIngo Weinhold	$(RM) "$(1)" && $(LN) -s "$(LINKCONTENTS)" "$(1)"
8910931b8f9SIngo Weinhold}
8920931b8f9SIngo Weinhold
8930931b8f9SIngo Weinholdrule RelSymLink
8940931b8f9SIngo Weinhold{
8950931b8f9SIngo Weinhold	# RelSymLink <link> : <link target>
8960931b8f9SIngo Weinhold	# Creates a relative symbolic link from <link> to <link target>.
8970931b8f9SIngo Weinhold	# <link> and <link target> can be usual targets. They may have a grist
8980931b8f9SIngo Weinhold	# and don't need to have any dirname. Their LOCATE variables are used to
8990931b8f9SIngo Weinhold	# find their locations.
9000931b8f9SIngo Weinhold
9010931b8f9SIngo Weinhold	local target = $(1) ;
9020931b8f9SIngo Weinhold	local source = $(2) ;
9030931b8f9SIngo Weinhold	local targetDir = [ on $(target) FDirName $(LOCATE[1]) $(target:D) ] ;
9040931b8f9SIngo Weinhold	local sourceDir = [ on $(source) FDirName $(LOCATE[1]) $(source:D) ] ;
9050931b8f9SIngo Weinhold	local sourcePath = $(source:G=) ;
9060931b8f9SIngo Weinhold	sourcePath = $(sourcePath:D=$(sourceDir)) ;
9070931b8f9SIngo Weinhold	local targetDirComponents = [ SplitPath $(targetDir) ] ;
9080931b8f9SIngo Weinhold	local sourceComponents = [ SplitPath $(sourcePath) ] ;
9090931b8f9SIngo Weinhold
9100931b8f9SIngo Weinhold	SymLink $(target)
9110931b8f9SIngo Weinhold		: [ FRelPath $(targetDirComponents) : $(sourceComponents) ] ;
9120931b8f9SIngo Weinhold	NOUPDATE $(target);
9139eea4522SIngo Weinhold	Depends $(target) : $(source) ;
9146991af8cSIngo Weinhold	LocalClean clean : $(target) ;
9153b9eae39SIngo Weinhold}
9163b9eae39SIngo Weinhold
91752a38012Sejakowatz#-------------------------------------------------------------------------------
91852a38012Sejakowatz# Low-level OBOS utility rules
91952a38012Sejakowatz#-------------------------------------------------------------------------------
92052a38012Sejakowatzrule SetupObjectsDir
92152a38012Sejakowatz{
92252a38012Sejakowatz	local rel_objectsdir;
92352a38012Sejakowatz
92452a38012Sejakowatz	# Copy subdir tokens except the first, as that will be "sources", and we
92552a38012Sejakowatz	# do not want to include that :)
92652a38012Sejakowatz	rel_objectsdir = [ FDirName $(SUBDIR_TOKENS[2-]) ] ;
92752a38012Sejakowatz	LOCATE_TARGET = [ FDirName $(OBOS_OBJECT_TARGET) $(rel_objectsdir) ] ;
92852a38012Sejakowatz}
92952a38012Sejakowatz
93052a38012Sejakowatz#-------------------------------------------------------------------------------
93152a38012Sejakowatz# Link rule/action are overwritten as they don't handle linking files who's name
93252a38012Sejakowatz# contain spaces very well. Also adds resources and version to executable.
93352a38012Sejakowatz#-------------------------------------------------------------------------------
93452a38012Sejakowatzrule Link
93552a38012Sejakowatz{
93652a38012Sejakowatz	# Note: RESFILES must be set before invocation.
93752a38012Sejakowatz	MODE on $(<) = $(EXEMODE) ;
93852a38012Sejakowatz	on $(1) XRes $(1) : $(RESFILES) ;
93952a38012Sejakowatz	Chmod $(<) ;
94052a38012Sejakowatz	SetType $(1) ;
94152a38012Sejakowatz	MimeSet $(1) ;
9421419ae2bSshatty	SetVersion $(1) ;
94352a38012Sejakowatz}
94452a38012Sejakowatz
94552a38012Sejakowatzactions Link bind NEEDLIBS
94652a38012Sejakowatz{
9471eb18edfSIngo Weinhold	$(LINK) $(LINKFLAGS) -o "$(1)" $(UNDEFS) "$(2)" "$(NEEDLIBS)" $(LINKLIBS) ;
94852a38012Sejakowatz}
94952a38012Sejakowatz
95052a38012Sejakowatz# BeOS specific rules
95152a38012Sejakowatz
95252a38012Sejakowatzrule XRes
95352a38012Sejakowatz{
95452a38012Sejakowatz	# XRes <target> : <resource files>
95552a38012Sejakowatz	if $(2)
95652a38012Sejakowatz	{
9579eea4522SIngo Weinhold		Depends $(1) : $(2) ;
95852a38012Sejakowatz		XRes1 $(1) : $(2) ;
95952a38012Sejakowatz	}
96052a38012Sejakowatz}
96152a38012Sejakowatz
96252a38012Sejakowatzrule XRes1 { }
96352a38012Sejakowatz
96452a38012Sejakowatzrule SetVersion
96552a38012Sejakowatz{
96652a38012Sejakowatz	# SetVersion <target>
96752a38012Sejakowatz}
96852a38012Sejakowatz
96952a38012Sejakowatzrule SetType
97052a38012Sejakowatz{
97152a38012Sejakowatz	# SetType <target>
97252a38012Sejakowatz}
97352a38012Sejakowatz
97452a38012Sejakowatzrule MimeSet
97552a38012Sejakowatz{
97652a38012Sejakowatz	# SetType <target>
97752a38012Sejakowatz}
97852a38012Sejakowatz
97952a38012Sejakowatz
98052a38012Sejakowatzif $(OS) = BEOS
98152a38012Sejakowatz{
98252a38012Sejakowatz
98352a38012Sejakowatzactions XRes1
98452a38012Sejakowatz{
9850931b8f9SIngo Weinhold	xres -o "$(1)" "$(2)" ;
98652a38012Sejakowatz}
98752a38012Sejakowatz
98852a38012Sejakowatzactions SetVersion
98952a38012Sejakowatz{
99052a38012Sejakowatz	setversion "$(1)" -system $(OBOS_BUILD_VERSION) -short "$(OBOS_BUILD_DESCRIPTION)" ;
99152a38012Sejakowatz}
99252a38012Sejakowatz
99352a38012Sejakowatzactions SetType
99452a38012Sejakowatz{
99552a38012Sejakowatz	settype -t $(OBOS_TARGET_TYPE) "$(1)" ;
99652a38012Sejakowatz}
99752a38012Sejakowatz
99852a38012Sejakowatzactions MimeSet
99952a38012Sejakowatz{
100052a38012Sejakowatz	mimeset -f "$(1)" ;
100152a38012Sejakowatz}
100252a38012Sejakowatz
100352a38012Sejakowatz}	# if BEOS
100452a38012Sejakowatz
100552a38012Sejakowatz
100652a38012Sejakowatzrule assemble
100752a38012Sejakowatz{
100894782cf7SIngo Weinhold	Depends $(<) : $(>) ;
100994782cf7SIngo Weinhold	ASFLAGS on $(<) += $(ASFLAGS) $(SUBDIRASFLAGS) ;
101094782cf7SIngo Weinhold	ASHDRS on $(<) = [ FIncludes $(SEARCH_SOURCE) $(SUBDIRHDRS) $(HDRS) ] ;
101152a38012Sejakowatz}
101252a38012Sejakowatz
101352a38012Sejakowatzactions assemble
101452a38012Sejakowatz{
101594782cf7SIngo Weinhold	$(CC) -c "$(2)" -O2 $(ASFLAGS) $(KERNEL_CCFLAGS) $(ASHDRS) -o "$(1)" ;
101652a38012Sejakowatz}
101752a38012Sejakowatz
10180931b8f9SIngo Weinhold# Overridden to allow spaces in file names.
10190931b8f9SIngo Weinholdactions Chmod1
10200931b8f9SIngo Weinhold{
10210931b8f9SIngo Weinhold	$(CHMOD) "$(MODE)" "$(1)"
10220931b8f9SIngo Weinhold}
10230931b8f9SIngo Weinhold
10246991af8cSIngo Weinhold# Overridden to allow spaces in file names.
10256991af8cSIngo Weinholdactions piecemeal together existing Clean
10266991af8cSIngo Weinhold{
10276991af8cSIngo Weinhold	$(RM) "$(>)"
10286991af8cSIngo Weinhold}
10296991af8cSIngo Weinhold
103008125d07SIngo Weinholdrule ObjectReference
103108125d07SIngo Weinhold{
103208125d07SIngo Weinhold	# ObjectReference <reference object> : <source object>
103308125d07SIngo Weinhold	# Makes <reference object> refer to the same file as <source object>.
103408125d07SIngo Weinhold	# The filenames must of course be identical.
103508125d07SIngo Weinhold	# <source object> must have already been LOCATEd.
103608125d07SIngo Weinhold
103708125d07SIngo Weinhold	local ref = $(1) ;
103808125d07SIngo Weinhold	local source = $(2) ;
103908125d07SIngo Weinhold	if $(ref) != $(source) {
10409eea4522SIngo Weinhold		Depends $(ref) : $(source) ;
104121df5945SIngo Weinhold		LOCATE on $(ref) = [ on $(source) return $(LOCATE) ] ;
104208125d07SIngo Weinhold	}
104308125d07SIngo Weinhold}
104408125d07SIngo Weinhold
104508125d07SIngo Weinholdrule ObjectReferences
104608125d07SIngo Weinhold{
104708125d07SIngo Weinhold	# ObjectReferences <source objects>
104808125d07SIngo Weinhold	# Creates local references to <source objects>, i.e. identifiers with the
104908125d07SIngo Weinhold	# current grist referring to the same files. <source objects> must have
105008125d07SIngo Weinhold	# already been LOCATEd.
105108125d07SIngo Weinhold
105208125d07SIngo Weinhold	local source ;
105308125d07SIngo Weinhold	for source in $(1) {
105408125d07SIngo Weinhold		ObjectReference [ FGristFiles $(source) ] : $(source) ;
105508125d07SIngo Weinhold	}
105608125d07SIngo Weinhold}
105708125d07SIngo Weinhold
10589fc6b2e1SIngo Weinholdrule Filter
10599fc6b2e1SIngo Weinhold{
10609fc6b2e1SIngo Weinhold	# Filter <list> : <excludes> ;
10619fc6b2e1SIngo Weinhold	# Removes all occurrences of <excludes> in <list>.
10629fc6b2e1SIngo Weinhold
10639fc6b2e1SIngo Weinhold	local list = $(1) ;
10649fc6b2e1SIngo Weinhold	local excludes = $(2) ;
10659fc6b2e1SIngo Weinhold	local newList ;
10669fc6b2e1SIngo Weinhold	local item ;
10679fc6b2e1SIngo Weinhold	for item in $(list) {
10689fc6b2e1SIngo Weinhold		local skip ;
10699fc6b2e1SIngo Weinhold		local exclude ;
10709fc6b2e1SIngo Weinhold		for exclude in $(excludes) {
10719fc6b2e1SIngo Weinhold			if $(item) = $(exclude) {
10729fc6b2e1SIngo Weinhold				skip = true ;
10739fc6b2e1SIngo Weinhold			}
10749fc6b2e1SIngo Weinhold		}
10759fc6b2e1SIngo Weinhold		if ! $(skip) {
10769fc6b2e1SIngo Weinhold			newList += item ;
10779fc6b2e1SIngo Weinhold		}
10789fc6b2e1SIngo Weinhold	}
10799fc6b2e1SIngo Weinhold	return $(newList) ;
10809fc6b2e1SIngo Weinhold}
10819fc6b2e1SIngo Weinhold
10820931b8f9SIngo Weinhold
108352a38012Sejakowatz## Kernel stuff!
108452a38012Sejakowatz
108552a38012Sejakowatzrule SetupKernel
108652a38012Sejakowatz{
108752a38012Sejakowatz	# Usage SetupKernel <sources_or_objects> : <extra_cc_flags>;
108852a38012Sejakowatz
108952a38012Sejakowatz	local _objs = $(1:S=$(SUFOBJ)) ;
109052a38012Sejakowatz
109128d2a30eSDaniel Reinhold	#Setup Kernel header directories
1092*089a0629Sbeveloper	local public_kernel_includes = add-ons/file_system add-ons/graphics device drivers kernel storage support ;
1093*089a0629Sbeveloper	local private_kernel_includes = kernel libroot ;
1094a6c008e1Sbeveloper	# Use posix headers directory
109528d2a30eSDaniel Reinhold	HDRS = [ FDirName $(OBOS_TOP) headers posix ] ;
1096a6c008e1Sbeveloper	# Use public OS header directories
1097*089a0629Sbeveloper	HDRS += [ PublicHeaders $(public_kernel_includes) ] ;
1098*089a0629Sbeveloper	# Use private directories
1099*089a0629Sbeveloper	HDRS += [ PrivateHeaders $(private_kernel_includes) ] ;
1100a6c008e1Sbeveloper
110152a38012Sejakowatz	UseArchHeaders $(OBOS_ARCH) ;
110252a38012Sejakowatz
110352a38012Sejakowatz	SetupObjectsDir ;
110452a38012Sejakowatz
110552a38012Sejakowatz	CCFLAGS on $(_objs) = $(KERNEL_CCFLAGS) $(2) ;
110652a38012Sejakowatz	C++FLAGS on $(_objs) = $(KERNEL_CCFLAGS) $(2) ;
110752a38012Sejakowatz}
110852a38012Sejakowatz
110952a38012Sejakowatzrule KernelObjects
111052a38012Sejakowatz{
111152a38012Sejakowatz	SetupKernel $(1) : $(2) ;
111252a38012Sejakowatz
111352a38012Sejakowatz	Objects $(1) ;
111452a38012Sejakowatz}
111552a38012Sejakowatz
111652a38012Sejakowatzrule KernelLd
111752a38012Sejakowatz{
111852a38012Sejakowatz	# KernelLd <name> : <objs> : <linkerscript> : <args> : <gcc_off> ;
111952a38012Sejakowatz
112052a38012Sejakowatz	SetupKernel $(2) ;
112152a38012Sejakowatz	LINK on $(1) = ld ;
112252a38012Sejakowatz
112352a38012Sejakowatz	LINKFLAGS on $(1) = $(4) ;
112452a38012Sejakowatz	if $(3) { LINKFLAGS on $(1) += --script=$(3) ; }
112552a38012Sejakowatz
112652a38012Sejakowatz	# Remove any preset LINKLIBS
112752a38012Sejakowatz	LINKLIBS on $(1) =  ;
112852a38012Sejakowatz
112952a38012Sejakowatz	# Show that we depend on the libraries we need
11309eea4522SIngo Weinhold	LocalClean clean : $(1) ;
11319eea4522SIngo Weinhold	LocalDepends all : $(1) ;
113252a38012Sejakowatz	Depends $(1) : $(2) ;
113352a38012Sejakowatz
113452a38012Sejakowatz	if $(6) {
113552a38012Sejakowatz		for i in $(6) {
11362a83bfb4SIngo Weinhold			KernelConfigSection $(i) : elf32 : $(1) ;
113752a38012Sejakowatz		}
113852a38012Sejakowatz	}
113952a38012Sejakowatz
114052a38012Sejakowatz	MakeLocate $(1) : $(LOCATE_TARGET) ;
114152a38012Sejakowatz
114252a38012Sejakowatz	# Add libgcc.a - NB this should be detected not hard coded!
114352a38012Sejakowatz	if ! $(5) {
11441eb18edfSIngo Weinhold		LINKLIBS on $(1) += -L $(GCC_PATH) -lgcc ;
114552a38012Sejakowatz	}
114652a38012Sejakowatz}
114752a38012Sejakowatz
114852a38012Sejakowatzactions KernelLd
114952a38012Sejakowatz{
11501eb18edfSIngo Weinhold	$(LINK) $(LINKFLAGS) -o "$(1)" "$(2)" $(LINKLIBS) ;
115152a38012Sejakowatz}
115252a38012Sejakowatz
115352a38012Sejakowatzrule KernelStaticLibrary
115452a38012Sejakowatz{
115552a38012Sejakowatz	# Usage KernelStaticLibrary <name> : <sources> : <extra cc flags>  ;
115652a38012Sejakowatz	# This is designed to take a set of sources and libraries and create
115752a38012Sejakowatz	# a file called lib<name>.a
115852a38012Sejakowatz
115952a38012Sejakowatz	SetupKernel $(2) : $(3) ;
116052a38012Sejakowatz
116152a38012Sejakowatz	MakeLocateObjects $(2) ;
116252a38012Sejakowatz	Library $(1) : $(2) ;
116352a38012Sejakowatz}
116452a38012Sejakowatz
116552a38012Sejakowatzrule KernelStaticLibraryObjects
116652a38012Sejakowatz{
116752a38012Sejakowatz	# Usage KernelStaticLibrary <name> : <sources> ;
116852a38012Sejakowatz	# This is designed to take a set of sources and libraries and create
116952a38012Sejakowatz	# a file called <name>
117052a38012Sejakowatz
117152a38012Sejakowatz	SetupKernel $(2) ;
117252a38012Sejakowatz
117352a38012Sejakowatz	# Show that we depend on the libraries we need
11749eea4522SIngo Weinhold	LocalClean clean : $(1) ;
11759eea4522SIngo Weinhold	LocalDepends all : $(1) ;
117652a38012Sejakowatz	Depends $(1) : $(2) ;
117752a38012Sejakowatz
117852a38012Sejakowatz	MakeLocate $(1) : $(LOCATE_TARGET) ;
117952a38012Sejakowatz}
118052a38012Sejakowatz
118152a38012Sejakowatzactions KernelStaticLibraryObjects
118252a38012Sejakowatz{
11830931b8f9SIngo Weinhold	ar -r "$(1)" "$(2)" ;
118452a38012Sejakowatz}
118552a38012Sejakowatz
118652a38012Sejakowatzrule SystemMain
118752a38012Sejakowatz{
11880c0b2cd0SIngo Weinhold	# Usage SystemMain <target> : <sources> ;
118952a38012Sejakowatz	SetupObjectsDir ;
119052a38012Sejakowatz
11910c0b2cd0SIngo Weinhold	LINKLIBS on $(1) = ;
119252a38012Sejakowatz
119352a38012Sejakowatz	Main $(1) : $(2) ;
119452a38012Sejakowatz}
119552a38012Sejakowatz
119652a38012Sejakowatzrule KernelConfigSection
119752a38012Sejakowatz{
119852a38012Sejakowatz	# KernelConfigSection <section> : <type> : <file>  ;
11992a83bfb4SIngo Weinhold
12002a83bfb4SIngo Weinhold	SECTION_NAMES on $(OBOS_KERNEL_CONFIG) += $(1) ;
12012a83bfb4SIngo Weinhold	SECTION_TYPES on $(OBOS_KERNEL_CONFIG) += $(2) ;
12022a83bfb4SIngo Weinhold	SECTION_FILES on $(OBOS_KERNEL_CONFIG) += $(3) ;
12032a83bfb4SIngo Weinhold
12042a83bfb4SIngo Weinhold	Depends $(OBOS_KERNEL_CONFIG) : $(3) ;
120552a38012Sejakowatz}
120652a38012Sejakowatz
120752a38012Sejakowatzrule WriteKernelConfig
120852a38012Sejakowatz{
120952a38012Sejakowatz	# usage: WriteKernelConfig <target> ;
121052a38012Sejakowatz
12119eea4522SIngo Weinhold	LocalDepends files : $(1) ;
121252a38012Sejakowatz
12132a83bfb4SIngo Weinhold	MakeLocate $(1) : $(OBOS_OBJECT_TARGET) ;
121452a38012Sejakowatz
12159eea4522SIngo Weinhold	LocalClean clean : $(1) ;
121652a38012Sejakowatz}
121752a38012Sejakowatz
12182a83bfb4SIngo Weinholdactions WriteKernelConfig bind SECTION_FILES
121952a38012Sejakowatz{
12200931b8f9SIngo Weinhold	target="$(1)"
12210931b8f9SIngo Weinhold	echo "# OpenBeOS Kernel Config File" > "$target"
12220931b8f9SIngo Weinhold	echo "# Automatically generated - do not edit!" >> "$target"
12232a83bfb4SIngo Weinhold	count=0
12242a83bfb4SIngo Weinhold	for section in "$(SECTION_NAMES)" ; do
12252a83bfb4SIngo Weinhold		count=`expr $count + 1`
12262a83bfb4SIngo Weinhold		eval section$count="$section"
12272a83bfb4SIngo Weinhold	done
12282a83bfb4SIngo Weinhold	i=1
12292a83bfb4SIngo Weinhold	for type in "$(SECTION_TYPES)" ; do
12302a83bfb4SIngo Weinhold		eval type$i="$type"
12312a83bfb4SIngo Weinhold		i=`expr $i + 1`
12322a83bfb4SIngo Weinhold	done
12332a83bfb4SIngo Weinhold	i=1
12342a83bfb4SIngo Weinhold	for file in "$(SECTION_FILES)" ; do
12352a83bfb4SIngo Weinhold		eval file$i="$file"
12362a83bfb4SIngo Weinhold		i=`expr $i + 1`
12372a83bfb4SIngo Weinhold	done
12382a83bfb4SIngo Weinhold	for i in `seq $count` ; do
12392a83bfb4SIngo Weinhold		eval section="\$section$i"
12402a83bfb4SIngo Weinhold		eval type="\$type$i"
12412a83bfb4SIngo Weinhold		eval file="\$file$i"
12420931b8f9SIngo Weinhold		echo "" >> "$target"
12432a83bfb4SIngo Weinhold		echo "["$section"]" >> "$target"
12442a83bfb4SIngo Weinhold		echo "type="$type >> "$target"
12450931b8f9SIngo Weinhold		case "$file" in
124652a38012Sejakowatz			/*) ;;
12470931b8f9SIngo Weinhold			*) file=`pwd`/"$file";;
124852a38012Sejakowatz		esac
12492a83bfb4SIngo Weinhold		echo "file="$file >> "$target"
125052a38012Sejakowatz	done
125152a38012Sejakowatz}
125252a38012Sejakowatz
125352a38012Sejakowatzrule BuildKernel
125452a38012Sejakowatz{
125552a38012Sejakowatz	# Usage BuildKernel <target> : <config_file> ;
12560c0b2cd0SIngo Weinhold	local kernel = $(1) ;
12570c0b2cd0SIngo Weinhold	local configFile = $(2) ;
12580c0b2cd0SIngo Weinhold	local bootmaker = bootmaker ;
125952a38012Sejakowatz
12609eea4522SIngo Weinhold	LocalDepends all : $(kernel) ;
12610c0b2cd0SIngo Weinhold	Depends $(kernel) : $(configFile) $(bootmaker) ;
12629eea4522SIngo Weinhold	LocalClean clean : $(kernel) ;
12630c0b2cd0SIngo Weinhold	MakeLocate $(kernel) : $(LOCATE_TARGET) ;
126452a38012Sejakowatz
12650c0b2cd0SIngo Weinhold	BOOT_MAKER on $(kernel) = $(bootmaker) ;
126652a38012Sejakowatz}
126752a38012Sejakowatz
12680c0b2cd0SIngo Weinholdactions BuildKernel bind BOOT_MAKER
126952a38012Sejakowatz{
12700c0b2cd0SIngo Weinhold	"$(BOOT_MAKER)" --strip-debug --strip-binary strip "$(2)" -o "$(1)" ;
127152a38012Sejakowatz	echo ""
127252a38012Sejakowatz	echo "Kernel linked!"
127352a38012Sejakowatz	echo ""
127452a38012Sejakowatz}
127552a38012Sejakowatz
127652a38012Sejakowatzrule KernelFloppyImage
127752a38012Sejakowatz{
127852a38012Sejakowatz	# Usage KernelFloppyImage <target> : <kernel> : <bootblock> ;
12790c0b2cd0SIngo Weinhold	local floppy = $(1) ;
12800c0b2cd0SIngo Weinhold	local kernel = $(2) ;
12810c0b2cd0SIngo Weinhold	local bootblock = $(3) ;
12820c0b2cd0SIngo Weinhold	local makeflop = makeflop ;
128352a38012Sejakowatz
12849eea4522SIngo Weinhold	LocalDepends all : $(floppy) ;
12850c0b2cd0SIngo Weinhold	Depends $(floppy) : $(kernel) $(bootblock) $(makeflop) ;
12869eea4522SIngo Weinhold	LocalClean clean : $(floppy) ;
12870c0b2cd0SIngo Weinhold	MakeLocate $(floppy) : $(OBOS_OBJECT_TARGET) ;
128852a38012Sejakowatz
12890c0b2cd0SIngo Weinhold	BOOT_BLOCK on $(floppy) = $(bootblock) ;
12900c0b2cd0SIngo Weinhold	MAKE_FLOP on $(floppy) = $(makeflop) ;
129152a38012Sejakowatz}
129252a38012Sejakowatz
129352a38012Sejakowatz# This may be a bit verbose, but I think it's useful to show what's
129452a38012Sejakowatz# going on, at least in this early stage of development.
12950c0b2cd0SIngo Weinholdactions KernelFloppyImage bind BOOT_BLOCK bind MAKE_FLOP
129652a38012Sejakowatz{
12977378dd7fSAxel Dörfler	"$(MAKE_FLOP)" "-p $(shell expr 18 \* 2 \* 512)" "$(BOOT_BLOCK)" "$(2)" "$(1)" ;
12980c0b2cd0SIngo Weinhold
129952a38012Sejakowatz	echo ""
130052a38012Sejakowatz	echo "*************************************************"
130152a38012Sejakowatz	echo "*         Kernel build completed!               *"
130252a38012Sejakowatz	echo "*    Boot image for a 1.44M floppy created      *"
130352a38012Sejakowatz	echo "*************************************************"
130452a38012Sejakowatz	echo ""
13050c0b2cd0SIngo Weinhold	echo "Floppy image is $(1)"
130652a38012Sejakowatz	echo "The following command will write it to a floppy on BeOS"
13070c0b2cd0SIngo Weinhold	echo "  dd if=$(1) of=/dev/disk/floppy/raw bs=18k"
13080c0b2cd0SIngo Weinhold	echo "Alternatively you can run"
13090c0b2cd0SIngo Weinhold	echo "  ./configure --floppy /dev/disk/floppy/raw"
13100c0b2cd0SIngo Weinhold	echo "once and build + write the image subsequently via"
13110c0b2cd0SIngo Weinhold	echo "  jam installfloppy"
131252a38012Sejakowatz	echo ""
131352a38012Sejakowatz}
131452a38012Sejakowatz
13150c0b2cd0SIngo Weinholdrule InstallFloppy
13160c0b2cd0SIngo Weinhold{
13170c0b2cd0SIngo Weinhold	# InstallFloppy <target> : <floppy>
13180c0b2cd0SIngo Weinhold	# "dd"s <floppy> to $(FLOPPY_PATH).
13190c0b2cd0SIngo Weinhold
13200c0b2cd0SIngo Weinhold	local target = $(1) ;
13210c0b2cd0SIngo Weinhold	local floppy = $(2) ;
13220c0b2cd0SIngo Weinhold
13230c0b2cd0SIngo Weinhold	NotFile $(target) ;
13240c0b2cd0SIngo Weinhold	Always $(target) ;
13250c0b2cd0SIngo Weinhold	Depends $(target) : $(floppy) ;
13260c0b2cd0SIngo Weinhold}
13270c0b2cd0SIngo Weinhold
13280c0b2cd0SIngo Weinholdactions InstallFloppy
13290c0b2cd0SIngo Weinhold{
13300c0b2cd0SIngo Weinhold	if [ -z $(FLOPPY_PATH) ] ; then
13310c0b2cd0SIngo Weinhold		echo "Can't install floppy: FLOPPY_PATH not set."
13320c0b2cd0SIngo Weinhold		echo "run: ./configure --floppy <floppy path>"
13330c0b2cd0SIngo Weinhold		echo
13340c0b2cd0SIngo Weinhold		exit 0
13350c0b2cd0SIngo Weinhold	fi
13360c0b2cd0SIngo Weinhold	dd if=$(2) of=$(FLOPPY_PATH) bs=18k
13370c0b2cd0SIngo Weinhold}
133852a38012Sejakowatz
133921df5945SIngo Weinhold
134021df5945SIngo Weinhold#-------------------------------------------------------------------------------
134121df5945SIngo Weinhold# FreeType 2 specific rules and variables
134221df5945SIngo Weinhold#-------------------------------------------------------------------------------
134321df5945SIngo Weinhold
134421df5945SIngo WeinholdFT2_INCLUDE = [ FDirName $(OBOS_TOP) headers libs freetype2 ] ;
134521df5945SIngo WeinholdFT2_SRC     = [ FDirName $(OBOS_TOP) src libs freetype2 ] ;
134621df5945SIngo Weinhold
134721df5945SIngo WeinholdFT2_LIB     = freetype ;
134821df5945SIngo Weinhold
134921df5945SIngo Weinholdrule UseFreeTypeHeaders
135021df5945SIngo Weinhold{
135121df5945SIngo Weinhold	SubDirHdrs $(FT2_INCLUDE) ;
135221df5945SIngo Weinhold}
135321df5945SIngo Weinhold
135421df5945SIngo Weinholdrule UseFreeTypeObjectHeaders
135521df5945SIngo Weinhold{
135621df5945SIngo Weinhold	ObjectHdrs $(1) : $(FT2_INCLUDE) ;
135721df5945SIngo Weinhold}
135821df5945SIngo Weinhold
135921df5945SIngo Weinholdrule FT2_SubDir
136021df5945SIngo Weinhold{
136121df5945SIngo Weinhold	# FT2_SubDir <dir>
136221df5945SIngo Weinhold	# <dir>: Components of a directory in the original hierarchy.
136321df5945SIngo Weinhold	local dir = $(1) ;
136421df5945SIngo Weinhold	local topDir ;
136521df5945SIngo Weinhold	switch $(dir[1])
136621df5945SIngo Weinhold	{
136721df5945SIngo Weinhold		case "include"	: topDir = $(FT2_INCLUDE) ;
136821df5945SIngo Weinhold		case src		: topDir = $(FT2_SRC) ;
136921df5945SIngo Weinhold		case *			: ECHO "Unknown FreeType2 directory: " $(dir) ;
137021df5945SIngo Weinhold	}
137121df5945SIngo Weinhold	return [ FDirName $(topDir) $(dir[2-]) ] ;
137221df5945SIngo Weinhold}
137321df5945SIngo Weinhold
137421df5945SIngo Weinholdrule FT2_Library
137521df5945SIngo Weinhold{
137621df5945SIngo Weinhold	# FT2_Library <libname> : <sources>
137721df5945SIngo Weinhold	# Builds objects from sources and adds the objects to the list of objects
137821df5945SIngo Weinhold	# to be linked into the library.
137921df5945SIngo Weinhold	# <libname> The name of the library.
138021df5945SIngo Weinhold	# <sources> The sources.
138121df5945SIngo Weinhold
138221df5945SIngo Weinhold	local library = lib$(1).so ;
138321df5945SIngo Weinhold	local sources = $(2) ;
138428d2a30eSDaniel Reinhold	SetupIncludes ;
138521df5945SIngo Weinhold	SetupObjectsDir ;
138621df5945SIngo Weinhold	MakeLocateObjects $(sources) ;
138721df5945SIngo Weinhold	Objects $(sources) ;
138821df5945SIngo Weinhold	LIBRARY_OBJECTS on $(library) += [ FGristFiles $(sources:S=$(SUFOBJ)) ] ;
138921df5945SIngo Weinhold}
139021df5945SIngo Weinhold
139121df5945SIngo Weinholdrule FT2_LinkLibrary
139221df5945SIngo Weinhold{
139321df5945SIngo Weinhold	# FT2_LinkLibrary <libname>
139421df5945SIngo Weinhold	# Links the library from the objects build with FT2_LIBRARY before.
139521df5945SIngo Weinhold
139621df5945SIngo Weinhold	local library = lib$(1).so ;
139721df5945SIngo Weinhold	local objects = [ on $(library) return $(LIBRARY_OBJECTS) ] ;
139821df5945SIngo Weinhold	ObjectReferences $(objects) ;
139921df5945SIngo Weinhold	objects = [ FGristFiles $(objects) ] ;
140021df5945SIngo Weinhold	SharedLibraryFromObjects $(1) : $(objects) ;
140121df5945SIngo Weinhold}
140221df5945SIngo Weinhold
1403