xref: /haiku/Jamrules (revision 79b498345886b4bb23a4a2af5622d407ae78d999)
1# Vanilla Jam compatibility
2if ! $(INVOCATION_SUBDIR_SET) {
3
4	rule FIsPrefix
5	{
6		# FIsPrefix <a> : <b> ;
7		# Returns true, if list <a> is a prefix (a proper one or equal) of
8		# list <b>, an empty list otherwise.
9		local a = $(1) ;
10		local b = $(2) ;
11		while $(a) && $(a[1]) = $(b[1]) {
12			a = $(a[2-]) ;
13			b = $(b[2-]) ;
14		}
15
16		if $(a) {
17			return ;
18		} else {
19			return true ;
20		}
21	}
22
23	rule LocalClean { Clean $(1) : $(2) ; }
24
25	rule LocalDepends { Depends $(1) : $(2) ; }
26
27} # vanilla Jam compatibility
28
29# The directory for build system specific files
30OBOS_BUILD_DIR = [ FDirName $(OBOS_TOP) build ] ;
31
32# Cache files for header scanning and jamfile caching
33HCACHEFILE = header_cache ;
34JCACHEFILE = jamfile_cache ;
35LOCATE on $(HCACHEFILE) $(JCACHEFILE) = $(OBOS_BUILD_DIR) ;
36
37# Include BuildConfig
38{
39	local buildConfig = [ GLOB $(OBOS_BUILD_DIR) : BuildConfig ] ;
40	if ! $(buildConfig)
41	{
42		ECHO "No BuildConfig found in $(OBOS_BUILD_DIR)!" ;
43		EXIT "Run ./configure in the source tree's root directory first!" ;
44	}
45	LOCATE on BuildConfig = $(OBOS_BUILD_DIR) ;
46	include BuildConfig ;
47}
48
49# analyze GCC version
50if ! $(GCC_RAW_VERSION) {
51	ECHO "Variable GCC_RAW_VERSION not set. Please run ./configure or" ;
52	EXIT "specify it manually." ;
53}
54GCC_VERSION = ;
55{
56	# split the raw version string at `.' and `-' characters
57	local version = $(GCC_RAW_VERSION) ;
58	while $(version) {
59		local split = [ Match "([^.-]*)[.-](.*)" : $(version) ] ;
60		if $(split) {
61			GCC_VERSION += $(split[1]) ;
62			version = $(split[2]) ;
63		} else {
64			GCC_VERSION += $(version) ;
65			version = ;
66		}
67	}
68}
69
70# Save the platform default headers.
71PLATFORM_DEFAULT_HEADERS = $(HDRS) ;
72
73# We do not include any local BeOS system headers by default
74CCFLAGS += -nostdinc ;
75C++FLAGS += -nostdinc ;
76
77# Allow compiling unit tests on Zeta. Instead of fixing the PostMessage()
78# issues, they deprecated that nice function. This will enable it again:
79C++FLAGS += -D_ZETA_USING_DEPRECATED_API_=1 ;
80
81# Determine if we're building on PPC or x86
82# Determine mimetype of executable
83# Cross compiling can come later
84
85TARGET_CPU ?= $(OSPLAT:L) ;
86OBOS_VERSION ?= R1 ;
87
88switch $(TARGET_CPU) {
89	case ppc :
90	{
91		if $(METROWERKS) {
92			# at least parts of OpenBeOS still can be compiled with
93			# the Metrowerks compiler on BeOS/PPC
94			OBOS_TARGET_TYPE ?= "application/x-be-executable" ;
95		} else {
96			OBOS_TARGET_TYPE ?= "application/x-vnd.Be-elfexecutable" ;
97		}
98		DEFINES += __POWERPC__ ;
99		OBOS_BOOT_PLATFORM = openfirmware ;
100	}
101	case x86 :
102	{
103		# nothing special to do here...
104		DEFINES += __INTEL__ ;
105		OBOS_BOOT_PLATFORM = bios_ia32 ;
106	}
107	case * :
108		Exit "Currently unsupported build platform:" $(TARGET_CPU) ;
109}
110
111# set target specific variables
112{
113	#Echo "Building for" $(TARGET_CPU) ;
114
115	OBOS_TARGET ?= $(TARGET_CPU).$(OBOS_VERSION) ;
116	OBOS_TARGET_TYPE ?= "application/x-vnd.Be-elfexecutable" ;
117	OBOS_ARCH ?= $(TARGET_CPU) ;
118	OBOS_TARGET_DEFINE ?= "ARCH_"$(TARGET_CPU) ;
119}
120
121# Disable warnings only if WARNINGS is set to 0
122# Should be enabled by default later
123#
124WARNINGS ?= 1 ;
125if $(WARNINGS) = 1 {
126	# For an explanation of the different warning options, see:
127	# http://gcc.gnu.org/onlinedocs/gcc-2.95.3/gcc_2.html
128	# to get even more warnings, add:
129	# -Wwrite-strings  	(doesn't work well with some Be headers)
130	# -Wundef			(dito)
131	# -Wconversion		(gets you many warnings about implicit conversions)
132	# -W				(gets you even more warnigs)
133	CCFLAGS += -Wall -Wno-multichar -Wmissing-prototypes ;
134	CCFLAGS += -Wpointer-arith -Wcast-align -Wsign-compare ;
135	C++FLAGS += -Wall -Wno-multichar -Wmissing-prototypes -Wno-ctor-dtor-privacy -Woverloaded-virtual ;
136	C++FLAGS += -Wpointer-arith -Wcast-align -Wsign-compare ;
137} else {
138	CCFLAGS += -Wno-multichar ;
139	C++FLAGS += -Wno-multichar ;
140}
141
142# standard kernel C/C++ flags
143KERNEL_CCFLAGS ?= -Wall -Wno-multichar -Wmissing-prototypes -finline -nostdinc ;
144KERNEL_CCFLAGS += -fno-builtin -D$(OBOS_TARGET_DEFINE) ;
145KERNEL_CCFLAGS += -DBOCHS_DEBUG_HACK=$(BOCHS_DEBUG_HACK) -D_KERNEL_MODE ;
146KERNEL_C++FLAGS ?= -Wall -Wno-multichar -Wmissing-prototypes -finline -nostdinc ;
147KERNEL_C++FLAGS += -fno-builtin -fno-exceptions -fno-rtti -D$(OBOS_TARGET_DEFINE) ;
148KERNEL_C++FLAGS += -DBOCHS_DEBUG_HACK=$(BOCHS_DEBUG_HACK) -D_KERNEL_MODE ;
149if $(GCC_VERSION[1]) >= 3 {
150	KERNEL_C++FLAGS += -fno-use-cxa-atexit ;
151}
152
153# We might later want to introduce debug levels or handle the whole issue
154# differently. For now there's only on or off.
155#
156DEBUG ?= 0 ;
157if $(DEBUG) != 0 {
158	OPTIM ?= -O0 ;
159	CCFLAGS += -g [ FDefines DEBUG=$(DEBUG) ] ;
160	C++FLAGS += -g [ FDefines DEBUG=$(DEBUG) ] ;
161	KERNEL_CCFLAGS += -g [ FDefines DEBUG=$(DEBUG) ] ;
162	KERNEL_C++FLAGS += -g [ FDefines DEBUG=$(DEBUG) ] ;
163	LINKFLAGS += -g ;
164} else {
165	OPTIM ?= -O2 ;
166}
167#
168# To disable for the tests OPTIM and DEBUG are overridden, set the environment
169# variable NO_TEST_DEBUG.
170
171# Instructs the Library rule to not make its object files temporary.
172# This is needed as some objects are used in a static library and for an
173# executable.
174KEEPOBJS = true ;
175
176# under BeOS use copyattr instead of cp
177if $(OS) = BEOS
178{
179	CP = copyattr --data ;
180}
181
182# If no OBOS_OBJECT_TARGET is not defined yet, use our default directory and
183# include our "OBOS_TARGET" as subdirectory in there (to prevent different
184# builds mixing objects from different targets).
185if ! $(OBOS_OBJECT_TARGET) {
186	OBOS_OBJECT_TARGET ?= [ FDirName $(OBOS_TOP) objects $(OBOS_TARGET) ] ;
187}
188
189# If no OBOS_DISTRO_TARGET is not defined yet, use our default directory and
190# include our "OBOS_TARGET" as subdirectory in there (to prevent different
191# builds mixing executables from different targets).
192if ! $(OBOS_DISTRO_TARGET) {
193	OBOS_DISTRO_TARGET ?= [ FDirName $(OBOS_TOP) distro $(OBOS_TARGET) ] ;
194}
195
196# Set our version number if not already set and mark it as a developer build
197if ! $(OBOS_BUILD_VERSION) {
198	OBOS_BUILD_VERSION ?= "1 0 0 a 1" ;
199	OBOS_BUILD_DESCRIPTION ?= "Developer Build" ;
200}
201
202# If OBOS_BUILD_VERSION is set, but OBOS_BUILD_DESCRIPTION isn't, mark it as
203# an unknown build.
204if ! $(OBOS_BUILD_DESCRIPTION) {
205	OBOS_BUILD_DESCRIPTION ?= "Unknown Build" ;
206}
207
208# Relative subdirs for distro dir
209OBOS_ADDON_DIR  ?= [ FDirName $(OBOS_DISTRO_TARGET) beos system add-ons ] ;
210OBOS_APPS_DIR   ?= [ FDirName $(OBOS_DISTRO_TARGET) beos apps ] ;
211OBOS_BIN_DIR    ?= [ FDirName $(OBOS_DISTRO_TARGET) beos bin ] ;
212OBOS_ETC_DIR    ?= [ FDirName $(OBOS_DISTRO_TARGET) beos etc ] ;
213OBOS_FONTS_DIR  ?= [ FDirName $(OBOS_ETC_DIR) fonts ] ;
214OBOS_KERNEL_DIR ?= [ FDirName $(OBOS_DISTRO_TARGET) beos system ] ;
215OBOS_PREFS_DIR  ?= [ FDirName $(OBOS_DISTRO_TARGET) beos preferences ] ;
216OBOS_SERVER_DIR ?= [ FDirName $(OBOS_DISTRO_TARGET) beos system servers ] ;
217OBOS_SHLIB_DIR  ?= [ FDirName $(OBOS_DISTRO_TARGET) beos system lib ] ;
218OBOS_STLIB_DIR  ?= [ FDirName $(OBOS_DISTRO_TARGET) develop lib
219							  $(OBOS_ARCH) ] ;
220OBOS_TEST_DIR   ?= [ FDirName $(OBOS_TOP) tests ] ;
221
222OBOS_PACKAGE_DIR ?= [ FDirName $(OBOS_TOP) packages $(OBOS_TARGET) ] ;
223OBOS_PACKAGE_OBJECT_DIR ?= [ FDirName $(OBOS_OBJECT_TARGET) packages ] ;
224
225OBOS_KERNEL_CONFIG = config.$(OBOS_ARCH).ini ;
226OBOS_KERNEL = kernel.$(OBOS_ARCH) ;
227OBOS_FLOPPY = floppy.$(OBOS_ARCH) ;
228
229rule SetupIncludes
230{
231	# XXX add "opengl" later
232	local os_includes = add-ons add-ons/file_system add-ons/graphics add-ons/input_server add-ons/screen_saver add-ons/tracker app device drivers game interface kernel media mail midi midi2 net storage support translation ;
233
234	# Overwrite any exiting content when changing HDRS. This rule may be invoked multiple times.
235
236	# Use headers directory, to allow to do things like include <posix/string.h>
237	HDRS = [ FDirName $(OBOS_TOP) headers ] ;
238
239	# Use posix headers directory
240	HDRS += [ FDirName $(OBOS_TOP) headers posix ] ;
241
242	# Use public OS header directories
243	HDRS += [ PublicHeaders $(os_includes) ] ;
244
245	# Used as a fallback, the R5 header directories (we should remove this as soon as possible)
246	HDRS += /boot/develop/headers/posix /boot/develop/headers/cpp ;
247
248	# The platform dependent headers.
249	HDRS += $(PLATFORM_HEADERS) ;
250}
251
252rule SetupR5Includes
253{
254	# Unsets HDRS, so that the OBOS headers do not `shadow' the system headers.
255	HDRS = ;
256}
257
258rule SetupDefaultIncludes
259{
260	# Resets HDRS to the default headers for the build platform.
261	HDRS = $(PLATFORM_DEFAULT_HEADERS) ;
262}
263
264#-------------------------------------------------------------------------------
265# Things Jam needs in order to work :)
266#-------------------------------------------------------------------------------
267
268# TODO: back-ported from jam 2.5: remove when not longer needed
269rule MakeLocate
270{
271	if $(>)
272	{
273	    LOCATE on $(<) = $(>) ;
274	    Depends $(<) : $(>[1]:G=dir) ;
275	    MkDir $(>[1]:G=dir) ;
276	}
277}
278
279rule Object
280{
281	# This is basically the original Jambase 2.4 Object rule stripped by
282	# comments. Only the final switch statement has been changed to allow
283	# intermediate C++ files for Yacc and Lex.
284
285	LocalClean clean : $(<) ;
286
287	MakeLocate $(<) : $(LOCATE_TARGET) ;
288	SEARCH on $(>) = $(SEARCH_SOURCE) ;
289
290	HDRS on $(<) = $(SEARCH_SOURCE) $(SUBDIRHDRS) $(HDRS) ;
291
292	HDRRULE on $(>) = HdrRule ;
293	HDRSCAN on $(>) = $(HDRPATTERN) ;
294	HDRSEARCH on $(>) =
295		$(SEARCH_SOURCE:E) $(SUBDIRHDRS) $(HDRS) $(STDHDRS) ;
296
297	HDRGRIST on $(>) = $(HDRGRIST) ;
298
299	DEFINES on $(<) += $(DEFINES) ;
300
301	# if source is not .c, generate .c with specific rule
302
303	switch $(>:S)
304	{
305	    case .asm : As $(<) : $(>) ;
306	    case .c :	Cc $(<) : $(>) ;
307	    case .C :	C++ $(<) : $(>) ;
308	    case .cc :	C++ $(<) : $(>) ;
309	    case .cpp : C++ $(<) : $(>) ;
310	    case .f :	Fortran $(<) : $(>) ;
311	    case .l :	if [ on $(2) return $(GENERATE_C++) ] {
312						C++ $(<) : $(<:S=.cpp) ;
313						LexC++ $(<:S=.cpp) : $(>) ;
314					} else {
315						Cc $(<) : $(<:S=.c) ;
316						Lex $(<:S=.c) : $(>) ;
317					}
318	    case .s :	As $(<) : $(>) ;
319	    case .y :	if [ on $(2) return $(GENERATE_C++) ] {
320						C++ $(<) : $(<:S=.cpp) ;
321						Bison $(<:S=.cpp) : $(>) ;
322					} else {
323						Cc $(<) : $(<:S=$(YACCGEN)) ;
324						Yacc $(<:S=$(YACCGEN)) : $(>) ;
325					}
326	    case * :	UserObject $(<) : $(>) ;
327	}
328}
329
330rule UserObject
331{
332	switch $(2)
333	{
334	case *.S    : assemble $(1) : $(2) ;
335	case *.o    : return ;
336	case *      : ECHO "unknown suffix on" $(2) ;
337	}
338}
339
340# Override the default to give "prettier" command lines.
341actions Cc
342{
343	$(CC) -c "$(2)" $(CCFLAGS) $(CCDEFS) $(CCHDRS) -o "$(1)" ;
344}
345
346actions C++
347{
348	$(C++) -c "$(2)" $(C++FLAGS) $(CCDEFS) $(CCHDRS) -o "$(1)" ;
349}
350
351
352#-------------------------------------------------------------------------------
353# General High-level OBOS target rules
354#-------------------------------------------------------------------------------
355
356rule App
357{
358	# App <name> : <sources> : <libraries> ;
359	SetupIncludes ;
360	SetupObjectsDir ;
361	Main $(1) : $(2) ;
362	MakeLocate $(1) : $(OBOS_APPS_DIR) ;
363	LinkSharedOSLibs $(1) : $(3) ;
364	LINKFLAGS on $(1) = [ on $(1) return $(LINKFLAGS) ]
365						-Xlinker -soname=_APP_ ;
366}
367
368rule BinCommand
369{
370	# BinCommand <name> : <sources> : <libraries> : <res> ;
371	SetupIncludes ;
372	SetupObjectsDir ;
373	AddResources $(1) : $(4) ;
374	Main $(1) : $(2) ;
375	MakeLocate $(1) : $(OBOS_BIN_DIR) ;
376	LinkSharedOSLibs $(1) : $(3) ;
377	LINKFLAGS on $(1) = [ on $(1) return $(LINKFLAGS) ]
378						-Xlinker -soname=_APP_ ;
379}
380
381rule StdBinCommands
382{
383	# StdBinCommands <sources> : <libs> : <res> ;
384	SetupIncludes ;
385	SetupObjectsDir ;
386	local libs = $(2) ;
387	local ress = $(3) ;
388	local source ;
389	for source in $(1)
390	{
391		local target = $(source:S=) ;
392		target = [ FGristFiles $(target) ] ;
393
394		BinCommand $(target) : $(source) : $(libs) : $(ress) ;
395	}
396}
397
398rule Preference
399{
400	# Preference <name> : <sources> : <libraries> ;
401	SetupIncludes ;
402	SetupObjectsDir ;
403	Main $(1) : $(2) ;
404	MakeLocate $(1) : $(OBOS_PREFS_DIR) ;
405	LinkSharedOSLibs $(1) : $(3) ;
406	LINKFLAGS on $(1) = [ on $(1) return $(LINKFLAGS) ]
407						-Xlinker -soname=_APP_ ;
408}
409
410rule Server
411{
412	# Server <name> : <sources> : <libraries> ;
413
414	SetupIncludes ;
415	SetupObjectsDir ;
416	Main $(1) : $(2) ;
417	MakeLocate $(1) : $(OBOS_SERVER_DIR) ;
418	LinkSharedOSLibs $(1) : $(3) ;
419	LINKFLAGS on $(1) = [ on $(1) return $(LINKFLAGS) ]
420						-Xlinker -soname=_APP_ ;
421}
422
423# test pseudo targets
424NOTFILE obostests ;
425NOTFILE r5tests ;
426
427rule CommonTestLib
428{
429	# CommonTestLib <target> : <sources> : <obos libraries>
430	#	: <r5 libraries> : <test libraries> : <public headers>;
431	# Builds a unit test for both OBOS and R5 modules.
432	# <target> The name of the target.
433	# <sources> The list of sources.
434	# <obos libraries> A list of link libraries for the OBOS tests (as passed
435	# to LinkSharedOSLibs).
436	# <r5 libraries> A list of link libraries for the R5 tests (as passed
437	# to LinkSharedOSLibs).
438	# <test libraries> A list of link libraries for both OBOS tests and R5 tests
439	# that have a common name (i.e. specify libx.so and the OBOS tests will link
440	# to libx.so and the R5 tests will link to libx_r5.so).
441	# <public headers> A list of public header dirs (as passed to
442	# UsePublicHeaders).
443
444	TestLib $(1) : $(2) : [ FDirName $(OBOS_TEST_DIR) unittester lib ] : $(3) $(5) : $(6) ;
445	R5TestLib $(1) : $(2) : [ FDirName $(OBOS_TEST_DIR) unittester_r5 lib ] : $(4) [ R5SharedLibraryNames $(5) ] ;
446}
447
448rule TestLib
449{
450	# TestLib <target> : <sources> : <dest> : <libraries> : <public headers>
451	# Builds a unit test library for an OBOS module.
452	# <target> The name of the target.
453	# <sources> The list of sources.
454	# <dest> The directory for the target (as passed to FDirName).
455	# <libraries> A list of link libraries (as passed to LinkSharedOSLibs).
456	# <public headers> A list of public header dirs (as passed to
457	# UsePublicHeaders).
458
459	local target = $(1) ;
460	local sources = $(2) ;
461	local dest = $(3) ;
462	local libraries = $(4) ;
463	local headerDirs = $(5) ;
464	local objects = [ FGristFiles $(sources:S=$(SUFOBJ)) ] ;
465
466	# Our Main replacement.
467	MainFromObjects $(target) : $(objects) ;
468	TestObjects $(sources) : $(headerDirs) ;
469
470	MakeLocate $(target) : $(dest) ;
471	Depends $(target) : libcppunit.so ;
472	Depends obostests : $(target) ;
473	LinkSharedOSLibs $(target) : libcppunit.so $(libraries) ;
474	LINKFLAGS on $(target) = $(LINKFLAGS) -nostart -Xlinker -soname=\"$(target)\" ;
475}
476
477rule R5TestLib
478{
479	# R5TestLib <target> : <sources> : <dest> : <libraries>
480	# Builds a unit test for an R5 module. "_r5" is appended to the object
481	# and the target name.
482	# <target> The name of the target.
483	# <sources> The list of sources.
484	# <dest> The directory for the target (as passed to FDirName).
485	# <libraries> A list of link libraries (as passed to LinkSharedOSLibs).
486
487	local target = $(1:B)_r5$(1:S) ;
488	local sources = $(2) ;
489	local dest = $(3) ;
490	local libraries = $(4) ;
491	local objects = [ R5ObjectNames $(sources) ] ;
492
493	# Our Main replacement.
494	MainFromObjects $(target) : $(objects) ;
495	TestObjects $(sources) : : true ;
496
497	MakeLocate $(target) : $(dest) ;
498	Depends $(target) : libcppunit.so ;
499	Depends r5tests : $(target) ;
500	LinkSharedOSLibs $(target) : libcppunit.so $(libraries) ;
501	LINKFLAGS on $(target) = $(LINKFLAGS) -nostart -Xlinker -soname=\"$(target)\" ;
502}
503
504rule CommonUnitTest
505{
506	# CommonUnitTest <target> : <sources> : <dest> : <obos libraries>
507	#	: <r5 libraries> : <public headers>;
508	# Builds a unit test for both OBOS and R5 modules.
509	# <target> The name of the target.
510	# <sources> The list of sources.
511	# <dest> The directory for the target (as passed to FDirName).
512	# <obos libraries> A list of link libraries for the OBOS tests (as passed
513	# to LinkSharedOSLibs).
514	# <r5 libraries> A list of link libraries for the R5 tests (as passed
515	# to LinkSharedOSLibs).
516	# <public headers> A list of public header dirs (as passed to
517	# UsePublicHeaders).
518
519	UnitTest $(1) : $(2) : $(3) : $(4) : $(6) ;
520	R5UnitTest $(1) : $(2) : $(3) : $(5) ;
521}
522
523rule UnitTest
524{
525	# UnitTest <target> : <sources> : <dest> : <libraries> : <public headers>
526	# Builds a unit test for an OBOS module.
527	# <target> The name of the target.
528	# <sources> The list of sources.
529	# <dest> The directory for the target (as passed to FDirName).
530	# <libraries> A list of link libraries (as passed to LinkSharedOSLibs).
531	# <public headers> A list of public header dirs (as passed to
532	# UsePublicHeaders).
533
534	local target = $(1) ;
535	local sources = $(2) ;
536	local dest = $(3) ;
537	local libraries = $(4) ;
538	local headerDirs = $(5) ;
539	local objects = [ FGristFiles $(sources:S=$(SUFOBJ)) ] ;
540
541	# Our Main replacement.
542	MainFromObjects $(target) : $(objects) ;
543	TestObjects $(sources) : $(headerDirs) ;
544
545	MakeLocate $(target) : [ FDirName $(OBOS_TEST_DIR) $(dest) ] ;
546	Depends $(target) : libcppunit.so ;
547	Depends obostests : $(target) ;
548	LinkSharedOSLibs $(target) : libcppunit.so $(libraries) ;
549}
550
551rule R5UnitTest
552{
553	# R5UnitTest <target> : <sources> : <dest> : <libraries>
554	# Builds a unit test for an R5 module. "_r5" is appended to the object
555	# and the target name.
556	# <target> The name of the target.
557	# <sources> The list of sources.
558	# <dest> The directory for the target (as passed to FDirName).
559	# <libraries> A list of link libraries (as passed to LinkSharedOSLibs).
560
561	local target = $(1)_r5 ;
562	local sources = $(2) ;
563	local dest = $(3) ;
564	local libraries = $(4) ;
565	local objects = [ R5ObjectNames $(sources) ] ;
566
567	# Our Main replacement.
568	MainFromObjects $(target) : $(objects) ;
569	TestObjects $(sources) : : true ;
570
571	MakeLocate $(target) : [ FDirName $(OBOS_TEST_DIR) $(dest) ] ;
572	Depends $(target) : libcppunit.so ;
573	Depends r5tests : $(target) ;
574	LinkSharedOSLibs $(target) : libcppunit.so $(libraries) ;
575}
576
577rule R5ObjectNames
578{
579	# R5ObjectNames <sources> ;
580	# Returns a list of gristed object names given a list of source file names.
581	# Moreover each object names gets "_r5" inserted before the object suffix.
582	local objects = $(1:S=)_r5 ;
583	return [ FGristFiles $(objects:S=$(SUFOBJ)) ] ;
584}
585
586rule R5Objects
587{
588	# R5Objects <sources>
589	# Similar to Objects, but appends "_r5" to the object file names and
590	# removes `-nostdinc' from the CC and C++ flags to enable system headers.
591	# <sources> The source files.
592
593	# Remove `-nostdinc' from CCFLAGS and C++FLAGS.
594	local oldCCFLAGS = $(CCFLAGS) ;
595	local oldC++FLAGS = $(C++FLAGS) ;
596	CCFLAGS = [ Filter $(CCFLAGS) : -nostdinc ] ;
597	C++FLAGS = [ Filter $(C++FLAGS) : -nostdinc ] ;
598
599	local sources = $(1) ;
600	local source ;
601	for source in [ FGristFiles $(sources) ]
602	{
603		local object = [ R5ObjectNames $(source) ] ;
604		Object $(object) : $(source) ;
605		LocalDepends obj : $(object) ;
606	}
607
608	# Reset CCFLAGS and C++FLAGS to original values.
609	CCFLAGS = $(oldCCFLAGS) ;
610	C++FLAGS = $(oldC++FLAGS) ;
611}
612
613rule TestObjects
614{
615	# TestLib <sources> : <public headers> : <r5>
616	# Compiles objects for tests.
617	# <sources> The list of sources.
618	# <public headers> A list of public header dirs (as passed to
619	# UsePublicHeaders).
620	# <r5> If set, "_r5" is appended to the object file names and
621	# <public headers> is ignored. Furthermore the pre-processor macro
622	# TEST_R5 is defined, TEST_OBOS otherwise.
623
624	local sources = $(1) ;
625	local headerDirs = $(2) ;
626	local r5 = $(3) ;
627	local objects ;
628
629	# Turn optimization off.
630	if ! $(NO_TEST_DEBUG) {
631		local optim = $(OPTIM) ;
632		OPTIM = ;
633	}
634
635	SetupObjectsDir ;
636
637	# compile
638	if $(r5) {
639		SetupR5Includes ;
640		objects = [ R5ObjectNames $(sources) ] ;
641		R5Objects $(sources) ;
642	} else {
643		SetupIncludes ;
644		objects = [ FGristFiles $(sources:S=$(SUFOBJ)) ] ;
645		Objects $(sources) ;
646	}
647
648	# set headers/defines
649	UseCppUnitObjectHeaders $(sources) : $(objects) ;
650	if $(r5) {
651		ObjectsDefines $(objects) : TEST_R5 ;
652	} else {
653		UsePublicObjectHeaders $(sources) : $(headerDirs) : $(objects) ;
654		ObjectsDefines $(objects) : TEST_OBOS ;
655	}
656
657	if ! $(NO_TEST_DEBUG) {
658		# Turn debugging on. That is usually desired for test code.
659		ObjectCcFlags $(objects) : "-g" ;
660		ObjectC++Flags $(objects) : "-g" ;
661
662		# Turn optimization on again.
663		OPTIM = $(optim) ;
664	}
665}
666
667rule R5SharedLibraryNames
668{
669	# R5SharedLibraryNames <sources> ;
670	# Returns a list of shared library names given a list of file names. NO
671	# GRISTING IS PERFORMED :-) However, each library names gets "_r5" inserted
672	# before the shared lib suffix.
673	return $(1:S=)_r5.so ;
674}
675
676rule SimpleTest
677{
678	# UnitTest <target> : <sources> : <libraries>
679	# Builds a unit test for an OBOS module.
680	# <target> The name of the target.
681	# <sources> The list of sources.
682	# <dest> The directory for the target (as passed to FDirName).
683	# <libraries> A list of link libraries (as passed to LinkSharedOSLibs).
684	# <public headers> A list of public header dirs (as passed to
685	# UsePublicHeaders).
686
687	local target = $(1) ;
688	local sources = $(2) ;
689	local libraries = $(3) ;
690	local relPath = [ FRelPath src tests : $(SUBDIR_TOKENS) ] ;
691
692	# Turn optimization off.
693	if ! $(NO_TEST_DEBUG) {
694		local optim = $(OPTIM) ;
695		OPTIM = ;
696	}
697
698	SetupIncludes ;
699	SetupObjectsDir ;
700	MakeLocateObjects $(sources) ;
701	Main $(target) : $(sources) ;
702	MakeLocate $(target) : [ FDirName $(OBOS_TEST_DIR) $(relPath) ] ;
703	Depends obostests : $(target) ;
704	LinkSharedOSLibs $(target) : $(libraries) ;
705	ObjectsDefines $(sources) : TEST_OBOS ;
706	if ! $(NO_TEST_DEBUG) {
707		# Turn debugging on. That is usually desired for test code.
708		ObjectCcFlags $(sources) : "-g" ;
709		ObjectC++Flags $(sources) : "-g" ;
710
711		# Turn optimization on again.
712		OPTIM = $(optim) ;
713	}
714}
715
716rule Addon
717{
718	# Addon <name> : <relpath> : <sources> : <is executable> : <libraries> ;
719	# <name>: Name of the add-on.
720	# <relpath>: Path where the add-on shall live relative to the add-on dir.
721	# <sources>: Source files.
722	# <is executable>: true, if the target shall be executable as well.
723	# <libraries>: Libraries to be linked against.
724
725	local isExecutable = $(4) ;
726
727	SetupIncludes ;
728	SetupObjectsDir ;
729	Main $(1) : $(3) ;
730
731	# Create output dir path for addon
732	local targetdir;
733	targetdir = [ FDirName $(OBOS_ADDON_DIR) $(2) ] ;
734
735	MakeLocate $(1) : $(targetdir) ;
736
737	local linkFlags = -Xlinker -soname=\"$(1)\" ;
738	if $(isExecutable) != true {
739		linkFlags = -nostart $(linkFlags) ;
740	}
741	LINKFLAGS on $(1) = [ on $(1) return $(LINKFLAGS) ] $(linkFlags) ;
742	LinkSharedOSLibs $(1) : $(5) ;
743}
744
745rule R5KernelAddon
746{
747	# R5KernelAddon <name> : <relpath> : <sources> : <static-libraries> ;
748
749	local sources = $(3) ;
750
751	Addon $(1) : $(2) : $(3) ;
752	ObjectCcFlags $(sources) : -D_KERNEL_MODE=1 -no-fpic ;
753	ObjectC++Flags $(sources) : -D_KERNEL_MODE=1 -no-fpic
754								-fno-exceptions -fno-rtti ;
755	LINKFLAGS on $(1) = [ on $(1) return $(LINKFLAGS) ] -nostdlib ;
756	LinkSharedOSLibs $(1) : $(4) /boot/develop/lib/x86/_KERNEL_ ;
757}
758
759rule Translator
760{
761	# Translator <name> : <sources> : <libraries> ;
762	SetupIncludes ;
763	SetupObjectsDir ;
764	Main $(1) : $(2) ;
765	LinkSharedOSLibs $(1) : $(3) ;
766
767	# Create output dir path for translator
768	local targetdir;
769	targetdir = [ FDirName $(OBOS_ADDON_DIR) Translators ] ;
770	MakeLocate $(1) : $(targetdir) ;
771}
772
773rule MakeLocateObjects
774{
775	# MakeLocateObjects <sources_or_objects> ;
776
777	local _objs = [ FGristFiles $(1:S=$(SUFOBJ)) ] ;
778
779	for o in $(_objs)
780	{
781		local dir = $(o:D) ;
782		if $(dir) {
783			MakeLocate $(o) : [ FDirName $(LOCATE_TARGET) $(dir) ] ;
784		} else {
785			MakeLocate $(o) : $(LOCATE_TARGET) ;
786		}
787	}
788}
789
790rule StaticLibrary
791{
792	# StaticLibrary <name> : <sources> [ : <target dir> ] ;
793	# Creates a static library from sources.
794	# <name>: Basename of the library, without leading "lib" and trailing ".a".
795	#         Grist is allowed -- it will be re-prepended after constructing
796	#         the complete library name.
797	# <source>: List of source files.
798	# <target dir>: Directory into which the library shall be placed. Defaults
799	#               to the objects directory for this subdir. If
800	#               STATIC_LIBRARY_DIR is supplied (the literal string)
801	#               the standard directory for static libs is used, otherwise
802	#               the parameter is interpreted as directory path.
803	#
804	local lib = lib$(1:B)$(SUFLIB) ;
805	lib = $(lib:G=$(1:G)) ;
806	SetupIncludes ;
807	SetupObjectsDir ;
808	MakeLocateObjects $(2) ;
809	Library $(lib) : $(2) ;
810	local targetDir = $(3) ;
811	if $(targetDir) {
812		if $(targetDir) = STATIC_LIBRARY_DIR {
813			targetDir = $(OBOS_STLIB_DIR) ;
814		}
815		MakeLocate $(lib) : $(targetDir) ;
816	} else {
817		# nothing to do, since the Library rule already located the library
818		# in $(LOCATE_TARGET)
819	}
820
821	# If KEEPOBJS is set, Library doesn't make the library depend on
822	# `lib'.
823	if $(KEEPOBJS) {
824		LocalDepends lib : $(lib) ;
825	}
826}
827
828rule R5KernelStaticLibrary
829{
830	# R5KernelStaticLibrary <name> : <sources> ;
831
832	local lib = lib$(1)$(SUFLIB) ;
833	local sources = $(2) ;
834
835	SetupIncludes ;
836	SetupObjectsDir ;
837	MakeLocateObjects $(sources) ;
838	Library $(lib) : $(sources) ;
839	ObjectCcFlags $(sources) : -D_KERNEL_MODE=1 -no-fpic ;
840	ObjectC++Flags $(sources) : -D_KERNEL_MODE=1 -no-fpic
841								-fno-exceptions -fno-rtti ;
842}
843
844rule MergeObjectFromObjects
845{
846	# MergeObjectFromObjects <name> : <objects> : <other objects> ;
847	# Merges object files to an object file.
848	# <name>: Name of the object file to create. No grist will be added.
849	# <objects>: Object files to be merged. Grist will be added.
850	# <other objects>: Object files or static libraries to be merged. No grist
851	#                  will be added.
852	#
853	local objects = [ FGristFiles $(2) ] ;
854	MakeLocate $(1) : $(LOCATE_TARGET) ;
855	Depends $(1) : $(objects) ;
856	Depends $(1) : $(3) ;
857	LINK on $(1) = ld ;
858	MergeObjectFromObjects1 $(1) : $(objects) $(3) ;
859}
860
861actions MergeObjectFromObjects1
862{
863	$(LINK) -r $(2) -o $(1) ;
864}
865
866rule MergeObject
867{
868	# MergeObject <name> : <sources> : <other objects> ;
869	# Compiles source files and merges the object files to an object file.
870	# <name>: Name of the object file to create. No grist will be added.
871	# <sources>: Sources to be compiled. Grist will be added.
872	# <other objects>: Object files or static libraries to be merged. No grist
873	#                  will be added.
874	#
875	SetupIncludes ;
876	SetupObjectsDir ;
877	MakeLocateObjects $(2) ;
878	Objects $(2) ;
879	MergeObjectFromObjects $(1) : $(2:S=$(SUFOBJ)) : $(3) ;
880}
881
882rule SharedLibraryFromObjects
883{
884	# SharedLibraryFromObjects <name> : <objects> : <libraries> ;
885	local _lib = lib$(1:B).so ;
886	_lib = $(_lib:G=$(1:G)) ;
887	MainFromObjects $(_lib) : $(2) ;
888	MakeLocate $(_lib) : $(OBOS_SHLIB_DIR) ;
889	LINKFLAGS on $(_lib) = [ on $(_lib) return $(LINKFLAGS) ]
890						   -nostart -Xlinker -soname=\"$(_lib)\" ;
891	LinkSharedOSLibs $(_lib) : $(3) ;
892}
893
894rule SharedLibrary
895{
896	# SharedLibrary <name> : <sources> : <libraries> ;
897	SetupIncludes ;
898	SetupObjectsDir ;
899	MakeLocateObjects $(2) ;
900	Objects $(2) ;
901	SharedLibraryFromObjects $(1) : $(2:S=$(SUFOBJ)) : $(3) ;
902}
903
904rule LinkSharedOSLibs
905{
906	# LinkSharedOSLibs <name> : <libs> ;
907	# Valid elements for <libs> are e.g. "be" or "libopenbeos.so" or
908	# "/boot/.../libfoo.so". If the basename starts with "lib" or the thingy
909	# has a dirname or grist, it is added to the NEEDLIBS variable (i.e. the
910	# file will be bound!), otherwise it is prefixed "-l" and added to
911	# LINKLIBS. If you want to specify a target that isn't a library and
912	# also has neither grist nor a dirname, you can prepend "<nogrist>" as
913	# grist; it will be stripped by this rule.
914
915	for i in $(>)
916	{
917		local isfile = ;
918		if $(i:D) || $(i:G) {
919			isfile = true ;
920			if $(i:G) = <nogrist> {
921				i = $(i:G=) ;
922			}
923		} else {
924			switch $(i:B)
925			{
926				# XXX: _APP_ and _KERNEL_ should not be needed for ELF.
927				case _APP_ : isfile = true ;
928				case _KERNEL_ : isfile = true ;
929				case lib*	: isfile = true ;
930				case *	: isfile = ;
931			}
932			if ! $(isfile) && ( $(i:S) = .so || $(i:S) = .a ) {
933				isfile = true ;
934			}
935		}
936		if $(isfile) {
937			NEEDLIBS on $(1) = [ on $(1) return $(NEEDLIBS) ] $(i) ;
938			Depends $(1) : $(i) ;
939		} else {
940			LINKLIBS on $(1) = [ on $(1) return $(LINKLIBS) ] -l$(i) ;
941		}
942	}
943}
944
945rule LinkStaticOSLibs
946{
947	# LinkStaticOSLibs <name> : <libs> ;
948
949	for i in $(>)
950	{
951		LINKLIBS on $(<) = $(LINKLIBS) -l $(i) ;
952	}
953}
954
955rule AddResources
956{
957	# AddResources <name> : <resourcefiles> ;
958
959	local resfiles = [ FGristFiles $(2) ] ;
960	SEARCH on $(resfiles) += $(SEARCH_SOURCE) ;
961
962	for file in $(resfiles) {
963		if $(file:S) = .rdef {
964			local rdef = $(file) ;
965			file = $(rdef:S=.rsrc) ;
966			ResComp $(file) : $(rdef) ;
967		}
968		RESFILES on $(1) += $(file) ;
969	}
970}
971
972rule ResComp
973{
974	# ResComp <resource file> : <rdef file> ;
975	#
976	# <resource file> and <rdef file> must be gristed.
977
978	SetupObjectsDir ;
979
980	SEARCH on $(2) += $(SEARCH_SOURCE) ;
981	MakeLocate $(1) : $(LOCATE_TARGET) ;
982	Depends $(1) : $(2) rc ;
983	LocalClean clean : $(1) ;
984	ResComp1 $(1) : rc $(2) ;
985}
986
987actions ResComp1
988{
989	$(2[1]) -o $(1) $(2[2-])
990}
991
992rule ObjectsDefines
993{
994	# Like ObjectDefines, but allows multiple files to be supplied
995	local file ;
996	for file in $(1) {
997		ObjectDefines $(file) : $(2) ;
998	}
999}
1000
1001rule SourceHdrs
1002{
1003	# SourceHdrs <sources> : <headers> [ : <gristed objects> ] ;
1004	#
1005	# Is a wrapper for ObjectHdrs, that passes <sources> and <headers> or,
1006	# if supplied <objects> and <headers>, and also adjusts HDRSEARCH (not
1007	# done by ObjectHdrs).
1008
1009	local sources = [ FGristFiles $(1) ] ;
1010	local headers = $(2) ;
1011	local objects = $(3) ;
1012
1013	local file ;
1014	if $(objects) {
1015		for file in $(objects) {
1016			ObjectHdrs $(file) : $(headers) ;
1017		}
1018	} else {
1019		for file in $(sources) {
1020			ObjectHdrs $(file) : $(headers) ;
1021		}
1022	}
1023
1024	# Also add the header search dirs to HDRSEARCH. Note, that these dirs
1025	# will be listed after the STDHDRS (if any), but that's better than not
1026	# being listed at all.
1027	HDRSEARCH on $(sources) += $(headers) ;
1028}
1029
1030rule PublicHeaders
1031{
1032	# PublicHeaders <group list>
1033	#
1034	# Returns the directory names for the public header dirs identified by
1035	# <group list>.
1036
1037	local list = $(1) ;
1038	local dirs = [ FDirName $(OBOS_TOP) headers os ] ;
1039
1040	for i in $(list) {
1041		dirs += [ FDirName $(OBOS_TOP) headers os $(i) ] ;
1042	}
1043	return $(dirs) ;
1044}
1045
1046rule PrivateHeaders
1047{
1048	# PrivateHeaders <group list>
1049	#
1050	# Returns the directory names for the private header dirs identified by
1051	# <group list>.
1052
1053	local list = $(1) ;
1054	local dirs ;
1055	for i in $(list) {
1056		dirs += [ FDirName $(OBOS_TOP) headers private $(i) ] ;
1057	}
1058	return $(dirs) ;
1059}
1060
1061rule LibraryHeaders
1062{
1063	# LibraryHeaders <group list>
1064	#
1065	# Returns the directory names for the library header dirs identified by
1066	# <group list>.
1067
1068	local list = $(1) ;
1069	local dirs ;
1070	for i in $(list) {
1071		dirs += [ FDirName $(OBOS_TOP) headers libs $(i) ] ;
1072	}
1073	return $(dirs) ;
1074}
1075
1076rule ArchHeaders
1077{
1078	# usage: ArchHeaders <arch> ;
1079	#
1080	# <arch> specifies the architecture (e.g. x86).
1081
1082	return [ FDirName $(OBOS_TOP) headers private kernel arch $(1) ] ;
1083}
1084
1085rule UsePublicHeaders
1086{
1087	# UsePublicHeaders <group list> ;
1088	#
1089	# Adds the public C header dirs given by <group list> to the header search
1090	# dirs of the subdirectory.
1091	# NOTE: This rule must be invoked *before* the rule that builds the
1092	# objects.
1093
1094	UseHeaders [ PublicHeaders $(1) ] ;
1095}
1096
1097rule UsePublicObjectHeaders
1098{
1099	# UsePublicObjectHeaders <sources> : <group list> [ : <objects> ] ;
1100	#
1101	# Adds the public C header dirs given by <group list> to the header search
1102	# dirs of either the object targets of <sources> or if supplied to
1103	# <objects>. Also adjusts HDRSEARCH of <sources>.
1104	# NOTE: This rule must be invoked *after* the rule that builds the objects.
1105
1106	SourceHdrs $(1) : [ PublicHeaders $(2) ] : $(3) ;
1107}
1108
1109rule UsePrivateHeaders
1110{
1111	# UsePrivateHeaders <group list> ;
1112	#
1113	# Adds the private C header dirs given by <group list> to the header search
1114	# dirs of the subdirectory.
1115	# NOTE: This rule must be invoked *before* the rule that builds the objects.
1116
1117	UseHeaders [ PrivateHeaders $(1) ] ;
1118}
1119
1120rule UsePrivateObjectHeaders
1121{
1122	# UsePrivateObjectHeaders <sources> : <group list> [ : <objects> ] ;
1123	#
1124	# Adds the private C header dirs given by <group list> to the header search
1125	# dirs of either the object targets of <sources> or if supplied to
1126	# <objects>. Also adjusts HDRSEARCH of <sources>.
1127	# NOTE: This rule must be invoked *after* the rule that builds the objects.
1128
1129	SourceHdrs $(1) : [ PrivateHeaders $(2) ] : $(3) ;
1130}
1131
1132rule UseHeaders
1133{
1134	# UseHeaders <headers> ;
1135	#
1136	# Adds the C header dirs <headers> to the header search
1137	# dirs of the subdirectory.
1138	# NOTE: This rule must be invoked *before* the rule that builds the objects.
1139
1140	local header ;
1141	for header in $(1) {
1142		SubDirHdrs $(header) ;
1143	}
1144}
1145
1146rule UseCppUnitHeaders
1147{
1148	SubDirHdrs [ FDirName $(OBOS_TOP) headers tools cppunit ] ;
1149}
1150
1151rule UseCppUnitObjectHeaders
1152{
1153	# UseCppUnitObjectHeaders <sources> [ : <objects> ] ;
1154	SourceHdrs $(1) : [ FDirName $(OBOS_TOP) headers tools cppunit ] : $(2) ;
1155}
1156
1157rule UseArchHeaders
1158{
1159	# usage: UseArchHeaders <arch> ;
1160	#
1161	# <arch> specifies the architecture (e.g. x86).
1162	# NOTE: This rule must be invoked *before* the rule that builds the objects.
1163
1164	local headers = [ ArchHeaders $(1) ] ;
1165	local opt = -D$(OBOS_TARGET_DEFINE) ;
1166
1167	SubDirCcFlags $(opt)  ;
1168	SubDirC++Flags $(opt)  ;
1169	HDRS += $(headers) ;
1170}
1171
1172rule UseArchObjectHeaders
1173{
1174	# usage: UseArchObjectHeaders <sources> : <arch> : [ <objects> ] ;
1175	#
1176	# <arch> specifies the architecture (e.g. x86).
1177	# <sources_or_objects> Source or object files.
1178	# NOTE: This rule must be invoked *after* the rule that builds the objects.
1179
1180	local sources = $(1) ;
1181	local headers = [ ArchHeaders $(2) ] ;
1182	local objects = $(3) ;
1183	local targets ;
1184	if $(objects) {
1185		targets = $(objects) ;
1186	} else {
1187		targets = $(sources) ;
1188	}
1189	local opt = -D$(OBOS_TARGET_DEFINE) ;
1190
1191	ObjectCcFlags $(targets) : $(opt)  ;
1192	ObjectC++Flags $(targets) : $(opt)  ;
1193	SourceHdrs $(sources) : $(headers) : $(objects) ;
1194}
1195
1196rule UsePosixHeaders
1197{
1198	# XXX changed to do nothing
1199}
1200
1201rule UsePosixObjectHeaders
1202{
1203	# UsePosixObjectHeaders <sources> [ : <objects> ] ;
1204	#
1205	# Adds the POSIX header dir to the header search
1206	# dirs of either the object targets of <sources> or if supplied to
1207	# <objects>. Also adjusts HDRSEARCH of <sources>.
1208	# NOTE: This rule must be invoked *after* the rule that builds the objects.
1209
1210	SourceHdrs $(1) : [ FDirName $(OBOS_TOP) headers posix ] : $(2) ;
1211}
1212
1213rule UseLibraryHeaders
1214{
1215	# UseLibraryHeaders <group list> ;
1216	#
1217	# Adds the library header dirs given by <group list> to the header search
1218	# dirs of the subdirectory.
1219	# NOTE: This rule must be invoked *before* the rule that builds the objects.
1220
1221	UseHeaders [ LibraryHeaders $(1) ] ;
1222}
1223
1224rule SplitPath
1225{
1226	# SplitPath <path> ;
1227	# Decomposes a path into its components.
1228	local path = $(1:G=) ;
1229	local components ;
1230	# $(path:D) for "/" is "/". Therefore the second condition.
1231	while $(path:D) && $(path:D) != $(path)
1232	{
1233		# Note: $(path:B) returns "." for "..", but $(path:D=) is fine.
1234		components = $(path:D=) $(components) ;
1235		path = $(path:D) ;
1236	}
1237	components = $(path) $(components) ;
1238	return $(components) ;
1239}
1240
1241rule PrependObjectHdrs
1242{
1243	# PrependObjectHdrs <objects_or_sources> : <dirs> ;
1244	# Prepends <dirs> to the list of header search dirs of the objects
1245	# specified by <objects_or_sources>. The HDRS variable will not be
1246	# changed, only CCHDRS.
1247	# Note: A subsequent ObjectHdrs invocation will therefore undo the
1248	# effect of this rule.
1249	# NOTE: This is a hack.
1250
1251	local objects = [ FGristFiles $(1:S=$(SUFOBJ)) ] ;
1252	local dirs = $(2) ;
1253	for object in $(objects) {
1254		# Don't change HDRS to avoid screwing up the header scanning.
1255		PREPENDED_HDRS on $(object)
1256			= $(dirs) [ on $(object) return $(PREPENDED_HDRS) ] ;
1257		CCHDRS on $(object)
1258			= [ FIncludes [ on $(object) return $(PREPENDED_HDRS) $(HDRS) ] ] ;
1259	}
1260}
1261
1262rule SymLink
1263{
1264	# SymLink <target> : <source> : <makeDefaultDependencies> ;
1265	# Links <target> to <source>.
1266	# <source> is the exact link contents. No binding is done.
1267	# <makeDefaultDependencies> If true, <target> will be made a dependency
1268	# of the `all' pseudo target, i.e. it will be made by default, and removed
1269	# on `jam clean'.
1270
1271	local target = $(1) ;
1272	local source = $(2) ;
1273	local makeDefaultDependencies = $(3) ;
1274	if ! $(makeDefaultDependencies) {
1275		makeDefaultDependencies = true ;
1276	}
1277	LINKCONTENTS on $(target) = $(source) ;
1278	SymLink1 $(target) ;
1279	if $(makeDefaultDependencies) = true {
1280		LocalDepends files : $(target) ;
1281		LocalClean clean : $(target) ;
1282	}
1283}
1284
1285actions SymLink1
1286{
1287	$(RM) "$(1)" && $(LN) -s "$(LINKCONTENTS)" "$(1)"
1288}
1289
1290rule RelSymLink
1291{
1292	# RelSymLink <link> : <link target> : <makeDefaultDependencies> ;
1293	# Creates a relative symbolic link from <link> to <link target>.
1294	# <link> and <link target> can be usual targets. They may have a grist
1295	# and don't need to have any dirname. Their LOCATE variables are used to
1296	# find their locations.
1297	# <makeDefaultDependencies> If true (which is the default), <link> will be
1298	# made a dependency of the `files' pseudo target, i.e. it will be made by
1299	# default, and removed on `jam clean'.
1300
1301	local target = $(1) ;
1302	local source = $(2) ;
1303	local makeDefaultDependencies = $(3) ;
1304	local targetDir = [ on $(target) FDirName $(LOCATE[1]) $(target:D) ] ;
1305	local sourceDir = [ on $(source) FDirName $(LOCATE[1]) $(source:D) ] ;
1306	local sourcePath = $(source:G=) ;
1307	sourcePath = $(sourcePath:D=$(sourceDir)) ;
1308	local targetDirComponents = [ SplitPath $(targetDir) ] ;
1309	local sourceComponents = [ SplitPath $(sourcePath) ] ;
1310
1311	SymLink $(target)
1312		: [ FRelPath $(targetDirComponents) : $(sourceComponents) ]
1313		: $(makeDefaultDependencies) ;
1314	NOUPDATE $(target) ;
1315	Depends $(target) : $(source) ;
1316}
1317
1318rule AbsSymLink
1319{
1320	# AbsSymLink <link> : <link target> : <link dir>
1321	#			: <makeDefaultDependencies> ;
1322	# Creates an absolute symbolic link from <link> to <link target>.
1323	# <link> and <link target> must be usual targets. If <link dir> is
1324	# given, then it is set as LOCATE directory on <link>.
1325	# <makeDefaultDependencies> If true (which is the default), <link> will be
1326	# made a dependency of the `files' pseudo target, i.e. it will be made by
1327	# default, and removed on `jam clean'.
1328
1329	local makeDefaultDependencies = $(4) ;
1330	if ! $(makeDefaultDependencies) {
1331		makeDefaultDependencies = true ;
1332	}
1333
1334	Depends $(1) : $(2) ;
1335	if $(3) {
1336		MakeLocate $(1) : $(3) ;
1337	}
1338	SEARCH on $(2) += $(SEARCH_SOURCE) ;
1339	if $(makeDefaultDependencies) = true {
1340		LocalDepends files : $(1) ;
1341		LocalClean clean : $(1) ;
1342	}
1343}
1344
1345actions AbsSymLink
1346{
1347	target="$(2)"
1348	case "$target" in
1349		/*) ;;
1350		*) target=`pwd`/"$target";;
1351	esac
1352	$(RM) "$(1)" && $(LN) -s "$target" "$(1)"
1353}
1354
1355rule OBOSInstall
1356{
1357	# Usage: OBOSInstall <[ install [ and uninstall ] pseudotarget ]>
1358	#					 : <directory> : <sources to install>
1359	#					 : [ <installgrist> ] : [ <install rule> ] ;
1360	local install = $(1[1]) ;
1361	install ?= install ;
1362	local uninstall = $(1[2]) ;
1363	uninstall ?= un$(install) ;
1364	local dir = $(2) ;
1365	local sources = $(3) ;
1366	local installgrist = $(4) ;
1367	installgrist ?= $(INSTALLGRIST) ;
1368	local installRule = $(5) ;
1369	installRule ?= Install ;
1370	local targets = $(sources:G=$(installgrist)) ;
1371
1372	NotFile $(install) ;
1373	NotFile $(uninstall) ;
1374	Depends $(install) : $(targets) ;
1375	Clean $(uninstall) : $(targets) ;
1376
1377	SEARCH on $(sources) += $(SEARCH_SOURCE) ;
1378	MakeLocate $(targets) : $(dir) ;
1379
1380	local source ;
1381	for source in $(sources) {
1382		local target = $(source:G=$(installgrist)) ;
1383
1384		Depends $(target) : $(source) ;
1385		$(installRule) $(target) : $(source) ;
1386
1387		if [ on $(target) return $(MODE) ] {
1388			Chmod $(target) ;
1389		}
1390
1391		if $(OWNER) && $(CHOWN) {
1392			Chown $(target) ;
1393			OWNER on $(target) = $(OWNER) ;
1394		}
1395
1396		if $(GROUP) && $(CHGRP) {
1397			Chgrp $(target) ;
1398			GROUP on $(target) = $(GROUP) ;
1399		}
1400	}
1401}
1402
1403rule InstallAbsSymLinkAdapter
1404{
1405	# InstallAbsSymLinkAdapter <link> : <link target>
1406	if ! [ on $(2) return $(TARGET) ] {
1407		TARGET on $(2) = [ on $(2) return $(SEARCH) ] ;
1408	}
1409	AbsSymLink $(1) : $(2) : : false ;
1410}
1411
1412rule OBOSInstallAbsSymLink
1413{
1414	# Usage: OBOSInstallAbsSymLink <[ install [ and uninstall ] pseudotarget ]>
1415	#							   : <directory> : <sources to install>
1416	#							   : [ <installgrist> ] ;
1417	OBOSInstall $(1) : $(2) : $(3) : $(4) : InstallAbsSymLinkAdapter ;
1418}
1419
1420rule InstallRelSymLinkAdapter
1421{
1422	# InstallRelSymLinkAdapter <link> : <link target>
1423	if ! [ on $(2) return $(TARGET) ] {
1424		TARGET on $(2) = [ on $(2) return $(SEARCH) ] ;
1425	}
1426	RelSymLink $(1) : $(2) : false ;
1427}
1428
1429rule OBOSInstallRelSymLink
1430{
1431	# Usage: OBOSInstallRelSymLink <[ install [ and uninstall ] pseudotarget ]>
1432	#							   : <directory> : <sources to install>
1433	#							   : [ <installgrist> ] ;
1434	OBOSInstall $(1) : $(2) : $(3) : $(4) : InstallRelSymLinkAdapter ;
1435}
1436
1437
1438#-------------------------------------------------------------------------------
1439# Low-level OBOS utility rules
1440#-------------------------------------------------------------------------------
1441rule FObjectsDir
1442{
1443	# FObjectsDir
1444	#
1445	# Returns the output directory for object files for the current
1446	# subdirectory.
1447
1448	return [ FDirName $(OBOS_OBJECT_TARGET) $(SUBDIR_TOKENS[2-]) ] ;
1449}
1450
1451rule SetupObjectsDir
1452{
1453	LOCATE_TARGET = [ FObjectsDir ] ;
1454	LOCATE_SOURCE = $(LOCATE_TARGET) ;
1455	SEARCH_SOURCE = [ Filter $(SEARCH_SOURCE) : $(LOCATE_TARGET) ]
1456					$(LOCATE_TARGET) ;
1457}
1458
1459#-------------------------------------------------------------------------------
1460# Link rule/action are overwritten as they don't handle linking files who's name
1461# contain spaces very well. Also adds resources and version to executable.
1462#-------------------------------------------------------------------------------
1463rule Link
1464{
1465	# Note: RESFILES must be set before invocation.
1466	MODE on $(<) = $(EXEMODE) ;
1467	on $(1) XRes $(1) : $(RESFILES) ;
1468	Chmod $(<) ;
1469	SetType $(1) ;
1470	MimeSet $(1) ;
1471	SetVersion $(1) ;
1472}
1473
1474actions Link bind NEEDLIBS
1475{
1476	$(LINK) $(LINKFLAGS) -o "$(1)" $(UNDEFS) "$(2)" "$(NEEDLIBS)" $(LINKLIBS) ;
1477}
1478
1479rule LexC++
1480{
1481	Depends $(1) : $(2) ;
1482	MakeLocate $(1) : $(LOCATE_SOURCE) ;
1483	LocalClean clean : $(1) ;
1484}
1485
1486actions LexC++
1487{
1488	$(LEX) -o$(1) $(2)
1489}
1490
1491rule Bison
1492{
1493	local _h ;
1494
1495	_h = $(1).h ;
1496
1497	MakeLocate $(<) $(_h) : $(LOCATE_SOURCE) ;
1498
1499    Depends $(<) $(_h) : $(>) ;
1500    Bison1 $(<) $(_h) : $(>) ;
1501    LocalClean clean : $(<) $(_h) ;
1502
1503	# make sure someone includes $(_h) else it will be
1504	# a deadly independent target
1505
1506	Includes $(<) : $(_h) ;
1507}
1508
1509actions Bison1
1510{
1511	bison $(YACCFLAGS) -o $(1[1]) $(2)
1512}
1513
1514# BeOS specific rules
1515
1516rule XRes
1517{
1518	# XRes <target> : <resource files>
1519	if $(2)
1520	{
1521		Depends $(1) : $(2) ;
1522		XRes1 $(1) : $(2) ;
1523	}
1524}
1525
1526rule XRes1 { }
1527
1528rule SetVersion
1529{
1530	# SetVersion <target>
1531}
1532
1533rule SetType
1534{
1535	# SetType <target>
1536}
1537
1538rule MimeSet
1539{
1540	# SetType <target>
1541}
1542
1543
1544if $(OS) = BEOS
1545{
1546
1547actions XRes1
1548{
1549	xres -o "$(1)" "$(2)" ;
1550}
1551
1552actions SetVersion
1553{
1554	setversion "$(1)" -system $(OBOS_BUILD_VERSION) -short "$(OBOS_BUILD_DESCRIPTION)" ;
1555}
1556
1557actions SetType
1558{
1559	settype -t $(OBOS_TARGET_TYPE) "$(1)" ;
1560}
1561
1562actions MimeSet
1563{
1564	mimeset -f "$(1)" ;
1565}
1566
1567}	# if BEOS
1568
1569
1570rule assemble
1571{
1572	Depends $(<) : $(>) ;
1573	ASFLAGS on $(<) += $(ASFLAGS) $(SUBDIRASFLAGS) ;
1574	ASHDRS on $(<) = [ FIncludes $(SEARCH_SOURCE) $(SUBDIRHDRS) $(HDRS) ] ;
1575}
1576
1577actions assemble
1578{
1579	$(CC) -c "$(2)" -O2 $(ASFLAGS) -D_ASSEMBLER $(KERNEL_CCFLAGS) $(ASHDRS) -o "$(1)" ;
1580}
1581
1582# Overridden to allow spaces in file names.
1583actions Chmod1
1584{
1585	$(CHMOD) "$(MODE)" "$(1)"
1586}
1587
1588# Overridden to allow spaces in file names.
1589actions piecemeal together existing Clean
1590{
1591	$(RM) "$(>)"
1592}
1593
1594rule ObjectReference
1595{
1596	# ObjectReference <reference object> : <source object>
1597	# Makes <reference object> refer to the same file as <source object>.
1598	# The filenames must of course be identical.
1599	# <source object> must have already been LOCATEd.
1600
1601	local ref = $(1) ;
1602	local source = $(2) ;
1603	if $(ref) != $(source) {
1604		Depends $(ref) : $(source) ;
1605		LOCATE on $(ref) = [ on $(source) return $(LOCATE) ] ;
1606	}
1607}
1608
1609rule ObjectReferences
1610{
1611	# ObjectReferences <source objects>
1612	# Creates local references to <source objects>, i.e. identifiers with the
1613	# current grist referring to the same files. <source objects> must have
1614	# already been LOCATEd.
1615
1616	local source ;
1617	for source in $(1) {
1618		ObjectReference [ FGristFiles $(source) ] : $(source) ;
1619	}
1620}
1621
1622rule Filter
1623{
1624	# Filter <list> : <excludes> ;
1625	# Removes all occurrences of <excludes> in <list>.
1626
1627	local list = $(1) ;
1628	local excludes = $(2) ;
1629	local newList ;
1630	local item ;
1631	for item in $(list) {
1632		local skip ;
1633		local exclude ;
1634		for exclude in $(excludes) {
1635			if $(item) = $(exclude) {
1636				skip = true ;
1637			}
1638		}
1639		if ! $(skip) {
1640			newList += $(item) ;
1641		}
1642	}
1643	return $(newList) ;
1644}
1645
1646
1647## Kernel stuff!
1648
1649rule SetupKernel
1650{
1651	# Usage SetupKernel <sources_or_objects> : <extra_cc_flags>;
1652
1653	local _objs = [ FGristFiles $(1:S=$(SUFOBJ)) ] ;
1654
1655	#Setup Kernel header directories
1656	local public_kernel_includes = add-ons/file_system add-ons/graphics app device drivers kernel storage support ;
1657	local private_kernel_includes = kernel libroot kernel/boot/platform/$(OBOS_BOOT_PLATFORM) ;
1658	# Use posix headers directory
1659	HDRS = [ FDirName $(OBOS_TOP) headers posix ] ;
1660	# Use public OS header directories
1661	HDRS += [ PublicHeaders $(public_kernel_includes) ] ;
1662	# Use private directories
1663	HDRS += [ PrivateHeaders $(private_kernel_includes) ] ;
1664	# The platform dependent headers.
1665	HDRS += $(PLATFORM_HEADERS) ;
1666
1667	UseArchHeaders $(OBOS_ARCH) ;
1668
1669	SetupObjectsDir ;
1670
1671	CCFLAGS on $(_objs) = $(KERNEL_CCFLAGS) $(2) ;
1672	C++FLAGS on $(_objs) = $(KERNEL_C++FLAGS) $(2) ;
1673}
1674
1675rule KernelObjects
1676{
1677	SetupKernel $(1) : $(2) ;
1678
1679	Objects $(1) ;
1680}
1681
1682rule KernelLd
1683{
1684	# KernelLd <name> : <objs> : <linkerscript> : <args> : <gcc_off> : <config_section> ;
1685
1686	SetupKernel $(2) ;
1687	LINK on $(1) = ld ;
1688
1689	LINKFLAGS on $(1) = $(4) ;
1690	if $(3) { LINKFLAGS on $(1) += --script=$(3) ; }
1691
1692	# Remove any preset LINKLIBS
1693	LINKLIBS on $(1) =  ;
1694
1695	# Show that we depend on the libraries we need
1696	LocalClean clean : $(1) ;
1697	LocalDepends all : $(1) ;
1698	Depends $(1) : $(2) ;
1699
1700	if $(6) {
1701		for i in $(6) {
1702			KernelConfigSection $(i) : elf32 : $(1) ;
1703		}
1704	}
1705
1706	MakeLocate $(1) : $(LOCATE_TARGET) ;
1707
1708	# Add the platform specific static libs (libgcc.a).
1709	if ! $(5) {
1710		LINKLIBS on $(1) += $(PLATFORM_LINKLIBS) ;
1711	}
1712}
1713
1714actions KernelLd
1715{
1716	$(LINK) $(LINKFLAGS) -o "$(1)" "$(2)" $(LINKLIBS) ;
1717}
1718
1719rule KernelAddon
1720{
1721	# KernelAddon <name> : <relpath> : <sources> : <static-libraries> ;
1722
1723	local sources = $(3) ;
1724
1725	SetupKernel $(3) ;
1726	Addon $(1) : $(2) : $(3) ;
1727	ObjectCcFlags $(sources) : -D_KERNEL_MODE=1 -no-fpic ;
1728	ObjectC++Flags $(sources) : -D_KERNEL_MODE=1 -no-fpic
1729								-fno-exceptions -fno-rtti ;
1730	LINKFLAGS on $(1) = [ on $(1) return $(LINKFLAGS) ] -nostdlib ;
1731	LinkSharedOSLibs $(1) : $(4) $(OBOS_TOP)/objects/$(OBOS_ARCH).$(OBOS_VERSION)/kernel/kernel.so ;
1732		# ToDo this has to be changed!
1733}
1734
1735rule KernelMergeObject
1736{
1737	# KernelMergeObject <name> : <sources> : <extra CFLAGS> : <other objects> ;
1738	# Compiles source files and merges the object files to an object file.
1739	# <name>: Name of the object file to create. No grist will be added.
1740	# <sources>: Sources to be compiled. Grist will be added.
1741	# <extra CFLAGS>: Additional flags for compilation.
1742	# <other objects>: Object files or static libraries to be merged. No grist
1743	#                  will be added.
1744	#
1745
1746	SetupKernel $(2) : $(3) ;
1747
1748	MakeLocateObjects $(2) ;
1749	Objects $(2) ;
1750	MergeObjectFromObjects $(1) : $(2:S=$(SUFOBJ)) : $(4) ;
1751}
1752
1753rule KernelStaticLibrary
1754{
1755	# Usage KernelStaticLibrary <name> : <sources> : <extra cc flags>  ;
1756	# This is designed to take a set of sources and libraries and create
1757	# a file called lib<name>.a
1758
1759	SetupKernel $(2) : $(3) ;
1760
1761	MakeLocateObjects $(2) ;
1762	Library $(1) : $(2) ;
1763}
1764
1765rule KernelStaticLibraryObjects
1766{
1767	# Usage KernelStaticLibrary <name> : <sources> ;
1768	# This is designed to take a set of sources and libraries and create
1769	# a file called <name>
1770
1771	SetupKernel $(2) ;
1772
1773	# Show that we depend on the libraries we need
1774	LocalClean clean : $(1) ;
1775	LocalDepends all : $(1) ;
1776	Depends $(1) : $(2) ;
1777
1778	MakeLocate $(1) : $(LOCATE_TARGET) ;
1779}
1780
1781actions KernelStaticLibraryObjects
1782{
1783	ar -r "$(1)" "$(2)" ;
1784}
1785
1786rule BuildPlatformMain
1787{
1788	# Usage BuildPlatformMain <target> : <sources> ;
1789	SetupObjectsDir ;
1790	SetupDefaultIncludes ;
1791
1792	# Remove `-nostdinc' from CCFLAGS and C++FLAGS.
1793	local oldCCFLAGS = $(CCFLAGS) ;
1794	local oldC++FLAGS = $(C++FLAGS) ;
1795	CCFLAGS = [ Filter $(CCFLAGS) : -nostdinc ] ;
1796	C++FLAGS = [ Filter $(C++FLAGS) : -nostdinc ] ;
1797
1798	Main $(1) : $(2) ;
1799
1800	# Reset CCFLAGS and C++FLAGS to original values.
1801	CCFLAGS = $(oldCCFLAGS) ;
1802	C++FLAGS = $(oldC++FLAGS) ;
1803}
1804
1805rule BuildPlatformTest
1806{
1807	# Usage BuildPlatformTest <target> : <sources> ;
1808
1809	local target = $(1) ;
1810	local sources = $(2) ;
1811
1812	BuildPlatformMain $(target) : $(sources) ;
1813	local relPath ;
1814	if [ FIsPrefix src tests : $(SUBDIR_TOKENS) ] {
1815		relPath = $(SUBDIR_TOKENS[3-]) ;
1816	} else {
1817		relPath = $(SUBDIR_TOKENS[2-]) ;
1818	}
1819	MakeLocate $(target) : [ FDirName $(OBOS_TEST_DIR) $(relPath) ] ;
1820}
1821
1822rule KernelConfigSection
1823{
1824	# KernelConfigSection <section> : <type> : <file>  ;
1825
1826	SECTION_NAMES on $(OBOS_KERNEL_CONFIG) += $(1) ;
1827	SECTION_TYPES on $(OBOS_KERNEL_CONFIG) += $(2) ;
1828	SECTION_FILES on $(OBOS_KERNEL_CONFIG) += $(3) ;
1829
1830	Depends $(OBOS_KERNEL_CONFIG) : $(3) ;
1831}
1832
1833rule WriteKernelConfig
1834{
1835	# usage: WriteKernelConfig <target> ;
1836
1837	LocalDepends files : $(1) ;
1838
1839	MakeLocate $(1) : $(OBOS_OBJECT_TARGET) ;
1840
1841	LocalClean clean : $(1) ;
1842}
1843
1844actions WriteKernelConfig bind SECTION_FILES
1845{
1846	target="$(1)"
1847	echo "# OpenBeOS Kernel Config File" > "$target"
1848	echo "# Automatically generated - do not edit!" >> "$target"
1849	count=0
1850	for section in "$(SECTION_NAMES)" ; do
1851		count=`expr $count + 1`
1852		eval section$count="$section"
1853	done
1854	i=1
1855	for type in "$(SECTION_TYPES)" ; do
1856		eval type$i="$type"
1857		i=`expr $i + 1`
1858	done
1859	i=1
1860	for file in "$(SECTION_FILES)" ; do
1861		eval file$i="$file"
1862		i=`expr $i + 1`
1863	done
1864	for i in `seq $count` ; do
1865		eval section="\$section$i"
1866		eval type="\$type$i"
1867		eval file="\$file$i"
1868		echo "" >> "$target"
1869		echo "["$section"]" >> "$target"
1870		echo "type="$type >> "$target"
1871		case "$file" in
1872			/*) ;;
1873			*) file=`pwd`/"$file";;
1874		esac
1875		echo "file="$file >> "$target"
1876	done
1877}
1878
1879rule BuildKernel
1880{
1881	# Usage BuildKernel <target> : <config_file> ;
1882	local kernel = $(1) ;
1883	local configFile = $(2) ;
1884	local bootmaker = bootmaker ;
1885
1886	LocalDepends all : $(kernel) ;
1887	Depends $(kernel) : $(configFile) $(bootmaker) ;
1888	LocalClean clean : $(kernel) ;
1889	MakeLocate $(kernel) : $(LOCATE_TARGET) ;
1890
1891	BOOT_MAKER on $(kernel) = $(bootmaker) ;
1892}
1893
1894actions BuildKernel bind BOOT_MAKER
1895{
1896	"$(BOOT_MAKER)" --strip-debug --strip-binary strip "$(2)" -o "$(1)" ;
1897	echo ""
1898	echo "Kernel linked!"
1899	echo ""
1900}
1901
1902rule KernelFloppyImage
1903{
1904	# Usage KernelFloppyImage <target> : <kernel> : <bootblock> ;
1905	local floppy = $(1) ;
1906	local kernel = $(2) ;
1907	local bootblock = $(3) ;
1908	local makeflop = makeflop ;
1909
1910	LocalDepends all : $(floppy) ;
1911	Depends $(floppy) : $(kernel) $(bootblock) $(makeflop) ;
1912	LocalClean clean : $(floppy) ;
1913	MakeLocate $(floppy) : $(OBOS_OBJECT_TARGET) ;
1914
1915	BOOT_BLOCK on $(floppy) = $(bootblock) ;
1916	MAKE_FLOP on $(floppy) = $(makeflop) ;
1917}
1918
1919# This may be a bit verbose, but I think it's useful to show what's
1920# going on, at least in this early stage of development.
1921actions KernelFloppyImage bind BOOT_BLOCK bind MAKE_FLOP
1922{
1923	"$(MAKE_FLOP)" "-p $(shell expr 18 \* 2 \* 512)" "$(BOOT_BLOCK)" "$(2)" "$(1)" ;
1924
1925	echo ""
1926	echo "*************************************************"
1927	echo "*         Kernel build completed!               *"
1928	echo "*    Boot image for a 1.44M floppy created      *"
1929	echo "*************************************************"
1930	echo ""
1931	echo "Floppy image is $(1)"
1932	echo "The following command will write it to a floppy on BeOS"
1933	echo "  dd if=$(1) of=/dev/disk/floppy/raw bs=18k"
1934	echo "Alternatively you can run"
1935	echo "  ./configure --floppy /dev/disk/floppy/raw"
1936	echo "once and build + write the image subsequently via"
1937	echo "  jam installfloppy"
1938	echo ""
1939}
1940
1941rule InstallFloppy
1942{
1943	# InstallFloppy <target> : <floppy>
1944	# "dd"s <floppy> to $(FLOPPY_PATH).
1945
1946	local target = $(1) ;
1947	local floppy = $(2) ;
1948
1949	NotFile $(target) ;
1950	Always $(target) ;
1951	Depends $(target) : $(floppy) ;
1952}
1953
1954actions InstallFloppy
1955{
1956	if [ -z $(FLOPPY_PATH) ] ; then
1957		echo "Can't install floppy: FLOPPY_PATH not set."
1958		echo "run: ./configure --floppy <floppy path>"
1959		echo
1960		exit 0
1961	fi
1962	dd if=$(2) of=$(FLOPPY_PATH) bs=18k
1963}
1964
1965#-------------------------------------------------------------------------------
1966# FreeType 2 specific rules and variables
1967#-------------------------------------------------------------------------------
1968
1969FT2_INCLUDE = [ FDirName $(OBOS_TOP) headers libs freetype2 ] ;
1970FT2_SRC     = [ FDirName $(OBOS_TOP) src libs freetype2 ] ;
1971
1972FT2_LIB     = freetype ;
1973
1974FT2_COMPONENTS ?= gzip       # support for gzip-compressed files.
1975                  autohint   # auto-hinter
1976                  base       # base component (public APIs)
1977                  bdf        # BDF font driver
1978                  cache      # cache sub-system
1979                  cff        # CFF/CEF font driver
1980                  cid        # Postscript CID-keyed font driver
1981                  pcf        # PCF font driver
1982                  pfr        # PFR/TrueDoc font driver
1983                  psaux      # Common Postscript routines module
1984                  pshinter   # Postscript hinter module
1985                  psnames    # Postscript names handling
1986                  raster     # Monochrome rasterizer
1987                  smooth     # Anti-aliased rasterizer
1988                  sfnt       # SFNT-based format support routines
1989                  truetype   # TrueType font driver
1990                  type1      # Postscript Type 1 font driver
1991                  type42     # Postscript Type 42 (embedded TrueType) driver
1992                  winfonts   # Windows FON/FNT font driver
1993                  ;
1994
1995rule UseFreeTypeHeaders
1996{
1997	SubDirHdrs $(FT2_INCLUDE) ;
1998}
1999
2000rule UseFreeTypeObjectHeaders
2001{
2002	# UseFreeTypeObjectHeaders <sources> [ : <objects> ] ;
2003	SourceHdrs $(1) : $(FT2_INCLUDE) : $(2) ;
2004}
2005
2006rule FT2_SubDir
2007{
2008	# FT2_SubDir <dir>
2009	# <dir>: Components of a directory in the original hierarchy.
2010	local dir = $(1) ;
2011	local topDir ;
2012	switch $(dir[1])
2013	{
2014		case "include"	: topDir = $(FT2_INCLUDE) ;
2015		case src		: topDir = $(FT2_SRC) ;
2016		case *			: ECHO "Unknown FreeType2 directory: " $(dir) ;
2017	}
2018	return [ FDirName $(topDir) $(dir[2-]) ] ;
2019}
2020
2021rule FT2_Library
2022{
2023	# FT2_Library <libname> : <sources>
2024	# Builds objects from sources and adds the objects to the list of objects
2025	# to be linked into the library.
2026	# <libname> The name of the library.
2027	# <sources> The sources.
2028
2029	local library = lib$(1).so ;
2030	local sources = $(2) ;
2031	SetupIncludes ;
2032	SetupObjectsDir ;
2033	MakeLocateObjects $(sources) ;
2034	Objects $(sources) ;
2035	LIBRARY_OBJECTS on $(library) += [ FGristFiles $(sources:S=$(SUFOBJ)) ] ;
2036}
2037
2038rule FT2_LinkLibrary
2039{
2040	# FT2_LinkLibrary <libname>
2041	# Links the library from the objects build with FT2_LIBRARY before.
2042
2043	local library = lib$(1).so ;
2044	local objects = [ on $(library) return $(LIBRARY_OBJECTS) ] ;
2045	ObjectReferences $(objects) ;
2046	objects = [ FGristFiles $(objects) ] ;
2047	SharedLibraryFromObjects $(1) : $(objects) ;
2048}
2049
2050#-------------------------------------------------------------------------------
2051# Packages for OBOS alpha/beta testers
2052#-------------------------------------------------------------------------------
2053
2054rule Copy
2055{
2056	Depends $(<) : $(>) ;
2057	SEARCH on $(>) = $(SEARCH_SOURCE) ;
2058}
2059
2060actions Copy
2061{
2062	cp -dp "$(>)" "$(<)" ;
2063	if [ -f "$(>)" ] ; then copyattr "$(>)" "$(<)" ; fi ;
2064}
2065
2066rule Packages
2067{
2068	local packagenames = $(1) ;
2069	local packagefiles = $(2) ;
2070	local path = $(3) ;
2071	for name in $(packagenames) {
2072		Package $(name) : $(packagefiles) : $(path) ;
2073    }
2074}
2075
2076rule Package
2077{
2078	local packagename = $(1) ;
2079    local packagefiles = $(2) ;
2080	local path = $(3) ;
2081
2082	local packagezip = $(packagename:S=.zip:G=_packages) ;
2083	local packagedir = [ FDirName $(OBOS_PACKAGE_DIR) $(packagename) ] ;
2084
2085    local installscript = install.sh ;
2086	local packageinstallscript = $(installscript:G=_packages!$(packagename)) ;
2087    local installzip = install.zip ;
2088	local packageinstallzip = $(installzip:G=_packages!$(packagename)) ;
2089
2090    local packageobjectdir
2091    	= [ FDirName $(OBOS_PACKAGE_OBJECT_DIR) $(packagename) ] ;
2092	local packagefiledir =  [ FDirName $(packageobjectdir) $(path) ] ;
2093    local packagefileinstallzip
2094    	= $(installzip:G=_package_objects!$(packagename)) ;
2095
2096	# add the files to the install.zip
2097	local packagefilegrist = [ FGrist _package_files $(packagename) $(path) ] ;
2098    for file in $(packagefiles) {
2099		if $(3[0]) = "boot" {
2100			local packagefile = $(file:G=$(packagefilegrist)) ;
2101			MakeLocate $(packagefile) : $(packagefiledir) ;
2102			Copy $(packagefile) : $(file) ;
2103			Clean cleanPackages : $(packagefile) ;
2104			PackageInstallZip $(packagefileinstallzip) : $(packagefile) ;
2105		} else {
2106			local packagefile = $(file:G=_packages!$(packagename)) ;
2107			MakeLocate $(packagefile) : $(packagedir) ;
2108			Copy $(packagefile) : [ FGristFiles $(file) ] ;
2109			Clean cleanPackages : $(packagefile) ;
2110			Depends $(packagezip) : $(packagefile) ;
2111		}
2112	}
2113
2114	# general setup for this packages -- only on first invocation
2115	if ! $(_setup_$(packagename)) {
2116		_setup_$(packagename) = true ;
2117
2118		NotFile $(packagename) ;
2119		Depends packages : $(packagename) ;
2120
2121		MakeLocate $(packagezip) : $(OBOS_PACKAGE_DIR) ;
2122		MakeLocate $(packageinstallscript) : $(packagedir) ;
2123		MakeLocate $(packageinstallzip) : $(packagedir) ;
2124		MakeLocate $(packagefileinstallzip) : $(packageobjectdir) ;
2125
2126		PackageInstallScript $(packageinstallscript) : $(packagedir) ;
2127		LinkInstallZip $(packageinstallzip) : $(packagefileinstallzip) ;
2128		Depends $(packagename) : $(packagezip) ;
2129		PackageZip $(packagezip) : $(packagedir)
2130			: $(packageinstallscript) $(packageinstallzip) ;
2131	}
2132
2133}
2134
2135rule PackageZip
2136{
2137	local dir = $(2:G=dir) ;
2138	Depends $(1) : $(dir) $(3) ;
2139	Clean cleanPackages : $(1) ;
2140	PackageZip1 $(1) : $(dir) ;
2141}
2142
2143actions together PackageZip1 {
2144	cd "$(OBOS_PACKAGE_DIR)" ;
2145	zip -rq "$(1:BS)" "$(2:BS)" ;
2146}
2147
2148rule PackageInstallScript
2149{
2150	MakeLocate $(1) : $(2) ;
2151	Clean cleanPackages : $(1) ;
2152	PackageInstallScript1 $(1) : $(2:G=dir) ;
2153}
2154
2155actions together PackageInstallScript1
2156{
2157echo '#!/bin/sh
2158base=`dirname "$0"`
2159cd "$base"
2160if [ -n "$TTY" ]
2161then
2162    unzip -d / install.zip
2163else
2164    response=`alert "Would you like to automatically overwrite existing files, or receive a prompt?" "Overwrite" "Prompt"`
2165    if [ $response == "Overwrite" ]
2166    then
2167        unzip -od / install.zip
2168        alert "Finished installing" "Thanks"
2169    else
2170        if [ -e /boot/beos/apps/Terminal ]
2171        then
2172            terminal=/boot/beos/apps/Terminal
2173        else
2174            terminal=`query Terminal | head -1`
2175        fi
2176        $terminal -t "installer" /bin/sh "$0"
2177    fi
2178fi' > "$(1)" ;
2179	chmod 755 "$(1)" ;
2180}
2181
2182rule PackageInstallZip
2183{
2184	Depends $(1) : $(2) ;
2185	Clean cleanPackages : $(1) ;
2186}
2187
2188actions together PackageInstallZip
2189{
2190	cd "$(1:P)" ;
2191	zip -rqy "$(1:BS)" boot ;
2192}
2193
2194rule LinkInstallZip
2195{
2196	Depends $(1) : $(2) ;
2197	Clean cleanPackages : $(1) ;
2198}
2199
2200actions together LinkInstallZip
2201{
2202	ln -sf "`pwd`/$(2)" "$(1)" ;
2203}
2204
2205rule SubIncludeGPL
2206{
2207	# SubInclude rule that can be used to conditionally include GPL licensed add-ons
2208	if $(INCLUDE_GPL_ADDONS) = 1 {
2209		SubInclude $(1) ;
2210	}
2211}
2212