xref: /haiku/Jamrules (revision 3c71865a51b06cdd850292a9f507b1da513b65e9)
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
294ff6d49fSIngo Weinhold# The directory for build system specific files
304ff6d49fSIngo WeinholdOBOS_BUILD_DIR = [ FDirName $(OBOS_TOP) build ] ;
314ff6d49fSIngo Weinhold
324ff6d49fSIngo Weinhold# Cache files for header scanning and jamfile caching
334ff6d49fSIngo WeinholdHCACHEFILE = header_cache ;
344ff6d49fSIngo WeinholdJCACHEFILE = jamfile_cache ;
354ff6d49fSIngo WeinholdLOCATE on $(HCACHEFILE) $(JCACHEFILE) = $(OBOS_BUILD_DIR) ;
369eea4522SIngo Weinhold
3752a38012Sejakowatz# Include BuildConfig
3852a38012Sejakowatz{
394ff6d49fSIngo Weinhold	local buildConfig = [ GLOB $(OBOS_BUILD_DIR) : BuildConfig ] ;
4052a38012Sejakowatz	if ! $(buildConfig)
4152a38012Sejakowatz	{
424ff6d49fSIngo Weinhold		ECHO "No BuildConfig found in $(OBOS_BUILD_DIR)!" ;
434ff6d49fSIngo Weinhold		EXIT "Run ./configure in the source tree's root directory first!" ;
4452a38012Sejakowatz	}
454ff6d49fSIngo Weinhold	LOCATE on BuildConfig = $(OBOS_BUILD_DIR) ;
464ff6d49fSIngo Weinhold	include BuildConfig ;
4752a38012Sejakowatz}
4852a38012Sejakowatz
498c17a26bSIngo Weinhold# analyze GCC version
508c17a26bSIngo Weinholdif ! $(GCC_RAW_VERSION) {
518c17a26bSIngo Weinhold	ECHO "Variable GCC_RAW_VERSION not set. Please run ./configure or" ;
528c17a26bSIngo Weinhold	EXIT "specify it manually." ;
538c17a26bSIngo Weinhold}
548c17a26bSIngo WeinholdGCC_VERSION = ;
558c17a26bSIngo Weinhold{
568c17a26bSIngo Weinhold	# split the raw version string at `.' and `-' characters
578c17a26bSIngo Weinhold	local version = $(GCC_RAW_VERSION) ;
588c17a26bSIngo Weinhold	while $(version) {
598c17a26bSIngo Weinhold		local split = [ Match "([^.-]*)[.-](.*)" : $(version) ] ;
608c17a26bSIngo Weinhold		if $(split) {
618c17a26bSIngo Weinhold			GCC_VERSION += $(split[1]) ;
628c17a26bSIngo Weinhold			version = $(split[2]) ;
638c17a26bSIngo Weinhold		} else {
648c17a26bSIngo Weinhold			GCC_VERSION += $(version) ;
658c17a26bSIngo Weinhold			version = ;
668c17a26bSIngo Weinhold		}
678c17a26bSIngo Weinhold	}
688c17a26bSIngo Weinhold}
698c17a26bSIngo Weinhold
705dc4e1efSIngo Weinhold# Save the platform default headers.
715dc4e1efSIngo WeinholdPLATFORM_DEFAULT_HEADERS = $(HDRS) ;
725dc4e1efSIngo Weinhold
73705fc998SAxel Dörfler# Add some grist to the libgcc objects
74705fc998SAxel DörflerLIBGCC_OBJECTS = $(LIBGCC_OBJECTS:G=libgcc) ;
75705fc998SAxel Dörfler
76a6c008e1Sbeveloper# We do not include any local BeOS system headers by default
77dd9f8062SIngo WeinholdCCFLAGS += -nostdinc ;
78dd9f8062SIngo WeinholdC++FLAGS += -nostdinc ;
79a6c008e1Sbeveloper
802abad45eSbeveloper# Allow compiling unit tests on Zeta. Instead of fixing the PostMessage()
812abad45eSbeveloper# issues, they deprecated that nice function. This will enable it again:
822abad45eSbeveloperC++FLAGS += -D_ZETA_USING_DEPRECATED_API_=1 ;
832abad45eSbeveloper
8452a38012Sejakowatz# Determine if we're building on PPC or x86
8552a38012Sejakowatz# Determine mimetype of executable
8652a38012Sejakowatz# Cross compiling can come later
8752a38012Sejakowatz
88c9882d9eSAxel DörflerTARGET_CPU ?= $(OSPLAT:L) ;
891f622a7bSAxel DörflerOBOS_VERSION ?= R1 ;
901f622a7bSAxel Dörfler
911f622a7bSAxel Dörflerswitch $(TARGET_CPU) {
921f622a7bSAxel Dörfler	case ppc :
931f622a7bSAxel Dörfler	{
9452a38012Sejakowatz		if $(METROWERKS) {
951f622a7bSAxel Dörfler			# at least parts of OpenBeOS still can be compiled with
961f622a7bSAxel Dörfler			# the Metrowerks compiler on BeOS/PPC
9752a38012Sejakowatz			OBOS_TARGET_TYPE ?= "application/x-be-executable" ;
9852a38012Sejakowatz		} else {
9952a38012Sejakowatz			OBOS_TARGET_TYPE ?= "application/x-vnd.Be-elfexecutable" ;
1001f622a7bSAxel Dörfler		}
101dd22481eSAxel Dörfler		DEFINES += __POWERPC__ ;
102e29d8533SAxel Dörfler		OBOS_BOOT_PLATFORM = openfirmware ;
1031f622a7bSAxel Dörfler	}
1041f622a7bSAxel Dörfler	case x86 :
1051f622a7bSAxel Dörfler	{
1061f622a7bSAxel Dörfler		# nothing special to do here...
107aa19f785SStefano Ceccherini		DEFINES += __INTEL__ ;
108e29d8533SAxel Dörfler		OBOS_BOOT_PLATFORM = bios_ia32 ;
1091f622a7bSAxel Dörfler	}
1101f622a7bSAxel Dörfler	case * :
1111f622a7bSAxel Dörfler		Exit "Currently unsupported build platform:" $(TARGET_CPU) ;
1121f622a7bSAxel Dörfler}
1131f622a7bSAxel Dörfler
1141f622a7bSAxel Dörfler# set target specific variables
1151f622a7bSAxel Dörfler{
1161f622a7bSAxel Dörfler	#Echo "Building for" $(TARGET_CPU) ;
1171f622a7bSAxel Dörfler
1181f622a7bSAxel Dörfler	OBOS_TARGET ?= $(TARGET_CPU).$(OBOS_VERSION) ;
1191f622a7bSAxel Dörfler	OBOS_TARGET_TYPE ?= "application/x-vnd.Be-elfexecutable" ;
1201f622a7bSAxel Dörfler	OBOS_ARCH ?= $(TARGET_CPU) ;
1211f622a7bSAxel Dörfler	OBOS_TARGET_DEFINE ?= "ARCH_"$(TARGET_CPU) ;
12252a38012Sejakowatz}
12352a38012Sejakowatz
12465c62a01SIngo Weinhold# Disable warnings only if WARNINGS is set to 0
125e5dc2d93Sbeveloper# Should be enabled by default later
12696d27465SIngo Weinhold#
12765c62a01SIngo WeinholdWARNINGS ?= 1 ;
12865c62a01SIngo Weinholdif $(WARNINGS) = 1 {
129e5dc2d93Sbeveloper	# For an explanation of the different warning options, see:
130e5dc2d93Sbeveloper	# http://gcc.gnu.org/onlinedocs/gcc-2.95.3/gcc_2.html
131e5dc2d93Sbeveloper	# to get even more warnings, add:
132e5dc2d93Sbeveloper	# -Wwrite-strings  	(doesn't work well with some Be headers)
133e5dc2d93Sbeveloper	# -Wundef			(dito)
134e5dc2d93Sbeveloper	# -Wconversion		(gets you many warnings about implicit conversions)
135e5dc2d93Sbeveloper	# -W				(gets you even more warnigs)
136dd9f8062SIngo Weinhold	CCFLAGS += -Wall -Wno-multichar -Wmissing-prototypes ;
137dd9f8062SIngo Weinhold	CCFLAGS += -Wpointer-arith -Wcast-align -Wsign-compare ;
138dd9f8062SIngo Weinhold	C++FLAGS += -Wall -Wno-multichar -Wmissing-prototypes -Wno-ctor-dtor-privacy -Woverloaded-virtual ;
139dd9f8062SIngo Weinhold	C++FLAGS += -Wpointer-arith -Wcast-align -Wsign-compare ;
14098cc804cSAxel Dörfler} else {
14198cc804cSAxel Dörfler	CCFLAGS += -Wno-multichar ;
14298cc804cSAxel Dörfler	C++FLAGS += -Wno-multichar ;
143e5dc2d93Sbeveloper}
144e5dc2d93Sbeveloper
14598cc804cSAxel Dörfler# standard kernel C/C++ flags
1460ff867c2SbeveloperKERNEL_CCFLAGS ?= -Wall -Wno-multichar -Wmissing-prototypes -finline -nostdinc ;
1470ff867c2SbeveloperKERNEL_CCFLAGS += -fno-builtin -D$(OBOS_TARGET_DEFINE) ;
148ea7627e5SAxel DörflerKERNEL_CCFLAGS += -DBOCHS_DEBUG_HACK=$(BOCHS_DEBUG_HACK) -D_KERNEL_MODE ;
14998cc804cSAxel DörflerKERNEL_C++FLAGS ?= -Wall -Wno-multichar -Wmissing-prototypes -finline -nostdinc ;
15098cc804cSAxel DörflerKERNEL_C++FLAGS += -fno-builtin -fno-exceptions -fno-rtti -D$(OBOS_TARGET_DEFINE) ;
151ea7627e5SAxel DörflerKERNEL_C++FLAGS += -DBOCHS_DEBUG_HACK=$(BOCHS_DEBUG_HACK) -D_KERNEL_MODE ;
152bbb6f2d4SAxel Dörflerif $(GCC_VERSION[1]) >= 3 {
153bbb6f2d4SAxel Dörfler	KERNEL_C++FLAGS += -fno-use-cxa-atexit ;
154bbb6f2d4SAxel Dörfler}
1550ff867c2Sbeveloper
1569eea4522SIngo Weinhold# We might later want to introduce debug levels or handle the whole issue
1579eea4522SIngo Weinhold# differently. For now there's only on or off.
1589eea4522SIngo Weinhold#
15965c62a01SIngo WeinholdDEBUG ?= 0 ;
16065c62a01SIngo Weinholdif $(DEBUG) != 0 {
1619eea4522SIngo Weinhold	OPTIM ?= -O0 ;
16265c62a01SIngo Weinhold	CCFLAGS += -g [ FDefines DEBUG=$(DEBUG) ] ;
16365c62a01SIngo Weinhold	C++FLAGS += -g [ FDefines DEBUG=$(DEBUG) ] ;
16465c62a01SIngo Weinhold	KERNEL_CCFLAGS += -g [ FDefines DEBUG=$(DEBUG) ] ;
16565c62a01SIngo Weinhold	KERNEL_C++FLAGS += -g [ FDefines DEBUG=$(DEBUG) ] ;
1669eea4522SIngo Weinhold	LINKFLAGS += -g ;
1679eea4522SIngo Weinhold} else {
1689eea4522SIngo Weinhold	OPTIM ?= -O2 ;
1699eea4522SIngo Weinhold}
17096d27465SIngo Weinhold#
17196d27465SIngo Weinhold# To disable for the tests OPTIM and DEBUG are overridden, set the environment
17296d27465SIngo Weinhold# variable NO_TEST_DEBUG.
1739eea4522SIngo Weinhold
17416fa4445SIngo Weinhold# Instructs the Library rule to not make its object files temporary.
175f1e077f8SIngo Weinhold# This is needed as some objects are used in a static library and for an
17616fa4445SIngo Weinhold# executable.
17716fa4445SIngo WeinholdKEEPOBJS = true ;
17816fa4445SIngo Weinhold
1797bc56df1SIngo Weinhold# under BeOS use copyattr instead of cp
1807bc56df1SIngo Weinholdif $(OS) = BEOS
1817bc56df1SIngo Weinhold{
1827bc56df1SIngo Weinhold	CP = copyattr --data ;
1837bc56df1SIngo Weinhold}
1847bc56df1SIngo Weinhold
18552a38012Sejakowatz# If no OBOS_OBJECT_TARGET is not defined yet, use our default directory and
18652a38012Sejakowatz# include our "OBOS_TARGET" as subdirectory in there (to prevent different
18752a38012Sejakowatz# builds mixing objects from different targets).
18852a38012Sejakowatzif ! $(OBOS_OBJECT_TARGET) {
18952a38012Sejakowatz	OBOS_OBJECT_TARGET ?= [ FDirName $(OBOS_TOP) objects $(OBOS_TARGET) ] ;
19052a38012Sejakowatz}
19152a38012Sejakowatz
19252a38012Sejakowatz# If no OBOS_DISTRO_TARGET is not defined yet, use our default directory and
19352a38012Sejakowatz# include our "OBOS_TARGET" as subdirectory in there (to prevent different
19452a38012Sejakowatz# builds mixing executables from different targets).
19552a38012Sejakowatzif ! $(OBOS_DISTRO_TARGET) {
19652a38012Sejakowatz	OBOS_DISTRO_TARGET ?= [ FDirName $(OBOS_TOP) distro $(OBOS_TARGET) ] ;
19752a38012Sejakowatz}
19852a38012Sejakowatz
19952a38012Sejakowatz# Set our version number if not already set and mark it as a developer build
20052a38012Sejakowatzif ! $(OBOS_BUILD_VERSION) {
20152a38012Sejakowatz	OBOS_BUILD_VERSION ?= "1 0 0 a 1" ;
20252a38012Sejakowatz	OBOS_BUILD_DESCRIPTION ?= "Developer Build" ;
20352a38012Sejakowatz}
20452a38012Sejakowatz
20552a38012Sejakowatz# If OBOS_BUILD_VERSION is set, but OBOS_BUILD_DESCRIPTION isn't, mark it as
20652a38012Sejakowatz# an unknown build.
20752a38012Sejakowatzif ! $(OBOS_BUILD_DESCRIPTION) {
20852a38012Sejakowatz	OBOS_BUILD_DESCRIPTION ?= "Unknown Build" ;
20952a38012Sejakowatz}
21052a38012Sejakowatz
211505554b4SIngo Weinhold# Relative subdirs for distro dir
212505554b4SIngo WeinholdOBOS_ADDON_DIR  ?= [ FDirName $(OBOS_DISTRO_TARGET) beos system add-ons ] ;
2135f281ed5SejakowatzOBOS_APPS_DIR   ?= [ FDirName $(OBOS_DISTRO_TARGET) beos apps ] ;
214f06de7f3SIngo WeinholdOBOS_BIN_DIR    ?= [ FDirName $(OBOS_DISTRO_TARGET) beos bin ] ;
215505554b4SIngo WeinholdOBOS_ETC_DIR    ?= [ FDirName $(OBOS_DISTRO_TARGET) beos etc ] ;
216505554b4SIngo WeinholdOBOS_FONTS_DIR  ?= [ FDirName $(OBOS_ETC_DIR) fonts ] ;
217505554b4SIngo WeinholdOBOS_KERNEL_DIR ?= [ FDirName $(OBOS_DISTRO_TARGET) beos system ] ;
21852a38012SejakowatzOBOS_PREFS_DIR  ?= [ FDirName $(OBOS_DISTRO_TARGET) beos preferences ] ;
21952a38012SejakowatzOBOS_SERVER_DIR ?= [ FDirName $(OBOS_DISTRO_TARGET) beos system servers ] ;
22052a38012SejakowatzOBOS_SHLIB_DIR  ?= [ FDirName $(OBOS_DISTRO_TARGET) beos system lib ] ;
221e9230d05SIngo WeinholdOBOS_STLIB_DIR  ?= [ FDirName $(OBOS_DISTRO_TARGET) develop lib
222e9230d05SIngo Weinhold							  $(OBOS_ARCH) ] ;
22352a38012SejakowatzOBOS_TEST_DIR   ?= [ FDirName $(OBOS_TOP) tests ] ;
22452a38012Sejakowatz
225c06f365fSIngo WeinholdOBOS_PACKAGE_DIR ?= [ FDirName $(OBOS_TOP) packages $(OBOS_TARGET) ] ;
226c06f365fSIngo WeinholdOBOS_PACKAGE_OBJECT_DIR ?= [ FDirName $(OBOS_OBJECT_TARGET) packages ] ;
227c06f365fSIngo Weinhold
22852a38012SejakowatzOBOS_KERNEL_CONFIG = config.$(OBOS_ARCH).ini ;
22952a38012SejakowatzOBOS_KERNEL = kernel.$(OBOS_ARCH) ;
23052a38012SejakowatzOBOS_FLOPPY = floppy.$(OBOS_ARCH) ;
23152a38012Sejakowatz
23252a38012Sejakowatzrule SetupIncludes
23352a38012Sejakowatz{
234cfc7b456Sshatty	# XXX add "opengl" later
235cfc7b456Sshatty	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 ;
236a6c008e1Sbeveloper
23728d2a30eSDaniel Reinhold	# Overwrite any exiting content when changing HDRS. This rule may be invoked multiple times.
238a6c008e1Sbeveloper
239a6c008e1Sbeveloper	# Use headers directory, to allow to do things like include <posix/string.h>
24028d2a30eSDaniel Reinhold	HDRS = [ FDirName $(OBOS_TOP) headers ] ;
241a6c008e1Sbeveloper
242a6c008e1Sbeveloper	# Use posix headers directory
24328d2a30eSDaniel Reinhold	HDRS += [ FDirName $(OBOS_TOP) headers posix ] ;
244a6c008e1Sbeveloper
245a6c008e1Sbeveloper	# Use public OS header directories
24628d2a30eSDaniel Reinhold	HDRS += [ PublicHeaders $(os_includes) ] ;
247a6c008e1Sbeveloper
248a6c008e1Sbeveloper	# Used as a fallback, the R5 header directories (we should remove this as soon as possible)
24928d2a30eSDaniel Reinhold	HDRS += /boot/develop/headers/posix /boot/develop/headers/cpp ;
25009c5682dSIngo Weinhold
25109c5682dSIngo Weinhold	# The platform dependent headers.
25209c5682dSIngo Weinhold	HDRS += $(PLATFORM_HEADERS) ;
25352a38012Sejakowatz}
25452a38012Sejakowatz
255dd9f8062SIngo Weinholdrule SetupR5Includes
256dd9f8062SIngo Weinhold{
257dd9f8062SIngo Weinhold	# Unsets HDRS, so that the OBOS headers do not `shadow' the system headers.
258dd9f8062SIngo Weinhold	HDRS = ;
259dd9f8062SIngo Weinhold}
260dd9f8062SIngo Weinhold
2615dc4e1efSIngo Weinholdrule SetupDefaultIncludes
2625dc4e1efSIngo Weinhold{
2635dc4e1efSIngo Weinhold	# Resets HDRS to the default headers for the build platform.
2645dc4e1efSIngo Weinhold	HDRS = $(PLATFORM_DEFAULT_HEADERS) ;
2655dc4e1efSIngo Weinhold}
2665dc4e1efSIngo Weinhold
26752a38012Sejakowatz#-------------------------------------------------------------------------------
26852a38012Sejakowatz# Things Jam needs in order to work :)
26952a38012Sejakowatz#-------------------------------------------------------------------------------
27052a38012Sejakowatz
271c06f365fSIngo Weinhold# TODO: back-ported from jam 2.5: remove when not longer needed
272c06f365fSIngo Weinholdrule MakeLocate
273c06f365fSIngo Weinhold{
274c06f365fSIngo Weinhold	if $(>)
275c06f365fSIngo Weinhold	{
276c06f365fSIngo Weinhold	    LOCATE on $(<) = $(>) ;
277c06f365fSIngo Weinhold	    Depends $(<) : $(>[1]:G=dir) ;
278c06f365fSIngo Weinhold	    MkDir $(>[1]:G=dir) ;
279c06f365fSIngo Weinhold	}
280c06f365fSIngo Weinhold}
281c06f365fSIngo Weinhold
2828d3308d9SIngo Weinholdrule Object
2838d3308d9SIngo Weinhold{
2848d3308d9SIngo Weinhold	# This is basically the original Jambase 2.4 Object rule stripped by
2858d3308d9SIngo Weinhold	# comments. Only the final switch statement has been changed to allow
2868d3308d9SIngo Weinhold	# intermediate C++ files for Yacc and Lex.
2878d3308d9SIngo Weinhold
2888d3308d9SIngo Weinhold	LocalClean clean : $(<) ;
2898d3308d9SIngo Weinhold
2908d3308d9SIngo Weinhold	MakeLocate $(<) : $(LOCATE_TARGET) ;
2918d3308d9SIngo Weinhold	SEARCH on $(>) = $(SEARCH_SOURCE) ;
2928d3308d9SIngo Weinhold
2938d3308d9SIngo Weinhold	HDRS on $(<) = $(SEARCH_SOURCE) $(SUBDIRHDRS) $(HDRS) ;
2948d3308d9SIngo Weinhold
2958d3308d9SIngo Weinhold	HDRRULE on $(>) = HdrRule ;
2968d3308d9SIngo Weinhold	HDRSCAN on $(>) = $(HDRPATTERN) ;
2978d3308d9SIngo Weinhold	HDRSEARCH on $(>) =
2988d3308d9SIngo Weinhold		$(SEARCH_SOURCE:E) $(SUBDIRHDRS) $(HDRS) $(STDHDRS) ;
2998d3308d9SIngo Weinhold
3008d3308d9SIngo Weinhold	HDRGRIST on $(>) = $(HDRGRIST) ;
3018d3308d9SIngo Weinhold
3028d3308d9SIngo Weinhold	DEFINES on $(<) += $(DEFINES) ;
3038d3308d9SIngo Weinhold
3048d3308d9SIngo Weinhold	# if source is not .c, generate .c with specific rule
3058d3308d9SIngo Weinhold
3068d3308d9SIngo Weinhold	switch $(>:S)
3078d3308d9SIngo Weinhold	{
3088d3308d9SIngo Weinhold	    case .asm : As $(<) : $(>) ;
3098d3308d9SIngo Weinhold	    case .c :	Cc $(<) : $(>) ;
3108d3308d9SIngo Weinhold	    case .C :	C++ $(<) : $(>) ;
3118d3308d9SIngo Weinhold	    case .cc :	C++ $(<) : $(>) ;
3128d3308d9SIngo Weinhold	    case .cpp : C++ $(<) : $(>) ;
3138d3308d9SIngo Weinhold	    case .f :	Fortran $(<) : $(>) ;
3148d3308d9SIngo Weinhold	    case .l :	if [ on $(2) return $(GENERATE_C++) ] {
3158d3308d9SIngo Weinhold						C++ $(<) : $(<:S=.cpp) ;
3168d3308d9SIngo Weinhold						LexC++ $(<:S=.cpp) : $(>) ;
3178d3308d9SIngo Weinhold					} else {
3188d3308d9SIngo Weinhold						Cc $(<) : $(<:S=.c) ;
3198d3308d9SIngo Weinhold						Lex $(<:S=.c) : $(>) ;
3208d3308d9SIngo Weinhold					}
3218d3308d9SIngo Weinhold	    case .s :	As $(<) : $(>) ;
3228d3308d9SIngo Weinhold	    case .y :	if [ on $(2) return $(GENERATE_C++) ] {
3238d3308d9SIngo Weinhold						C++ $(<) : $(<:S=.cpp) ;
3248d3308d9SIngo Weinhold						Bison $(<:S=.cpp) : $(>) ;
3258d3308d9SIngo Weinhold					} else {
3268d3308d9SIngo Weinhold						Cc $(<) : $(<:S=$(YACCGEN)) ;
3278d3308d9SIngo Weinhold						Yacc $(<:S=$(YACCGEN)) : $(>) ;
3288d3308d9SIngo Weinhold					}
3298d3308d9SIngo Weinhold	    case * :	UserObject $(<) : $(>) ;
3308d3308d9SIngo Weinhold	}
3318d3308d9SIngo Weinhold}
3328d3308d9SIngo Weinhold
33352a38012Sejakowatzrule UserObject
33452a38012Sejakowatz{
33552a38012Sejakowatz	switch $(2)
33652a38012Sejakowatz	{
33752a38012Sejakowatz	case *.S    : assemble $(1) : $(2) ;
33808125d07SIngo Weinhold	case *.o    : return ;
33952a38012Sejakowatz	case *      : ECHO "unknown suffix on" $(2) ;
34052a38012Sejakowatz	}
34152a38012Sejakowatz}
34252a38012Sejakowatz
34352a38012Sejakowatz# Override the default to give "prettier" command lines.
34452a38012Sejakowatzactions Cc
34552a38012Sejakowatz{
3460931b8f9SIngo Weinhold	$(CC) -c "$(2)" $(CCFLAGS) $(CCDEFS) $(CCHDRS) -o "$(1)" ;
34752a38012Sejakowatz}
34852a38012Sejakowatz
34952a38012Sejakowatzactions C++
35052a38012Sejakowatz{
3510931b8f9SIngo Weinhold	$(C++) -c "$(2)" $(C++FLAGS) $(CCDEFS) $(CCHDRS) -o "$(1)" ;
35252a38012Sejakowatz}
35352a38012Sejakowatz
35452a38012Sejakowatz
35552a38012Sejakowatz#-------------------------------------------------------------------------------
35652a38012Sejakowatz# General High-level OBOS target rules
35752a38012Sejakowatz#-------------------------------------------------------------------------------
35852a38012Sejakowatz
3595f281ed5Sejakowatzrule App
3605f281ed5Sejakowatz{
361007eb5f2SIngo Weinhold	# App <name> : <sources> : <libraries> ;
362a6c008e1Sbeveloper	SetupIncludes ;
3635f281ed5Sejakowatz	SetupObjectsDir ;
364007eb5f2SIngo Weinhold	Main $(1) : $(2) ;
365007eb5f2SIngo Weinhold	MakeLocate $(1) : $(OBOS_APPS_DIR) ;
366007eb5f2SIngo Weinhold	LinkSharedOSLibs $(1) : $(3) ;
367007eb5f2SIngo Weinhold	LINKFLAGS on $(1) = [ on $(1) return $(LINKFLAGS) ]
368007eb5f2SIngo Weinhold						-Xlinker -soname=_APP_ ;
3695f281ed5Sejakowatz}
3705f281ed5Sejakowatz
371f06de7f3SIngo Weinholdrule BinCommand
372f06de7f3SIngo Weinhold{
37311fa3682SJérôme Duval	# BinCommand <name> : <sources> : <libraries> : <res> ;
374a6c008e1Sbeveloper	SetupIncludes ;
375f06de7f3SIngo Weinhold	SetupObjectsDir ;
37611fa3682SJérôme Duval	AddResources $(1) : $(4) ;
377f06de7f3SIngo Weinhold	Main $(1) : $(2) ;
378f06de7f3SIngo Weinhold	MakeLocate $(1) : $(OBOS_BIN_DIR) ;
379f06de7f3SIngo Weinhold	LinkSharedOSLibs $(1) : $(3) ;
380007eb5f2SIngo Weinhold	LINKFLAGS on $(1) = [ on $(1) return $(LINKFLAGS) ]
381007eb5f2SIngo Weinhold						-Xlinker -soname=_APP_ ;
382f06de7f3SIngo Weinhold}
383f06de7f3SIngo Weinhold
384f06de7f3SIngo Weinholdrule StdBinCommands
385f06de7f3SIngo Weinhold{
38611fa3682SJérôme Duval	# StdBinCommands <sources> : <libs> : <res> ;
387a6c008e1Sbeveloper	SetupIncludes ;
388a6c008e1Sbeveloper	SetupObjectsDir ;
389f06de7f3SIngo Weinhold	local libs = $(2) ;
39011fa3682SJérôme Duval	local ress = $(3) ;
3919342c27aSIngo Weinhold	local source ;
392f06de7f3SIngo Weinhold	for source in $(1)
393f06de7f3SIngo Weinhold	{
394f06de7f3SIngo Weinhold		local target = $(source:S=) ;
395f06de7f3SIngo Weinhold		target = [ FGristFiles $(target) ] ;
396a6c008e1Sbeveloper
39711fa3682SJérôme Duval		BinCommand $(target) : $(source) : $(libs) : $(ress) ;
398f06de7f3SIngo Weinhold	}
399f06de7f3SIngo Weinhold}
400f06de7f3SIngo Weinhold
40152a38012Sejakowatzrule Preference
40252a38012Sejakowatz{
403007eb5f2SIngo Weinhold	# Preference <name> : <sources> : <libraries> ;
404a6c008e1Sbeveloper	SetupIncludes ;
40552a38012Sejakowatz	SetupObjectsDir ;
406007eb5f2SIngo Weinhold	Main $(1) : $(2) ;
407007eb5f2SIngo Weinhold	MakeLocate $(1) : $(OBOS_PREFS_DIR) ;
408007eb5f2SIngo Weinhold	LinkSharedOSLibs $(1) : $(3) ;
409007eb5f2SIngo Weinhold	LINKFLAGS on $(1) = [ on $(1) return $(LINKFLAGS) ]
410007eb5f2SIngo Weinhold						-Xlinker -soname=_APP_ ;
41152a38012Sejakowatz}
41252a38012Sejakowatz
41352a38012Sejakowatzrule Server
41452a38012Sejakowatz{
415007eb5f2SIngo Weinhold	# Server <name> : <sources> : <libraries> ;
41652a38012Sejakowatz
417a6c008e1Sbeveloper	SetupIncludes ;
41852a38012Sejakowatz	SetupObjectsDir ;
419007eb5f2SIngo Weinhold	Main $(1) : $(2) ;
420007eb5f2SIngo Weinhold	MakeLocate $(1) : $(OBOS_SERVER_DIR) ;
421007eb5f2SIngo Weinhold	LinkSharedOSLibs $(1) : $(3) ;
422007eb5f2SIngo Weinhold	LINKFLAGS on $(1) = [ on $(1) return $(LINKFLAGS) ]
423007eb5f2SIngo Weinhold						-Xlinker -soname=_APP_ ;
42452a38012Sejakowatz}
42552a38012Sejakowatz
42652a38012Sejakowatz# test pseudo targets
42752a38012SejakowatzNOTFILE obostests ;
42852a38012SejakowatzNOTFILE r5tests ;
42952a38012Sejakowatz
430d1f6c38fSTyler Dauwalderrule CommonTestLib
431d1f6c38fSTyler Dauwalder{
432c5ff4aa6STyler Dauwalder	# CommonTestLib <target> : <sources> : <obos libraries>
4339285de51STyler Dauwalder	#	: <r5 libraries> : <test libraries> : <public headers>;
434d1f6c38fSTyler Dauwalder	# Builds a unit test for both OBOS and R5 modules.
435d1f6c38fSTyler Dauwalder	# <target> The name of the target.
436d1f6c38fSTyler Dauwalder	# <sources> The list of sources.
437d1f6c38fSTyler Dauwalder	# <obos libraries> A list of link libraries for the OBOS tests (as passed
438d1f6c38fSTyler Dauwalder	# to LinkSharedOSLibs).
439d1f6c38fSTyler Dauwalder	# <r5 libraries> A list of link libraries for the R5 tests (as passed
440d1f6c38fSTyler Dauwalder	# to LinkSharedOSLibs).
4419285de51STyler Dauwalder	# <test libraries> A list of link libraries for both OBOS tests and R5 tests
4429285de51STyler Dauwalder	# that have a common name (i.e. specify libx.so and the OBOS tests will link
4439285de51STyler Dauwalder	# to libx.so and the R5 tests will link to libx_r5.so).
444d1f6c38fSTyler Dauwalder	# <public headers> A list of public header dirs (as passed to
445d1f6c38fSTyler Dauwalder	# UsePublicHeaders).
446d1f6c38fSTyler Dauwalder
447c5ff4aa6STyler Dauwalder	TestLib $(1) : $(2) : [ FDirName $(OBOS_TEST_DIR) unittester lib ] : $(3) $(5) : $(6) ;
448c5ff4aa6STyler Dauwalder	R5TestLib $(1) : $(2) : [ FDirName $(OBOS_TEST_DIR) unittester_r5 lib ] : $(4) [ R5SharedLibraryNames $(5) ] ;
449d1f6c38fSTyler Dauwalder}
450d1f6c38fSTyler Dauwalder
451d1f6c38fSTyler Dauwalderrule TestLib
452d1f6c38fSTyler Dauwalder{
453d1f6c38fSTyler Dauwalder	# TestLib <target> : <sources> : <dest> : <libraries> : <public headers>
454d1f6c38fSTyler Dauwalder	# Builds a unit test library for an OBOS module.
455d1f6c38fSTyler Dauwalder	# <target> The name of the target.
456d1f6c38fSTyler Dauwalder	# <sources> The list of sources.
457d1f6c38fSTyler Dauwalder	# <dest> The directory for the target (as passed to FDirName).
458d1f6c38fSTyler Dauwalder	# <libraries> A list of link libraries (as passed to LinkSharedOSLibs).
459d1f6c38fSTyler Dauwalder	# <public headers> A list of public header dirs (as passed to
460d1f6c38fSTyler Dauwalder	# UsePublicHeaders).
461d1f6c38fSTyler Dauwalder
462d1f6c38fSTyler Dauwalder	local target = $(1) ;
463d1f6c38fSTyler Dauwalder	local sources = $(2) ;
464d1f6c38fSTyler Dauwalder	local dest = $(3) ;
465d1f6c38fSTyler Dauwalder	local libraries = $(4) ;
466d1f6c38fSTyler Dauwalder	local headerDirs = $(5) ;
4679342c27aSIngo Weinhold	local objects = [ FGristFiles $(sources:S=$(SUFOBJ)) ] ;
468d1f6c38fSTyler Dauwalder
4699342c27aSIngo Weinhold	# Our Main replacement.
4709342c27aSIngo Weinhold	MainFromObjects $(target) : $(objects) ;
4719342c27aSIngo Weinhold	TestObjects $(sources) : $(headerDirs) ;
472d1f6c38fSTyler Dauwalder
473d1f6c38fSTyler Dauwalder	MakeLocate $(target) : $(dest) ;
4740d1cdd94SIngo Weinhold	Depends $(target) : libcppunit.so ;
4750d1cdd94SIngo Weinhold	Depends obostests : $(target) ;
476d1f6c38fSTyler Dauwalder	LinkSharedOSLibs $(target) : libcppunit.so $(libraries) ;
477d1f6c38fSTyler Dauwalder	LINKFLAGS on $(target) = $(LINKFLAGS) -nostart -Xlinker -soname=\"$(target)\" ;
478d1f6c38fSTyler Dauwalder}
479d1f6c38fSTyler Dauwalder
480d1f6c38fSTyler Dauwalderrule R5TestLib
481d1f6c38fSTyler Dauwalder{
482c5ff4aa6STyler Dauwalder	# R5TestLib <target> : <sources> : <dest> : <libraries>
483d1f6c38fSTyler Dauwalder	# Builds a unit test for an R5 module. "_r5" is appended to the object
484d1f6c38fSTyler Dauwalder	# and the target name.
485d1f6c38fSTyler Dauwalder	# <target> The name of the target.
486d1f6c38fSTyler Dauwalder	# <sources> The list of sources.
487d1f6c38fSTyler Dauwalder	# <dest> The directory for the target (as passed to FDirName).
488d1f6c38fSTyler Dauwalder	# <libraries> A list of link libraries (as passed to LinkSharedOSLibs).
489d1f6c38fSTyler Dauwalder
490d1f6c38fSTyler Dauwalder	local target = $(1:B)_r5$(1:S) ;
491d1f6c38fSTyler Dauwalder	local sources = $(2) ;
492c5ff4aa6STyler Dauwalder	local dest = $(3) ;
493d1f6c38fSTyler Dauwalder	local libraries = $(4) ;
494d1f6c38fSTyler Dauwalder	local objects = [ R5ObjectNames $(sources) ] ;
495d1f6c38fSTyler Dauwalder
496d1f6c38fSTyler Dauwalder	# Our Main replacement.
497d1f6c38fSTyler Dauwalder	MainFromObjects $(target) : $(objects) ;
4989342c27aSIngo Weinhold	TestObjects $(sources) : : true ;
499d1f6c38fSTyler Dauwalder
500d1f6c38fSTyler Dauwalder	MakeLocate $(target) : $(dest) ;
5010d1cdd94SIngo Weinhold	Depends $(target) : libcppunit.so ;
5020d1cdd94SIngo Weinhold	Depends r5tests : $(target) ;
503d1f6c38fSTyler Dauwalder	LinkSharedOSLibs $(target) : libcppunit.so $(libraries) ;
504d1f6c38fSTyler Dauwalder	LINKFLAGS on $(target) = $(LINKFLAGS) -nostart -Xlinker -soname=\"$(target)\" ;
505d1f6c38fSTyler Dauwalder}
506d1f6c38fSTyler Dauwalder
50752a38012Sejakowatzrule CommonUnitTest
50852a38012Sejakowatz{
50952a38012Sejakowatz	# CommonUnitTest <target> : <sources> : <dest> : <obos libraries>
51052a38012Sejakowatz	#	: <r5 libraries> : <public headers>;
51152a38012Sejakowatz	# Builds a unit test for both OBOS and R5 modules.
51252a38012Sejakowatz	# <target> The name of the target.
51352a38012Sejakowatz	# <sources> The list of sources.
51452a38012Sejakowatz	# <dest> The directory for the target (as passed to FDirName).
51552a38012Sejakowatz	# <obos libraries> A list of link libraries for the OBOS tests (as passed
51652a38012Sejakowatz	# to LinkSharedOSLibs).
51752a38012Sejakowatz	# <r5 libraries> A list of link libraries for the R5 tests (as passed
51852a38012Sejakowatz	# to LinkSharedOSLibs).
51952a38012Sejakowatz	# <public headers> A list of public header dirs (as passed to
52052a38012Sejakowatz	# UsePublicHeaders).
52152a38012Sejakowatz
52252a38012Sejakowatz	UnitTest $(1) : $(2) : $(3) : $(4) : $(6) ;
52352a38012Sejakowatz	R5UnitTest $(1) : $(2) : $(3) : $(5) ;
52452a38012Sejakowatz}
52552a38012Sejakowatz
52652a38012Sejakowatzrule UnitTest
52752a38012Sejakowatz{
52852a38012Sejakowatz	# UnitTest <target> : <sources> : <dest> : <libraries> : <public headers>
52952a38012Sejakowatz	# Builds a unit test for an OBOS module.
53052a38012Sejakowatz	# <target> The name of the target.
53152a38012Sejakowatz	# <sources> The list of sources.
53252a38012Sejakowatz	# <dest> The directory for the target (as passed to FDirName).
53352a38012Sejakowatz	# <libraries> A list of link libraries (as passed to LinkSharedOSLibs).
53452a38012Sejakowatz	# <public headers> A list of public header dirs (as passed to
53552a38012Sejakowatz	# UsePublicHeaders).
53652a38012Sejakowatz
53752a38012Sejakowatz	local target = $(1) ;
53852a38012Sejakowatz	local sources = $(2) ;
53952a38012Sejakowatz	local dest = $(3) ;
54052a38012Sejakowatz	local libraries = $(4) ;
54152a38012Sejakowatz	local headerDirs = $(5) ;
5429342c27aSIngo Weinhold	local objects = [ FGristFiles $(sources:S=$(SUFOBJ)) ] ;
54352a38012Sejakowatz
5449342c27aSIngo Weinhold	# Our Main replacement.
5459342c27aSIngo Weinhold	MainFromObjects $(target) : $(objects) ;
5469342c27aSIngo Weinhold	TestObjects $(sources) : $(headerDirs) ;
5473b9eae39SIngo Weinhold
54852a38012Sejakowatz	MakeLocate $(target) : [ FDirName $(OBOS_TEST_DIR) $(dest) ] ;
5499eea4522SIngo Weinhold	Depends $(target) : libcppunit.so ;
5509eea4522SIngo Weinhold	Depends obostests : $(target) ;
55152a38012Sejakowatz	LinkSharedOSLibs $(target) : libcppunit.so $(libraries) ;
55252a38012Sejakowatz}
55352a38012Sejakowatz
55452a38012Sejakowatzrule R5UnitTest
55552a38012Sejakowatz{
55652a38012Sejakowatz	# R5UnitTest <target> : <sources> : <dest> : <libraries>
55752a38012Sejakowatz	# Builds a unit test for an R5 module. "_r5" is appended to the object
55852a38012Sejakowatz	# and the target name.
55952a38012Sejakowatz	# <target> The name of the target.
56052a38012Sejakowatz	# <sources> The list of sources.
56152a38012Sejakowatz	# <dest> The directory for the target (as passed to FDirName).
56252a38012Sejakowatz	# <libraries> A list of link libraries (as passed to LinkSharedOSLibs).
56352a38012Sejakowatz
56452a38012Sejakowatz	local target = $(1)_r5 ;
56552a38012Sejakowatz	local sources = $(2) ;
56652a38012Sejakowatz	local dest = $(3) ;
56752a38012Sejakowatz	local libraries = $(4) ;
56852a38012Sejakowatz	local objects = [ R5ObjectNames $(sources) ] ;
56952a38012Sejakowatz
57052a38012Sejakowatz	# Our Main replacement.
57152a38012Sejakowatz	MainFromObjects $(target) : $(objects) ;
5729342c27aSIngo Weinhold	TestObjects $(sources) : : true ;
57352a38012Sejakowatz
57452a38012Sejakowatz	MakeLocate $(target) : [ FDirName $(OBOS_TEST_DIR) $(dest) ] ;
5759eea4522SIngo Weinhold	Depends $(target) : libcppunit.so ;
5769eea4522SIngo Weinhold	Depends r5tests : $(target) ;
57752a38012Sejakowatz	LinkSharedOSLibs $(target) : libcppunit.so $(libraries) ;
57852a38012Sejakowatz}
57952a38012Sejakowatz
58052a38012Sejakowatzrule R5ObjectNames
58152a38012Sejakowatz{
58252a38012Sejakowatz	# R5ObjectNames <sources> ;
58352a38012Sejakowatz	# Returns a list of gristed object names given a list of source file names.
58452a38012Sejakowatz	# Moreover each object names gets "_r5" inserted before the object suffix.
58552a38012Sejakowatz	local objects = $(1:S=)_r5 ;
58652a38012Sejakowatz	return [ FGristFiles $(objects:S=$(SUFOBJ)) ] ;
58752a38012Sejakowatz}
58852a38012Sejakowatz
5899342c27aSIngo Weinholdrule R5Objects
5909342c27aSIngo Weinhold{
5919342c27aSIngo Weinhold	# R5Objects <sources>
592dd9f8062SIngo Weinhold	# Similar to Objects, but appends "_r5" to the object file names and
593dd9f8062SIngo Weinhold	# removes `-nostdinc' from the CC and C++ flags to enable system headers.
5949342c27aSIngo Weinhold	# <sources> The source files.
5959342c27aSIngo Weinhold
596dd9f8062SIngo Weinhold	# Remove `-nostdinc' from CCFLAGS and C++FLAGS.
597dd9f8062SIngo Weinhold	local oldCCFLAGS = $(CCFLAGS) ;
598dd9f8062SIngo Weinhold	local oldC++FLAGS = $(C++FLAGS) ;
599dd9f8062SIngo Weinhold	CCFLAGS = [ Filter $(CCFLAGS) : -nostdinc ] ;
600dd9f8062SIngo Weinhold	C++FLAGS = [ Filter $(C++FLAGS) : -nostdinc ] ;
601dd9f8062SIngo Weinhold
6029342c27aSIngo Weinhold	local sources = $(1) ;
6039342c27aSIngo Weinhold	local source ;
6049342c27aSIngo Weinhold	for source in [ FGristFiles $(sources) ]
6059342c27aSIngo Weinhold	{
6069342c27aSIngo Weinhold		local object = [ R5ObjectNames $(source) ] ;
6079342c27aSIngo Weinhold		Object $(object) : $(source) ;
6089342c27aSIngo Weinhold		LocalDepends obj : $(object) ;
6099342c27aSIngo Weinhold	}
610dd9f8062SIngo Weinhold
611dd9f8062SIngo Weinhold	# Reset CCFLAGS and C++FLAGS to original values.
612dd9f8062SIngo Weinhold	CCFLAGS = $(oldCCFLAGS) ;
613dd9f8062SIngo Weinhold	C++FLAGS = $(oldC++FLAGS) ;
6149342c27aSIngo Weinhold}
6159342c27aSIngo Weinhold
6169342c27aSIngo Weinholdrule TestObjects
6179342c27aSIngo Weinhold{
6189342c27aSIngo Weinhold	# TestLib <sources> : <public headers> : <r5>
6199342c27aSIngo Weinhold	# Compiles objects for tests.
6209342c27aSIngo Weinhold	# <sources> The list of sources.
6219342c27aSIngo Weinhold	# <public headers> A list of public header dirs (as passed to
6229342c27aSIngo Weinhold	# UsePublicHeaders).
6239342c27aSIngo Weinhold	# <r5> If set, "_r5" is appended to the object file names and
6249342c27aSIngo Weinhold	# <public headers> is ignored. Furthermore the pre-processor macro
6259342c27aSIngo Weinhold	# TEST_R5 is defined, TEST_OBOS otherwise.
6269342c27aSIngo Weinhold
6279342c27aSIngo Weinhold	local sources = $(1) ;
6289342c27aSIngo Weinhold	local headerDirs = $(2) ;
6299342c27aSIngo Weinhold	local r5 = $(3) ;
6309342c27aSIngo Weinhold	local objects ;
6319342c27aSIngo Weinhold
6329342c27aSIngo Weinhold	# Turn optimization off.
63396d27465SIngo Weinhold	if ! $(NO_TEST_DEBUG) {
6349342c27aSIngo Weinhold		local optim = $(OPTIM) ;
6359342c27aSIngo Weinhold		OPTIM = ;
63696d27465SIngo Weinhold	}
6379342c27aSIngo Weinhold
6389342c27aSIngo Weinhold	SetupObjectsDir ;
6399342c27aSIngo Weinhold
6409342c27aSIngo Weinhold	# compile
6419342c27aSIngo Weinhold	if $(r5) {
642dd9f8062SIngo Weinhold		SetupR5Includes ;
6439342c27aSIngo Weinhold		objects = [ R5ObjectNames $(sources) ] ;
6449342c27aSIngo Weinhold		R5Objects $(sources) ;
6459342c27aSIngo Weinhold	} else {
646dd9f8062SIngo Weinhold		SetupIncludes ;
6479342c27aSIngo Weinhold		objects = [ FGristFiles $(sources:S=$(SUFOBJ)) ] ;
6489342c27aSIngo Weinhold		Objects $(sources) ;
6499342c27aSIngo Weinhold	}
6509342c27aSIngo Weinhold
6519342c27aSIngo Weinhold	# set headers/defines
6529b60a208SIngo Weinhold	UseCppUnitObjectHeaders $(sources) : $(objects) ;
6539342c27aSIngo Weinhold	if $(r5) {
654728b5725SIngo Weinhold		ObjectsDefines $(objects) : TEST_R5 ;
6559342c27aSIngo Weinhold	} else {
6569b60a208SIngo Weinhold		UsePublicObjectHeaders $(sources) : $(headerDirs) : $(objects) ;
657728b5725SIngo Weinhold		ObjectsDefines $(objects) : TEST_OBOS ;
6589342c27aSIngo Weinhold	}
6599342c27aSIngo Weinhold
66096d27465SIngo Weinhold	if ! $(NO_TEST_DEBUG) {
6619342c27aSIngo Weinhold		# Turn debugging on. That is usually desired for test code.
6629342c27aSIngo Weinhold		ObjectCcFlags $(objects) : "-g" ;
6639342c27aSIngo Weinhold		ObjectC++Flags $(objects) : "-g" ;
6649342c27aSIngo Weinhold
6659342c27aSIngo Weinhold		# Turn optimization on again.
6669342c27aSIngo Weinhold		OPTIM = $(optim) ;
6679342c27aSIngo Weinhold	}
66896d27465SIngo Weinhold}
6699342c27aSIngo Weinhold
6709285de51STyler Dauwalderrule R5SharedLibraryNames
6719285de51STyler Dauwalder{
6729285de51STyler Dauwalder	# R5SharedLibraryNames <sources> ;
6739285de51STyler Dauwalder	# Returns a list of shared library names given a list of file names. NO
6749285de51STyler Dauwalder	# GRISTING IS PERFORMED :-) However, each library names gets "_r5" inserted
6759285de51STyler Dauwalder	# before the shared lib suffix.
6769285de51STyler Dauwalder	return $(1:S=)_r5.so ;
6779285de51STyler Dauwalder}
6789285de51STyler Dauwalder
6799fc6b2e1SIngo Weinholdrule SimpleTest
6809fc6b2e1SIngo Weinhold{
6819fc6b2e1SIngo Weinhold	# UnitTest <target> : <sources> : <libraries>
6829fc6b2e1SIngo Weinhold	# Builds a unit test for an OBOS module.
6839fc6b2e1SIngo Weinhold	# <target> The name of the target.
6849fc6b2e1SIngo Weinhold	# <sources> The list of sources.
6859fc6b2e1SIngo Weinhold	# <dest> The directory for the target (as passed to FDirName).
6869fc6b2e1SIngo Weinhold	# <libraries> A list of link libraries (as passed to LinkSharedOSLibs).
6879fc6b2e1SIngo Weinhold	# <public headers> A list of public header dirs (as passed to
6889fc6b2e1SIngo Weinhold	# UsePublicHeaders).
6899fc6b2e1SIngo Weinhold
6909fc6b2e1SIngo Weinhold	local target = $(1) ;
6919fc6b2e1SIngo Weinhold	local sources = $(2) ;
6929fc6b2e1SIngo Weinhold	local libraries = $(3) ;
6939fc6b2e1SIngo Weinhold	local relPath = [ FRelPath src tests : $(SUBDIR_TOKENS) ] ;
6949fc6b2e1SIngo Weinhold
6959fc6b2e1SIngo Weinhold	# Turn optimization off.
69696d27465SIngo Weinhold	if ! $(NO_TEST_DEBUG) {
6979fc6b2e1SIngo Weinhold		local optim = $(OPTIM) ;
6989fc6b2e1SIngo Weinhold		OPTIM = ;
69996d27465SIngo Weinhold	}
7009fc6b2e1SIngo Weinhold
701a6c008e1Sbeveloper	SetupIncludes ;
7029fc6b2e1SIngo Weinhold	SetupObjectsDir ;
7039fc6b2e1SIngo Weinhold	MakeLocateObjects $(sources) ;
7049fc6b2e1SIngo Weinhold	Main $(target) : $(sources) ;
7059fc6b2e1SIngo Weinhold	MakeLocate $(target) : [ FDirName $(OBOS_TEST_DIR) $(relPath) ] ;
7069eea4522SIngo Weinhold	Depends obostests : $(target) ;
7079fc6b2e1SIngo Weinhold	LinkSharedOSLibs $(target) : $(libraries) ;
708728b5725SIngo Weinhold	ObjectsDefines $(sources) : TEST_OBOS ;
70996d27465SIngo Weinhold	if ! $(NO_TEST_DEBUG) {
7109fc6b2e1SIngo Weinhold		# Turn debugging on. That is usually desired for test code.
7119fc6b2e1SIngo Weinhold		ObjectCcFlags $(sources) : "-g" ;
7129fc6b2e1SIngo Weinhold		ObjectC++Flags $(sources) : "-g" ;
7139fc6b2e1SIngo Weinhold
7149fc6b2e1SIngo Weinhold		# Turn optimization on again.
7159fc6b2e1SIngo Weinhold		OPTIM = $(optim) ;
7169fc6b2e1SIngo Weinhold	}
71796d27465SIngo Weinhold}
7189fc6b2e1SIngo Weinhold
71952a38012Sejakowatzrule Addon
72052a38012Sejakowatz{
72183b3b0dfSIngo Weinhold	# Addon <name> : <relpath> : <sources> : <is executable> : <libraries> ;
7227a384fdeSIngo Weinhold	# <name>: Name of the add-on.
7237a384fdeSIngo Weinhold	# <relpath>: Path where the add-on shall live relative to the add-on dir.
7247a384fdeSIngo Weinhold	# <sources>: Source files.
72583b3b0dfSIngo Weinhold	# <is executable>: true, if the target shall be executable as well.
72683b3b0dfSIngo Weinhold	# <libraries>: Libraries to be linked against.
7277a384fdeSIngo Weinhold
7287a384fdeSIngo Weinhold	local isExecutable = $(4) ;
72952a38012Sejakowatz
730a6c008e1Sbeveloper	SetupIncludes ;
73152a38012Sejakowatz	SetupObjectsDir ;
73252a38012Sejakowatz	Main $(1) : $(3) ;
73352a38012Sejakowatz
73452a38012Sejakowatz	# Create output dir path for addon
73552a38012Sejakowatz	local targetdir;
73652a38012Sejakowatz	targetdir = [ FDirName $(OBOS_ADDON_DIR) $(2) ] ;
73752a38012Sejakowatz
73852a38012Sejakowatz	MakeLocate $(1) : $(targetdir) ;
7397a384fdeSIngo Weinhold
7407a384fdeSIngo Weinhold	local linkFlags = -Xlinker -soname=\"$(1)\" ;
7417a384fdeSIngo Weinhold	if $(isExecutable) != true {
7427a384fdeSIngo Weinhold		linkFlags = -nostart $(linkFlags) ;
7437a384fdeSIngo Weinhold	}
7447a384fdeSIngo Weinhold	LINKFLAGS on $(1) = [ on $(1) return $(LINKFLAGS) ] $(linkFlags) ;
74583b3b0dfSIngo Weinhold	LinkSharedOSLibs $(1) : $(5) ;
746af28904fSIngo Weinhold}
747af28904fSIngo Weinhold
74858efc9d8SIngo Weinholdrule R5KernelAddon
749af28904fSIngo Weinhold{
750600203b1SAxel Dörfler	# R5KernelAddon <name> : <relpath> : <sources> : <static-libraries> ;
751af28904fSIngo Weinhold
752af28904fSIngo Weinhold	local sources = $(3) ;
753af28904fSIngo Weinhold
754af28904fSIngo Weinhold	Addon $(1) : $(2) : $(3) ;
755af28904fSIngo Weinhold	ObjectCcFlags $(sources) : -D_KERNEL_MODE=1 -no-fpic ;
756af28904fSIngo Weinhold	ObjectC++Flags $(sources) : -D_KERNEL_MODE=1 -no-fpic
757af28904fSIngo Weinhold								-fno-exceptions -fno-rtti ;
7589eea4522SIngo Weinhold	LINKFLAGS on $(1) = [ on $(1) return $(LINKFLAGS) ] -nostdlib ;
759600203b1SAxel Dörfler	LinkSharedOSLibs $(1) : $(4) /boot/develop/lib/x86/_KERNEL_ ;
76052a38012Sejakowatz}
76152a38012Sejakowatz
7624fb5add0SMatthew Wilberrule Translator
7634fb5add0SMatthew Wilber{
764007eb5f2SIngo Weinhold	# Translator <name> : <sources> : <libraries> ;
765a6c008e1Sbeveloper	SetupIncludes ;
7664fb5add0SMatthew Wilber	SetupObjectsDir ;
7674fb5add0SMatthew Wilber	Main $(1) : $(2) ;
768007eb5f2SIngo Weinhold	LinkSharedOSLibs $(1) : $(3) ;
7694fb5add0SMatthew Wilber
7704fb5add0SMatthew Wilber	# Create output dir path for translator
7714fb5add0SMatthew Wilber	local targetdir;
772d5b07cf2Sshatty	targetdir = [ FDirName $(OBOS_ADDON_DIR) Translators ] ;
7734fb5add0SMatthew Wilber	MakeLocate $(1) : $(targetdir) ;
7744fb5add0SMatthew Wilber}
7754fb5add0SMatthew Wilber
77652a38012Sejakowatzrule MakeLocateObjects
77752a38012Sejakowatz{
77821df5945SIngo Weinhold	# MakeLocateObjects <sources_or_objects> ;
77952a38012Sejakowatz
78021df5945SIngo Weinhold	local _objs = [ FGristFiles $(1:S=$(SUFOBJ)) ] ;
78152a38012Sejakowatz
78252a38012Sejakowatz	for o in $(_objs)
78352a38012Sejakowatz	{
78452a38012Sejakowatz		local dir = $(o:D) ;
78552a38012Sejakowatz		if $(dir) {
78652a38012Sejakowatz			MakeLocate $(o) : [ FDirName $(LOCATE_TARGET) $(dir) ] ;
78752a38012Sejakowatz		} else {
78852a38012Sejakowatz			MakeLocate $(o) : $(LOCATE_TARGET) ;
78952a38012Sejakowatz		}
79052a38012Sejakowatz	}
79152a38012Sejakowatz}
79252a38012Sejakowatz
79352a38012Sejakowatzrule StaticLibrary
79452a38012Sejakowatz{
795e9230d05SIngo Weinhold	# StaticLibrary <name> : <sources> [ : <target dir> ] ;
796e9230d05SIngo Weinhold	# Creates a static library from sources.
797e9230d05SIngo Weinhold	# <name>: Basename of the library, without leading "lib" and trailing ".a".
79860c9c40fSIngo Weinhold	#         Grist is allowed -- it will be re-prepended after constructing
79960c9c40fSIngo Weinhold	#         the complete library name.
800e9230d05SIngo Weinhold	# <source>: List of source files.
801e9230d05SIngo Weinhold	# <target dir>: Directory into which the library shall be placed. Defaults
80260c9c40fSIngo Weinhold	#               to the objects directory for this subdir. If
80360c9c40fSIngo Weinhold	#               STATIC_LIBRARY_DIR is supplied (the literal string)
80460c9c40fSIngo Weinhold	#               the standard directory for static libs is used, otherwise
80560c9c40fSIngo Weinhold	#               the parameter is interpreted as directory path.
806e9230d05SIngo Weinhold	#
80760c9c40fSIngo Weinhold	local lib = lib$(1:B)$(SUFLIB) ;
80860c9c40fSIngo Weinhold	lib = $(lib:G=$(1:G)) ;
809a6c008e1Sbeveloper	SetupIncludes ;
81052a38012Sejakowatz	SetupObjectsDir ;
81152a38012Sejakowatz	MakeLocateObjects $(2) ;
812e9230d05SIngo Weinhold	Library $(lib) : $(2) ;
813e9230d05SIngo Weinhold	local targetDir = $(3) ;
81460c9c40fSIngo Weinhold	if $(targetDir) {
81560c9c40fSIngo Weinhold		if $(targetDir) = STATIC_LIBRARY_DIR {
816e9230d05SIngo Weinhold			targetDir = $(OBOS_STLIB_DIR) ;
817e9230d05SIngo Weinhold		}
818e9230d05SIngo Weinhold		MakeLocate $(lib) : $(targetDir) ;
81960c9c40fSIngo Weinhold	} else {
82060c9c40fSIngo Weinhold		# nothing to do, since the Library rule already located the library
82160c9c40fSIngo Weinhold		# in $(LOCATE_TARGET)
82260c9c40fSIngo Weinhold	}
823f1e077f8SIngo Weinhold
824f1e077f8SIngo Weinhold	# If KEEPOBJS is set, Library doesn't make the library depend on
825f1e077f8SIngo Weinhold	# `lib'.
826f1e077f8SIngo Weinhold	if $(KEEPOBJS) {
827f1e077f8SIngo Weinhold		LocalDepends lib : $(lib) ;
828f1e077f8SIngo Weinhold	}
82952a38012Sejakowatz}
83052a38012Sejakowatz
831dbf96817SIngo Weinholdrule R5KernelStaticLibrary
832dbf96817SIngo Weinhold{
833dbf96817SIngo Weinhold	# R5KernelStaticLibrary <name> : <sources> ;
834dbf96817SIngo Weinhold
835f1e077f8SIngo Weinhold	local lib = lib$(1)$(SUFLIB) ;
836dbf96817SIngo Weinhold	local sources = $(2) ;
837dbf96817SIngo Weinhold
838dbf96817SIngo Weinhold	SetupIncludes ;
839dbf96817SIngo Weinhold	SetupObjectsDir ;
840dbf96817SIngo Weinhold	MakeLocateObjects $(sources) ;
841dbf96817SIngo Weinhold	Library $(lib) : $(sources) ;
842dbf96817SIngo Weinhold	ObjectCcFlags $(sources) : -D_KERNEL_MODE=1 -no-fpic ;
843dbf96817SIngo Weinhold	ObjectC++Flags $(sources) : -D_KERNEL_MODE=1 -no-fpic
844dbf96817SIngo Weinhold								-fno-exceptions -fno-rtti ;
845dbf96817SIngo Weinhold}
846dbf96817SIngo Weinhold
84780721244SAxel Dörflerrule MergeObjectFromObjects
84880721244SAxel Dörfler{
8492fbd7065SIngo Weinhold	# MergeObjectFromObjects <name> : <objects> : <other objects> ;
8502fbd7065SIngo Weinhold	# Merges object files to an object file.
8512fbd7065SIngo Weinhold	# <name>: Name of the object file to create. No grist will be added.
8522fbd7065SIngo Weinhold	# <objects>: Object files to be merged. Grist will be added.
8532fbd7065SIngo Weinhold	# <other objects>: Object files or static libraries to be merged. No grist
8542fbd7065SIngo Weinhold	#                  will be added.
8552fbd7065SIngo Weinhold	#
856c8aa252aSIngo Weinhold	local objects = [ FGristFiles $(2) ] ;
85780721244SAxel Dörfler	MakeLocate $(1) : $(LOCATE_TARGET) ;
858c8aa252aSIngo Weinhold	Depends $(1) : $(objects) ;
8592fbd7065SIngo Weinhold	Depends $(1) : $(3) ;
86080721244SAxel Dörfler	LINK on $(1) = ld ;
8612fbd7065SIngo Weinhold	MergeObjectFromObjects1 $(1) : $(objects) $(3) ;
86280721244SAxel Dörfler}
86380721244SAxel Dörfler
86454b7cbe1SIngo Weinholdactions MergeObjectFromObjects1
86580721244SAxel Dörfler{
86680721244SAxel Dörfler	$(LINK) -r $(2) -o $(1) ;
86780721244SAxel Dörfler}
86880721244SAxel Dörfler
86980721244SAxel Dörflerrule MergeObject
87080721244SAxel Dörfler{
8712fbd7065SIngo Weinhold	# MergeObject <name> : <sources> : <other objects> ;
8722fbd7065SIngo Weinhold	# Compiles source files and merges the object files to an object file.
8732fbd7065SIngo Weinhold	# <name>: Name of the object file to create. No grist will be added.
8742fbd7065SIngo Weinhold	# <sources>: Sources to be compiled. Grist will be added.
8752fbd7065SIngo Weinhold	# <other objects>: Object files or static libraries to be merged. No grist
8762fbd7065SIngo Weinhold	#                  will be added.
8772fbd7065SIngo Weinhold	#
87880721244SAxel Dörfler	SetupIncludes ;
87980721244SAxel Dörfler	SetupObjectsDir ;
88080721244SAxel Dörfler	MakeLocateObjects $(2) ;
88180721244SAxel Dörfler	Objects $(2) ;
8822fbd7065SIngo Weinhold	MergeObjectFromObjects $(1) : $(2:S=$(SUFOBJ)) : $(3) ;
88380721244SAxel Dörfler}
88480721244SAxel Dörfler
88521df5945SIngo Weinholdrule SharedLibraryFromObjects
88652a38012Sejakowatz{
8878d3308d9SIngo Weinhold	# SharedLibraryFromObjects <name> : <objects> : <libraries> ;
88860c9c40fSIngo Weinhold	local _lib = lib$(1:B).so ;
88960c9c40fSIngo Weinhold	_lib = $(_lib:G=$(1:G)) ;
89021df5945SIngo Weinhold	MainFromObjects $(_lib) : $(2) ;
89152a38012Sejakowatz	MakeLocate $(_lib) : $(OBOS_SHLIB_DIR) ;
8929eea4522SIngo Weinhold	LINKFLAGS on $(_lib) = [ on $(_lib) return $(LINKFLAGS) ]
8939eea4522SIngo Weinhold						   -nostart -Xlinker -soname=\"$(_lib)\" ;
8948d3308d9SIngo Weinhold	LinkSharedOSLibs $(_lib) : $(3) ;
89552a38012Sejakowatz}
89652a38012Sejakowatz
89721df5945SIngo Weinholdrule SharedLibrary
89821df5945SIngo Weinhold{
8998d3308d9SIngo Weinhold	# SharedLibrary <name> : <sources> : <libraries> ;
900a6c008e1Sbeveloper	SetupIncludes ;
90121df5945SIngo Weinhold	SetupObjectsDir ;
90221df5945SIngo Weinhold	MakeLocateObjects $(2) ;
90321df5945SIngo Weinhold	Objects $(2) ;
9048d3308d9SIngo Weinhold	SharedLibraryFromObjects $(1) : $(2:S=$(SUFOBJ)) : $(3) ;
90521df5945SIngo Weinhold}
90621df5945SIngo Weinhold
90752a38012Sejakowatzrule LinkSharedOSLibs
90852a38012Sejakowatz{
90952a38012Sejakowatz	# LinkSharedOSLibs <name> : <libs> ;
91052a38012Sejakowatz	# Valid elements for <libs> are e.g. "be" or "libopenbeos.so" or
9114236d490SIngo Weinhold	# "/boot/.../libfoo.so". If the basename starts with "lib" or the thingy
9124236d490SIngo Weinhold	# has a dirname or grist, it is added to the NEEDLIBS variable (i.e. the
9134236d490SIngo Weinhold	# file will be bound!), otherwise it is prefixed "-l" and added to
914a8cd0719SIngo Weinhold	# LINKLIBS. If you want to specify a target that isn't a library and
915a8cd0719SIngo Weinhold	# also has neither grist nor a dirname, you can prepend "<nogrist>" as
916a8cd0719SIngo Weinhold	# grist; it will be stripped by this rule.
91752a38012Sejakowatz
91852a38012Sejakowatz	for i in $(>)
91952a38012Sejakowatz	{
9204236d490SIngo Weinhold		local isfile = ;
9214236d490SIngo Weinhold		if $(i:D) || $(i:G) {
9224236d490SIngo Weinhold			isfile = true ;
923a8cd0719SIngo Weinhold			if $(i:G) = <nogrist> {
924a8cd0719SIngo Weinhold				i = $(i:G=) ;
925a8cd0719SIngo Weinhold			}
9264236d490SIngo Weinhold		} else {
92752a38012Sejakowatz			switch $(i:B)
92852a38012Sejakowatz			{
929007eb5f2SIngo Weinhold				# XXX: _APP_ and _KERNEL_ should not be needed for ELF.
930f7901247SPhilippe Houdoin				case _APP_ : isfile = true ;
931f7901247SPhilippe Houdoin				case _KERNEL_ : isfile = true ;
9324236d490SIngo Weinhold				case lib*	: isfile = true ;
9334236d490SIngo Weinhold				case *	: isfile = ;
9344236d490SIngo Weinhold			}
935b8baf385SIngo Weinhold			if ! $(isfile) && ( $(i:S) = .so || $(i:S) = .a ) {
936b8baf385SIngo Weinhold				isfile = true ;
937b8baf385SIngo Weinhold			}
9384236d490SIngo Weinhold		}
9394236d490SIngo Weinhold		if $(isfile) {
9409eea4522SIngo Weinhold			NEEDLIBS on $(1) = [ on $(1) return $(NEEDLIBS) ] $(i) ;
9419eea4522SIngo Weinhold			Depends $(1) : $(i) ;
9424236d490SIngo Weinhold		} else {
9439eea4522SIngo Weinhold			LINKLIBS on $(1) = [ on $(1) return $(LINKLIBS) ] -l$(i) ;
94452a38012Sejakowatz		}
94552a38012Sejakowatz	}
94652a38012Sejakowatz}
94752a38012Sejakowatz
94852a38012Sejakowatzrule LinkStaticOSLibs
94952a38012Sejakowatz{
95052a38012Sejakowatz	# LinkStaticOSLibs <name> : <libs> ;
95152a38012Sejakowatz
95252a38012Sejakowatz	for i in $(>)
95352a38012Sejakowatz	{
95452a38012Sejakowatz		LINKLIBS on $(<) = $(LINKLIBS) -l $(i) ;
95552a38012Sejakowatz	}
95652a38012Sejakowatz}
95752a38012Sejakowatz
95852a38012Sejakowatzrule AddResources
95952a38012Sejakowatz{
96052a38012Sejakowatz	# AddResources <name> : <resourcefiles> ;
96152a38012Sejakowatz
9628d3308d9SIngo Weinhold	local resfiles = [ FGristFiles $(2) ] ;
9638d3308d9SIngo Weinhold	SEARCH on $(resfiles) += $(SEARCH_SOURCE) ;
9648d3308d9SIngo Weinhold
9658d3308d9SIngo Weinhold	for file in $(resfiles) {
9668d3308d9SIngo Weinhold		if $(file:S) = .rdef {
9678d3308d9SIngo Weinhold			local rdef = $(file) ;
9688d3308d9SIngo Weinhold			file = $(rdef:S=.rsrc) ;
9698d3308d9SIngo Weinhold			ResComp $(file) : $(rdef) ;
9708d3308d9SIngo Weinhold		}
9718d3308d9SIngo Weinhold		RESFILES on $(1) += $(file) ;
9728d3308d9SIngo Weinhold	}
9738d3308d9SIngo Weinhold}
9748d3308d9SIngo Weinhold
9758d3308d9SIngo Weinholdrule ResComp
9768d3308d9SIngo Weinhold{
9778d3308d9SIngo Weinhold	# ResComp <resource file> : <rdef file> ;
9788d3308d9SIngo Weinhold	#
9798d3308d9SIngo Weinhold	# <resource file> and <rdef file> must be gristed.
9808d3308d9SIngo Weinhold
9818d3308d9SIngo Weinhold	SetupObjectsDir ;
9828d3308d9SIngo Weinhold
9839fc6b2e1SIngo Weinhold	SEARCH on $(2) += $(SEARCH_SOURCE) ;
9848d3308d9SIngo Weinhold	MakeLocate $(1) : $(LOCATE_TARGET) ;
9858d3308d9SIngo Weinhold	Depends $(1) : $(2) rc ;
9868d3308d9SIngo Weinhold	LocalClean clean : $(1) ;
9878d3308d9SIngo Weinhold	ResComp1 $(1) : rc $(2) ;
9888d3308d9SIngo Weinhold}
9898d3308d9SIngo Weinhold
9908d3308d9SIngo Weinholdactions ResComp1
9918d3308d9SIngo Weinhold{
9926af76074SIngo Weinhold	$(2[1]) -o $(1) $(2[2-])
99352a38012Sejakowatz}
99452a38012Sejakowatz
995728b5725SIngo Weinholdrule ObjectsDefines
996728b5725SIngo Weinhold{
997728b5725SIngo Weinhold	# Like ObjectDefines, but allows multiple files to be supplied
998728b5725SIngo Weinhold	local file ;
999728b5725SIngo Weinhold	for file in $(1) {
1000728b5725SIngo Weinhold		ObjectDefines $(file) : $(2) ;
1001728b5725SIngo Weinhold	}
1002728b5725SIngo Weinhold}
1003728b5725SIngo Weinhold
10049b60a208SIngo Weinholdrule SourceHdrs
10059b60a208SIngo Weinhold{
10069b60a208SIngo Weinhold	# SourceHdrs <sources> : <headers> [ : <gristed objects> ] ;
10079b60a208SIngo Weinhold	#
10089b60a208SIngo Weinhold	# Is a wrapper for ObjectHdrs, that passes <sources> and <headers> or,
10099b60a208SIngo Weinhold	# if supplied <objects> and <headers>, and also adjusts HDRSEARCH (not
10109b60a208SIngo Weinhold	# done by ObjectHdrs).
10119b60a208SIngo Weinhold
10129b60a208SIngo Weinhold	local sources = [ FGristFiles $(1) ] ;
10139b60a208SIngo Weinhold	local headers = $(2) ;
10149b60a208SIngo Weinhold	local objects = $(3) ;
10159b60a208SIngo Weinhold
1016728b5725SIngo Weinhold	local file ;
10179b60a208SIngo Weinhold	if $(objects) {
1018728b5725SIngo Weinhold		for file in $(objects) {
1019728b5725SIngo Weinhold			ObjectHdrs $(file) : $(headers) ;
1020728b5725SIngo Weinhold		}
10219b60a208SIngo Weinhold	} else {
1022728b5725SIngo Weinhold		for file in $(sources) {
1023728b5725SIngo Weinhold			ObjectHdrs $(file) : $(headers) ;
1024728b5725SIngo Weinhold		}
10259b60a208SIngo Weinhold	}
10269b60a208SIngo Weinhold
10279b60a208SIngo Weinhold	# Also add the header search dirs to HDRSEARCH. Note, that these dirs
10289b60a208SIngo Weinhold	# will be listed after the STDHDRS (if any), but that's better than not
10299b60a208SIngo Weinhold	# being listed at all.
10309b60a208SIngo Weinhold	HDRSEARCH on $(sources) += $(headers) ;
10319b60a208SIngo Weinhold}
10329b60a208SIngo Weinhold
10337d7f280eSIngo Weinholdrule PublicHeaders
103452a38012Sejakowatz{
10357d7f280eSIngo Weinhold	# PublicHeaders <group list>
103652a38012Sejakowatz	#
10377d7f280eSIngo Weinhold	# Returns the directory names for the public header dirs identified by
10387d7f280eSIngo Weinhold	# <group list>.
103952a38012Sejakowatz
104052a38012Sejakowatz	local list = $(1) ;
1041b005dbe3SAxel Dörfler	local dirs = [ FDirName $(OBOS_TOP) headers os ] ;
1042b005dbe3SAxel Dörfler
104352a38012Sejakowatz	for i in $(list) {
10447d7f280eSIngo Weinhold		dirs += [ FDirName $(OBOS_TOP) headers os $(i) ] ;
10457d7f280eSIngo Weinhold	}
10467d7f280eSIngo Weinhold	return $(dirs) ;
104752a38012Sejakowatz}
104852a38012Sejakowatz
10497d7f280eSIngo Weinholdrule PrivateHeaders
10507d7f280eSIngo Weinhold{
10517d7f280eSIngo Weinhold	# PrivateHeaders <group list>
10527d7f280eSIngo Weinhold	#
10537d7f280eSIngo Weinhold	# Returns the directory names for the private header dirs identified by
10547d7f280eSIngo Weinhold	# <group list>.
10557d7f280eSIngo Weinhold
10567d7f280eSIngo Weinhold	local list = $(1) ;
10577d7f280eSIngo Weinhold	local dirs ;
10587d7f280eSIngo Weinhold	for i in $(list) {
10597d7f280eSIngo Weinhold		dirs += [ FDirName $(OBOS_TOP) headers private $(i) ] ;
10607d7f280eSIngo Weinhold	}
10617d7f280eSIngo Weinhold	return $(dirs) ;
10627d7f280eSIngo Weinhold}
10637d7f280eSIngo Weinhold
10640f434a0aSDarkWyrmrule LibraryHeaders
10650f434a0aSDarkWyrm{
10660f434a0aSDarkWyrm	# LibraryHeaders <group list>
10670f434a0aSDarkWyrm	#
10680f434a0aSDarkWyrm	# Returns the directory names for the library header dirs identified by
10690f434a0aSDarkWyrm	# <group list>.
10700f434a0aSDarkWyrm
10710f434a0aSDarkWyrm	local list = $(1) ;
10720f434a0aSDarkWyrm	local dirs ;
10730f434a0aSDarkWyrm	for i in $(list) {
10740f434a0aSDarkWyrm		dirs += [ FDirName $(OBOS_TOP) headers libs $(i) ] ;
10750f434a0aSDarkWyrm	}
10760f434a0aSDarkWyrm	return $(dirs) ;
10770f434a0aSDarkWyrm}
10780f434a0aSDarkWyrm
10797d7f280eSIngo Weinholdrule ArchHeaders
10807d7f280eSIngo Weinhold{
10817d7f280eSIngo Weinhold	# usage: ArchHeaders <arch> ;
10827d7f280eSIngo Weinhold	#
10837d7f280eSIngo Weinhold	# <arch> specifies the architecture (e.g. x86).
10847d7f280eSIngo Weinhold
10857d7f280eSIngo Weinhold	return [ FDirName $(OBOS_TOP) headers private kernel arch $(1) ] ;
10867d7f280eSIngo Weinhold}
10877d7f280eSIngo Weinhold
10887d7f280eSIngo Weinholdrule UsePublicHeaders
10897d7f280eSIngo Weinhold{
1090966528dcSIngo Weinhold	# UsePublicHeaders <group list> ;
1091966528dcSIngo Weinhold	#
1092966528dcSIngo Weinhold	# Adds the public C header dirs given by <group list> to the header search
1093966528dcSIngo Weinhold	# dirs of the subdirectory.
1094966528dcSIngo Weinhold	# NOTE: This rule must be invoked *before* the rule that builds the
1095966528dcSIngo Weinhold	# objects.
1096966528dcSIngo Weinhold
1097966528dcSIngo Weinhold	UseHeaders [ PublicHeaders $(1) ] ;
10987d7f280eSIngo Weinhold}
10997d7f280eSIngo Weinhold
11007d7f280eSIngo Weinholdrule UsePublicObjectHeaders
11017d7f280eSIngo Weinhold{
11029b60a208SIngo Weinhold	# UsePublicObjectHeaders <sources> : <group list> [ : <objects> ] ;
11037d7f280eSIngo Weinhold	#
11047d7f280eSIngo Weinhold	# Adds the public C header dirs given by <group list> to the header search
11059b60a208SIngo Weinhold	# dirs of either the object targets of <sources> or if supplied to
11069b60a208SIngo Weinhold	# <objects>. Also adjusts HDRSEARCH of <sources>.
11077d7f280eSIngo Weinhold	# NOTE: This rule must be invoked *after* the rule that builds the objects.
11087d7f280eSIngo Weinhold
11099b60a208SIngo Weinhold	SourceHdrs $(1) : [ PublicHeaders $(2) ] : $(3) ;
111052a38012Sejakowatz}
111152a38012Sejakowatz
111252a38012Sejakowatzrule UsePrivateHeaders
111352a38012Sejakowatz{
11147d7f280eSIngo Weinhold	# UsePrivateHeaders <group list> ;
111552a38012Sejakowatz	#
111652a38012Sejakowatz	# Adds the private C header dirs given by <group list> to the header search
11177d7f280eSIngo Weinhold	# dirs of the subdirectory.
11187d7f280eSIngo Weinhold	# NOTE: This rule must be invoked *before* the rule that builds the objects.
111952a38012Sejakowatz
11207d7f280eSIngo Weinhold	UseHeaders [ PrivateHeaders $(1) ] ;
112152a38012Sejakowatz}
112252a38012Sejakowatz
11237d7f280eSIngo Weinholdrule UsePrivateObjectHeaders
11247d7f280eSIngo Weinhold{
11259b60a208SIngo Weinhold	# UsePrivateObjectHeaders <sources> : <group list> [ : <objects> ] ;
11267d7f280eSIngo Weinhold	#
11277d7f280eSIngo Weinhold	# Adds the private C header dirs given by <group list> to the header search
11289b60a208SIngo Weinhold	# dirs of either the object targets of <sources> or if supplied to
11299b60a208SIngo Weinhold	# <objects>. Also adjusts HDRSEARCH of <sources>.
11307d7f280eSIngo Weinhold	# NOTE: This rule must be invoked *after* the rule that builds the objects.
11317d7f280eSIngo Weinhold
11329b60a208SIngo Weinhold	SourceHdrs $(1) : [ PrivateHeaders $(2) ] : $(3) ;
113352a38012Sejakowatz}
113452a38012Sejakowatz
113552a38012Sejakowatzrule UseHeaders
113652a38012Sejakowatz{
11377d7f280eSIngo Weinhold	# UseHeaders <headers> ;
113852a38012Sejakowatz	#
113952a38012Sejakowatz	# Adds the C header dirs <headers> to the header search
11407d7f280eSIngo Weinhold	# dirs of the subdirectory.
11417d7f280eSIngo Weinhold	# NOTE: This rule must be invoked *before* the rule that builds the objects.
114252a38012Sejakowatz
11437d7f280eSIngo Weinhold	local header ;
11447d7f280eSIngo Weinhold	for header in $(1) {
114552a38012Sejakowatz		SubDirHdrs $(header) ;
114652a38012Sejakowatz	}
114752a38012Sejakowatz}
114852a38012Sejakowatz
114952a38012Sejakowatzrule UseCppUnitHeaders
115052a38012Sejakowatz{
11517d7f280eSIngo Weinhold	SubDirHdrs [ FDirName $(OBOS_TOP) headers tools cppunit ] ;
115252a38012Sejakowatz}
115352a38012Sejakowatz
1154be5af1baSIngo Weinholdrule UseCppUnitObjectHeaders
1155be5af1baSIngo Weinhold{
11569b60a208SIngo Weinhold	# UseCppUnitObjectHeaders <sources> [ : <objects> ] ;
11579b60a208SIngo Weinhold	SourceHdrs $(1) : [ FDirName $(OBOS_TOP) headers tools cppunit ] : $(2) ;
1158be5af1baSIngo Weinhold}
1159be5af1baSIngo Weinhold
116052a38012Sejakowatzrule UseArchHeaders
116152a38012Sejakowatz{
11627d7f280eSIngo Weinhold	# usage: UseArchHeaders <arch> ;
11637d7f280eSIngo Weinhold	#
116452a38012Sejakowatz	# <arch> specifies the architecture (e.g. x86).
11657d7f280eSIngo Weinhold	# NOTE: This rule must be invoked *before* the rule that builds the objects.
11667d7f280eSIngo Weinhold
11677d7f280eSIngo Weinhold	local headers = [ ArchHeaders $(1) ] ;
116852a38012Sejakowatz	local opt = -D$(OBOS_TARGET_DEFINE) ;
1169c633961aSIngo Weinhold
117052a38012Sejakowatz	SubDirCcFlags $(opt)  ;
117152a38012Sejakowatz	SubDirC++Flags $(opt)  ;
1172089a0629Sbeveloper	HDRS += $(headers) ;
1173c633961aSIngo Weinhold}
1174c633961aSIngo Weinhold
11757d7f280eSIngo Weinholdrule UseArchObjectHeaders
11767d7f280eSIngo Weinhold{
11779b60a208SIngo Weinhold	# usage: UseArchObjectHeaders <sources> : <arch> : [ <objects> ] ;
11787d7f280eSIngo Weinhold	#
11797d7f280eSIngo Weinhold	# <arch> specifies the architecture (e.g. x86).
11807d7f280eSIngo Weinhold	# <sources_or_objects> Source or object files.
11817d7f280eSIngo Weinhold	# NOTE: This rule must be invoked *after* the rule that builds the objects.
11827d7f280eSIngo Weinhold
11839b60a208SIngo Weinhold	local sources = $(1) ;
11847d7f280eSIngo Weinhold	local headers = [ ArchHeaders $(2) ] ;
11859b60a208SIngo Weinhold	local objects = $(3) ;
11869b60a208SIngo Weinhold	local targets ;
11879b60a208SIngo Weinhold	if $(objects) {
11889b60a208SIngo Weinhold		targets = $(objects) ;
11899b60a208SIngo Weinhold	} else {
11909b60a208SIngo Weinhold		targets = $(sources) ;
11919b60a208SIngo Weinhold	}
11927d7f280eSIngo Weinhold	local opt = -D$(OBOS_TARGET_DEFINE) ;
11937d7f280eSIngo Weinhold
11947d7f280eSIngo Weinhold	ObjectCcFlags $(targets) : $(opt)  ;
11957d7f280eSIngo Weinhold	ObjectC++Flags $(targets) : $(opt)  ;
11969b60a208SIngo Weinhold	SourceHdrs $(sources) : $(headers) : $(objects) ;
119752a38012Sejakowatz}
119852a38012Sejakowatz
1199d25a77b4SIngo Weinholdrule UsePosixHeaders
1200d25a77b4SIngo Weinhold{
1201a6c008e1Sbeveloper	# XXX changed to do nothing
1202d25a77b4SIngo Weinhold}
1203d25a77b4SIngo Weinhold
1204d25a77b4SIngo Weinholdrule UsePosixObjectHeaders
1205d25a77b4SIngo Weinhold{
12069b60a208SIngo Weinhold	# UsePosixObjectHeaders <sources> [ : <objects> ] ;
1207d25a77b4SIngo Weinhold	#
1208d25a77b4SIngo Weinhold	# Adds the POSIX header dir to the header search
12099b60a208SIngo Weinhold	# dirs of either the object targets of <sources> or if supplied to
12109b60a208SIngo Weinhold	# <objects>. Also adjusts HDRSEARCH of <sources>.
1211d25a77b4SIngo Weinhold	# NOTE: This rule must be invoked *after* the rule that builds the objects.
1212d25a77b4SIngo Weinhold
12139b60a208SIngo Weinhold	SourceHdrs $(1) : [ FDirName $(OBOS_TOP) headers posix ] : $(2) ;
1214d25a77b4SIngo Weinhold}
1215d25a77b4SIngo Weinhold
12160f434a0aSDarkWyrmrule UseLibraryHeaders
12170f434a0aSDarkWyrm{
12180f434a0aSDarkWyrm	# UseLibraryHeaders <group list> ;
12190f434a0aSDarkWyrm	#
12200f434a0aSDarkWyrm	# Adds the library header dirs given by <group list> to the header search
12210f434a0aSDarkWyrm	# dirs of the subdirectory.
12220f434a0aSDarkWyrm	# NOTE: This rule must be invoked *before* the rule that builds the objects.
12230f434a0aSDarkWyrm
12240f434a0aSDarkWyrm	UseHeaders [ LibraryHeaders $(1) ] ;
12250f434a0aSDarkWyrm}
12260f434a0aSDarkWyrm
12273b9eae39SIngo Weinholdrule SplitPath
12283b9eae39SIngo Weinhold{
12293b9eae39SIngo Weinhold	# SplitPath <path> ;
12303b9eae39SIngo Weinhold	# Decomposes a path into its components.
12313b9eae39SIngo Weinhold	local path = $(1:G=) ;
12323b9eae39SIngo Weinhold	local components ;
12338c27f58dSIngo Weinhold	# $(path:D) for "/" is "/". Therefore the second condition.
12348c27f58dSIngo Weinhold	while $(path:D) && $(path:D) != $(path)
12353b9eae39SIngo Weinhold	{
12363b9eae39SIngo Weinhold		# Note: $(path:B) returns "." for "..", but $(path:D=) is fine.
12373b9eae39SIngo Weinhold		components = $(path:D=) $(components) ;
12383b9eae39SIngo Weinhold		path = $(path:D) ;
12393b9eae39SIngo Weinhold	}
12403b9eae39SIngo Weinhold	components = $(path) $(components) ;
12413b9eae39SIngo Weinhold	return $(components) ;
12423b9eae39SIngo Weinhold}
12433b9eae39SIngo Weinhold
12449fc6b2e1SIngo Weinholdrule PrependObjectHdrs
12459fc6b2e1SIngo Weinhold{
12469fc6b2e1SIngo Weinhold	# PrependObjectHdrs <objects_or_sources> : <dirs> ;
12479fc6b2e1SIngo Weinhold	# Prepends <dirs> to the list of header search dirs of the objects
12489fc6b2e1SIngo Weinhold	# specified by <objects_or_sources>. The HDRS variable will not be
12499fc6b2e1SIngo Weinhold	# changed, only CCHDRS.
12509fc6b2e1SIngo Weinhold	# Note: A subsequent ObjectHdrs invocation will therefore undo the
12519fc6b2e1SIngo Weinhold	# effect of this rule.
12529fc6b2e1SIngo Weinhold	# NOTE: This is a hack.
12539fc6b2e1SIngo Weinhold
12549fc6b2e1SIngo Weinhold	local objects = [ FGristFiles $(1:S=$(SUFOBJ)) ] ;
12559fc6b2e1SIngo Weinhold	local dirs = $(2) ;
12569fc6b2e1SIngo Weinhold	for object in $(objects) {
12579fc6b2e1SIngo Weinhold		# Don't change HDRS to avoid screwing up the header scanning.
12589fc6b2e1SIngo Weinhold		PREPENDED_HDRS on $(object)
12599fc6b2e1SIngo Weinhold			= $(dirs) [ on $(object) return $(PREPENDED_HDRS) ] ;
12609fc6b2e1SIngo Weinhold		CCHDRS on $(object)
12619fc6b2e1SIngo Weinhold			= [ FIncludes [ on $(object) return $(PREPENDED_HDRS) $(HDRS) ] ] ;
12629fc6b2e1SIngo Weinhold	}
12639fc6b2e1SIngo Weinhold}
12649fc6b2e1SIngo Weinhold
12653b9eae39SIngo Weinholdrule SymLink
12663b9eae39SIngo Weinhold{
12677669b69fSIngo Weinhold	# SymLink <target> : <source> : <makeDefaultDependencies> ;
12683b9eae39SIngo Weinhold	# Links <target> to <source>.
12693b9eae39SIngo Weinhold	# <source> is the exact link contents. No binding is done.
12707669b69fSIngo Weinhold	# <makeDefaultDependencies> If true, <target> will be made a dependency
12717669b69fSIngo Weinhold	# of the `all' pseudo target, i.e. it will be made by default, and removed
12727669b69fSIngo Weinhold	# on `jam clean'.
12737669b69fSIngo Weinhold
12747669b69fSIngo Weinhold	local target = $(1) ;
12757669b69fSIngo Weinhold	local source = $(2) ;
12767669b69fSIngo Weinhold	local makeDefaultDependencies = $(3) ;
12777669b69fSIngo Weinhold	if ! $(makeDefaultDependencies) {
12787669b69fSIngo Weinhold		makeDefaultDependencies = true ;
12797669b69fSIngo Weinhold	}
12807669b69fSIngo Weinhold	LINKCONTENTS on $(target) = $(source) ;
12817669b69fSIngo Weinhold	SymLink1 $(target) ;
12827669b69fSIngo Weinhold	if $(makeDefaultDependencies) = true {
12837669b69fSIngo Weinhold		LocalDepends files : $(target) ;
12847669b69fSIngo Weinhold		LocalClean clean : $(target) ;
12857669b69fSIngo Weinhold	}
12863b9eae39SIngo Weinhold}
12873b9eae39SIngo Weinhold
12883b9eae39SIngo Weinholdactions SymLink1
12893b9eae39SIngo Weinhold{
12900931b8f9SIngo Weinhold	$(RM) "$(1)" && $(LN) -s "$(LINKCONTENTS)" "$(1)"
12910931b8f9SIngo Weinhold}
12920931b8f9SIngo Weinhold
12930931b8f9SIngo Weinholdrule RelSymLink
12940931b8f9SIngo Weinhold{
12957669b69fSIngo Weinhold	# RelSymLink <link> : <link target> : <makeDefaultDependencies> ;
12960931b8f9SIngo Weinhold	# Creates a relative symbolic link from <link> to <link target>.
12970931b8f9SIngo Weinhold	# <link> and <link target> can be usual targets. They may have a grist
12980931b8f9SIngo Weinhold	# and don't need to have any dirname. Their LOCATE variables are used to
12990931b8f9SIngo Weinhold	# find their locations.
13007669b69fSIngo Weinhold	# <makeDefaultDependencies> If true (which is the default), <link> will be
13017669b69fSIngo Weinhold	# made a dependency of the `files' pseudo target, i.e. it will be made by
13027669b69fSIngo Weinhold	# default, and removed on `jam clean'.
13030931b8f9SIngo Weinhold
13040931b8f9SIngo Weinhold	local target = $(1) ;
13050931b8f9SIngo Weinhold	local source = $(2) ;
13067669b69fSIngo Weinhold	local makeDefaultDependencies = $(3) ;
13070931b8f9SIngo Weinhold	local targetDir = [ on $(target) FDirName $(LOCATE[1]) $(target:D) ] ;
13080931b8f9SIngo Weinhold	local sourceDir = [ on $(source) FDirName $(LOCATE[1]) $(source:D) ] ;
13090931b8f9SIngo Weinhold	local sourcePath = $(source:G=) ;
13100931b8f9SIngo Weinhold	sourcePath = $(sourcePath:D=$(sourceDir)) ;
13110931b8f9SIngo Weinhold	local targetDirComponents = [ SplitPath $(targetDir) ] ;
13120931b8f9SIngo Weinhold	local sourceComponents = [ SplitPath $(sourcePath) ] ;
13130931b8f9SIngo Weinhold
13140931b8f9SIngo Weinhold	SymLink $(target)
13157669b69fSIngo Weinhold		: [ FRelPath $(targetDirComponents) : $(sourceComponents) ]
13167669b69fSIngo Weinhold		: $(makeDefaultDependencies) ;
13170931b8f9SIngo Weinhold	NOUPDATE $(target) ;
13189eea4522SIngo Weinhold	Depends $(target) : $(source) ;
13193b9eae39SIngo Weinhold}
13203b9eae39SIngo Weinhold
1321d391d2ebSIngo Weinholdrule AbsSymLink
1322d391d2ebSIngo Weinhold{
13237bc56df1SIngo Weinhold	# AbsSymLink <link> : <link target> : <link dir>
13247669b69fSIngo Weinhold	#			: <makeDefaultDependencies> ;
1325d391d2ebSIngo Weinhold	# Creates an absolute symbolic link from <link> to <link target>.
1326d391d2ebSIngo Weinhold	# <link> and <link target> must be usual targets. If <link dir> is
1327d391d2ebSIngo Weinhold	# given, then it is set as LOCATE directory on <link>.
13287669b69fSIngo Weinhold	# <makeDefaultDependencies> If true (which is the default), <link> will be
13297669b69fSIngo Weinhold	# made a dependency of the `files' pseudo target, i.e. it will be made by
13307669b69fSIngo Weinhold	# default, and removed on `jam clean'.
1331d391d2ebSIngo Weinhold
13327669b69fSIngo Weinhold	local makeDefaultDependencies = $(4) ;
13337669b69fSIngo Weinhold	if ! $(makeDefaultDependencies) {
13347669b69fSIngo Weinhold		makeDefaultDependencies = true ;
13357669b69fSIngo Weinhold	}
13367669b69fSIngo Weinhold
1337d391d2ebSIngo Weinhold	Depends $(1) : $(2) ;
1338d391d2ebSIngo Weinhold	if $(3) {
1339d391d2ebSIngo Weinhold		MakeLocate $(1) : $(3) ;
1340d391d2ebSIngo Weinhold	}
1341d391d2ebSIngo Weinhold	SEARCH on $(2) += $(SEARCH_SOURCE) ;
13427669b69fSIngo Weinhold	if $(makeDefaultDependencies) = true {
13437669b69fSIngo Weinhold		LocalDepends files : $(1) ;
1344d391d2ebSIngo Weinhold		LocalClean clean : $(1) ;
1345d391d2ebSIngo Weinhold	}
13467669b69fSIngo Weinhold}
1347d391d2ebSIngo Weinhold
1348d391d2ebSIngo Weinholdactions AbsSymLink
1349d391d2ebSIngo Weinhold{
1350d391d2ebSIngo Weinhold	target="$(2)"
1351d391d2ebSIngo Weinhold	case "$target" in
1352d391d2ebSIngo Weinhold		/*) ;;
1353d391d2ebSIngo Weinhold		*) target=`pwd`/"$target";;
1354d391d2ebSIngo Weinhold	esac
1355d391d2ebSIngo Weinhold	$(RM) "$(1)" && $(LN) -s "$target" "$(1)"
1356d391d2ebSIngo Weinhold}
1357d391d2ebSIngo Weinhold
13587bc56df1SIngo Weinholdrule OBOSInstall
13597bc56df1SIngo Weinhold{
13607bc56df1SIngo Weinhold	# Usage: OBOSInstall <[ install [ and uninstall ] pseudotarget ]>
13617bc56df1SIngo Weinhold	#					 : <directory> : <sources to install>
13627bc56df1SIngo Weinhold	#					 : [ <installgrist> ] : [ <install rule> ] ;
13637bc56df1SIngo Weinhold	local install = $(1[1]) ;
13647bc56df1SIngo Weinhold	install ?= install ;
13657bc56df1SIngo Weinhold	local uninstall = $(1[2]) ;
13667bc56df1SIngo Weinhold	uninstall ?= un$(install) ;
13677bc56df1SIngo Weinhold	local dir = $(2) ;
13687bc56df1SIngo Weinhold	local sources = $(3) ;
13697bc56df1SIngo Weinhold	local installgrist = $(4) ;
13707bc56df1SIngo Weinhold	installgrist ?= $(INSTALLGRIST) ;
13717bc56df1SIngo Weinhold	local installRule = $(5) ;
13727bc56df1SIngo Weinhold	installRule ?= Install ;
13737bc56df1SIngo Weinhold	local targets = $(sources:G=$(installgrist)) ;
13747bc56df1SIngo Weinhold
1375bacf6872Sshatty	NotFile $(install) ;
1376bacf6872Sshatty	NotFile $(uninstall) ;
13777bc56df1SIngo Weinhold	Depends $(install) : $(targets) ;
13787bc56df1SIngo Weinhold	Clean $(uninstall) : $(targets) ;
13797bc56df1SIngo Weinhold
13807bc56df1SIngo Weinhold	SEARCH on $(sources) += $(SEARCH_SOURCE) ;
13817bc56df1SIngo Weinhold	MakeLocate $(targets) : $(dir) ;
13827bc56df1SIngo Weinhold
13837bc56df1SIngo Weinhold	local source ;
13847bc56df1SIngo Weinhold	for source in $(sources) {
13857bc56df1SIngo Weinhold		local target = $(source:G=$(installgrist)) ;
13867bc56df1SIngo Weinhold
13877bc56df1SIngo Weinhold		Depends $(target) : $(source) ;
13887bc56df1SIngo Weinhold		$(installRule) $(target) : $(source) ;
13897bc56df1SIngo Weinhold
13907bc56df1SIngo Weinhold		if [ on $(target) return $(MODE) ] {
13917bc56df1SIngo Weinhold			Chmod $(target) ;
13927bc56df1SIngo Weinhold		}
13937bc56df1SIngo Weinhold
13947bc56df1SIngo Weinhold		if $(OWNER) && $(CHOWN) {
13957bc56df1SIngo Weinhold			Chown $(target) ;
13967bc56df1SIngo Weinhold			OWNER on $(target) = $(OWNER) ;
13977bc56df1SIngo Weinhold		}
13987bc56df1SIngo Weinhold
13997bc56df1SIngo Weinhold		if $(GROUP) && $(CHGRP) {
14007bc56df1SIngo Weinhold			Chgrp $(target) ;
14017bc56df1SIngo Weinhold			GROUP on $(target) = $(GROUP) ;
14027bc56df1SIngo Weinhold		}
14037bc56df1SIngo Weinhold	}
14047bc56df1SIngo Weinhold}
14057bc56df1SIngo Weinhold
14067669b69fSIngo Weinholdrule InstallAbsSymLinkAdapter
14077669b69fSIngo Weinhold{
14087669b69fSIngo Weinhold	# InstallAbsSymLinkAdapter <link> : <link target>
14097669b69fSIngo Weinhold	if ! [ on $(2) return $(TARGET) ] {
14107669b69fSIngo Weinhold		TARGET on $(2) = [ on $(2) return $(SEARCH) ] ;
14117669b69fSIngo Weinhold	}
14127669b69fSIngo Weinhold	AbsSymLink $(1) : $(2) : : false ;
14137669b69fSIngo Weinhold}
14147669b69fSIngo Weinhold
14157bc56df1SIngo Weinholdrule OBOSInstallAbsSymLink
14167bc56df1SIngo Weinhold{
14177bc56df1SIngo Weinhold	# Usage: OBOSInstallAbsSymLink <[ install [ and uninstall ] pseudotarget ]>
14187bc56df1SIngo Weinhold	#							   : <directory> : <sources to install>
14197bc56df1SIngo Weinhold	#							   : [ <installgrist> ] ;
14207669b69fSIngo Weinhold	OBOSInstall $(1) : $(2) : $(3) : $(4) : InstallAbsSymLinkAdapter ;
14217bc56df1SIngo Weinhold}
14227bc56df1SIngo Weinhold
14237bc56df1SIngo Weinholdrule InstallRelSymLinkAdapter
14247bc56df1SIngo Weinhold{
14257bc56df1SIngo Weinhold	# InstallRelSymLinkAdapter <link> : <link target>
14267bc56df1SIngo Weinhold	if ! [ on $(2) return $(TARGET) ] {
14277bc56df1SIngo Weinhold		TARGET on $(2) = [ on $(2) return $(SEARCH) ] ;
14287bc56df1SIngo Weinhold	}
14297669b69fSIngo Weinhold	RelSymLink $(1) : $(2) : false ;
14307bc56df1SIngo Weinhold}
14317bc56df1SIngo Weinhold
14327bc56df1SIngo Weinholdrule OBOSInstallRelSymLink
14337bc56df1SIngo Weinhold{
14347bc56df1SIngo Weinhold	# Usage: OBOSInstallRelSymLink <[ install [ and uninstall ] pseudotarget ]>
14357bc56df1SIngo Weinhold	#							   : <directory> : <sources to install>
14367bc56df1SIngo Weinhold	#							   : [ <installgrist> ] ;
14377bc56df1SIngo Weinhold	OBOSInstall $(1) : $(2) : $(3) : $(4) : InstallRelSymLinkAdapter ;
14387bc56df1SIngo Weinhold}
14397bc56df1SIngo Weinhold
14407bc56df1SIngo Weinhold
144152a38012Sejakowatz#-------------------------------------------------------------------------------
144252a38012Sejakowatz# Low-level OBOS utility rules
144352a38012Sejakowatz#-------------------------------------------------------------------------------
144479b49834SIngo Weinholdrule FObjectsDir
144579b49834SIngo Weinhold{
144679b49834SIngo Weinhold	# FObjectsDir
144779b49834SIngo Weinhold	#
144879b49834SIngo Weinhold	# Returns the output directory for object files for the current
144979b49834SIngo Weinhold	# subdirectory.
145079b49834SIngo Weinhold
145179b49834SIngo Weinhold	return [ FDirName $(OBOS_OBJECT_TARGET) $(SUBDIR_TOKENS[2-]) ] ;
145279b49834SIngo Weinhold}
145379b49834SIngo Weinhold
145452a38012Sejakowatzrule SetupObjectsDir
145552a38012Sejakowatz{
145679b49834SIngo Weinhold	LOCATE_TARGET = [ FObjectsDir ] ;
14578d3308d9SIngo Weinhold	LOCATE_SOURCE = $(LOCATE_TARGET) ;
14588d3308d9SIngo Weinhold	SEARCH_SOURCE = [ Filter $(SEARCH_SOURCE) : $(LOCATE_TARGET) ]
14598d3308d9SIngo Weinhold					$(LOCATE_TARGET) ;
146052a38012Sejakowatz}
146152a38012Sejakowatz
146252a38012Sejakowatz#-------------------------------------------------------------------------------
146352a38012Sejakowatz# Link rule/action are overwritten as they don't handle linking files who's name
146452a38012Sejakowatz# contain spaces very well. Also adds resources and version to executable.
146552a38012Sejakowatz#-------------------------------------------------------------------------------
146652a38012Sejakowatzrule Link
146752a38012Sejakowatz{
146852a38012Sejakowatz	# Note: RESFILES must be set before invocation.
146952a38012Sejakowatz	MODE on $(<) = $(EXEMODE) ;
147052a38012Sejakowatz	on $(1) XRes $(1) : $(RESFILES) ;
147152a38012Sejakowatz	Chmod $(<) ;
147252a38012Sejakowatz	SetType $(1) ;
147352a38012Sejakowatz	MimeSet $(1) ;
14741419ae2bSshatty	SetVersion $(1) ;
147552a38012Sejakowatz}
147652a38012Sejakowatz
147752a38012Sejakowatzactions Link bind NEEDLIBS
147852a38012Sejakowatz{
14791eb18edfSIngo Weinhold	$(LINK) $(LINKFLAGS) -o "$(1)" $(UNDEFS) "$(2)" "$(NEEDLIBS)" $(LINKLIBS) ;
148052a38012Sejakowatz}
148152a38012Sejakowatz
14828d3308d9SIngo Weinholdrule LexC++
14838d3308d9SIngo Weinhold{
14848d3308d9SIngo Weinhold	Depends $(1) : $(2) ;
14858d3308d9SIngo Weinhold	MakeLocate $(1) : $(LOCATE_SOURCE) ;
14868d3308d9SIngo Weinhold	LocalClean clean : $(1) ;
14878d3308d9SIngo Weinhold}
14888d3308d9SIngo Weinhold
14898d3308d9SIngo Weinholdactions LexC++
14908d3308d9SIngo Weinhold{
14918d3308d9SIngo Weinhold	$(LEX) -o$(1) $(2)
14928d3308d9SIngo Weinhold}
14938d3308d9SIngo Weinhold
14948d3308d9SIngo Weinholdrule Bison
14958d3308d9SIngo Weinhold{
14968d3308d9SIngo Weinhold	local _h ;
14978d3308d9SIngo Weinhold
1498cec8c8b5SJérôme Duval	_h = $(1:S=.hpp) ;
14998d3308d9SIngo Weinhold
15008d3308d9SIngo Weinhold	MakeLocate $(<) $(_h) : $(LOCATE_SOURCE) ;
15018d3308d9SIngo Weinhold
15028d3308d9SIngo Weinhold	Depends $(<) $(_h) : $(>) ;
15038d3308d9SIngo Weinhold	Bison1 $(<) $(_h) : $(>) ;
15048d3308d9SIngo Weinhold	LocalClean clean : $(<) $(_h) ;
15058d3308d9SIngo Weinhold
15068d3308d9SIngo Weinhold	# make sure someone includes $(_h) else it will be
15078d3308d9SIngo Weinhold	# a deadly independent target
15088d3308d9SIngo Weinhold
15098d3308d9SIngo Weinhold	Includes $(<) : $(_h) ;
15108d3308d9SIngo Weinhold}
15118d3308d9SIngo Weinhold
15128d3308d9SIngo Weinholdactions Bison1
15138d3308d9SIngo Weinhold{
15148d3308d9SIngo Weinhold	bison $(YACCFLAGS) -o $(1[1]) $(2)
1515cec8c8b5SJérôme Duval	[ -f $(1[1]).h ] && mv $(1[1]).h $(1[2]) || true
15168d3308d9SIngo Weinhold}
15178d3308d9SIngo Weinhold
1518705fc998SAxel Dörflerrule UnarchiveObjects
1519705fc998SAxel Dörfler{
1520705fc998SAxel Dörfler	# UnarchiveObjects <target objects> : <static object>
1521705fc998SAxel Dörfler
1522705fc998SAxel Dörfler	MakeLocate $(1) : $(LOCATE_TARGET) ;
1523705fc998SAxel Dörfler	Depends $(2) : $(1) ;
1524705fc998SAxel Dörfler	SEARCH on $(2) = $(SEARCH_SOURCE) ;
1525705fc998SAxel Dörfler}
1526705fc998SAxel Dörfler
1527705fc998SAxel Dörfleractions UnarchiveObjects
1528705fc998SAxel Dörfler{
1529*3c71865aSAxel Dörfler	cd $(1[1]:D)
1530*3c71865aSAxel Dörfler	ar -x "$(2)" $(1:B).o
1531705fc998SAxel Dörfler	cd -
1532705fc998SAxel Dörfler}
1533705fc998SAxel Dörfler
153452a38012Sejakowatz# BeOS specific rules
153552a38012Sejakowatz
153652a38012Sejakowatzrule XRes
153752a38012Sejakowatz{
153852a38012Sejakowatz	# XRes <target> : <resource files>
153952a38012Sejakowatz	if $(2)
154052a38012Sejakowatz	{
15419eea4522SIngo Weinhold		Depends $(1) : $(2) ;
154252a38012Sejakowatz		XRes1 $(1) : $(2) ;
154352a38012Sejakowatz	}
154452a38012Sejakowatz}
154552a38012Sejakowatz
154652a38012Sejakowatzrule XRes1 { }
154752a38012Sejakowatz
154852a38012Sejakowatzrule SetVersion
154952a38012Sejakowatz{
155052a38012Sejakowatz	# SetVersion <target>
155152a38012Sejakowatz}
155252a38012Sejakowatz
155352a38012Sejakowatzrule SetType
155452a38012Sejakowatz{
155552a38012Sejakowatz	# SetType <target>
155652a38012Sejakowatz}
155752a38012Sejakowatz
155852a38012Sejakowatzrule MimeSet
155952a38012Sejakowatz{
156052a38012Sejakowatz	# SetType <target>
156152a38012Sejakowatz}
156252a38012Sejakowatz
156352a38012Sejakowatz
156452a38012Sejakowatzif $(OS) = BEOS
156552a38012Sejakowatz{
156652a38012Sejakowatz
156752a38012Sejakowatzactions XRes1
156852a38012Sejakowatz{
15690931b8f9SIngo Weinhold	xres -o "$(1)" "$(2)" ;
157052a38012Sejakowatz}
157152a38012Sejakowatz
157252a38012Sejakowatzactions SetVersion
157352a38012Sejakowatz{
157452a38012Sejakowatz	setversion "$(1)" -system $(OBOS_BUILD_VERSION) -short "$(OBOS_BUILD_DESCRIPTION)" ;
157552a38012Sejakowatz}
157652a38012Sejakowatz
157752a38012Sejakowatzactions SetType
157852a38012Sejakowatz{
157952a38012Sejakowatz	settype -t $(OBOS_TARGET_TYPE) "$(1)" ;
158052a38012Sejakowatz}
158152a38012Sejakowatz
158252a38012Sejakowatzactions MimeSet
158352a38012Sejakowatz{
158452a38012Sejakowatz	mimeset -f "$(1)" ;
158552a38012Sejakowatz}
158652a38012Sejakowatz
158752a38012Sejakowatz}	# if BEOS
158852a38012Sejakowatz
158952a38012Sejakowatz
159052a38012Sejakowatzrule assemble
159152a38012Sejakowatz{
159294782cf7SIngo Weinhold	Depends $(<) : $(>) ;
159394782cf7SIngo Weinhold	ASFLAGS on $(<) += $(ASFLAGS) $(SUBDIRASFLAGS) ;
159494782cf7SIngo Weinhold	ASHDRS on $(<) = [ FIncludes $(SEARCH_SOURCE) $(SUBDIRHDRS) $(HDRS) ] ;
159552a38012Sejakowatz}
159652a38012Sejakowatz
159752a38012Sejakowatzactions assemble
159852a38012Sejakowatz{
1599a8687de4SAxel Dörfler	$(CC) -c "$(2)" -O2 $(ASFLAGS) -D_ASSEMBLER $(KERNEL_CCFLAGS) $(ASHDRS) -o "$(1)" ;
160052a38012Sejakowatz}
160152a38012Sejakowatz
16020931b8f9SIngo Weinhold# Overridden to allow spaces in file names.
16030931b8f9SIngo Weinholdactions Chmod1
16040931b8f9SIngo Weinhold{
16050931b8f9SIngo Weinhold	$(CHMOD) "$(MODE)" "$(1)"
16060931b8f9SIngo Weinhold}
16070931b8f9SIngo Weinhold
16086991af8cSIngo Weinhold# Overridden to allow spaces in file names.
16096991af8cSIngo Weinholdactions piecemeal together existing Clean
16106991af8cSIngo Weinhold{
16116991af8cSIngo Weinhold	$(RM) "$(>)"
16126991af8cSIngo Weinhold}
16136991af8cSIngo Weinhold
161408125d07SIngo Weinholdrule ObjectReference
161508125d07SIngo Weinhold{
161608125d07SIngo Weinhold	# ObjectReference <reference object> : <source object>
161708125d07SIngo Weinhold	# Makes <reference object> refer to the same file as <source object>.
161808125d07SIngo Weinhold	# The filenames must of course be identical.
161908125d07SIngo Weinhold	# <source object> must have already been LOCATEd.
162008125d07SIngo Weinhold
162108125d07SIngo Weinhold	local ref = $(1) ;
162208125d07SIngo Weinhold	local source = $(2) ;
162308125d07SIngo Weinhold	if $(ref) != $(source) {
16249eea4522SIngo Weinhold		Depends $(ref) : $(source) ;
162521df5945SIngo Weinhold		LOCATE on $(ref) = [ on $(source) return $(LOCATE) ] ;
162608125d07SIngo Weinhold	}
162708125d07SIngo Weinhold}
162808125d07SIngo Weinhold
162908125d07SIngo Weinholdrule ObjectReferences
163008125d07SIngo Weinhold{
163108125d07SIngo Weinhold	# ObjectReferences <source objects>
163208125d07SIngo Weinhold	# Creates local references to <source objects>, i.e. identifiers with the
163308125d07SIngo Weinhold	# current grist referring to the same files. <source objects> must have
163408125d07SIngo Weinhold	# already been LOCATEd.
163508125d07SIngo Weinhold
163608125d07SIngo Weinhold	local source ;
163708125d07SIngo Weinhold	for source in $(1) {
163808125d07SIngo Weinhold		ObjectReference [ FGristFiles $(source) ] : $(source) ;
163908125d07SIngo Weinhold	}
164008125d07SIngo Weinhold}
164108125d07SIngo Weinhold
16429fc6b2e1SIngo Weinholdrule Filter
16439fc6b2e1SIngo Weinhold{
16449fc6b2e1SIngo Weinhold	# Filter <list> : <excludes> ;
16459fc6b2e1SIngo Weinhold	# Removes all occurrences of <excludes> in <list>.
16469fc6b2e1SIngo Weinhold
16479fc6b2e1SIngo Weinhold	local list = $(1) ;
16489fc6b2e1SIngo Weinhold	local excludes = $(2) ;
16499fc6b2e1SIngo Weinhold	local newList ;
16509fc6b2e1SIngo Weinhold	local item ;
16519fc6b2e1SIngo Weinhold	for item in $(list) {
16529fc6b2e1SIngo Weinhold		local skip ;
16539fc6b2e1SIngo Weinhold		local exclude ;
16549fc6b2e1SIngo Weinhold		for exclude in $(excludes) {
16559fc6b2e1SIngo Weinhold			if $(item) = $(exclude) {
16569fc6b2e1SIngo Weinhold				skip = true ;
16579fc6b2e1SIngo Weinhold			}
16589fc6b2e1SIngo Weinhold		}
16599fc6b2e1SIngo Weinhold		if ! $(skip) {
1660dd9f8062SIngo Weinhold			newList += $(item) ;
16619fc6b2e1SIngo Weinhold		}
16629fc6b2e1SIngo Weinhold	}
16639fc6b2e1SIngo Weinhold	return $(newList) ;
16649fc6b2e1SIngo Weinhold}
16659fc6b2e1SIngo Weinhold
16660931b8f9SIngo Weinhold
166752a38012Sejakowatz## Kernel stuff!
166852a38012Sejakowatz
166952a38012Sejakowatzrule SetupKernel
167052a38012Sejakowatz{
167152a38012Sejakowatz	# Usage SetupKernel <sources_or_objects> : <extra_cc_flags>;
167252a38012Sejakowatz
16732dd47f63SIngo Weinhold	local _objs = [ FGristFiles $(1:S=$(SUFOBJ)) ] ;
167452a38012Sejakowatz
167528d2a30eSDaniel Reinhold	#Setup Kernel header directories
167699b8dab3SAxel Dörfler	local public_kernel_includes = add-ons/file_system add-ons/graphics app device drivers kernel storage support ;
1677b8b44e7aSAxel Dörfler	local private_kernel_includes = kernel libroot kernel/boot/platform/$(OBOS_BOOT_PLATFORM) ;
1678a6c008e1Sbeveloper	# Use posix headers directory
167928d2a30eSDaniel Reinhold	HDRS = [ FDirName $(OBOS_TOP) headers posix ] ;
1680a6c008e1Sbeveloper	# Use public OS header directories
1681089a0629Sbeveloper	HDRS += [ PublicHeaders $(public_kernel_includes) ] ;
1682089a0629Sbeveloper	# Use private directories
1683089a0629Sbeveloper	HDRS += [ PrivateHeaders $(private_kernel_includes) ] ;
168409c5682dSIngo Weinhold	# The platform dependent headers.
168509c5682dSIngo Weinhold	HDRS += $(PLATFORM_HEADERS) ;
1686a6c008e1Sbeveloper
168752a38012Sejakowatz	UseArchHeaders $(OBOS_ARCH) ;
168852a38012Sejakowatz
168952a38012Sejakowatz	SetupObjectsDir ;
169052a38012Sejakowatz
169152a38012Sejakowatz	CCFLAGS on $(_objs) = $(KERNEL_CCFLAGS) $(2) ;
169298cc804cSAxel Dörfler	C++FLAGS on $(_objs) = $(KERNEL_C++FLAGS) $(2) ;
169352a38012Sejakowatz}
169452a38012Sejakowatz
169552a38012Sejakowatzrule KernelObjects
169652a38012Sejakowatz{
169752a38012Sejakowatz	SetupKernel $(1) : $(2) ;
169852a38012Sejakowatz
169952a38012Sejakowatz	Objects $(1) ;
170052a38012Sejakowatz}
170152a38012Sejakowatz
170252a38012Sejakowatzrule KernelLd
170352a38012Sejakowatz{
170480721244SAxel Dörfler	# KernelLd <name> : <objs> : <linkerscript> : <args> : <gcc_off> : <config_section> ;
170552a38012Sejakowatz
170652a38012Sejakowatz	SetupKernel $(2) ;
170752a38012Sejakowatz	LINK on $(1) = ld ;
170852a38012Sejakowatz
170952a38012Sejakowatz	LINKFLAGS on $(1) = $(4) ;
171052a38012Sejakowatz	if $(3) { LINKFLAGS on $(1) += --script=$(3) ; }
171152a38012Sejakowatz
171252a38012Sejakowatz	# Remove any preset LINKLIBS
171352a38012Sejakowatz	LINKLIBS on $(1) =  ;
171452a38012Sejakowatz
171552a38012Sejakowatz	# Show that we depend on the libraries we need
17169eea4522SIngo Weinhold	LocalClean clean : $(1) ;
17179eea4522SIngo Weinhold	LocalDepends all : $(1) ;
171852a38012Sejakowatz	Depends $(1) : $(2) ;
171952a38012Sejakowatz
172052a38012Sejakowatz	if $(6) {
172152a38012Sejakowatz		for i in $(6) {
17222a83bfb4SIngo Weinhold			KernelConfigSection $(i) : elf32 : $(1) ;
172352a38012Sejakowatz		}
172452a38012Sejakowatz	}
172552a38012Sejakowatz
172652a38012Sejakowatz	MakeLocate $(1) : $(LOCATE_TARGET) ;
172752a38012Sejakowatz
172809c5682dSIngo Weinhold	# Add the platform specific static libs (libgcc.a).
172952a38012Sejakowatz	if ! $(5) {
173009c5682dSIngo Weinhold		LINKLIBS on $(1) += $(PLATFORM_LINKLIBS) ;
173152a38012Sejakowatz	}
173252a38012Sejakowatz}
173352a38012Sejakowatz
173452a38012Sejakowatzactions KernelLd
173552a38012Sejakowatz{
17361eb18edfSIngo Weinhold	$(LINK) $(LINKFLAGS) -o "$(1)" "$(2)" $(LINKLIBS) ;
173752a38012Sejakowatz}
173852a38012Sejakowatz
1739811903d1SAxel Dörflerrule KernelAddon
1740811903d1SAxel Dörfler{
1741600203b1SAxel Dörfler	# KernelAddon <name> : <relpath> : <sources> : <static-libraries> ;
1742811903d1SAxel Dörfler
1743811903d1SAxel Dörfler	local sources = $(3) ;
1744811903d1SAxel Dörfler
1745811903d1SAxel Dörfler	SetupKernel $(3) ;
1746811903d1SAxel Dörfler	Addon $(1) : $(2) : $(3) ;
1747811903d1SAxel Dörfler	ObjectCcFlags $(sources) : -D_KERNEL_MODE=1 -no-fpic ;
1748811903d1SAxel Dörfler	ObjectC++Flags $(sources) : -D_KERNEL_MODE=1 -no-fpic
1749811903d1SAxel Dörfler								-fno-exceptions -fno-rtti ;
1750811903d1SAxel Dörfler	LINKFLAGS on $(1) = [ on $(1) return $(LINKFLAGS) ] -nostdlib ;
1751600203b1SAxel Dörfler	LinkSharedOSLibs $(1) : $(4) $(OBOS_TOP)/objects/$(OBOS_ARCH).$(OBOS_VERSION)/kernel/kernel.so ;
1752811903d1SAxel Dörfler		# ToDo this has to be changed!
1753811903d1SAxel Dörfler}
1754811903d1SAxel Dörfler
175580721244SAxel Dörflerrule KernelMergeObject
175680721244SAxel Dörfler{
17572fbd7065SIngo Weinhold	# KernelMergeObject <name> : <sources> : <extra CFLAGS> : <other objects> ;
17582fbd7065SIngo Weinhold	# Compiles source files and merges the object files to an object file.
17592fbd7065SIngo Weinhold	# <name>: Name of the object file to create. No grist will be added.
17602fbd7065SIngo Weinhold	# <sources>: Sources to be compiled. Grist will be added.
17612fbd7065SIngo Weinhold	# <extra CFLAGS>: Additional flags for compilation.
17622fbd7065SIngo Weinhold	# <other objects>: Object files or static libraries to be merged. No grist
17632fbd7065SIngo Weinhold	#                  will be added.
17642fbd7065SIngo Weinhold	#
176580721244SAxel Dörfler
176680721244SAxel Dörfler	SetupKernel $(2) : $(3) ;
176780721244SAxel Dörfler
176880721244SAxel Dörfler	MakeLocateObjects $(2) ;
176980721244SAxel Dörfler	Objects $(2) ;
17702fbd7065SIngo Weinhold	MergeObjectFromObjects $(1) : $(2:S=$(SUFOBJ)) : $(4) ;
177180721244SAxel Dörfler}
177280721244SAxel Dörfler
177352a38012Sejakowatzrule KernelStaticLibrary
177452a38012Sejakowatz{
177552a38012Sejakowatz	# Usage KernelStaticLibrary <name> : <sources> : <extra cc flags>  ;
177652a38012Sejakowatz	# This is designed to take a set of sources and libraries and create
177752a38012Sejakowatz	# a file called lib<name>.a
177852a38012Sejakowatz
177952a38012Sejakowatz	SetupKernel $(2) : $(3) ;
178052a38012Sejakowatz
178152a38012Sejakowatz	MakeLocateObjects $(2) ;
178252a38012Sejakowatz	Library $(1) : $(2) ;
178352a38012Sejakowatz}
178452a38012Sejakowatz
178552a38012Sejakowatzrule KernelStaticLibraryObjects
178652a38012Sejakowatz{
178752a38012Sejakowatz	# Usage KernelStaticLibrary <name> : <sources> ;
178852a38012Sejakowatz	# This is designed to take a set of sources and libraries and create
178952a38012Sejakowatz	# a file called <name>
179052a38012Sejakowatz
179152a38012Sejakowatz	SetupKernel $(2) ;
179252a38012Sejakowatz
179352a38012Sejakowatz	# Show that we depend on the libraries we need
17949eea4522SIngo Weinhold	LocalClean clean : $(1) ;
17959eea4522SIngo Weinhold	LocalDepends all : $(1) ;
179652a38012Sejakowatz	Depends $(1) : $(2) ;
179752a38012Sejakowatz
179852a38012Sejakowatz	MakeLocate $(1) : $(LOCATE_TARGET) ;
179952a38012Sejakowatz}
180052a38012Sejakowatz
180152a38012Sejakowatzactions KernelStaticLibraryObjects
180252a38012Sejakowatz{
18030931b8f9SIngo Weinhold	ar -r "$(1)" "$(2)" ;
180452a38012Sejakowatz}
180552a38012Sejakowatz
18065dc4e1efSIngo Weinholdrule BuildPlatformMain
180752a38012Sejakowatz{
18085dc4e1efSIngo Weinhold	# Usage BuildPlatformMain <target> : <sources> ;
180952a38012Sejakowatz	SetupObjectsDir ;
18105dc4e1efSIngo Weinhold	SetupDefaultIncludes ;
181152a38012Sejakowatz
18125dc4e1efSIngo Weinhold	# Remove `-nostdinc' from CCFLAGS and C++FLAGS.
18135dc4e1efSIngo Weinhold	local oldCCFLAGS = $(CCFLAGS) ;
18145dc4e1efSIngo Weinhold	local oldC++FLAGS = $(C++FLAGS) ;
18155dc4e1efSIngo Weinhold	CCFLAGS = [ Filter $(CCFLAGS) : -nostdinc ] ;
18165dc4e1efSIngo Weinhold	C++FLAGS = [ Filter $(C++FLAGS) : -nostdinc ] ;
181752a38012Sejakowatz
181852a38012Sejakowatz	Main $(1) : $(2) ;
18195dc4e1efSIngo Weinhold
18205dc4e1efSIngo Weinhold	# Reset CCFLAGS and C++FLAGS to original values.
18215dc4e1efSIngo Weinhold	CCFLAGS = $(oldCCFLAGS) ;
18225dc4e1efSIngo Weinhold	C++FLAGS = $(oldC++FLAGS) ;
182352a38012Sejakowatz}
182452a38012Sejakowatz
18259fcaa61dSIngo Weinholdrule BuildPlatformTest
18269fcaa61dSIngo Weinhold{
18279fcaa61dSIngo Weinhold	# Usage BuildPlatformTest <target> : <sources> ;
18289fcaa61dSIngo Weinhold
18299fcaa61dSIngo Weinhold	local target = $(1) ;
18309fcaa61dSIngo Weinhold	local sources = $(2) ;
18319fcaa61dSIngo Weinhold
18329fcaa61dSIngo Weinhold	BuildPlatformMain $(target) : $(sources) ;
18339fcaa61dSIngo Weinhold	local relPath ;
18349fcaa61dSIngo Weinhold	if [ FIsPrefix src tests : $(SUBDIR_TOKENS) ] {
18359fcaa61dSIngo Weinhold		relPath = $(SUBDIR_TOKENS[3-]) ;
18369fcaa61dSIngo Weinhold	} else {
18379fcaa61dSIngo Weinhold		relPath = $(SUBDIR_TOKENS[2-]) ;
18389fcaa61dSIngo Weinhold	}
18399fcaa61dSIngo Weinhold	MakeLocate $(target) : [ FDirName $(OBOS_TEST_DIR) $(relPath) ] ;
18409fcaa61dSIngo Weinhold}
18419fcaa61dSIngo Weinhold
184252a38012Sejakowatzrule KernelConfigSection
184352a38012Sejakowatz{
184452a38012Sejakowatz	# KernelConfigSection <section> : <type> : <file>  ;
18452a83bfb4SIngo Weinhold
18462a83bfb4SIngo Weinhold	SECTION_NAMES on $(OBOS_KERNEL_CONFIG) += $(1) ;
18472a83bfb4SIngo Weinhold	SECTION_TYPES on $(OBOS_KERNEL_CONFIG) += $(2) ;
18482a83bfb4SIngo Weinhold	SECTION_FILES on $(OBOS_KERNEL_CONFIG) += $(3) ;
18492a83bfb4SIngo Weinhold
18502a83bfb4SIngo Weinhold	Depends $(OBOS_KERNEL_CONFIG) : $(3) ;
185152a38012Sejakowatz}
185252a38012Sejakowatz
185352a38012Sejakowatzrule WriteKernelConfig
185452a38012Sejakowatz{
185552a38012Sejakowatz	# usage: WriteKernelConfig <target> ;
185652a38012Sejakowatz
18579eea4522SIngo Weinhold	LocalDepends files : $(1) ;
185852a38012Sejakowatz
18592a83bfb4SIngo Weinhold	MakeLocate $(1) : $(OBOS_OBJECT_TARGET) ;
186052a38012Sejakowatz
18619eea4522SIngo Weinhold	LocalClean clean : $(1) ;
186252a38012Sejakowatz}
186352a38012Sejakowatz
18642a83bfb4SIngo Weinholdactions WriteKernelConfig bind SECTION_FILES
186552a38012Sejakowatz{
18660931b8f9SIngo Weinhold	target="$(1)"
18670931b8f9SIngo Weinhold	echo "# OpenBeOS Kernel Config File" > "$target"
18680931b8f9SIngo Weinhold	echo "# Automatically generated - do not edit!" >> "$target"
18692a83bfb4SIngo Weinhold	count=0
18702a83bfb4SIngo Weinhold	for section in "$(SECTION_NAMES)" ; do
18712a83bfb4SIngo Weinhold		count=`expr $count + 1`
18722a83bfb4SIngo Weinhold		eval section$count="$section"
18732a83bfb4SIngo Weinhold	done
18742a83bfb4SIngo Weinhold	i=1
18752a83bfb4SIngo Weinhold	for type in "$(SECTION_TYPES)" ; do
18762a83bfb4SIngo Weinhold		eval type$i="$type"
18772a83bfb4SIngo Weinhold		i=`expr $i + 1`
18782a83bfb4SIngo Weinhold	done
18792a83bfb4SIngo Weinhold	i=1
18802a83bfb4SIngo Weinhold	for file in "$(SECTION_FILES)" ; do
18812a83bfb4SIngo Weinhold		eval file$i="$file"
18822a83bfb4SIngo Weinhold		i=`expr $i + 1`
18832a83bfb4SIngo Weinhold	done
18842a83bfb4SIngo Weinhold	for i in `seq $count` ; do
18852a83bfb4SIngo Weinhold		eval section="\$section$i"
18862a83bfb4SIngo Weinhold		eval type="\$type$i"
18872a83bfb4SIngo Weinhold		eval file="\$file$i"
18880931b8f9SIngo Weinhold		echo "" >> "$target"
18892a83bfb4SIngo Weinhold		echo "["$section"]" >> "$target"
18902a83bfb4SIngo Weinhold		echo "type="$type >> "$target"
18910931b8f9SIngo Weinhold		case "$file" in
189252a38012Sejakowatz			/*) ;;
18930931b8f9SIngo Weinhold			*) file=`pwd`/"$file";;
189452a38012Sejakowatz		esac
18952a83bfb4SIngo Weinhold		echo "file="$file >> "$target"
189652a38012Sejakowatz	done
189752a38012Sejakowatz}
189852a38012Sejakowatz
189952a38012Sejakowatzrule BuildKernel
190052a38012Sejakowatz{
190152a38012Sejakowatz	# Usage BuildKernel <target> : <config_file> ;
19020c0b2cd0SIngo Weinhold	local kernel = $(1) ;
19030c0b2cd0SIngo Weinhold	local configFile = $(2) ;
19040c0b2cd0SIngo Weinhold	local bootmaker = bootmaker ;
190552a38012Sejakowatz
19069eea4522SIngo Weinhold	LocalDepends all : $(kernel) ;
19070c0b2cd0SIngo Weinhold	Depends $(kernel) : $(configFile) $(bootmaker) ;
19089eea4522SIngo Weinhold	LocalClean clean : $(kernel) ;
19090c0b2cd0SIngo Weinhold	MakeLocate $(kernel) : $(LOCATE_TARGET) ;
191052a38012Sejakowatz
19110c0b2cd0SIngo Weinhold	BOOT_MAKER on $(kernel) = $(bootmaker) ;
191252a38012Sejakowatz}
191352a38012Sejakowatz
19140c0b2cd0SIngo Weinholdactions BuildKernel bind BOOT_MAKER
191552a38012Sejakowatz{
19160c0b2cd0SIngo Weinhold	"$(BOOT_MAKER)" --strip-debug --strip-binary strip "$(2)" -o "$(1)" ;
191752a38012Sejakowatz	echo ""
191852a38012Sejakowatz	echo "Kernel linked!"
191952a38012Sejakowatz	echo ""
192052a38012Sejakowatz}
192152a38012Sejakowatz
192252a38012Sejakowatzrule KernelFloppyImage
192352a38012Sejakowatz{
192452a38012Sejakowatz	# Usage KernelFloppyImage <target> : <kernel> : <bootblock> ;
19250c0b2cd0SIngo Weinhold	local floppy = $(1) ;
19260c0b2cd0SIngo Weinhold	local kernel = $(2) ;
19270c0b2cd0SIngo Weinhold	local bootblock = $(3) ;
19280c0b2cd0SIngo Weinhold	local makeflop = makeflop ;
192952a38012Sejakowatz
19309eea4522SIngo Weinhold	LocalDepends all : $(floppy) ;
19310c0b2cd0SIngo Weinhold	Depends $(floppy) : $(kernel) $(bootblock) $(makeflop) ;
19329eea4522SIngo Weinhold	LocalClean clean : $(floppy) ;
19330c0b2cd0SIngo Weinhold	MakeLocate $(floppy) : $(OBOS_OBJECT_TARGET) ;
193452a38012Sejakowatz
19350c0b2cd0SIngo Weinhold	BOOT_BLOCK on $(floppy) = $(bootblock) ;
19360c0b2cd0SIngo Weinhold	MAKE_FLOP on $(floppy) = $(makeflop) ;
193752a38012Sejakowatz}
193852a38012Sejakowatz
193952a38012Sejakowatz# This may be a bit verbose, but I think it's useful to show what's
194052a38012Sejakowatz# going on, at least in this early stage of development.
19410c0b2cd0SIngo Weinholdactions KernelFloppyImage bind BOOT_BLOCK bind MAKE_FLOP
194252a38012Sejakowatz{
19437378dd7fSAxel Dörfler	"$(MAKE_FLOP)" "-p $(shell expr 18 \* 2 \* 512)" "$(BOOT_BLOCK)" "$(2)" "$(1)" ;
19440c0b2cd0SIngo Weinhold
194552a38012Sejakowatz	echo ""
194652a38012Sejakowatz	echo "*************************************************"
194752a38012Sejakowatz	echo "*         Kernel build completed!               *"
194852a38012Sejakowatz	echo "*    Boot image for a 1.44M floppy created      *"
194952a38012Sejakowatz	echo "*************************************************"
195052a38012Sejakowatz	echo ""
19510c0b2cd0SIngo Weinhold	echo "Floppy image is $(1)"
195252a38012Sejakowatz	echo "The following command will write it to a floppy on BeOS"
19530c0b2cd0SIngo Weinhold	echo "  dd if=$(1) of=/dev/disk/floppy/raw bs=18k"
19540c0b2cd0SIngo Weinhold	echo "Alternatively you can run"
19550c0b2cd0SIngo Weinhold	echo "  ./configure --floppy /dev/disk/floppy/raw"
19560c0b2cd0SIngo Weinhold	echo "once and build + write the image subsequently via"
19570c0b2cd0SIngo Weinhold	echo "  jam installfloppy"
195852a38012Sejakowatz	echo ""
195952a38012Sejakowatz}
196052a38012Sejakowatz
19610c0b2cd0SIngo Weinholdrule InstallFloppy
19620c0b2cd0SIngo Weinhold{
19630c0b2cd0SIngo Weinhold	# InstallFloppy <target> : <floppy>
19640c0b2cd0SIngo Weinhold	# "dd"s <floppy> to $(FLOPPY_PATH).
19650c0b2cd0SIngo Weinhold
19660c0b2cd0SIngo Weinhold	local target = $(1) ;
19670c0b2cd0SIngo Weinhold	local floppy = $(2) ;
19680c0b2cd0SIngo Weinhold
19690c0b2cd0SIngo Weinhold	NotFile $(target) ;
19700c0b2cd0SIngo Weinhold	Always $(target) ;
19710c0b2cd0SIngo Weinhold	Depends $(target) : $(floppy) ;
19720c0b2cd0SIngo Weinhold}
19730c0b2cd0SIngo Weinhold
19740c0b2cd0SIngo Weinholdactions InstallFloppy
19750c0b2cd0SIngo Weinhold{
19760c0b2cd0SIngo Weinhold	if [ -z $(FLOPPY_PATH) ] ; then
19770c0b2cd0SIngo Weinhold		echo "Can't install floppy: FLOPPY_PATH not set."
19780c0b2cd0SIngo Weinhold		echo "run: ./configure --floppy <floppy path>"
19790c0b2cd0SIngo Weinhold		echo
19800c0b2cd0SIngo Weinhold		exit 0
19810c0b2cd0SIngo Weinhold	fi
19820c0b2cd0SIngo Weinhold	dd if=$(2) of=$(FLOPPY_PATH) bs=18k
19830c0b2cd0SIngo Weinhold}
198452a38012Sejakowatz
198521df5945SIngo Weinhold#-------------------------------------------------------------------------------
198621df5945SIngo Weinhold# FreeType 2 specific rules and variables
198721df5945SIngo Weinhold#-------------------------------------------------------------------------------
198821df5945SIngo Weinhold
198921df5945SIngo WeinholdFT2_INCLUDE = [ FDirName $(OBOS_TOP) headers libs freetype2 ] ;
199021df5945SIngo WeinholdFT2_SRC     = [ FDirName $(OBOS_TOP) src libs freetype2 ] ;
199121df5945SIngo Weinhold
199221df5945SIngo WeinholdFT2_LIB     = freetype ;
199321df5945SIngo Weinhold
1994fbd28219SIngo WeinholdFT2_COMPONENTS ?= gzip       # support for gzip-compressed files.
1995fbd28219SIngo Weinhold                  autohint   # auto-hinter
1996fbd28219SIngo Weinhold                  base       # base component (public APIs)
1997fbd28219SIngo Weinhold                  bdf        # BDF font driver
1998fbd28219SIngo Weinhold                  cache      # cache sub-system
1999fbd28219SIngo Weinhold                  cff        # CFF/CEF font driver
2000fbd28219SIngo Weinhold                  cid        # Postscript CID-keyed font driver
20019ec866ccSDarkWyrm		lzw	   # LZW routines
2002fbd28219SIngo Weinhold                  pcf        # PCF font driver
2003fbd28219SIngo Weinhold                  pfr        # PFR/TrueDoc font driver
2004fbd28219SIngo Weinhold                  psaux      # Common Postscript routines module
2005fbd28219SIngo Weinhold                  pshinter   # Postscript hinter module
2006fbd28219SIngo Weinhold                  psnames    # Postscript names handling
2007fbd28219SIngo Weinhold                  raster     # Monochrome rasterizer
2008fbd28219SIngo Weinhold                  smooth     # Anti-aliased rasterizer
2009fbd28219SIngo Weinhold                  sfnt       # SFNT-based format support routines
2010fbd28219SIngo Weinhold                  truetype   # TrueType font driver
2011fbd28219SIngo Weinhold                  type1      # Postscript Type 1 font driver
2012fbd28219SIngo Weinhold                  type42     # Postscript Type 42 (embedded TrueType) driver
2013fbd28219SIngo Weinhold                  winfonts   # Windows FON/FNT font driver
2014fbd28219SIngo Weinhold                  ;
2015fbd28219SIngo Weinhold
201621df5945SIngo Weinholdrule UseFreeTypeHeaders
201721df5945SIngo Weinhold{
201821df5945SIngo Weinhold	SubDirHdrs $(FT2_INCLUDE) ;
201921df5945SIngo Weinhold}
202021df5945SIngo Weinhold
202121df5945SIngo Weinholdrule UseFreeTypeObjectHeaders
202221df5945SIngo Weinhold{
20239b60a208SIngo Weinhold	# UseFreeTypeObjectHeaders <sources> [ : <objects> ] ;
20249b60a208SIngo Weinhold	SourceHdrs $(1) : $(FT2_INCLUDE) : $(2) ;
202521df5945SIngo Weinhold}
202621df5945SIngo Weinhold
202721df5945SIngo Weinholdrule FT2_SubDir
202821df5945SIngo Weinhold{
202921df5945SIngo Weinhold	# FT2_SubDir <dir>
203021df5945SIngo Weinhold	# <dir>: Components of a directory in the original hierarchy.
203121df5945SIngo Weinhold	local dir = $(1) ;
203221df5945SIngo Weinhold	local topDir ;
203321df5945SIngo Weinhold	switch $(dir[1])
203421df5945SIngo Weinhold	{
203521df5945SIngo Weinhold		case "include"	: topDir = $(FT2_INCLUDE) ;
203621df5945SIngo Weinhold		case src		: topDir = $(FT2_SRC) ;
203721df5945SIngo Weinhold		case *			: ECHO "Unknown FreeType2 directory: " $(dir) ;
203821df5945SIngo Weinhold	}
203921df5945SIngo Weinhold	return [ FDirName $(topDir) $(dir[2-]) ] ;
204021df5945SIngo Weinhold}
204121df5945SIngo Weinhold
204221df5945SIngo Weinholdrule FT2_Library
204321df5945SIngo Weinhold{
204421df5945SIngo Weinhold	# FT2_Library <libname> : <sources>
204521df5945SIngo Weinhold	# Builds objects from sources and adds the objects to the list of objects
204621df5945SIngo Weinhold	# to be linked into the library.
204721df5945SIngo Weinhold	# <libname> The name of the library.
204821df5945SIngo Weinhold	# <sources> The sources.
204921df5945SIngo Weinhold
205021df5945SIngo Weinhold	local library = lib$(1).so ;
205121df5945SIngo Weinhold	local sources = $(2) ;
205228d2a30eSDaniel Reinhold	SetupIncludes ;
205321df5945SIngo Weinhold	SetupObjectsDir ;
205421df5945SIngo Weinhold	MakeLocateObjects $(sources) ;
205521df5945SIngo Weinhold	Objects $(sources) ;
205621df5945SIngo Weinhold	LIBRARY_OBJECTS on $(library) += [ FGristFiles $(sources:S=$(SUFOBJ)) ] ;
205721df5945SIngo Weinhold}
205821df5945SIngo Weinhold
205921df5945SIngo Weinholdrule FT2_LinkLibrary
206021df5945SIngo Weinhold{
206121df5945SIngo Weinhold	# FT2_LinkLibrary <libname>
206221df5945SIngo Weinhold	# Links the library from the objects build with FT2_LIBRARY before.
206321df5945SIngo Weinhold
206421df5945SIngo Weinhold	local library = lib$(1).so ;
206521df5945SIngo Weinhold	local objects = [ on $(library) return $(LIBRARY_OBJECTS) ] ;
206621df5945SIngo Weinhold	ObjectReferences $(objects) ;
206721df5945SIngo Weinhold	objects = [ FGristFiles $(objects) ] ;
206821df5945SIngo Weinhold	SharedLibraryFromObjects $(1) : $(objects) ;
206921df5945SIngo Weinhold}
207021df5945SIngo Weinhold
20719b7a4b5dSshatty#-------------------------------------------------------------------------------
20729b7a4b5dSshatty# Packages for OBOS alpha/beta testers
20739b7a4b5dSshatty#-------------------------------------------------------------------------------
20749b7a4b5dSshatty
20759b7a4b5dSshattyrule Copy
20769b7a4b5dSshatty{
20775c413522Sshatty	Depends $(<) : $(>) ;
20789b7a4b5dSshatty	SEARCH on $(>) = $(SEARCH_SOURCE) ;
20799b7a4b5dSshatty}
20809b7a4b5dSshatty
20819b7a4b5dSshattyactions Copy
20829b7a4b5dSshatty{
208315716fddSPhilippe Houdoin	cp -dp "$(>)" "$(<)" ;
208415716fddSPhilippe Houdoin	if [ -f "$(>)" ] ; then copyattr "$(>)" "$(<)" ; fi ;
20859b7a4b5dSshatty}
20869b7a4b5dSshatty
20879b7a4b5dSshattyrule Packages
20889b7a4b5dSshatty{
20899b7a4b5dSshatty	local packagenames = $(1) ;
20909b7a4b5dSshatty	local packagefiles = $(2) ;
20919b7a4b5dSshatty	local path = $(3) ;
20929b7a4b5dSshatty	for name in $(packagenames) {
20939b7a4b5dSshatty		Package $(name) : $(packagefiles) : $(path) ;
20949b7a4b5dSshatty    }
20959b7a4b5dSshatty}
20969b7a4b5dSshatty
20979b7a4b5dSshattyrule Package
20989b7a4b5dSshatty{
20999b7a4b5dSshatty	local packagename = $(1) ;
21009b7a4b5dSshatty    local packagefiles = $(2) ;
21019b7a4b5dSshatty	local path = $(3) ;
21029b7a4b5dSshatty
2103c06f365fSIngo Weinhold	local packagezip = $(packagename:S=.zip:G=_packages) ;
21049b7a4b5dSshatty	local packagedir = [ FDirName $(OBOS_PACKAGE_DIR) $(packagename) ] ;
21059b7a4b5dSshatty
21069b7a4b5dSshatty    local installscript = install.sh ;
2107c06f365fSIngo Weinhold	local packageinstallscript = $(installscript:G=_packages!$(packagename)) ;
21089b7a4b5dSshatty    local installzip = install.zip ;
2109c06f365fSIngo Weinhold	local packageinstallzip = $(installzip:G=_packages!$(packagename)) ;
21109b7a4b5dSshatty
2111c06f365fSIngo Weinhold    local packageobjectdir
2112c06f365fSIngo Weinhold    	= [ FDirName $(OBOS_PACKAGE_OBJECT_DIR) $(packagename) ] ;
21139b7a4b5dSshatty	local packagefiledir =  [ FDirName $(packageobjectdir) $(path) ] ;
2114c06f365fSIngo Weinhold    local packagefileinstallzip
2115c06f365fSIngo Weinhold    	= $(installzip:G=_package_objects!$(packagename)) ;
2116c06f365fSIngo Weinhold
2117c06f365fSIngo Weinhold	# add the files to the install.zip
2118c06f365fSIngo Weinhold	local packagefilegrist = [ FGrist _package_files $(packagename) $(path) ] ;
21199b7a4b5dSshatty    for file in $(packagefiles) {
21209b7a4b5dSshatty		if $(3[0]) = "boot" {
2121c06f365fSIngo Weinhold			local packagefile = $(file:G=$(packagefilegrist)) ;
21229b7a4b5dSshatty			MakeLocate $(packagefile) : $(packagefiledir) ;
21239b7a4b5dSshatty			Copy $(packagefile) : $(file) ;
21249b7a4b5dSshatty			Clean cleanPackages : $(packagefile) ;
21259b7a4b5dSshatty			PackageInstallZip $(packagefileinstallzip) : $(packagefile) ;
21269b7a4b5dSshatty		} else {
2127c06f365fSIngo Weinhold			local packagefile = $(file:G=_packages!$(packagename)) ;
21289b7a4b5dSshatty			MakeLocate $(packagefile) : $(packagedir) ;
212982bec102Sshatty			Copy $(packagefile) : [ FGristFiles $(file) ] ;
21309b7a4b5dSshatty			Clean cleanPackages : $(packagefile) ;
21319b7a4b5dSshatty			Depends $(packagezip) : $(packagefile) ;
21329b7a4b5dSshatty		}
21339b7a4b5dSshatty	}
2134c06f365fSIngo Weinhold
2135c06f365fSIngo Weinhold	# general setup for this packages -- only on first invocation
2136c06f365fSIngo Weinhold	if ! $(_setup_$(packagename)) {
2137c06f365fSIngo Weinhold		_setup_$(packagename) = true ;
2138c06f365fSIngo Weinhold
2139c06f365fSIngo Weinhold		NotFile $(packagename) ;
2140c06f365fSIngo Weinhold		Depends packages : $(packagename) ;
2141c06f365fSIngo Weinhold
2142c06f365fSIngo Weinhold		MakeLocate $(packagezip) : $(OBOS_PACKAGE_DIR) ;
2143c06f365fSIngo Weinhold		MakeLocate $(packageinstallscript) : $(packagedir) ;
2144c06f365fSIngo Weinhold		MakeLocate $(packageinstallzip) : $(packagedir) ;
2145c06f365fSIngo Weinhold		MakeLocate $(packagefileinstallzip) : $(packageobjectdir) ;
2146c06f365fSIngo Weinhold
21479b7a4b5dSshatty		PackageInstallScript $(packageinstallscript) : $(packagedir) ;
21489b7a4b5dSshatty		LinkInstallZip $(packageinstallzip) : $(packagefileinstallzip) ;
21499b7a4b5dSshatty		Depends $(packagename) : $(packagezip) ;
2150c06f365fSIngo Weinhold		PackageZip $(packagezip) : $(packagedir)
2151c06f365fSIngo Weinhold			: $(packageinstallscript) $(packageinstallzip) ;
2152c06f365fSIngo Weinhold	}
2153c06f365fSIngo Weinhold
21549b7a4b5dSshatty}
21559b7a4b5dSshatty
21569b7a4b5dSshattyrule PackageZip
21579b7a4b5dSshatty{
2158c06f365fSIngo Weinhold	local dir = $(2:G=dir) ;
2159c06f365fSIngo Weinhold	Depends $(1) : $(dir) $(3) ;
21609b7a4b5dSshatty	Clean cleanPackages : $(1) ;
2161c06f365fSIngo Weinhold	PackageZip1 $(1) : $(dir) ;
21629b7a4b5dSshatty}
21639b7a4b5dSshatty
2164c06f365fSIngo Weinholdactions together PackageZip1 {
21658042d2a0SPhilippe Houdoin	cd "$(OBOS_PACKAGE_DIR)" ;
21668042d2a0SPhilippe Houdoin	zip -rq "$(1:BS)" "$(2:BS)" ;
21679b7a4b5dSshatty}
21689b7a4b5dSshatty
21699b7a4b5dSshattyrule PackageInstallScript
21709b7a4b5dSshatty{
21719b7a4b5dSshatty	MakeLocate $(1) : $(2) ;
21729b7a4b5dSshatty	Clean cleanPackages : $(1) ;
2173c06f365fSIngo Weinhold	PackageInstallScript1 $(1) : $(2:G=dir) ;
21749b7a4b5dSshatty}
21759b7a4b5dSshatty
2176c06f365fSIngo Weinholdactions together PackageInstallScript1
21779b7a4b5dSshatty{
217851fe1be4Sshattyecho '#!/bin/sh
217951fe1be4Sshattybase=`dirname "$0"`
21808042d2a0SPhilippe Houdoincd "$base"
218151fe1be4Sshattyif [ -n "$TTY" ]
218251fe1be4Sshattythen
218351fe1be4Sshatty    unzip -d / install.zip
218451fe1be4Sshattyelse
218551fe1be4Sshatty    response=`alert "Would you like to automatically overwrite existing files, or receive a prompt?" "Overwrite" "Prompt"`
218651fe1be4Sshatty    if [ $response == "Overwrite" ]
218751fe1be4Sshatty    then
218851fe1be4Sshatty        unzip -od / install.zip
218951fe1be4Sshatty        alert "Finished installing" "Thanks"
219051fe1be4Sshatty    else
219151fe1be4Sshatty        if [ -e /boot/beos/apps/Terminal ]
219251fe1be4Sshatty        then
219351fe1be4Sshatty            terminal=/boot/beos/apps/Terminal
219451fe1be4Sshatty        else
219551fe1be4Sshatty            terminal=`query Terminal | head -1`
219651fe1be4Sshatty        fi
21978042d2a0SPhilippe Houdoin        $terminal -t "installer" /bin/sh "$0"
219851fe1be4Sshatty    fi
21998042d2a0SPhilippe Houdoinfi' > "$(1)" ;
22008042d2a0SPhilippe Houdoin	chmod 755 "$(1)" ;
22019b7a4b5dSshatty}
22029b7a4b5dSshatty
22039b7a4b5dSshattyrule PackageInstallZip
22049b7a4b5dSshatty{
22059b7a4b5dSshatty	Depends $(1) : $(2) ;
22069b7a4b5dSshatty	Clean cleanPackages : $(1) ;
22079b7a4b5dSshatty}
22089b7a4b5dSshatty
22099b7a4b5dSshattyactions together PackageInstallZip
22109b7a4b5dSshatty{
22118042d2a0SPhilippe Houdoin	cd "$(1:P)" ;
22128042d2a0SPhilippe Houdoin	zip -rqy "$(1:BS)" boot ;
22139b7a4b5dSshatty}
22149b7a4b5dSshatty
22159b7a4b5dSshattyrule LinkInstallZip
22169b7a4b5dSshatty{
22179b7a4b5dSshatty	Depends $(1) : $(2) ;
22189b7a4b5dSshatty	Clean cleanPackages : $(1) ;
22199b7a4b5dSshatty}
22209b7a4b5dSshatty
22219b7a4b5dSshattyactions together LinkInstallZip
22229b7a4b5dSshatty{
22238042d2a0SPhilippe Houdoin	ln -sf "`pwd`/$(2)" "$(1)" ;
22249b7a4b5dSshatty}
2225e91f3ca1Sbeveloper
2226e91f3ca1Sbeveloperrule SubIncludeGPL
2227e91f3ca1Sbeveloper{
2228e91f3ca1Sbeveloper	# SubInclude rule that can be used to conditionally include GPL licensed add-ons
2229e91f3ca1Sbeveloper	if $(INCLUDE_GPL_ADDONS) = 1 {
2230e91f3ca1Sbeveloper		SubInclude $(1) ;
2231e91f3ca1Sbeveloper	}
2232e91f3ca1Sbeveloper}
2233