xref: /haiku/Jamrules (revision 21df5945019b886117bc16ba81333e25e78cdd2a)
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) " ;
92405439beSbeveloperKERNEL_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{
564*21df5945SIngo Weinhold	# MakeLocateObjects <sources_or_objects> ;
56552a38012Sejakowatz
566*21df5945SIngo Weinhold	local _objs = [ FGristFiles $(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
590*21df5945SIngo Weinholdrule SharedLibraryFromObjects
59152a38012Sejakowatz{
592*21df5945SIngo Weinhold	# SharedLibraryFromObjects <name> : <objects> ;
59352a38012Sejakowatz	local _lib = lib$(1).so ;
594*21df5945SIngo Weinhold	MainFromObjects $(_lib) : $(2) ;
59552a38012Sejakowatz	MakeLocate $(_lib) : $(OBOS_SHLIB_DIR) ;
5969eea4522SIngo Weinhold	LINKFLAGS on $(_lib) = [ on $(_lib) return $(LINKFLAGS) ]
5979eea4522SIngo Weinhold						   -nostart -Xlinker -soname=\"$(_lib)\" ;
59852a38012Sejakowatz}
59952a38012Sejakowatz
600*21df5945SIngo Weinholdrule SharedLibrary
601*21df5945SIngo Weinhold{
602*21df5945SIngo Weinhold	# SharedLibrary <name> : <sources> ;
603*21df5945SIngo Weinhold#	SetupIncludes ;
604*21df5945SIngo Weinhold	SetupObjectsDir ;
605*21df5945SIngo Weinhold	MakeLocateObjects $(2) ;
606*21df5945SIngo Weinhold	Objects $(2) ;
607*21df5945SIngo Weinhold	SharedLibraryFromObjects $(1) : $(2:S=$(SUFOBJ)) ;
608*21df5945SIngo Weinhold}
609*21df5945SIngo Weinhold
61052a38012Sejakowatzrule LinkSharedOSLibs
61152a38012Sejakowatz{
61252a38012Sejakowatz	# LinkSharedOSLibs <name> : <libs> ;
61352a38012Sejakowatz	# Valid elements for <libs> are e.g. "be" or "libopenbeos.so" or
6144236d490SIngo Weinhold	# "/boot/.../libfoo.so". If the basename starts with "lib" or the thingy
6154236d490SIngo Weinhold	# has a dirname or grist, it is added to the NEEDLIBS variable (i.e. the
6164236d490SIngo Weinhold	# file will be bound!), otherwise it is prefixed "-l" and added to
6174236d490SIngo Weinhold	# LINKLIBS.
61852a38012Sejakowatz
61952a38012Sejakowatz	for i in $(>)
62052a38012Sejakowatz	{
6214236d490SIngo Weinhold		local isfile = ;
6224236d490SIngo Weinhold		if $(i:D) || $(i:G) {
6234236d490SIngo Weinhold			isfile = true ;
6244236d490SIngo Weinhold		} else {
62552a38012Sejakowatz			switch $(i:B)
62652a38012Sejakowatz			{
6274236d490SIngo Weinhold				case lib*	: isfile = true ;
6284236d490SIngo Weinhold				case *		: isfile = ;
6294236d490SIngo Weinhold			}
6304236d490SIngo Weinhold		}
6314236d490SIngo Weinhold		if $(isfile) {
6329eea4522SIngo Weinhold			NEEDLIBS on $(1) = [ on $(1) return $(NEEDLIBS) ] $(i) ;
6339eea4522SIngo Weinhold			Depends $(1) : $(i) ;
6344236d490SIngo Weinhold		} else {
6359eea4522SIngo Weinhold			LINKLIBS on $(1) = [ on $(1) return $(LINKLIBS) ] -l$(i) ;
63652a38012Sejakowatz		}
63752a38012Sejakowatz	}
63852a38012Sejakowatz}
63952a38012Sejakowatz
64052a38012Sejakowatzrule LinkStaticOSLibs
64152a38012Sejakowatz{
64252a38012Sejakowatz	# LinkStaticOSLibs <name> : <libs> ;
64352a38012Sejakowatz
64452a38012Sejakowatz	for i in $(>)
64552a38012Sejakowatz	{
64652a38012Sejakowatz		LINKLIBS on $(<) = $(LINKLIBS) -l $(i) ;
64752a38012Sejakowatz	}
64852a38012Sejakowatz}
64952a38012Sejakowatz
65052a38012Sejakowatzrule AddResources
65152a38012Sejakowatz{
65252a38012Sejakowatz	# AddResources <name> : <resourcefiles> ;
65352a38012Sejakowatz
6549fc6b2e1SIngo Weinhold	SEARCH on $(2) += $(SEARCH_SOURCE) ;
65578599cf0SIngo Weinhold	RESFILES on $(1) += $(2) ;
65652a38012Sejakowatz}
65752a38012Sejakowatz
6587d7f280eSIngo Weinholdrule PublicHeaders
65952a38012Sejakowatz{
6607d7f280eSIngo Weinhold	# PublicHeaders <group list>
66152a38012Sejakowatz	#
6627d7f280eSIngo Weinhold	# Returns the directory names for the public header dirs identified by
6637d7f280eSIngo Weinhold	# <group list>.
66452a38012Sejakowatz
66552a38012Sejakowatz	local list = $(1) ;
666b005dbe3SAxel Dörfler	local dirs = [ FDirName $(OBOS_TOP) headers os ] ;
667b005dbe3SAxel Dörfler
66852a38012Sejakowatz	for i in $(list) {
6697d7f280eSIngo Weinhold		dirs += [ FDirName $(OBOS_TOP) headers os $(i) ] ;
6707d7f280eSIngo Weinhold	}
6717d7f280eSIngo Weinhold	return $(dirs) ;
67252a38012Sejakowatz}
67352a38012Sejakowatz
6747d7f280eSIngo Weinholdrule PrivateHeaders
6757d7f280eSIngo Weinhold{
6767d7f280eSIngo Weinhold	# PrivateHeaders <group list>
6777d7f280eSIngo Weinhold	#
6787d7f280eSIngo Weinhold	# Returns the directory names for the private header dirs identified by
6797d7f280eSIngo Weinhold	# <group list>.
6807d7f280eSIngo Weinhold
6817d7f280eSIngo Weinhold	local list = $(1) ;
6827d7f280eSIngo Weinhold	local dirs ;
6837d7f280eSIngo Weinhold	for i in $(list) {
6847d7f280eSIngo Weinhold		dirs += [ FDirName $(OBOS_TOP) headers private $(i) ] ;
6857d7f280eSIngo Weinhold	}
6867d7f280eSIngo Weinhold	return $(dirs) ;
6877d7f280eSIngo Weinhold}
6887d7f280eSIngo Weinhold
6897d7f280eSIngo Weinholdrule ArchHeaders
6907d7f280eSIngo Weinhold{
6917d7f280eSIngo Weinhold	# usage: ArchHeaders <arch> ;
6927d7f280eSIngo Weinhold	#
6937d7f280eSIngo Weinhold	# <arch> specifies the architecture (e.g. x86).
6947d7f280eSIngo Weinhold
6957d7f280eSIngo Weinhold	return [ FDirName $(OBOS_TOP) headers private kernel arch $(1) ] ;
6967d7f280eSIngo Weinhold}
6977d7f280eSIngo Weinhold
6987d7f280eSIngo Weinholdrule UsePublicHeaders
6997d7f280eSIngo Weinhold{
7007d7f280eSIngo Weinhold	# UsePublicHeaders <group list> ;
7017d7f280eSIngo Weinhold	#
7027d7f280eSIngo Weinhold	# Adds the public C header dirs given by <group list> to the header search
7037d7f280eSIngo Weinhold	# dirs of the subdirectory.
7047d7f280eSIngo Weinhold	# NOTE: This rule must be invoked *before* the rule that builds the objects.
7057d7f280eSIngo Weinhold
7067d7f280eSIngo Weinhold	UseHeaders [ PublicHeaders $(1) ] ;
7077d7f280eSIngo Weinhold}
7087d7f280eSIngo Weinhold
7097d7f280eSIngo Weinholdrule UsePublicObjectHeaders
7107d7f280eSIngo Weinhold{
7117d7f280eSIngo Weinhold	# UsePublicObjectHeaders <sources_or_objects> : <group list> ;
7127d7f280eSIngo Weinhold	#
7137d7f280eSIngo Weinhold	# Adds the public C header dirs given by <group list> to the header search
7147d7f280eSIngo Weinhold	# dirs of <sources_or_objects>.
7157d7f280eSIngo Weinhold	# NOTE: This rule must be invoked *after* the rule that builds the objects.
7167d7f280eSIngo Weinhold
7177d7f280eSIngo Weinhold	ObjectHdrs $(1) : [ PublicHeaders $(2) ] ;
71852a38012Sejakowatz}
71952a38012Sejakowatz
72052a38012Sejakowatzrule UsePrivateHeaders
72152a38012Sejakowatz{
7227d7f280eSIngo Weinhold	# UsePrivateHeaders <group list> ;
72352a38012Sejakowatz	#
72452a38012Sejakowatz	# Adds the private C header dirs given by <group list> to the header search
7257d7f280eSIngo Weinhold	# dirs of the subdirectory.
7267d7f280eSIngo Weinhold	# NOTE: This rule must be invoked *before* the rule that builds the objects.
72752a38012Sejakowatz
7287d7f280eSIngo Weinhold	UseHeaders [ PrivateHeaders $(1) ] ;
72952a38012Sejakowatz}
73052a38012Sejakowatz
7317d7f280eSIngo Weinholdrule UsePrivateObjectHeaders
7327d7f280eSIngo Weinhold{
7337d7f280eSIngo Weinhold	# UsePrivateObjectHeaders <sources_or_objects> : <group list> ;
7347d7f280eSIngo Weinhold	#
7357d7f280eSIngo Weinhold	# Adds the private C header dirs given by <group list> to the header search
7367d7f280eSIngo Weinhold	# dirs of <sources_or_objects>.
7377d7f280eSIngo Weinhold	# NOTE: This rule must be invoked *after* the rule that builds the objects.
7387d7f280eSIngo Weinhold
7397d7f280eSIngo Weinhold	ObjectHdrs $(1) : [ PrivateHeaders $(2) ] ;
74052a38012Sejakowatz}
74152a38012Sejakowatz
74252a38012Sejakowatzrule UseHeaders
74352a38012Sejakowatz{
7447d7f280eSIngo Weinhold	# UseHeaders <headers> ;
74552a38012Sejakowatz	#
74652a38012Sejakowatz	# Adds the C header dirs <headers> to the header search
7477d7f280eSIngo Weinhold	# dirs of the subdirectory.
7487d7f280eSIngo Weinhold	# NOTE: This rule must be invoked *before* the rule that builds the objects.
74952a38012Sejakowatz
7507d7f280eSIngo Weinhold	local header ;
7517d7f280eSIngo Weinhold	for header in $(1) {
75252a38012Sejakowatz		SubDirHdrs $(header) ;
75352a38012Sejakowatz	}
75452a38012Sejakowatz}
75552a38012Sejakowatz
75652a38012Sejakowatzrule UseCppUnitHeaders
75752a38012Sejakowatz{
7587d7f280eSIngo Weinhold	SubDirHdrs [ FDirName $(OBOS_TOP) headers tools cppunit ] ;
75952a38012Sejakowatz}
76052a38012Sejakowatz
761be5af1baSIngo Weinholdrule UseCppUnitObjectHeaders
762be5af1baSIngo Weinhold{
763be5af1baSIngo Weinhold	ObjectHdrs $(1) : [ FDirName $(OBOS_TOP) headers tools cppunit ] ;
764be5af1baSIngo Weinhold}
765be5af1baSIngo Weinhold
76652a38012Sejakowatzrule UseArchHeaders
76752a38012Sejakowatz{
7687d7f280eSIngo Weinhold	# usage: UseArchHeaders <arch> ;
7697d7f280eSIngo Weinhold	#
77052a38012Sejakowatz	# <arch> specifies the architecture (e.g. x86).
7717d7f280eSIngo Weinhold	# NOTE: This rule must be invoked *before* the rule that builds the objects.
7727d7f280eSIngo Weinhold
7737d7f280eSIngo Weinhold	local headers = [ ArchHeaders $(1) ] ;
77452a38012Sejakowatz	local opt = -D$(OBOS_TARGET_DEFINE) ;
775c633961aSIngo Weinhold
77652a38012Sejakowatz	SubDirCcFlags $(opt)  ;
77752a38012Sejakowatz	SubDirC++Flags $(opt)  ;
778c633961aSIngo Weinhold	SubDirHdrs $(headers) ;
779c633961aSIngo Weinhold}
780c633961aSIngo Weinhold
7817d7f280eSIngo Weinholdrule UseArchObjectHeaders
7827d7f280eSIngo Weinhold{
7837d7f280eSIngo Weinhold	# usage: UseArchObjectHeaders <sources_or_objects> : <arch> ;
7847d7f280eSIngo Weinhold	#
7857d7f280eSIngo Weinhold	# <arch> specifies the architecture (e.g. x86).
7867d7f280eSIngo Weinhold	# <sources_or_objects> Source or object files.
7877d7f280eSIngo Weinhold	# NOTE: This rule must be invoked *after* the rule that builds the objects.
7887d7f280eSIngo Weinhold
7897d7f280eSIngo Weinhold	local targets = $(1) ;
7907d7f280eSIngo Weinhold	local headers = [ ArchHeaders $(2) ] ;
7917d7f280eSIngo Weinhold	local opt = -D$(OBOS_TARGET_DEFINE) ;
7927d7f280eSIngo Weinhold
7937d7f280eSIngo Weinhold	ObjectCcFlags $(targets) : $(opt)  ;
7947d7f280eSIngo Weinhold	ObjectC++Flags $(targets) : $(opt)  ;
7957d7f280eSIngo Weinhold	ObjectHdrs $(targets) : $(headers) ;
79652a38012Sejakowatz}
79752a38012Sejakowatz
798d25a77b4SIngo Weinholdrule UsePosixHeaders
799d25a77b4SIngo Weinhold{
800d25a77b4SIngo Weinhold	# UsePrivateHeaders <group list> ;
801d25a77b4SIngo Weinhold	#
802d25a77b4SIngo Weinhold	# Adds the POSIX header dir to the header search
803d25a77b4SIngo Weinhold	# dirs of the subdirectory.
804d25a77b4SIngo Weinhold	# NOTE: This rule must be invoked *before* the rule that builds the objects.
805d25a77b4SIngo Weinhold
806d25a77b4SIngo Weinhold	SubDirHdrs [ FDirName $(OBOS_TOP) headers posix ] ;
807d25a77b4SIngo Weinhold}
808d25a77b4SIngo Weinhold
809d25a77b4SIngo Weinholdrule UsePosixObjectHeaders
810d25a77b4SIngo Weinhold{
811d25a77b4SIngo Weinhold	# UsePosixObjectHeaders <sources_or_objects> ;
812d25a77b4SIngo Weinhold	#
813d25a77b4SIngo Weinhold	# Adds the POSIX header dir to the header search
814d25a77b4SIngo Weinhold	# dirs of <sources_or_objects>.
815d25a77b4SIngo Weinhold	# NOTE: This rule must be invoked *after* the rule that builds the objects.
816d25a77b4SIngo Weinhold
817d25a77b4SIngo Weinhold	ObjectHdrs $(1) : [ FDirName $(OBOS_TOP) headers posix ] ;
818d25a77b4SIngo Weinhold}
819d25a77b4SIngo Weinhold
8203b9eae39SIngo Weinholdrule SplitPath
8213b9eae39SIngo Weinhold{
8223b9eae39SIngo Weinhold	# SplitPath <path> ;
8233b9eae39SIngo Weinhold	# Decomposes a path into its components.
8243b9eae39SIngo Weinhold	local path = $(1:G=) ;
8253b9eae39SIngo Weinhold	local components ;
8268c27f58dSIngo Weinhold	# $(path:D) for "/" is "/". Therefore the second condition.
8278c27f58dSIngo Weinhold	while $(path:D) && $(path:D) != $(path)
8283b9eae39SIngo Weinhold	{
8293b9eae39SIngo Weinhold		# Note: $(path:B) returns "." for "..", but $(path:D=) is fine.
8303b9eae39SIngo Weinhold		components = $(path:D=) $(components) ;
8313b9eae39SIngo Weinhold		path = $(path:D) ;
8323b9eae39SIngo Weinhold	}
8333b9eae39SIngo Weinhold	components = $(path) $(components) ;
8343b9eae39SIngo Weinhold	return $(components) ;
8353b9eae39SIngo Weinhold}
8363b9eae39SIngo Weinhold
8379fc6b2e1SIngo Weinholdrule PrependObjectHdrs
8389fc6b2e1SIngo Weinhold{
8399fc6b2e1SIngo Weinhold	# PrependObjectHdrs <objects_or_sources> : <dirs> ;
8409fc6b2e1SIngo Weinhold	# Prepends <dirs> to the list of header search dirs of the objects
8419fc6b2e1SIngo Weinhold	# specified by <objects_or_sources>. The HDRS variable will not be
8429fc6b2e1SIngo Weinhold	# changed, only CCHDRS.
8439fc6b2e1SIngo Weinhold	# Note: A subsequent ObjectHdrs invocation will therefore undo the
8449fc6b2e1SIngo Weinhold	# effect of this rule.
8459fc6b2e1SIngo Weinhold	# NOTE: This is a hack.
8469fc6b2e1SIngo Weinhold
8479fc6b2e1SIngo Weinhold	local objects = [ FGristFiles $(1:S=$(SUFOBJ)) ] ;
8489fc6b2e1SIngo Weinhold	local dirs = $(2) ;
8499fc6b2e1SIngo Weinhold	for object in $(objects) {
8509fc6b2e1SIngo Weinhold		# Don't change HDRS to avoid screwing up the header scanning.
8519fc6b2e1SIngo Weinhold		PREPENDED_HDRS on $(object)
8529fc6b2e1SIngo Weinhold			= $(dirs) [ on $(object) return $(PREPENDED_HDRS) ] ;
8539fc6b2e1SIngo Weinhold		CCHDRS on $(object)
8549fc6b2e1SIngo Weinhold			= [ FIncludes [ on $(object) return $(PREPENDED_HDRS) $(HDRS) ] ] ;
8559fc6b2e1SIngo Weinhold	}
8569fc6b2e1SIngo Weinhold}
8579fc6b2e1SIngo Weinhold
8583b9eae39SIngo Weinholdrule SymLink
8593b9eae39SIngo Weinhold{
8603b9eae39SIngo Weinhold	# SymLink <target> : <source> ;
8613b9eae39SIngo Weinhold	# Links <target> to <source>.
8623b9eae39SIngo Weinhold	# <source> is the exact link contents. No binding is done.
8633b9eae39SIngo Weinhold	LINKCONTENTS on $(1) = $(2) ;
8643b9eae39SIngo Weinhold	SymLink1 $(1) ;
8659eea4522SIngo Weinhold	LocalDepends all : $(target) ;
8663b9eae39SIngo Weinhold}
8673b9eae39SIngo Weinhold
8683b9eae39SIngo Weinholdactions SymLink1
8693b9eae39SIngo Weinhold{
8700931b8f9SIngo Weinhold	$(RM) "$(1)" && $(LN) -s "$(LINKCONTENTS)" "$(1)"
8710931b8f9SIngo Weinhold}
8720931b8f9SIngo Weinhold
8730931b8f9SIngo Weinholdrule RelSymLink
8740931b8f9SIngo Weinhold{
8750931b8f9SIngo Weinhold	# RelSymLink <link> : <link target>
8760931b8f9SIngo Weinhold	# Creates a relative symbolic link from <link> to <link target>.
8770931b8f9SIngo Weinhold	# <link> and <link target> can be usual targets. They may have a grist
8780931b8f9SIngo Weinhold	# and don't need to have any dirname. Their LOCATE variables are used to
8790931b8f9SIngo Weinhold	# find their locations.
8800931b8f9SIngo Weinhold
8810931b8f9SIngo Weinhold	local target = $(1) ;
8820931b8f9SIngo Weinhold	local source = $(2) ;
8830931b8f9SIngo Weinhold	local targetDir = [ on $(target) FDirName $(LOCATE[1]) $(target:D) ] ;
8840931b8f9SIngo Weinhold	local sourceDir = [ on $(source) FDirName $(LOCATE[1]) $(source:D) ] ;
8850931b8f9SIngo Weinhold	local sourcePath = $(source:G=) ;
8860931b8f9SIngo Weinhold	sourcePath = $(sourcePath:D=$(sourceDir)) ;
8870931b8f9SIngo Weinhold	local targetDirComponents = [ SplitPath $(targetDir) ] ;
8880931b8f9SIngo Weinhold	local sourceComponents = [ SplitPath $(sourcePath) ] ;
8890931b8f9SIngo Weinhold
8900931b8f9SIngo Weinhold	SymLink $(target)
8910931b8f9SIngo Weinhold		: [ FRelPath $(targetDirComponents) : $(sourceComponents) ] ;
8920931b8f9SIngo Weinhold	NOUPDATE $(target);
8939eea4522SIngo Weinhold	Depends $(target) : $(source) ;
8946991af8cSIngo Weinhold	LocalClean clean : $(target) ;
8953b9eae39SIngo Weinhold}
8963b9eae39SIngo Weinhold
89752a38012Sejakowatz#-------------------------------------------------------------------------------
89852a38012Sejakowatz# Low-level OBOS utility rules
89952a38012Sejakowatz#-------------------------------------------------------------------------------
90052a38012Sejakowatzrule SetupObjectsDir
90152a38012Sejakowatz{
90252a38012Sejakowatz	local rel_objectsdir;
90352a38012Sejakowatz
90452a38012Sejakowatz	# Copy subdir tokens except the first, as that will be "sources", and we
90552a38012Sejakowatz	# do not want to include that :)
90652a38012Sejakowatz	rel_objectsdir = [ FDirName $(SUBDIR_TOKENS[2-]) ] ;
90752a38012Sejakowatz	LOCATE_TARGET = [ FDirName $(OBOS_OBJECT_TARGET) $(rel_objectsdir) ] ;
90852a38012Sejakowatz}
90952a38012Sejakowatz
91052a38012Sejakowatz#-------------------------------------------------------------------------------
91152a38012Sejakowatz# Link rule/action are overwritten as they don't handle linking files who's name
91252a38012Sejakowatz# contain spaces very well. Also adds resources and version to executable.
91352a38012Sejakowatz#-------------------------------------------------------------------------------
91452a38012Sejakowatzrule Link
91552a38012Sejakowatz{
91652a38012Sejakowatz	# Note: RESFILES must be set before invocation.
91752a38012Sejakowatz	MODE on $(<) = $(EXEMODE) ;
91852a38012Sejakowatz	on $(1) XRes $(1) : $(RESFILES) ;
91952a38012Sejakowatz	Chmod $(<) ;
92052a38012Sejakowatz	SetType $(1) ;
92152a38012Sejakowatz	MimeSet $(1) ;
9221419ae2bSshatty	SetVersion $(1) ;
92352a38012Sejakowatz}
92452a38012Sejakowatz
92552a38012Sejakowatzactions Link bind NEEDLIBS
92652a38012Sejakowatz{
9271eb18edfSIngo Weinhold	$(LINK) $(LINKFLAGS) -o "$(1)" $(UNDEFS) "$(2)" "$(NEEDLIBS)" $(LINKLIBS) ;
92852a38012Sejakowatz}
92952a38012Sejakowatz
93052a38012Sejakowatz# BeOS specific rules
93152a38012Sejakowatz
93252a38012Sejakowatzrule XRes
93352a38012Sejakowatz{
93452a38012Sejakowatz	# XRes <target> : <resource files>
93552a38012Sejakowatz	if $(2)
93652a38012Sejakowatz	{
9379eea4522SIngo Weinhold		Depends $(1) : $(2) ;
93852a38012Sejakowatz		XRes1 $(1) : $(2) ;
93952a38012Sejakowatz	}
94052a38012Sejakowatz}
94152a38012Sejakowatz
94252a38012Sejakowatzrule XRes1 { }
94352a38012Sejakowatz
94452a38012Sejakowatzrule SetVersion
94552a38012Sejakowatz{
94652a38012Sejakowatz	# SetVersion <target>
94752a38012Sejakowatz}
94852a38012Sejakowatz
94952a38012Sejakowatzrule SetType
95052a38012Sejakowatz{
95152a38012Sejakowatz	# SetType <target>
95252a38012Sejakowatz}
95352a38012Sejakowatz
95452a38012Sejakowatzrule MimeSet
95552a38012Sejakowatz{
95652a38012Sejakowatz	# SetType <target>
95752a38012Sejakowatz}
95852a38012Sejakowatz
95952a38012Sejakowatz
96052a38012Sejakowatzif $(OS) = BEOS
96152a38012Sejakowatz{
96252a38012Sejakowatz
96352a38012Sejakowatzactions XRes1
96452a38012Sejakowatz{
9650931b8f9SIngo Weinhold	xres -o "$(1)" "$(2)" ;
96652a38012Sejakowatz}
96752a38012Sejakowatz
96852a38012Sejakowatzactions SetVersion
96952a38012Sejakowatz{
97052a38012Sejakowatz	setversion "$(1)" -system $(OBOS_BUILD_VERSION) -short "$(OBOS_BUILD_DESCRIPTION)" ;
97152a38012Sejakowatz}
97252a38012Sejakowatz
97352a38012Sejakowatzactions SetType
97452a38012Sejakowatz{
97552a38012Sejakowatz	settype -t $(OBOS_TARGET_TYPE) "$(1)" ;
97652a38012Sejakowatz}
97752a38012Sejakowatz
97852a38012Sejakowatzactions MimeSet
97952a38012Sejakowatz{
98052a38012Sejakowatz	mimeset -f "$(1)" ;
98152a38012Sejakowatz}
98252a38012Sejakowatz
98352a38012Sejakowatz}	# if BEOS
98452a38012Sejakowatz
98552a38012Sejakowatz
98652a38012Sejakowatzrule assemble
98752a38012Sejakowatz{
98894782cf7SIngo Weinhold	Depends $(<) : $(>) ;
98994782cf7SIngo Weinhold	ASFLAGS on $(<) += $(ASFLAGS) $(SUBDIRASFLAGS) ;
99094782cf7SIngo Weinhold	ASHDRS on $(<) = [ FIncludes $(SEARCH_SOURCE) $(SUBDIRHDRS) $(HDRS) ] ;
99152a38012Sejakowatz}
99252a38012Sejakowatz
99352a38012Sejakowatzactions assemble
99452a38012Sejakowatz{
99594782cf7SIngo Weinhold	$(CC) -c "$(2)" -O2 $(ASFLAGS) $(KERNEL_CCFLAGS) $(ASHDRS) -o "$(1)" ;
99652a38012Sejakowatz}
99752a38012Sejakowatz
9980931b8f9SIngo Weinhold# Overridden to allow spaces in file names.
9990931b8f9SIngo Weinholdactions Chmod1
10000931b8f9SIngo Weinhold{
10010931b8f9SIngo Weinhold	$(CHMOD) "$(MODE)" "$(1)"
10020931b8f9SIngo Weinhold}
10030931b8f9SIngo Weinhold
10046991af8cSIngo Weinhold# Overridden to allow spaces in file names.
10056991af8cSIngo Weinholdactions piecemeal together existing Clean
10066991af8cSIngo Weinhold{
10076991af8cSIngo Weinhold	$(RM) "$(>)"
10086991af8cSIngo Weinhold}
10096991af8cSIngo Weinhold
101008125d07SIngo Weinholdrule ObjectReference
101108125d07SIngo Weinhold{
101208125d07SIngo Weinhold	# ObjectReference <reference object> : <source object>
101308125d07SIngo Weinhold	# Makes <reference object> refer to the same file as <source object>.
101408125d07SIngo Weinhold	# The filenames must of course be identical.
101508125d07SIngo Weinhold	# <source object> must have already been LOCATEd.
101608125d07SIngo Weinhold
101708125d07SIngo Weinhold	local ref = $(1) ;
101808125d07SIngo Weinhold	local source = $(2) ;
101908125d07SIngo Weinhold	if $(ref) != $(source) {
10209eea4522SIngo Weinhold		Depends $(ref) : $(source) ;
1021*21df5945SIngo Weinhold		LOCATE on $(ref) = [ on $(source) return $(LOCATE) ] ;
102208125d07SIngo Weinhold	}
102308125d07SIngo Weinhold}
102408125d07SIngo Weinhold
102508125d07SIngo Weinholdrule ObjectReferences
102608125d07SIngo Weinhold{
102708125d07SIngo Weinhold	# ObjectReferences <source objects>
102808125d07SIngo Weinhold	# Creates local references to <source objects>, i.e. identifiers with the
102908125d07SIngo Weinhold	# current grist referring to the same files. <source objects> must have
103008125d07SIngo Weinhold	# already been LOCATEd.
103108125d07SIngo Weinhold
103208125d07SIngo Weinhold	local source ;
103308125d07SIngo Weinhold	for source in $(1) {
103408125d07SIngo Weinhold		ObjectReference [ FGristFiles $(source) ] : $(source) ;
103508125d07SIngo Weinhold	}
103608125d07SIngo Weinhold}
103708125d07SIngo Weinhold
10389fc6b2e1SIngo Weinholdrule Filter
10399fc6b2e1SIngo Weinhold{
10409fc6b2e1SIngo Weinhold	# Filter <list> : <excludes> ;
10419fc6b2e1SIngo Weinhold	# Removes all occurrences of <excludes> in <list>.
10429fc6b2e1SIngo Weinhold
10439fc6b2e1SIngo Weinhold	local list = $(1) ;
10449fc6b2e1SIngo Weinhold	local excludes = $(2) ;
10459fc6b2e1SIngo Weinhold	local newList ;
10469fc6b2e1SIngo Weinhold	local item ;
10479fc6b2e1SIngo Weinhold	for item in $(list) {
10489fc6b2e1SIngo Weinhold		local skip ;
10499fc6b2e1SIngo Weinhold		local exclude ;
10509fc6b2e1SIngo Weinhold		for exclude in $(excludes) {
10519fc6b2e1SIngo Weinhold			if $(item) = $(exclude) {
10529fc6b2e1SIngo Weinhold				skip = true ;
10539fc6b2e1SIngo Weinhold			}
10549fc6b2e1SIngo Weinhold		}
10559fc6b2e1SIngo Weinhold		if ! $(skip) {
10569fc6b2e1SIngo Weinhold			newList += item ;
10579fc6b2e1SIngo Weinhold		}
10589fc6b2e1SIngo Weinhold	}
10599fc6b2e1SIngo Weinhold	return $(newList) ;
10609fc6b2e1SIngo Weinhold}
10619fc6b2e1SIngo Weinhold
10620931b8f9SIngo Weinhold
106352a38012Sejakowatz## Kernel stuff!
106452a38012Sejakowatz
106552a38012Sejakowatzrule SetupKernel
106652a38012Sejakowatz{
106752a38012Sejakowatz	# Usage SetupKernel <sources_or_objects> : <extra_cc_flags>;
106852a38012Sejakowatz
106952a38012Sejakowatz	local _objs = $(1:S=$(SUFOBJ)) ;
107052a38012Sejakowatz
107113be4911SDavid Reid	UsePublicHeaders kernel support drivers ;
1072c633961aSIngo Weinhold	UsePublicHeaders [ FDirName os kernel ] ;
107352a38012Sejakowatz	UsePrivateHeaders kernel ;
10748059752eSDavid Reid	UsePosixHeaders ;
107552a38012Sejakowatz	UseArchHeaders $(OBOS_ARCH) ;
107652a38012Sejakowatz
107752a38012Sejakowatz	SetupObjectsDir ;
107852a38012Sejakowatz
107952a38012Sejakowatz	CCFLAGS on $(_objs) = $(KERNEL_CCFLAGS) $(2) ;
108052a38012Sejakowatz	C++FLAGS on $(_objs) = $(KERNEL_CCFLAGS) $(2) ;
108152a38012Sejakowatz}
108252a38012Sejakowatz
108352a38012Sejakowatzrule KernelObjects
108452a38012Sejakowatz{
108552a38012Sejakowatz	SetupKernel $(1) : $(2) ;
108652a38012Sejakowatz
108752a38012Sejakowatz	Objects $(1) ;
108852a38012Sejakowatz}
108952a38012Sejakowatz
109052a38012Sejakowatzrule KernelLd
109152a38012Sejakowatz{
109252a38012Sejakowatz	# KernelLd <name> : <objs> : <linkerscript> : <args> : <gcc_off> ;
109352a38012Sejakowatz
109452a38012Sejakowatz	SetupKernel $(2) ;
109552a38012Sejakowatz	LINK on $(1) = ld ;
109652a38012Sejakowatz
109752a38012Sejakowatz	LINKFLAGS on $(1) = $(4) ;
109852a38012Sejakowatz	if $(3) { LINKFLAGS on $(1) += --script=$(3) ; }
109952a38012Sejakowatz
110052a38012Sejakowatz	# Remove any preset LINKLIBS
110152a38012Sejakowatz	LINKLIBS on $(1) =  ;
110252a38012Sejakowatz
110352a38012Sejakowatz	# Show that we depend on the libraries we need
11049eea4522SIngo Weinhold	LocalClean clean : $(1) ;
11059eea4522SIngo Weinhold	LocalDepends all : $(1) ;
110652a38012Sejakowatz	Depends $(1) : $(2) ;
110752a38012Sejakowatz
110852a38012Sejakowatz	if $(6) {
110952a38012Sejakowatz		for i in $(6) {
11102a83bfb4SIngo Weinhold			KernelConfigSection $(i) : elf32 : $(1) ;
111152a38012Sejakowatz		}
111252a38012Sejakowatz	}
111352a38012Sejakowatz
111452a38012Sejakowatz	MakeLocate $(1) : $(LOCATE_TARGET) ;
111552a38012Sejakowatz
111652a38012Sejakowatz	# Add libgcc.a - NB this should be detected not hard coded!
111752a38012Sejakowatz	if ! $(5) {
11181eb18edfSIngo Weinhold		LINKLIBS on $(1) += -L $(GCC_PATH) -lgcc ;
111952a38012Sejakowatz	}
112052a38012Sejakowatz}
112152a38012Sejakowatz
112252a38012Sejakowatzactions KernelLd
112352a38012Sejakowatz{
11241eb18edfSIngo Weinhold	$(LINK) $(LINKFLAGS) -o "$(1)" "$(2)" $(LINKLIBS) ;
112552a38012Sejakowatz}
112652a38012Sejakowatz
112752a38012Sejakowatzrule KernelStaticLibrary
112852a38012Sejakowatz{
112952a38012Sejakowatz	# Usage KernelStaticLibrary <name> : <sources> : <extra cc flags>  ;
113052a38012Sejakowatz	# This is designed to take a set of sources and libraries and create
113152a38012Sejakowatz	# a file called lib<name>.a
113252a38012Sejakowatz
113352a38012Sejakowatz	SetupKernel $(2) : $(3) ;
113452a38012Sejakowatz
113552a38012Sejakowatz	MakeLocateObjects $(2) ;
113652a38012Sejakowatz	Library $(1) : $(2) ;
113752a38012Sejakowatz}
113852a38012Sejakowatz
113952a38012Sejakowatzrule KernelStaticLibraryObjects
114052a38012Sejakowatz{
114152a38012Sejakowatz	# Usage KernelStaticLibrary <name> : <sources> ;
114252a38012Sejakowatz	# This is designed to take a set of sources and libraries and create
114352a38012Sejakowatz	# a file called <name>
114452a38012Sejakowatz
114552a38012Sejakowatz	SetupKernel $(2) ;
114652a38012Sejakowatz
114752a38012Sejakowatz	# Show that we depend on the libraries we need
11489eea4522SIngo Weinhold	LocalClean clean : $(1) ;
11499eea4522SIngo Weinhold	LocalDepends all : $(1) ;
115052a38012Sejakowatz	Depends $(1) : $(2) ;
115152a38012Sejakowatz
115252a38012Sejakowatz	MakeLocate $(1) : $(LOCATE_TARGET) ;
115352a38012Sejakowatz}
115452a38012Sejakowatz
115552a38012Sejakowatzactions KernelStaticLibraryObjects
115652a38012Sejakowatz{
11570931b8f9SIngo Weinhold	ar -r "$(1)" "$(2)" ;
115852a38012Sejakowatz}
115952a38012Sejakowatz
116052a38012Sejakowatzrule SystemMain
116152a38012Sejakowatz{
11620c0b2cd0SIngo Weinhold	# Usage SystemMain <target> : <sources> ;
116352a38012Sejakowatz	SetupObjectsDir ;
116452a38012Sejakowatz
11650c0b2cd0SIngo Weinhold	LINKLIBS on $(1) = ;
116652a38012Sejakowatz
116752a38012Sejakowatz	Main $(1) : $(2) ;
116852a38012Sejakowatz}
116952a38012Sejakowatz
117052a38012Sejakowatzrule KernelConfigSection
117152a38012Sejakowatz{
117252a38012Sejakowatz	# KernelConfigSection <section> : <type> : <file>  ;
11732a83bfb4SIngo Weinhold
11742a83bfb4SIngo Weinhold	SECTION_NAMES on $(OBOS_KERNEL_CONFIG) += $(1) ;
11752a83bfb4SIngo Weinhold	SECTION_TYPES on $(OBOS_KERNEL_CONFIG) += $(2) ;
11762a83bfb4SIngo Weinhold	SECTION_FILES on $(OBOS_KERNEL_CONFIG) += $(3) ;
11772a83bfb4SIngo Weinhold
11782a83bfb4SIngo Weinhold	Depends $(OBOS_KERNEL_CONFIG) : $(3) ;
117952a38012Sejakowatz}
118052a38012Sejakowatz
118152a38012Sejakowatzrule WriteKernelConfig
118252a38012Sejakowatz{
118352a38012Sejakowatz	# usage: WriteKernelConfig <target> ;
118452a38012Sejakowatz
11859eea4522SIngo Weinhold	LocalDepends files : $(1) ;
118652a38012Sejakowatz
11872a83bfb4SIngo Weinhold	MakeLocate $(1) : $(OBOS_OBJECT_TARGET) ;
118852a38012Sejakowatz
11899eea4522SIngo Weinhold	LocalClean clean : $(1) ;
119052a38012Sejakowatz}
119152a38012Sejakowatz
11922a83bfb4SIngo Weinholdactions WriteKernelConfig bind SECTION_FILES
119352a38012Sejakowatz{
11940931b8f9SIngo Weinhold	target="$(1)"
11950931b8f9SIngo Weinhold	echo "# OpenBeOS Kernel Config File" > "$target"
11960931b8f9SIngo Weinhold	echo "# Automatically generated - do not edit!" >> "$target"
11972a83bfb4SIngo Weinhold	count=0
11982a83bfb4SIngo Weinhold	for section in "$(SECTION_NAMES)" ; do
11992a83bfb4SIngo Weinhold		count=`expr $count + 1`
12002a83bfb4SIngo Weinhold		eval section$count="$section"
12012a83bfb4SIngo Weinhold	done
12022a83bfb4SIngo Weinhold	i=1
12032a83bfb4SIngo Weinhold	for type in "$(SECTION_TYPES)" ; do
12042a83bfb4SIngo Weinhold		eval type$i="$type"
12052a83bfb4SIngo Weinhold		i=`expr $i + 1`
12062a83bfb4SIngo Weinhold	done
12072a83bfb4SIngo Weinhold	i=1
12082a83bfb4SIngo Weinhold	for file in "$(SECTION_FILES)" ; do
12092a83bfb4SIngo Weinhold		eval file$i="$file"
12102a83bfb4SIngo Weinhold		i=`expr $i + 1`
12112a83bfb4SIngo Weinhold	done
12122a83bfb4SIngo Weinhold	for i in `seq $count` ; do
12132a83bfb4SIngo Weinhold		eval section="\$section$i"
12142a83bfb4SIngo Weinhold		eval type="\$type$i"
12152a83bfb4SIngo Weinhold		eval file="\$file$i"
12160931b8f9SIngo Weinhold		echo "" >> "$target"
12172a83bfb4SIngo Weinhold		echo "["$section"]" >> "$target"
12182a83bfb4SIngo Weinhold		echo "type="$type >> "$target"
12190931b8f9SIngo Weinhold		case "$file" in
122052a38012Sejakowatz			/*) ;;
12210931b8f9SIngo Weinhold			*) file=`pwd`/"$file";;
122252a38012Sejakowatz		esac
12232a83bfb4SIngo Weinhold		echo "file="$file >> "$target"
122452a38012Sejakowatz	done
122552a38012Sejakowatz}
122652a38012Sejakowatz
122752a38012Sejakowatzrule BuildKernel
122852a38012Sejakowatz{
122952a38012Sejakowatz	# Usage BuildKernel <target> : <config_file> ;
12300c0b2cd0SIngo Weinhold	local kernel = $(1) ;
12310c0b2cd0SIngo Weinhold	local configFile = $(2) ;
12320c0b2cd0SIngo Weinhold	local bootmaker = bootmaker ;
123352a38012Sejakowatz
12349eea4522SIngo Weinhold	LocalDepends all : $(kernel) ;
12350c0b2cd0SIngo Weinhold	Depends $(kernel) : $(configFile) $(bootmaker) ;
12369eea4522SIngo Weinhold	LocalClean clean : $(kernel) ;
12370c0b2cd0SIngo Weinhold	MakeLocate $(kernel) : $(LOCATE_TARGET) ;
123852a38012Sejakowatz
12390c0b2cd0SIngo Weinhold	BOOT_MAKER on $(kernel) = $(bootmaker) ;
124052a38012Sejakowatz}
124152a38012Sejakowatz
12420c0b2cd0SIngo Weinholdactions BuildKernel bind BOOT_MAKER
124352a38012Sejakowatz{
12440c0b2cd0SIngo Weinhold	"$(BOOT_MAKER)" --strip-debug --strip-binary strip "$(2)" -o "$(1)" ;
124552a38012Sejakowatz	echo ""
124652a38012Sejakowatz	echo "Kernel linked!"
124752a38012Sejakowatz	echo ""
124852a38012Sejakowatz}
124952a38012Sejakowatz
125052a38012Sejakowatzrule KernelFloppyImage
125152a38012Sejakowatz{
125252a38012Sejakowatz	# Usage KernelFloppyImage <target> : <kernel> : <bootblock> ;
12530c0b2cd0SIngo Weinhold	local floppy = $(1) ;
12540c0b2cd0SIngo Weinhold	local kernel = $(2) ;
12550c0b2cd0SIngo Weinhold	local bootblock = $(3) ;
12560c0b2cd0SIngo Weinhold	local makeflop = makeflop ;
125752a38012Sejakowatz
12589eea4522SIngo Weinhold	LocalDepends all : $(floppy) ;
12590c0b2cd0SIngo Weinhold	Depends $(floppy) : $(kernel) $(bootblock) $(makeflop) ;
12609eea4522SIngo Weinhold	LocalClean clean : $(floppy) ;
12610c0b2cd0SIngo Weinhold	MakeLocate $(floppy) : $(OBOS_OBJECT_TARGET) ;
126252a38012Sejakowatz
12630c0b2cd0SIngo Weinhold	BOOT_BLOCK on $(floppy) = $(bootblock) ;
12640c0b2cd0SIngo Weinhold	MAKE_FLOP on $(floppy) = $(makeflop) ;
126552a38012Sejakowatz}
126652a38012Sejakowatz
126752a38012Sejakowatz# This may be a bit verbose, but I think it's useful to show what's
126852a38012Sejakowatz# going on, at least in this early stage of development.
12690c0b2cd0SIngo Weinholdactions KernelFloppyImage bind BOOT_BLOCK bind MAKE_FLOP
127052a38012Sejakowatz{
12717378dd7fSAxel Dörfler	"$(MAKE_FLOP)" "-p $(shell expr 18 \* 2 \* 512)" "$(BOOT_BLOCK)" "$(2)" "$(1)" ;
12720c0b2cd0SIngo Weinhold
127352a38012Sejakowatz	echo ""
127452a38012Sejakowatz	echo "*************************************************"
127552a38012Sejakowatz	echo "*         Kernel build completed!               *"
127652a38012Sejakowatz	echo "*    Boot image for a 1.44M floppy created      *"
127752a38012Sejakowatz	echo "*************************************************"
127852a38012Sejakowatz	echo ""
12790c0b2cd0SIngo Weinhold	echo "Floppy image is $(1)"
128052a38012Sejakowatz	echo "The following command will write it to a floppy on BeOS"
12810c0b2cd0SIngo Weinhold	echo "  dd if=$(1) of=/dev/disk/floppy/raw bs=18k"
12820c0b2cd0SIngo Weinhold	echo "Alternatively you can run"
12830c0b2cd0SIngo Weinhold	echo "  ./configure --floppy /dev/disk/floppy/raw"
12840c0b2cd0SIngo Weinhold	echo "once and build + write the image subsequently via"
12850c0b2cd0SIngo Weinhold	echo "  jam installfloppy"
128652a38012Sejakowatz	echo ""
128752a38012Sejakowatz}
128852a38012Sejakowatz
12890c0b2cd0SIngo Weinholdrule InstallFloppy
12900c0b2cd0SIngo Weinhold{
12910c0b2cd0SIngo Weinhold	# InstallFloppy <target> : <floppy>
12920c0b2cd0SIngo Weinhold	# "dd"s <floppy> to $(FLOPPY_PATH).
12930c0b2cd0SIngo Weinhold
12940c0b2cd0SIngo Weinhold	local target = $(1) ;
12950c0b2cd0SIngo Weinhold	local floppy = $(2) ;
12960c0b2cd0SIngo Weinhold
12970c0b2cd0SIngo Weinhold	NotFile $(target) ;
12980c0b2cd0SIngo Weinhold	Always $(target) ;
12990c0b2cd0SIngo Weinhold	Depends $(target) : $(floppy) ;
13000c0b2cd0SIngo Weinhold}
13010c0b2cd0SIngo Weinhold
13020c0b2cd0SIngo Weinholdactions InstallFloppy
13030c0b2cd0SIngo Weinhold{
13040c0b2cd0SIngo Weinhold	if [ -z $(FLOPPY_PATH) ] ; then
13050c0b2cd0SIngo Weinhold		echo "Can't install floppy: FLOPPY_PATH not set."
13060c0b2cd0SIngo Weinhold		echo "run: ./configure --floppy <floppy path>"
13070c0b2cd0SIngo Weinhold		echo
13080c0b2cd0SIngo Weinhold		exit 0
13090c0b2cd0SIngo Weinhold	fi
13100c0b2cd0SIngo Weinhold	dd if=$(2) of=$(FLOPPY_PATH) bs=18k
13110c0b2cd0SIngo Weinhold}
131252a38012Sejakowatz
1313*21df5945SIngo Weinhold
1314*21df5945SIngo Weinhold#-------------------------------------------------------------------------------
1315*21df5945SIngo Weinhold# FreeType 2 specific rules and variables
1316*21df5945SIngo Weinhold#-------------------------------------------------------------------------------
1317*21df5945SIngo Weinhold
1318*21df5945SIngo WeinholdFT2_INCLUDE = [ FDirName $(OBOS_TOP) headers libs freetype2 ] ;
1319*21df5945SIngo WeinholdFT2_SRC     = [ FDirName $(OBOS_TOP) src libs freetype2 ] ;
1320*21df5945SIngo Weinhold
1321*21df5945SIngo WeinholdFT2_LIB     = freetype ;
1322*21df5945SIngo Weinhold
1323*21df5945SIngo Weinholdrule UseFreeTypeHeaders
1324*21df5945SIngo Weinhold{
1325*21df5945SIngo Weinhold	SubDirHdrs $(FT2_INCLUDE) ;
1326*21df5945SIngo Weinhold}
1327*21df5945SIngo Weinhold
1328*21df5945SIngo Weinholdrule UseFreeTypeObjectHeaders
1329*21df5945SIngo Weinhold{
1330*21df5945SIngo Weinhold	ObjectHdrs $(1) : $(FT2_INCLUDE) ;
1331*21df5945SIngo Weinhold}
1332*21df5945SIngo Weinhold
1333*21df5945SIngo Weinholdrule FT2_SubDir
1334*21df5945SIngo Weinhold{
1335*21df5945SIngo Weinhold	# FT2_SubDir <dir>
1336*21df5945SIngo Weinhold	# <dir>: Components of a directory in the original hierarchy.
1337*21df5945SIngo Weinhold	local dir = $(1) ;
1338*21df5945SIngo Weinhold	local topDir ;
1339*21df5945SIngo Weinhold	switch $(dir[1])
1340*21df5945SIngo Weinhold	{
1341*21df5945SIngo Weinhold		case "include"	: topDir = $(FT2_INCLUDE) ;
1342*21df5945SIngo Weinhold		case src		: topDir = $(FT2_SRC) ;
1343*21df5945SIngo Weinhold		case *			: ECHO "Unknown FreeType2 directory: " $(dir) ;
1344*21df5945SIngo Weinhold	}
1345*21df5945SIngo Weinhold	return [ FDirName $(topDir) $(dir[2-]) ] ;
1346*21df5945SIngo Weinhold}
1347*21df5945SIngo Weinhold
1348*21df5945SIngo Weinholdrule FT2_Library
1349*21df5945SIngo Weinhold{
1350*21df5945SIngo Weinhold	# FT2_Library <libname> : <sources>
1351*21df5945SIngo Weinhold	# Builds objects from sources and adds the objects to the list of objects
1352*21df5945SIngo Weinhold	# to be linked into the library.
1353*21df5945SIngo Weinhold	# <libname> The name of the library.
1354*21df5945SIngo Weinhold	# <sources> The sources.
1355*21df5945SIngo Weinhold
1356*21df5945SIngo Weinhold	local library = lib$(1).so ;
1357*21df5945SIngo Weinhold	local sources = $(2) ;
1358*21df5945SIngo Weinhold	SetupObjectsDir ;
1359*21df5945SIngo Weinhold	MakeLocateObjects $(sources) ;
1360*21df5945SIngo Weinhold	Objects $(sources) ;
1361*21df5945SIngo Weinhold	LIBRARY_OBJECTS on $(library) += [ FGristFiles $(sources:S=$(SUFOBJ)) ] ;
1362*21df5945SIngo Weinhold}
1363*21df5945SIngo Weinhold
1364*21df5945SIngo Weinholdrule FT2_LinkLibrary
1365*21df5945SIngo Weinhold{
1366*21df5945SIngo Weinhold	# FT2_LinkLibrary <libname>
1367*21df5945SIngo Weinhold	# Links the library from the objects build with FT2_LIBRARY before.
1368*21df5945SIngo Weinhold
1369*21df5945SIngo Weinhold	local library = lib$(1).so ;
1370*21df5945SIngo Weinhold	local objects = [ on $(library) return $(LIBRARY_OBJECTS) ] ;
1371*21df5945SIngo Weinhold	ObjectReferences $(objects) ;
1372*21df5945SIngo Weinhold	objects = [ FGristFiles $(objects) ] ;
1373*21df5945SIngo Weinhold	SharedLibraryFromObjects $(1) : $(objects) ;
1374*21df5945SIngo Weinhold}
1375*21df5945SIngo Weinhold
1376