xref: /haiku/Jamrules (revision b1e5b60ccffa844d663fbca95f61156b90d360e3)
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
37*b1e5b60cSAxel Dörfler# Include BuildConfig/Timezones/libgccObjects
3852a38012Sejakowatz{
394ff6d49fSIngo Weinhold	local buildConfig = [ GLOB $(OBOS_BUILD_DIR) : BuildConfig ] ;
40*b1e5b60cSAxel Dörfler	local timezones = [ GLOB $(OBOS_BUILD_DIR) : Timezones ] ;
41*b1e5b60cSAxel Dörfler	local libgccObjects = [ GLOB $(OBOS_BUILD_DIR) : libgccObjects ] ;
42*b1e5b60cSAxel Dörfler
43*b1e5b60cSAxel Dörfler	if ! $(buildConfig) {
44*b1e5b60cSAxel Dörfler		ECHO "No `BuildConfig' found in $(OBOS_BUILD_DIR)!" ;
454ff6d49fSIngo Weinhold		EXIT "Run ./configure in the source tree's root directory first!" ;
4652a38012Sejakowatz	}
47*b1e5b60cSAxel Dörfler	if ! ( $(timezones) && $(libgccObjects) ) {
48*b1e5b60cSAxel Dörfler		ECHO "No `Timezones' or `libgccObjects' found in $(OBOS_BUILD_DIR)!" ;
49*b1e5b60cSAxel Dörfler		EXIT "Please run ./configure in the source tree's root directory again!" ;
50*b1e5b60cSAxel Dörfler	}
51*b1e5b60cSAxel Dörfler
524ff6d49fSIngo Weinhold	LOCATE on BuildConfig = $(OBOS_BUILD_DIR) ;
53*b1e5b60cSAxel Dörfler	LOCATE on Timezones = $(OBOS_BUILD_DIR) ;
54*b1e5b60cSAxel Dörfler	LOCATE on libgccObjects = $(OBOS_BUILD_DIR) ;
55*b1e5b60cSAxel Dörfler
564ff6d49fSIngo Weinhold	include BuildConfig ;
57*b1e5b60cSAxel Dörfler	include Timezones ;
58*b1e5b60cSAxel Dörfler	include libgccObjects ;
5952a38012Sejakowatz}
6052a38012Sejakowatz
618c17a26bSIngo Weinhold# analyze GCC version
628c17a26bSIngo Weinholdif ! $(GCC_RAW_VERSION) {
638c17a26bSIngo Weinhold	ECHO "Variable GCC_RAW_VERSION not set. Please run ./configure or" ;
648c17a26bSIngo Weinhold	EXIT "specify it manually." ;
658c17a26bSIngo Weinhold}
668c17a26bSIngo WeinholdGCC_VERSION = ;
678c17a26bSIngo Weinhold{
688c17a26bSIngo Weinhold	# split the raw version string at `.' and `-' characters
698c17a26bSIngo Weinhold	local version = $(GCC_RAW_VERSION) ;
708c17a26bSIngo Weinhold	while $(version) {
718c17a26bSIngo Weinhold		local split = [ Match "([^.-]*)[.-](.*)" : $(version) ] ;
728c17a26bSIngo Weinhold		if $(split) {
738c17a26bSIngo Weinhold			GCC_VERSION += $(split[1]) ;
748c17a26bSIngo Weinhold			version = $(split[2]) ;
758c17a26bSIngo Weinhold		} else {
768c17a26bSIngo Weinhold			GCC_VERSION += $(version) ;
778c17a26bSIngo Weinhold			version = ;
788c17a26bSIngo Weinhold		}
798c17a26bSIngo Weinhold	}
808c17a26bSIngo Weinhold}
818c17a26bSIngo Weinhold
825dc4e1efSIngo Weinhold# Save the platform default headers.
835dc4e1efSIngo WeinholdPLATFORM_DEFAULT_HEADERS = $(HDRS) ;
845dc4e1efSIngo Weinhold
85705fc998SAxel Dörfler# Add some grist to the libgcc objects
86705fc998SAxel DörflerLIBGCC_OBJECTS = $(LIBGCC_OBJECTS:G=libgcc) ;
87705fc998SAxel Dörfler
88a6c008e1Sbeveloper# We do not include any local BeOS system headers by default
89dd9f8062SIngo WeinholdCCFLAGS += -nostdinc ;
90dd9f8062SIngo WeinholdC++FLAGS += -nostdinc ;
91a6c008e1Sbeveloper
922abad45eSbeveloper# Allow compiling unit tests on Zeta. Instead of fixing the PostMessage()
932abad45eSbeveloper# issues, they deprecated that nice function. This will enable it again:
942abad45eSbeveloperC++FLAGS += -D_ZETA_USING_DEPRECATED_API_=1 ;
952abad45eSbeveloper
964bb19442Sshattyif ! $(TARGET_PLATFORM) {
974bb19442Sshatty	ECHO "Variable TARGET_PLATFORM not set. Please run ./configure or" ;
984bb19442Sshatty	EXIT "specify it manually." ;
994bb19442Sshatty}
100a17b9c0cSshattyswitch $(TARGET_PLATFORM)
101a17b9c0cSshatty{
102a17b9c0cSshatty	case r5 :
103a17b9c0cSshatty	{
1044bb19442Sshatty		# "everything" is r5 compatible
105be1aef42Sshatty	}
106a17b9c0cSshatty	case bone :
107a17b9c0cSshatty	{
108a17b9c0cSshatty		BONE_COMPATIBLE = true ;
109a17b9c0cSshatty	}
110a17b9c0cSshatty	case dano :
111a17b9c0cSshatty	{
112a17b9c0cSshatty		BONE_COMPATIBLE = true ;
113a17b9c0cSshatty		DANO_COMPATIBLE = true ;
114a17b9c0cSshatty	}
115a17b9c0cSshatty	case haiku :
116a17b9c0cSshatty	{
117a17b9c0cSshatty		BONE_COMPATIBLE = true ;
118a17b9c0cSshatty		DANO_COMPATIBLE = true ;
119a17b9c0cSshatty		HAIKU_COMPATIBLE = true ;
120a104c31bSshatty		DEFINES += __HAIKU__ ;
121a17b9c0cSshatty	}
122a17b9c0cSshatty}
1236040be99Sshattyif $(BONE_COMPATIBLE) {
1246040be99Sshatty	NETWORK_LIBS = libsocket.so libbind.so ;
1252506bbb6Sshatty	SELECT_UNAME_ETC_LIB = libroot.so ;
1266040be99Sshatty} else {
1276040be99Sshatty	NETWORK_LIBS = libnet.so ;
1282506bbb6Sshatty	SELECT_UNAME_ETC_LIB = libnet.so ;
1296040be99Sshatty}
130be1aef42Sshatty
13152a38012Sejakowatz# Determine if we're building on PPC or x86
13252a38012Sejakowatz# Determine mimetype of executable
13352a38012Sejakowatz# Cross compiling can come later
13452a38012Sejakowatz
135c9882d9eSAxel DörflerTARGET_CPU ?= $(OSPLAT:L) ;
1361f622a7bSAxel DörflerOBOS_VERSION ?= R1 ;
1371f622a7bSAxel Dörfler
1381f622a7bSAxel Dörflerswitch $(TARGET_CPU) {
1391f622a7bSAxel Dörfler	case ppc :
1401f622a7bSAxel Dörfler	{
14152a38012Sejakowatz		if $(METROWERKS) {
1421f622a7bSAxel Dörfler			# at least parts of OpenBeOS still can be compiled with
1431f622a7bSAxel Dörfler			# the Metrowerks compiler on BeOS/PPC
14452a38012Sejakowatz			OBOS_TARGET_TYPE ?= "application/x-be-executable" ;
14552a38012Sejakowatz		} else {
14652a38012Sejakowatz			OBOS_TARGET_TYPE ?= "application/x-vnd.Be-elfexecutable" ;
1471f622a7bSAxel Dörfler		}
148894d1636Sshatty		DEFINES += __POWERPC__ ARCH_ppc ;
149e29d8533SAxel Dörfler		OBOS_BOOT_PLATFORM = openfirmware ;
1501f622a7bSAxel Dörfler	}
1511f622a7bSAxel Dörfler	case x86 :
1521f622a7bSAxel Dörfler	{
1531f622a7bSAxel Dörfler		# nothing special to do here...
154894d1636Sshatty		DEFINES += __INTEL__ ARCH_x86 ;
155e29d8533SAxel Dörfler		OBOS_BOOT_PLATFORM = bios_ia32 ;
1561f622a7bSAxel Dörfler	}
1571f622a7bSAxel Dörfler	case * :
1581f622a7bSAxel Dörfler		Exit "Currently unsupported build platform:" $(TARGET_CPU) ;
1591f622a7bSAxel Dörfler}
1601f622a7bSAxel Dörfler
1611f622a7bSAxel Dörfler# set target specific variables
1621f622a7bSAxel Dörfler{
1631f622a7bSAxel Dörfler	#Echo "Building for" $(TARGET_CPU) ;
1641f622a7bSAxel Dörfler
1651f622a7bSAxel Dörfler	OBOS_TARGET ?= $(TARGET_CPU).$(OBOS_VERSION) ;
1661f622a7bSAxel Dörfler	OBOS_TARGET_TYPE ?= "application/x-vnd.Be-elfexecutable" ;
1671f622a7bSAxel Dörfler	OBOS_ARCH ?= $(TARGET_CPU) ;
1681f622a7bSAxel Dörfler	OBOS_TARGET_DEFINE ?= "ARCH_"$(TARGET_CPU) ;
16952a38012Sejakowatz}
17052a38012Sejakowatz
17165c62a01SIngo Weinhold# Disable warnings only if WARNINGS is set to 0
172e5dc2d93Sbeveloper# Should be enabled by default later
17396d27465SIngo Weinhold#
17465c62a01SIngo WeinholdWARNINGS ?= 1 ;
17565c62a01SIngo Weinholdif $(WARNINGS) = 1 {
176e5dc2d93Sbeveloper	# For an explanation of the different warning options, see:
177e5dc2d93Sbeveloper	# http://gcc.gnu.org/onlinedocs/gcc-2.95.3/gcc_2.html
178e5dc2d93Sbeveloper	# to get even more warnings, add:
179e5dc2d93Sbeveloper	# -Wwrite-strings  	(doesn't work well with some Be headers)
180e5dc2d93Sbeveloper	# -Wundef			(dito)
181e5dc2d93Sbeveloper	# -Wconversion		(gets you many warnings about implicit conversions)
182e5dc2d93Sbeveloper	# -W				(gets you even more warnigs)
183dd9f8062SIngo Weinhold	CCFLAGS += -Wall -Wno-multichar -Wmissing-prototypes ;
184dd9f8062SIngo Weinhold	CCFLAGS += -Wpointer-arith -Wcast-align -Wsign-compare ;
185dd9f8062SIngo Weinhold	C++FLAGS += -Wall -Wno-multichar -Wmissing-prototypes -Wno-ctor-dtor-privacy -Woverloaded-virtual ;
186dd9f8062SIngo Weinhold	C++FLAGS += -Wpointer-arith -Wcast-align -Wsign-compare ;
18798cc804cSAxel Dörfler} else {
18898cc804cSAxel Dörfler	CCFLAGS += -Wno-multichar ;
18998cc804cSAxel Dörfler	C++FLAGS += -Wno-multichar ;
190e5dc2d93Sbeveloper}
191e5dc2d93Sbeveloper
19298cc804cSAxel Dörfler# standard kernel C/C++ flags
1930ff867c2SbeveloperKERNEL_CCFLAGS ?= -Wall -Wno-multichar -Wmissing-prototypes -finline -nostdinc ;
1944d74cda3SAxel DörflerKERNEL_CCFLAGS += -fno-builtin -D$(OBOS_TARGET_DEFINE) -D__HAIKU__ ;
195ea7627e5SAxel DörflerKERNEL_CCFLAGS += -DBOCHS_DEBUG_HACK=$(BOCHS_DEBUG_HACK) -D_KERNEL_MODE ;
19698cc804cSAxel DörflerKERNEL_C++FLAGS ?= -Wall -Wno-multichar -Wmissing-prototypes -finline -nostdinc ;
1974d74cda3SAxel DörflerKERNEL_C++FLAGS += -fno-builtin -fno-exceptions -D$(OBOS_TARGET_DEFINE) -D__HAIKU__ ;
198ea7627e5SAxel DörflerKERNEL_C++FLAGS += -DBOCHS_DEBUG_HACK=$(BOCHS_DEBUG_HACK) -D_KERNEL_MODE ;
199bbb6f2d4SAxel Dörflerif $(GCC_VERSION[1]) >= 3 {
200bbb6f2d4SAxel Dörfler	KERNEL_C++FLAGS += -fno-use-cxa-atexit ;
201bbb6f2d4SAxel Dörfler}
2020ff867c2Sbeveloper
2039eea4522SIngo Weinhold# We might later want to introduce debug levels or handle the whole issue
2049eea4522SIngo Weinhold# differently. For now there's only on or off.
2059eea4522SIngo Weinhold#
20665c62a01SIngo WeinholdDEBUG ?= 0 ;
20765c62a01SIngo Weinholdif $(DEBUG) != 0 {
2089eea4522SIngo Weinhold	OPTIM ?= -O0 ;
20965c62a01SIngo Weinhold	CCFLAGS += -g [ FDefines DEBUG=$(DEBUG) ] ;
21065c62a01SIngo Weinhold	C++FLAGS += -g [ FDefines DEBUG=$(DEBUG) ] ;
21165c62a01SIngo Weinhold	KERNEL_CCFLAGS += -g [ FDefines DEBUG=$(DEBUG) ] ;
21265c62a01SIngo Weinhold	KERNEL_C++FLAGS += -g [ FDefines DEBUG=$(DEBUG) ] ;
2139eea4522SIngo Weinhold	LINKFLAGS += -g ;
2149eea4522SIngo Weinhold} else {
2159eea4522SIngo Weinhold	OPTIM ?= -O2 ;
2169eea4522SIngo Weinhold}
21796d27465SIngo Weinhold#
21896d27465SIngo Weinhold# To disable for the tests OPTIM and DEBUG are overridden, set the environment
21996d27465SIngo Weinhold# variable NO_TEST_DEBUG.
2209eea4522SIngo Weinhold
221d5807053SIngo Weinhold# If the environment variable DEBUG_PRINTF is defined we define an equally
222d5807053SIngo Weinhold# named macro to the variable value. Some components use the macro to allow
223d5807053SIngo Weinhold# another function than printf() to print the debug output. The variable should
224d5807053SIngo Weinhold# be set to the name of the alternative function.
225d5807053SIngo Weinhold#
226d5807053SIngo Weinholdif $(DEBUG_PRINTF) {
227d5807053SIngo Weinhold	CCFLAGS += [ FDefines DEBUG_PRINTF=$(DEBUG_PRINTF) ] ;
228d5807053SIngo Weinhold	C++FLAGS += [ FDefines DEBUG_PRINTF=$(DEBUG_PRINTF) ] ;
229d5807053SIngo Weinhold}
230d5807053SIngo Weinhold
23116fa4445SIngo Weinhold# Instructs the Library rule to not make its object files temporary.
232f1e077f8SIngo Weinhold# This is needed as some objects are used in a static library and for an
23316fa4445SIngo Weinhold# executable.
23416fa4445SIngo WeinholdKEEPOBJS = true ;
23516fa4445SIngo Weinhold
2367bc56df1SIngo Weinhold# under BeOS use copyattr instead of cp
2377bc56df1SIngo Weinholdif $(OS) = BEOS
2387bc56df1SIngo Weinhold{
2397bc56df1SIngo Weinhold	CP = copyattr --data ;
2407bc56df1SIngo Weinhold}
2417bc56df1SIngo Weinhold
24253cf6d7aSAxel Dörfler# for builds of tools in the current environment
24353cf6d7aSAxel Dörflerif $(OS) = BEOS {
24453cf6d7aSAxel Dörfler	BUILD_LIBSTDC++ = stdc++.r4 ;
24553cf6d7aSAxel Dörfler} else {
24653cf6d7aSAxel Dörfler	BUILD_LIBSTDC++ = stdc++ ;
24753cf6d7aSAxel Dörfler}
24853cf6d7aSAxel Dörfler
24952a38012Sejakowatz# If no OBOS_OBJECT_TARGET is not defined yet, use our default directory and
25052a38012Sejakowatz# include our "OBOS_TARGET" as subdirectory in there (to prevent different
25152a38012Sejakowatz# builds mixing objects from different targets).
25252a38012Sejakowatzif ! $(OBOS_OBJECT_TARGET) {
25352a38012Sejakowatz	OBOS_OBJECT_TARGET ?= [ FDirName $(OBOS_TOP) objects $(OBOS_TARGET) ] ;
25452a38012Sejakowatz}
25552a38012Sejakowatz
25652a38012Sejakowatz# If no OBOS_DISTRO_TARGET is not defined yet, use our default directory and
25752a38012Sejakowatz# include our "OBOS_TARGET" as subdirectory in there (to prevent different
25852a38012Sejakowatz# builds mixing executables from different targets).
25952a38012Sejakowatzif ! $(OBOS_DISTRO_TARGET) {
26052a38012Sejakowatz	OBOS_DISTRO_TARGET ?= [ FDirName $(OBOS_TOP) distro $(OBOS_TARGET) ] ;
26152a38012Sejakowatz}
26252a38012Sejakowatz
26352a38012Sejakowatz# Set our version number if not already set and mark it as a developer build
26452a38012Sejakowatzif ! $(OBOS_BUILD_VERSION) {
26552a38012Sejakowatz	OBOS_BUILD_VERSION ?= "1 0 0 a 1" ;
26652a38012Sejakowatz	OBOS_BUILD_DESCRIPTION ?= "Developer Build" ;
26752a38012Sejakowatz}
26852a38012Sejakowatz
26952a38012Sejakowatz# If OBOS_BUILD_VERSION is set, but OBOS_BUILD_DESCRIPTION isn't, mark it as
27052a38012Sejakowatz# an unknown build.
27152a38012Sejakowatzif ! $(OBOS_BUILD_DESCRIPTION) {
27252a38012Sejakowatz	OBOS_BUILD_DESCRIPTION ?= "Unknown Build" ;
27352a38012Sejakowatz}
27452a38012Sejakowatz
275505554b4SIngo Weinhold# Relative subdirs for distro dir
276505554b4SIngo WeinholdOBOS_ADDON_DIR  ?= [ FDirName $(OBOS_DISTRO_TARGET) beos system add-ons ] ;
2775f281ed5SejakowatzOBOS_APPS_DIR   ?= [ FDirName $(OBOS_DISTRO_TARGET) beos apps ] ;
278f06de7f3SIngo WeinholdOBOS_BIN_DIR    ?= [ FDirName $(OBOS_DISTRO_TARGET) beos bin ] ;
279505554b4SIngo WeinholdOBOS_ETC_DIR    ?= [ FDirName $(OBOS_DISTRO_TARGET) beos etc ] ;
280505554b4SIngo WeinholdOBOS_FONTS_DIR  ?= [ FDirName $(OBOS_ETC_DIR) fonts ] ;
281505554b4SIngo WeinholdOBOS_KERNEL_DIR ?= [ FDirName $(OBOS_DISTRO_TARGET) beos system ] ;
28252a38012SejakowatzOBOS_PREFS_DIR  ?= [ FDirName $(OBOS_DISTRO_TARGET) beos preferences ] ;
28352a38012SejakowatzOBOS_SERVER_DIR ?= [ FDirName $(OBOS_DISTRO_TARGET) beos system servers ] ;
28452a38012SejakowatzOBOS_SHLIB_DIR  ?= [ FDirName $(OBOS_DISTRO_TARGET) beos system lib ] ;
285e9230d05SIngo WeinholdOBOS_STLIB_DIR  ?= [ FDirName $(OBOS_DISTRO_TARGET) develop lib
286e9230d05SIngo Weinhold							  $(OBOS_ARCH) ] ;
28752a38012SejakowatzOBOS_TEST_DIR   ?= [ FDirName $(OBOS_TOP) tests ] ;
28852a38012Sejakowatz
289c06f365fSIngo WeinholdOBOS_PACKAGE_DIR ?= [ FDirName $(OBOS_TOP) packages $(OBOS_TARGET) ] ;
290c06f365fSIngo WeinholdOBOS_PACKAGE_OBJECT_DIR ?= [ FDirName $(OBOS_OBJECT_TARGET) packages ] ;
291c06f365fSIngo Weinhold
29252a38012SejakowatzOBOS_KERNEL_CONFIG = config.$(OBOS_ARCH).ini ;
29352a38012SejakowatzOBOS_KERNEL = kernel.$(OBOS_ARCH) ;
29452a38012SejakowatzOBOS_FLOPPY = floppy.$(OBOS_ARCH) ;
29552a38012Sejakowatz
29652a38012Sejakowatzrule SetupIncludes
29752a38012Sejakowatz{
298cfc7b456Sshatty	# XXX add "opengl" later
299cfc7b456Sshatty	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 ;
300a6c008e1Sbeveloper
30128d2a30eSDaniel Reinhold	# Overwrite any exiting content when changing HDRS. This rule may be invoked multiple times.
302a6c008e1Sbeveloper
303a6c008e1Sbeveloper	# Use headers directory, to allow to do things like include <posix/string.h>
30428d2a30eSDaniel Reinhold	HDRS = [ FDirName $(OBOS_TOP) headers ] ;
305a6c008e1Sbeveloper
306a6c008e1Sbeveloper	# Use posix headers directory
30728d2a30eSDaniel Reinhold	HDRS += [ FDirName $(OBOS_TOP) headers posix ] ;
308a6c008e1Sbeveloper
309a6c008e1Sbeveloper	# Use public OS header directories
31028d2a30eSDaniel Reinhold	HDRS += [ PublicHeaders $(os_includes) ] ;
311a6c008e1Sbeveloper
312c0e501e0SIngo Weinhold	# Use the root of the private headers -- not so nice, but simplifies things.
313c0e501e0SIngo Weinhold	HDRS += [ PrivateHeaders $(DOT) ] ;
314c0e501e0SIngo Weinhold
315a6c008e1Sbeveloper	# Used as a fallback, the R5 header directories (we should remove this as soon as possible)
31628d2a30eSDaniel Reinhold	HDRS += /boot/develop/headers/posix /boot/develop/headers/cpp ;
31709c5682dSIngo Weinhold
31809c5682dSIngo Weinhold	# The platform dependent headers.
31909c5682dSIngo Weinhold	HDRS += $(PLATFORM_HEADERS) ;
32052a38012Sejakowatz}
32152a38012Sejakowatz
322dd9f8062SIngo Weinholdrule SetupR5Includes
323dd9f8062SIngo Weinhold{
324dd9f8062SIngo Weinhold	# Unsets HDRS, so that the OBOS headers do not `shadow' the system headers.
325dd9f8062SIngo Weinhold	HDRS = ;
326dd9f8062SIngo Weinhold}
327dd9f8062SIngo Weinhold
3285dc4e1efSIngo Weinholdrule SetupDefaultIncludes
3295dc4e1efSIngo Weinhold{
3305dc4e1efSIngo Weinhold	# Resets HDRS to the default headers for the build platform.
3315dc4e1efSIngo Weinhold	HDRS = $(PLATFORM_DEFAULT_HEADERS) ;
3325dc4e1efSIngo Weinhold}
3335dc4e1efSIngo Weinhold
33452a38012Sejakowatz#-------------------------------------------------------------------------------
33552a38012Sejakowatz# Things Jam needs in order to work :)
33652a38012Sejakowatz#-------------------------------------------------------------------------------
33752a38012Sejakowatz
338c06f365fSIngo Weinhold# TODO: back-ported from jam 2.5: remove when not longer needed
339c06f365fSIngo Weinholdrule MakeLocate
340c06f365fSIngo Weinhold{
341c06f365fSIngo Weinhold	if $(>)
342c06f365fSIngo Weinhold	{
343c06f365fSIngo Weinhold	    LOCATE on $(<) = $(>) ;
344c06f365fSIngo Weinhold	    Depends $(<) : $(>[1]:G=dir) ;
345c06f365fSIngo Weinhold	    MkDir $(>[1]:G=dir) ;
346c06f365fSIngo Weinhold	}
347c06f365fSIngo Weinhold}
348c06f365fSIngo Weinhold
3498d3308d9SIngo Weinholdrule Object
3508d3308d9SIngo Weinhold{
3518d3308d9SIngo Weinhold	# This is basically the original Jambase 2.4 Object rule stripped by
3528d3308d9SIngo Weinhold	# comments. Only the final switch statement has been changed to allow
3538d3308d9SIngo Weinhold	# intermediate C++ files for Yacc and Lex.
3548d3308d9SIngo Weinhold
3558d3308d9SIngo Weinhold	LocalClean clean : $(<) ;
3568d3308d9SIngo Weinhold
3578d3308d9SIngo Weinhold	MakeLocate $(<) : $(LOCATE_TARGET) ;
3588d3308d9SIngo Weinhold	SEARCH on $(>) = $(SEARCH_SOURCE) ;
3598d3308d9SIngo Weinhold
3608d3308d9SIngo Weinhold	HDRS on $(<) = $(SEARCH_SOURCE) $(SUBDIRHDRS) $(HDRS) ;
3618d3308d9SIngo Weinhold
3628d3308d9SIngo Weinhold	HDRRULE on $(>) = HdrRule ;
3638d3308d9SIngo Weinhold	HDRSCAN on $(>) = $(HDRPATTERN) ;
3648d3308d9SIngo Weinhold	HDRSEARCH on $(>) =
3658d3308d9SIngo Weinhold		$(SEARCH_SOURCE:E) $(SUBDIRHDRS) $(HDRS) $(STDHDRS) ;
3668d3308d9SIngo Weinhold
3678d3308d9SIngo Weinhold	HDRGRIST on $(>) = $(HDRGRIST) ;
3688d3308d9SIngo Weinhold
3698d3308d9SIngo Weinhold	DEFINES on $(<) += $(DEFINES) ;
3708d3308d9SIngo Weinhold
3718d3308d9SIngo Weinhold	# if source is not .c, generate .c with specific rule
3728d3308d9SIngo Weinhold
3738d3308d9SIngo Weinhold	switch $(>:S)
3748d3308d9SIngo Weinhold	{
3758d3308d9SIngo Weinhold	    case .asm : As $(<) : $(>) ;
3768d3308d9SIngo Weinhold	    case .c :	Cc $(<) : $(>) ;
3778d3308d9SIngo Weinhold	    case .C :	C++ $(<) : $(>) ;
3788d3308d9SIngo Weinhold	    case .cc :	C++ $(<) : $(>) ;
3798d3308d9SIngo Weinhold	    case .cpp : C++ $(<) : $(>) ;
3808d3308d9SIngo Weinhold	    case .f :	Fortran $(<) : $(>) ;
3818d3308d9SIngo Weinhold	    case .l :	if [ on $(2) return $(GENERATE_C++) ] {
3828d3308d9SIngo Weinhold						C++ $(<) : $(<:S=.cpp) ;
3838d3308d9SIngo Weinhold						LexC++ $(<:S=.cpp) : $(>) ;
3848d3308d9SIngo Weinhold					} else {
3858d3308d9SIngo Weinhold						Cc $(<) : $(<:S=.c) ;
3868d3308d9SIngo Weinhold						Lex $(<:S=.c) : $(>) ;
3878d3308d9SIngo Weinhold					}
3888d3308d9SIngo Weinhold	    case .s :	As $(<) : $(>) ;
3898d3308d9SIngo Weinhold	    case .y :	if [ on $(2) return $(GENERATE_C++) ] {
3908d3308d9SIngo Weinhold						C++ $(<) : $(<:S=.cpp) ;
3918d3308d9SIngo Weinhold						Bison $(<:S=.cpp) : $(>) ;
3928d3308d9SIngo Weinhold					} else {
3938d3308d9SIngo Weinhold						Cc $(<) : $(<:S=$(YACCGEN)) ;
3948d3308d9SIngo Weinhold						Yacc $(<:S=$(YACCGEN)) : $(>) ;
3958d3308d9SIngo Weinhold					}
3968d3308d9SIngo Weinhold	    case * :	UserObject $(<) : $(>) ;
3978d3308d9SIngo Weinhold	}
3988d3308d9SIngo Weinhold}
3998d3308d9SIngo Weinhold
40052a38012Sejakowatzrule UserObject
40152a38012Sejakowatz{
40252a38012Sejakowatz	switch $(2)
40352a38012Sejakowatz	{
40452a38012Sejakowatz	case *.S    : assemble $(1) : $(2) ;
40508125d07SIngo Weinhold	case *.o    : return ;
40652a38012Sejakowatz	case *      : ECHO "unknown suffix on" $(2) ;
40752a38012Sejakowatz	}
40852a38012Sejakowatz}
40952a38012Sejakowatz
41052a38012Sejakowatz# Override the default to give "prettier" command lines.
41152a38012Sejakowatzactions Cc
41252a38012Sejakowatz{
413025d0733SJérôme Duval	$(CC) $(CCFLAGS) -c "$(2)" $(CCDEFS) $(CCHDRS) -o "$(1)" ;
41452a38012Sejakowatz}
41552a38012Sejakowatz
41652a38012Sejakowatzactions C++
41752a38012Sejakowatz{
4180931b8f9SIngo Weinhold	$(C++) -c "$(2)" $(C++FLAGS) $(CCDEFS) $(CCHDRS) -o "$(1)" ;
41952a38012Sejakowatz}
42052a38012Sejakowatz
42152a38012Sejakowatz
42252a38012Sejakowatz#-------------------------------------------------------------------------------
42352a38012Sejakowatz# General High-level OBOS target rules
42452a38012Sejakowatz#-------------------------------------------------------------------------------
42552a38012Sejakowatz
4265f281ed5Sejakowatzrule App
4275f281ed5Sejakowatz{
42839a01fbbSshatty	# App <name> : <sources> : <libraries> : <res> ;
429a6c008e1Sbeveloper	SetupIncludes ;
4305f281ed5Sejakowatz	SetupObjectsDir ;
43139a01fbbSshatty	AddResources $(1) : $(4) ;
432007eb5f2SIngo Weinhold	Main $(1) : $(2) ;
433007eb5f2SIngo Weinhold	MakeLocate $(1) : $(OBOS_APPS_DIR) ;
434007eb5f2SIngo Weinhold	LinkSharedOSLibs $(1) : $(3) ;
435007eb5f2SIngo Weinhold	LINKFLAGS on $(1) = [ on $(1) return $(LINKFLAGS) ]
436007eb5f2SIngo Weinhold						-Xlinker -soname=_APP_ ;
4375f281ed5Sejakowatz}
4385f281ed5Sejakowatz
439f06de7f3SIngo Weinholdrule BinCommand
440f06de7f3SIngo Weinhold{
44111fa3682SJérôme Duval	# BinCommand <name> : <sources> : <libraries> : <res> ;
442a6c008e1Sbeveloper	SetupIncludes ;
443f06de7f3SIngo Weinhold	SetupObjectsDir ;
44411fa3682SJérôme Duval	AddResources $(1) : $(4) ;
445f06de7f3SIngo Weinhold	Main $(1) : $(2) ;
446f06de7f3SIngo Weinhold	MakeLocate $(1) : $(OBOS_BIN_DIR) ;
447f06de7f3SIngo Weinhold	LinkSharedOSLibs $(1) : $(3) ;
448007eb5f2SIngo Weinhold	LINKFLAGS on $(1) = [ on $(1) return $(LINKFLAGS) ]
449007eb5f2SIngo Weinhold						-Xlinker -soname=_APP_ ;
450f06de7f3SIngo Weinhold}
451f06de7f3SIngo Weinhold
452f06de7f3SIngo Weinholdrule StdBinCommands
453f06de7f3SIngo Weinhold{
45411fa3682SJérôme Duval	# StdBinCommands <sources> : <libs> : <res> ;
455a6c008e1Sbeveloper	SetupIncludes ;
456a6c008e1Sbeveloper	SetupObjectsDir ;
457f06de7f3SIngo Weinhold	local libs = $(2) ;
45811fa3682SJérôme Duval	local ress = $(3) ;
4599342c27aSIngo Weinhold	local source ;
460f06de7f3SIngo Weinhold	for source in $(1)
461f06de7f3SIngo Weinhold	{
462f06de7f3SIngo Weinhold		local target = $(source:S=) ;
463a6c008e1Sbeveloper
46411fa3682SJérôme Duval		BinCommand $(target) : $(source) : $(libs) : $(ress) ;
465f06de7f3SIngo Weinhold	}
466f06de7f3SIngo Weinhold}
467f06de7f3SIngo Weinhold
46852a38012Sejakowatzrule Preference
46952a38012Sejakowatz{
470007eb5f2SIngo Weinhold	# Preference <name> : <sources> : <libraries> ;
471a6c008e1Sbeveloper	SetupIncludes ;
47252a38012Sejakowatz	SetupObjectsDir ;
473007eb5f2SIngo Weinhold	Main $(1) : $(2) ;
474007eb5f2SIngo Weinhold	MakeLocate $(1) : $(OBOS_PREFS_DIR) ;
475007eb5f2SIngo Weinhold	LinkSharedOSLibs $(1) : $(3) ;
476007eb5f2SIngo Weinhold	LINKFLAGS on $(1) = [ on $(1) return $(LINKFLAGS) ]
477007eb5f2SIngo Weinhold						-Xlinker -soname=_APP_ ;
47852a38012Sejakowatz}
47952a38012Sejakowatz
48052a38012Sejakowatzrule Server
48152a38012Sejakowatz{
482007eb5f2SIngo Weinhold	# Server <name> : <sources> : <libraries> ;
48352a38012Sejakowatz
484a6c008e1Sbeveloper	SetupIncludes ;
48552a38012Sejakowatz	SetupObjectsDir ;
486007eb5f2SIngo Weinhold	Main $(1) : $(2) ;
487007eb5f2SIngo Weinhold	MakeLocate $(1) : $(OBOS_SERVER_DIR) ;
488007eb5f2SIngo Weinhold	LinkSharedOSLibs $(1) : $(3) ;
489007eb5f2SIngo Weinhold	LINKFLAGS on $(1) = [ on $(1) return $(LINKFLAGS) ]
490007eb5f2SIngo Weinhold						-Xlinker -soname=_APP_ ;
49152a38012Sejakowatz}
49252a38012Sejakowatz
49352a38012Sejakowatz# test pseudo targets
49452a38012SejakowatzNOTFILE obostests ;
49552a38012SejakowatzNOTFILE r5tests ;
49652a38012Sejakowatz
497d1f6c38fSTyler Dauwalderrule CommonTestLib
498d1f6c38fSTyler Dauwalder{
499c5ff4aa6STyler Dauwalder	# CommonTestLib <target> : <sources> : <obos libraries>
5009285de51STyler Dauwalder	#	: <r5 libraries> : <test libraries> : <public headers>;
501d1f6c38fSTyler Dauwalder	# Builds a unit test for both OBOS and R5 modules.
502d1f6c38fSTyler Dauwalder	# <target> The name of the target.
503d1f6c38fSTyler Dauwalder	# <sources> The list of sources.
504d1f6c38fSTyler Dauwalder	# <obos libraries> A list of link libraries for the OBOS tests (as passed
505d1f6c38fSTyler Dauwalder	# to LinkSharedOSLibs).
506d1f6c38fSTyler Dauwalder	# <r5 libraries> A list of link libraries for the R5 tests (as passed
507d1f6c38fSTyler Dauwalder	# to LinkSharedOSLibs).
5089285de51STyler Dauwalder	# <test libraries> A list of link libraries for both OBOS tests and R5 tests
5099285de51STyler Dauwalder	# that have a common name (i.e. specify libx.so and the OBOS tests will link
5109285de51STyler Dauwalder	# to libx.so and the R5 tests will link to libx_r5.so).
511d1f6c38fSTyler Dauwalder	# <public headers> A list of public header dirs (as passed to
512d1f6c38fSTyler Dauwalder	# UsePublicHeaders).
513d1f6c38fSTyler Dauwalder
514c5ff4aa6STyler Dauwalder	TestLib $(1) : $(2) : [ FDirName $(OBOS_TEST_DIR) unittester lib ] : $(3) $(5) : $(6) ;
515c5ff4aa6STyler Dauwalder	R5TestLib $(1) : $(2) : [ FDirName $(OBOS_TEST_DIR) unittester_r5 lib ] : $(4) [ R5SharedLibraryNames $(5) ] ;
516d1f6c38fSTyler Dauwalder}
517d1f6c38fSTyler Dauwalder
518d1f6c38fSTyler Dauwalderrule TestLib
519d1f6c38fSTyler Dauwalder{
520d1f6c38fSTyler Dauwalder	# TestLib <target> : <sources> : <dest> : <libraries> : <public headers>
521d1f6c38fSTyler Dauwalder	# Builds a unit test library for an OBOS module.
522d1f6c38fSTyler Dauwalder	# <target> The name of the target.
523d1f6c38fSTyler Dauwalder	# <sources> The list of sources.
524d1f6c38fSTyler Dauwalder	# <dest> The directory for the target (as passed to FDirName).
525d1f6c38fSTyler Dauwalder	# <libraries> A list of link libraries (as passed to LinkSharedOSLibs).
526d1f6c38fSTyler Dauwalder	# <public headers> A list of public header dirs (as passed to
527d1f6c38fSTyler Dauwalder	# UsePublicHeaders).
528d1f6c38fSTyler Dauwalder
529d1f6c38fSTyler Dauwalder	local target = $(1) ;
530d1f6c38fSTyler Dauwalder	local sources = $(2) ;
531d1f6c38fSTyler Dauwalder	local dest = $(3) ;
532d1f6c38fSTyler Dauwalder	local libraries = $(4) ;
533d1f6c38fSTyler Dauwalder	local headerDirs = $(5) ;
5349342c27aSIngo Weinhold	local objects = [ FGristFiles $(sources:S=$(SUFOBJ)) ] ;
535d1f6c38fSTyler Dauwalder
5369342c27aSIngo Weinhold	# Our Main replacement.
5379342c27aSIngo Weinhold	MainFromObjects $(target) : $(objects) ;
5389342c27aSIngo Weinhold	TestObjects $(sources) : $(headerDirs) ;
539d1f6c38fSTyler Dauwalder
540d1f6c38fSTyler Dauwalder	MakeLocate $(target) : $(dest) ;
5410d1cdd94SIngo Weinhold	Depends $(target) : libcppunit.so ;
5420d1cdd94SIngo Weinhold	Depends obostests : $(target) ;
543d1f6c38fSTyler Dauwalder	LinkSharedOSLibs $(target) : libcppunit.so $(libraries) ;
544d1f6c38fSTyler Dauwalder	LINKFLAGS on $(target) = $(LINKFLAGS) -nostart -Xlinker -soname=\"$(target)\" ;
545d1f6c38fSTyler Dauwalder}
546d1f6c38fSTyler Dauwalder
547d1f6c38fSTyler Dauwalderrule R5TestLib
548d1f6c38fSTyler Dauwalder{
549c5ff4aa6STyler Dauwalder	# R5TestLib <target> : <sources> : <dest> : <libraries>
550d1f6c38fSTyler Dauwalder	# Builds a unit test for an R5 module. "_r5" is appended to the object
551d1f6c38fSTyler Dauwalder	# and the target name.
552d1f6c38fSTyler Dauwalder	# <target> The name of the target.
553d1f6c38fSTyler Dauwalder	# <sources> The list of sources.
554d1f6c38fSTyler Dauwalder	# <dest> The directory for the target (as passed to FDirName).
555d1f6c38fSTyler Dauwalder	# <libraries> A list of link libraries (as passed to LinkSharedOSLibs).
556d1f6c38fSTyler Dauwalder
557d1f6c38fSTyler Dauwalder	local target = $(1:B)_r5$(1:S) ;
558d1f6c38fSTyler Dauwalder	local sources = $(2) ;
559c5ff4aa6STyler Dauwalder	local dest = $(3) ;
560d1f6c38fSTyler Dauwalder	local libraries = $(4) ;
561d1f6c38fSTyler Dauwalder	local objects = [ R5ObjectNames $(sources) ] ;
562d1f6c38fSTyler Dauwalder
563d1f6c38fSTyler Dauwalder	# Our Main replacement.
564d1f6c38fSTyler Dauwalder	MainFromObjects $(target) : $(objects) ;
5659342c27aSIngo Weinhold	TestObjects $(sources) : : true ;
566d1f6c38fSTyler Dauwalder
567d1f6c38fSTyler Dauwalder	MakeLocate $(target) : $(dest) ;
5680d1cdd94SIngo Weinhold	Depends $(target) : libcppunit.so ;
5690d1cdd94SIngo Weinhold	Depends r5tests : $(target) ;
570d1f6c38fSTyler Dauwalder	LinkSharedOSLibs $(target) : libcppunit.so $(libraries) ;
571d1f6c38fSTyler Dauwalder	LINKFLAGS on $(target) = $(LINKFLAGS) -nostart -Xlinker -soname=\"$(target)\" ;
572d1f6c38fSTyler Dauwalder}
573d1f6c38fSTyler Dauwalder
57452a38012Sejakowatzrule CommonUnitTest
57552a38012Sejakowatz{
57652a38012Sejakowatz	# CommonUnitTest <target> : <sources> : <dest> : <obos libraries>
57752a38012Sejakowatz	#	: <r5 libraries> : <public headers>;
57852a38012Sejakowatz	# Builds a unit test for both OBOS and R5 modules.
57952a38012Sejakowatz	# <target> The name of the target.
58052a38012Sejakowatz	# <sources> The list of sources.
58152a38012Sejakowatz	# <dest> The directory for the target (as passed to FDirName).
58252a38012Sejakowatz	# <obos libraries> A list of link libraries for the OBOS tests (as passed
58352a38012Sejakowatz	# to LinkSharedOSLibs).
58452a38012Sejakowatz	# <r5 libraries> A list of link libraries for the R5 tests (as passed
58552a38012Sejakowatz	# to LinkSharedOSLibs).
58652a38012Sejakowatz	# <public headers> A list of public header dirs (as passed to
58752a38012Sejakowatz	# UsePublicHeaders).
58852a38012Sejakowatz
58952a38012Sejakowatz	UnitTest $(1) : $(2) : $(3) : $(4) : $(6) ;
59052a38012Sejakowatz	R5UnitTest $(1) : $(2) : $(3) : $(5) ;
59152a38012Sejakowatz}
59252a38012Sejakowatz
59352a38012Sejakowatzrule UnitTest
59452a38012Sejakowatz{
59552a38012Sejakowatz	# UnitTest <target> : <sources> : <dest> : <libraries> : <public headers>
59652a38012Sejakowatz	# Builds a unit test for an OBOS module.
59752a38012Sejakowatz	# <target> The name of the target.
59852a38012Sejakowatz	# <sources> The list of sources.
59952a38012Sejakowatz	# <dest> The directory for the target (as passed to FDirName).
60052a38012Sejakowatz	# <libraries> A list of link libraries (as passed to LinkSharedOSLibs).
60152a38012Sejakowatz	# <public headers> A list of public header dirs (as passed to
60252a38012Sejakowatz	# UsePublicHeaders).
60352a38012Sejakowatz
60452a38012Sejakowatz	local target = $(1) ;
60552a38012Sejakowatz	local sources = $(2) ;
60652a38012Sejakowatz	local dest = $(3) ;
60752a38012Sejakowatz	local libraries = $(4) ;
60852a38012Sejakowatz	local headerDirs = $(5) ;
6099342c27aSIngo Weinhold	local objects = [ FGristFiles $(sources:S=$(SUFOBJ)) ] ;
61052a38012Sejakowatz
6119342c27aSIngo Weinhold	# Our Main replacement.
6129342c27aSIngo Weinhold	MainFromObjects $(target) : $(objects) ;
6139342c27aSIngo Weinhold	TestObjects $(sources) : $(headerDirs) ;
6143b9eae39SIngo Weinhold
61552a38012Sejakowatz	MakeLocate $(target) : [ FDirName $(OBOS_TEST_DIR) $(dest) ] ;
6169eea4522SIngo Weinhold	Depends $(target) : libcppunit.so ;
6179eea4522SIngo Weinhold	Depends obostests : $(target) ;
61852a38012Sejakowatz	LinkSharedOSLibs $(target) : libcppunit.so $(libraries) ;
61952a38012Sejakowatz}
62052a38012Sejakowatz
62152a38012Sejakowatzrule R5UnitTest
62252a38012Sejakowatz{
62352a38012Sejakowatz	# R5UnitTest <target> : <sources> : <dest> : <libraries>
62452a38012Sejakowatz	# Builds a unit test for an R5 module. "_r5" is appended to the object
62552a38012Sejakowatz	# and the target name.
62652a38012Sejakowatz	# <target> The name of the target.
62752a38012Sejakowatz	# <sources> The list of sources.
62852a38012Sejakowatz	# <dest> The directory for the target (as passed to FDirName).
62952a38012Sejakowatz	# <libraries> A list of link libraries (as passed to LinkSharedOSLibs).
63052a38012Sejakowatz
63152a38012Sejakowatz	local target = $(1)_r5 ;
63252a38012Sejakowatz	local sources = $(2) ;
63352a38012Sejakowatz	local dest = $(3) ;
63452a38012Sejakowatz	local libraries = $(4) ;
63552a38012Sejakowatz	local objects = [ R5ObjectNames $(sources) ] ;
63652a38012Sejakowatz
63752a38012Sejakowatz	# Our Main replacement.
63852a38012Sejakowatz	MainFromObjects $(target) : $(objects) ;
6399342c27aSIngo Weinhold	TestObjects $(sources) : : true ;
64052a38012Sejakowatz
64152a38012Sejakowatz	MakeLocate $(target) : [ FDirName $(OBOS_TEST_DIR) $(dest) ] ;
6429eea4522SIngo Weinhold	Depends $(target) : libcppunit.so ;
6439eea4522SIngo Weinhold	Depends r5tests : $(target) ;
64452a38012Sejakowatz	LinkSharedOSLibs $(target) : libcppunit.so $(libraries) ;
64552a38012Sejakowatz}
64652a38012Sejakowatz
64752a38012Sejakowatzrule R5ObjectNames
64852a38012Sejakowatz{
64952a38012Sejakowatz	# R5ObjectNames <sources> ;
65052a38012Sejakowatz	# Returns a list of gristed object names given a list of source file names.
65152a38012Sejakowatz	# Moreover each object names gets "_r5" inserted before the object suffix.
65252a38012Sejakowatz	local objects = $(1:S=)_r5 ;
65352a38012Sejakowatz	return [ FGristFiles $(objects:S=$(SUFOBJ)) ] ;
65452a38012Sejakowatz}
65552a38012Sejakowatz
6569342c27aSIngo Weinholdrule R5Objects
6579342c27aSIngo Weinhold{
6589342c27aSIngo Weinhold	# R5Objects <sources>
659dd9f8062SIngo Weinhold	# Similar to Objects, but appends "_r5" to the object file names and
660dd9f8062SIngo Weinhold	# removes `-nostdinc' from the CC and C++ flags to enable system headers.
6619342c27aSIngo Weinhold	# <sources> The source files.
6629342c27aSIngo Weinhold
663dd9f8062SIngo Weinhold	# Remove `-nostdinc' from CCFLAGS and C++FLAGS.
664dd9f8062SIngo Weinhold	local oldCCFLAGS = $(CCFLAGS) ;
665dd9f8062SIngo Weinhold	local oldC++FLAGS = $(C++FLAGS) ;
666dd9f8062SIngo Weinhold	CCFLAGS = [ Filter $(CCFLAGS) : -nostdinc ] ;
667dd9f8062SIngo Weinhold	C++FLAGS = [ Filter $(C++FLAGS) : -nostdinc ] ;
668dd9f8062SIngo Weinhold
6699342c27aSIngo Weinhold	local sources = $(1) ;
6709342c27aSIngo Weinhold	local source ;
6719342c27aSIngo Weinhold	for source in [ FGristFiles $(sources) ]
6729342c27aSIngo Weinhold	{
6739342c27aSIngo Weinhold		local object = [ R5ObjectNames $(source) ] ;
6749342c27aSIngo Weinhold		Object $(object) : $(source) ;
6759342c27aSIngo Weinhold		LocalDepends obj : $(object) ;
6769342c27aSIngo Weinhold	}
677dd9f8062SIngo Weinhold
678dd9f8062SIngo Weinhold	# Reset CCFLAGS and C++FLAGS to original values.
679dd9f8062SIngo Weinhold	CCFLAGS = $(oldCCFLAGS) ;
680dd9f8062SIngo Weinhold	C++FLAGS = $(oldC++FLAGS) ;
6819342c27aSIngo Weinhold}
6829342c27aSIngo Weinhold
6839342c27aSIngo Weinholdrule TestObjects
6849342c27aSIngo Weinhold{
6859342c27aSIngo Weinhold	# TestLib <sources> : <public headers> : <r5>
6869342c27aSIngo Weinhold	# Compiles objects for tests.
6879342c27aSIngo Weinhold	# <sources> The list of sources.
6889342c27aSIngo Weinhold	# <public headers> A list of public header dirs (as passed to
6899342c27aSIngo Weinhold	# UsePublicHeaders).
6909342c27aSIngo Weinhold	# <r5> If set, "_r5" is appended to the object file names and
6919342c27aSIngo Weinhold	# <public headers> is ignored. Furthermore the pre-processor macro
6929342c27aSIngo Weinhold	# TEST_R5 is defined, TEST_OBOS otherwise.
6939342c27aSIngo Weinhold
6949342c27aSIngo Weinhold	local sources = $(1) ;
6959342c27aSIngo Weinhold	local headerDirs = $(2) ;
6969342c27aSIngo Weinhold	local r5 = $(3) ;
6979342c27aSIngo Weinhold	local objects ;
6989342c27aSIngo Weinhold
6999342c27aSIngo Weinhold	# Turn optimization off.
70096d27465SIngo Weinhold	if ! $(NO_TEST_DEBUG) {
7019342c27aSIngo Weinhold		local optim = $(OPTIM) ;
7029342c27aSIngo Weinhold		OPTIM = ;
70396d27465SIngo Weinhold	}
7049342c27aSIngo Weinhold
7059342c27aSIngo Weinhold	SetupObjectsDir ;
7069342c27aSIngo Weinhold
7079342c27aSIngo Weinhold	# compile
7089342c27aSIngo Weinhold	if $(r5) {
709dd9f8062SIngo Weinhold		SetupR5Includes ;
7109342c27aSIngo Weinhold		objects = [ R5ObjectNames $(sources) ] ;
7119342c27aSIngo Weinhold		R5Objects $(sources) ;
7129342c27aSIngo Weinhold	} else {
713dd9f8062SIngo Weinhold		SetupIncludes ;
7149342c27aSIngo Weinhold		objects = [ FGristFiles $(sources:S=$(SUFOBJ)) ] ;
7159342c27aSIngo Weinhold		Objects $(sources) ;
7169342c27aSIngo Weinhold	}
7179342c27aSIngo Weinhold
7189342c27aSIngo Weinhold	# set headers/defines
7199b60a208SIngo Weinhold	UseCppUnitObjectHeaders $(sources) : $(objects) ;
7209342c27aSIngo Weinhold	if $(r5) {
721728b5725SIngo Weinhold		ObjectsDefines $(objects) : TEST_R5 ;
7229342c27aSIngo Weinhold	} else {
7239b60a208SIngo Weinhold		UsePublicObjectHeaders $(sources) : $(headerDirs) : $(objects) ;
724728b5725SIngo Weinhold		ObjectsDefines $(objects) : TEST_OBOS ;
7259342c27aSIngo Weinhold	}
7269342c27aSIngo Weinhold
72796d27465SIngo Weinhold	if ! $(NO_TEST_DEBUG) {
7289342c27aSIngo Weinhold		# Turn debugging on. That is usually desired for test code.
7299342c27aSIngo Weinhold		ObjectCcFlags $(objects) : "-g" ;
7309342c27aSIngo Weinhold		ObjectC++Flags $(objects) : "-g" ;
7319342c27aSIngo Weinhold
7329342c27aSIngo Weinhold		# Turn optimization on again.
7339342c27aSIngo Weinhold		OPTIM = $(optim) ;
7349342c27aSIngo Weinhold	}
73596d27465SIngo Weinhold}
7369342c27aSIngo Weinhold
7379285de51STyler Dauwalderrule R5SharedLibraryNames
7389285de51STyler Dauwalder{
7399285de51STyler Dauwalder	# R5SharedLibraryNames <sources> ;
7409285de51STyler Dauwalder	# Returns a list of shared library names given a list of file names. NO
7419285de51STyler Dauwalder	# GRISTING IS PERFORMED :-) However, each library names gets "_r5" inserted
7429285de51STyler Dauwalder	# before the shared lib suffix.
7439285de51STyler Dauwalder	return $(1:S=)_r5.so ;
7449285de51STyler Dauwalder}
7459285de51STyler Dauwalder
7469fc6b2e1SIngo Weinholdrule SimpleTest
7479fc6b2e1SIngo Weinhold{
7489fc6b2e1SIngo Weinhold	# UnitTest <target> : <sources> : <libraries>
7499fc6b2e1SIngo Weinhold	# Builds a unit test for an OBOS module.
7509fc6b2e1SIngo Weinhold	# <target> The name of the target.
7519fc6b2e1SIngo Weinhold	# <sources> The list of sources.
7529fc6b2e1SIngo Weinhold	# <dest> The directory for the target (as passed to FDirName).
7539fc6b2e1SIngo Weinhold	# <libraries> A list of link libraries (as passed to LinkSharedOSLibs).
7549fc6b2e1SIngo Weinhold	# <public headers> A list of public header dirs (as passed to
7559fc6b2e1SIngo Weinhold	# UsePublicHeaders).
7569fc6b2e1SIngo Weinhold
7579fc6b2e1SIngo Weinhold	local target = $(1) ;
7589fc6b2e1SIngo Weinhold	local sources = $(2) ;
7599fc6b2e1SIngo Weinhold	local libraries = $(3) ;
7609fc6b2e1SIngo Weinhold	local relPath = [ FRelPath src tests : $(SUBDIR_TOKENS) ] ;
7619fc6b2e1SIngo Weinhold
7629fc6b2e1SIngo Weinhold	# Turn optimization off.
76396d27465SIngo Weinhold	if ! $(NO_TEST_DEBUG) {
7649fc6b2e1SIngo Weinhold		local optim = $(OPTIM) ;
7659fc6b2e1SIngo Weinhold		OPTIM = ;
76696d27465SIngo Weinhold	}
7679fc6b2e1SIngo Weinhold
768a6c008e1Sbeveloper	SetupIncludes ;
7699fc6b2e1SIngo Weinhold	SetupObjectsDir ;
7709fc6b2e1SIngo Weinhold	MakeLocateObjects $(sources) ;
7719fc6b2e1SIngo Weinhold	Main $(target) : $(sources) ;
7729fc6b2e1SIngo Weinhold	MakeLocate $(target) : [ FDirName $(OBOS_TEST_DIR) $(relPath) ] ;
7739eea4522SIngo Weinhold	Depends obostests : $(target) ;
7749fc6b2e1SIngo Weinhold	LinkSharedOSLibs $(target) : $(libraries) ;
775728b5725SIngo Weinhold	ObjectsDefines $(sources) : TEST_OBOS ;
77696d27465SIngo Weinhold	if ! $(NO_TEST_DEBUG) {
7779fc6b2e1SIngo Weinhold		# Turn debugging on. That is usually desired for test code.
7789fc6b2e1SIngo Weinhold		ObjectCcFlags $(sources) : "-g" ;
7799fc6b2e1SIngo Weinhold		ObjectC++Flags $(sources) : "-g" ;
7809fc6b2e1SIngo Weinhold
7819fc6b2e1SIngo Weinhold		# Turn optimization on again.
7829fc6b2e1SIngo Weinhold		OPTIM = $(optim) ;
7839fc6b2e1SIngo Weinhold	}
78496d27465SIngo Weinhold}
7859fc6b2e1SIngo Weinhold
78652a38012Sejakowatzrule Addon
78752a38012Sejakowatz{
78883b3b0dfSIngo Weinhold	# Addon <name> : <relpath> : <sources> : <is executable> : <libraries> ;
7897a384fdeSIngo Weinhold	# <name>: Name of the add-on.
7907a384fdeSIngo Weinhold	# <relpath>: Path where the add-on shall live relative to the add-on dir.
7917a384fdeSIngo Weinhold	# <sources>: Source files.
79283b3b0dfSIngo Weinhold	# <is executable>: true, if the target shall be executable as well.
79383b3b0dfSIngo Weinhold	# <libraries>: Libraries to be linked against.
7947a384fdeSIngo Weinhold
7957a384fdeSIngo Weinhold	local isExecutable = $(4) ;
79652a38012Sejakowatz
797a6c008e1Sbeveloper	SetupIncludes ;
79852a38012Sejakowatz	SetupObjectsDir ;
79952a38012Sejakowatz	Main $(1) : $(3) ;
80052a38012Sejakowatz
80152a38012Sejakowatz	# Create output dir path for addon
80252a38012Sejakowatz	local targetdir;
80352a38012Sejakowatz	targetdir = [ FDirName $(OBOS_ADDON_DIR) $(2) ] ;
80452a38012Sejakowatz
80552a38012Sejakowatz	MakeLocate $(1) : $(targetdir) ;
8067a384fdeSIngo Weinhold
8077a384fdeSIngo Weinhold	local linkFlags = -Xlinker -soname=\"$(1)\" ;
8087a384fdeSIngo Weinhold	if $(isExecutable) != true {
8097a384fdeSIngo Weinhold		linkFlags = -nostart $(linkFlags) ;
8107a384fdeSIngo Weinhold	}
8117a384fdeSIngo Weinhold	LINKFLAGS on $(1) = [ on $(1) return $(LINKFLAGS) ] $(linkFlags) ;
81283b3b0dfSIngo Weinhold	LinkSharedOSLibs $(1) : $(5) ;
813af28904fSIngo Weinhold}
814af28904fSIngo Weinhold
81558efc9d8SIngo Weinholdrule R5KernelAddon
816af28904fSIngo Weinhold{
817600203b1SAxel Dörfler	# R5KernelAddon <name> : <relpath> : <sources> : <static-libraries> ;
818af28904fSIngo Weinhold
819af28904fSIngo Weinhold	local sources = $(3) ;
820af28904fSIngo Weinhold
821af28904fSIngo Weinhold	Addon $(1) : $(2) : $(3) ;
822af28904fSIngo Weinhold	ObjectCcFlags $(sources) : -D_KERNEL_MODE=1 -no-fpic ;
823df48dfedSIngo Weinhold	ObjectC++Flags $(sources) : -D_KERNEL_MODE=1 -no-fpic -fno-exceptions ;
8249eea4522SIngo Weinhold	LINKFLAGS on $(1) = [ on $(1) return $(LINKFLAGS) ] -nostdlib ;
825600203b1SAxel Dörfler	LinkSharedOSLibs $(1) : $(4) /boot/develop/lib/x86/_KERNEL_ ;
82652a38012Sejakowatz}
82752a38012Sejakowatz
8284fb5add0SMatthew Wilberrule Translator
8294fb5add0SMatthew Wilber{
830007eb5f2SIngo Weinhold	# Translator <name> : <sources> : <libraries> ;
831a6c008e1Sbeveloper	SetupIncludes ;
8324fb5add0SMatthew Wilber	SetupObjectsDir ;
8334fb5add0SMatthew Wilber	Main $(1) : $(2) ;
834007eb5f2SIngo Weinhold	LinkSharedOSLibs $(1) : $(3) ;
8354fb5add0SMatthew Wilber
8364fb5add0SMatthew Wilber	# Create output dir path for translator
8374fb5add0SMatthew Wilber	local targetdir;
838d5b07cf2Sshatty	targetdir = [ FDirName $(OBOS_ADDON_DIR) Translators ] ;
8394fb5add0SMatthew Wilber	MakeLocate $(1) : $(targetdir) ;
8404fb5add0SMatthew Wilber}
8414fb5add0SMatthew Wilber
842c4071913SMatthew Wilberrule ScreenSaver
843c4071913SMatthew Wilber{
844c4071913SMatthew Wilber	# ScreenSaver <name> : <sources> : <libraries> ;
845c4071913SMatthew Wilber	Addon $(1) : screen_savers : $(2) : false : $(3) ;
846c4071913SMatthew Wilber}
847c4071913SMatthew Wilber
84852a38012Sejakowatzrule MakeLocateObjects
84952a38012Sejakowatz{
85021df5945SIngo Weinhold	# MakeLocateObjects <sources_or_objects> ;
85152a38012Sejakowatz
85221df5945SIngo Weinhold	local _objs = [ FGristFiles $(1:S=$(SUFOBJ)) ] ;
85352a38012Sejakowatz
85452a38012Sejakowatz	for o in $(_objs)
85552a38012Sejakowatz	{
85652a38012Sejakowatz		local dir = $(o:D) ;
85752a38012Sejakowatz		if $(dir) {
85852a38012Sejakowatz			MakeLocate $(o) : [ FDirName $(LOCATE_TARGET) $(dir) ] ;
85952a38012Sejakowatz		} else {
86052a38012Sejakowatz			MakeLocate $(o) : $(LOCATE_TARGET) ;
86152a38012Sejakowatz		}
86252a38012Sejakowatz	}
86352a38012Sejakowatz}
86452a38012Sejakowatz
86552a38012Sejakowatzrule StaticLibrary
86652a38012Sejakowatz{
867e9230d05SIngo Weinhold	# StaticLibrary <name> : <sources> [ : <target dir> ] ;
868e9230d05SIngo Weinhold	# Creates a static library from sources.
869e9230d05SIngo Weinhold	# <name>: Basename of the library, without leading "lib" and trailing ".a".
87060c9c40fSIngo Weinhold	#         Grist is allowed -- it will be re-prepended after constructing
87160c9c40fSIngo Weinhold	#         the complete library name.
872e9230d05SIngo Weinhold	# <source>: List of source files.
873e9230d05SIngo Weinhold	# <target dir>: Directory into which the library shall be placed. Defaults
87460c9c40fSIngo Weinhold	#               to the objects directory for this subdir. If
87560c9c40fSIngo Weinhold	#               STATIC_LIBRARY_DIR is supplied (the literal string)
87660c9c40fSIngo Weinhold	#               the standard directory for static libs is used, otherwise
87760c9c40fSIngo Weinhold	#               the parameter is interpreted as directory path.
878e9230d05SIngo Weinhold	#
87960c9c40fSIngo Weinhold	local lib = lib$(1:B)$(SUFLIB) ;
88060c9c40fSIngo Weinhold	lib = $(lib:G=$(1:G)) ;
881a6c008e1Sbeveloper	SetupIncludes ;
88252a38012Sejakowatz	SetupObjectsDir ;
88352a38012Sejakowatz	MakeLocateObjects $(2) ;
884e9230d05SIngo Weinhold	Library $(lib) : $(2) ;
885e9230d05SIngo Weinhold	local targetDir = $(3) ;
88660c9c40fSIngo Weinhold	if $(targetDir) {
88760c9c40fSIngo Weinhold		if $(targetDir) = STATIC_LIBRARY_DIR {
888e9230d05SIngo Weinhold			targetDir = $(OBOS_STLIB_DIR) ;
889e9230d05SIngo Weinhold		}
890e9230d05SIngo Weinhold		MakeLocate $(lib) : $(targetDir) ;
89160c9c40fSIngo Weinhold	} else {
89260c9c40fSIngo Weinhold		# nothing to do, since the Library rule already located the library
89360c9c40fSIngo Weinhold		# in $(LOCATE_TARGET)
89460c9c40fSIngo Weinhold	}
895f1e077f8SIngo Weinhold
896f1e077f8SIngo Weinhold	# If KEEPOBJS is set, Library doesn't make the library depend on
897f1e077f8SIngo Weinhold	# `lib'.
898f1e077f8SIngo Weinhold	if $(KEEPOBJS) {
899f1e077f8SIngo Weinhold		LocalDepends lib : $(lib) ;
900f1e077f8SIngo Weinhold	}
90152a38012Sejakowatz}
90252a38012Sejakowatz
903dbf96817SIngo Weinholdrule R5KernelStaticLibrary
904dbf96817SIngo Weinhold{
905dbf96817SIngo Weinhold	# R5KernelStaticLibrary <name> : <sources> ;
906dbf96817SIngo Weinhold
907f1e077f8SIngo Weinhold	local lib = lib$(1)$(SUFLIB) ;
908dbf96817SIngo Weinhold	local sources = $(2) ;
909dbf96817SIngo Weinhold
910dbf96817SIngo Weinhold	SetupIncludes ;
911dbf96817SIngo Weinhold	SetupObjectsDir ;
912dbf96817SIngo Weinhold	MakeLocateObjects $(sources) ;
913dbf96817SIngo Weinhold	Library $(lib) : $(sources) ;
914dbf96817SIngo Weinhold	ObjectCcFlags $(sources) : -D_KERNEL_MODE=1 -no-fpic ;
915df48dfedSIngo Weinhold	ObjectC++Flags $(sources) : -D_KERNEL_MODE=1 -no-fpic -fno-exceptions ;
916dbf96817SIngo Weinhold}
917dbf96817SIngo Weinhold
91880721244SAxel Dörflerrule MergeObjectFromObjects
91980721244SAxel Dörfler{
9202fbd7065SIngo Weinhold	# MergeObjectFromObjects <name> : <objects> : <other objects> ;
9212fbd7065SIngo Weinhold	# Merges object files to an object file.
9222fbd7065SIngo Weinhold	# <name>: Name of the object file to create. No grist will be added.
9232fbd7065SIngo Weinhold	# <objects>: Object files to be merged. Grist will be added.
9242fbd7065SIngo Weinhold	# <other objects>: Object files or static libraries to be merged. No grist
9252fbd7065SIngo Weinhold	#                  will be added.
9262fbd7065SIngo Weinhold	#
927c8aa252aSIngo Weinhold	local objects = [ FGristFiles $(2) ] ;
92880721244SAxel Dörfler	MakeLocate $(1) : $(LOCATE_TARGET) ;
929c8aa252aSIngo Weinhold	Depends $(1) : $(objects) ;
9302fbd7065SIngo Weinhold	Depends $(1) : $(3) ;
93180721244SAxel Dörfler	LINK on $(1) = ld ;
9322fbd7065SIngo Weinhold	MergeObjectFromObjects1 $(1) : $(objects) $(3) ;
93380721244SAxel Dörfler}
93480721244SAxel Dörfler
93554b7cbe1SIngo Weinholdactions MergeObjectFromObjects1
93680721244SAxel Dörfler{
93780721244SAxel Dörfler	$(LINK) -r $(2) -o $(1) ;
93880721244SAxel Dörfler}
93980721244SAxel Dörfler
94080721244SAxel Dörflerrule MergeObject
94180721244SAxel Dörfler{
9422fbd7065SIngo Weinhold	# MergeObject <name> : <sources> : <other objects> ;
9432fbd7065SIngo Weinhold	# Compiles source files and merges the object files to an object file.
9442fbd7065SIngo Weinhold	# <name>: Name of the object file to create. No grist will be added.
9452fbd7065SIngo Weinhold	# <sources>: Sources to be compiled. Grist will be added.
9462fbd7065SIngo Weinhold	# <other objects>: Object files or static libraries to be merged. No grist
9472fbd7065SIngo Weinhold	#                  will be added.
9482fbd7065SIngo Weinhold	#
94980721244SAxel Dörfler	SetupIncludes ;
95080721244SAxel Dörfler	SetupObjectsDir ;
95180721244SAxel Dörfler	MakeLocateObjects $(2) ;
95280721244SAxel Dörfler	Objects $(2) ;
9532fbd7065SIngo Weinhold	MergeObjectFromObjects $(1) : $(2:S=$(SUFOBJ)) : $(3) ;
95480721244SAxel Dörfler}
95580721244SAxel Dörfler
95621df5945SIngo Weinholdrule SharedLibraryFromObjects
95752a38012Sejakowatz{
9588d3308d9SIngo Weinhold	# SharedLibraryFromObjects <name> : <objects> : <libraries> ;
95960c9c40fSIngo Weinhold	local _lib = lib$(1:B).so ;
96060c9c40fSIngo Weinhold	_lib = $(_lib:G=$(1:G)) ;
96121df5945SIngo Weinhold	MainFromObjects $(_lib) : $(2) ;
96252a38012Sejakowatz	MakeLocate $(_lib) : $(OBOS_SHLIB_DIR) ;
9639eea4522SIngo Weinhold	LINKFLAGS on $(_lib) = [ on $(_lib) return $(LINKFLAGS) ]
9649eea4522SIngo Weinhold						   -nostart -Xlinker -soname=\"$(_lib)\" ;
9658d3308d9SIngo Weinhold	LinkSharedOSLibs $(_lib) : $(3) ;
96652a38012Sejakowatz}
96752a38012Sejakowatz
96821df5945SIngo Weinholdrule SharedLibrary
96921df5945SIngo Weinhold{
9708d3308d9SIngo Weinhold	# SharedLibrary <name> : <sources> : <libraries> ;
971a6c008e1Sbeveloper	SetupIncludes ;
97221df5945SIngo Weinhold	SetupObjectsDir ;
97321df5945SIngo Weinhold	MakeLocateObjects $(2) ;
97421df5945SIngo Weinhold	Objects $(2) ;
9758d3308d9SIngo Weinhold	SharedLibraryFromObjects $(1) : $(2:S=$(SUFOBJ)) : $(3) ;
97621df5945SIngo Weinhold}
97721df5945SIngo Weinhold
97852a38012Sejakowatzrule LinkSharedOSLibs
97952a38012Sejakowatz{
98052a38012Sejakowatz	# LinkSharedOSLibs <name> : <libs> ;
98152a38012Sejakowatz	# Valid elements for <libs> are e.g. "be" or "libopenbeos.so" or
9824236d490SIngo Weinhold	# "/boot/.../libfoo.so". If the basename starts with "lib" or the thingy
9834236d490SIngo Weinhold	# has a dirname or grist, it is added to the NEEDLIBS variable (i.e. the
9844236d490SIngo Weinhold	# file will be bound!), otherwise it is prefixed "-l" and added to
985a8cd0719SIngo Weinhold	# LINKLIBS. If you want to specify a target that isn't a library and
986a8cd0719SIngo Weinhold	# also has neither grist nor a dirname, you can prepend "<nogrist>" as
987a8cd0719SIngo Weinhold	# grist; it will be stripped by this rule.
98852a38012Sejakowatz
98952a38012Sejakowatz	for i in $(>)
99052a38012Sejakowatz	{
9914236d490SIngo Weinhold		local isfile = ;
9924236d490SIngo Weinhold		if $(i:D) || $(i:G) {
9934236d490SIngo Weinhold			isfile = true ;
994a8cd0719SIngo Weinhold			if $(i:G) = <nogrist> {
995a8cd0719SIngo Weinhold				i = $(i:G=) ;
996a8cd0719SIngo Weinhold			}
9974236d490SIngo Weinhold		} else {
99852a38012Sejakowatz			switch $(i:B)
99952a38012Sejakowatz			{
1000007eb5f2SIngo Weinhold				# XXX: _APP_ and _KERNEL_ should not be needed for ELF.
1001f7901247SPhilippe Houdoin				case _APP_ : isfile = true ;
1002f7901247SPhilippe Houdoin				case _KERNEL_ : isfile = true ;
10034236d490SIngo Weinhold				case lib*	: isfile = true ;
10044236d490SIngo Weinhold				case *	: isfile = ;
10054236d490SIngo Weinhold			}
1006b8baf385SIngo Weinhold			if ! $(isfile) && ( $(i:S) = .so || $(i:S) = .a ) {
1007b8baf385SIngo Weinhold				isfile = true ;
1008b8baf385SIngo Weinhold			}
10094236d490SIngo Weinhold		}
10104236d490SIngo Weinhold		if $(isfile) {
10119eea4522SIngo Weinhold			NEEDLIBS on $(1) = [ on $(1) return $(NEEDLIBS) ] $(i) ;
10129eea4522SIngo Weinhold			Depends $(1) : $(i) ;
10134236d490SIngo Weinhold		} else {
10149eea4522SIngo Weinhold			LINKLIBS on $(1) = [ on $(1) return $(LINKLIBS) ] -l$(i) ;
101552a38012Sejakowatz		}
101652a38012Sejakowatz	}
101752a38012Sejakowatz}
101852a38012Sejakowatz
101952a38012Sejakowatzrule AddResources
102052a38012Sejakowatz{
102152a38012Sejakowatz	# AddResources <name> : <resourcefiles> ;
102252a38012Sejakowatz
10238d3308d9SIngo Weinhold	local resfiles = [ FGristFiles $(2) ] ;
10248d3308d9SIngo Weinhold	SEARCH on $(resfiles) += $(SEARCH_SOURCE) ;
10258d3308d9SIngo Weinhold
10268d3308d9SIngo Weinhold	for file in $(resfiles) {
10278d3308d9SIngo Weinhold		if $(file:S) = .rdef {
10288d3308d9SIngo Weinhold			local rdef = $(file) ;
10298d3308d9SIngo Weinhold			file = $(rdef:S=.rsrc) ;
10308d3308d9SIngo Weinhold			ResComp $(file) : $(rdef) ;
10318d3308d9SIngo Weinhold		}
10328d3308d9SIngo Weinhold		RESFILES on $(1) += $(file) ;
10338d3308d9SIngo Weinhold	}
10348d3308d9SIngo Weinhold}
10358d3308d9SIngo Weinhold
10368d3308d9SIngo Weinholdrule ResComp
10378d3308d9SIngo Weinhold{
10388d3308d9SIngo Weinhold	# ResComp <resource file> : <rdef file> ;
10398d3308d9SIngo Weinhold	#
10408d3308d9SIngo Weinhold	# <resource file> and <rdef file> must be gristed.
10418d3308d9SIngo Weinhold
10428d3308d9SIngo Weinhold	SetupObjectsDir ;
10438d3308d9SIngo Weinhold
10449fc6b2e1SIngo Weinhold	SEARCH on $(2) += $(SEARCH_SOURCE) ;
10458d3308d9SIngo Weinhold	MakeLocate $(1) : $(LOCATE_TARGET) ;
10468d3308d9SIngo Weinhold	Depends $(1) : $(2) rc ;
10478d3308d9SIngo Weinhold	LocalClean clean : $(1) ;
10488d3308d9SIngo Weinhold	ResComp1 $(1) : rc $(2) ;
10498d3308d9SIngo Weinhold}
10508d3308d9SIngo Weinhold
10518d3308d9SIngo Weinholdactions ResComp1
10528d3308d9SIngo Weinhold{
10536af76074SIngo Weinhold	$(2[1]) -o $(1) $(2[2-])
105452a38012Sejakowatz}
105552a38012Sejakowatz
1056728b5725SIngo Weinholdrule ObjectsDefines
1057728b5725SIngo Weinhold{
1058728b5725SIngo Weinhold	# Like ObjectDefines, but allows multiple files to be supplied
1059728b5725SIngo Weinhold	local file ;
1060728b5725SIngo Weinhold	for file in $(1) {
1061728b5725SIngo Weinhold		ObjectDefines $(file) : $(2) ;
1062728b5725SIngo Weinhold	}
1063728b5725SIngo Weinhold}
1064728b5725SIngo Weinhold
10659b60a208SIngo Weinholdrule SourceHdrs
10669b60a208SIngo Weinhold{
10679b60a208SIngo Weinhold	# SourceHdrs <sources> : <headers> [ : <gristed objects> ] ;
10689b60a208SIngo Weinhold	#
10699b60a208SIngo Weinhold	# Is a wrapper for ObjectHdrs, that passes <sources> and <headers> or,
10709b60a208SIngo Weinhold	# if supplied <objects> and <headers>, and also adjusts HDRSEARCH (not
10719b60a208SIngo Weinhold	# done by ObjectHdrs).
10729b60a208SIngo Weinhold
10739b60a208SIngo Weinhold	local sources = [ FGristFiles $(1) ] ;
10749b60a208SIngo Weinhold	local headers = $(2) ;
10759b60a208SIngo Weinhold	local objects = $(3) ;
10769b60a208SIngo Weinhold
1077728b5725SIngo Weinhold	local file ;
10789b60a208SIngo Weinhold	if $(objects) {
1079728b5725SIngo Weinhold		for file in $(objects) {
1080728b5725SIngo Weinhold			ObjectHdrs $(file) : $(headers) ;
1081c0e501e0SIngo Weinhold			# also reformat the assembler headers
1082c0e501e0SIngo Weinhold			ASHDRS on $(file) = [ FIncludes $(SEARCH_SOURCE) $(SUBDIRHDRS)
1083c0e501e0SIngo Weinhold								  [ on $(file) return $(HDRS) ] ] ;
1084728b5725SIngo Weinhold		}
10859b60a208SIngo Weinhold	} else {
1086081debe8SIngo Weinhold		for file in $(sources:S=$(SUFOBJ)) {
1087728b5725SIngo Weinhold			ObjectHdrs $(file) : $(headers) ;
1088c0e501e0SIngo Weinhold			# also reformat the assembler headers
1089c0e501e0SIngo Weinhold			ASHDRS on $(file) = [ FIncludes $(SEARCH_SOURCE) $(SUBDIRHDRS)
1090c0e501e0SIngo Weinhold								  [ on $(file) return $(HDRS) ] ] ;
1091728b5725SIngo Weinhold		}
10929b60a208SIngo Weinhold	}
10939b60a208SIngo Weinhold
10949b60a208SIngo Weinhold	# Also add the header search dirs to HDRSEARCH. Note, that these dirs
10959b60a208SIngo Weinhold	# will be listed after the STDHDRS (if any), but that's better than not
10969b60a208SIngo Weinhold	# being listed at all.
10979b60a208SIngo Weinhold	HDRSEARCH on $(sources) += $(headers) ;
10989b60a208SIngo Weinhold}
10999b60a208SIngo Weinhold
11007d7f280eSIngo Weinholdrule PublicHeaders
110152a38012Sejakowatz{
11027d7f280eSIngo Weinhold	# PublicHeaders <group list>
110352a38012Sejakowatz	#
11047d7f280eSIngo Weinhold	# Returns the directory names for the public header dirs identified by
11057d7f280eSIngo Weinhold	# <group list>.
110652a38012Sejakowatz
110752a38012Sejakowatz	local list = $(1) ;
1108b005dbe3SAxel Dörfler	local dirs = [ FDirName $(OBOS_TOP) headers os ] ;
1109b005dbe3SAxel Dörfler
111052a38012Sejakowatz	for i in $(list) {
11117d7f280eSIngo Weinhold		dirs += [ FDirName $(OBOS_TOP) headers os $(i) ] ;
11127d7f280eSIngo Weinhold	}
11137d7f280eSIngo Weinhold	return $(dirs) ;
111452a38012Sejakowatz}
111552a38012Sejakowatz
11167d7f280eSIngo Weinholdrule PrivateHeaders
11177d7f280eSIngo Weinhold{
11187d7f280eSIngo Weinhold	# PrivateHeaders <group list>
11197d7f280eSIngo Weinhold	#
11207d7f280eSIngo Weinhold	# Returns the directory names for the private header dirs identified by
11217d7f280eSIngo Weinhold	# <group list>.
11227d7f280eSIngo Weinhold
11237d7f280eSIngo Weinhold	local list = $(1) ;
11247d7f280eSIngo Weinhold	local dirs ;
11257d7f280eSIngo Weinhold	for i in $(list) {
11267d7f280eSIngo Weinhold		dirs += [ FDirName $(OBOS_TOP) headers private $(i) ] ;
11277d7f280eSIngo Weinhold	}
11287d7f280eSIngo Weinhold	return $(dirs) ;
11297d7f280eSIngo Weinhold}
11307d7f280eSIngo Weinhold
11310f434a0aSDarkWyrmrule LibraryHeaders
11320f434a0aSDarkWyrm{
11330f434a0aSDarkWyrm	# LibraryHeaders <group list>
11340f434a0aSDarkWyrm	#
11350f434a0aSDarkWyrm	# Returns the directory names for the library header dirs identified by
11360f434a0aSDarkWyrm	# <group list>.
11370f434a0aSDarkWyrm
11380f434a0aSDarkWyrm	local list = $(1) ;
11390f434a0aSDarkWyrm	local dirs ;
11400f434a0aSDarkWyrm	for i in $(list) {
11410f434a0aSDarkWyrm		dirs += [ FDirName $(OBOS_TOP) headers libs $(i) ] ;
11420f434a0aSDarkWyrm	}
11430f434a0aSDarkWyrm	return $(dirs) ;
11440f434a0aSDarkWyrm}
11450f434a0aSDarkWyrm
11467d7f280eSIngo Weinholdrule ArchHeaders
11477d7f280eSIngo Weinhold{
11487d7f280eSIngo Weinhold	# usage: ArchHeaders <arch> ;
11497d7f280eSIngo Weinhold	#
11507d7f280eSIngo Weinhold	# <arch> specifies the architecture (e.g. x86).
11517d7f280eSIngo Weinhold
11527d7f280eSIngo Weinhold	return [ FDirName $(OBOS_TOP) headers private kernel arch $(1) ] ;
11537d7f280eSIngo Weinhold}
11547d7f280eSIngo Weinhold
11557d7f280eSIngo Weinholdrule UsePublicHeaders
11567d7f280eSIngo Weinhold{
1157966528dcSIngo Weinhold	# UsePublicHeaders <group list> ;
1158966528dcSIngo Weinhold	#
1159966528dcSIngo Weinhold	# Adds the public C header dirs given by <group list> to the header search
1160966528dcSIngo Weinhold	# dirs of the subdirectory.
1161966528dcSIngo Weinhold	# NOTE: This rule must be invoked *before* the rule that builds the
1162966528dcSIngo Weinhold	# objects.
1163966528dcSIngo Weinhold
1164966528dcSIngo Weinhold	UseHeaders [ PublicHeaders $(1) ] ;
11657d7f280eSIngo Weinhold}
11667d7f280eSIngo Weinhold
11677d7f280eSIngo Weinholdrule UsePublicObjectHeaders
11687d7f280eSIngo Weinhold{
11699b60a208SIngo Weinhold	# UsePublicObjectHeaders <sources> : <group list> [ : <objects> ] ;
11707d7f280eSIngo Weinhold	#
11717d7f280eSIngo Weinhold	# Adds the public C header dirs given by <group list> to the header search
11729b60a208SIngo Weinhold	# dirs of either the object targets of <sources> or if supplied to
11739b60a208SIngo Weinhold	# <objects>. Also adjusts HDRSEARCH of <sources>.
11747d7f280eSIngo Weinhold	# NOTE: This rule must be invoked *after* the rule that builds the objects.
11757d7f280eSIngo Weinhold
11769b60a208SIngo Weinhold	SourceHdrs $(1) : [ PublicHeaders $(2) ] : $(3) ;
117752a38012Sejakowatz}
117852a38012Sejakowatz
117952a38012Sejakowatzrule UsePrivateHeaders
118052a38012Sejakowatz{
11817d7f280eSIngo Weinhold	# UsePrivateHeaders <group list> ;
118252a38012Sejakowatz	#
118352a38012Sejakowatz	# Adds the private C header dirs given by <group list> to the header search
11847d7f280eSIngo Weinhold	# dirs of the subdirectory.
11857d7f280eSIngo Weinhold	# NOTE: This rule must be invoked *before* the rule that builds the objects.
118652a38012Sejakowatz
11877d7f280eSIngo Weinhold	UseHeaders [ PrivateHeaders $(1) ] ;
118852a38012Sejakowatz}
118952a38012Sejakowatz
11907d7f280eSIngo Weinholdrule UsePrivateObjectHeaders
11917d7f280eSIngo Weinhold{
11929b60a208SIngo Weinhold	# UsePrivateObjectHeaders <sources> : <group list> [ : <objects> ] ;
11937d7f280eSIngo Weinhold	#
11947d7f280eSIngo Weinhold	# Adds the private C header dirs given by <group list> to the header search
11959b60a208SIngo Weinhold	# dirs of either the object targets of <sources> or if supplied to
11969b60a208SIngo Weinhold	# <objects>. Also adjusts HDRSEARCH of <sources>.
11977d7f280eSIngo Weinhold	# NOTE: This rule must be invoked *after* the rule that builds the objects.
11987d7f280eSIngo Weinhold
11999b60a208SIngo Weinhold	SourceHdrs $(1) : [ PrivateHeaders $(2) ] : $(3) ;
120052a38012Sejakowatz}
120152a38012Sejakowatz
120252a38012Sejakowatzrule UseHeaders
120352a38012Sejakowatz{
12047d7f280eSIngo Weinhold	# UseHeaders <headers> ;
120552a38012Sejakowatz	#
120652a38012Sejakowatz	# Adds the C header dirs <headers> to the header search
12077d7f280eSIngo Weinhold	# dirs of the subdirectory.
12087d7f280eSIngo Weinhold	# NOTE: This rule must be invoked *before* the rule that builds the objects.
120952a38012Sejakowatz
12107d7f280eSIngo Weinhold	local header ;
12117d7f280eSIngo Weinhold	for header in $(1) {
121252a38012Sejakowatz		SubDirHdrs $(header) ;
121352a38012Sejakowatz	}
121452a38012Sejakowatz}
121552a38012Sejakowatz
121652a38012Sejakowatzrule UseCppUnitHeaders
121752a38012Sejakowatz{
12187d7f280eSIngo Weinhold	SubDirHdrs [ FDirName $(OBOS_TOP) headers tools cppunit ] ;
121952a38012Sejakowatz}
122052a38012Sejakowatz
1221be5af1baSIngo Weinholdrule UseCppUnitObjectHeaders
1222be5af1baSIngo Weinhold{
12239b60a208SIngo Weinhold	# UseCppUnitObjectHeaders <sources> [ : <objects> ] ;
12249b60a208SIngo Weinhold	SourceHdrs $(1) : [ FDirName $(OBOS_TOP) headers tools cppunit ] : $(2) ;
1225be5af1baSIngo Weinhold}
1226be5af1baSIngo Weinhold
122752a38012Sejakowatzrule UseArchHeaders
122852a38012Sejakowatz{
12297d7f280eSIngo Weinhold	# usage: UseArchHeaders <arch> ;
12307d7f280eSIngo Weinhold	#
123152a38012Sejakowatz	# <arch> specifies the architecture (e.g. x86).
12327d7f280eSIngo Weinhold	# NOTE: This rule must be invoked *before* the rule that builds the objects.
12337d7f280eSIngo Weinhold
12347d7f280eSIngo Weinhold	local headers = [ ArchHeaders $(1) ] ;
123552a38012Sejakowatz	local opt = -D$(OBOS_TARGET_DEFINE) ;
1236c633961aSIngo Weinhold
123752a38012Sejakowatz	SubDirCcFlags $(opt)  ;
123852a38012Sejakowatz	SubDirC++Flags $(opt)  ;
1239089a0629Sbeveloper	HDRS += $(headers) ;
1240c633961aSIngo Weinhold}
1241c633961aSIngo Weinhold
12427d7f280eSIngo Weinholdrule UseArchObjectHeaders
12437d7f280eSIngo Weinhold{
12449b60a208SIngo Weinhold	# usage: UseArchObjectHeaders <sources> : <arch> : [ <objects> ] ;
12457d7f280eSIngo Weinhold	#
12467d7f280eSIngo Weinhold	# <arch> specifies the architecture (e.g. x86).
12477d7f280eSIngo Weinhold	# <sources_or_objects> Source or object files.
12487d7f280eSIngo Weinhold	# NOTE: This rule must be invoked *after* the rule that builds the objects.
12497d7f280eSIngo Weinhold
12509b60a208SIngo Weinhold	local sources = $(1) ;
12517d7f280eSIngo Weinhold	local headers = [ ArchHeaders $(2) ] ;
12529b60a208SIngo Weinhold	local objects = $(3) ;
12539b60a208SIngo Weinhold	local targets ;
12549b60a208SIngo Weinhold	if $(objects) {
12559b60a208SIngo Weinhold		targets = $(objects) ;
12569b60a208SIngo Weinhold	} else {
1257081debe8SIngo Weinhold		targets = [ FGristFiles $(sources:S=$(SUFOBJ)) ] ;
12589b60a208SIngo Weinhold	}
12597d7f280eSIngo Weinhold	local opt = -D$(OBOS_TARGET_DEFINE) ;
12607d7f280eSIngo Weinhold
12617d7f280eSIngo Weinhold	ObjectCcFlags $(targets) : $(opt)  ;
12627d7f280eSIngo Weinhold	ObjectC++Flags $(targets) : $(opt)  ;
12639b60a208SIngo Weinhold	SourceHdrs $(sources) : $(headers) : $(objects) ;
126452a38012Sejakowatz}
126552a38012Sejakowatz
1266d25a77b4SIngo Weinholdrule UsePosixHeaders
1267d25a77b4SIngo Weinhold{
1268a6c008e1Sbeveloper	# XXX changed to do nothing
1269d25a77b4SIngo Weinhold}
1270d25a77b4SIngo Weinhold
1271d25a77b4SIngo Weinholdrule UsePosixObjectHeaders
1272d25a77b4SIngo Weinhold{
12739b60a208SIngo Weinhold	# UsePosixObjectHeaders <sources> [ : <objects> ] ;
1274d25a77b4SIngo Weinhold	#
1275d25a77b4SIngo Weinhold	# Adds the POSIX header dir to the header search
12769b60a208SIngo Weinhold	# dirs of either the object targets of <sources> or if supplied to
12779b60a208SIngo Weinhold	# <objects>. Also adjusts HDRSEARCH of <sources>.
1278d25a77b4SIngo Weinhold	# NOTE: This rule must be invoked *after* the rule that builds the objects.
1279d25a77b4SIngo Weinhold
12809b60a208SIngo Weinhold	SourceHdrs $(1) : [ FDirName $(OBOS_TOP) headers posix ] : $(2) ;
1281d25a77b4SIngo Weinhold}
1282d25a77b4SIngo Weinhold
12830f434a0aSDarkWyrmrule UseLibraryHeaders
12840f434a0aSDarkWyrm{
12850f434a0aSDarkWyrm	# UseLibraryHeaders <group list> ;
12860f434a0aSDarkWyrm	#
12870f434a0aSDarkWyrm	# Adds the library header dirs given by <group list> to the header search
12880f434a0aSDarkWyrm	# dirs of the subdirectory.
12890f434a0aSDarkWyrm	# NOTE: This rule must be invoked *before* the rule that builds the objects.
12900f434a0aSDarkWyrm
12910f434a0aSDarkWyrm	UseHeaders [ LibraryHeaders $(1) ] ;
12920f434a0aSDarkWyrm}
12930f434a0aSDarkWyrm
12943b9eae39SIngo Weinholdrule SplitPath
12953b9eae39SIngo Weinhold{
12963b9eae39SIngo Weinhold	# SplitPath <path> ;
12973b9eae39SIngo Weinhold	# Decomposes a path into its components.
12983b9eae39SIngo Weinhold	local path = $(1:G=) ;
12993b9eae39SIngo Weinhold	local components ;
13008c27f58dSIngo Weinhold	# $(path:D) for "/" is "/". Therefore the second condition.
13018c27f58dSIngo Weinhold	while $(path:D) && $(path:D) != $(path)
13023b9eae39SIngo Weinhold	{
13033b9eae39SIngo Weinhold		# Note: $(path:B) returns "." for "..", but $(path:D=) is fine.
13043b9eae39SIngo Weinhold		components = $(path:D=) $(components) ;
13053b9eae39SIngo Weinhold		path = $(path:D) ;
13063b9eae39SIngo Weinhold	}
13073b9eae39SIngo Weinhold	components = $(path) $(components) ;
13083b9eae39SIngo Weinhold	return $(components) ;
13093b9eae39SIngo Weinhold}
13103b9eae39SIngo Weinhold
13119fc6b2e1SIngo Weinholdrule PrependObjectHdrs
13129fc6b2e1SIngo Weinhold{
13139fc6b2e1SIngo Weinhold	# PrependObjectHdrs <objects_or_sources> : <dirs> ;
13149fc6b2e1SIngo Weinhold	# Prepends <dirs> to the list of header search dirs of the objects
13159fc6b2e1SIngo Weinhold	# specified by <objects_or_sources>. The HDRS variable will not be
13169fc6b2e1SIngo Weinhold	# changed, only CCHDRS.
13179fc6b2e1SIngo Weinhold	# Note: A subsequent ObjectHdrs invocation will therefore undo the
13189fc6b2e1SIngo Weinhold	# effect of this rule.
13199fc6b2e1SIngo Weinhold	# NOTE: This is a hack.
13209fc6b2e1SIngo Weinhold
13219fc6b2e1SIngo Weinhold	local objects = [ FGristFiles $(1:S=$(SUFOBJ)) ] ;
13229fc6b2e1SIngo Weinhold	local dirs = $(2) ;
13239fc6b2e1SIngo Weinhold	for object in $(objects) {
13249fc6b2e1SIngo Weinhold		# Don't change HDRS to avoid screwing up the header scanning.
13259fc6b2e1SIngo Weinhold		PREPENDED_HDRS on $(object)
13269fc6b2e1SIngo Weinhold			= $(dirs) [ on $(object) return $(PREPENDED_HDRS) ] ;
13279fc6b2e1SIngo Weinhold		CCHDRS on $(object)
13289fc6b2e1SIngo Weinhold			= [ FIncludes [ on $(object) return $(PREPENDED_HDRS) $(HDRS) ] ] ;
13299fc6b2e1SIngo Weinhold	}
13309fc6b2e1SIngo Weinhold}
13319fc6b2e1SIngo Weinhold
13323b9eae39SIngo Weinholdrule SymLink
13333b9eae39SIngo Weinhold{
13347669b69fSIngo Weinhold	# SymLink <target> : <source> : <makeDefaultDependencies> ;
13353b9eae39SIngo Weinhold	# Links <target> to <source>.
13363b9eae39SIngo Weinhold	# <source> is the exact link contents. No binding is done.
13377669b69fSIngo Weinhold	# <makeDefaultDependencies> If true, <target> will be made a dependency
13387669b69fSIngo Weinhold	# of the `all' pseudo target, i.e. it will be made by default, and removed
13397669b69fSIngo Weinhold	# on `jam clean'.
13407669b69fSIngo Weinhold
13417669b69fSIngo Weinhold	local target = $(1) ;
13427669b69fSIngo Weinhold	local source = $(2) ;
13437669b69fSIngo Weinhold	local makeDefaultDependencies = $(3) ;
13447669b69fSIngo Weinhold	if ! $(makeDefaultDependencies) {
13457669b69fSIngo Weinhold		makeDefaultDependencies = true ;
13467669b69fSIngo Weinhold	}
13477669b69fSIngo Weinhold	LINKCONTENTS on $(target) = $(source) ;
13487669b69fSIngo Weinhold	SymLink1 $(target) ;
13497669b69fSIngo Weinhold	if $(makeDefaultDependencies) = true {
13507669b69fSIngo Weinhold		LocalDepends files : $(target) ;
13517669b69fSIngo Weinhold		LocalClean clean : $(target) ;
13527669b69fSIngo Weinhold	}
13533b9eae39SIngo Weinhold}
13543b9eae39SIngo Weinhold
13553b9eae39SIngo Weinholdactions SymLink1
13563b9eae39SIngo Weinhold{
13570931b8f9SIngo Weinhold	$(RM) "$(1)" && $(LN) -s "$(LINKCONTENTS)" "$(1)"
13580931b8f9SIngo Weinhold}
13590931b8f9SIngo Weinhold
13600931b8f9SIngo Weinholdrule RelSymLink
13610931b8f9SIngo Weinhold{
13627669b69fSIngo Weinhold	# RelSymLink <link> : <link target> : <makeDefaultDependencies> ;
13630931b8f9SIngo Weinhold	# Creates a relative symbolic link from <link> to <link target>.
13640931b8f9SIngo Weinhold	# <link> and <link target> can be usual targets. They may have a grist
13650931b8f9SIngo Weinhold	# and don't need to have any dirname. Their LOCATE variables are used to
13660931b8f9SIngo Weinhold	# find their locations.
13677669b69fSIngo Weinhold	# <makeDefaultDependencies> If true (which is the default), <link> will be
13687669b69fSIngo Weinhold	# made a dependency of the `files' pseudo target, i.e. it will be made by
13697669b69fSIngo Weinhold	# default, and removed on `jam clean'.
13700931b8f9SIngo Weinhold
13710931b8f9SIngo Weinhold	local target = $(1) ;
13720931b8f9SIngo Weinhold	local source = $(2) ;
13737669b69fSIngo Weinhold	local makeDefaultDependencies = $(3) ;
13740931b8f9SIngo Weinhold	local targetDir = [ on $(target) FDirName $(LOCATE[1]) $(target:D) ] ;
13750931b8f9SIngo Weinhold	local sourceDir = [ on $(source) FDirName $(LOCATE[1]) $(source:D) ] ;
13760931b8f9SIngo Weinhold	local sourcePath = $(source:G=) ;
13770931b8f9SIngo Weinhold	sourcePath = $(sourcePath:D=$(sourceDir)) ;
13780931b8f9SIngo Weinhold	local targetDirComponents = [ SplitPath $(targetDir) ] ;
13790931b8f9SIngo Weinhold	local sourceComponents = [ SplitPath $(sourcePath) ] ;
13800931b8f9SIngo Weinhold
13810931b8f9SIngo Weinhold	SymLink $(target)
13827669b69fSIngo Weinhold		: [ FRelPath $(targetDirComponents) : $(sourceComponents) ]
13837669b69fSIngo Weinhold		: $(makeDefaultDependencies) ;
13840931b8f9SIngo Weinhold	NOUPDATE $(target) ;
13859eea4522SIngo Weinhold	Depends $(target) : $(source) ;
13863b9eae39SIngo Weinhold}
13873b9eae39SIngo Weinhold
1388d391d2ebSIngo Weinholdrule AbsSymLink
1389d391d2ebSIngo Weinhold{
13907bc56df1SIngo Weinhold	# AbsSymLink <link> : <link target> : <link dir>
13917669b69fSIngo Weinhold	#			: <makeDefaultDependencies> ;
1392d391d2ebSIngo Weinhold	# Creates an absolute symbolic link from <link> to <link target>.
1393d391d2ebSIngo Weinhold	# <link> and <link target> must be usual targets. If <link dir> is
1394d391d2ebSIngo Weinhold	# given, then it is set as LOCATE directory on <link>.
13957669b69fSIngo Weinhold	# <makeDefaultDependencies> If true (which is the default), <link> will be
13967669b69fSIngo Weinhold	# made a dependency of the `files' pseudo target, i.e. it will be made by
13977669b69fSIngo Weinhold	# default, and removed on `jam clean'.
1398d391d2ebSIngo Weinhold
13997669b69fSIngo Weinhold	local makeDefaultDependencies = $(4) ;
14007669b69fSIngo Weinhold	if ! $(makeDefaultDependencies) {
14017669b69fSIngo Weinhold		makeDefaultDependencies = true ;
14027669b69fSIngo Weinhold	}
14037669b69fSIngo Weinhold
1404d391d2ebSIngo Weinhold	Depends $(1) : $(2) ;
1405d391d2ebSIngo Weinhold	if $(3) {
1406d391d2ebSIngo Weinhold		MakeLocate $(1) : $(3) ;
1407d391d2ebSIngo Weinhold	}
1408d391d2ebSIngo Weinhold	SEARCH on $(2) += $(SEARCH_SOURCE) ;
14097669b69fSIngo Weinhold	if $(makeDefaultDependencies) = true {
14107669b69fSIngo Weinhold		LocalDepends files : $(1) ;
1411d391d2ebSIngo Weinhold		LocalClean clean : $(1) ;
1412d391d2ebSIngo Weinhold	}
14137669b69fSIngo Weinhold}
1414d391d2ebSIngo Weinhold
1415d391d2ebSIngo Weinholdactions AbsSymLink
1416d391d2ebSIngo Weinhold{
1417d391d2ebSIngo Weinhold	target="$(2)"
1418d391d2ebSIngo Weinhold	case "$target" in
1419d391d2ebSIngo Weinhold		/*) ;;
1420d391d2ebSIngo Weinhold		*) target=`pwd`/"$target";;
1421d391d2ebSIngo Weinhold	esac
1422d391d2ebSIngo Weinhold	$(RM) "$(1)" && $(LN) -s "$target" "$(1)"
1423d391d2ebSIngo Weinhold}
1424d391d2ebSIngo Weinhold
14257bc56df1SIngo Weinholdrule OBOSInstall
14267bc56df1SIngo Weinhold{
14277bc56df1SIngo Weinhold	# Usage: OBOSInstall <[ install [ and uninstall ] pseudotarget ]>
14287bc56df1SIngo Weinhold	#					 : <directory> : <sources to install>
14297bc56df1SIngo Weinhold	#					 : [ <installgrist> ] : [ <install rule> ] ;
14307bc56df1SIngo Weinhold	local install = $(1[1]) ;
14317bc56df1SIngo Weinhold	install ?= install ;
14327bc56df1SIngo Weinhold	local uninstall = $(1[2]) ;
14337bc56df1SIngo Weinhold	uninstall ?= un$(install) ;
14347bc56df1SIngo Weinhold	local dir = $(2) ;
14357bc56df1SIngo Weinhold	local sources = $(3) ;
14367bc56df1SIngo Weinhold	local installgrist = $(4) ;
14377bc56df1SIngo Weinhold	installgrist ?= $(INSTALLGRIST) ;
14387bc56df1SIngo Weinhold	local installRule = $(5) ;
14397bc56df1SIngo Weinhold	installRule ?= Install ;
14407bc56df1SIngo Weinhold	local targets = $(sources:G=$(installgrist)) ;
14417bc56df1SIngo Weinhold
1442bacf6872Sshatty	NotFile $(install) ;
1443bacf6872Sshatty	NotFile $(uninstall) ;
14447bc56df1SIngo Weinhold	Depends $(install) : $(targets) ;
14457bc56df1SIngo Weinhold	Clean $(uninstall) : $(targets) ;
14467bc56df1SIngo Weinhold
14477bc56df1SIngo Weinhold	SEARCH on $(sources) += $(SEARCH_SOURCE) ;
14487bc56df1SIngo Weinhold	MakeLocate $(targets) : $(dir) ;
14497bc56df1SIngo Weinhold
14507bc56df1SIngo Weinhold	local source ;
14517bc56df1SIngo Weinhold	for source in $(sources) {
14527bc56df1SIngo Weinhold		local target = $(source:G=$(installgrist)) ;
14537bc56df1SIngo Weinhold
14547bc56df1SIngo Weinhold		Depends $(target) : $(source) ;
14557bc56df1SIngo Weinhold		$(installRule) $(target) : $(source) ;
14567bc56df1SIngo Weinhold
14577bc56df1SIngo Weinhold		if [ on $(target) return $(MODE) ] {
14587bc56df1SIngo Weinhold			Chmod $(target) ;
14597bc56df1SIngo Weinhold		}
14607bc56df1SIngo Weinhold
14617bc56df1SIngo Weinhold		if $(OWNER) && $(CHOWN) {
14627bc56df1SIngo Weinhold			Chown $(target) ;
14637bc56df1SIngo Weinhold			OWNER on $(target) = $(OWNER) ;
14647bc56df1SIngo Weinhold		}
14657bc56df1SIngo Weinhold
14667bc56df1SIngo Weinhold		if $(GROUP) && $(CHGRP) {
14677bc56df1SIngo Weinhold			Chgrp $(target) ;
14687bc56df1SIngo Weinhold			GROUP on $(target) = $(GROUP) ;
14697bc56df1SIngo Weinhold		}
14707bc56df1SIngo Weinhold	}
14717bc56df1SIngo Weinhold}
14727bc56df1SIngo Weinhold
14737669b69fSIngo Weinholdrule InstallAbsSymLinkAdapter
14747669b69fSIngo Weinhold{
14757669b69fSIngo Weinhold	# InstallAbsSymLinkAdapter <link> : <link target>
14767669b69fSIngo Weinhold	if ! [ on $(2) return $(TARGET) ] {
14777669b69fSIngo Weinhold		TARGET on $(2) = [ on $(2) return $(SEARCH) ] ;
14787669b69fSIngo Weinhold	}
14797669b69fSIngo Weinhold	AbsSymLink $(1) : $(2) : : false ;
14807669b69fSIngo Weinhold}
14817669b69fSIngo Weinhold
14827bc56df1SIngo Weinholdrule OBOSInstallAbsSymLink
14837bc56df1SIngo Weinhold{
14847bc56df1SIngo Weinhold	# Usage: OBOSInstallAbsSymLink <[ install [ and uninstall ] pseudotarget ]>
14857bc56df1SIngo Weinhold	#							   : <directory> : <sources to install>
14867bc56df1SIngo Weinhold	#							   : [ <installgrist> ] ;
14877669b69fSIngo Weinhold	OBOSInstall $(1) : $(2) : $(3) : $(4) : InstallAbsSymLinkAdapter ;
14887bc56df1SIngo Weinhold}
14897bc56df1SIngo Weinhold
14907bc56df1SIngo Weinholdrule InstallRelSymLinkAdapter
14917bc56df1SIngo Weinhold{
14927bc56df1SIngo Weinhold	# InstallRelSymLinkAdapter <link> : <link target>
14937bc56df1SIngo Weinhold	if ! [ on $(2) return $(TARGET) ] {
14947bc56df1SIngo Weinhold		TARGET on $(2) = [ on $(2) return $(SEARCH) ] ;
14957bc56df1SIngo Weinhold	}
14967669b69fSIngo Weinhold	RelSymLink $(1) : $(2) : false ;
14977bc56df1SIngo Weinhold}
14987bc56df1SIngo Weinhold
14997bc56df1SIngo Weinholdrule OBOSInstallRelSymLink
15007bc56df1SIngo Weinhold{
15017bc56df1SIngo Weinhold	# Usage: OBOSInstallRelSymLink <[ install [ and uninstall ] pseudotarget ]>
15027bc56df1SIngo Weinhold	#							   : <directory> : <sources to install>
15037bc56df1SIngo Weinhold	#							   : [ <installgrist> ] ;
15047bc56df1SIngo Weinhold	OBOSInstall $(1) : $(2) : $(3) : $(4) : InstallRelSymLinkAdapter ;
15057bc56df1SIngo Weinhold}
15067bc56df1SIngo Weinhold
15077bc56df1SIngo Weinhold
150852a38012Sejakowatz#-------------------------------------------------------------------------------
150952a38012Sejakowatz# Low-level OBOS utility rules
151052a38012Sejakowatz#-------------------------------------------------------------------------------
151179b49834SIngo Weinholdrule FObjectsDir
151279b49834SIngo Weinhold{
1513121af366SIngo Weinhold	# FObjectsDir <subdir tokens>
1514121af366SIngo Weinhold	#
1515121af366SIngo Weinhold	# Returns the output directory for object files the specified
1516121af366SIngo Weinhold	# subdirectory.
1517121af366SIngo Weinhold	#
1518121af366SIngo Weinhold	# <subdir tokens>: The tokens of the subdir relative to the top.
1519121af366SIngo Weinhold	#
1520121af366SIngo Weinhold
1521121af366SIngo Weinhold	return [ FDirName $(OBOS_OBJECT_TARGET) $(1[2-]) ] ;
1522121af366SIngo Weinhold}
1523121af366SIngo Weinhold
1524121af366SIngo Weinholdrule FCurrentObjectsDir
1525121af366SIngo Weinhold{
1526121af366SIngo Weinhold	# FCurrentObjectsDir
152779b49834SIngo Weinhold	#
152879b49834SIngo Weinhold	# Returns the output directory for object files for the current
152979b49834SIngo Weinhold	# subdirectory.
153079b49834SIngo Weinhold
1531121af366SIngo Weinhold	return [ FObjectsDir $(SUBDIR_TOKENS) ] ;
153279b49834SIngo Weinhold}
153379b49834SIngo Weinhold
153452a38012Sejakowatzrule SetupObjectsDir
153552a38012Sejakowatz{
1536121af366SIngo Weinhold	LOCATE_TARGET = [ FCurrentObjectsDir ] ;
15378d3308d9SIngo Weinhold	LOCATE_SOURCE = $(LOCATE_TARGET) ;
15388d3308d9SIngo Weinhold	SEARCH_SOURCE = [ Filter $(SEARCH_SOURCE) : $(LOCATE_TARGET) ]
15398d3308d9SIngo Weinhold					$(LOCATE_TARGET) ;
154052a38012Sejakowatz}
154152a38012Sejakowatz
154252a38012Sejakowatz#-------------------------------------------------------------------------------
154352a38012Sejakowatz# Link rule/action are overwritten as they don't handle linking files who's name
154452a38012Sejakowatz# contain spaces very well. Also adds resources and version to executable.
154552a38012Sejakowatz#-------------------------------------------------------------------------------
154652a38012Sejakowatzrule Link
154752a38012Sejakowatz{
154852a38012Sejakowatz	# Note: RESFILES must be set before invocation.
154952a38012Sejakowatz	MODE on $(<) = $(EXEMODE) ;
155052a38012Sejakowatz	on $(1) XRes $(1) : $(RESFILES) ;
155152a38012Sejakowatz	Chmod $(<) ;
155252a38012Sejakowatz	SetType $(1) ;
155352a38012Sejakowatz	MimeSet $(1) ;
15541419ae2bSshatty	SetVersion $(1) ;
155552a38012Sejakowatz}
155652a38012Sejakowatz
155752a38012Sejakowatzactions Link bind NEEDLIBS
155852a38012Sejakowatz{
15591eb18edfSIngo Weinhold	$(LINK) $(LINKFLAGS) -o "$(1)" $(UNDEFS) "$(2)" "$(NEEDLIBS)" $(LINKLIBS) ;
156052a38012Sejakowatz}
156152a38012Sejakowatz
15628d3308d9SIngo Weinholdrule LexC++
15638d3308d9SIngo Weinhold{
15648d3308d9SIngo Weinhold	Depends $(1) : $(2) ;
15658d3308d9SIngo Weinhold	MakeLocate $(1) : $(LOCATE_SOURCE) ;
15668d3308d9SIngo Weinhold	LocalClean clean : $(1) ;
15678d3308d9SIngo Weinhold}
15688d3308d9SIngo Weinhold
15698d3308d9SIngo Weinholdactions LexC++
15708d3308d9SIngo Weinhold{
15718d3308d9SIngo Weinhold	$(LEX) -o$(1) $(2)
15728d3308d9SIngo Weinhold}
15738d3308d9SIngo Weinhold
15748d3308d9SIngo Weinholdrule Bison
15758d3308d9SIngo Weinhold{
15768d3308d9SIngo Weinhold	local _h ;
15778d3308d9SIngo Weinhold
1578cec8c8b5SJérôme Duval	_h = $(1:S=.hpp) ;
15798d3308d9SIngo Weinhold
15808d3308d9SIngo Weinhold	MakeLocate $(<) $(_h) : $(LOCATE_SOURCE) ;
15818d3308d9SIngo Weinhold
15828d3308d9SIngo Weinhold	Depends $(<) $(_h) : $(>) ;
15838d3308d9SIngo Weinhold	Bison1 $(<) $(_h) : $(>) ;
15848d3308d9SIngo Weinhold	LocalClean clean : $(<) $(_h) ;
15858d3308d9SIngo Weinhold
15868d3308d9SIngo Weinhold	# make sure someone includes $(_h) else it will be
15878d3308d9SIngo Weinhold	# a deadly independent target
15888d3308d9SIngo Weinhold
15898d3308d9SIngo Weinhold	Includes $(<) : $(_h) ;
15908d3308d9SIngo Weinhold}
15918d3308d9SIngo Weinhold
15928d3308d9SIngo Weinholdactions Bison1
15938d3308d9SIngo Weinhold{
15948d3308d9SIngo Weinhold	bison $(YACCFLAGS) -o $(1[1]) $(2)
1595cec8c8b5SJérôme Duval	[ -f $(1[1]).h ] && mv $(1[1]).h $(1[2]) || true
15968d3308d9SIngo Weinhold}
15978d3308d9SIngo Weinhold
1598705fc998SAxel Dörflerrule UnarchiveObjects
1599705fc998SAxel Dörfler{
1600705fc998SAxel Dörfler	# UnarchiveObjects <target objects> : <static object>
1601705fc998SAxel Dörfler
1602705fc998SAxel Dörfler	MakeLocate $(1) : $(LOCATE_TARGET) ;
1603705fc998SAxel Dörfler	Depends $(2) : $(1) ;
1604705fc998SAxel Dörfler	SEARCH on $(2) = $(SEARCH_SOURCE) ;
1605705fc998SAxel Dörfler}
1606705fc998SAxel Dörfler
1607705fc998SAxel Dörfleractions UnarchiveObjects
1608705fc998SAxel Dörfler{
16093c71865aSAxel Dörfler	cd $(1[1]:D)
16103c71865aSAxel Dörfler	ar -x "$(2)" $(1:B).o
1611705fc998SAxel Dörfler	cd -
1612705fc998SAxel Dörfler}
1613705fc998SAxel Dörfler
161452a38012Sejakowatz# BeOS specific rules
161552a38012Sejakowatz
161652a38012Sejakowatzrule XRes
161752a38012Sejakowatz{
161852a38012Sejakowatz	# XRes <target> : <resource files>
161952a38012Sejakowatz	if $(2)
162052a38012Sejakowatz	{
16219eea4522SIngo Weinhold		Depends $(1) : $(2) ;
162252a38012Sejakowatz		XRes1 $(1) : $(2) ;
162352a38012Sejakowatz	}
162452a38012Sejakowatz}
162552a38012Sejakowatz
162652a38012Sejakowatzrule XRes1 { }
162752a38012Sejakowatz
162852a38012Sejakowatzrule SetVersion
162952a38012Sejakowatz{
163052a38012Sejakowatz	# SetVersion <target>
163152a38012Sejakowatz}
163252a38012Sejakowatz
163352a38012Sejakowatzrule SetType
163452a38012Sejakowatz{
163552a38012Sejakowatz	# SetType <target>
163652a38012Sejakowatz}
163752a38012Sejakowatz
163852a38012Sejakowatzrule MimeSet
163952a38012Sejakowatz{
164052a38012Sejakowatz	# SetType <target>
164152a38012Sejakowatz}
164252a38012Sejakowatz
164352a38012Sejakowatz
164452a38012Sejakowatzif $(OS) = BEOS
164552a38012Sejakowatz{
164652a38012Sejakowatz
164752a38012Sejakowatzactions XRes1
164852a38012Sejakowatz{
16490931b8f9SIngo Weinhold	xres -o "$(1)" "$(2)" ;
165052a38012Sejakowatz}
165152a38012Sejakowatz
165252a38012Sejakowatzactions SetVersion
165352a38012Sejakowatz{
165452a38012Sejakowatz	setversion "$(1)" -system $(OBOS_BUILD_VERSION) -short "$(OBOS_BUILD_DESCRIPTION)" ;
165552a38012Sejakowatz}
165652a38012Sejakowatz
165752a38012Sejakowatzactions SetType
165852a38012Sejakowatz{
165952a38012Sejakowatz	settype -t $(OBOS_TARGET_TYPE) "$(1)" ;
166052a38012Sejakowatz}
166152a38012Sejakowatz
166252a38012Sejakowatzactions MimeSet
166352a38012Sejakowatz{
166452a38012Sejakowatz	mimeset -f "$(1)" ;
166552a38012Sejakowatz}
166652a38012Sejakowatz
166752a38012Sejakowatz}	# if BEOS
166852a38012Sejakowatz
166952a38012Sejakowatz
167052a38012Sejakowatzrule assemble
167152a38012Sejakowatz{
167294782cf7SIngo Weinhold	Depends $(<) : $(>) ;
167394782cf7SIngo Weinhold	ASFLAGS on $(<) += $(ASFLAGS) $(SUBDIRASFLAGS) ;
167494782cf7SIngo Weinhold	ASHDRS on $(<) = [ FIncludes $(SEARCH_SOURCE) $(SUBDIRHDRS) $(HDRS) ] ;
167552a38012Sejakowatz}
167652a38012Sejakowatz
167752a38012Sejakowatzactions assemble
167852a38012Sejakowatz{
1679a8687de4SAxel Dörfler	$(CC) -c "$(2)" -O2 $(ASFLAGS) -D_ASSEMBLER $(KERNEL_CCFLAGS) $(ASHDRS) -o "$(1)" ;
168052a38012Sejakowatz}
168152a38012Sejakowatz
16820931b8f9SIngo Weinhold# Overridden to allow spaces in file names.
16830931b8f9SIngo Weinholdactions Chmod1
16840931b8f9SIngo Weinhold{
16850931b8f9SIngo Weinhold	$(CHMOD) "$(MODE)" "$(1)"
16860931b8f9SIngo Weinhold}
16870931b8f9SIngo Weinhold
16886991af8cSIngo Weinhold# Overridden to allow spaces in file names.
16896991af8cSIngo Weinholdactions piecemeal together existing Clean
16906991af8cSIngo Weinhold{
16916991af8cSIngo Weinhold	$(RM) "$(>)"
16926991af8cSIngo Weinhold}
16936991af8cSIngo Weinhold
169408125d07SIngo Weinholdrule ObjectReference
169508125d07SIngo Weinhold{
169608125d07SIngo Weinhold	# ObjectReference <reference object> : <source object>
169708125d07SIngo Weinhold	# Makes <reference object> refer to the same file as <source object>.
169808125d07SIngo Weinhold	# The filenames must of course be identical.
169908125d07SIngo Weinhold	# <source object> must have already been LOCATEd.
170008125d07SIngo Weinhold
170108125d07SIngo Weinhold	local ref = $(1) ;
170208125d07SIngo Weinhold	local source = $(2) ;
170308125d07SIngo Weinhold	if $(ref) != $(source) {
17049eea4522SIngo Weinhold		Depends $(ref) : $(source) ;
170521df5945SIngo Weinhold		LOCATE on $(ref) = [ on $(source) return $(LOCATE) ] ;
170608125d07SIngo Weinhold	}
170708125d07SIngo Weinhold}
170808125d07SIngo Weinhold
170908125d07SIngo Weinholdrule ObjectReferences
171008125d07SIngo Weinhold{
171108125d07SIngo Weinhold	# ObjectReferences <source objects>
171208125d07SIngo Weinhold	# Creates local references to <source objects>, i.e. identifiers with the
171308125d07SIngo Weinhold	# current grist referring to the same files. <source objects> must have
171408125d07SIngo Weinhold	# already been LOCATEd.
171508125d07SIngo Weinhold
171608125d07SIngo Weinhold	local source ;
171708125d07SIngo Weinhold	for source in $(1) {
171808125d07SIngo Weinhold		ObjectReference [ FGristFiles $(source) ] : $(source) ;
171908125d07SIngo Weinhold	}
172008125d07SIngo Weinhold}
172108125d07SIngo Weinhold
17229fc6b2e1SIngo Weinholdrule Filter
17239fc6b2e1SIngo Weinhold{
17249fc6b2e1SIngo Weinhold	# Filter <list> : <excludes> ;
17259fc6b2e1SIngo Weinhold	# Removes all occurrences of <excludes> in <list>.
17269fc6b2e1SIngo Weinhold
17279fc6b2e1SIngo Weinhold	local list = $(1) ;
17289fc6b2e1SIngo Weinhold	local excludes = $(2) ;
17299fc6b2e1SIngo Weinhold	local newList ;
17309fc6b2e1SIngo Weinhold	local item ;
17319fc6b2e1SIngo Weinhold	for item in $(list) {
17329fc6b2e1SIngo Weinhold		local skip ;
17339fc6b2e1SIngo Weinhold		local exclude ;
17349fc6b2e1SIngo Weinhold		for exclude in $(excludes) {
17359fc6b2e1SIngo Weinhold			if $(item) = $(exclude) {
17369fc6b2e1SIngo Weinhold				skip = true ;
17379fc6b2e1SIngo Weinhold			}
17389fc6b2e1SIngo Weinhold		}
17399fc6b2e1SIngo Weinhold		if ! $(skip) {
1740dd9f8062SIngo Weinhold			newList += $(item) ;
17419fc6b2e1SIngo Weinhold		}
17429fc6b2e1SIngo Weinhold	}
17439fc6b2e1SIngo Weinhold	return $(newList) ;
17449fc6b2e1SIngo Weinhold}
17459fc6b2e1SIngo Weinhold
17460931b8f9SIngo Weinhold
174752a38012Sejakowatz## Kernel stuff!
174852a38012Sejakowatz
174952a38012Sejakowatzrule SetupKernel
175052a38012Sejakowatz{
175152a38012Sejakowatz	# Usage SetupKernel <sources_or_objects> : <extra_cc_flags>;
175294a49b21SIngo Weinhold	#
175394a49b21SIngo Weinhold	# <sources_or_objects> - Ideally sources, otherwise HDRSEARCH can not be
175494a49b21SIngo Weinhold	#                        set for the sources and the sources some header
175594a49b21SIngo Weinhold	#                        dependencies might be missing.
175652a38012Sejakowatz
175794a49b21SIngo Weinhold	local sources = [ FGristFiles $(1) ] ;
175894a49b21SIngo Weinhold	local _objs = $(sources:S=$(SUFOBJ)) ;
175952a38012Sejakowatz
176028d2a30eSDaniel Reinhold	#Setup Kernel header directories
176199b8dab3SAxel Dörfler	local public_kernel_includes = add-ons/file_system add-ons/graphics app device drivers kernel storage support ;
1762c0e501e0SIngo Weinhold	local private_kernel_includes = $(DOT) kernel libroot kernel/boot/platform/$(OBOS_BOOT_PLATFORM) ;
1763a6c008e1Sbeveloper	# Use posix headers directory
1764c0e501e0SIngo Weinhold	local headers = [ FDirName $(OBOS_TOP) headers posix ] ;
1765a6c008e1Sbeveloper	# Use public OS header directories
1766c0e501e0SIngo Weinhold	headers += [ PublicHeaders $(public_kernel_includes) ] ;
1767089a0629Sbeveloper	# Use private directories
1768c0e501e0SIngo Weinhold	headers += [ PrivateHeaders $(private_kernel_includes) ] ;
176909c5682dSIngo Weinhold	# The platform dependent headers.
1770c0e501e0SIngo Weinhold	headers += $(PLATFORM_HEADERS) ;
1771a6c008e1Sbeveloper
177294a49b21SIngo Weinhold	SourceHdrs $(sources) : $(headers) ;
177394a49b21SIngo Weinhold	UseArchObjectHeaders $(sources) : $(OBOS_ARCH) ;
177452a38012Sejakowatz
1775c0e501e0SIngo Weinhold	local object ;
1776c0e501e0SIngo Weinhold	for object in $(_objs) {
1777c0e501e0SIngo Weinhold		ObjectCcFlags $(object) : $(KERNEL_CCFLAGS) $(2) ;
1778c0e501e0SIngo Weinhold		ObjectC++Flags $(object) : $(KERNEL_C++FLAGS) $(2) ;
1779c0e501e0SIngo Weinhold	}
178052a38012Sejakowatz}
178152a38012Sejakowatz
178252a38012Sejakowatzrule KernelObjects
178352a38012Sejakowatz{
1784c0e501e0SIngo Weinhold	SetupObjectsDir ;
178552a38012Sejakowatz
178652a38012Sejakowatz	Objects $(1) ;
1787c0e501e0SIngo Weinhold
1788c0e501e0SIngo Weinhold	SetupKernel $(1) : $(2) ;
178952a38012Sejakowatz}
179052a38012Sejakowatz
179152a38012Sejakowatzrule KernelLd
179252a38012Sejakowatz{
179380721244SAxel Dörfler	# KernelLd <name> : <objs> : <linkerscript> : <args> : <gcc_off> : <config_section> ;
179452a38012Sejakowatz
1795c0e501e0SIngo Weinhold	SetupObjectsDir ;
179652a38012Sejakowatz	LINK on $(1) = ld ;
179752a38012Sejakowatz
179852a38012Sejakowatz	LINKFLAGS on $(1) = $(4) ;
179952a38012Sejakowatz	if $(3) { LINKFLAGS on $(1) += --script=$(3) ; }
180052a38012Sejakowatz
180152a38012Sejakowatz	# Remove any preset LINKLIBS
180252a38012Sejakowatz	LINKLIBS on $(1) =  ;
180352a38012Sejakowatz
180452a38012Sejakowatz	# Show that we depend on the libraries we need
18059eea4522SIngo Weinhold	LocalClean clean : $(1) ;
18069eea4522SIngo Weinhold	LocalDepends all : $(1) ;
180752a38012Sejakowatz	Depends $(1) : $(2) ;
180852a38012Sejakowatz
180952a38012Sejakowatz	if $(6) {
181052a38012Sejakowatz		for i in $(6) {
18112a83bfb4SIngo Weinhold			KernelConfigSection $(i) : elf32 : $(1) ;
181252a38012Sejakowatz		}
181352a38012Sejakowatz	}
181452a38012Sejakowatz
181552a38012Sejakowatz	MakeLocate $(1) : $(LOCATE_TARGET) ;
181652a38012Sejakowatz
181709c5682dSIngo Weinhold	# Add the platform specific static libs (libgcc.a).
181852a38012Sejakowatz	if ! $(5) {
181909c5682dSIngo Weinhold		LINKLIBS on $(1) += $(PLATFORM_LINKLIBS) ;
182052a38012Sejakowatz	}
1821c0e501e0SIngo Weinhold
1822c0e501e0SIngo Weinhold	SetupKernel $(2) ;
182352a38012Sejakowatz}
182452a38012Sejakowatz
182552a38012Sejakowatzactions KernelLd
182652a38012Sejakowatz{
18271eb18edfSIngo Weinhold	$(LINK) $(LINKFLAGS) -o "$(1)" "$(2)" $(LINKLIBS) ;
182852a38012Sejakowatz}
182952a38012Sejakowatz
1830811903d1SAxel Dörflerrule KernelAddon
1831811903d1SAxel Dörfler{
1832600203b1SAxel Dörfler	# KernelAddon <name> : <relpath> : <sources> : <static-libraries> ;
1833811903d1SAxel Dörfler
1834811903d1SAxel Dörfler	local sources = $(3) ;
1835811903d1SAxel Dörfler
1836c0e501e0SIngo Weinhold	SetupObjectsDir ;
183794a49b21SIngo Weinhold	Addon $(1) : $(2) : $(sources) ;
1838811903d1SAxel Dörfler	ObjectCcFlags $(sources) : -D_KERNEL_MODE=1 -no-fpic ;
1839df48dfedSIngo Weinhold	ObjectC++Flags $(sources) : -D_KERNEL_MODE=1 -no-fpic -fno-exceptions ;
1840811903d1SAxel Dörfler	LINKFLAGS on $(1) = [ on $(1) return $(LINKFLAGS) ] -nostdlib ;
1841d5807053SIngo Weinhold	LinkSharedOSLibs $(1) : $(4) <nogrist>kernel.so ;
184294a49b21SIngo Weinhold	SetupKernel $(sources) ;
1843811903d1SAxel Dörfler}
1844811903d1SAxel Dörfler
184580721244SAxel Dörflerrule KernelMergeObject
184680721244SAxel Dörfler{
18472fbd7065SIngo Weinhold	# KernelMergeObject <name> : <sources> : <extra CFLAGS> : <other objects> ;
18482fbd7065SIngo Weinhold	# Compiles source files and merges the object files to an object file.
18492fbd7065SIngo Weinhold	# <name>: Name of the object file to create. No grist will be added.
18502fbd7065SIngo Weinhold	# <sources>: Sources to be compiled. Grist will be added.
18512fbd7065SIngo Weinhold	# <extra CFLAGS>: Additional flags for compilation.
18522fbd7065SIngo Weinhold	# <other objects>: Object files or static libraries to be merged. No grist
18532fbd7065SIngo Weinhold	#                  will be added.
18542fbd7065SIngo Weinhold	#
185580721244SAxel Dörfler
1856c0e501e0SIngo Weinhold	SetupObjectsDir ;
185780721244SAxel Dörfler
185880721244SAxel Dörfler	MakeLocateObjects $(2) ;
185980721244SAxel Dörfler	Objects $(2) ;
18602fbd7065SIngo Weinhold	MergeObjectFromObjects $(1) : $(2:S=$(SUFOBJ)) : $(4) ;
1861c0e501e0SIngo Weinhold
1862c0e501e0SIngo Weinhold	SetupKernel $(2) : $(3) ;
186380721244SAxel Dörfler}
186480721244SAxel Dörfler
186552a38012Sejakowatzrule KernelStaticLibrary
186652a38012Sejakowatz{
186752a38012Sejakowatz	# Usage KernelStaticLibrary <name> : <sources> : <extra cc flags>  ;
186852a38012Sejakowatz	# This is designed to take a set of sources and libraries and create
186952a38012Sejakowatz	# a file called lib<name>.a
187052a38012Sejakowatz
1871c0e501e0SIngo Weinhold	SetupObjectsDir ;
187252a38012Sejakowatz
187352a38012Sejakowatz	MakeLocateObjects $(2) ;
187452a38012Sejakowatz	Library $(1) : $(2) ;
1875c0e501e0SIngo Weinhold
1876c0e501e0SIngo Weinhold	SetupKernel $(2) : $(3) ;
187752a38012Sejakowatz}
187852a38012Sejakowatz
187952a38012Sejakowatzrule KernelStaticLibraryObjects
188052a38012Sejakowatz{
188152a38012Sejakowatz	# Usage KernelStaticLibrary <name> : <sources> ;
188252a38012Sejakowatz	# This is designed to take a set of sources and libraries and create
188352a38012Sejakowatz	# a file called <name>
188452a38012Sejakowatz
1885c0e501e0SIngo Weinhold	SetupObjectsDir ;
188652a38012Sejakowatz
188752a38012Sejakowatz	# Show that we depend on the libraries we need
18889eea4522SIngo Weinhold	LocalClean clean : $(1) ;
18899eea4522SIngo Weinhold	LocalDepends all : $(1) ;
189052a38012Sejakowatz	Depends $(1) : $(2) ;
189152a38012Sejakowatz
189252a38012Sejakowatz	MakeLocate $(1) : $(LOCATE_TARGET) ;
1893c0e501e0SIngo Weinhold
1894c0e501e0SIngo Weinhold	SetupKernel $(2) ;
189552a38012Sejakowatz}
189652a38012Sejakowatz
189752a38012Sejakowatzactions KernelStaticLibraryObjects
189852a38012Sejakowatz{
18990931b8f9SIngo Weinhold	ar -r "$(1)" "$(2)" ;
190052a38012Sejakowatz}
190152a38012Sejakowatz
19025dc4e1efSIngo Weinholdrule BuildPlatformMain
190352a38012Sejakowatz{
19045dc4e1efSIngo Weinhold	# Usage BuildPlatformMain <target> : <sources> ;
190552a38012Sejakowatz	SetupObjectsDir ;
19065dc4e1efSIngo Weinhold	SetupDefaultIncludes ;
190752a38012Sejakowatz
19085dc4e1efSIngo Weinhold	# Remove `-nostdinc' from CCFLAGS and C++FLAGS.
19095dc4e1efSIngo Weinhold	local oldCCFLAGS = $(CCFLAGS) ;
19105dc4e1efSIngo Weinhold	local oldC++FLAGS = $(C++FLAGS) ;
19115dc4e1efSIngo Weinhold	CCFLAGS = [ Filter $(CCFLAGS) : -nostdinc ] ;
19125dc4e1efSIngo Weinhold	C++FLAGS = [ Filter $(C++FLAGS) : -nostdinc ] ;
191352a38012Sejakowatz
191452a38012Sejakowatz	Main $(1) : $(2) ;
19155dc4e1efSIngo Weinhold
19165dc4e1efSIngo Weinhold	# Reset CCFLAGS and C++FLAGS to original values.
19175dc4e1efSIngo Weinhold	CCFLAGS = $(oldCCFLAGS) ;
19185dc4e1efSIngo Weinhold	C++FLAGS = $(oldC++FLAGS) ;
191952a38012Sejakowatz}
192052a38012Sejakowatz
19219fcaa61dSIngo Weinholdrule BuildPlatformTest
19229fcaa61dSIngo Weinhold{
19239fcaa61dSIngo Weinhold	# Usage BuildPlatformTest <target> : <sources> ;
19249fcaa61dSIngo Weinhold
19259fcaa61dSIngo Weinhold	local target = $(1) ;
19269fcaa61dSIngo Weinhold	local sources = $(2) ;
19279fcaa61dSIngo Weinhold
19289fcaa61dSIngo Weinhold	BuildPlatformMain $(target) : $(sources) ;
19299fcaa61dSIngo Weinhold	local relPath ;
19309fcaa61dSIngo Weinhold	if [ FIsPrefix src tests : $(SUBDIR_TOKENS) ] {
19319fcaa61dSIngo Weinhold		relPath = $(SUBDIR_TOKENS[3-]) ;
19329fcaa61dSIngo Weinhold	} else {
19339fcaa61dSIngo Weinhold		relPath = $(SUBDIR_TOKENS[2-]) ;
19349fcaa61dSIngo Weinhold	}
19359fcaa61dSIngo Weinhold	MakeLocate $(target) : [ FDirName $(OBOS_TEST_DIR) $(relPath) ] ;
19369fcaa61dSIngo Weinhold}
19379fcaa61dSIngo Weinhold
193852a38012Sejakowatzrule KernelConfigSection
193952a38012Sejakowatz{
194052a38012Sejakowatz	# KernelConfigSection <section> : <type> : <file>  ;
19412a83bfb4SIngo Weinhold
19422a83bfb4SIngo Weinhold	SECTION_NAMES on $(OBOS_KERNEL_CONFIG) += $(1) ;
19432a83bfb4SIngo Weinhold	SECTION_TYPES on $(OBOS_KERNEL_CONFIG) += $(2) ;
19442a83bfb4SIngo Weinhold	SECTION_FILES on $(OBOS_KERNEL_CONFIG) += $(3) ;
19452a83bfb4SIngo Weinhold
19462a83bfb4SIngo Weinhold	Depends $(OBOS_KERNEL_CONFIG) : $(3) ;
194752a38012Sejakowatz}
194852a38012Sejakowatz
194952a38012Sejakowatzrule WriteKernelConfig
195052a38012Sejakowatz{
195152a38012Sejakowatz	# usage: WriteKernelConfig <target> ;
195252a38012Sejakowatz
19539eea4522SIngo Weinhold	LocalDepends files : $(1) ;
195452a38012Sejakowatz
19552a83bfb4SIngo Weinhold	MakeLocate $(1) : $(OBOS_OBJECT_TARGET) ;
195652a38012Sejakowatz
19579eea4522SIngo Weinhold	LocalClean clean : $(1) ;
195852a38012Sejakowatz}
195952a38012Sejakowatz
19602a83bfb4SIngo Weinholdactions WriteKernelConfig bind SECTION_FILES
196152a38012Sejakowatz{
19620931b8f9SIngo Weinhold	target="$(1)"
19630931b8f9SIngo Weinhold	echo "# OpenBeOS Kernel Config File" > "$target"
19640931b8f9SIngo Weinhold	echo "# Automatically generated - do not edit!" >> "$target"
19652a83bfb4SIngo Weinhold	count=0
19662a83bfb4SIngo Weinhold	for section in "$(SECTION_NAMES)" ; do
19672a83bfb4SIngo Weinhold		count=`expr $count + 1`
19682a83bfb4SIngo Weinhold		eval section$count="$section"
19692a83bfb4SIngo Weinhold	done
19702a83bfb4SIngo Weinhold	i=1
19712a83bfb4SIngo Weinhold	for type in "$(SECTION_TYPES)" ; do
19722a83bfb4SIngo Weinhold		eval type$i="$type"
19732a83bfb4SIngo Weinhold		i=`expr $i + 1`
19742a83bfb4SIngo Weinhold	done
19752a83bfb4SIngo Weinhold	i=1
19762a83bfb4SIngo Weinhold	for file in "$(SECTION_FILES)" ; do
19772a83bfb4SIngo Weinhold		eval file$i="$file"
19782a83bfb4SIngo Weinhold		i=`expr $i + 1`
19792a83bfb4SIngo Weinhold	done
19802a83bfb4SIngo Weinhold	for i in `seq $count` ; do
19812a83bfb4SIngo Weinhold		eval section="\$section$i"
19822a83bfb4SIngo Weinhold		eval type="\$type$i"
19832a83bfb4SIngo Weinhold		eval file="\$file$i"
19840931b8f9SIngo Weinhold		echo "" >> "$target"
19852a83bfb4SIngo Weinhold		echo "["$section"]" >> "$target"
19862a83bfb4SIngo Weinhold		echo "type="$type >> "$target"
19870931b8f9SIngo Weinhold		case "$file" in
198852a38012Sejakowatz			/*) ;;
19890931b8f9SIngo Weinhold			*) file=`pwd`/"$file";;
199052a38012Sejakowatz		esac
19912a83bfb4SIngo Weinhold		echo "file="$file >> "$target"
199252a38012Sejakowatz	done
199352a38012Sejakowatz}
199452a38012Sejakowatz
199552a38012Sejakowatzrule BuildKernel
199652a38012Sejakowatz{
199752a38012Sejakowatz	# Usage BuildKernel <target> : <config_file> ;
19980c0b2cd0SIngo Weinhold	local kernel = $(1) ;
19990c0b2cd0SIngo Weinhold	local configFile = $(2) ;
20000c0b2cd0SIngo Weinhold	local bootmaker = bootmaker ;
200152a38012Sejakowatz
20029eea4522SIngo Weinhold	LocalDepends all : $(kernel) ;
20030c0b2cd0SIngo Weinhold	Depends $(kernel) : $(configFile) $(bootmaker) ;
20049eea4522SIngo Weinhold	LocalClean clean : $(kernel) ;
20050c0b2cd0SIngo Weinhold	MakeLocate $(kernel) : $(LOCATE_TARGET) ;
200652a38012Sejakowatz
20070c0b2cd0SIngo Weinhold	BOOT_MAKER on $(kernel) = $(bootmaker) ;
200852a38012Sejakowatz}
200952a38012Sejakowatz
20100c0b2cd0SIngo Weinholdactions BuildKernel bind BOOT_MAKER
201152a38012Sejakowatz{
20120c0b2cd0SIngo Weinhold	"$(BOOT_MAKER)" --strip-debug --strip-binary strip "$(2)" -o "$(1)" ;
201352a38012Sejakowatz	echo ""
201452a38012Sejakowatz	echo "Kernel linked!"
201552a38012Sejakowatz	echo ""
201652a38012Sejakowatz}
201752a38012Sejakowatz
201852a38012Sejakowatzrule KernelFloppyImage
201952a38012Sejakowatz{
202052a38012Sejakowatz	# Usage KernelFloppyImage <target> : <kernel> : <bootblock> ;
20210c0b2cd0SIngo Weinhold	local floppy = $(1) ;
20220c0b2cd0SIngo Weinhold	local kernel = $(2) ;
20230c0b2cd0SIngo Weinhold	local bootblock = $(3) ;
20240c0b2cd0SIngo Weinhold	local makeflop = makeflop ;
202552a38012Sejakowatz
20269eea4522SIngo Weinhold	LocalDepends all : $(floppy) ;
20270c0b2cd0SIngo Weinhold	Depends $(floppy) : $(kernel) $(bootblock) $(makeflop) ;
20289eea4522SIngo Weinhold	LocalClean clean : $(floppy) ;
20290c0b2cd0SIngo Weinhold	MakeLocate $(floppy) : $(OBOS_OBJECT_TARGET) ;
203052a38012Sejakowatz
20310c0b2cd0SIngo Weinhold	BOOT_BLOCK on $(floppy) = $(bootblock) ;
20320c0b2cd0SIngo Weinhold	MAKE_FLOP on $(floppy) = $(makeflop) ;
203352a38012Sejakowatz}
203452a38012Sejakowatz
203552a38012Sejakowatz# This may be a bit verbose, but I think it's useful to show what's
203652a38012Sejakowatz# going on, at least in this early stage of development.
20370c0b2cd0SIngo Weinholdactions KernelFloppyImage bind BOOT_BLOCK bind MAKE_FLOP
203852a38012Sejakowatz{
20397378dd7fSAxel Dörfler	"$(MAKE_FLOP)" "-p $(shell expr 18 \* 2 \* 512)" "$(BOOT_BLOCK)" "$(2)" "$(1)" ;
20400c0b2cd0SIngo Weinhold
204152a38012Sejakowatz	echo ""
204252a38012Sejakowatz	echo "*************************************************"
204352a38012Sejakowatz	echo "*         Kernel build completed!               *"
204452a38012Sejakowatz	echo "*    Boot image for a 1.44M floppy created      *"
204552a38012Sejakowatz	echo "*************************************************"
204652a38012Sejakowatz	echo ""
20470c0b2cd0SIngo Weinhold	echo "Floppy image is $(1)"
204852a38012Sejakowatz	echo "The following command will write it to a floppy on BeOS"
20490c0b2cd0SIngo Weinhold	echo "  dd if=$(1) of=/dev/disk/floppy/raw bs=18k"
20500c0b2cd0SIngo Weinhold	echo "Alternatively you can run"
20510c0b2cd0SIngo Weinhold	echo "  ./configure --floppy /dev/disk/floppy/raw"
20520c0b2cd0SIngo Weinhold	echo "once and build + write the image subsequently via"
20530c0b2cd0SIngo Weinhold	echo "  jam installfloppy"
205452a38012Sejakowatz	echo ""
205552a38012Sejakowatz}
205652a38012Sejakowatz
20570c0b2cd0SIngo Weinholdrule InstallFloppy
20580c0b2cd0SIngo Weinhold{
20590c0b2cd0SIngo Weinhold	# InstallFloppy <target> : <floppy>
20600c0b2cd0SIngo Weinhold	# "dd"s <floppy> to $(FLOPPY_PATH).
20610c0b2cd0SIngo Weinhold
20620c0b2cd0SIngo Weinhold	local target = $(1) ;
20630c0b2cd0SIngo Weinhold	local floppy = $(2) ;
20640c0b2cd0SIngo Weinhold
20650c0b2cd0SIngo Weinhold	NotFile $(target) ;
20660c0b2cd0SIngo Weinhold	Always $(target) ;
20670c0b2cd0SIngo Weinhold	Depends $(target) : $(floppy) ;
20680c0b2cd0SIngo Weinhold}
20690c0b2cd0SIngo Weinhold
20700c0b2cd0SIngo Weinholdactions InstallFloppy
20710c0b2cd0SIngo Weinhold{
20720c0b2cd0SIngo Weinhold	if [ -z $(FLOPPY_PATH) ] ; then
20730c0b2cd0SIngo Weinhold		echo "Can't install floppy: FLOPPY_PATH not set."
20740c0b2cd0SIngo Weinhold		echo "run: ./configure --floppy <floppy path>"
20750c0b2cd0SIngo Weinhold		echo
20760c0b2cd0SIngo Weinhold		exit 0
20770c0b2cd0SIngo Weinhold	fi
20780c0b2cd0SIngo Weinhold	dd if=$(2) of=$(FLOPPY_PATH) bs=18k
20790c0b2cd0SIngo Weinhold}
208052a38012Sejakowatz
208121df5945SIngo Weinhold#-------------------------------------------------------------------------------
208221df5945SIngo Weinhold# FreeType 2 specific rules and variables
208321df5945SIngo Weinhold#-------------------------------------------------------------------------------
208421df5945SIngo Weinhold
208521df5945SIngo WeinholdFT2_INCLUDE = [ FDirName $(OBOS_TOP) headers libs freetype2 ] ;
208621df5945SIngo WeinholdFT2_SRC     = [ FDirName $(OBOS_TOP) src libs freetype2 ] ;
208721df5945SIngo Weinhold
208821df5945SIngo WeinholdFT2_LIB     = freetype ;
208921df5945SIngo Weinhold
2090fbd28219SIngo WeinholdFT2_COMPONENTS ?= gzip       # support for gzip-compressed files.
2091fbd28219SIngo Weinhold                  autohint   # auto-hinter
2092fbd28219SIngo Weinhold                  base       # base component (public APIs)
2093fbd28219SIngo Weinhold                  bdf        # BDF font driver
2094fbd28219SIngo Weinhold                  cache      # cache sub-system
2095fbd28219SIngo Weinhold                  cff        # CFF/CEF font driver
2096fbd28219SIngo Weinhold                  cid        # Postscript CID-keyed font driver
20979ec866ccSDarkWyrm		lzw	   # LZW routines
2098fbd28219SIngo Weinhold                  pcf        # PCF font driver
2099fbd28219SIngo Weinhold                  pfr        # PFR/TrueDoc font driver
2100fbd28219SIngo Weinhold                  psaux      # Common Postscript routines module
2101fbd28219SIngo Weinhold                  pshinter   # Postscript hinter module
2102fbd28219SIngo Weinhold                  psnames    # Postscript names handling
2103fbd28219SIngo Weinhold                  raster     # Monochrome rasterizer
2104fbd28219SIngo Weinhold                  smooth     # Anti-aliased rasterizer
2105fbd28219SIngo Weinhold                  sfnt       # SFNT-based format support routines
2106fbd28219SIngo Weinhold                  truetype   # TrueType font driver
2107fbd28219SIngo Weinhold                  type1      # Postscript Type 1 font driver
2108fbd28219SIngo Weinhold                  type42     # Postscript Type 42 (embedded TrueType) driver
2109fbd28219SIngo Weinhold                  winfonts   # Windows FON/FNT font driver
2110fbd28219SIngo Weinhold                  ;
2111fbd28219SIngo Weinhold
211221df5945SIngo Weinholdrule UseFreeTypeHeaders
211321df5945SIngo Weinhold{
211421df5945SIngo Weinhold	SubDirHdrs $(FT2_INCLUDE) ;
211521df5945SIngo Weinhold}
211621df5945SIngo Weinhold
211721df5945SIngo Weinholdrule UseFreeTypeObjectHeaders
211821df5945SIngo Weinhold{
21199b60a208SIngo Weinhold	# UseFreeTypeObjectHeaders <sources> [ : <objects> ] ;
21209b60a208SIngo Weinhold	SourceHdrs $(1) : $(FT2_INCLUDE) : $(2) ;
212121df5945SIngo Weinhold}
212221df5945SIngo Weinhold
212321df5945SIngo Weinholdrule FT2_SubDir
212421df5945SIngo Weinhold{
212521df5945SIngo Weinhold	# FT2_SubDir <dir>
212621df5945SIngo Weinhold	# <dir>: Components of a directory in the original hierarchy.
212721df5945SIngo Weinhold	local dir = $(1) ;
212821df5945SIngo Weinhold	local topDir ;
212921df5945SIngo Weinhold	switch $(dir[1])
213021df5945SIngo Weinhold	{
213121df5945SIngo Weinhold		case "include"	: topDir = $(FT2_INCLUDE) ;
213221df5945SIngo Weinhold		case src		: topDir = $(FT2_SRC) ;
213321df5945SIngo Weinhold		case *			: ECHO "Unknown FreeType2 directory: " $(dir) ;
213421df5945SIngo Weinhold	}
213521df5945SIngo Weinhold	return [ FDirName $(topDir) $(dir[2-]) ] ;
213621df5945SIngo Weinhold}
213721df5945SIngo Weinhold
213821df5945SIngo Weinholdrule FT2_Library
213921df5945SIngo Weinhold{
214021df5945SIngo Weinhold	# FT2_Library <libname> : <sources>
214121df5945SIngo Weinhold	# Builds objects from sources and adds the objects to the list of objects
214221df5945SIngo Weinhold	# to be linked into the library.
214321df5945SIngo Weinhold	# <libname> The name of the library.
214421df5945SIngo Weinhold	# <sources> The sources.
214521df5945SIngo Weinhold
214621df5945SIngo Weinhold	local library = lib$(1).so ;
214721df5945SIngo Weinhold	local sources = $(2) ;
214828d2a30eSDaniel Reinhold	SetupIncludes ;
214921df5945SIngo Weinhold	SetupObjectsDir ;
215021df5945SIngo Weinhold	MakeLocateObjects $(sources) ;
215121df5945SIngo Weinhold	Objects $(sources) ;
215221df5945SIngo Weinhold	LIBRARY_OBJECTS on $(library) += [ FGristFiles $(sources:S=$(SUFOBJ)) ] ;
215321df5945SIngo Weinhold}
215421df5945SIngo Weinhold
215521df5945SIngo Weinholdrule FT2_LinkLibrary
215621df5945SIngo Weinhold{
215721df5945SIngo Weinhold	# FT2_LinkLibrary <libname>
215821df5945SIngo Weinhold	# Links the library from the objects build with FT2_LIBRARY before.
215921df5945SIngo Weinhold
216021df5945SIngo Weinhold	local library = lib$(1).so ;
216121df5945SIngo Weinhold	local objects = [ on $(library) return $(LIBRARY_OBJECTS) ] ;
216221df5945SIngo Weinhold	ObjectReferences $(objects) ;
216321df5945SIngo Weinhold	objects = [ FGristFiles $(objects) ] ;
216421df5945SIngo Weinhold	SharedLibraryFromObjects $(1) : $(objects) ;
216521df5945SIngo Weinhold}
216621df5945SIngo Weinhold
21679b7a4b5dSshatty#-------------------------------------------------------------------------------
21689b7a4b5dSshatty# Packages for OBOS alpha/beta testers
21699b7a4b5dSshatty#-------------------------------------------------------------------------------
21709b7a4b5dSshatty
21719b7a4b5dSshattyrule Copy
21729b7a4b5dSshatty{
21735c413522Sshatty	Depends $(<) : $(>) ;
21749b7a4b5dSshatty	SEARCH on $(>) = $(SEARCH_SOURCE) ;
21759b7a4b5dSshatty}
21769b7a4b5dSshatty
21779b7a4b5dSshattyactions Copy
21789b7a4b5dSshatty{
217915716fddSPhilippe Houdoin	cp -dp "$(>)" "$(<)" ;
218015716fddSPhilippe Houdoin	if [ -f "$(>)" ] ; then copyattr "$(>)" "$(<)" ; fi ;
21819b7a4b5dSshatty}
21829b7a4b5dSshatty
21839b7a4b5dSshattyrule Packages
21849b7a4b5dSshatty{
21859b7a4b5dSshatty	local packagenames = $(1) ;
21869b7a4b5dSshatty	local packagefiles = $(2) ;
21879b7a4b5dSshatty	local path = $(3) ;
21889b7a4b5dSshatty	for name in $(packagenames) {
21899b7a4b5dSshatty		Package $(name) : $(packagefiles) : $(path) ;
21909b7a4b5dSshatty    }
21919b7a4b5dSshatty}
21929b7a4b5dSshatty
21939b7a4b5dSshattyrule Package
21949b7a4b5dSshatty{
21959b7a4b5dSshatty	local packagename = $(1) ;
21969b7a4b5dSshatty    local packagefiles = $(2) ;
21979b7a4b5dSshatty	local path = $(3) ;
21989b7a4b5dSshatty
2199c06f365fSIngo Weinhold	local packagezip = $(packagename:S=.zip:G=_packages) ;
22009b7a4b5dSshatty	local packagedir = [ FDirName $(OBOS_PACKAGE_DIR) $(packagename) ] ;
22019b7a4b5dSshatty
22029b7a4b5dSshatty    local installscript = install.sh ;
2203c06f365fSIngo Weinhold	local packageinstallscript = $(installscript:G=_packages!$(packagename)) ;
22049b7a4b5dSshatty    local installzip = install.zip ;
2205c06f365fSIngo Weinhold	local packageinstallzip = $(installzip:G=_packages!$(packagename)) ;
22069b7a4b5dSshatty
2207c06f365fSIngo Weinhold    local packageobjectdir
2208c06f365fSIngo Weinhold    	= [ FDirName $(OBOS_PACKAGE_OBJECT_DIR) $(packagename) ] ;
22099b7a4b5dSshatty	local packagefiledir =  [ FDirName $(packageobjectdir) $(path) ] ;
2210c06f365fSIngo Weinhold    local packagefileinstallzip
2211c06f365fSIngo Weinhold    	= $(installzip:G=_package_objects!$(packagename)) ;
2212c06f365fSIngo Weinhold
2213c06f365fSIngo Weinhold	# add the files to the install.zip
2214c06f365fSIngo Weinhold	local packagefilegrist = [ FGrist _package_files $(packagename) $(path) ] ;
22159b7a4b5dSshatty    for file in $(packagefiles) {
22169b7a4b5dSshatty		if $(3[0]) = "boot" {
2217c06f365fSIngo Weinhold			local packagefile = $(file:G=$(packagefilegrist)) ;
22189b7a4b5dSshatty			MakeLocate $(packagefile) : $(packagefiledir) ;
22199b7a4b5dSshatty			Copy $(packagefile) : $(file) ;
22209b7a4b5dSshatty			Clean cleanPackages : $(packagefile) ;
22219b7a4b5dSshatty			PackageInstallZip $(packagefileinstallzip) : $(packagefile) ;
22229b7a4b5dSshatty		} else {
2223c06f365fSIngo Weinhold			local packagefile = $(file:G=_packages!$(packagename)) ;
22249b7a4b5dSshatty			MakeLocate $(packagefile) : $(packagedir) ;
222582bec102Sshatty			Copy $(packagefile) : [ FGristFiles $(file) ] ;
22269b7a4b5dSshatty			Clean cleanPackages : $(packagefile) ;
22279b7a4b5dSshatty			Depends $(packagezip) : $(packagefile) ;
22289b7a4b5dSshatty		}
22299b7a4b5dSshatty	}
2230c06f365fSIngo Weinhold
2231c06f365fSIngo Weinhold	# general setup for this packages -- only on first invocation
2232c06f365fSIngo Weinhold	if ! $(_setup_$(packagename)) {
2233c06f365fSIngo Weinhold		_setup_$(packagename) = true ;
2234c06f365fSIngo Weinhold
2235c06f365fSIngo Weinhold		NotFile $(packagename) ;
2236b560211bSshatty		LocalDepends packages : $(packagename) ;
2237c06f365fSIngo Weinhold
2238c06f365fSIngo Weinhold		MakeLocate $(packagezip) : $(OBOS_PACKAGE_DIR) ;
2239c06f365fSIngo Weinhold		MakeLocate $(packageinstallscript) : $(packagedir) ;
2240c06f365fSIngo Weinhold		MakeLocate $(packageinstallzip) : $(packagedir) ;
2241c06f365fSIngo Weinhold		MakeLocate $(packagefileinstallzip) : $(packageobjectdir) ;
2242c06f365fSIngo Weinhold
22439b7a4b5dSshatty		PackageInstallScript $(packageinstallscript) : $(packagedir) ;
22449b7a4b5dSshatty		LinkInstallZip $(packageinstallzip) : $(packagefileinstallzip) ;
22459b7a4b5dSshatty		Depends $(packagename) : $(packagezip) ;
2246c06f365fSIngo Weinhold		PackageZip $(packagezip) : $(packagedir)
2247c06f365fSIngo Weinhold			: $(packageinstallscript) $(packageinstallzip) ;
2248c06f365fSIngo Weinhold	}
2249c06f365fSIngo Weinhold
22509b7a4b5dSshatty}
22519b7a4b5dSshatty
22529b7a4b5dSshattyrule PackageZip
22539b7a4b5dSshatty{
2254c06f365fSIngo Weinhold	local dir = $(2:G=dir) ;
2255c06f365fSIngo Weinhold	Depends $(1) : $(dir) $(3) ;
22569b7a4b5dSshatty	Clean cleanPackages : $(1) ;
2257c06f365fSIngo Weinhold	PackageZip1 $(1) : $(dir) ;
22589b7a4b5dSshatty}
22599b7a4b5dSshatty
2260c06f365fSIngo Weinholdactions together PackageZip1 {
22618042d2a0SPhilippe Houdoin	cd "$(OBOS_PACKAGE_DIR)" ;
22628042d2a0SPhilippe Houdoin	zip -rq "$(1:BS)" "$(2:BS)" ;
22639b7a4b5dSshatty}
22649b7a4b5dSshatty
22659b7a4b5dSshattyrule PackageInstallScript
22669b7a4b5dSshatty{
22679b7a4b5dSshatty	MakeLocate $(1) : $(2) ;
22689b7a4b5dSshatty	Clean cleanPackages : $(1) ;
2269c06f365fSIngo Weinhold	PackageInstallScript1 $(1) : $(2:G=dir) ;
22709b7a4b5dSshatty}
22719b7a4b5dSshatty
2272c06f365fSIngo Weinholdactions together PackageInstallScript1
22739b7a4b5dSshatty{
227451fe1be4Sshattyecho '#!/bin/sh
227551fe1be4Sshattybase=`dirname "$0"`
22768042d2a0SPhilippe Houdoincd "$base"
227751fe1be4Sshattyif [ -n "$TTY" ]
227851fe1be4Sshattythen
227951fe1be4Sshatty    unzip -d / install.zip
228051fe1be4Sshattyelse
228151fe1be4Sshatty    response=`alert "Would you like to automatically overwrite existing files, or receive a prompt?" "Overwrite" "Prompt"`
228251fe1be4Sshatty    if [ $response == "Overwrite" ]
228351fe1be4Sshatty    then
228451fe1be4Sshatty        unzip -od / install.zip
228551fe1be4Sshatty        alert "Finished installing" "Thanks"
228651fe1be4Sshatty    else
228751fe1be4Sshatty        if [ -e /boot/beos/apps/Terminal ]
228851fe1be4Sshatty        then
228951fe1be4Sshatty            terminal=/boot/beos/apps/Terminal
229051fe1be4Sshatty        else
229151fe1be4Sshatty            terminal=`query Terminal | head -1`
229251fe1be4Sshatty        fi
22938042d2a0SPhilippe Houdoin        $terminal -t "installer" /bin/sh "$0"
229451fe1be4Sshatty    fi
22958042d2a0SPhilippe Houdoinfi' > "$(1)" ;
22968042d2a0SPhilippe Houdoin	chmod 755 "$(1)" ;
22979b7a4b5dSshatty}
22989b7a4b5dSshatty
22999b7a4b5dSshattyrule PackageInstallZip
23009b7a4b5dSshatty{
23019b7a4b5dSshatty	Depends $(1) : $(2) ;
23029b7a4b5dSshatty	Clean cleanPackages : $(1) ;
23039b7a4b5dSshatty}
23049b7a4b5dSshatty
23059b7a4b5dSshattyactions together PackageInstallZip
23069b7a4b5dSshatty{
23078042d2a0SPhilippe Houdoin	cd "$(1:P)" ;
23088042d2a0SPhilippe Houdoin	zip -rqy "$(1:BS)" boot ;
23099b7a4b5dSshatty}
23109b7a4b5dSshatty
23119b7a4b5dSshattyrule LinkInstallZip
23129b7a4b5dSshatty{
23139b7a4b5dSshatty	Depends $(1) : $(2) ;
23149b7a4b5dSshatty	Clean cleanPackages : $(1) ;
23159b7a4b5dSshatty}
23169b7a4b5dSshatty
23179b7a4b5dSshattyactions together LinkInstallZip
23189b7a4b5dSshatty{
23198042d2a0SPhilippe Houdoin	ln -sf "`pwd`/$(2)" "$(1)" ;
23209b7a4b5dSshatty}
2321e91f3ca1Sbeveloper
2322e91f3ca1Sbeveloperrule SubIncludeGPL
2323e91f3ca1Sbeveloper{
2324e91f3ca1Sbeveloper	# SubInclude rule that can be used to conditionally include GPL licensed add-ons
2325e91f3ca1Sbeveloper	if $(INCLUDE_GPL_ADDONS) = 1 {
2326e91f3ca1Sbeveloper		SubInclude $(1) ;
2327e91f3ca1Sbeveloper	}
2328e91f3ca1Sbeveloper}
2329