xref: /haiku/Jamrules (revision 405439be5c942a4d3f86899456e2c5ddc81ba42d)
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
4152a38012Sejakowatz# Determine if we're building on PPC or x86
4252a38012Sejakowatz# Determine mimetype of executable
4352a38012Sejakowatz# Cross compiling can come later
4452a38012Sejakowatz
4552a38012Sejakowatzif $(METROWERKS) {
4678599cf0SIngo Weinhold	OBOS_TARGET ?= "ppc.R1" ;
4752a38012Sejakowatz	OBOS_TARGET_TYPE ?= "application/x-be-executable" ;
4852a38012Sejakowatz	OBOS_ARCH ?= "ppc" ;
4952a38012Sejakowatz	OBOS_TARGET_DEFINE ?= "ARCH_ppc" ;
5052a38012Sejakowatz} else {
5178599cf0SIngo Weinhold	OBOS_TARGET ?= "x86.R1" ;
5252a38012Sejakowatz	OBOS_TARGET_TYPE ?= "application/x-vnd.Be-elfexecutable" ;
5352a38012Sejakowatz	OBOS_ARCH ?= "x86" ;
5452a38012Sejakowatz	OBOS_TARGET_DEFINE ?= "ARCH_x86" ;
5552a38012Sejakowatz	OBOS_TARGET_DIR ?= "x86" ;
5652a38012Sejakowatz}
5752a38012Sejakowatz
58e5dc2d93Sbeveloper# Enable warnings only if WARNINGS is defined
59e5dc2d93Sbeveloper# Should be enabled by default later
6096d27465SIngo Weinhold#
61e5dc2d93Sbeveloperif $(WARNINGS) {
62e5dc2d93Sbeveloper	# For an explanation of the different warning options, see:
63e5dc2d93Sbeveloper	# http://gcc.gnu.org/onlinedocs/gcc-2.95.3/gcc_2.html
64e5dc2d93Sbeveloper	# to get even more warnings, add:
65e5dc2d93Sbeveloper	# -Wwrite-strings  	(doesn't work well with some Be headers)
66e5dc2d93Sbeveloper	# -Wundef			(dito)
67e5dc2d93Sbeveloper	# -Wconversion		(gets you many warnings about implicit conversions)
68e5dc2d93Sbeveloper	# -W				(gets you even more warnigs)
69e5dc2d93Sbeveloper	CCFLAGS ?= "-Wall -Wno-multichar -Wmissing-prototypes" ;
70e5dc2d93Sbeveloper	CCFLAGS += "-Wpointer-arith -Wcast-align -Wsign-compare" ;
71e5dc2d93Sbeveloper	C++FLAGS ?= "-Wall -Wno-multichar -Wmissing-prototypes -Wno-ctor-dtor-privacy -Woverloaded-virtual" ;
72e5dc2d93Sbeveloper	C++FLAGS += "-Wpointer-arith -Wcast-align -Wsign-compare" ;
73e5dc2d93Sbeveloper}
74e5dc2d93Sbeveloper
759eea4522SIngo Weinhold# We might later want to introduce debug levels or handle the whole issue
769eea4522SIngo Weinhold# differently. For now there's only on or off.
779eea4522SIngo Weinhold#
789eea4522SIngo Weinholdif $(DEBUG) {
799eea4522SIngo Weinhold	OPTIM ?= -O0 ;
809eea4522SIngo Weinhold	CCFLAGS += -g ;
819eea4522SIngo Weinhold	C++FLAGS += -g ;
829eea4522SIngo Weinhold	LINKFLAGS += -g ;
839eea4522SIngo Weinhold} else {
849eea4522SIngo Weinhold	OPTIM ?= -O2 ;
859eea4522SIngo Weinhold}
8696d27465SIngo Weinhold#
8796d27465SIngo Weinhold# To disable for the tests OPTIM and DEBUG are overridden, set the environment
8896d27465SIngo Weinhold# variable NO_TEST_DEBUG.
899eea4522SIngo Weinhold
9052a38012SejakowatzKERNEL_CCFLAGS ?= "-Wall -Wno-multichar -Wmissing-prototypes -finline -nostdinc" ;
9152a38012SejakowatzKERNEL_CCFLAGS += "-fno-builtin -D$(OBOS_TARGET_DEFINE) " ;
92*405439beSbeveloperKERNEL_CCFLAGS += "-DBOCHS_DEBUG_HACK=$(BOCHS_DEBUG_HACK) " ;
9352a38012Sejakowatz
9416fa4445SIngo Weinhold# Instructs the Library rule to not make its object files temporary.
9516fa4445SIngo Weinhold# This is need as some objects are used in a static library and for an
9616fa4445SIngo Weinhold# executable.
9716fa4445SIngo WeinholdKEEPOBJS = true ;
9816fa4445SIngo Weinhold
9952a38012SejakowatzAR = ar r ;
10052a38012Sejakowatz
10152a38012Sejakowatz# If no OBOS_OBJECT_TARGET is not defined yet, use our default directory and
10252a38012Sejakowatz# include our "OBOS_TARGET" as subdirectory in there (to prevent different
10352a38012Sejakowatz# builds mixing objects from different targets).
10452a38012Sejakowatzif ! $(OBOS_OBJECT_TARGET) {
10552a38012Sejakowatz	OBOS_OBJECT_TARGET ?= [ FDirName $(OBOS_TOP) objects $(OBOS_TARGET) ] ;
10652a38012Sejakowatz}
10752a38012Sejakowatz
10852a38012Sejakowatz# If no OBOS_DISTRO_TARGET is not defined yet, use our default directory and
10952a38012Sejakowatz# include our "OBOS_TARGET" as subdirectory in there (to prevent different
11052a38012Sejakowatz# builds mixing executables from different targets).
11152a38012Sejakowatzif ! $(OBOS_DISTRO_TARGET) {
11252a38012Sejakowatz	OBOS_DISTRO_TARGET ?= [ FDirName $(OBOS_TOP) distro $(OBOS_TARGET) ] ;
11352a38012Sejakowatz}
11452a38012Sejakowatz
11552a38012Sejakowatz# Set our version number if not already set and mark it as a developer build
11652a38012Sejakowatzif ! $(OBOS_BUILD_VERSION) {
11752a38012Sejakowatz	OBOS_BUILD_VERSION ?= "1 0 0 a 1" ;
11852a38012Sejakowatz	OBOS_BUILD_DESCRIPTION ?= "Developer Build" ;
11952a38012Sejakowatz}
12052a38012Sejakowatz
12152a38012Sejakowatz# If OBOS_BUILD_VERSION is set, but OBOS_BUILD_DESCRIPTION isn't, mark it as
12252a38012Sejakowatz# an unknown build.
12352a38012Sejakowatzif ! $(OBOS_BUILD_DESCRIPTION) {
12452a38012Sejakowatz	OBOS_BUILD_DESCRIPTION ?= "Unknown Build" ;
12552a38012Sejakowatz}
12652a38012Sejakowatz
12752a38012Sejakowatz# Relative subdirs for distro dir (these are for *INTERNAL* use by the following rules only!)
1285f281ed5SejakowatzOBOS_APPS_DIR   ?= [ FDirName $(OBOS_DISTRO_TARGET) beos apps ] ;
129f06de7f3SIngo WeinholdOBOS_BIN_DIR    ?= [ FDirName $(OBOS_DISTRO_TARGET) beos bin ] ;
13052a38012SejakowatzOBOS_PREFS_DIR  ?= [ FDirName $(OBOS_DISTRO_TARGET) beos preferences ] ;
13152a38012SejakowatzOBOS_SERVER_DIR ?= [ FDirName $(OBOS_DISTRO_TARGET) beos system servers ] ;
13252a38012SejakowatzOBOS_ADDON_DIR  ?= [ FDirName $(OBOS_DISTRO_TARGET) beos system add-ons ] ;
13352a38012SejakowatzOBOS_SHLIB_DIR  ?= [ FDirName $(OBOS_DISTRO_TARGET) beos system lib ] ;
13452a38012SejakowatzOBOS_STLIB_DIR  ?= [ FDirName $(OBOS_DISTRO_TARGET) beos system lib ] ;
13552a38012SejakowatzOBOS_KERNEL_DIR ?= [ FDirName $(OBOS_DISTRO_TARGET) beos system ] ;
13652a38012SejakowatzOBOS_TEST_DIR   ?= [ FDirName $(OBOS_TOP) tests ] ;
13752a38012Sejakowatz
13852a38012SejakowatzOBOS_KERNEL_CONFIG = config.$(OBOS_ARCH).ini ;
13952a38012SejakowatzOBOS_KERNEL = kernel.$(OBOS_ARCH) ;
14052a38012SejakowatzOBOS_FLOPPY = floppy.$(OBOS_ARCH) ;
14152a38012Sejakowatz
14252a38012Sejakowatzrule SetupIncludes
14352a38012Sejakowatz{
14452a38012Sejakowatz	OBOS_INCLUDES ?= . add-ons app be_apps device drivers game interface kernel mail media midi midi2 net opengl storage support translation ;
14552a38012Sejakowatz	UsePublicHeaders $(OBOS_INCLUDES) ;
146d25a77b4SIngo Weinhold    UsePosixHeaders ;
14752a38012Sejakowatz}
14852a38012Sejakowatz
14952a38012Sejakowatz#-------------------------------------------------------------------------------
15052a38012Sejakowatz# Things Jam needs in order to work :)
15152a38012Sejakowatz#-------------------------------------------------------------------------------
15252a38012Sejakowatz
15352a38012Sejakowatzrule UserObject
15452a38012Sejakowatz{
15552a38012Sejakowatz	switch $(2)
15652a38012Sejakowatz	{
15752a38012Sejakowatz	case *.S    : assemble $(1) : $(2) ;
15808125d07SIngo Weinhold	case *.o    : return ;
15952a38012Sejakowatz	case *      : ECHO "unknown suffix on" $(2) ;
16052a38012Sejakowatz	}
16152a38012Sejakowatz}
16252a38012Sejakowatz
16352a38012Sejakowatz# Override the default to give "prettier" command lines.
16452a38012Sejakowatzactions Cc
16552a38012Sejakowatz{
1660931b8f9SIngo Weinhold	$(CC) -c "$(2)" $(CCFLAGS) $(CCDEFS) $(CCHDRS) -o "$(1)" ;
16752a38012Sejakowatz}
16852a38012Sejakowatz
16952a38012Sejakowatzactions C++
17052a38012Sejakowatz{
1710931b8f9SIngo Weinhold	$(C++) -c "$(2)" $(C++FLAGS) $(CCDEFS) $(CCHDRS) -o "$(1)" ;
17252a38012Sejakowatz}
17352a38012Sejakowatz
17452a38012Sejakowatz
17552a38012Sejakowatz#-------------------------------------------------------------------------------
17652a38012Sejakowatz# General High-level OBOS target rules
17752a38012Sejakowatz#-------------------------------------------------------------------------------
17852a38012Sejakowatz
1795f281ed5Sejakowatzrule App
1805f281ed5Sejakowatz{
1815f281ed5Sejakowatz	# App <name> : <sources> ;
1825f281ed5Sejakowatz	SetupObjectsDir ;
1835f281ed5Sejakowatz	Main $(<) : $(>) ;
1845f281ed5Sejakowatz	MakeLocate $(<) : $(OBOS_APPS_DIR) ;
1855f281ed5Sejakowatz}
1865f281ed5Sejakowatz
187f06de7f3SIngo Weinholdrule BinCommand
188f06de7f3SIngo Weinhold{
189f06de7f3SIngo Weinhold	# BinCommand <name> : <sources> : <libraries> ;
190f06de7f3SIngo Weinhold	SetupObjectsDir ;
191f06de7f3SIngo Weinhold	Main $(1) : $(2) ;
192f06de7f3SIngo Weinhold	MakeLocate $(1) : $(OBOS_BIN_DIR) ;
193f06de7f3SIngo Weinhold	LinkSharedOSLibs $(1) : $(3) ;
194f06de7f3SIngo Weinhold}
195f06de7f3SIngo Weinhold
196f06de7f3SIngo Weinholdrule StdBinCommands
197f06de7f3SIngo Weinhold{
198f06de7f3SIngo Weinhold	# StdBinCommands <sources> : <libs> ;
199f06de7f3SIngo Weinhold	local libs = $(2) ;
2009342c27aSIngo Weinhold	local source ;
201f06de7f3SIngo Weinhold	for source in $(1)
202f06de7f3SIngo Weinhold	{
203f06de7f3SIngo Weinhold		local target = $(source:S=) ;
204f06de7f3SIngo Weinhold		target = [ FGristFiles $(target) ] ;
205f06de7f3SIngo Weinhold		BinCommand $(target) : $(source) : $(libs) ;
206f06de7f3SIngo Weinhold	}
207f06de7f3SIngo Weinhold}
208f06de7f3SIngo Weinhold
20952a38012Sejakowatzrule Preference
21052a38012Sejakowatz{
21152a38012Sejakowatz	# Preference <name> : <sources> ;
21252a38012Sejakowatz#	SetupIncludes ;
21352a38012Sejakowatz	SetupObjectsDir ;
21452a38012Sejakowatz	Main $(<) : $(>) ;
21552a38012Sejakowatz	MakeLocate $(<) : $(OBOS_PREFS_DIR) ;
21652a38012Sejakowatz}
21752a38012Sejakowatz
21852a38012Sejakowatzrule Server
21952a38012Sejakowatz{
22052a38012Sejakowatz	# Server <name> : <sources> ;
22152a38012Sejakowatz
222f63877e7SIngo Weinhold#	SetupIncludes ;
22352a38012Sejakowatz	SetupObjectsDir ;
22452a38012Sejakowatz	Main $(<) : $(>) ;
22552a38012Sejakowatz	MakeLocate $(<) : $(OBOS_SERVER_DIR) ;
22652a38012Sejakowatz}
22752a38012Sejakowatz
22852a38012Sejakowatz# test pseudo targets
22952a38012SejakowatzNOTFILE obostests ;
23052a38012SejakowatzNOTFILE r5tests ;
23152a38012Sejakowatz
232d1f6c38fSTyler Dauwalderrule CommonTestLib
233d1f6c38fSTyler Dauwalder{
234c5ff4aa6STyler Dauwalder	# CommonTestLib <target> : <sources> : <obos libraries>
2359285de51STyler Dauwalder	#	: <r5 libraries> : <test libraries> : <public headers>;
236d1f6c38fSTyler Dauwalder	# Builds a unit test for both OBOS and R5 modules.
237d1f6c38fSTyler Dauwalder	# <target> The name of the target.
238d1f6c38fSTyler Dauwalder	# <sources> The list of sources.
239d1f6c38fSTyler Dauwalder	# <obos libraries> A list of link libraries for the OBOS tests (as passed
240d1f6c38fSTyler Dauwalder	# to LinkSharedOSLibs).
241d1f6c38fSTyler Dauwalder	# <r5 libraries> A list of link libraries for the R5 tests (as passed
242d1f6c38fSTyler Dauwalder	# to LinkSharedOSLibs).
2439285de51STyler Dauwalder	# <test libraries> A list of link libraries for both OBOS tests and R5 tests
2449285de51STyler Dauwalder	# that have a common name (i.e. specify libx.so and the OBOS tests will link
2459285de51STyler Dauwalder	# to libx.so and the R5 tests will link to libx_r5.so).
246d1f6c38fSTyler Dauwalder	# <public headers> A list of public header dirs (as passed to
247d1f6c38fSTyler Dauwalder	# UsePublicHeaders).
248d1f6c38fSTyler Dauwalder
249c5ff4aa6STyler Dauwalder	TestLib $(1) : $(2) : [ FDirName $(OBOS_TEST_DIR) unittester lib ] : $(3) $(5) : $(6) ;
250c5ff4aa6STyler Dauwalder	R5TestLib $(1) : $(2) : [ FDirName $(OBOS_TEST_DIR) unittester_r5 lib ] : $(4) [ R5SharedLibraryNames $(5) ] ;
251d1f6c38fSTyler Dauwalder}
252d1f6c38fSTyler Dauwalder
253d1f6c38fSTyler Dauwalderrule TestLib
254d1f6c38fSTyler Dauwalder{
255d1f6c38fSTyler Dauwalder	# TestLib <target> : <sources> : <dest> : <libraries> : <public headers>
256d1f6c38fSTyler Dauwalder	# Builds a unit test library for an OBOS module.
257d1f6c38fSTyler Dauwalder	# <target> The name of the target.
258d1f6c38fSTyler Dauwalder	# <sources> The list of sources.
259d1f6c38fSTyler Dauwalder	# <dest> The directory for the target (as passed to FDirName).
260d1f6c38fSTyler Dauwalder	# <libraries> A list of link libraries (as passed to LinkSharedOSLibs).
261d1f6c38fSTyler Dauwalder	# <public headers> A list of public header dirs (as passed to
262d1f6c38fSTyler Dauwalder	# UsePublicHeaders).
263d1f6c38fSTyler Dauwalder
264d1f6c38fSTyler Dauwalder	local target = $(1) ;
265d1f6c38fSTyler Dauwalder	local sources = $(2) ;
266d1f6c38fSTyler Dauwalder	local dest = $(3) ;
267d1f6c38fSTyler Dauwalder	local libraries = $(4) ;
268d1f6c38fSTyler Dauwalder	local headerDirs = $(5) ;
2699342c27aSIngo Weinhold	local objects = [ FGristFiles $(sources:S=$(SUFOBJ)) ] ;
270d1f6c38fSTyler Dauwalder
2719342c27aSIngo Weinhold	# Our Main replacement.
2729342c27aSIngo Weinhold	MainFromObjects $(target) : $(objects) ;
2739342c27aSIngo Weinhold	TestObjects $(sources) : $(headerDirs) ;
274d1f6c38fSTyler Dauwalder
275d1f6c38fSTyler Dauwalder	MakeLocate $(target) : $(dest) ;
2760d1cdd94SIngo Weinhold	Depends $(target) : libcppunit.so ;
2770d1cdd94SIngo Weinhold	Depends obostests : $(target) ;
278d1f6c38fSTyler Dauwalder	LinkSharedOSLibs $(target) : libcppunit.so $(libraries) ;
279d1f6c38fSTyler Dauwalder	LINKFLAGS on $(target) = $(LINKFLAGS) -nostart -Xlinker -soname=\"$(target)\" ;
280d1f6c38fSTyler Dauwalder}
281d1f6c38fSTyler Dauwalder
282d1f6c38fSTyler Dauwalderrule R5TestLib
283d1f6c38fSTyler Dauwalder{
284c5ff4aa6STyler Dauwalder	# R5TestLib <target> : <sources> : <dest> : <libraries>
285d1f6c38fSTyler Dauwalder	# Builds a unit test for an R5 module. "_r5" is appended to the object
286d1f6c38fSTyler Dauwalder	# and the target name.
287d1f6c38fSTyler Dauwalder	# <target> The name of the target.
288d1f6c38fSTyler Dauwalder	# <sources> The list of sources.
289d1f6c38fSTyler Dauwalder	# <dest> The directory for the target (as passed to FDirName).
290d1f6c38fSTyler Dauwalder	# <libraries> A list of link libraries (as passed to LinkSharedOSLibs).
291d1f6c38fSTyler Dauwalder
292d1f6c38fSTyler Dauwalder	local target = $(1:B)_r5$(1:S) ;
293d1f6c38fSTyler Dauwalder	local sources = $(2) ;
294c5ff4aa6STyler Dauwalder	local dest = $(3) ;
295d1f6c38fSTyler Dauwalder	local libraries = $(4) ;
296d1f6c38fSTyler Dauwalder	local objects = [ R5ObjectNames $(sources) ] ;
297d1f6c38fSTyler Dauwalder
298d1f6c38fSTyler Dauwalder	# Our Main replacement.
299d1f6c38fSTyler Dauwalder	MainFromObjects $(target) : $(objects) ;
3009342c27aSIngo Weinhold	TestObjects $(sources) : : true ;
301d1f6c38fSTyler Dauwalder
302d1f6c38fSTyler Dauwalder	MakeLocate $(target) : $(dest) ;
3030d1cdd94SIngo Weinhold	Depends $(target) : libcppunit.so ;
3040d1cdd94SIngo Weinhold	Depends r5tests : $(target) ;
305d1f6c38fSTyler Dauwalder	LinkSharedOSLibs $(target) : libcppunit.so $(libraries) ;
306d1f6c38fSTyler Dauwalder	LINKFLAGS on $(target) = $(LINKFLAGS) -nostart -Xlinker -soname=\"$(target)\" ;
307d1f6c38fSTyler Dauwalder}
308d1f6c38fSTyler Dauwalder
30952a38012Sejakowatzrule CommonUnitTest
31052a38012Sejakowatz{
31152a38012Sejakowatz	# CommonUnitTest <target> : <sources> : <dest> : <obos libraries>
31252a38012Sejakowatz	#	: <r5 libraries> : <public headers>;
31352a38012Sejakowatz	# Builds a unit test for both OBOS and R5 modules.
31452a38012Sejakowatz	# <target> The name of the target.
31552a38012Sejakowatz	# <sources> The list of sources.
31652a38012Sejakowatz	# <dest> The directory for the target (as passed to FDirName).
31752a38012Sejakowatz	# <obos libraries> A list of link libraries for the OBOS tests (as passed
31852a38012Sejakowatz	# to LinkSharedOSLibs).
31952a38012Sejakowatz	# <r5 libraries> A list of link libraries for the R5 tests (as passed
32052a38012Sejakowatz	# to LinkSharedOSLibs).
32152a38012Sejakowatz	# <public headers> A list of public header dirs (as passed to
32252a38012Sejakowatz	# UsePublicHeaders).
32352a38012Sejakowatz
32452a38012Sejakowatz	UnitTest $(1) : $(2) : $(3) : $(4) : $(6) ;
32552a38012Sejakowatz	R5UnitTest $(1) : $(2) : $(3) : $(5) ;
32652a38012Sejakowatz}
32752a38012Sejakowatz
32852a38012Sejakowatzrule UnitTest
32952a38012Sejakowatz{
33052a38012Sejakowatz	# UnitTest <target> : <sources> : <dest> : <libraries> : <public headers>
33152a38012Sejakowatz	# Builds a unit test for an OBOS module.
33252a38012Sejakowatz	# <target> The name of the target.
33352a38012Sejakowatz	# <sources> The list of sources.
33452a38012Sejakowatz	# <dest> The directory for the target (as passed to FDirName).
33552a38012Sejakowatz	# <libraries> A list of link libraries (as passed to LinkSharedOSLibs).
33652a38012Sejakowatz	# <public headers> A list of public header dirs (as passed to
33752a38012Sejakowatz	# UsePublicHeaders).
33852a38012Sejakowatz
33952a38012Sejakowatz	local target = $(1) ;
34052a38012Sejakowatz	local sources = $(2) ;
34152a38012Sejakowatz	local dest = $(3) ;
34252a38012Sejakowatz	local libraries = $(4) ;
34352a38012Sejakowatz	local headerDirs = $(5) ;
3449342c27aSIngo Weinhold	local objects = [ FGristFiles $(sources:S=$(SUFOBJ)) ] ;
34552a38012Sejakowatz
3469342c27aSIngo Weinhold	# Our Main replacement.
3479342c27aSIngo Weinhold	MainFromObjects $(target) : $(objects) ;
3489342c27aSIngo Weinhold	TestObjects $(sources) : $(headerDirs) ;
3493b9eae39SIngo Weinhold
35052a38012Sejakowatz	MakeLocate $(target) : [ FDirName $(OBOS_TEST_DIR) $(dest) ] ;
3519eea4522SIngo Weinhold	Depends $(target) : libcppunit.so ;
3529eea4522SIngo Weinhold	Depends obostests : $(target) ;
35352a38012Sejakowatz	LinkSharedOSLibs $(target) : libcppunit.so $(libraries) ;
35452a38012Sejakowatz}
35552a38012Sejakowatz
35652a38012Sejakowatzrule R5UnitTest
35752a38012Sejakowatz{
35852a38012Sejakowatz	# R5UnitTest <target> : <sources> : <dest> : <libraries>
35952a38012Sejakowatz	# Builds a unit test for an R5 module. "_r5" is appended to the object
36052a38012Sejakowatz	# and the target name.
36152a38012Sejakowatz	# <target> The name of the target.
36252a38012Sejakowatz	# <sources> The list of sources.
36352a38012Sejakowatz	# <dest> The directory for the target (as passed to FDirName).
36452a38012Sejakowatz	# <libraries> A list of link libraries (as passed to LinkSharedOSLibs).
36552a38012Sejakowatz
36652a38012Sejakowatz	local target = $(1)_r5 ;
36752a38012Sejakowatz	local sources = $(2) ;
36852a38012Sejakowatz	local dest = $(3) ;
36952a38012Sejakowatz	local libraries = $(4) ;
37052a38012Sejakowatz	local objects = [ R5ObjectNames $(sources) ] ;
37152a38012Sejakowatz
37252a38012Sejakowatz	# Our Main replacement.
37352a38012Sejakowatz	MainFromObjects $(target) : $(objects) ;
3749342c27aSIngo Weinhold	TestObjects $(sources) : : true ;
37552a38012Sejakowatz
37652a38012Sejakowatz	MakeLocate $(target) : [ FDirName $(OBOS_TEST_DIR) $(dest) ] ;
3779eea4522SIngo Weinhold	Depends $(target) : libcppunit.so ;
3789eea4522SIngo Weinhold	Depends r5tests : $(target) ;
37952a38012Sejakowatz	LinkSharedOSLibs $(target) : libcppunit.so $(libraries) ;
38052a38012Sejakowatz}
38152a38012Sejakowatz
38252a38012Sejakowatzrule R5ObjectNames
38352a38012Sejakowatz{
38452a38012Sejakowatz	# R5ObjectNames <sources> ;
38552a38012Sejakowatz	# Returns a list of gristed object names given a list of source file names.
38652a38012Sejakowatz	# Moreover each object names gets "_r5" inserted before the object suffix.
38752a38012Sejakowatz	local objects = $(1:S=)_r5 ;
38852a38012Sejakowatz	return [ FGristFiles $(objects:S=$(SUFOBJ)) ] ;
38952a38012Sejakowatz}
39052a38012Sejakowatz
3919342c27aSIngo Weinholdrule R5Objects
3929342c27aSIngo Weinhold{
3939342c27aSIngo Weinhold	# R5Objects <sources>
3949342c27aSIngo Weinhold	# Similar to Objects, but appends "_r5" to the object file names.
3959342c27aSIngo Weinhold	# <sources> The source files.
3969342c27aSIngo Weinhold
3979342c27aSIngo Weinhold	local sources = $(1) ;
3989342c27aSIngo Weinhold	local source ;
3999342c27aSIngo Weinhold	for source in [ FGristFiles $(sources) ]
4009342c27aSIngo Weinhold	{
4019342c27aSIngo Weinhold		local object = [ R5ObjectNames $(source) ] ;
4029342c27aSIngo Weinhold		Object $(object) : $(source) ;
4039342c27aSIngo Weinhold		LocalDepends obj : $(object) ;
4049342c27aSIngo Weinhold	}
4059342c27aSIngo Weinhold}
4069342c27aSIngo Weinhold
4079342c27aSIngo Weinholdrule TestObjects
4089342c27aSIngo Weinhold{
4099342c27aSIngo Weinhold	# TestLib <sources> : <public headers> : <r5>
4109342c27aSIngo Weinhold	# Compiles objects for tests.
4119342c27aSIngo Weinhold	# <sources> The list of sources.
4129342c27aSIngo Weinhold	# <public headers> A list of public header dirs (as passed to
4139342c27aSIngo Weinhold	# UsePublicHeaders).
4149342c27aSIngo Weinhold	# <r5> If set, "_r5" is appended to the object file names and
4159342c27aSIngo Weinhold	# <public headers> is ignored. Furthermore the pre-processor macro
4169342c27aSIngo Weinhold	# TEST_R5 is defined, TEST_OBOS otherwise.
4179342c27aSIngo Weinhold
4189342c27aSIngo Weinhold	local sources = $(1) ;
4199342c27aSIngo Weinhold	local headerDirs = $(2) ;
4209342c27aSIngo Weinhold	local r5 = $(3) ;
4219342c27aSIngo Weinhold	local objects ;
4229342c27aSIngo Weinhold
4239342c27aSIngo Weinhold	# Turn optimization off.
42496d27465SIngo Weinhold	if ! $(NO_TEST_DEBUG) {
4259342c27aSIngo Weinhold		local optim = $(OPTIM) ;
4269342c27aSIngo Weinhold		OPTIM = ;
42796d27465SIngo Weinhold	}
4289342c27aSIngo Weinhold
4299342c27aSIngo Weinhold	SetupObjectsDir ;
4309342c27aSIngo Weinhold
4319342c27aSIngo Weinhold	# compile
4329342c27aSIngo Weinhold	if $(r5) {
4339342c27aSIngo Weinhold		objects = [ R5ObjectNames $(sources) ] ;
4349342c27aSIngo Weinhold		R5Objects $(sources) ;
4359342c27aSIngo Weinhold	} else {
4369342c27aSIngo Weinhold		objects = [ FGristFiles $(sources:S=$(SUFOBJ)) ] ;
4379342c27aSIngo Weinhold		Objects $(sources) ;
4389342c27aSIngo Weinhold	}
4399342c27aSIngo Weinhold
4409342c27aSIngo Weinhold	# set headers/defines
4419342c27aSIngo Weinhold	UseCppUnitObjectHeaders $(objects) ;
4429342c27aSIngo Weinhold	if $(r5) {
4439342c27aSIngo Weinhold		ObjectDefines $(objects) : TEST_R5 ;
4449342c27aSIngo Weinhold	} else {
4459342c27aSIngo Weinhold		UsePublicObjectHeaders $(objects) : $(headerDirs) ;
4469342c27aSIngo Weinhold		ObjectDefines $(objects) : TEST_OBOS ;
4479342c27aSIngo Weinhold	}
4489342c27aSIngo Weinhold
44996d27465SIngo Weinhold	if ! $(NO_TEST_DEBUG) {
4509342c27aSIngo Weinhold		# Turn debugging on. That is usually desired for test code.
4519342c27aSIngo Weinhold		ObjectCcFlags $(objects) : "-g" ;
4529342c27aSIngo Weinhold		ObjectC++Flags $(objects) : "-g" ;
4539342c27aSIngo Weinhold
4549342c27aSIngo Weinhold		# Turn optimization on again.
4559342c27aSIngo Weinhold		OPTIM = $(optim) ;
4569342c27aSIngo Weinhold	}
45796d27465SIngo Weinhold}
4589342c27aSIngo Weinhold
4599285de51STyler Dauwalderrule R5SharedLibraryNames
4609285de51STyler Dauwalder{
4619285de51STyler Dauwalder	# R5SharedLibraryNames <sources> ;
4629285de51STyler Dauwalder	# Returns a list of shared library names given a list of file names. NO
4639285de51STyler Dauwalder	# GRISTING IS PERFORMED :-) However, each library names gets "_r5" inserted
4649285de51STyler Dauwalder	# before the shared lib suffix.
4659285de51STyler Dauwalder	return $(1:S=)_r5.so ;
4669285de51STyler Dauwalder}
4679285de51STyler Dauwalder
4689fc6b2e1SIngo Weinholdrule SimpleTest
4699fc6b2e1SIngo Weinhold{
4709fc6b2e1SIngo Weinhold	# UnitTest <target> : <sources> : <libraries>
4719fc6b2e1SIngo Weinhold	# Builds a unit test for an OBOS module.
4729fc6b2e1SIngo Weinhold	# <target> The name of the target.
4739fc6b2e1SIngo Weinhold	# <sources> The list of sources.
4749fc6b2e1SIngo Weinhold	# <dest> The directory for the target (as passed to FDirName).
4759fc6b2e1SIngo Weinhold	# <libraries> A list of link libraries (as passed to LinkSharedOSLibs).
4769fc6b2e1SIngo Weinhold	# <public headers> A list of public header dirs (as passed to
4779fc6b2e1SIngo Weinhold	# UsePublicHeaders).
4789fc6b2e1SIngo Weinhold
4799fc6b2e1SIngo Weinhold	local target = $(1) ;
4809fc6b2e1SIngo Weinhold	local sources = $(2) ;
4819fc6b2e1SIngo Weinhold	local libraries = $(3) ;
4829fc6b2e1SIngo Weinhold	local relPath = [ FRelPath src tests : $(SUBDIR_TOKENS) ] ;
4839fc6b2e1SIngo Weinhold
4849fc6b2e1SIngo Weinhold	# Turn optimization off.
48596d27465SIngo Weinhold	if ! $(NO_TEST_DEBUG) {
4869fc6b2e1SIngo Weinhold		local optim = $(OPTIM) ;
4879fc6b2e1SIngo Weinhold		OPTIM = ;
48896d27465SIngo Weinhold	}
4899fc6b2e1SIngo Weinhold
4909fc6b2e1SIngo Weinhold#	SetupIncludes ;
4919fc6b2e1SIngo Weinhold	SetupObjectsDir ;
4929fc6b2e1SIngo Weinhold	MakeLocateObjects $(sources) ;
4939fc6b2e1SIngo Weinhold	Main $(target) : $(sources) ;
4949fc6b2e1SIngo Weinhold	MakeLocate $(target) : [ FDirName $(OBOS_TEST_DIR) $(relPath) ] ;
4959eea4522SIngo Weinhold	Depends obostests : $(target) ;
4969fc6b2e1SIngo Weinhold	LinkSharedOSLibs $(target) : $(libraries) ;
4979fc6b2e1SIngo Weinhold	ObjectDefines $(sources) : TEST_OBOS ;
4989fc6b2e1SIngo Weinhold
49996d27465SIngo Weinhold	if ! $(NO_TEST_DEBUG) {
5009fc6b2e1SIngo Weinhold		# Turn debugging on. That is usually desired for test code.
5019fc6b2e1SIngo Weinhold		ObjectCcFlags $(sources) : "-g" ;
5029fc6b2e1SIngo Weinhold		ObjectC++Flags $(sources) : "-g" ;
5039fc6b2e1SIngo Weinhold
5049fc6b2e1SIngo Weinhold		# Turn optimization on again.
5059fc6b2e1SIngo Weinhold		OPTIM = $(optim) ;
5069fc6b2e1SIngo Weinhold	}
50796d27465SIngo Weinhold}
5089fc6b2e1SIngo Weinhold
50952a38012Sejakowatzrule Addon
51052a38012Sejakowatz{
5117a384fdeSIngo Weinhold	# Addon <name> : <relpath> : <sources> : <is executable> ;
5127a384fdeSIngo Weinhold	# <name>: Name of the add-on.
5137a384fdeSIngo Weinhold	# <relpath>: Path where the add-on shall live relative to the add-on dir.
5147a384fdeSIngo Weinhold	# <sources>: Source files.
5157a384fdeSIngo Weinhold	# <is executable>: true, if the target shall be executable as well
5167a384fdeSIngo Weinhold
5177a384fdeSIngo Weinhold	local isExecutable = $(4) ;
51852a38012Sejakowatz
5197d7f280eSIngo Weinhold#	SetupIncludes ;
52052a38012Sejakowatz	SetupObjectsDir ;
52152a38012Sejakowatz	Main $(1) : $(3) ;
52252a38012Sejakowatz
52352a38012Sejakowatz	# Create output dir path for addon
52452a38012Sejakowatz	local targetdir;
52552a38012Sejakowatz	targetdir = [ FDirName $(OBOS_ADDON_DIR) $(2) ] ;
52652a38012Sejakowatz
52752a38012Sejakowatz	MakeLocate $(1) : $(targetdir) ;
5287a384fdeSIngo Weinhold
5297a384fdeSIngo Weinhold	local linkFlags = -Xlinker -soname=\"$(1)\" ;
5307a384fdeSIngo Weinhold	if $(isExecutable) != true {
5317a384fdeSIngo Weinhold		linkFlags = -nostart $(linkFlags) ;
5327a384fdeSIngo Weinhold	}
5337a384fdeSIngo Weinhold	LINKFLAGS on $(1) = [ on $(1) return $(LINKFLAGS) ] $(linkFlags) ;
534af28904fSIngo Weinhold}
535af28904fSIngo Weinhold
53658efc9d8SIngo Weinholdrule R5KernelAddon
537af28904fSIngo Weinhold{
53858efc9d8SIngo Weinhold	# R5KernelAddon <name> : <relpath> : <sources> ;
539af28904fSIngo Weinhold
540af28904fSIngo Weinhold	local sources = $(3) ;
541af28904fSIngo Weinhold
542af28904fSIngo Weinhold	Addon $(1) : $(2) : $(3) ;
543af28904fSIngo Weinhold	ObjectCcFlags $(sources) : -D_KERNEL_MODE=1 -no-fpic ;
544af28904fSIngo Weinhold	ObjectC++Flags $(sources) : -D_KERNEL_MODE=1 -no-fpic
545af28904fSIngo Weinhold								-fno-exceptions -fno-rtti ;
5469eea4522SIngo Weinhold	LINKFLAGS on $(1) = [ on $(1) return $(LINKFLAGS) ] -nostdlib ;
547af28904fSIngo Weinhold	LinkSharedOSLibs $(1) : /boot/develop/lib/x86/_KERNEL_ ;
54852a38012Sejakowatz}
54952a38012Sejakowatz
5504fb5add0SMatthew Wilberrule Translator
5514fb5add0SMatthew Wilber{
5524fb5add0SMatthew Wilber	# Translator <name> : <sources> ;
5534fb5add0SMatthew Wilber	SetupObjectsDir ;
5544fb5add0SMatthew Wilber	Main $(1) : $(2) ;
5554fb5add0SMatthew Wilber
5564fb5add0SMatthew Wilber	# Create output dir path for translator
5574fb5add0SMatthew Wilber	local targetdir;
5584fb5add0SMatthew Wilber	targetdir = [ FDirName $(OBOS_ADDON_DIR) translators ] ;
5594fb5add0SMatthew Wilber	MakeLocate $(1) : $(targetdir) ;
5604fb5add0SMatthew Wilber}
5614fb5add0SMatthew Wilber
56252a38012Sejakowatzrule MakeLocateObjects
56352a38012Sejakowatz{
56452a38012Sejakowatz	# MakeLocateObjects <gristed_sources_or_objects> ;
56552a38012Sejakowatz
56652a38012Sejakowatz	local _objs = $(1:S=$(SUFOBJ)) ;
56752a38012Sejakowatz
56852a38012Sejakowatz	for o in $(_objs)
56952a38012Sejakowatz	{
57052a38012Sejakowatz		local dir = $(o:D) ;
57152a38012Sejakowatz		if $(dir) {
57252a38012Sejakowatz			MakeLocate $(o) : [ FDirName $(LOCATE_TARGET) $(dir) ] ;
57352a38012Sejakowatz		} else {
57452a38012Sejakowatz			MakeLocate $(o) : $(LOCATE_TARGET) ;
57552a38012Sejakowatz		}
57652a38012Sejakowatz	}
57752a38012Sejakowatz}
57852a38012Sejakowatz
57952a38012Sejakowatzrule StaticLibrary
58052a38012Sejakowatz{
58152a38012Sejakowatz	# StaticLibrary <name> : <sources> ;
58252a38012Sejakowatz
58308125d07SIngo Weinhold#	SetupIncludes ;
58452a38012Sejakowatz	SetupObjectsDir ;
58552a38012Sejakowatz	MakeLocateObjects $(2) ;
58652a38012Sejakowatz	Library lib$(<).a : $(>) ;
58752a38012Sejakowatz	MakeLocate lib$(<).a : $(OBOS_STLIB_DIR) ;
58852a38012Sejakowatz}
58952a38012Sejakowatz
59052a38012Sejakowatzrule SharedLibrary
59152a38012Sejakowatz{
59252a38012Sejakowatz	# SharedLibrary <name> : <sources> ;
59352a38012Sejakowatz	local _lib = lib$(1).so ;
59452a38012Sejakowatz
59552a38012Sejakowatz#	SetupIncludes ;
59652a38012Sejakowatz	SetupObjectsDir ;
59752a38012Sejakowatz	MakeLocateObjects $(2) ;
59852a38012Sejakowatz	Main $(_lib) : $(2) ;
59952a38012Sejakowatz	MakeLocate $(_lib) : $(OBOS_SHLIB_DIR) ;
6009eea4522SIngo Weinhold	LINKFLAGS on $(_lib) = [ on $(_lib) return $(LINKFLAGS) ]
6019eea4522SIngo Weinhold						   -nostart -Xlinker -soname=\"$(_lib)\" ;
60252a38012Sejakowatz}
60352a38012Sejakowatz
60452a38012Sejakowatzrule LinkSharedOSLibs
60552a38012Sejakowatz{
60652a38012Sejakowatz	# LinkSharedOSLibs <name> : <libs> ;
60752a38012Sejakowatz	# Valid elements for <libs> are e.g. "be" or "libopenbeos.so" or
6084236d490SIngo Weinhold	# "/boot/.../libfoo.so". If the basename starts with "lib" or the thingy
6094236d490SIngo Weinhold	# has a dirname or grist, it is added to the NEEDLIBS variable (i.e. the
6104236d490SIngo Weinhold	# file will be bound!), otherwise it is prefixed "-l" and added to
6114236d490SIngo Weinhold	# LINKLIBS.
61252a38012Sejakowatz
61352a38012Sejakowatz	for i in $(>)
61452a38012Sejakowatz	{
6154236d490SIngo Weinhold		local isfile = ;
6164236d490SIngo Weinhold		if $(i:D) || $(i:G) {
6174236d490SIngo Weinhold			isfile = true ;
6184236d490SIngo Weinhold		} else {
61952a38012Sejakowatz			switch $(i:B)
62052a38012Sejakowatz			{
6214236d490SIngo Weinhold				case lib*	: isfile = true ;
6224236d490SIngo Weinhold				case *		: isfile = ;
6234236d490SIngo Weinhold			}
6244236d490SIngo Weinhold		}
6254236d490SIngo Weinhold		if $(isfile) {
6269eea4522SIngo Weinhold			NEEDLIBS on $(1) = [ on $(1) return $(NEEDLIBS) ] $(i) ;
6279eea4522SIngo Weinhold			Depends $(1) : $(i) ;
6284236d490SIngo Weinhold		} else {
6299eea4522SIngo Weinhold			LINKLIBS on $(1) = [ on $(1) return $(LINKLIBS) ] -l$(i) ;
63052a38012Sejakowatz		}
63152a38012Sejakowatz	}
63252a38012Sejakowatz}
63352a38012Sejakowatz
63452a38012Sejakowatzrule LinkStaticOSLibs
63552a38012Sejakowatz{
63652a38012Sejakowatz	# LinkStaticOSLibs <name> : <libs> ;
63752a38012Sejakowatz
63852a38012Sejakowatz	for i in $(>)
63952a38012Sejakowatz	{
64052a38012Sejakowatz		LINKLIBS on $(<) = $(LINKLIBS) -l $(i) ;
64152a38012Sejakowatz	}
64252a38012Sejakowatz}
64352a38012Sejakowatz
64452a38012Sejakowatzrule AddResources
64552a38012Sejakowatz{
64652a38012Sejakowatz	# AddResources <name> : <resourcefiles> ;
64752a38012Sejakowatz
6489fc6b2e1SIngo Weinhold	SEARCH on $(2) += $(SEARCH_SOURCE) ;
64978599cf0SIngo Weinhold	RESFILES on $(1) += $(2) ;
65052a38012Sejakowatz}
65152a38012Sejakowatz
6527d7f280eSIngo Weinholdrule PublicHeaders
65352a38012Sejakowatz{
6547d7f280eSIngo Weinhold	# PublicHeaders <group list>
65552a38012Sejakowatz	#
6567d7f280eSIngo Weinhold	# Returns the directory names for the public header dirs identified by
6577d7f280eSIngo Weinhold	# <group list>.
65852a38012Sejakowatz
65952a38012Sejakowatz	local list = $(1) ;
660b005dbe3SAxel Dörfler	local dirs = [ FDirName $(OBOS_TOP) headers os ] ;
661b005dbe3SAxel Dörfler
66252a38012Sejakowatz	for i in $(list) {
6637d7f280eSIngo Weinhold		dirs += [ FDirName $(OBOS_TOP) headers os $(i) ] ;
6647d7f280eSIngo Weinhold	}
6657d7f280eSIngo Weinhold	return $(dirs) ;
66652a38012Sejakowatz}
66752a38012Sejakowatz
6687d7f280eSIngo Weinholdrule PrivateHeaders
6697d7f280eSIngo Weinhold{
6707d7f280eSIngo Weinhold	# PrivateHeaders <group list>
6717d7f280eSIngo Weinhold	#
6727d7f280eSIngo Weinhold	# Returns the directory names for the private header dirs identified by
6737d7f280eSIngo Weinhold	# <group list>.
6747d7f280eSIngo Weinhold
6757d7f280eSIngo Weinhold	local list = $(1) ;
6767d7f280eSIngo Weinhold	local dirs ;
6777d7f280eSIngo Weinhold	for i in $(list) {
6787d7f280eSIngo Weinhold		dirs += [ FDirName $(OBOS_TOP) headers private $(i) ] ;
6797d7f280eSIngo Weinhold	}
6807d7f280eSIngo Weinhold	return $(dirs) ;
6817d7f280eSIngo Weinhold}
6827d7f280eSIngo Weinhold
6837d7f280eSIngo Weinholdrule ArchHeaders
6847d7f280eSIngo Weinhold{
6857d7f280eSIngo Weinhold	# usage: ArchHeaders <arch> ;
6867d7f280eSIngo Weinhold	#
6877d7f280eSIngo Weinhold	# <arch> specifies the architecture (e.g. x86).
6887d7f280eSIngo Weinhold
6897d7f280eSIngo Weinhold	return [ FDirName $(OBOS_TOP) headers private kernel arch $(1) ] ;
6907d7f280eSIngo Weinhold}
6917d7f280eSIngo Weinhold
6927d7f280eSIngo Weinholdrule UsePublicHeaders
6937d7f280eSIngo Weinhold{
6947d7f280eSIngo Weinhold	# UsePublicHeaders <group list> ;
6957d7f280eSIngo Weinhold	#
6967d7f280eSIngo Weinhold	# Adds the public C header dirs given by <group list> to the header search
6977d7f280eSIngo Weinhold	# dirs of the subdirectory.
6987d7f280eSIngo Weinhold	# NOTE: This rule must be invoked *before* the rule that builds the objects.
6997d7f280eSIngo Weinhold
7007d7f280eSIngo Weinhold	UseHeaders [ PublicHeaders $(1) ] ;
7017d7f280eSIngo Weinhold}
7027d7f280eSIngo Weinhold
7037d7f280eSIngo Weinholdrule UsePublicObjectHeaders
7047d7f280eSIngo Weinhold{
7057d7f280eSIngo Weinhold	# UsePublicObjectHeaders <sources_or_objects> : <group list> ;
7067d7f280eSIngo Weinhold	#
7077d7f280eSIngo Weinhold	# Adds the public C header dirs given by <group list> to the header search
7087d7f280eSIngo Weinhold	# dirs of <sources_or_objects>.
7097d7f280eSIngo Weinhold	# NOTE: This rule must be invoked *after* the rule that builds the objects.
7107d7f280eSIngo Weinhold
7117d7f280eSIngo Weinhold	ObjectHdrs $(1) : [ PublicHeaders $(2) ] ;
71252a38012Sejakowatz}
71352a38012Sejakowatz
71452a38012Sejakowatzrule UsePrivateHeaders
71552a38012Sejakowatz{
7167d7f280eSIngo Weinhold	# UsePrivateHeaders <group list> ;
71752a38012Sejakowatz	#
71852a38012Sejakowatz	# Adds the private C header dirs given by <group list> to the header search
7197d7f280eSIngo Weinhold	# dirs of the subdirectory.
7207d7f280eSIngo Weinhold	# NOTE: This rule must be invoked *before* the rule that builds the objects.
72152a38012Sejakowatz
7227d7f280eSIngo Weinhold	UseHeaders [ PrivateHeaders $(1) ] ;
72352a38012Sejakowatz}
72452a38012Sejakowatz
7257d7f280eSIngo Weinholdrule UsePrivateObjectHeaders
7267d7f280eSIngo Weinhold{
7277d7f280eSIngo Weinhold	# UsePrivateObjectHeaders <sources_or_objects> : <group list> ;
7287d7f280eSIngo Weinhold	#
7297d7f280eSIngo Weinhold	# Adds the private C header dirs given by <group list> to the header search
7307d7f280eSIngo Weinhold	# dirs of <sources_or_objects>.
7317d7f280eSIngo Weinhold	# NOTE: This rule must be invoked *after* the rule that builds the objects.
7327d7f280eSIngo Weinhold
7337d7f280eSIngo Weinhold	ObjectHdrs $(1) : [ PrivateHeaders $(2) ] ;
73452a38012Sejakowatz}
73552a38012Sejakowatz
73652a38012Sejakowatzrule UseHeaders
73752a38012Sejakowatz{
7387d7f280eSIngo Weinhold	# UseHeaders <headers> ;
73952a38012Sejakowatz	#
74052a38012Sejakowatz	# Adds the C header dirs <headers> to the header search
7417d7f280eSIngo Weinhold	# dirs of the subdirectory.
7427d7f280eSIngo Weinhold	# NOTE: This rule must be invoked *before* the rule that builds the objects.
74352a38012Sejakowatz
7447d7f280eSIngo Weinhold	local header ;
7457d7f280eSIngo Weinhold	for header in $(1) {
74652a38012Sejakowatz		SubDirHdrs $(header) ;
74752a38012Sejakowatz	}
74852a38012Sejakowatz}
74952a38012Sejakowatz
75052a38012Sejakowatzrule UseCppUnitHeaders
75152a38012Sejakowatz{
7527d7f280eSIngo Weinhold	SubDirHdrs [ FDirName $(OBOS_TOP) headers tools cppunit ] ;
75352a38012Sejakowatz}
75452a38012Sejakowatz
755be5af1baSIngo Weinholdrule UseCppUnitObjectHeaders
756be5af1baSIngo Weinhold{
757be5af1baSIngo Weinhold	ObjectHdrs $(1) : [ FDirName $(OBOS_TOP) headers tools cppunit ] ;
758be5af1baSIngo Weinhold}
759be5af1baSIngo Weinhold
76052a38012Sejakowatzrule UseArchHeaders
76152a38012Sejakowatz{
7627d7f280eSIngo Weinhold	# usage: UseArchHeaders <arch> ;
7637d7f280eSIngo Weinhold	#
76452a38012Sejakowatz	# <arch> specifies the architecture (e.g. x86).
7657d7f280eSIngo Weinhold	# NOTE: This rule must be invoked *before* the rule that builds the objects.
7667d7f280eSIngo Weinhold
7677d7f280eSIngo Weinhold	local headers = [ ArchHeaders $(1) ] ;
76852a38012Sejakowatz	local opt = -D$(OBOS_TARGET_DEFINE) ;
769c633961aSIngo Weinhold
77052a38012Sejakowatz	SubDirCcFlags $(opt)  ;
77152a38012Sejakowatz	SubDirC++Flags $(opt)  ;
772c633961aSIngo Weinhold	SubDirHdrs $(headers) ;
773c633961aSIngo Weinhold}
774c633961aSIngo Weinhold
7757d7f280eSIngo Weinholdrule UseArchObjectHeaders
7767d7f280eSIngo Weinhold{
7777d7f280eSIngo Weinhold	# usage: UseArchObjectHeaders <sources_or_objects> : <arch> ;
7787d7f280eSIngo Weinhold	#
7797d7f280eSIngo Weinhold	# <arch> specifies the architecture (e.g. x86).
7807d7f280eSIngo Weinhold	# <sources_or_objects> Source or object files.
7817d7f280eSIngo Weinhold	# NOTE: This rule must be invoked *after* the rule that builds the objects.
7827d7f280eSIngo Weinhold
7837d7f280eSIngo Weinhold	local targets = $(1) ;
7847d7f280eSIngo Weinhold	local headers = [ ArchHeaders $(2) ] ;
7857d7f280eSIngo Weinhold	local opt = -D$(OBOS_TARGET_DEFINE) ;
7867d7f280eSIngo Weinhold
7877d7f280eSIngo Weinhold	ObjectCcFlags $(targets) : $(opt)  ;
7887d7f280eSIngo Weinhold	ObjectC++Flags $(targets) : $(opt)  ;
7897d7f280eSIngo Weinhold	ObjectHdrs $(targets) : $(headers) ;
79052a38012Sejakowatz}
79152a38012Sejakowatz
792d25a77b4SIngo Weinholdrule UsePosixHeaders
793d25a77b4SIngo Weinhold{
794d25a77b4SIngo Weinhold	# UsePrivateHeaders <group list> ;
795d25a77b4SIngo Weinhold	#
796d25a77b4SIngo Weinhold	# Adds the POSIX header dir to the header search
797d25a77b4SIngo Weinhold	# dirs of the subdirectory.
798d25a77b4SIngo Weinhold	# NOTE: This rule must be invoked *before* the rule that builds the objects.
799d25a77b4SIngo Weinhold
800d25a77b4SIngo Weinhold	SubDirHdrs [ FDirName $(OBOS_TOP) headers posix ] ;
801d25a77b4SIngo Weinhold}
802d25a77b4SIngo Weinhold
803d25a77b4SIngo Weinholdrule UsePosixObjectHeaders
804d25a77b4SIngo Weinhold{
805d25a77b4SIngo Weinhold	# UsePosixObjectHeaders <sources_or_objects> ;
806d25a77b4SIngo Weinhold	#
807d25a77b4SIngo Weinhold	# Adds the POSIX header dir to the header search
808d25a77b4SIngo Weinhold	# dirs of <sources_or_objects>.
809d25a77b4SIngo Weinhold	# NOTE: This rule must be invoked *after* the rule that builds the objects.
810d25a77b4SIngo Weinhold
811d25a77b4SIngo Weinhold	ObjectHdrs $(1) : [ FDirName $(OBOS_TOP) headers posix ] ;
812d25a77b4SIngo Weinhold}
813d25a77b4SIngo Weinhold
8143b9eae39SIngo Weinholdrule SplitPath
8153b9eae39SIngo Weinhold{
8163b9eae39SIngo Weinhold	# SplitPath <path> ;
8173b9eae39SIngo Weinhold	# Decomposes a path into its components.
8183b9eae39SIngo Weinhold	local path = $(1:G=) ;
8193b9eae39SIngo Weinhold	local components ;
8208c27f58dSIngo Weinhold	# $(path:D) for "/" is "/". Therefore the second condition.
8218c27f58dSIngo Weinhold	while $(path:D) && $(path:D) != $(path)
8223b9eae39SIngo Weinhold	{
8233b9eae39SIngo Weinhold		# Note: $(path:B) returns "." for "..", but $(path:D=) is fine.
8243b9eae39SIngo Weinhold		components = $(path:D=) $(components) ;
8253b9eae39SIngo Weinhold		path = $(path:D) ;
8263b9eae39SIngo Weinhold	}
8273b9eae39SIngo Weinhold	components = $(path) $(components) ;
8283b9eae39SIngo Weinhold	return $(components) ;
8293b9eae39SIngo Weinhold}
8303b9eae39SIngo Weinhold
8319fc6b2e1SIngo Weinholdrule PrependObjectHdrs
8329fc6b2e1SIngo Weinhold{
8339fc6b2e1SIngo Weinhold	# PrependObjectHdrs <objects_or_sources> : <dirs> ;
8349fc6b2e1SIngo Weinhold	# Prepends <dirs> to the list of header search dirs of the objects
8359fc6b2e1SIngo Weinhold	# specified by <objects_or_sources>. The HDRS variable will not be
8369fc6b2e1SIngo Weinhold	# changed, only CCHDRS.
8379fc6b2e1SIngo Weinhold	# Note: A subsequent ObjectHdrs invocation will therefore undo the
8389fc6b2e1SIngo Weinhold	# effect of this rule.
8399fc6b2e1SIngo Weinhold	# NOTE: This is a hack.
8409fc6b2e1SIngo Weinhold
8419fc6b2e1SIngo Weinhold	local objects = [ FGristFiles $(1:S=$(SUFOBJ)) ] ;
8429fc6b2e1SIngo Weinhold	local dirs = $(2) ;
8439fc6b2e1SIngo Weinhold	for object in $(objects) {
8449fc6b2e1SIngo Weinhold		# Don't change HDRS to avoid screwing up the header scanning.
8459fc6b2e1SIngo Weinhold		PREPENDED_HDRS on $(object)
8469fc6b2e1SIngo Weinhold			= $(dirs) [ on $(object) return $(PREPENDED_HDRS) ] ;
8479fc6b2e1SIngo Weinhold		CCHDRS on $(object)
8489fc6b2e1SIngo Weinhold			= [ FIncludes [ on $(object) return $(PREPENDED_HDRS) $(HDRS) ] ] ;
8499fc6b2e1SIngo Weinhold	}
8509fc6b2e1SIngo Weinhold}
8519fc6b2e1SIngo Weinhold
8523b9eae39SIngo Weinholdrule SymLink
8533b9eae39SIngo Weinhold{
8543b9eae39SIngo Weinhold	# SymLink <target> : <source> ;
8553b9eae39SIngo Weinhold	# Links <target> to <source>.
8563b9eae39SIngo Weinhold	# <source> is the exact link contents. No binding is done.
8573b9eae39SIngo Weinhold	LINKCONTENTS on $(1) = $(2) ;
8583b9eae39SIngo Weinhold	SymLink1 $(1) ;
8599eea4522SIngo Weinhold	LocalDepends all : $(target) ;
8603b9eae39SIngo Weinhold}
8613b9eae39SIngo Weinhold
8623b9eae39SIngo Weinholdactions SymLink1
8633b9eae39SIngo Weinhold{
8640931b8f9SIngo Weinhold	$(RM) "$(1)" && $(LN) -s "$(LINKCONTENTS)" "$(1)"
8650931b8f9SIngo Weinhold}
8660931b8f9SIngo Weinhold
8670931b8f9SIngo Weinholdrule RelSymLink
8680931b8f9SIngo Weinhold{
8690931b8f9SIngo Weinhold	# RelSymLink <link> : <link target>
8700931b8f9SIngo Weinhold	# Creates a relative symbolic link from <link> to <link target>.
8710931b8f9SIngo Weinhold	# <link> and <link target> can be usual targets. They may have a grist
8720931b8f9SIngo Weinhold	# and don't need to have any dirname. Their LOCATE variables are used to
8730931b8f9SIngo Weinhold	# find their locations.
8740931b8f9SIngo Weinhold
8750931b8f9SIngo Weinhold	local target = $(1) ;
8760931b8f9SIngo Weinhold	local source = $(2) ;
8770931b8f9SIngo Weinhold	local targetDir = [ on $(target) FDirName $(LOCATE[1]) $(target:D) ] ;
8780931b8f9SIngo Weinhold	local sourceDir = [ on $(source) FDirName $(LOCATE[1]) $(source:D) ] ;
8790931b8f9SIngo Weinhold	local sourcePath = $(source:G=) ;
8800931b8f9SIngo Weinhold	sourcePath = $(sourcePath:D=$(sourceDir)) ;
8810931b8f9SIngo Weinhold	local targetDirComponents = [ SplitPath $(targetDir) ] ;
8820931b8f9SIngo Weinhold	local sourceComponents = [ SplitPath $(sourcePath) ] ;
8830931b8f9SIngo Weinhold
8840931b8f9SIngo Weinhold	SymLink $(target)
8850931b8f9SIngo Weinhold		: [ FRelPath $(targetDirComponents) : $(sourceComponents) ] ;
8860931b8f9SIngo Weinhold	NOUPDATE $(target);
8879eea4522SIngo Weinhold	Depends $(target) : $(source) ;
8886991af8cSIngo Weinhold	LocalClean clean : $(target) ;
8893b9eae39SIngo Weinhold}
8903b9eae39SIngo Weinhold
89152a38012Sejakowatz#-------------------------------------------------------------------------------
89252a38012Sejakowatz# Low-level OBOS utility rules
89352a38012Sejakowatz#-------------------------------------------------------------------------------
89452a38012Sejakowatzrule SetupObjectsDir
89552a38012Sejakowatz{
89652a38012Sejakowatz	local rel_objectsdir;
89752a38012Sejakowatz
89852a38012Sejakowatz	# Copy subdir tokens except the first, as that will be "sources", and we
89952a38012Sejakowatz	# do not want to include that :)
90052a38012Sejakowatz	rel_objectsdir = [ FDirName $(SUBDIR_TOKENS[2-]) ] ;
90152a38012Sejakowatz	LOCATE_TARGET = [ FDirName $(OBOS_OBJECT_TARGET) $(rel_objectsdir) ] ;
90252a38012Sejakowatz}
90352a38012Sejakowatz
90452a38012Sejakowatz#-------------------------------------------------------------------------------
90552a38012Sejakowatz# Link rule/action are overwritten as they don't handle linking files who's name
90652a38012Sejakowatz# contain spaces very well. Also adds resources and version to executable.
90752a38012Sejakowatz#-------------------------------------------------------------------------------
90852a38012Sejakowatzrule Link
90952a38012Sejakowatz{
91052a38012Sejakowatz	# Note: RESFILES must be set before invocation.
91152a38012Sejakowatz	MODE on $(<) = $(EXEMODE) ;
91252a38012Sejakowatz	on $(1) XRes $(1) : $(RESFILES) ;
91352a38012Sejakowatz	SetVersion $(1) ;
91452a38012Sejakowatz	Chmod $(<) ;
91552a38012Sejakowatz	SetType $(1) ;
91652a38012Sejakowatz	MimeSet $(1) ;
91752a38012Sejakowatz}
91852a38012Sejakowatz
91952a38012Sejakowatzactions Link bind NEEDLIBS
92052a38012Sejakowatz{
9211eb18edfSIngo Weinhold	$(LINK) $(LINKFLAGS) -o "$(1)" $(UNDEFS) "$(2)" "$(NEEDLIBS)" $(LINKLIBS) ;
92252a38012Sejakowatz}
92352a38012Sejakowatz
92452a38012Sejakowatz# BeOS specific rules
92552a38012Sejakowatz
92652a38012Sejakowatzrule XRes
92752a38012Sejakowatz{
92852a38012Sejakowatz	# XRes <target> : <resource files>
92952a38012Sejakowatz	if $(2)
93052a38012Sejakowatz	{
9319eea4522SIngo Weinhold		Depends $(1) : $(2) ;
93252a38012Sejakowatz		XRes1 $(1) : $(2) ;
93352a38012Sejakowatz	}
93452a38012Sejakowatz}
93552a38012Sejakowatz
93652a38012Sejakowatzrule XRes1 { }
93752a38012Sejakowatz
93852a38012Sejakowatzrule SetVersion
93952a38012Sejakowatz{
94052a38012Sejakowatz	# SetVersion <target>
94152a38012Sejakowatz}
94252a38012Sejakowatz
94352a38012Sejakowatzrule SetType
94452a38012Sejakowatz{
94552a38012Sejakowatz	# SetType <target>
94652a38012Sejakowatz}
94752a38012Sejakowatz
94852a38012Sejakowatzrule MimeSet
94952a38012Sejakowatz{
95052a38012Sejakowatz	# SetType <target>
95152a38012Sejakowatz}
95252a38012Sejakowatz
95352a38012Sejakowatz
95452a38012Sejakowatzif $(OS) = BEOS
95552a38012Sejakowatz{
95652a38012Sejakowatz
95752a38012Sejakowatzactions XRes1
95852a38012Sejakowatz{
9590931b8f9SIngo Weinhold	xres -o "$(1)" "$(2)" ;
96052a38012Sejakowatz}
96152a38012Sejakowatz
96252a38012Sejakowatzactions SetVersion
96352a38012Sejakowatz{
96452a38012Sejakowatz	setversion "$(1)" -system $(OBOS_BUILD_VERSION) -short "$(OBOS_BUILD_DESCRIPTION)" ;
96552a38012Sejakowatz}
96652a38012Sejakowatz
96752a38012Sejakowatzactions SetType
96852a38012Sejakowatz{
96952a38012Sejakowatz	settype -t $(OBOS_TARGET_TYPE) "$(1)" ;
97052a38012Sejakowatz}
97152a38012Sejakowatz
97252a38012Sejakowatzactions MimeSet
97352a38012Sejakowatz{
97452a38012Sejakowatz	mimeset -f "$(1)" ;
97552a38012Sejakowatz}
97652a38012Sejakowatz
97752a38012Sejakowatz}	# if BEOS
97852a38012Sejakowatz
97952a38012Sejakowatz
98052a38012Sejakowatzrule assemble
98152a38012Sejakowatz{
98294782cf7SIngo Weinhold	Depends $(<) : $(>) ;
98394782cf7SIngo Weinhold	ASFLAGS on $(<) += $(ASFLAGS) $(SUBDIRASFLAGS) ;
98494782cf7SIngo Weinhold	ASHDRS on $(<) = [ FIncludes $(SEARCH_SOURCE) $(SUBDIRHDRS) $(HDRS) ] ;
98552a38012Sejakowatz}
98652a38012Sejakowatz
98752a38012Sejakowatzactions assemble
98852a38012Sejakowatz{
98994782cf7SIngo Weinhold	$(CC) -c "$(2)" -O2 $(ASFLAGS) $(KERNEL_CCFLAGS) $(ASHDRS) -o "$(1)" ;
99052a38012Sejakowatz}
99152a38012Sejakowatz
9920931b8f9SIngo Weinhold# Overridden to allow spaces in file names.
9930931b8f9SIngo Weinholdactions Chmod1
9940931b8f9SIngo Weinhold{
9950931b8f9SIngo Weinhold	$(CHMOD) "$(MODE)" "$(1)"
9960931b8f9SIngo Weinhold}
9970931b8f9SIngo Weinhold
9986991af8cSIngo Weinhold# Overridden to allow spaces in file names.
9996991af8cSIngo Weinholdactions piecemeal together existing Clean
10006991af8cSIngo Weinhold{
10016991af8cSIngo Weinhold	$(RM) "$(>)"
10026991af8cSIngo Weinhold}
10036991af8cSIngo Weinhold
100408125d07SIngo Weinholdrule ObjectReference
100508125d07SIngo Weinhold{
100608125d07SIngo Weinhold	# ObjectReference <reference object> : <source object>
100708125d07SIngo Weinhold	# Makes <reference object> refer to the same file as <source object>.
100808125d07SIngo Weinhold	# The filenames must of course be identical.
100908125d07SIngo Weinhold	# <source object> must have already been LOCATEd.
101008125d07SIngo Weinhold
101108125d07SIngo Weinhold	local ref = $(1) ;
101208125d07SIngo Weinhold	local source = $(2) ;
101308125d07SIngo Weinhold	if $(ref) != $(source) {
10149eea4522SIngo Weinhold		Depends $(ref) : $(source) ;
101508125d07SIngo Weinhold		on $(ref) LOCATE = [ on $(source) return $(LOCATE) ] ;
101608125d07SIngo Weinhold	}
101708125d07SIngo Weinhold}
101808125d07SIngo Weinhold
101908125d07SIngo Weinholdrule ObjectReferences
102008125d07SIngo Weinhold{
102108125d07SIngo Weinhold	# ObjectReferences <source objects>
102208125d07SIngo Weinhold	# Creates local references to <source objects>, i.e. identifiers with the
102308125d07SIngo Weinhold	# current grist referring to the same files. <source objects> must have
102408125d07SIngo Weinhold	# already been LOCATEd.
102508125d07SIngo Weinhold
102608125d07SIngo Weinhold	local source ;
102708125d07SIngo Weinhold	for source in $(1) {
102808125d07SIngo Weinhold		ObjectReference [ FGristFiles $(source) ] : $(source) ;
102908125d07SIngo Weinhold	}
103008125d07SIngo Weinhold}
103108125d07SIngo Weinhold
10329fc6b2e1SIngo Weinholdrule Filter
10339fc6b2e1SIngo Weinhold{
10349fc6b2e1SIngo Weinhold	# Filter <list> : <excludes> ;
10359fc6b2e1SIngo Weinhold	# Removes all occurrences of <excludes> in <list>.
10369fc6b2e1SIngo Weinhold
10379fc6b2e1SIngo Weinhold	local list = $(1) ;
10389fc6b2e1SIngo Weinhold	local excludes = $(2) ;
10399fc6b2e1SIngo Weinhold	local newList ;
10409fc6b2e1SIngo Weinhold	local item ;
10419fc6b2e1SIngo Weinhold	for item in $(list) {
10429fc6b2e1SIngo Weinhold		local skip ;
10439fc6b2e1SIngo Weinhold		local exclude ;
10449fc6b2e1SIngo Weinhold		for exclude in $(excludes) {
10459fc6b2e1SIngo Weinhold			if $(item) = $(exclude) {
10469fc6b2e1SIngo Weinhold				skip = true ;
10479fc6b2e1SIngo Weinhold			}
10489fc6b2e1SIngo Weinhold		}
10499fc6b2e1SIngo Weinhold		if ! $(skip) {
10509fc6b2e1SIngo Weinhold			newList += item ;
10519fc6b2e1SIngo Weinhold		}
10529fc6b2e1SIngo Weinhold	}
10539fc6b2e1SIngo Weinhold	return $(newList) ;
10549fc6b2e1SIngo Weinhold}
10559fc6b2e1SIngo Weinhold
10560931b8f9SIngo Weinhold
105752a38012Sejakowatz## Kernel stuff!
105852a38012Sejakowatz
105952a38012Sejakowatzrule SetupKernel
106052a38012Sejakowatz{
106152a38012Sejakowatz	# Usage SetupKernel <sources_or_objects> : <extra_cc_flags>;
106252a38012Sejakowatz
106352a38012Sejakowatz	local _objs = $(1:S=$(SUFOBJ)) ;
106452a38012Sejakowatz
106513be4911SDavid Reid	UsePublicHeaders kernel support drivers ;
1066c633961aSIngo Weinhold	UsePublicHeaders [ FDirName os kernel ] ;
106752a38012Sejakowatz	UsePrivateHeaders kernel ;
10688059752eSDavid Reid	UsePosixHeaders ;
106952a38012Sejakowatz	UseArchHeaders $(OBOS_ARCH) ;
107052a38012Sejakowatz
107152a38012Sejakowatz	SetupObjectsDir ;
107252a38012Sejakowatz
107352a38012Sejakowatz	CCFLAGS on $(_objs) = $(KERNEL_CCFLAGS) $(2) ;
107452a38012Sejakowatz	C++FLAGS on $(_objs) = $(KERNEL_CCFLAGS) $(2) ;
107552a38012Sejakowatz}
107652a38012Sejakowatz
107752a38012Sejakowatzrule KernelObjects
107852a38012Sejakowatz{
107952a38012Sejakowatz	SetupKernel $(1) : $(2) ;
108052a38012Sejakowatz
108152a38012Sejakowatz	Objects $(1) ;
108252a38012Sejakowatz}
108352a38012Sejakowatz
108452a38012Sejakowatzrule KernelLd
108552a38012Sejakowatz{
108652a38012Sejakowatz	# KernelLd <name> : <objs> : <linkerscript> : <args> : <gcc_off> ;
108752a38012Sejakowatz
108852a38012Sejakowatz	SetupKernel $(2) ;
108952a38012Sejakowatz	LINK on $(1) = ld ;
109052a38012Sejakowatz
109152a38012Sejakowatz	LINKFLAGS on $(1) = $(4) ;
109252a38012Sejakowatz	if $(3) { LINKFLAGS on $(1) += --script=$(3) ; }
109352a38012Sejakowatz
109452a38012Sejakowatz	# Remove any preset LINKLIBS
109552a38012Sejakowatz	LINKLIBS on $(1) =  ;
109652a38012Sejakowatz
109752a38012Sejakowatz	# Show that we depend on the libraries we need
10989eea4522SIngo Weinhold	LocalClean clean : $(1) ;
10999eea4522SIngo Weinhold	LocalDepends all : $(1) ;
110052a38012Sejakowatz	Depends $(1) : $(2) ;
110152a38012Sejakowatz
110252a38012Sejakowatz	if $(6) {
110352a38012Sejakowatz		for i in $(6) {
11042a83bfb4SIngo Weinhold			KernelConfigSection $(i) : elf32 : $(1) ;
110552a38012Sejakowatz		}
110652a38012Sejakowatz	}
110752a38012Sejakowatz
110852a38012Sejakowatz	MakeLocate $(1) : $(LOCATE_TARGET) ;
110952a38012Sejakowatz
111052a38012Sejakowatz	# Add libgcc.a - NB this should be detected not hard coded!
111152a38012Sejakowatz	if ! $(5) {
11121eb18edfSIngo Weinhold		LINKLIBS on $(1) += -L $(GCC_PATH) -lgcc ;
111352a38012Sejakowatz	}
111452a38012Sejakowatz}
111552a38012Sejakowatz
111652a38012Sejakowatzactions KernelLd
111752a38012Sejakowatz{
11181eb18edfSIngo Weinhold	$(LINK) $(LINKFLAGS) -o "$(1)" "$(2)" $(LINKLIBS) ;
111952a38012Sejakowatz}
112052a38012Sejakowatz
112152a38012Sejakowatzrule KernelStaticLibrary
112252a38012Sejakowatz{
112352a38012Sejakowatz	# Usage KernelStaticLibrary <name> : <sources> : <extra cc flags>  ;
112452a38012Sejakowatz	# This is designed to take a set of sources and libraries and create
112552a38012Sejakowatz	# a file called lib<name>.a
112652a38012Sejakowatz
112752a38012Sejakowatz	SetupKernel $(2) : $(3) ;
112852a38012Sejakowatz
112952a38012Sejakowatz	MakeLocateObjects $(2) ;
113052a38012Sejakowatz	Library $(1) : $(2) ;
113152a38012Sejakowatz}
113252a38012Sejakowatz
113352a38012Sejakowatzrule KernelStaticLibraryObjects
113452a38012Sejakowatz{
113552a38012Sejakowatz	# Usage KernelStaticLibrary <name> : <sources> ;
113652a38012Sejakowatz	# This is designed to take a set of sources and libraries and create
113752a38012Sejakowatz	# a file called <name>
113852a38012Sejakowatz
113952a38012Sejakowatz	SetupKernel $(2) ;
114052a38012Sejakowatz
114152a38012Sejakowatz	# Show that we depend on the libraries we need
11429eea4522SIngo Weinhold	LocalClean clean : $(1) ;
11439eea4522SIngo Weinhold	LocalDepends all : $(1) ;
114452a38012Sejakowatz	Depends $(1) : $(2) ;
114552a38012Sejakowatz
114652a38012Sejakowatz	MakeLocate $(1) : $(LOCATE_TARGET) ;
114752a38012Sejakowatz}
114852a38012Sejakowatz
114952a38012Sejakowatzactions KernelStaticLibraryObjects
115052a38012Sejakowatz{
11510931b8f9SIngo Weinhold	ar -r "$(1)" "$(2)" ;
115252a38012Sejakowatz}
115352a38012Sejakowatz
115452a38012Sejakowatzrule SystemMain
115552a38012Sejakowatz{
11560c0b2cd0SIngo Weinhold	# Usage SystemMain <target> : <sources> ;
115752a38012Sejakowatz	SetupObjectsDir ;
115852a38012Sejakowatz
11590c0b2cd0SIngo Weinhold	LINKLIBS on $(1) = ;
116052a38012Sejakowatz
116152a38012Sejakowatz	Main $(1) : $(2) ;
116252a38012Sejakowatz}
116352a38012Sejakowatz
116452a38012Sejakowatzrule KernelConfigSection
116552a38012Sejakowatz{
116652a38012Sejakowatz	# KernelConfigSection <section> : <type> : <file>  ;
11672a83bfb4SIngo Weinhold
11682a83bfb4SIngo Weinhold	SECTION_NAMES on $(OBOS_KERNEL_CONFIG) += $(1) ;
11692a83bfb4SIngo Weinhold	SECTION_TYPES on $(OBOS_KERNEL_CONFIG) += $(2) ;
11702a83bfb4SIngo Weinhold	SECTION_FILES on $(OBOS_KERNEL_CONFIG) += $(3) ;
11712a83bfb4SIngo Weinhold
11722a83bfb4SIngo Weinhold	Depends $(OBOS_KERNEL_CONFIG) : $(3) ;
117352a38012Sejakowatz}
117452a38012Sejakowatz
117552a38012Sejakowatzrule WriteKernelConfig
117652a38012Sejakowatz{
117752a38012Sejakowatz	# usage: WriteKernelConfig <target> ;
117852a38012Sejakowatz
11799eea4522SIngo Weinhold	LocalDepends files : $(1) ;
118052a38012Sejakowatz
11812a83bfb4SIngo Weinhold	MakeLocate $(1) : $(OBOS_OBJECT_TARGET) ;
118252a38012Sejakowatz
11839eea4522SIngo Weinhold	LocalClean clean : $(1) ;
118452a38012Sejakowatz}
118552a38012Sejakowatz
11862a83bfb4SIngo Weinholdactions WriteKernelConfig bind SECTION_FILES
118752a38012Sejakowatz{
11880931b8f9SIngo Weinhold	target="$(1)"
11890931b8f9SIngo Weinhold	echo "# OpenBeOS Kernel Config File" > "$target"
11900931b8f9SIngo Weinhold	echo "# Automatically generated - do not edit!" >> "$target"
11912a83bfb4SIngo Weinhold	count=0
11922a83bfb4SIngo Weinhold	for section in "$(SECTION_NAMES)" ; do
11932a83bfb4SIngo Weinhold		count=`expr $count + 1`
11942a83bfb4SIngo Weinhold		eval section$count="$section"
11952a83bfb4SIngo Weinhold	done
11962a83bfb4SIngo Weinhold	i=1
11972a83bfb4SIngo Weinhold	for type in "$(SECTION_TYPES)" ; do
11982a83bfb4SIngo Weinhold		eval type$i="$type"
11992a83bfb4SIngo Weinhold		i=`expr $i + 1`
12002a83bfb4SIngo Weinhold	done
12012a83bfb4SIngo Weinhold	i=1
12022a83bfb4SIngo Weinhold	for file in "$(SECTION_FILES)" ; do
12032a83bfb4SIngo Weinhold		eval file$i="$file"
12042a83bfb4SIngo Weinhold		i=`expr $i + 1`
12052a83bfb4SIngo Weinhold	done
12062a83bfb4SIngo Weinhold	for i in `seq $count` ; do
12072a83bfb4SIngo Weinhold		eval section="\$section$i"
12082a83bfb4SIngo Weinhold		eval type="\$type$i"
12092a83bfb4SIngo Weinhold		eval file="\$file$i"
12100931b8f9SIngo Weinhold		echo "" >> "$target"
12112a83bfb4SIngo Weinhold		echo "["$section"]" >> "$target"
12122a83bfb4SIngo Weinhold		echo "type="$type >> "$target"
12130931b8f9SIngo Weinhold		case "$file" in
121452a38012Sejakowatz			/*) ;;
12150931b8f9SIngo Weinhold			*) file=`pwd`/"$file";;
121652a38012Sejakowatz		esac
12172a83bfb4SIngo Weinhold		echo "file="$file >> "$target"
121852a38012Sejakowatz	done
121952a38012Sejakowatz}
122052a38012Sejakowatz
122152a38012Sejakowatzrule BuildKernel
122252a38012Sejakowatz{
122352a38012Sejakowatz	# Usage BuildKernel <target> : <config_file> ;
12240c0b2cd0SIngo Weinhold	local kernel = $(1) ;
12250c0b2cd0SIngo Weinhold	local configFile = $(2) ;
12260c0b2cd0SIngo Weinhold	local bootmaker = bootmaker ;
122752a38012Sejakowatz
12289eea4522SIngo Weinhold	LocalDepends all : $(kernel) ;
12290c0b2cd0SIngo Weinhold	Depends $(kernel) : $(configFile) $(bootmaker) ;
12309eea4522SIngo Weinhold	LocalClean clean : $(kernel) ;
12310c0b2cd0SIngo Weinhold	MakeLocate $(kernel) : $(LOCATE_TARGET) ;
123252a38012Sejakowatz
12330c0b2cd0SIngo Weinhold	BOOT_MAKER on $(kernel) = $(bootmaker) ;
123452a38012Sejakowatz}
123552a38012Sejakowatz
12360c0b2cd0SIngo Weinholdactions BuildKernel bind BOOT_MAKER
123752a38012Sejakowatz{
12380c0b2cd0SIngo Weinhold	"$(BOOT_MAKER)" --strip-debug --strip-binary strip "$(2)" -o "$(1)" ;
123952a38012Sejakowatz	echo ""
124052a38012Sejakowatz	echo "Kernel linked!"
124152a38012Sejakowatz	echo ""
124252a38012Sejakowatz}
124352a38012Sejakowatz
124452a38012Sejakowatzrule KernelFloppyImage
124552a38012Sejakowatz{
124652a38012Sejakowatz	# Usage KernelFloppyImage <target> : <kernel> : <bootblock> ;
12470c0b2cd0SIngo Weinhold	local floppy = $(1) ;
12480c0b2cd0SIngo Weinhold	local kernel = $(2) ;
12490c0b2cd0SIngo Weinhold	local bootblock = $(3) ;
12500c0b2cd0SIngo Weinhold	local makeflop = makeflop ;
125152a38012Sejakowatz
12529eea4522SIngo Weinhold	LocalDepends all : $(floppy) ;
12530c0b2cd0SIngo Weinhold	Depends $(floppy) : $(kernel) $(bootblock) $(makeflop) ;
12549eea4522SIngo Weinhold	LocalClean clean : $(floppy) ;
12550c0b2cd0SIngo Weinhold	MakeLocate $(floppy) : $(OBOS_OBJECT_TARGET) ;
125652a38012Sejakowatz
12570c0b2cd0SIngo Weinhold	BOOT_BLOCK on $(floppy) = $(bootblock) ;
12580c0b2cd0SIngo Weinhold	MAKE_FLOP on $(floppy) = $(makeflop) ;
125952a38012Sejakowatz}
126052a38012Sejakowatz
126152a38012Sejakowatz# This may be a bit verbose, but I think it's useful to show what's
126252a38012Sejakowatz# going on, at least in this early stage of development.
12630c0b2cd0SIngo Weinholdactions KernelFloppyImage bind BOOT_BLOCK bind MAKE_FLOP
126452a38012Sejakowatz{
12657378dd7fSAxel Dörfler	"$(MAKE_FLOP)" "-p $(shell expr 18 \* 2 \* 512)" "$(BOOT_BLOCK)" "$(2)" "$(1)" ;
12660c0b2cd0SIngo Weinhold
126752a38012Sejakowatz	echo ""
126852a38012Sejakowatz	echo "*************************************************"
126952a38012Sejakowatz	echo "*         Kernel build completed!               *"
127052a38012Sejakowatz	echo "*    Boot image for a 1.44M floppy created      *"
127152a38012Sejakowatz	echo "*************************************************"
127252a38012Sejakowatz	echo ""
12730c0b2cd0SIngo Weinhold	echo "Floppy image is $(1)"
127452a38012Sejakowatz	echo "The following command will write it to a floppy on BeOS"
12750c0b2cd0SIngo Weinhold	echo "  dd if=$(1) of=/dev/disk/floppy/raw bs=18k"
12760c0b2cd0SIngo Weinhold	echo "Alternatively you can run"
12770c0b2cd0SIngo Weinhold	echo "  ./configure --floppy /dev/disk/floppy/raw"
12780c0b2cd0SIngo Weinhold	echo "once and build + write the image subsequently via"
12790c0b2cd0SIngo Weinhold	echo "  jam installfloppy"
128052a38012Sejakowatz	echo ""
128152a38012Sejakowatz}
128252a38012Sejakowatz
12830c0b2cd0SIngo Weinholdrule InstallFloppy
12840c0b2cd0SIngo Weinhold{
12850c0b2cd0SIngo Weinhold	# InstallFloppy <target> : <floppy>
12860c0b2cd0SIngo Weinhold	# "dd"s <floppy> to $(FLOPPY_PATH).
12870c0b2cd0SIngo Weinhold
12880c0b2cd0SIngo Weinhold	local target = $(1) ;
12890c0b2cd0SIngo Weinhold	local floppy = $(2) ;
12900c0b2cd0SIngo Weinhold
12910c0b2cd0SIngo Weinhold	NotFile $(target) ;
12920c0b2cd0SIngo Weinhold	Always $(target) ;
12930c0b2cd0SIngo Weinhold	Depends $(target) : $(floppy) ;
12940c0b2cd0SIngo Weinhold}
12950c0b2cd0SIngo Weinhold
12960c0b2cd0SIngo Weinholdactions InstallFloppy
12970c0b2cd0SIngo Weinhold{
12980c0b2cd0SIngo Weinhold	if [ -z $(FLOPPY_PATH) ] ; then
12990c0b2cd0SIngo Weinhold		echo "Can't install floppy: FLOPPY_PATH not set."
13000c0b2cd0SIngo Weinhold		echo "run: ./configure --floppy <floppy path>"
13010c0b2cd0SIngo Weinhold		echo
13020c0b2cd0SIngo Weinhold		exit 0
13030c0b2cd0SIngo Weinhold	fi
13040c0b2cd0SIngo Weinhold	dd if=$(2) of=$(FLOPPY_PATH) bs=18k
13050c0b2cd0SIngo Weinhold}
130652a38012Sejakowatz
1307