xref: /haiku/Jamrules (revision a104c31b995823002042d1238ef9d83f8af549b1)
19eea4522SIngo Weinhold# Vanilla Jam compatibility
29eea4522SIngo Weinholdif ! $(INVOCATION_SUBDIR_SET) {
39eea4522SIngo Weinhold
49eea4522SIngo Weinhold	rule FIsPrefix
59eea4522SIngo Weinhold	{
69eea4522SIngo Weinhold		# FIsPrefix <a> : <b> ;
79eea4522SIngo Weinhold		# Returns true, if list <a> is a prefix (a proper one or equal) of
89eea4522SIngo Weinhold		# list <b>, an empty list otherwise.
99eea4522SIngo Weinhold		local a = $(1) ;
109eea4522SIngo Weinhold		local b = $(2) ;
119eea4522SIngo Weinhold		while $(a) && $(a[1]) = $(b[1]) {
129eea4522SIngo Weinhold			a = $(a[2-]) ;
139eea4522SIngo Weinhold			b = $(b[2-]) ;
149eea4522SIngo Weinhold		}
159eea4522SIngo Weinhold
169eea4522SIngo Weinhold		if $(a) {
179eea4522SIngo Weinhold			return ;
189eea4522SIngo Weinhold		} else {
199eea4522SIngo Weinhold			return true ;
209eea4522SIngo Weinhold		}
219eea4522SIngo Weinhold	}
229eea4522SIngo Weinhold
239eea4522SIngo Weinhold	rule LocalClean { Clean $(1) : $(2) ; }
249eea4522SIngo Weinhold
259eea4522SIngo Weinhold	rule LocalDepends { Depends $(1) : $(2) ; }
269eea4522SIngo Weinhold
279eea4522SIngo Weinhold} # vanilla Jam compatibility
289eea4522SIngo Weinhold
294ff6d49fSIngo Weinhold# The directory for build system specific files
304ff6d49fSIngo WeinholdOBOS_BUILD_DIR = [ FDirName $(OBOS_TOP) build ] ;
314ff6d49fSIngo Weinhold
324ff6d49fSIngo Weinhold# Cache files for header scanning and jamfile caching
334ff6d49fSIngo WeinholdHCACHEFILE = header_cache ;
344ff6d49fSIngo WeinholdJCACHEFILE = jamfile_cache ;
354ff6d49fSIngo WeinholdLOCATE on $(HCACHEFILE) $(JCACHEFILE) = $(OBOS_BUILD_DIR) ;
369eea4522SIngo Weinhold
3752a38012Sejakowatz# Include BuildConfig
3852a38012Sejakowatz{
394ff6d49fSIngo Weinhold	local buildConfig = [ GLOB $(OBOS_BUILD_DIR) : BuildConfig ] ;
4052a38012Sejakowatz	if ! $(buildConfig)
4152a38012Sejakowatz	{
424ff6d49fSIngo Weinhold		ECHO "No BuildConfig found in $(OBOS_BUILD_DIR)!" ;
434ff6d49fSIngo Weinhold		EXIT "Run ./configure in the source tree's root directory first!" ;
4452a38012Sejakowatz	}
454ff6d49fSIngo Weinhold	LOCATE on BuildConfig = $(OBOS_BUILD_DIR) ;
464ff6d49fSIngo Weinhold	include BuildConfig ;
4752a38012Sejakowatz}
4852a38012Sejakowatz
498c17a26bSIngo Weinhold# analyze GCC version
508c17a26bSIngo Weinholdif ! $(GCC_RAW_VERSION) {
518c17a26bSIngo Weinhold	ECHO "Variable GCC_RAW_VERSION not set. Please run ./configure or" ;
528c17a26bSIngo Weinhold	EXIT "specify it manually." ;
538c17a26bSIngo Weinhold}
548c17a26bSIngo WeinholdGCC_VERSION = ;
558c17a26bSIngo Weinhold{
568c17a26bSIngo Weinhold	# split the raw version string at `.' and `-' characters
578c17a26bSIngo Weinhold	local version = $(GCC_RAW_VERSION) ;
588c17a26bSIngo Weinhold	while $(version) {
598c17a26bSIngo Weinhold		local split = [ Match "([^.-]*)[.-](.*)" : $(version) ] ;
608c17a26bSIngo Weinhold		if $(split) {
618c17a26bSIngo Weinhold			GCC_VERSION += $(split[1]) ;
628c17a26bSIngo Weinhold			version = $(split[2]) ;
638c17a26bSIngo Weinhold		} else {
648c17a26bSIngo Weinhold			GCC_VERSION += $(version) ;
658c17a26bSIngo Weinhold			version = ;
668c17a26bSIngo Weinhold		}
678c17a26bSIngo Weinhold	}
688c17a26bSIngo Weinhold}
698c17a26bSIngo Weinhold
705dc4e1efSIngo Weinhold# Save the platform default headers.
715dc4e1efSIngo WeinholdPLATFORM_DEFAULT_HEADERS = $(HDRS) ;
725dc4e1efSIngo Weinhold
73705fc998SAxel Dörfler# Add some grist to the libgcc objects
74705fc998SAxel DörflerLIBGCC_OBJECTS = $(LIBGCC_OBJECTS:G=libgcc) ;
75705fc998SAxel Dörfler
76a6c008e1Sbeveloper# We do not include any local BeOS system headers by default
77dd9f8062SIngo WeinholdCCFLAGS += -nostdinc ;
78dd9f8062SIngo WeinholdC++FLAGS += -nostdinc ;
79a6c008e1Sbeveloper
802abad45eSbeveloper# Allow compiling unit tests on Zeta. Instead of fixing the PostMessage()
812abad45eSbeveloper# issues, they deprecated that nice function. This will enable it again:
822abad45eSbeveloperC++FLAGS += -D_ZETA_USING_DEPRECATED_API_=1 ;
832abad45eSbeveloper
844bb19442Sshattyif ! $(TARGET_PLATFORM) {
854bb19442Sshatty	ECHO "Variable TARGET_PLATFORM not set. Please run ./configure or" ;
864bb19442Sshatty	EXIT "specify it manually." ;
874bb19442Sshatty}
88a17b9c0cSshattyswitch $(TARGET_PLATFORM)
89a17b9c0cSshatty{
90a17b9c0cSshatty	case r5 :
91a17b9c0cSshatty	{
924bb19442Sshatty		# "everything" is r5 compatible
93be1aef42Sshatty	}
94a17b9c0cSshatty	case bone :
95a17b9c0cSshatty	{
96a17b9c0cSshatty		BONE_COMPATIBLE = true ;
97a17b9c0cSshatty	}
98a17b9c0cSshatty	case dano :
99a17b9c0cSshatty	{
100a17b9c0cSshatty		BONE_COMPATIBLE = true ;
101a17b9c0cSshatty		DANO_COMPATIBLE = true ;
102a17b9c0cSshatty	}
103a17b9c0cSshatty	case haiku :
104a17b9c0cSshatty	{
105a17b9c0cSshatty		BONE_COMPATIBLE = true ;
106a17b9c0cSshatty		DANO_COMPATIBLE = true ;
107a17b9c0cSshatty		HAIKU_COMPATIBLE = true ;
108*a104c31bSshatty		DEFINES += __HAIKU__ ;
109a17b9c0cSshatty	}
110a17b9c0cSshatty}
1116040be99Sshattyif $(BONE_COMPATIBLE) {
1126040be99Sshatty	NETWORK_LIBS = libsocket.so libbind.so ;
1136040be99Sshatty} else {
1146040be99Sshatty	NETWORK_LIBS = libnet.so ;
1156040be99Sshatty}
116be1aef42Sshatty
11752a38012Sejakowatz# Determine if we're building on PPC or x86
11852a38012Sejakowatz# Determine mimetype of executable
11952a38012Sejakowatz# Cross compiling can come later
12052a38012Sejakowatz
121c9882d9eSAxel DörflerTARGET_CPU ?= $(OSPLAT:L) ;
1221f622a7bSAxel DörflerOBOS_VERSION ?= R1 ;
1231f622a7bSAxel Dörfler
1241f622a7bSAxel Dörflerswitch $(TARGET_CPU) {
1251f622a7bSAxel Dörfler	case ppc :
1261f622a7bSAxel Dörfler	{
12752a38012Sejakowatz		if $(METROWERKS) {
1281f622a7bSAxel Dörfler			# at least parts of OpenBeOS still can be compiled with
1291f622a7bSAxel Dörfler			# the Metrowerks compiler on BeOS/PPC
13052a38012Sejakowatz			OBOS_TARGET_TYPE ?= "application/x-be-executable" ;
13152a38012Sejakowatz		} else {
13252a38012Sejakowatz			OBOS_TARGET_TYPE ?= "application/x-vnd.Be-elfexecutable" ;
1331f622a7bSAxel Dörfler		}
134894d1636Sshatty		DEFINES += __POWERPC__ ARCH_ppc ;
135e29d8533SAxel Dörfler		OBOS_BOOT_PLATFORM = openfirmware ;
1361f622a7bSAxel Dörfler	}
1371f622a7bSAxel Dörfler	case x86 :
1381f622a7bSAxel Dörfler	{
1391f622a7bSAxel Dörfler		# nothing special to do here...
140894d1636Sshatty		DEFINES += __INTEL__ ARCH_x86 ;
141e29d8533SAxel Dörfler		OBOS_BOOT_PLATFORM = bios_ia32 ;
1421f622a7bSAxel Dörfler	}
1431f622a7bSAxel Dörfler	case * :
1441f622a7bSAxel Dörfler		Exit "Currently unsupported build platform:" $(TARGET_CPU) ;
1451f622a7bSAxel Dörfler}
1461f622a7bSAxel Dörfler
1471f622a7bSAxel Dörfler# set target specific variables
1481f622a7bSAxel Dörfler{
1491f622a7bSAxel Dörfler	#Echo "Building for" $(TARGET_CPU) ;
1501f622a7bSAxel Dörfler
1511f622a7bSAxel Dörfler	OBOS_TARGET ?= $(TARGET_CPU).$(OBOS_VERSION) ;
1521f622a7bSAxel Dörfler	OBOS_TARGET_TYPE ?= "application/x-vnd.Be-elfexecutable" ;
1531f622a7bSAxel Dörfler	OBOS_ARCH ?= $(TARGET_CPU) ;
1541f622a7bSAxel Dörfler	OBOS_TARGET_DEFINE ?= "ARCH_"$(TARGET_CPU) ;
15552a38012Sejakowatz}
15652a38012Sejakowatz
15765c62a01SIngo Weinhold# Disable warnings only if WARNINGS is set to 0
158e5dc2d93Sbeveloper# Should be enabled by default later
15996d27465SIngo Weinhold#
16065c62a01SIngo WeinholdWARNINGS ?= 1 ;
16165c62a01SIngo Weinholdif $(WARNINGS) = 1 {
162e5dc2d93Sbeveloper	# For an explanation of the different warning options, see:
163e5dc2d93Sbeveloper	# http://gcc.gnu.org/onlinedocs/gcc-2.95.3/gcc_2.html
164e5dc2d93Sbeveloper	# to get even more warnings, add:
165e5dc2d93Sbeveloper	# -Wwrite-strings  	(doesn't work well with some Be headers)
166e5dc2d93Sbeveloper	# -Wundef			(dito)
167e5dc2d93Sbeveloper	# -Wconversion		(gets you many warnings about implicit conversions)
168e5dc2d93Sbeveloper	# -W				(gets you even more warnigs)
169dd9f8062SIngo Weinhold	CCFLAGS += -Wall -Wno-multichar -Wmissing-prototypes ;
170dd9f8062SIngo Weinhold	CCFLAGS += -Wpointer-arith -Wcast-align -Wsign-compare ;
171dd9f8062SIngo Weinhold	C++FLAGS += -Wall -Wno-multichar -Wmissing-prototypes -Wno-ctor-dtor-privacy -Woverloaded-virtual ;
172dd9f8062SIngo Weinhold	C++FLAGS += -Wpointer-arith -Wcast-align -Wsign-compare ;
17398cc804cSAxel Dörfler} else {
17498cc804cSAxel Dörfler	CCFLAGS += -Wno-multichar ;
17598cc804cSAxel Dörfler	C++FLAGS += -Wno-multichar ;
176e5dc2d93Sbeveloper}
177e5dc2d93Sbeveloper
17898cc804cSAxel Dörfler# standard kernel C/C++ flags
1790ff867c2SbeveloperKERNEL_CCFLAGS ?= -Wall -Wno-multichar -Wmissing-prototypes -finline -nostdinc ;
1800ff867c2SbeveloperKERNEL_CCFLAGS += -fno-builtin -D$(OBOS_TARGET_DEFINE) ;
181ea7627e5SAxel DörflerKERNEL_CCFLAGS += -DBOCHS_DEBUG_HACK=$(BOCHS_DEBUG_HACK) -D_KERNEL_MODE ;
18298cc804cSAxel DörflerKERNEL_C++FLAGS ?= -Wall -Wno-multichar -Wmissing-prototypes -finline -nostdinc ;
183df48dfedSIngo WeinholdKERNEL_C++FLAGS += -fno-builtin -fno-exceptions -D$(OBOS_TARGET_DEFINE) ;
184ea7627e5SAxel DörflerKERNEL_C++FLAGS += -DBOCHS_DEBUG_HACK=$(BOCHS_DEBUG_HACK) -D_KERNEL_MODE ;
185bbb6f2d4SAxel Dörflerif $(GCC_VERSION[1]) >= 3 {
186bbb6f2d4SAxel Dörfler	KERNEL_C++FLAGS += -fno-use-cxa-atexit ;
187bbb6f2d4SAxel Dörfler}
1880ff867c2Sbeveloper
1899eea4522SIngo Weinhold# We might later want to introduce debug levels or handle the whole issue
1909eea4522SIngo Weinhold# differently. For now there's only on or off.
1919eea4522SIngo Weinhold#
19265c62a01SIngo WeinholdDEBUG ?= 0 ;
19365c62a01SIngo Weinholdif $(DEBUG) != 0 {
1949eea4522SIngo Weinhold	OPTIM ?= -O0 ;
19565c62a01SIngo Weinhold	CCFLAGS += -g [ FDefines DEBUG=$(DEBUG) ] ;
19665c62a01SIngo Weinhold	C++FLAGS += -g [ FDefines DEBUG=$(DEBUG) ] ;
19765c62a01SIngo Weinhold	KERNEL_CCFLAGS += -g [ FDefines DEBUG=$(DEBUG) ] ;
19865c62a01SIngo Weinhold	KERNEL_C++FLAGS += -g [ FDefines DEBUG=$(DEBUG) ] ;
1999eea4522SIngo Weinhold	LINKFLAGS += -g ;
2009eea4522SIngo Weinhold} else {
2019eea4522SIngo Weinhold	OPTIM ?= -O2 ;
2029eea4522SIngo Weinhold}
20396d27465SIngo Weinhold#
20496d27465SIngo Weinhold# To disable for the tests OPTIM and DEBUG are overridden, set the environment
20596d27465SIngo Weinhold# variable NO_TEST_DEBUG.
2069eea4522SIngo Weinhold
20716fa4445SIngo Weinhold# Instructs the Library rule to not make its object files temporary.
208f1e077f8SIngo Weinhold# This is needed as some objects are used in a static library and for an
20916fa4445SIngo Weinhold# executable.
21016fa4445SIngo WeinholdKEEPOBJS = true ;
21116fa4445SIngo Weinhold
2127bc56df1SIngo Weinhold# under BeOS use copyattr instead of cp
2137bc56df1SIngo Weinholdif $(OS) = BEOS
2147bc56df1SIngo Weinhold{
2157bc56df1SIngo Weinhold	CP = copyattr --data ;
2167bc56df1SIngo Weinhold}
2177bc56df1SIngo Weinhold
21853cf6d7aSAxel Dörfler# for builds of tools in the current environment
21953cf6d7aSAxel Dörflerif $(OS) = BEOS {
22053cf6d7aSAxel Dörfler	BUILD_LIBSTDC++ = stdc++.r4 ;
22153cf6d7aSAxel Dörfler} else {
22253cf6d7aSAxel Dörfler	BUILD_LIBSTDC++ = stdc++ ;
22353cf6d7aSAxel Dörfler}
22453cf6d7aSAxel Dörfler
22552a38012Sejakowatz# If no OBOS_OBJECT_TARGET is not defined yet, use our default directory and
22652a38012Sejakowatz# include our "OBOS_TARGET" as subdirectory in there (to prevent different
22752a38012Sejakowatz# builds mixing objects from different targets).
22852a38012Sejakowatzif ! $(OBOS_OBJECT_TARGET) {
22952a38012Sejakowatz	OBOS_OBJECT_TARGET ?= [ FDirName $(OBOS_TOP) objects $(OBOS_TARGET) ] ;
23052a38012Sejakowatz}
23152a38012Sejakowatz
23252a38012Sejakowatz# If no OBOS_DISTRO_TARGET is not defined yet, use our default directory and
23352a38012Sejakowatz# include our "OBOS_TARGET" as subdirectory in there (to prevent different
23452a38012Sejakowatz# builds mixing executables from different targets).
23552a38012Sejakowatzif ! $(OBOS_DISTRO_TARGET) {
23652a38012Sejakowatz	OBOS_DISTRO_TARGET ?= [ FDirName $(OBOS_TOP) distro $(OBOS_TARGET) ] ;
23752a38012Sejakowatz}
23852a38012Sejakowatz
23952a38012Sejakowatz# Set our version number if not already set and mark it as a developer build
24052a38012Sejakowatzif ! $(OBOS_BUILD_VERSION) {
24152a38012Sejakowatz	OBOS_BUILD_VERSION ?= "1 0 0 a 1" ;
24252a38012Sejakowatz	OBOS_BUILD_DESCRIPTION ?= "Developer Build" ;
24352a38012Sejakowatz}
24452a38012Sejakowatz
24552a38012Sejakowatz# If OBOS_BUILD_VERSION is set, but OBOS_BUILD_DESCRIPTION isn't, mark it as
24652a38012Sejakowatz# an unknown build.
24752a38012Sejakowatzif ! $(OBOS_BUILD_DESCRIPTION) {
24852a38012Sejakowatz	OBOS_BUILD_DESCRIPTION ?= "Unknown Build" ;
24952a38012Sejakowatz}
25052a38012Sejakowatz
251505554b4SIngo Weinhold# Relative subdirs for distro dir
252505554b4SIngo WeinholdOBOS_ADDON_DIR  ?= [ FDirName $(OBOS_DISTRO_TARGET) beos system add-ons ] ;
2535f281ed5SejakowatzOBOS_APPS_DIR   ?= [ FDirName $(OBOS_DISTRO_TARGET) beos apps ] ;
254f06de7f3SIngo WeinholdOBOS_BIN_DIR    ?= [ FDirName $(OBOS_DISTRO_TARGET) beos bin ] ;
255505554b4SIngo WeinholdOBOS_ETC_DIR    ?= [ FDirName $(OBOS_DISTRO_TARGET) beos etc ] ;
256505554b4SIngo WeinholdOBOS_FONTS_DIR  ?= [ FDirName $(OBOS_ETC_DIR) fonts ] ;
257505554b4SIngo WeinholdOBOS_KERNEL_DIR ?= [ FDirName $(OBOS_DISTRO_TARGET) beos system ] ;
25852a38012SejakowatzOBOS_PREFS_DIR  ?= [ FDirName $(OBOS_DISTRO_TARGET) beos preferences ] ;
25952a38012SejakowatzOBOS_SERVER_DIR ?= [ FDirName $(OBOS_DISTRO_TARGET) beos system servers ] ;
26052a38012SejakowatzOBOS_SHLIB_DIR  ?= [ FDirName $(OBOS_DISTRO_TARGET) beos system lib ] ;
261e9230d05SIngo WeinholdOBOS_STLIB_DIR  ?= [ FDirName $(OBOS_DISTRO_TARGET) develop lib
262e9230d05SIngo Weinhold							  $(OBOS_ARCH) ] ;
26352a38012SejakowatzOBOS_TEST_DIR   ?= [ FDirName $(OBOS_TOP) tests ] ;
26452a38012Sejakowatz
265c06f365fSIngo WeinholdOBOS_PACKAGE_DIR ?= [ FDirName $(OBOS_TOP) packages $(OBOS_TARGET) ] ;
266c06f365fSIngo WeinholdOBOS_PACKAGE_OBJECT_DIR ?= [ FDirName $(OBOS_OBJECT_TARGET) packages ] ;
267c06f365fSIngo Weinhold
26852a38012SejakowatzOBOS_KERNEL_CONFIG = config.$(OBOS_ARCH).ini ;
26952a38012SejakowatzOBOS_KERNEL = kernel.$(OBOS_ARCH) ;
27052a38012SejakowatzOBOS_FLOPPY = floppy.$(OBOS_ARCH) ;
27152a38012Sejakowatz
27252a38012Sejakowatzrule SetupIncludes
27352a38012Sejakowatz{
274cfc7b456Sshatty	# XXX add "opengl" later
275cfc7b456Sshatty	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 ;
276a6c008e1Sbeveloper
27728d2a30eSDaniel Reinhold	# Overwrite any exiting content when changing HDRS. This rule may be invoked multiple times.
278a6c008e1Sbeveloper
279a6c008e1Sbeveloper	# Use headers directory, to allow to do things like include <posix/string.h>
28028d2a30eSDaniel Reinhold	HDRS = [ FDirName $(OBOS_TOP) headers ] ;
281a6c008e1Sbeveloper
282a6c008e1Sbeveloper	# Use posix headers directory
28328d2a30eSDaniel Reinhold	HDRS += [ FDirName $(OBOS_TOP) headers posix ] ;
284a6c008e1Sbeveloper
285a6c008e1Sbeveloper	# Use public OS header directories
28628d2a30eSDaniel Reinhold	HDRS += [ PublicHeaders $(os_includes) ] ;
287a6c008e1Sbeveloper
288c0e501e0SIngo Weinhold	# Use the root of the private headers -- not so nice, but simplifies things.
289c0e501e0SIngo Weinhold	HDRS += [ PrivateHeaders $(DOT) ] ;
290c0e501e0SIngo Weinhold
291a6c008e1Sbeveloper	# Used as a fallback, the R5 header directories (we should remove this as soon as possible)
29228d2a30eSDaniel Reinhold	HDRS += /boot/develop/headers/posix /boot/develop/headers/cpp ;
29309c5682dSIngo Weinhold
29409c5682dSIngo Weinhold	# The platform dependent headers.
29509c5682dSIngo Weinhold	HDRS += $(PLATFORM_HEADERS) ;
29652a38012Sejakowatz}
29752a38012Sejakowatz
298dd9f8062SIngo Weinholdrule SetupR5Includes
299dd9f8062SIngo Weinhold{
300dd9f8062SIngo Weinhold	# Unsets HDRS, so that the OBOS headers do not `shadow' the system headers.
301dd9f8062SIngo Weinhold	HDRS = ;
302dd9f8062SIngo Weinhold}
303dd9f8062SIngo Weinhold
3045dc4e1efSIngo Weinholdrule SetupDefaultIncludes
3055dc4e1efSIngo Weinhold{
3065dc4e1efSIngo Weinhold	# Resets HDRS to the default headers for the build platform.
3075dc4e1efSIngo Weinhold	HDRS = $(PLATFORM_DEFAULT_HEADERS) ;
3085dc4e1efSIngo Weinhold}
3095dc4e1efSIngo Weinhold
31052a38012Sejakowatz#-------------------------------------------------------------------------------
31152a38012Sejakowatz# Things Jam needs in order to work :)
31252a38012Sejakowatz#-------------------------------------------------------------------------------
31352a38012Sejakowatz
314c06f365fSIngo Weinhold# TODO: back-ported from jam 2.5: remove when not longer needed
315c06f365fSIngo Weinholdrule MakeLocate
316c06f365fSIngo Weinhold{
317c06f365fSIngo Weinhold	if $(>)
318c06f365fSIngo Weinhold	{
319c06f365fSIngo Weinhold	    LOCATE on $(<) = $(>) ;
320c06f365fSIngo Weinhold	    Depends $(<) : $(>[1]:G=dir) ;
321c06f365fSIngo Weinhold	    MkDir $(>[1]:G=dir) ;
322c06f365fSIngo Weinhold	}
323c06f365fSIngo Weinhold}
324c06f365fSIngo Weinhold
3258d3308d9SIngo Weinholdrule Object
3268d3308d9SIngo Weinhold{
3278d3308d9SIngo Weinhold	# This is basically the original Jambase 2.4 Object rule stripped by
3288d3308d9SIngo Weinhold	# comments. Only the final switch statement has been changed to allow
3298d3308d9SIngo Weinhold	# intermediate C++ files for Yacc and Lex.
3308d3308d9SIngo Weinhold
3318d3308d9SIngo Weinhold	LocalClean clean : $(<) ;
3328d3308d9SIngo Weinhold
3338d3308d9SIngo Weinhold	MakeLocate $(<) : $(LOCATE_TARGET) ;
3348d3308d9SIngo Weinhold	SEARCH on $(>) = $(SEARCH_SOURCE) ;
3358d3308d9SIngo Weinhold
3368d3308d9SIngo Weinhold	HDRS on $(<) = $(SEARCH_SOURCE) $(SUBDIRHDRS) $(HDRS) ;
3378d3308d9SIngo Weinhold
3388d3308d9SIngo Weinhold	HDRRULE on $(>) = HdrRule ;
3398d3308d9SIngo Weinhold	HDRSCAN on $(>) = $(HDRPATTERN) ;
3408d3308d9SIngo Weinhold	HDRSEARCH on $(>) =
3418d3308d9SIngo Weinhold		$(SEARCH_SOURCE:E) $(SUBDIRHDRS) $(HDRS) $(STDHDRS) ;
3428d3308d9SIngo Weinhold
3438d3308d9SIngo Weinhold	HDRGRIST on $(>) = $(HDRGRIST) ;
3448d3308d9SIngo Weinhold
3458d3308d9SIngo Weinhold	DEFINES on $(<) += $(DEFINES) ;
3468d3308d9SIngo Weinhold
3478d3308d9SIngo Weinhold	# if source is not .c, generate .c with specific rule
3488d3308d9SIngo Weinhold
3498d3308d9SIngo Weinhold	switch $(>:S)
3508d3308d9SIngo Weinhold	{
3518d3308d9SIngo Weinhold	    case .asm : As $(<) : $(>) ;
3528d3308d9SIngo Weinhold	    case .c :	Cc $(<) : $(>) ;
3538d3308d9SIngo Weinhold	    case .C :	C++ $(<) : $(>) ;
3548d3308d9SIngo Weinhold	    case .cc :	C++ $(<) : $(>) ;
3558d3308d9SIngo Weinhold	    case .cpp : C++ $(<) : $(>) ;
3568d3308d9SIngo Weinhold	    case .f :	Fortran $(<) : $(>) ;
3578d3308d9SIngo Weinhold	    case .l :	if [ on $(2) return $(GENERATE_C++) ] {
3588d3308d9SIngo Weinhold						C++ $(<) : $(<:S=.cpp) ;
3598d3308d9SIngo Weinhold						LexC++ $(<:S=.cpp) : $(>) ;
3608d3308d9SIngo Weinhold					} else {
3618d3308d9SIngo Weinhold						Cc $(<) : $(<:S=.c) ;
3628d3308d9SIngo Weinhold						Lex $(<:S=.c) : $(>) ;
3638d3308d9SIngo Weinhold					}
3648d3308d9SIngo Weinhold	    case .s :	As $(<) : $(>) ;
3658d3308d9SIngo Weinhold	    case .y :	if [ on $(2) return $(GENERATE_C++) ] {
3668d3308d9SIngo Weinhold						C++ $(<) : $(<:S=.cpp) ;
3678d3308d9SIngo Weinhold						Bison $(<:S=.cpp) : $(>) ;
3688d3308d9SIngo Weinhold					} else {
3698d3308d9SIngo Weinhold						Cc $(<) : $(<:S=$(YACCGEN)) ;
3708d3308d9SIngo Weinhold						Yacc $(<:S=$(YACCGEN)) : $(>) ;
3718d3308d9SIngo Weinhold					}
3728d3308d9SIngo Weinhold	    case * :	UserObject $(<) : $(>) ;
3738d3308d9SIngo Weinhold	}
3748d3308d9SIngo Weinhold}
3758d3308d9SIngo Weinhold
37652a38012Sejakowatzrule UserObject
37752a38012Sejakowatz{
37852a38012Sejakowatz	switch $(2)
37952a38012Sejakowatz	{
38052a38012Sejakowatz	case *.S    : assemble $(1) : $(2) ;
38108125d07SIngo Weinhold	case *.o    : return ;
38252a38012Sejakowatz	case *      : ECHO "unknown suffix on" $(2) ;
38352a38012Sejakowatz	}
38452a38012Sejakowatz}
38552a38012Sejakowatz
38652a38012Sejakowatz# Override the default to give "prettier" command lines.
38752a38012Sejakowatzactions Cc
38852a38012Sejakowatz{
3890931b8f9SIngo Weinhold	$(CC) -c "$(2)" $(CCFLAGS) $(CCDEFS) $(CCHDRS) -o "$(1)" ;
39052a38012Sejakowatz}
39152a38012Sejakowatz
39252a38012Sejakowatzactions C++
39352a38012Sejakowatz{
3940931b8f9SIngo Weinhold	$(C++) -c "$(2)" $(C++FLAGS) $(CCDEFS) $(CCHDRS) -o "$(1)" ;
39552a38012Sejakowatz}
39652a38012Sejakowatz
39752a38012Sejakowatz
39852a38012Sejakowatz#-------------------------------------------------------------------------------
39952a38012Sejakowatz# General High-level OBOS target rules
40052a38012Sejakowatz#-------------------------------------------------------------------------------
40152a38012Sejakowatz
4025f281ed5Sejakowatzrule App
4035f281ed5Sejakowatz{
40439a01fbbSshatty	# App <name> : <sources> : <libraries> : <res> ;
405a6c008e1Sbeveloper	SetupIncludes ;
4065f281ed5Sejakowatz	SetupObjectsDir ;
40739a01fbbSshatty	AddResources $(1) : $(4) ;
408007eb5f2SIngo Weinhold	Main $(1) : $(2) ;
409007eb5f2SIngo Weinhold	MakeLocate $(1) : $(OBOS_APPS_DIR) ;
410007eb5f2SIngo Weinhold	LinkSharedOSLibs $(1) : $(3) ;
411007eb5f2SIngo Weinhold	LINKFLAGS on $(1) = [ on $(1) return $(LINKFLAGS) ]
412007eb5f2SIngo Weinhold						-Xlinker -soname=_APP_ ;
4135f281ed5Sejakowatz}
4145f281ed5Sejakowatz
415f06de7f3SIngo Weinholdrule BinCommand
416f06de7f3SIngo Weinhold{
41711fa3682SJérôme Duval	# BinCommand <name> : <sources> : <libraries> : <res> ;
418a6c008e1Sbeveloper	SetupIncludes ;
419f06de7f3SIngo Weinhold	SetupObjectsDir ;
42011fa3682SJérôme Duval	AddResources $(1) : $(4) ;
421f06de7f3SIngo Weinhold	Main $(1) : $(2) ;
422f06de7f3SIngo Weinhold	MakeLocate $(1) : $(OBOS_BIN_DIR) ;
423f06de7f3SIngo Weinhold	LinkSharedOSLibs $(1) : $(3) ;
424007eb5f2SIngo Weinhold	LINKFLAGS on $(1) = [ on $(1) return $(LINKFLAGS) ]
425007eb5f2SIngo Weinhold						-Xlinker -soname=_APP_ ;
426f06de7f3SIngo Weinhold}
427f06de7f3SIngo Weinhold
428f06de7f3SIngo Weinholdrule StdBinCommands
429f06de7f3SIngo Weinhold{
43011fa3682SJérôme Duval	# StdBinCommands <sources> : <libs> : <res> ;
431a6c008e1Sbeveloper	SetupIncludes ;
432a6c008e1Sbeveloper	SetupObjectsDir ;
433f06de7f3SIngo Weinhold	local libs = $(2) ;
43411fa3682SJérôme Duval	local ress = $(3) ;
4359342c27aSIngo Weinhold	local source ;
436f06de7f3SIngo Weinhold	for source in $(1)
437f06de7f3SIngo Weinhold	{
438f06de7f3SIngo Weinhold		local target = $(source:S=) ;
439a6c008e1Sbeveloper
44011fa3682SJérôme Duval		BinCommand $(target) : $(source) : $(libs) : $(ress) ;
441f06de7f3SIngo Weinhold	}
442f06de7f3SIngo Weinhold}
443f06de7f3SIngo Weinhold
44452a38012Sejakowatzrule Preference
44552a38012Sejakowatz{
446007eb5f2SIngo Weinhold	# Preference <name> : <sources> : <libraries> ;
447a6c008e1Sbeveloper	SetupIncludes ;
44852a38012Sejakowatz	SetupObjectsDir ;
449007eb5f2SIngo Weinhold	Main $(1) : $(2) ;
450007eb5f2SIngo Weinhold	MakeLocate $(1) : $(OBOS_PREFS_DIR) ;
451007eb5f2SIngo Weinhold	LinkSharedOSLibs $(1) : $(3) ;
452007eb5f2SIngo Weinhold	LINKFLAGS on $(1) = [ on $(1) return $(LINKFLAGS) ]
453007eb5f2SIngo Weinhold						-Xlinker -soname=_APP_ ;
45452a38012Sejakowatz}
45552a38012Sejakowatz
45652a38012Sejakowatzrule Server
45752a38012Sejakowatz{
458007eb5f2SIngo Weinhold	# Server <name> : <sources> : <libraries> ;
45952a38012Sejakowatz
460a6c008e1Sbeveloper	SetupIncludes ;
46152a38012Sejakowatz	SetupObjectsDir ;
462007eb5f2SIngo Weinhold	Main $(1) : $(2) ;
463007eb5f2SIngo Weinhold	MakeLocate $(1) : $(OBOS_SERVER_DIR) ;
464007eb5f2SIngo Weinhold	LinkSharedOSLibs $(1) : $(3) ;
465007eb5f2SIngo Weinhold	LINKFLAGS on $(1) = [ on $(1) return $(LINKFLAGS) ]
466007eb5f2SIngo Weinhold						-Xlinker -soname=_APP_ ;
46752a38012Sejakowatz}
46852a38012Sejakowatz
46952a38012Sejakowatz# test pseudo targets
47052a38012SejakowatzNOTFILE obostests ;
47152a38012SejakowatzNOTFILE r5tests ;
47252a38012Sejakowatz
473d1f6c38fSTyler Dauwalderrule CommonTestLib
474d1f6c38fSTyler Dauwalder{
475c5ff4aa6STyler Dauwalder	# CommonTestLib <target> : <sources> : <obos libraries>
4769285de51STyler Dauwalder	#	: <r5 libraries> : <test libraries> : <public headers>;
477d1f6c38fSTyler Dauwalder	# Builds a unit test for both OBOS and R5 modules.
478d1f6c38fSTyler Dauwalder	# <target> The name of the target.
479d1f6c38fSTyler Dauwalder	# <sources> The list of sources.
480d1f6c38fSTyler Dauwalder	# <obos libraries> A list of link libraries for the OBOS tests (as passed
481d1f6c38fSTyler Dauwalder	# to LinkSharedOSLibs).
482d1f6c38fSTyler Dauwalder	# <r5 libraries> A list of link libraries for the R5 tests (as passed
483d1f6c38fSTyler Dauwalder	# to LinkSharedOSLibs).
4849285de51STyler Dauwalder	# <test libraries> A list of link libraries for both OBOS tests and R5 tests
4859285de51STyler Dauwalder	# that have a common name (i.e. specify libx.so and the OBOS tests will link
4869285de51STyler Dauwalder	# to libx.so and the R5 tests will link to libx_r5.so).
487d1f6c38fSTyler Dauwalder	# <public headers> A list of public header dirs (as passed to
488d1f6c38fSTyler Dauwalder	# UsePublicHeaders).
489d1f6c38fSTyler Dauwalder
490c5ff4aa6STyler Dauwalder	TestLib $(1) : $(2) : [ FDirName $(OBOS_TEST_DIR) unittester lib ] : $(3) $(5) : $(6) ;
491c5ff4aa6STyler Dauwalder	R5TestLib $(1) : $(2) : [ FDirName $(OBOS_TEST_DIR) unittester_r5 lib ] : $(4) [ R5SharedLibraryNames $(5) ] ;
492d1f6c38fSTyler Dauwalder}
493d1f6c38fSTyler Dauwalder
494d1f6c38fSTyler Dauwalderrule TestLib
495d1f6c38fSTyler Dauwalder{
496d1f6c38fSTyler Dauwalder	# TestLib <target> : <sources> : <dest> : <libraries> : <public headers>
497d1f6c38fSTyler Dauwalder	# Builds a unit test library for an OBOS module.
498d1f6c38fSTyler Dauwalder	# <target> The name of the target.
499d1f6c38fSTyler Dauwalder	# <sources> The list of sources.
500d1f6c38fSTyler Dauwalder	# <dest> The directory for the target (as passed to FDirName).
501d1f6c38fSTyler Dauwalder	# <libraries> A list of link libraries (as passed to LinkSharedOSLibs).
502d1f6c38fSTyler Dauwalder	# <public headers> A list of public header dirs (as passed to
503d1f6c38fSTyler Dauwalder	# UsePublicHeaders).
504d1f6c38fSTyler Dauwalder
505d1f6c38fSTyler Dauwalder	local target = $(1) ;
506d1f6c38fSTyler Dauwalder	local sources = $(2) ;
507d1f6c38fSTyler Dauwalder	local dest = $(3) ;
508d1f6c38fSTyler Dauwalder	local libraries = $(4) ;
509d1f6c38fSTyler Dauwalder	local headerDirs = $(5) ;
5109342c27aSIngo Weinhold	local objects = [ FGristFiles $(sources:S=$(SUFOBJ)) ] ;
511d1f6c38fSTyler Dauwalder
5129342c27aSIngo Weinhold	# Our Main replacement.
5139342c27aSIngo Weinhold	MainFromObjects $(target) : $(objects) ;
5149342c27aSIngo Weinhold	TestObjects $(sources) : $(headerDirs) ;
515d1f6c38fSTyler Dauwalder
516d1f6c38fSTyler Dauwalder	MakeLocate $(target) : $(dest) ;
5170d1cdd94SIngo Weinhold	Depends $(target) : libcppunit.so ;
5180d1cdd94SIngo Weinhold	Depends obostests : $(target) ;
519d1f6c38fSTyler Dauwalder	LinkSharedOSLibs $(target) : libcppunit.so $(libraries) ;
520d1f6c38fSTyler Dauwalder	LINKFLAGS on $(target) = $(LINKFLAGS) -nostart -Xlinker -soname=\"$(target)\" ;
521d1f6c38fSTyler Dauwalder}
522d1f6c38fSTyler Dauwalder
523d1f6c38fSTyler Dauwalderrule R5TestLib
524d1f6c38fSTyler Dauwalder{
525c5ff4aa6STyler Dauwalder	# R5TestLib <target> : <sources> : <dest> : <libraries>
526d1f6c38fSTyler Dauwalder	# Builds a unit test for an R5 module. "_r5" is appended to the object
527d1f6c38fSTyler Dauwalder	# and the target name.
528d1f6c38fSTyler Dauwalder	# <target> The name of the target.
529d1f6c38fSTyler Dauwalder	# <sources> The list of sources.
530d1f6c38fSTyler Dauwalder	# <dest> The directory for the target (as passed to FDirName).
531d1f6c38fSTyler Dauwalder	# <libraries> A list of link libraries (as passed to LinkSharedOSLibs).
532d1f6c38fSTyler Dauwalder
533d1f6c38fSTyler Dauwalder	local target = $(1:B)_r5$(1:S) ;
534d1f6c38fSTyler Dauwalder	local sources = $(2) ;
535c5ff4aa6STyler Dauwalder	local dest = $(3) ;
536d1f6c38fSTyler Dauwalder	local libraries = $(4) ;
537d1f6c38fSTyler Dauwalder	local objects = [ R5ObjectNames $(sources) ] ;
538d1f6c38fSTyler Dauwalder
539d1f6c38fSTyler Dauwalder	# Our Main replacement.
540d1f6c38fSTyler Dauwalder	MainFromObjects $(target) : $(objects) ;
5419342c27aSIngo Weinhold	TestObjects $(sources) : : true ;
542d1f6c38fSTyler Dauwalder
543d1f6c38fSTyler Dauwalder	MakeLocate $(target) : $(dest) ;
5440d1cdd94SIngo Weinhold	Depends $(target) : libcppunit.so ;
5450d1cdd94SIngo Weinhold	Depends r5tests : $(target) ;
546d1f6c38fSTyler Dauwalder	LinkSharedOSLibs $(target) : libcppunit.so $(libraries) ;
547d1f6c38fSTyler Dauwalder	LINKFLAGS on $(target) = $(LINKFLAGS) -nostart -Xlinker -soname=\"$(target)\" ;
548d1f6c38fSTyler Dauwalder}
549d1f6c38fSTyler Dauwalder
55052a38012Sejakowatzrule CommonUnitTest
55152a38012Sejakowatz{
55252a38012Sejakowatz	# CommonUnitTest <target> : <sources> : <dest> : <obos libraries>
55352a38012Sejakowatz	#	: <r5 libraries> : <public headers>;
55452a38012Sejakowatz	# Builds a unit test for both OBOS and R5 modules.
55552a38012Sejakowatz	# <target> The name of the target.
55652a38012Sejakowatz	# <sources> The list of sources.
55752a38012Sejakowatz	# <dest> The directory for the target (as passed to FDirName).
55852a38012Sejakowatz	# <obos libraries> A list of link libraries for the OBOS tests (as passed
55952a38012Sejakowatz	# to LinkSharedOSLibs).
56052a38012Sejakowatz	# <r5 libraries> A list of link libraries for the R5 tests (as passed
56152a38012Sejakowatz	# to LinkSharedOSLibs).
56252a38012Sejakowatz	# <public headers> A list of public header dirs (as passed to
56352a38012Sejakowatz	# UsePublicHeaders).
56452a38012Sejakowatz
56552a38012Sejakowatz	UnitTest $(1) : $(2) : $(3) : $(4) : $(6) ;
56652a38012Sejakowatz	R5UnitTest $(1) : $(2) : $(3) : $(5) ;
56752a38012Sejakowatz}
56852a38012Sejakowatz
56952a38012Sejakowatzrule UnitTest
57052a38012Sejakowatz{
57152a38012Sejakowatz	# UnitTest <target> : <sources> : <dest> : <libraries> : <public headers>
57252a38012Sejakowatz	# Builds a unit test for an OBOS module.
57352a38012Sejakowatz	# <target> The name of the target.
57452a38012Sejakowatz	# <sources> The list of sources.
57552a38012Sejakowatz	# <dest> The directory for the target (as passed to FDirName).
57652a38012Sejakowatz	# <libraries> A list of link libraries (as passed to LinkSharedOSLibs).
57752a38012Sejakowatz	# <public headers> A list of public header dirs (as passed to
57852a38012Sejakowatz	# UsePublicHeaders).
57952a38012Sejakowatz
58052a38012Sejakowatz	local target = $(1) ;
58152a38012Sejakowatz	local sources = $(2) ;
58252a38012Sejakowatz	local dest = $(3) ;
58352a38012Sejakowatz	local libraries = $(4) ;
58452a38012Sejakowatz	local headerDirs = $(5) ;
5859342c27aSIngo Weinhold	local objects = [ FGristFiles $(sources:S=$(SUFOBJ)) ] ;
58652a38012Sejakowatz
5879342c27aSIngo Weinhold	# Our Main replacement.
5889342c27aSIngo Weinhold	MainFromObjects $(target) : $(objects) ;
5899342c27aSIngo Weinhold	TestObjects $(sources) : $(headerDirs) ;
5903b9eae39SIngo Weinhold
59152a38012Sejakowatz	MakeLocate $(target) : [ FDirName $(OBOS_TEST_DIR) $(dest) ] ;
5929eea4522SIngo Weinhold	Depends $(target) : libcppunit.so ;
5939eea4522SIngo Weinhold	Depends obostests : $(target) ;
59452a38012Sejakowatz	LinkSharedOSLibs $(target) : libcppunit.so $(libraries) ;
59552a38012Sejakowatz}
59652a38012Sejakowatz
59752a38012Sejakowatzrule R5UnitTest
59852a38012Sejakowatz{
59952a38012Sejakowatz	# R5UnitTest <target> : <sources> : <dest> : <libraries>
60052a38012Sejakowatz	# Builds a unit test for an R5 module. "_r5" is appended to the object
60152a38012Sejakowatz	# and the target name.
60252a38012Sejakowatz	# <target> The name of the target.
60352a38012Sejakowatz	# <sources> The list of sources.
60452a38012Sejakowatz	# <dest> The directory for the target (as passed to FDirName).
60552a38012Sejakowatz	# <libraries> A list of link libraries (as passed to LinkSharedOSLibs).
60652a38012Sejakowatz
60752a38012Sejakowatz	local target = $(1)_r5 ;
60852a38012Sejakowatz	local sources = $(2) ;
60952a38012Sejakowatz	local dest = $(3) ;
61052a38012Sejakowatz	local libraries = $(4) ;
61152a38012Sejakowatz	local objects = [ R5ObjectNames $(sources) ] ;
61252a38012Sejakowatz
61352a38012Sejakowatz	# Our Main replacement.
61452a38012Sejakowatz	MainFromObjects $(target) : $(objects) ;
6159342c27aSIngo Weinhold	TestObjects $(sources) : : true ;
61652a38012Sejakowatz
61752a38012Sejakowatz	MakeLocate $(target) : [ FDirName $(OBOS_TEST_DIR) $(dest) ] ;
6189eea4522SIngo Weinhold	Depends $(target) : libcppunit.so ;
6199eea4522SIngo Weinhold	Depends r5tests : $(target) ;
62052a38012Sejakowatz	LinkSharedOSLibs $(target) : libcppunit.so $(libraries) ;
62152a38012Sejakowatz}
62252a38012Sejakowatz
62352a38012Sejakowatzrule R5ObjectNames
62452a38012Sejakowatz{
62552a38012Sejakowatz	# R5ObjectNames <sources> ;
62652a38012Sejakowatz	# Returns a list of gristed object names given a list of source file names.
62752a38012Sejakowatz	# Moreover each object names gets "_r5" inserted before the object suffix.
62852a38012Sejakowatz	local objects = $(1:S=)_r5 ;
62952a38012Sejakowatz	return [ FGristFiles $(objects:S=$(SUFOBJ)) ] ;
63052a38012Sejakowatz}
63152a38012Sejakowatz
6329342c27aSIngo Weinholdrule R5Objects
6339342c27aSIngo Weinhold{
6349342c27aSIngo Weinhold	# R5Objects <sources>
635dd9f8062SIngo Weinhold	# Similar to Objects, but appends "_r5" to the object file names and
636dd9f8062SIngo Weinhold	# removes `-nostdinc' from the CC and C++ flags to enable system headers.
6379342c27aSIngo Weinhold	# <sources> The source files.
6389342c27aSIngo Weinhold
639dd9f8062SIngo Weinhold	# Remove `-nostdinc' from CCFLAGS and C++FLAGS.
640dd9f8062SIngo Weinhold	local oldCCFLAGS = $(CCFLAGS) ;
641dd9f8062SIngo Weinhold	local oldC++FLAGS = $(C++FLAGS) ;
642dd9f8062SIngo Weinhold	CCFLAGS = [ Filter $(CCFLAGS) : -nostdinc ] ;
643dd9f8062SIngo Weinhold	C++FLAGS = [ Filter $(C++FLAGS) : -nostdinc ] ;
644dd9f8062SIngo Weinhold
6459342c27aSIngo Weinhold	local sources = $(1) ;
6469342c27aSIngo Weinhold	local source ;
6479342c27aSIngo Weinhold	for source in [ FGristFiles $(sources) ]
6489342c27aSIngo Weinhold	{
6499342c27aSIngo Weinhold		local object = [ R5ObjectNames $(source) ] ;
6509342c27aSIngo Weinhold		Object $(object) : $(source) ;
6519342c27aSIngo Weinhold		LocalDepends obj : $(object) ;
6529342c27aSIngo Weinhold	}
653dd9f8062SIngo Weinhold
654dd9f8062SIngo Weinhold	# Reset CCFLAGS and C++FLAGS to original values.
655dd9f8062SIngo Weinhold	CCFLAGS = $(oldCCFLAGS) ;
656dd9f8062SIngo Weinhold	C++FLAGS = $(oldC++FLAGS) ;
6579342c27aSIngo Weinhold}
6589342c27aSIngo Weinhold
6599342c27aSIngo Weinholdrule TestObjects
6609342c27aSIngo Weinhold{
6619342c27aSIngo Weinhold	# TestLib <sources> : <public headers> : <r5>
6629342c27aSIngo Weinhold	# Compiles objects for tests.
6639342c27aSIngo Weinhold	# <sources> The list of sources.
6649342c27aSIngo Weinhold	# <public headers> A list of public header dirs (as passed to
6659342c27aSIngo Weinhold	# UsePublicHeaders).
6669342c27aSIngo Weinhold	# <r5> If set, "_r5" is appended to the object file names and
6679342c27aSIngo Weinhold	# <public headers> is ignored. Furthermore the pre-processor macro
6689342c27aSIngo Weinhold	# TEST_R5 is defined, TEST_OBOS otherwise.
6699342c27aSIngo Weinhold
6709342c27aSIngo Weinhold	local sources = $(1) ;
6719342c27aSIngo Weinhold	local headerDirs = $(2) ;
6729342c27aSIngo Weinhold	local r5 = $(3) ;
6739342c27aSIngo Weinhold	local objects ;
6749342c27aSIngo Weinhold
6759342c27aSIngo Weinhold	# Turn optimization off.
67696d27465SIngo Weinhold	if ! $(NO_TEST_DEBUG) {
6779342c27aSIngo Weinhold		local optim = $(OPTIM) ;
6789342c27aSIngo Weinhold		OPTIM = ;
67996d27465SIngo Weinhold	}
6809342c27aSIngo Weinhold
6819342c27aSIngo Weinhold	SetupObjectsDir ;
6829342c27aSIngo Weinhold
6839342c27aSIngo Weinhold	# compile
6849342c27aSIngo Weinhold	if $(r5) {
685dd9f8062SIngo Weinhold		SetupR5Includes ;
6869342c27aSIngo Weinhold		objects = [ R5ObjectNames $(sources) ] ;
6879342c27aSIngo Weinhold		R5Objects $(sources) ;
6889342c27aSIngo Weinhold	} else {
689dd9f8062SIngo Weinhold		SetupIncludes ;
6909342c27aSIngo Weinhold		objects = [ FGristFiles $(sources:S=$(SUFOBJ)) ] ;
6919342c27aSIngo Weinhold		Objects $(sources) ;
6929342c27aSIngo Weinhold	}
6939342c27aSIngo Weinhold
6949342c27aSIngo Weinhold	# set headers/defines
6959b60a208SIngo Weinhold	UseCppUnitObjectHeaders $(sources) : $(objects) ;
6969342c27aSIngo Weinhold	if $(r5) {
697728b5725SIngo Weinhold		ObjectsDefines $(objects) : TEST_R5 ;
6989342c27aSIngo Weinhold	} else {
6999b60a208SIngo Weinhold		UsePublicObjectHeaders $(sources) : $(headerDirs) : $(objects) ;
700728b5725SIngo Weinhold		ObjectsDefines $(objects) : TEST_OBOS ;
7019342c27aSIngo Weinhold	}
7029342c27aSIngo Weinhold
70396d27465SIngo Weinhold	if ! $(NO_TEST_DEBUG) {
7049342c27aSIngo Weinhold		# Turn debugging on. That is usually desired for test code.
7059342c27aSIngo Weinhold		ObjectCcFlags $(objects) : "-g" ;
7069342c27aSIngo Weinhold		ObjectC++Flags $(objects) : "-g" ;
7079342c27aSIngo Weinhold
7089342c27aSIngo Weinhold		# Turn optimization on again.
7099342c27aSIngo Weinhold		OPTIM = $(optim) ;
7109342c27aSIngo Weinhold	}
71196d27465SIngo Weinhold}
7129342c27aSIngo Weinhold
7139285de51STyler Dauwalderrule R5SharedLibraryNames
7149285de51STyler Dauwalder{
7159285de51STyler Dauwalder	# R5SharedLibraryNames <sources> ;
7169285de51STyler Dauwalder	# Returns a list of shared library names given a list of file names. NO
7179285de51STyler Dauwalder	# GRISTING IS PERFORMED :-) However, each library names gets "_r5" inserted
7189285de51STyler Dauwalder	# before the shared lib suffix.
7199285de51STyler Dauwalder	return $(1:S=)_r5.so ;
7209285de51STyler Dauwalder}
7219285de51STyler Dauwalder
7229fc6b2e1SIngo Weinholdrule SimpleTest
7239fc6b2e1SIngo Weinhold{
7249fc6b2e1SIngo Weinhold	# UnitTest <target> : <sources> : <libraries>
7259fc6b2e1SIngo Weinhold	# Builds a unit test for an OBOS module.
7269fc6b2e1SIngo Weinhold	# <target> The name of the target.
7279fc6b2e1SIngo Weinhold	# <sources> The list of sources.
7289fc6b2e1SIngo Weinhold	# <dest> The directory for the target (as passed to FDirName).
7299fc6b2e1SIngo Weinhold	# <libraries> A list of link libraries (as passed to LinkSharedOSLibs).
7309fc6b2e1SIngo Weinhold	# <public headers> A list of public header dirs (as passed to
7319fc6b2e1SIngo Weinhold	# UsePublicHeaders).
7329fc6b2e1SIngo Weinhold
7339fc6b2e1SIngo Weinhold	local target = $(1) ;
7349fc6b2e1SIngo Weinhold	local sources = $(2) ;
7359fc6b2e1SIngo Weinhold	local libraries = $(3) ;
7369fc6b2e1SIngo Weinhold	local relPath = [ FRelPath src tests : $(SUBDIR_TOKENS) ] ;
7379fc6b2e1SIngo Weinhold
7389fc6b2e1SIngo Weinhold	# Turn optimization off.
73996d27465SIngo Weinhold	if ! $(NO_TEST_DEBUG) {
7409fc6b2e1SIngo Weinhold		local optim = $(OPTIM) ;
7419fc6b2e1SIngo Weinhold		OPTIM = ;
74296d27465SIngo Weinhold	}
7439fc6b2e1SIngo Weinhold
744a6c008e1Sbeveloper	SetupIncludes ;
7459fc6b2e1SIngo Weinhold	SetupObjectsDir ;
7469fc6b2e1SIngo Weinhold	MakeLocateObjects $(sources) ;
7479fc6b2e1SIngo Weinhold	Main $(target) : $(sources) ;
7489fc6b2e1SIngo Weinhold	MakeLocate $(target) : [ FDirName $(OBOS_TEST_DIR) $(relPath) ] ;
7499eea4522SIngo Weinhold	Depends obostests : $(target) ;
7509fc6b2e1SIngo Weinhold	LinkSharedOSLibs $(target) : $(libraries) ;
751728b5725SIngo Weinhold	ObjectsDefines $(sources) : TEST_OBOS ;
75296d27465SIngo Weinhold	if ! $(NO_TEST_DEBUG) {
7539fc6b2e1SIngo Weinhold		# Turn debugging on. That is usually desired for test code.
7549fc6b2e1SIngo Weinhold		ObjectCcFlags $(sources) : "-g" ;
7559fc6b2e1SIngo Weinhold		ObjectC++Flags $(sources) : "-g" ;
7569fc6b2e1SIngo Weinhold
7579fc6b2e1SIngo Weinhold		# Turn optimization on again.
7589fc6b2e1SIngo Weinhold		OPTIM = $(optim) ;
7599fc6b2e1SIngo Weinhold	}
76096d27465SIngo Weinhold}
7619fc6b2e1SIngo Weinhold
76252a38012Sejakowatzrule Addon
76352a38012Sejakowatz{
76483b3b0dfSIngo Weinhold	# Addon <name> : <relpath> : <sources> : <is executable> : <libraries> ;
7657a384fdeSIngo Weinhold	# <name>: Name of the add-on.
7667a384fdeSIngo Weinhold	# <relpath>: Path where the add-on shall live relative to the add-on dir.
7677a384fdeSIngo Weinhold	# <sources>: Source files.
76883b3b0dfSIngo Weinhold	# <is executable>: true, if the target shall be executable as well.
76983b3b0dfSIngo Weinhold	# <libraries>: Libraries to be linked against.
7707a384fdeSIngo Weinhold
7717a384fdeSIngo Weinhold	local isExecutable = $(4) ;
77252a38012Sejakowatz
773a6c008e1Sbeveloper	SetupIncludes ;
77452a38012Sejakowatz	SetupObjectsDir ;
77552a38012Sejakowatz	Main $(1) : $(3) ;
77652a38012Sejakowatz
77752a38012Sejakowatz	# Create output dir path for addon
77852a38012Sejakowatz	local targetdir;
77952a38012Sejakowatz	targetdir = [ FDirName $(OBOS_ADDON_DIR) $(2) ] ;
78052a38012Sejakowatz
78152a38012Sejakowatz	MakeLocate $(1) : $(targetdir) ;
7827a384fdeSIngo Weinhold
7837a384fdeSIngo Weinhold	local linkFlags = -Xlinker -soname=\"$(1)\" ;
7847a384fdeSIngo Weinhold	if $(isExecutable) != true {
7857a384fdeSIngo Weinhold		linkFlags = -nostart $(linkFlags) ;
7867a384fdeSIngo Weinhold	}
7877a384fdeSIngo Weinhold	LINKFLAGS on $(1) = [ on $(1) return $(LINKFLAGS) ] $(linkFlags) ;
78883b3b0dfSIngo Weinhold	LinkSharedOSLibs $(1) : $(5) ;
789af28904fSIngo Weinhold}
790af28904fSIngo Weinhold
79158efc9d8SIngo Weinholdrule R5KernelAddon
792af28904fSIngo Weinhold{
793600203b1SAxel Dörfler	# R5KernelAddon <name> : <relpath> : <sources> : <static-libraries> ;
794af28904fSIngo Weinhold
795af28904fSIngo Weinhold	local sources = $(3) ;
796af28904fSIngo Weinhold
797af28904fSIngo Weinhold	Addon $(1) : $(2) : $(3) ;
798af28904fSIngo Weinhold	ObjectCcFlags $(sources) : -D_KERNEL_MODE=1 -no-fpic ;
799df48dfedSIngo Weinhold	ObjectC++Flags $(sources) : -D_KERNEL_MODE=1 -no-fpic -fno-exceptions ;
8009eea4522SIngo Weinhold	LINKFLAGS on $(1) = [ on $(1) return $(LINKFLAGS) ] -nostdlib ;
801600203b1SAxel Dörfler	LinkSharedOSLibs $(1) : $(4) /boot/develop/lib/x86/_KERNEL_ ;
80252a38012Sejakowatz}
80352a38012Sejakowatz
8044fb5add0SMatthew Wilberrule Translator
8054fb5add0SMatthew Wilber{
806007eb5f2SIngo Weinhold	# Translator <name> : <sources> : <libraries> ;
807a6c008e1Sbeveloper	SetupIncludes ;
8084fb5add0SMatthew Wilber	SetupObjectsDir ;
8094fb5add0SMatthew Wilber	Main $(1) : $(2) ;
810007eb5f2SIngo Weinhold	LinkSharedOSLibs $(1) : $(3) ;
8114fb5add0SMatthew Wilber
8124fb5add0SMatthew Wilber	# Create output dir path for translator
8134fb5add0SMatthew Wilber	local targetdir;
814d5b07cf2Sshatty	targetdir = [ FDirName $(OBOS_ADDON_DIR) Translators ] ;
8154fb5add0SMatthew Wilber	MakeLocate $(1) : $(targetdir) ;
8164fb5add0SMatthew Wilber}
8174fb5add0SMatthew Wilber
81852a38012Sejakowatzrule MakeLocateObjects
81952a38012Sejakowatz{
82021df5945SIngo Weinhold	# MakeLocateObjects <sources_or_objects> ;
82152a38012Sejakowatz
82221df5945SIngo Weinhold	local _objs = [ FGristFiles $(1:S=$(SUFOBJ)) ] ;
82352a38012Sejakowatz
82452a38012Sejakowatz	for o in $(_objs)
82552a38012Sejakowatz	{
82652a38012Sejakowatz		local dir = $(o:D) ;
82752a38012Sejakowatz		if $(dir) {
82852a38012Sejakowatz			MakeLocate $(o) : [ FDirName $(LOCATE_TARGET) $(dir) ] ;
82952a38012Sejakowatz		} else {
83052a38012Sejakowatz			MakeLocate $(o) : $(LOCATE_TARGET) ;
83152a38012Sejakowatz		}
83252a38012Sejakowatz	}
83352a38012Sejakowatz}
83452a38012Sejakowatz
83552a38012Sejakowatzrule StaticLibrary
83652a38012Sejakowatz{
837e9230d05SIngo Weinhold	# StaticLibrary <name> : <sources> [ : <target dir> ] ;
838e9230d05SIngo Weinhold	# Creates a static library from sources.
839e9230d05SIngo Weinhold	# <name>: Basename of the library, without leading "lib" and trailing ".a".
84060c9c40fSIngo Weinhold	#         Grist is allowed -- it will be re-prepended after constructing
84160c9c40fSIngo Weinhold	#         the complete library name.
842e9230d05SIngo Weinhold	# <source>: List of source files.
843e9230d05SIngo Weinhold	# <target dir>: Directory into which the library shall be placed. Defaults
84460c9c40fSIngo Weinhold	#               to the objects directory for this subdir. If
84560c9c40fSIngo Weinhold	#               STATIC_LIBRARY_DIR is supplied (the literal string)
84660c9c40fSIngo Weinhold	#               the standard directory for static libs is used, otherwise
84760c9c40fSIngo Weinhold	#               the parameter is interpreted as directory path.
848e9230d05SIngo Weinhold	#
84960c9c40fSIngo Weinhold	local lib = lib$(1:B)$(SUFLIB) ;
85060c9c40fSIngo Weinhold	lib = $(lib:G=$(1:G)) ;
851a6c008e1Sbeveloper	SetupIncludes ;
85252a38012Sejakowatz	SetupObjectsDir ;
85352a38012Sejakowatz	MakeLocateObjects $(2) ;
854e9230d05SIngo Weinhold	Library $(lib) : $(2) ;
855e9230d05SIngo Weinhold	local targetDir = $(3) ;
85660c9c40fSIngo Weinhold	if $(targetDir) {
85760c9c40fSIngo Weinhold		if $(targetDir) = STATIC_LIBRARY_DIR {
858e9230d05SIngo Weinhold			targetDir = $(OBOS_STLIB_DIR) ;
859e9230d05SIngo Weinhold		}
860e9230d05SIngo Weinhold		MakeLocate $(lib) : $(targetDir) ;
86160c9c40fSIngo Weinhold	} else {
86260c9c40fSIngo Weinhold		# nothing to do, since the Library rule already located the library
86360c9c40fSIngo Weinhold		# in $(LOCATE_TARGET)
86460c9c40fSIngo Weinhold	}
865f1e077f8SIngo Weinhold
866f1e077f8SIngo Weinhold	# If KEEPOBJS is set, Library doesn't make the library depend on
867f1e077f8SIngo Weinhold	# `lib'.
868f1e077f8SIngo Weinhold	if $(KEEPOBJS) {
869f1e077f8SIngo Weinhold		LocalDepends lib : $(lib) ;
870f1e077f8SIngo Weinhold	}
87152a38012Sejakowatz}
87252a38012Sejakowatz
873dbf96817SIngo Weinholdrule R5KernelStaticLibrary
874dbf96817SIngo Weinhold{
875dbf96817SIngo Weinhold	# R5KernelStaticLibrary <name> : <sources> ;
876dbf96817SIngo Weinhold
877f1e077f8SIngo Weinhold	local lib = lib$(1)$(SUFLIB) ;
878dbf96817SIngo Weinhold	local sources = $(2) ;
879dbf96817SIngo Weinhold
880dbf96817SIngo Weinhold	SetupIncludes ;
881dbf96817SIngo Weinhold	SetupObjectsDir ;
882dbf96817SIngo Weinhold	MakeLocateObjects $(sources) ;
883dbf96817SIngo Weinhold	Library $(lib) : $(sources) ;
884dbf96817SIngo Weinhold	ObjectCcFlags $(sources) : -D_KERNEL_MODE=1 -no-fpic ;
885df48dfedSIngo Weinhold	ObjectC++Flags $(sources) : -D_KERNEL_MODE=1 -no-fpic -fno-exceptions ;
886dbf96817SIngo Weinhold}
887dbf96817SIngo Weinhold
88880721244SAxel Dörflerrule MergeObjectFromObjects
88980721244SAxel Dörfler{
8902fbd7065SIngo Weinhold	# MergeObjectFromObjects <name> : <objects> : <other objects> ;
8912fbd7065SIngo Weinhold	# Merges object files to an object file.
8922fbd7065SIngo Weinhold	# <name>: Name of the object file to create. No grist will be added.
8932fbd7065SIngo Weinhold	# <objects>: Object files to be merged. Grist will be added.
8942fbd7065SIngo Weinhold	# <other objects>: Object files or static libraries to be merged. No grist
8952fbd7065SIngo Weinhold	#                  will be added.
8962fbd7065SIngo Weinhold	#
897c8aa252aSIngo Weinhold	local objects = [ FGristFiles $(2) ] ;
89880721244SAxel Dörfler	MakeLocate $(1) : $(LOCATE_TARGET) ;
899c8aa252aSIngo Weinhold	Depends $(1) : $(objects) ;
9002fbd7065SIngo Weinhold	Depends $(1) : $(3) ;
90180721244SAxel Dörfler	LINK on $(1) = ld ;
9022fbd7065SIngo Weinhold	MergeObjectFromObjects1 $(1) : $(objects) $(3) ;
90380721244SAxel Dörfler}
90480721244SAxel Dörfler
90554b7cbe1SIngo Weinholdactions MergeObjectFromObjects1
90680721244SAxel Dörfler{
90780721244SAxel Dörfler	$(LINK) -r $(2) -o $(1) ;
90880721244SAxel Dörfler}
90980721244SAxel Dörfler
91080721244SAxel Dörflerrule MergeObject
91180721244SAxel Dörfler{
9122fbd7065SIngo Weinhold	# MergeObject <name> : <sources> : <other objects> ;
9132fbd7065SIngo Weinhold	# Compiles source files and merges the object files to an object file.
9142fbd7065SIngo Weinhold	# <name>: Name of the object file to create. No grist will be added.
9152fbd7065SIngo Weinhold	# <sources>: Sources to be compiled. Grist will be added.
9162fbd7065SIngo Weinhold	# <other objects>: Object files or static libraries to be merged. No grist
9172fbd7065SIngo Weinhold	#                  will be added.
9182fbd7065SIngo Weinhold	#
91980721244SAxel Dörfler	SetupIncludes ;
92080721244SAxel Dörfler	SetupObjectsDir ;
92180721244SAxel Dörfler	MakeLocateObjects $(2) ;
92280721244SAxel Dörfler	Objects $(2) ;
9232fbd7065SIngo Weinhold	MergeObjectFromObjects $(1) : $(2:S=$(SUFOBJ)) : $(3) ;
92480721244SAxel Dörfler}
92580721244SAxel Dörfler
92621df5945SIngo Weinholdrule SharedLibraryFromObjects
92752a38012Sejakowatz{
9288d3308d9SIngo Weinhold	# SharedLibraryFromObjects <name> : <objects> : <libraries> ;
92960c9c40fSIngo Weinhold	local _lib = lib$(1:B).so ;
93060c9c40fSIngo Weinhold	_lib = $(_lib:G=$(1:G)) ;
93121df5945SIngo Weinhold	MainFromObjects $(_lib) : $(2) ;
93252a38012Sejakowatz	MakeLocate $(_lib) : $(OBOS_SHLIB_DIR) ;
9339eea4522SIngo Weinhold	LINKFLAGS on $(_lib) = [ on $(_lib) return $(LINKFLAGS) ]
9349eea4522SIngo Weinhold						   -nostart -Xlinker -soname=\"$(_lib)\" ;
9358d3308d9SIngo Weinhold	LinkSharedOSLibs $(_lib) : $(3) ;
93652a38012Sejakowatz}
93752a38012Sejakowatz
93821df5945SIngo Weinholdrule SharedLibrary
93921df5945SIngo Weinhold{
9408d3308d9SIngo Weinhold	# SharedLibrary <name> : <sources> : <libraries> ;
941a6c008e1Sbeveloper	SetupIncludes ;
94221df5945SIngo Weinhold	SetupObjectsDir ;
94321df5945SIngo Weinhold	MakeLocateObjects $(2) ;
94421df5945SIngo Weinhold	Objects $(2) ;
9458d3308d9SIngo Weinhold	SharedLibraryFromObjects $(1) : $(2:S=$(SUFOBJ)) : $(3) ;
94621df5945SIngo Weinhold}
94721df5945SIngo Weinhold
94852a38012Sejakowatzrule LinkSharedOSLibs
94952a38012Sejakowatz{
95052a38012Sejakowatz	# LinkSharedOSLibs <name> : <libs> ;
95152a38012Sejakowatz	# Valid elements for <libs> are e.g. "be" or "libopenbeos.so" or
9524236d490SIngo Weinhold	# "/boot/.../libfoo.so". If the basename starts with "lib" or the thingy
9534236d490SIngo Weinhold	# has a dirname or grist, it is added to the NEEDLIBS variable (i.e. the
9544236d490SIngo Weinhold	# file will be bound!), otherwise it is prefixed "-l" and added to
955a8cd0719SIngo Weinhold	# LINKLIBS. If you want to specify a target that isn't a library and
956a8cd0719SIngo Weinhold	# also has neither grist nor a dirname, you can prepend "<nogrist>" as
957a8cd0719SIngo Weinhold	# grist; it will be stripped by this rule.
95852a38012Sejakowatz
95952a38012Sejakowatz	for i in $(>)
96052a38012Sejakowatz	{
9614236d490SIngo Weinhold		local isfile = ;
9624236d490SIngo Weinhold		if $(i:D) || $(i:G) {
9634236d490SIngo Weinhold			isfile = true ;
964a8cd0719SIngo Weinhold			if $(i:G) = <nogrist> {
965a8cd0719SIngo Weinhold				i = $(i:G=) ;
966a8cd0719SIngo Weinhold			}
9674236d490SIngo Weinhold		} else {
96852a38012Sejakowatz			switch $(i:B)
96952a38012Sejakowatz			{
970007eb5f2SIngo Weinhold				# XXX: _APP_ and _KERNEL_ should not be needed for ELF.
971f7901247SPhilippe Houdoin				case _APP_ : isfile = true ;
972f7901247SPhilippe Houdoin				case _KERNEL_ : isfile = true ;
9734236d490SIngo Weinhold				case lib*	: isfile = true ;
9744236d490SIngo Weinhold				case *	: isfile = ;
9754236d490SIngo Weinhold			}
976b8baf385SIngo Weinhold			if ! $(isfile) && ( $(i:S) = .so || $(i:S) = .a ) {
977b8baf385SIngo Weinhold				isfile = true ;
978b8baf385SIngo Weinhold			}
9794236d490SIngo Weinhold		}
9804236d490SIngo Weinhold		if $(isfile) {
9819eea4522SIngo Weinhold			NEEDLIBS on $(1) = [ on $(1) return $(NEEDLIBS) ] $(i) ;
9829eea4522SIngo Weinhold			Depends $(1) : $(i) ;
9834236d490SIngo Weinhold		} else {
9849eea4522SIngo Weinhold			LINKLIBS on $(1) = [ on $(1) return $(LINKLIBS) ] -l$(i) ;
98552a38012Sejakowatz		}
98652a38012Sejakowatz	}
98752a38012Sejakowatz}
98852a38012Sejakowatz
98952a38012Sejakowatzrule AddResources
99052a38012Sejakowatz{
99152a38012Sejakowatz	# AddResources <name> : <resourcefiles> ;
99252a38012Sejakowatz
9938d3308d9SIngo Weinhold	local resfiles = [ FGristFiles $(2) ] ;
9948d3308d9SIngo Weinhold	SEARCH on $(resfiles) += $(SEARCH_SOURCE) ;
9958d3308d9SIngo Weinhold
9968d3308d9SIngo Weinhold	for file in $(resfiles) {
9978d3308d9SIngo Weinhold		if $(file:S) = .rdef {
9988d3308d9SIngo Weinhold			local rdef = $(file) ;
9998d3308d9SIngo Weinhold			file = $(rdef:S=.rsrc) ;
10008d3308d9SIngo Weinhold			ResComp $(file) : $(rdef) ;
10018d3308d9SIngo Weinhold		}
10028d3308d9SIngo Weinhold		RESFILES on $(1) += $(file) ;
10038d3308d9SIngo Weinhold	}
10048d3308d9SIngo Weinhold}
10058d3308d9SIngo Weinhold
10068d3308d9SIngo Weinholdrule ResComp
10078d3308d9SIngo Weinhold{
10088d3308d9SIngo Weinhold	# ResComp <resource file> : <rdef file> ;
10098d3308d9SIngo Weinhold	#
10108d3308d9SIngo Weinhold	# <resource file> and <rdef file> must be gristed.
10118d3308d9SIngo Weinhold
10128d3308d9SIngo Weinhold	SetupObjectsDir ;
10138d3308d9SIngo Weinhold
10149fc6b2e1SIngo Weinhold	SEARCH on $(2) += $(SEARCH_SOURCE) ;
10158d3308d9SIngo Weinhold	MakeLocate $(1) : $(LOCATE_TARGET) ;
10168d3308d9SIngo Weinhold	Depends $(1) : $(2) rc ;
10178d3308d9SIngo Weinhold	LocalClean clean : $(1) ;
10188d3308d9SIngo Weinhold	ResComp1 $(1) : rc $(2) ;
10198d3308d9SIngo Weinhold}
10208d3308d9SIngo Weinhold
10218d3308d9SIngo Weinholdactions ResComp1
10228d3308d9SIngo Weinhold{
10236af76074SIngo Weinhold	$(2[1]) -o $(1) $(2[2-])
102452a38012Sejakowatz}
102552a38012Sejakowatz
1026728b5725SIngo Weinholdrule ObjectsDefines
1027728b5725SIngo Weinhold{
1028728b5725SIngo Weinhold	# Like ObjectDefines, but allows multiple files to be supplied
1029728b5725SIngo Weinhold	local file ;
1030728b5725SIngo Weinhold	for file in $(1) {
1031728b5725SIngo Weinhold		ObjectDefines $(file) : $(2) ;
1032728b5725SIngo Weinhold	}
1033728b5725SIngo Weinhold}
1034728b5725SIngo Weinhold
10359b60a208SIngo Weinholdrule SourceHdrs
10369b60a208SIngo Weinhold{
10379b60a208SIngo Weinhold	# SourceHdrs <sources> : <headers> [ : <gristed objects> ] ;
10389b60a208SIngo Weinhold	#
10399b60a208SIngo Weinhold	# Is a wrapper for ObjectHdrs, that passes <sources> and <headers> or,
10409b60a208SIngo Weinhold	# if supplied <objects> and <headers>, and also adjusts HDRSEARCH (not
10419b60a208SIngo Weinhold	# done by ObjectHdrs).
10429b60a208SIngo Weinhold
10439b60a208SIngo Weinhold	local sources = [ FGristFiles $(1) ] ;
10449b60a208SIngo Weinhold	local headers = $(2) ;
10459b60a208SIngo Weinhold	local objects = $(3) ;
10469b60a208SIngo Weinhold
1047728b5725SIngo Weinhold	local file ;
10489b60a208SIngo Weinhold	if $(objects) {
1049728b5725SIngo Weinhold		for file in $(objects) {
1050728b5725SIngo Weinhold			ObjectHdrs $(file) : $(headers) ;
1051c0e501e0SIngo Weinhold			# also reformat the assembler headers
1052c0e501e0SIngo Weinhold			ASHDRS on $(file) = [ FIncludes $(SEARCH_SOURCE) $(SUBDIRHDRS)
1053c0e501e0SIngo Weinhold								  [ on $(file) return $(HDRS) ] ] ;
1054728b5725SIngo Weinhold		}
10559b60a208SIngo Weinhold	} else {
1056081debe8SIngo Weinhold		for file in $(sources:S=$(SUFOBJ)) {
1057728b5725SIngo Weinhold			ObjectHdrs $(file) : $(headers) ;
1058c0e501e0SIngo Weinhold			# also reformat the assembler headers
1059c0e501e0SIngo Weinhold			ASHDRS on $(file) = [ FIncludes $(SEARCH_SOURCE) $(SUBDIRHDRS)
1060c0e501e0SIngo Weinhold								  [ on $(file) return $(HDRS) ] ] ;
1061728b5725SIngo Weinhold		}
10629b60a208SIngo Weinhold	}
10639b60a208SIngo Weinhold
10649b60a208SIngo Weinhold	# Also add the header search dirs to HDRSEARCH. Note, that these dirs
10659b60a208SIngo Weinhold	# will be listed after the STDHDRS (if any), but that's better than not
10669b60a208SIngo Weinhold	# being listed at all.
10679b60a208SIngo Weinhold	HDRSEARCH on $(sources) += $(headers) ;
10689b60a208SIngo Weinhold}
10699b60a208SIngo Weinhold
10707d7f280eSIngo Weinholdrule PublicHeaders
107152a38012Sejakowatz{
10727d7f280eSIngo Weinhold	# PublicHeaders <group list>
107352a38012Sejakowatz	#
10747d7f280eSIngo Weinhold	# Returns the directory names for the public header dirs identified by
10757d7f280eSIngo Weinhold	# <group list>.
107652a38012Sejakowatz
107752a38012Sejakowatz	local list = $(1) ;
1078b005dbe3SAxel Dörfler	local dirs = [ FDirName $(OBOS_TOP) headers os ] ;
1079b005dbe3SAxel Dörfler
108052a38012Sejakowatz	for i in $(list) {
10817d7f280eSIngo Weinhold		dirs += [ FDirName $(OBOS_TOP) headers os $(i) ] ;
10827d7f280eSIngo Weinhold	}
10837d7f280eSIngo Weinhold	return $(dirs) ;
108452a38012Sejakowatz}
108552a38012Sejakowatz
10867d7f280eSIngo Weinholdrule PrivateHeaders
10877d7f280eSIngo Weinhold{
10887d7f280eSIngo Weinhold	# PrivateHeaders <group list>
10897d7f280eSIngo Weinhold	#
10907d7f280eSIngo Weinhold	# Returns the directory names for the private header dirs identified by
10917d7f280eSIngo Weinhold	# <group list>.
10927d7f280eSIngo Weinhold
10937d7f280eSIngo Weinhold	local list = $(1) ;
10947d7f280eSIngo Weinhold	local dirs ;
10957d7f280eSIngo Weinhold	for i in $(list) {
10967d7f280eSIngo Weinhold		dirs += [ FDirName $(OBOS_TOP) headers private $(i) ] ;
10977d7f280eSIngo Weinhold	}
10987d7f280eSIngo Weinhold	return $(dirs) ;
10997d7f280eSIngo Weinhold}
11007d7f280eSIngo Weinhold
11010f434a0aSDarkWyrmrule LibraryHeaders
11020f434a0aSDarkWyrm{
11030f434a0aSDarkWyrm	# LibraryHeaders <group list>
11040f434a0aSDarkWyrm	#
11050f434a0aSDarkWyrm	# Returns the directory names for the library header dirs identified by
11060f434a0aSDarkWyrm	# <group list>.
11070f434a0aSDarkWyrm
11080f434a0aSDarkWyrm	local list = $(1) ;
11090f434a0aSDarkWyrm	local dirs ;
11100f434a0aSDarkWyrm	for i in $(list) {
11110f434a0aSDarkWyrm		dirs += [ FDirName $(OBOS_TOP) headers libs $(i) ] ;
11120f434a0aSDarkWyrm	}
11130f434a0aSDarkWyrm	return $(dirs) ;
11140f434a0aSDarkWyrm}
11150f434a0aSDarkWyrm
11167d7f280eSIngo Weinholdrule ArchHeaders
11177d7f280eSIngo Weinhold{
11187d7f280eSIngo Weinhold	# usage: ArchHeaders <arch> ;
11197d7f280eSIngo Weinhold	#
11207d7f280eSIngo Weinhold	# <arch> specifies the architecture (e.g. x86).
11217d7f280eSIngo Weinhold
11227d7f280eSIngo Weinhold	return [ FDirName $(OBOS_TOP) headers private kernel arch $(1) ] ;
11237d7f280eSIngo Weinhold}
11247d7f280eSIngo Weinhold
11257d7f280eSIngo Weinholdrule UsePublicHeaders
11267d7f280eSIngo Weinhold{
1127966528dcSIngo Weinhold	# UsePublicHeaders <group list> ;
1128966528dcSIngo Weinhold	#
1129966528dcSIngo Weinhold	# Adds the public C header dirs given by <group list> to the header search
1130966528dcSIngo Weinhold	# dirs of the subdirectory.
1131966528dcSIngo Weinhold	# NOTE: This rule must be invoked *before* the rule that builds the
1132966528dcSIngo Weinhold	# objects.
1133966528dcSIngo Weinhold
1134966528dcSIngo Weinhold	UseHeaders [ PublicHeaders $(1) ] ;
11357d7f280eSIngo Weinhold}
11367d7f280eSIngo Weinhold
11377d7f280eSIngo Weinholdrule UsePublicObjectHeaders
11387d7f280eSIngo Weinhold{
11399b60a208SIngo Weinhold	# UsePublicObjectHeaders <sources> : <group list> [ : <objects> ] ;
11407d7f280eSIngo Weinhold	#
11417d7f280eSIngo Weinhold	# Adds the public C header dirs given by <group list> to the header search
11429b60a208SIngo Weinhold	# dirs of either the object targets of <sources> or if supplied to
11439b60a208SIngo Weinhold	# <objects>. Also adjusts HDRSEARCH of <sources>.
11447d7f280eSIngo Weinhold	# NOTE: This rule must be invoked *after* the rule that builds the objects.
11457d7f280eSIngo Weinhold
11469b60a208SIngo Weinhold	SourceHdrs $(1) : [ PublicHeaders $(2) ] : $(3) ;
114752a38012Sejakowatz}
114852a38012Sejakowatz
114952a38012Sejakowatzrule UsePrivateHeaders
115052a38012Sejakowatz{
11517d7f280eSIngo Weinhold	# UsePrivateHeaders <group list> ;
115252a38012Sejakowatz	#
115352a38012Sejakowatz	# Adds the private C header dirs given by <group list> to the header search
11547d7f280eSIngo Weinhold	# dirs of the subdirectory.
11557d7f280eSIngo Weinhold	# NOTE: This rule must be invoked *before* the rule that builds the objects.
115652a38012Sejakowatz
11577d7f280eSIngo Weinhold	UseHeaders [ PrivateHeaders $(1) ] ;
115852a38012Sejakowatz}
115952a38012Sejakowatz
11607d7f280eSIngo Weinholdrule UsePrivateObjectHeaders
11617d7f280eSIngo Weinhold{
11629b60a208SIngo Weinhold	# UsePrivateObjectHeaders <sources> : <group list> [ : <objects> ] ;
11637d7f280eSIngo Weinhold	#
11647d7f280eSIngo Weinhold	# Adds the private C header dirs given by <group list> to the header search
11659b60a208SIngo Weinhold	# dirs of either the object targets of <sources> or if supplied to
11669b60a208SIngo Weinhold	# <objects>. Also adjusts HDRSEARCH of <sources>.
11677d7f280eSIngo Weinhold	# NOTE: This rule must be invoked *after* the rule that builds the objects.
11687d7f280eSIngo Weinhold
11699b60a208SIngo Weinhold	SourceHdrs $(1) : [ PrivateHeaders $(2) ] : $(3) ;
117052a38012Sejakowatz}
117152a38012Sejakowatz
117252a38012Sejakowatzrule UseHeaders
117352a38012Sejakowatz{
11747d7f280eSIngo Weinhold	# UseHeaders <headers> ;
117552a38012Sejakowatz	#
117652a38012Sejakowatz	# Adds the C header dirs <headers> to the header search
11777d7f280eSIngo Weinhold	# dirs of the subdirectory.
11787d7f280eSIngo Weinhold	# NOTE: This rule must be invoked *before* the rule that builds the objects.
117952a38012Sejakowatz
11807d7f280eSIngo Weinhold	local header ;
11817d7f280eSIngo Weinhold	for header in $(1) {
118252a38012Sejakowatz		SubDirHdrs $(header) ;
118352a38012Sejakowatz	}
118452a38012Sejakowatz}
118552a38012Sejakowatz
118652a38012Sejakowatzrule UseCppUnitHeaders
118752a38012Sejakowatz{
11887d7f280eSIngo Weinhold	SubDirHdrs [ FDirName $(OBOS_TOP) headers tools cppunit ] ;
118952a38012Sejakowatz}
119052a38012Sejakowatz
1191be5af1baSIngo Weinholdrule UseCppUnitObjectHeaders
1192be5af1baSIngo Weinhold{
11939b60a208SIngo Weinhold	# UseCppUnitObjectHeaders <sources> [ : <objects> ] ;
11949b60a208SIngo Weinhold	SourceHdrs $(1) : [ FDirName $(OBOS_TOP) headers tools cppunit ] : $(2) ;
1195be5af1baSIngo Weinhold}
1196be5af1baSIngo Weinhold
119752a38012Sejakowatzrule UseArchHeaders
119852a38012Sejakowatz{
11997d7f280eSIngo Weinhold	# usage: UseArchHeaders <arch> ;
12007d7f280eSIngo Weinhold	#
120152a38012Sejakowatz	# <arch> specifies the architecture (e.g. x86).
12027d7f280eSIngo Weinhold	# NOTE: This rule must be invoked *before* the rule that builds the objects.
12037d7f280eSIngo Weinhold
12047d7f280eSIngo Weinhold	local headers = [ ArchHeaders $(1) ] ;
120552a38012Sejakowatz	local opt = -D$(OBOS_TARGET_DEFINE) ;
1206c633961aSIngo Weinhold
120752a38012Sejakowatz	SubDirCcFlags $(opt)  ;
120852a38012Sejakowatz	SubDirC++Flags $(opt)  ;
1209089a0629Sbeveloper	HDRS += $(headers) ;
1210c633961aSIngo Weinhold}
1211c633961aSIngo Weinhold
12127d7f280eSIngo Weinholdrule UseArchObjectHeaders
12137d7f280eSIngo Weinhold{
12149b60a208SIngo Weinhold	# usage: UseArchObjectHeaders <sources> : <arch> : [ <objects> ] ;
12157d7f280eSIngo Weinhold	#
12167d7f280eSIngo Weinhold	# <arch> specifies the architecture (e.g. x86).
12177d7f280eSIngo Weinhold	# <sources_or_objects> Source or object files.
12187d7f280eSIngo Weinhold	# NOTE: This rule must be invoked *after* the rule that builds the objects.
12197d7f280eSIngo Weinhold
12209b60a208SIngo Weinhold	local sources = $(1) ;
12217d7f280eSIngo Weinhold	local headers = [ ArchHeaders $(2) ] ;
12229b60a208SIngo Weinhold	local objects = $(3) ;
12239b60a208SIngo Weinhold	local targets ;
12249b60a208SIngo Weinhold	if $(objects) {
12259b60a208SIngo Weinhold		targets = $(objects) ;
12269b60a208SIngo Weinhold	} else {
1227081debe8SIngo Weinhold		targets = [ FGristFiles $(sources:S=$(SUFOBJ)) ] ;
12289b60a208SIngo Weinhold	}
12297d7f280eSIngo Weinhold	local opt = -D$(OBOS_TARGET_DEFINE) ;
12307d7f280eSIngo Weinhold
12317d7f280eSIngo Weinhold	ObjectCcFlags $(targets) : $(opt)  ;
12327d7f280eSIngo Weinhold	ObjectC++Flags $(targets) : $(opt)  ;
12339b60a208SIngo Weinhold	SourceHdrs $(sources) : $(headers) : $(objects) ;
123452a38012Sejakowatz}
123552a38012Sejakowatz
1236d25a77b4SIngo Weinholdrule UsePosixHeaders
1237d25a77b4SIngo Weinhold{
1238a6c008e1Sbeveloper	# XXX changed to do nothing
1239d25a77b4SIngo Weinhold}
1240d25a77b4SIngo Weinhold
1241d25a77b4SIngo Weinholdrule UsePosixObjectHeaders
1242d25a77b4SIngo Weinhold{
12439b60a208SIngo Weinhold	# UsePosixObjectHeaders <sources> [ : <objects> ] ;
1244d25a77b4SIngo Weinhold	#
1245d25a77b4SIngo Weinhold	# Adds the POSIX header dir to the header search
12469b60a208SIngo Weinhold	# dirs of either the object targets of <sources> or if supplied to
12479b60a208SIngo Weinhold	# <objects>. Also adjusts HDRSEARCH of <sources>.
1248d25a77b4SIngo Weinhold	# NOTE: This rule must be invoked *after* the rule that builds the objects.
1249d25a77b4SIngo Weinhold
12509b60a208SIngo Weinhold	SourceHdrs $(1) : [ FDirName $(OBOS_TOP) headers posix ] : $(2) ;
1251d25a77b4SIngo Weinhold}
1252d25a77b4SIngo Weinhold
12530f434a0aSDarkWyrmrule UseLibraryHeaders
12540f434a0aSDarkWyrm{
12550f434a0aSDarkWyrm	# UseLibraryHeaders <group list> ;
12560f434a0aSDarkWyrm	#
12570f434a0aSDarkWyrm	# Adds the library header dirs given by <group list> to the header search
12580f434a0aSDarkWyrm	# dirs of the subdirectory.
12590f434a0aSDarkWyrm	# NOTE: This rule must be invoked *before* the rule that builds the objects.
12600f434a0aSDarkWyrm
12610f434a0aSDarkWyrm	UseHeaders [ LibraryHeaders $(1) ] ;
12620f434a0aSDarkWyrm}
12630f434a0aSDarkWyrm
12643b9eae39SIngo Weinholdrule SplitPath
12653b9eae39SIngo Weinhold{
12663b9eae39SIngo Weinhold	# SplitPath <path> ;
12673b9eae39SIngo Weinhold	# Decomposes a path into its components.
12683b9eae39SIngo Weinhold	local path = $(1:G=) ;
12693b9eae39SIngo Weinhold	local components ;
12708c27f58dSIngo Weinhold	# $(path:D) for "/" is "/". Therefore the second condition.
12718c27f58dSIngo Weinhold	while $(path:D) && $(path:D) != $(path)
12723b9eae39SIngo Weinhold	{
12733b9eae39SIngo Weinhold		# Note: $(path:B) returns "." for "..", but $(path:D=) is fine.
12743b9eae39SIngo Weinhold		components = $(path:D=) $(components) ;
12753b9eae39SIngo Weinhold		path = $(path:D) ;
12763b9eae39SIngo Weinhold	}
12773b9eae39SIngo Weinhold	components = $(path) $(components) ;
12783b9eae39SIngo Weinhold	return $(components) ;
12793b9eae39SIngo Weinhold}
12803b9eae39SIngo Weinhold
12819fc6b2e1SIngo Weinholdrule PrependObjectHdrs
12829fc6b2e1SIngo Weinhold{
12839fc6b2e1SIngo Weinhold	# PrependObjectHdrs <objects_or_sources> : <dirs> ;
12849fc6b2e1SIngo Weinhold	# Prepends <dirs> to the list of header search dirs of the objects
12859fc6b2e1SIngo Weinhold	# specified by <objects_or_sources>. The HDRS variable will not be
12869fc6b2e1SIngo Weinhold	# changed, only CCHDRS.
12879fc6b2e1SIngo Weinhold	# Note: A subsequent ObjectHdrs invocation will therefore undo the
12889fc6b2e1SIngo Weinhold	# effect of this rule.
12899fc6b2e1SIngo Weinhold	# NOTE: This is a hack.
12909fc6b2e1SIngo Weinhold
12919fc6b2e1SIngo Weinhold	local objects = [ FGristFiles $(1:S=$(SUFOBJ)) ] ;
12929fc6b2e1SIngo Weinhold	local dirs = $(2) ;
12939fc6b2e1SIngo Weinhold	for object in $(objects) {
12949fc6b2e1SIngo Weinhold		# Don't change HDRS to avoid screwing up the header scanning.
12959fc6b2e1SIngo Weinhold		PREPENDED_HDRS on $(object)
12969fc6b2e1SIngo Weinhold			= $(dirs) [ on $(object) return $(PREPENDED_HDRS) ] ;
12979fc6b2e1SIngo Weinhold		CCHDRS on $(object)
12989fc6b2e1SIngo Weinhold			= [ FIncludes [ on $(object) return $(PREPENDED_HDRS) $(HDRS) ] ] ;
12999fc6b2e1SIngo Weinhold	}
13009fc6b2e1SIngo Weinhold}
13019fc6b2e1SIngo Weinhold
13023b9eae39SIngo Weinholdrule SymLink
13033b9eae39SIngo Weinhold{
13047669b69fSIngo Weinhold	# SymLink <target> : <source> : <makeDefaultDependencies> ;
13053b9eae39SIngo Weinhold	# Links <target> to <source>.
13063b9eae39SIngo Weinhold	# <source> is the exact link contents. No binding is done.
13077669b69fSIngo Weinhold	# <makeDefaultDependencies> If true, <target> will be made a dependency
13087669b69fSIngo Weinhold	# of the `all' pseudo target, i.e. it will be made by default, and removed
13097669b69fSIngo Weinhold	# on `jam clean'.
13107669b69fSIngo Weinhold
13117669b69fSIngo Weinhold	local target = $(1) ;
13127669b69fSIngo Weinhold	local source = $(2) ;
13137669b69fSIngo Weinhold	local makeDefaultDependencies = $(3) ;
13147669b69fSIngo Weinhold	if ! $(makeDefaultDependencies) {
13157669b69fSIngo Weinhold		makeDefaultDependencies = true ;
13167669b69fSIngo Weinhold	}
13177669b69fSIngo Weinhold	LINKCONTENTS on $(target) = $(source) ;
13187669b69fSIngo Weinhold	SymLink1 $(target) ;
13197669b69fSIngo Weinhold	if $(makeDefaultDependencies) = true {
13207669b69fSIngo Weinhold		LocalDepends files : $(target) ;
13217669b69fSIngo Weinhold		LocalClean clean : $(target) ;
13227669b69fSIngo Weinhold	}
13233b9eae39SIngo Weinhold}
13243b9eae39SIngo Weinhold
13253b9eae39SIngo Weinholdactions SymLink1
13263b9eae39SIngo Weinhold{
13270931b8f9SIngo Weinhold	$(RM) "$(1)" && $(LN) -s "$(LINKCONTENTS)" "$(1)"
13280931b8f9SIngo Weinhold}
13290931b8f9SIngo Weinhold
13300931b8f9SIngo Weinholdrule RelSymLink
13310931b8f9SIngo Weinhold{
13327669b69fSIngo Weinhold	# RelSymLink <link> : <link target> : <makeDefaultDependencies> ;
13330931b8f9SIngo Weinhold	# Creates a relative symbolic link from <link> to <link target>.
13340931b8f9SIngo Weinhold	# <link> and <link target> can be usual targets. They may have a grist
13350931b8f9SIngo Weinhold	# and don't need to have any dirname. Their LOCATE variables are used to
13360931b8f9SIngo Weinhold	# find their locations.
13377669b69fSIngo Weinhold	# <makeDefaultDependencies> If true (which is the default), <link> will be
13387669b69fSIngo Weinhold	# made a dependency of the `files' pseudo target, i.e. it will be made by
13397669b69fSIngo Weinhold	# default, and removed on `jam clean'.
13400931b8f9SIngo Weinhold
13410931b8f9SIngo Weinhold	local target = $(1) ;
13420931b8f9SIngo Weinhold	local source = $(2) ;
13437669b69fSIngo Weinhold	local makeDefaultDependencies = $(3) ;
13440931b8f9SIngo Weinhold	local targetDir = [ on $(target) FDirName $(LOCATE[1]) $(target:D) ] ;
13450931b8f9SIngo Weinhold	local sourceDir = [ on $(source) FDirName $(LOCATE[1]) $(source:D) ] ;
13460931b8f9SIngo Weinhold	local sourcePath = $(source:G=) ;
13470931b8f9SIngo Weinhold	sourcePath = $(sourcePath:D=$(sourceDir)) ;
13480931b8f9SIngo Weinhold	local targetDirComponents = [ SplitPath $(targetDir) ] ;
13490931b8f9SIngo Weinhold	local sourceComponents = [ SplitPath $(sourcePath) ] ;
13500931b8f9SIngo Weinhold
13510931b8f9SIngo Weinhold	SymLink $(target)
13527669b69fSIngo Weinhold		: [ FRelPath $(targetDirComponents) : $(sourceComponents) ]
13537669b69fSIngo Weinhold		: $(makeDefaultDependencies) ;
13540931b8f9SIngo Weinhold	NOUPDATE $(target) ;
13559eea4522SIngo Weinhold	Depends $(target) : $(source) ;
13563b9eae39SIngo Weinhold}
13573b9eae39SIngo Weinhold
1358d391d2ebSIngo Weinholdrule AbsSymLink
1359d391d2ebSIngo Weinhold{
13607bc56df1SIngo Weinhold	# AbsSymLink <link> : <link target> : <link dir>
13617669b69fSIngo Weinhold	#			: <makeDefaultDependencies> ;
1362d391d2ebSIngo Weinhold	# Creates an absolute symbolic link from <link> to <link target>.
1363d391d2ebSIngo Weinhold	# <link> and <link target> must be usual targets. If <link dir> is
1364d391d2ebSIngo Weinhold	# given, then it is set as LOCATE directory on <link>.
13657669b69fSIngo Weinhold	# <makeDefaultDependencies> If true (which is the default), <link> will be
13667669b69fSIngo Weinhold	# made a dependency of the `files' pseudo target, i.e. it will be made by
13677669b69fSIngo Weinhold	# default, and removed on `jam clean'.
1368d391d2ebSIngo Weinhold
13697669b69fSIngo Weinhold	local makeDefaultDependencies = $(4) ;
13707669b69fSIngo Weinhold	if ! $(makeDefaultDependencies) {
13717669b69fSIngo Weinhold		makeDefaultDependencies = true ;
13727669b69fSIngo Weinhold	}
13737669b69fSIngo Weinhold
1374d391d2ebSIngo Weinhold	Depends $(1) : $(2) ;
1375d391d2ebSIngo Weinhold	if $(3) {
1376d391d2ebSIngo Weinhold		MakeLocate $(1) : $(3) ;
1377d391d2ebSIngo Weinhold	}
1378d391d2ebSIngo Weinhold	SEARCH on $(2) += $(SEARCH_SOURCE) ;
13797669b69fSIngo Weinhold	if $(makeDefaultDependencies) = true {
13807669b69fSIngo Weinhold		LocalDepends files : $(1) ;
1381d391d2ebSIngo Weinhold		LocalClean clean : $(1) ;
1382d391d2ebSIngo Weinhold	}
13837669b69fSIngo Weinhold}
1384d391d2ebSIngo Weinhold
1385d391d2ebSIngo Weinholdactions AbsSymLink
1386d391d2ebSIngo Weinhold{
1387d391d2ebSIngo Weinhold	target="$(2)"
1388d391d2ebSIngo Weinhold	case "$target" in
1389d391d2ebSIngo Weinhold		/*) ;;
1390d391d2ebSIngo Weinhold		*) target=`pwd`/"$target";;
1391d391d2ebSIngo Weinhold	esac
1392d391d2ebSIngo Weinhold	$(RM) "$(1)" && $(LN) -s "$target" "$(1)"
1393d391d2ebSIngo Weinhold}
1394d391d2ebSIngo Weinhold
13957bc56df1SIngo Weinholdrule OBOSInstall
13967bc56df1SIngo Weinhold{
13977bc56df1SIngo Weinhold	# Usage: OBOSInstall <[ install [ and uninstall ] pseudotarget ]>
13987bc56df1SIngo Weinhold	#					 : <directory> : <sources to install>
13997bc56df1SIngo Weinhold	#					 : [ <installgrist> ] : [ <install rule> ] ;
14007bc56df1SIngo Weinhold	local install = $(1[1]) ;
14017bc56df1SIngo Weinhold	install ?= install ;
14027bc56df1SIngo Weinhold	local uninstall = $(1[2]) ;
14037bc56df1SIngo Weinhold	uninstall ?= un$(install) ;
14047bc56df1SIngo Weinhold	local dir = $(2) ;
14057bc56df1SIngo Weinhold	local sources = $(3) ;
14067bc56df1SIngo Weinhold	local installgrist = $(4) ;
14077bc56df1SIngo Weinhold	installgrist ?= $(INSTALLGRIST) ;
14087bc56df1SIngo Weinhold	local installRule = $(5) ;
14097bc56df1SIngo Weinhold	installRule ?= Install ;
14107bc56df1SIngo Weinhold	local targets = $(sources:G=$(installgrist)) ;
14117bc56df1SIngo Weinhold
1412bacf6872Sshatty	NotFile $(install) ;
1413bacf6872Sshatty	NotFile $(uninstall) ;
14147bc56df1SIngo Weinhold	Depends $(install) : $(targets) ;
14157bc56df1SIngo Weinhold	Clean $(uninstall) : $(targets) ;
14167bc56df1SIngo Weinhold
14177bc56df1SIngo Weinhold	SEARCH on $(sources) += $(SEARCH_SOURCE) ;
14187bc56df1SIngo Weinhold	MakeLocate $(targets) : $(dir) ;
14197bc56df1SIngo Weinhold
14207bc56df1SIngo Weinhold	local source ;
14217bc56df1SIngo Weinhold	for source in $(sources) {
14227bc56df1SIngo Weinhold		local target = $(source:G=$(installgrist)) ;
14237bc56df1SIngo Weinhold
14247bc56df1SIngo Weinhold		Depends $(target) : $(source) ;
14257bc56df1SIngo Weinhold		$(installRule) $(target) : $(source) ;
14267bc56df1SIngo Weinhold
14277bc56df1SIngo Weinhold		if [ on $(target) return $(MODE) ] {
14287bc56df1SIngo Weinhold			Chmod $(target) ;
14297bc56df1SIngo Weinhold		}
14307bc56df1SIngo Weinhold
14317bc56df1SIngo Weinhold		if $(OWNER) && $(CHOWN) {
14327bc56df1SIngo Weinhold			Chown $(target) ;
14337bc56df1SIngo Weinhold			OWNER on $(target) = $(OWNER) ;
14347bc56df1SIngo Weinhold		}
14357bc56df1SIngo Weinhold
14367bc56df1SIngo Weinhold		if $(GROUP) && $(CHGRP) {
14377bc56df1SIngo Weinhold			Chgrp $(target) ;
14387bc56df1SIngo Weinhold			GROUP on $(target) = $(GROUP) ;
14397bc56df1SIngo Weinhold		}
14407bc56df1SIngo Weinhold	}
14417bc56df1SIngo Weinhold}
14427bc56df1SIngo Weinhold
14437669b69fSIngo Weinholdrule InstallAbsSymLinkAdapter
14447669b69fSIngo Weinhold{
14457669b69fSIngo Weinhold	# InstallAbsSymLinkAdapter <link> : <link target>
14467669b69fSIngo Weinhold	if ! [ on $(2) return $(TARGET) ] {
14477669b69fSIngo Weinhold		TARGET on $(2) = [ on $(2) return $(SEARCH) ] ;
14487669b69fSIngo Weinhold	}
14497669b69fSIngo Weinhold	AbsSymLink $(1) : $(2) : : false ;
14507669b69fSIngo Weinhold}
14517669b69fSIngo Weinhold
14527bc56df1SIngo Weinholdrule OBOSInstallAbsSymLink
14537bc56df1SIngo Weinhold{
14547bc56df1SIngo Weinhold	# Usage: OBOSInstallAbsSymLink <[ install [ and uninstall ] pseudotarget ]>
14557bc56df1SIngo Weinhold	#							   : <directory> : <sources to install>
14567bc56df1SIngo Weinhold	#							   : [ <installgrist> ] ;
14577669b69fSIngo Weinhold	OBOSInstall $(1) : $(2) : $(3) : $(4) : InstallAbsSymLinkAdapter ;
14587bc56df1SIngo Weinhold}
14597bc56df1SIngo Weinhold
14607bc56df1SIngo Weinholdrule InstallRelSymLinkAdapter
14617bc56df1SIngo Weinhold{
14627bc56df1SIngo Weinhold	# InstallRelSymLinkAdapter <link> : <link target>
14637bc56df1SIngo Weinhold	if ! [ on $(2) return $(TARGET) ] {
14647bc56df1SIngo Weinhold		TARGET on $(2) = [ on $(2) return $(SEARCH) ] ;
14657bc56df1SIngo Weinhold	}
14667669b69fSIngo Weinhold	RelSymLink $(1) : $(2) : false ;
14677bc56df1SIngo Weinhold}
14687bc56df1SIngo Weinhold
14697bc56df1SIngo Weinholdrule OBOSInstallRelSymLink
14707bc56df1SIngo Weinhold{
14717bc56df1SIngo Weinhold	# Usage: OBOSInstallRelSymLink <[ install [ and uninstall ] pseudotarget ]>
14727bc56df1SIngo Weinhold	#							   : <directory> : <sources to install>
14737bc56df1SIngo Weinhold	#							   : [ <installgrist> ] ;
14747bc56df1SIngo Weinhold	OBOSInstall $(1) : $(2) : $(3) : $(4) : InstallRelSymLinkAdapter ;
14757bc56df1SIngo Weinhold}
14767bc56df1SIngo Weinhold
14777bc56df1SIngo Weinhold
147852a38012Sejakowatz#-------------------------------------------------------------------------------
147952a38012Sejakowatz# Low-level OBOS utility rules
148052a38012Sejakowatz#-------------------------------------------------------------------------------
148179b49834SIngo Weinholdrule FObjectsDir
148279b49834SIngo Weinhold{
1483121af366SIngo Weinhold	# FObjectsDir <subdir tokens>
1484121af366SIngo Weinhold	#
1485121af366SIngo Weinhold	# Returns the output directory for object files the specified
1486121af366SIngo Weinhold	# subdirectory.
1487121af366SIngo Weinhold	#
1488121af366SIngo Weinhold	# <subdir tokens>: The tokens of the subdir relative to the top.
1489121af366SIngo Weinhold	#
1490121af366SIngo Weinhold
1491121af366SIngo Weinhold	return [ FDirName $(OBOS_OBJECT_TARGET) $(1[2-]) ] ;
1492121af366SIngo Weinhold}
1493121af366SIngo Weinhold
1494121af366SIngo Weinholdrule FCurrentObjectsDir
1495121af366SIngo Weinhold{
1496121af366SIngo Weinhold	# FCurrentObjectsDir
149779b49834SIngo Weinhold	#
149879b49834SIngo Weinhold	# Returns the output directory for object files for the current
149979b49834SIngo Weinhold	# subdirectory.
150079b49834SIngo Weinhold
1501121af366SIngo Weinhold	return [ FObjectsDir $(SUBDIR_TOKENS) ] ;
150279b49834SIngo Weinhold}
150379b49834SIngo Weinhold
150452a38012Sejakowatzrule SetupObjectsDir
150552a38012Sejakowatz{
1506121af366SIngo Weinhold	LOCATE_TARGET = [ FCurrentObjectsDir ] ;
15078d3308d9SIngo Weinhold	LOCATE_SOURCE = $(LOCATE_TARGET) ;
15088d3308d9SIngo Weinhold	SEARCH_SOURCE = [ Filter $(SEARCH_SOURCE) : $(LOCATE_TARGET) ]
15098d3308d9SIngo Weinhold					$(LOCATE_TARGET) ;
151052a38012Sejakowatz}
151152a38012Sejakowatz
151252a38012Sejakowatz#-------------------------------------------------------------------------------
151352a38012Sejakowatz# Link rule/action are overwritten as they don't handle linking files who's name
151452a38012Sejakowatz# contain spaces very well. Also adds resources and version to executable.
151552a38012Sejakowatz#-------------------------------------------------------------------------------
151652a38012Sejakowatzrule Link
151752a38012Sejakowatz{
151852a38012Sejakowatz	# Note: RESFILES must be set before invocation.
151952a38012Sejakowatz	MODE on $(<) = $(EXEMODE) ;
152052a38012Sejakowatz	on $(1) XRes $(1) : $(RESFILES) ;
152152a38012Sejakowatz	Chmod $(<) ;
152252a38012Sejakowatz	SetType $(1) ;
152352a38012Sejakowatz	MimeSet $(1) ;
15241419ae2bSshatty	SetVersion $(1) ;
152552a38012Sejakowatz}
152652a38012Sejakowatz
152752a38012Sejakowatzactions Link bind NEEDLIBS
152852a38012Sejakowatz{
15291eb18edfSIngo Weinhold	$(LINK) $(LINKFLAGS) -o "$(1)" $(UNDEFS) "$(2)" "$(NEEDLIBS)" $(LINKLIBS) ;
153052a38012Sejakowatz}
153152a38012Sejakowatz
15328d3308d9SIngo Weinholdrule LexC++
15338d3308d9SIngo Weinhold{
15348d3308d9SIngo Weinhold	Depends $(1) : $(2) ;
15358d3308d9SIngo Weinhold	MakeLocate $(1) : $(LOCATE_SOURCE) ;
15368d3308d9SIngo Weinhold	LocalClean clean : $(1) ;
15378d3308d9SIngo Weinhold}
15388d3308d9SIngo Weinhold
15398d3308d9SIngo Weinholdactions LexC++
15408d3308d9SIngo Weinhold{
15418d3308d9SIngo Weinhold	$(LEX) -o$(1) $(2)
15428d3308d9SIngo Weinhold}
15438d3308d9SIngo Weinhold
15448d3308d9SIngo Weinholdrule Bison
15458d3308d9SIngo Weinhold{
15468d3308d9SIngo Weinhold	local _h ;
15478d3308d9SIngo Weinhold
1548cec8c8b5SJérôme Duval	_h = $(1:S=.hpp) ;
15498d3308d9SIngo Weinhold
15508d3308d9SIngo Weinhold	MakeLocate $(<) $(_h) : $(LOCATE_SOURCE) ;
15518d3308d9SIngo Weinhold
15528d3308d9SIngo Weinhold	Depends $(<) $(_h) : $(>) ;
15538d3308d9SIngo Weinhold	Bison1 $(<) $(_h) : $(>) ;
15548d3308d9SIngo Weinhold	LocalClean clean : $(<) $(_h) ;
15558d3308d9SIngo Weinhold
15568d3308d9SIngo Weinhold	# make sure someone includes $(_h) else it will be
15578d3308d9SIngo Weinhold	# a deadly independent target
15588d3308d9SIngo Weinhold
15598d3308d9SIngo Weinhold	Includes $(<) : $(_h) ;
15608d3308d9SIngo Weinhold}
15618d3308d9SIngo Weinhold
15628d3308d9SIngo Weinholdactions Bison1
15638d3308d9SIngo Weinhold{
15648d3308d9SIngo Weinhold	bison $(YACCFLAGS) -o $(1[1]) $(2)
1565cec8c8b5SJérôme Duval	[ -f $(1[1]).h ] && mv $(1[1]).h $(1[2]) || true
15668d3308d9SIngo Weinhold}
15678d3308d9SIngo Weinhold
1568705fc998SAxel Dörflerrule UnarchiveObjects
1569705fc998SAxel Dörfler{
1570705fc998SAxel Dörfler	# UnarchiveObjects <target objects> : <static object>
1571705fc998SAxel Dörfler
1572705fc998SAxel Dörfler	MakeLocate $(1) : $(LOCATE_TARGET) ;
1573705fc998SAxel Dörfler	Depends $(2) : $(1) ;
1574705fc998SAxel Dörfler	SEARCH on $(2) = $(SEARCH_SOURCE) ;
1575705fc998SAxel Dörfler}
1576705fc998SAxel Dörfler
1577705fc998SAxel Dörfleractions UnarchiveObjects
1578705fc998SAxel Dörfler{
15793c71865aSAxel Dörfler	cd $(1[1]:D)
15803c71865aSAxel Dörfler	ar -x "$(2)" $(1:B).o
1581705fc998SAxel Dörfler	cd -
1582705fc998SAxel Dörfler}
1583705fc998SAxel Dörfler
158452a38012Sejakowatz# BeOS specific rules
158552a38012Sejakowatz
158652a38012Sejakowatzrule XRes
158752a38012Sejakowatz{
158852a38012Sejakowatz	# XRes <target> : <resource files>
158952a38012Sejakowatz	if $(2)
159052a38012Sejakowatz	{
15919eea4522SIngo Weinhold		Depends $(1) : $(2) ;
159252a38012Sejakowatz		XRes1 $(1) : $(2) ;
159352a38012Sejakowatz	}
159452a38012Sejakowatz}
159552a38012Sejakowatz
159652a38012Sejakowatzrule XRes1 { }
159752a38012Sejakowatz
159852a38012Sejakowatzrule SetVersion
159952a38012Sejakowatz{
160052a38012Sejakowatz	# SetVersion <target>
160152a38012Sejakowatz}
160252a38012Sejakowatz
160352a38012Sejakowatzrule SetType
160452a38012Sejakowatz{
160552a38012Sejakowatz	# SetType <target>
160652a38012Sejakowatz}
160752a38012Sejakowatz
160852a38012Sejakowatzrule MimeSet
160952a38012Sejakowatz{
161052a38012Sejakowatz	# SetType <target>
161152a38012Sejakowatz}
161252a38012Sejakowatz
161352a38012Sejakowatz
161452a38012Sejakowatzif $(OS) = BEOS
161552a38012Sejakowatz{
161652a38012Sejakowatz
161752a38012Sejakowatzactions XRes1
161852a38012Sejakowatz{
16190931b8f9SIngo Weinhold	xres -o "$(1)" "$(2)" ;
162052a38012Sejakowatz}
162152a38012Sejakowatz
162252a38012Sejakowatzactions SetVersion
162352a38012Sejakowatz{
162452a38012Sejakowatz	setversion "$(1)" -system $(OBOS_BUILD_VERSION) -short "$(OBOS_BUILD_DESCRIPTION)" ;
162552a38012Sejakowatz}
162652a38012Sejakowatz
162752a38012Sejakowatzactions SetType
162852a38012Sejakowatz{
162952a38012Sejakowatz	settype -t $(OBOS_TARGET_TYPE) "$(1)" ;
163052a38012Sejakowatz}
163152a38012Sejakowatz
163252a38012Sejakowatzactions MimeSet
163352a38012Sejakowatz{
163452a38012Sejakowatz	mimeset -f "$(1)" ;
163552a38012Sejakowatz}
163652a38012Sejakowatz
163752a38012Sejakowatz}	# if BEOS
163852a38012Sejakowatz
163952a38012Sejakowatz
164052a38012Sejakowatzrule assemble
164152a38012Sejakowatz{
164294782cf7SIngo Weinhold	Depends $(<) : $(>) ;
164394782cf7SIngo Weinhold	ASFLAGS on $(<) += $(ASFLAGS) $(SUBDIRASFLAGS) ;
164494782cf7SIngo Weinhold	ASHDRS on $(<) = [ FIncludes $(SEARCH_SOURCE) $(SUBDIRHDRS) $(HDRS) ] ;
164552a38012Sejakowatz}
164652a38012Sejakowatz
164752a38012Sejakowatzactions assemble
164852a38012Sejakowatz{
1649a8687de4SAxel Dörfler	$(CC) -c "$(2)" -O2 $(ASFLAGS) -D_ASSEMBLER $(KERNEL_CCFLAGS) $(ASHDRS) -o "$(1)" ;
165052a38012Sejakowatz}
165152a38012Sejakowatz
16520931b8f9SIngo Weinhold# Overridden to allow spaces in file names.
16530931b8f9SIngo Weinholdactions Chmod1
16540931b8f9SIngo Weinhold{
16550931b8f9SIngo Weinhold	$(CHMOD) "$(MODE)" "$(1)"
16560931b8f9SIngo Weinhold}
16570931b8f9SIngo Weinhold
16586991af8cSIngo Weinhold# Overridden to allow spaces in file names.
16596991af8cSIngo Weinholdactions piecemeal together existing Clean
16606991af8cSIngo Weinhold{
16616991af8cSIngo Weinhold	$(RM) "$(>)"
16626991af8cSIngo Weinhold}
16636991af8cSIngo Weinhold
166408125d07SIngo Weinholdrule ObjectReference
166508125d07SIngo Weinhold{
166608125d07SIngo Weinhold	# ObjectReference <reference object> : <source object>
166708125d07SIngo Weinhold	# Makes <reference object> refer to the same file as <source object>.
166808125d07SIngo Weinhold	# The filenames must of course be identical.
166908125d07SIngo Weinhold	# <source object> must have already been LOCATEd.
167008125d07SIngo Weinhold
167108125d07SIngo Weinhold	local ref = $(1) ;
167208125d07SIngo Weinhold	local source = $(2) ;
167308125d07SIngo Weinhold	if $(ref) != $(source) {
16749eea4522SIngo Weinhold		Depends $(ref) : $(source) ;
167521df5945SIngo Weinhold		LOCATE on $(ref) = [ on $(source) return $(LOCATE) ] ;
167608125d07SIngo Weinhold	}
167708125d07SIngo Weinhold}
167808125d07SIngo Weinhold
167908125d07SIngo Weinholdrule ObjectReferences
168008125d07SIngo Weinhold{
168108125d07SIngo Weinhold	# ObjectReferences <source objects>
168208125d07SIngo Weinhold	# Creates local references to <source objects>, i.e. identifiers with the
168308125d07SIngo Weinhold	# current grist referring to the same files. <source objects> must have
168408125d07SIngo Weinhold	# already been LOCATEd.
168508125d07SIngo Weinhold
168608125d07SIngo Weinhold	local source ;
168708125d07SIngo Weinhold	for source in $(1) {
168808125d07SIngo Weinhold		ObjectReference [ FGristFiles $(source) ] : $(source) ;
168908125d07SIngo Weinhold	}
169008125d07SIngo Weinhold}
169108125d07SIngo Weinhold
16929fc6b2e1SIngo Weinholdrule Filter
16939fc6b2e1SIngo Weinhold{
16949fc6b2e1SIngo Weinhold	# Filter <list> : <excludes> ;
16959fc6b2e1SIngo Weinhold	# Removes all occurrences of <excludes> in <list>.
16969fc6b2e1SIngo Weinhold
16979fc6b2e1SIngo Weinhold	local list = $(1) ;
16989fc6b2e1SIngo Weinhold	local excludes = $(2) ;
16999fc6b2e1SIngo Weinhold	local newList ;
17009fc6b2e1SIngo Weinhold	local item ;
17019fc6b2e1SIngo Weinhold	for item in $(list) {
17029fc6b2e1SIngo Weinhold		local skip ;
17039fc6b2e1SIngo Weinhold		local exclude ;
17049fc6b2e1SIngo Weinhold		for exclude in $(excludes) {
17059fc6b2e1SIngo Weinhold			if $(item) = $(exclude) {
17069fc6b2e1SIngo Weinhold				skip = true ;
17079fc6b2e1SIngo Weinhold			}
17089fc6b2e1SIngo Weinhold		}
17099fc6b2e1SIngo Weinhold		if ! $(skip) {
1710dd9f8062SIngo Weinhold			newList += $(item) ;
17119fc6b2e1SIngo Weinhold		}
17129fc6b2e1SIngo Weinhold	}
17139fc6b2e1SIngo Weinhold	return $(newList) ;
17149fc6b2e1SIngo Weinhold}
17159fc6b2e1SIngo Weinhold
17160931b8f9SIngo Weinhold
171752a38012Sejakowatz## Kernel stuff!
171852a38012Sejakowatz
171952a38012Sejakowatzrule SetupKernel
172052a38012Sejakowatz{
172152a38012Sejakowatz	# Usage SetupKernel <sources_or_objects> : <extra_cc_flags>;
172294a49b21SIngo Weinhold	#
172394a49b21SIngo Weinhold	# <sources_or_objects> - Ideally sources, otherwise HDRSEARCH can not be
172494a49b21SIngo Weinhold	#                        set for the sources and the sources some header
172594a49b21SIngo Weinhold	#                        dependencies might be missing.
172652a38012Sejakowatz
172794a49b21SIngo Weinhold	local sources = [ FGristFiles $(1) ] ;
172894a49b21SIngo Weinhold	local _objs = $(sources:S=$(SUFOBJ)) ;
172952a38012Sejakowatz
173028d2a30eSDaniel Reinhold	#Setup Kernel header directories
173199b8dab3SAxel Dörfler	local public_kernel_includes = add-ons/file_system add-ons/graphics app device drivers kernel storage support ;
1732c0e501e0SIngo Weinhold	local private_kernel_includes = $(DOT) kernel libroot kernel/boot/platform/$(OBOS_BOOT_PLATFORM) ;
1733a6c008e1Sbeveloper	# Use posix headers directory
1734c0e501e0SIngo Weinhold	local headers = [ FDirName $(OBOS_TOP) headers posix ] ;
1735a6c008e1Sbeveloper	# Use public OS header directories
1736c0e501e0SIngo Weinhold	headers += [ PublicHeaders $(public_kernel_includes) ] ;
1737089a0629Sbeveloper	# Use private directories
1738c0e501e0SIngo Weinhold	headers += [ PrivateHeaders $(private_kernel_includes) ] ;
173909c5682dSIngo Weinhold	# The platform dependent headers.
1740c0e501e0SIngo Weinhold	headers += $(PLATFORM_HEADERS) ;
1741a6c008e1Sbeveloper
174294a49b21SIngo Weinhold	SourceHdrs $(sources) : $(headers) ;
174394a49b21SIngo Weinhold	UseArchObjectHeaders $(sources) : $(OBOS_ARCH) ;
174452a38012Sejakowatz
1745c0e501e0SIngo Weinhold	local object ;
1746c0e501e0SIngo Weinhold	for object in $(_objs) {
1747c0e501e0SIngo Weinhold		ObjectCcFlags $(object) : $(KERNEL_CCFLAGS) $(2) ;
1748c0e501e0SIngo Weinhold		ObjectC++Flags $(object) : $(KERNEL_C++FLAGS) $(2) ;
1749c0e501e0SIngo Weinhold	}
175052a38012Sejakowatz}
175152a38012Sejakowatz
175252a38012Sejakowatzrule KernelObjects
175352a38012Sejakowatz{
1754c0e501e0SIngo Weinhold	SetupObjectsDir ;
175552a38012Sejakowatz
175652a38012Sejakowatz	Objects $(1) ;
1757c0e501e0SIngo Weinhold
1758c0e501e0SIngo Weinhold	SetupKernel $(1) : $(2) ;
175952a38012Sejakowatz}
176052a38012Sejakowatz
176152a38012Sejakowatzrule KernelLd
176252a38012Sejakowatz{
176380721244SAxel Dörfler	# KernelLd <name> : <objs> : <linkerscript> : <args> : <gcc_off> : <config_section> ;
176452a38012Sejakowatz
1765c0e501e0SIngo Weinhold	SetupObjectsDir ;
176652a38012Sejakowatz	LINK on $(1) = ld ;
176752a38012Sejakowatz
176852a38012Sejakowatz	LINKFLAGS on $(1) = $(4) ;
176952a38012Sejakowatz	if $(3) { LINKFLAGS on $(1) += --script=$(3) ; }
177052a38012Sejakowatz
177152a38012Sejakowatz	# Remove any preset LINKLIBS
177252a38012Sejakowatz	LINKLIBS on $(1) =  ;
177352a38012Sejakowatz
177452a38012Sejakowatz	# Show that we depend on the libraries we need
17759eea4522SIngo Weinhold	LocalClean clean : $(1) ;
17769eea4522SIngo Weinhold	LocalDepends all : $(1) ;
177752a38012Sejakowatz	Depends $(1) : $(2) ;
177852a38012Sejakowatz
177952a38012Sejakowatz	if $(6) {
178052a38012Sejakowatz		for i in $(6) {
17812a83bfb4SIngo Weinhold			KernelConfigSection $(i) : elf32 : $(1) ;
178252a38012Sejakowatz		}
178352a38012Sejakowatz	}
178452a38012Sejakowatz
178552a38012Sejakowatz	MakeLocate $(1) : $(LOCATE_TARGET) ;
178652a38012Sejakowatz
178709c5682dSIngo Weinhold	# Add the platform specific static libs (libgcc.a).
178852a38012Sejakowatz	if ! $(5) {
178909c5682dSIngo Weinhold		LINKLIBS on $(1) += $(PLATFORM_LINKLIBS) ;
179052a38012Sejakowatz	}
1791c0e501e0SIngo Weinhold
1792c0e501e0SIngo Weinhold	SetupKernel $(2) ;
179352a38012Sejakowatz}
179452a38012Sejakowatz
179552a38012Sejakowatzactions KernelLd
179652a38012Sejakowatz{
17971eb18edfSIngo Weinhold	$(LINK) $(LINKFLAGS) -o "$(1)" "$(2)" $(LINKLIBS) ;
179852a38012Sejakowatz}
179952a38012Sejakowatz
1800811903d1SAxel Dörflerrule KernelAddon
1801811903d1SAxel Dörfler{
1802600203b1SAxel Dörfler	# KernelAddon <name> : <relpath> : <sources> : <static-libraries> ;
1803811903d1SAxel Dörfler
1804811903d1SAxel Dörfler	local sources = $(3) ;
1805811903d1SAxel Dörfler
1806c0e501e0SIngo Weinhold	SetupObjectsDir ;
180794a49b21SIngo Weinhold	Addon $(1) : $(2) : $(sources) ;
1808811903d1SAxel Dörfler	ObjectCcFlags $(sources) : -D_KERNEL_MODE=1 -no-fpic ;
1809df48dfedSIngo Weinhold	ObjectC++Flags $(sources) : -D_KERNEL_MODE=1 -no-fpic -fno-exceptions ;
1810811903d1SAxel Dörfler	LINKFLAGS on $(1) = [ on $(1) return $(LINKFLAGS) ] -nostdlib ;
1811600203b1SAxel Dörfler	LinkSharedOSLibs $(1) : $(4) $(OBOS_TOP)/objects/$(OBOS_ARCH).$(OBOS_VERSION)/kernel/kernel.so ;
1812811903d1SAxel Dörfler		# ToDo this has to be changed!
181394a49b21SIngo Weinhold	SetupKernel $(sources) ;
1814811903d1SAxel Dörfler}
1815811903d1SAxel Dörfler
181680721244SAxel Dörflerrule KernelMergeObject
181780721244SAxel Dörfler{
18182fbd7065SIngo Weinhold	# KernelMergeObject <name> : <sources> : <extra CFLAGS> : <other objects> ;
18192fbd7065SIngo Weinhold	# Compiles source files and merges the object files to an object file.
18202fbd7065SIngo Weinhold	# <name>: Name of the object file to create. No grist will be added.
18212fbd7065SIngo Weinhold	# <sources>: Sources to be compiled. Grist will be added.
18222fbd7065SIngo Weinhold	# <extra CFLAGS>: Additional flags for compilation.
18232fbd7065SIngo Weinhold	# <other objects>: Object files or static libraries to be merged. No grist
18242fbd7065SIngo Weinhold	#                  will be added.
18252fbd7065SIngo Weinhold	#
182680721244SAxel Dörfler
1827c0e501e0SIngo Weinhold	SetupObjectsDir ;
182880721244SAxel Dörfler
182980721244SAxel Dörfler	MakeLocateObjects $(2) ;
183080721244SAxel Dörfler	Objects $(2) ;
18312fbd7065SIngo Weinhold	MergeObjectFromObjects $(1) : $(2:S=$(SUFOBJ)) : $(4) ;
1832c0e501e0SIngo Weinhold
1833c0e501e0SIngo Weinhold	SetupKernel $(2) : $(3) ;
183480721244SAxel Dörfler}
183580721244SAxel Dörfler
183652a38012Sejakowatzrule KernelStaticLibrary
183752a38012Sejakowatz{
183852a38012Sejakowatz	# Usage KernelStaticLibrary <name> : <sources> : <extra cc flags>  ;
183952a38012Sejakowatz	# This is designed to take a set of sources and libraries and create
184052a38012Sejakowatz	# a file called lib<name>.a
184152a38012Sejakowatz
1842c0e501e0SIngo Weinhold	SetupObjectsDir ;
184352a38012Sejakowatz
184452a38012Sejakowatz	MakeLocateObjects $(2) ;
184552a38012Sejakowatz	Library $(1) : $(2) ;
1846c0e501e0SIngo Weinhold
1847c0e501e0SIngo Weinhold	SetupKernel $(2) : $(3) ;
184852a38012Sejakowatz}
184952a38012Sejakowatz
185052a38012Sejakowatzrule KernelStaticLibraryObjects
185152a38012Sejakowatz{
185252a38012Sejakowatz	# Usage KernelStaticLibrary <name> : <sources> ;
185352a38012Sejakowatz	# This is designed to take a set of sources and libraries and create
185452a38012Sejakowatz	# a file called <name>
185552a38012Sejakowatz
1856c0e501e0SIngo Weinhold	SetupObjectsDir ;
185752a38012Sejakowatz
185852a38012Sejakowatz	# Show that we depend on the libraries we need
18599eea4522SIngo Weinhold	LocalClean clean : $(1) ;
18609eea4522SIngo Weinhold	LocalDepends all : $(1) ;
186152a38012Sejakowatz	Depends $(1) : $(2) ;
186252a38012Sejakowatz
186352a38012Sejakowatz	MakeLocate $(1) : $(LOCATE_TARGET) ;
1864c0e501e0SIngo Weinhold
1865c0e501e0SIngo Weinhold	SetupKernel $(2) ;
186652a38012Sejakowatz}
186752a38012Sejakowatz
186852a38012Sejakowatzactions KernelStaticLibraryObjects
186952a38012Sejakowatz{
18700931b8f9SIngo Weinhold	ar -r "$(1)" "$(2)" ;
187152a38012Sejakowatz}
187252a38012Sejakowatz
18735dc4e1efSIngo Weinholdrule BuildPlatformMain
187452a38012Sejakowatz{
18755dc4e1efSIngo Weinhold	# Usage BuildPlatformMain <target> : <sources> ;
187652a38012Sejakowatz	SetupObjectsDir ;
18775dc4e1efSIngo Weinhold	SetupDefaultIncludes ;
187852a38012Sejakowatz
18795dc4e1efSIngo Weinhold	# Remove `-nostdinc' from CCFLAGS and C++FLAGS.
18805dc4e1efSIngo Weinhold	local oldCCFLAGS = $(CCFLAGS) ;
18815dc4e1efSIngo Weinhold	local oldC++FLAGS = $(C++FLAGS) ;
18825dc4e1efSIngo Weinhold	CCFLAGS = [ Filter $(CCFLAGS) : -nostdinc ] ;
18835dc4e1efSIngo Weinhold	C++FLAGS = [ Filter $(C++FLAGS) : -nostdinc ] ;
188452a38012Sejakowatz
188552a38012Sejakowatz	Main $(1) : $(2) ;
18865dc4e1efSIngo Weinhold
18875dc4e1efSIngo Weinhold	# Reset CCFLAGS and C++FLAGS to original values.
18885dc4e1efSIngo Weinhold	CCFLAGS = $(oldCCFLAGS) ;
18895dc4e1efSIngo Weinhold	C++FLAGS = $(oldC++FLAGS) ;
189052a38012Sejakowatz}
189152a38012Sejakowatz
18929fcaa61dSIngo Weinholdrule BuildPlatformTest
18939fcaa61dSIngo Weinhold{
18949fcaa61dSIngo Weinhold	# Usage BuildPlatformTest <target> : <sources> ;
18959fcaa61dSIngo Weinhold
18969fcaa61dSIngo Weinhold	local target = $(1) ;
18979fcaa61dSIngo Weinhold	local sources = $(2) ;
18989fcaa61dSIngo Weinhold
18999fcaa61dSIngo Weinhold	BuildPlatformMain $(target) : $(sources) ;
19009fcaa61dSIngo Weinhold	local relPath ;
19019fcaa61dSIngo Weinhold	if [ FIsPrefix src tests : $(SUBDIR_TOKENS) ] {
19029fcaa61dSIngo Weinhold		relPath = $(SUBDIR_TOKENS[3-]) ;
19039fcaa61dSIngo Weinhold	} else {
19049fcaa61dSIngo Weinhold		relPath = $(SUBDIR_TOKENS[2-]) ;
19059fcaa61dSIngo Weinhold	}
19069fcaa61dSIngo Weinhold	MakeLocate $(target) : [ FDirName $(OBOS_TEST_DIR) $(relPath) ] ;
19079fcaa61dSIngo Weinhold}
19089fcaa61dSIngo Weinhold
190952a38012Sejakowatzrule KernelConfigSection
191052a38012Sejakowatz{
191152a38012Sejakowatz	# KernelConfigSection <section> : <type> : <file>  ;
19122a83bfb4SIngo Weinhold
19132a83bfb4SIngo Weinhold	SECTION_NAMES on $(OBOS_KERNEL_CONFIG) += $(1) ;
19142a83bfb4SIngo Weinhold	SECTION_TYPES on $(OBOS_KERNEL_CONFIG) += $(2) ;
19152a83bfb4SIngo Weinhold	SECTION_FILES on $(OBOS_KERNEL_CONFIG) += $(3) ;
19162a83bfb4SIngo Weinhold
19172a83bfb4SIngo Weinhold	Depends $(OBOS_KERNEL_CONFIG) : $(3) ;
191852a38012Sejakowatz}
191952a38012Sejakowatz
192052a38012Sejakowatzrule WriteKernelConfig
192152a38012Sejakowatz{
192252a38012Sejakowatz	# usage: WriteKernelConfig <target> ;
192352a38012Sejakowatz
19249eea4522SIngo Weinhold	LocalDepends files : $(1) ;
192552a38012Sejakowatz
19262a83bfb4SIngo Weinhold	MakeLocate $(1) : $(OBOS_OBJECT_TARGET) ;
192752a38012Sejakowatz
19289eea4522SIngo Weinhold	LocalClean clean : $(1) ;
192952a38012Sejakowatz}
193052a38012Sejakowatz
19312a83bfb4SIngo Weinholdactions WriteKernelConfig bind SECTION_FILES
193252a38012Sejakowatz{
19330931b8f9SIngo Weinhold	target="$(1)"
19340931b8f9SIngo Weinhold	echo "# OpenBeOS Kernel Config File" > "$target"
19350931b8f9SIngo Weinhold	echo "# Automatically generated - do not edit!" >> "$target"
19362a83bfb4SIngo Weinhold	count=0
19372a83bfb4SIngo Weinhold	for section in "$(SECTION_NAMES)" ; do
19382a83bfb4SIngo Weinhold		count=`expr $count + 1`
19392a83bfb4SIngo Weinhold		eval section$count="$section"
19402a83bfb4SIngo Weinhold	done
19412a83bfb4SIngo Weinhold	i=1
19422a83bfb4SIngo Weinhold	for type in "$(SECTION_TYPES)" ; do
19432a83bfb4SIngo Weinhold		eval type$i="$type"
19442a83bfb4SIngo Weinhold		i=`expr $i + 1`
19452a83bfb4SIngo Weinhold	done
19462a83bfb4SIngo Weinhold	i=1
19472a83bfb4SIngo Weinhold	for file in "$(SECTION_FILES)" ; do
19482a83bfb4SIngo Weinhold		eval file$i="$file"
19492a83bfb4SIngo Weinhold		i=`expr $i + 1`
19502a83bfb4SIngo Weinhold	done
19512a83bfb4SIngo Weinhold	for i in `seq $count` ; do
19522a83bfb4SIngo Weinhold		eval section="\$section$i"
19532a83bfb4SIngo Weinhold		eval type="\$type$i"
19542a83bfb4SIngo Weinhold		eval file="\$file$i"
19550931b8f9SIngo Weinhold		echo "" >> "$target"
19562a83bfb4SIngo Weinhold		echo "["$section"]" >> "$target"
19572a83bfb4SIngo Weinhold		echo "type="$type >> "$target"
19580931b8f9SIngo Weinhold		case "$file" in
195952a38012Sejakowatz			/*) ;;
19600931b8f9SIngo Weinhold			*) file=`pwd`/"$file";;
196152a38012Sejakowatz		esac
19622a83bfb4SIngo Weinhold		echo "file="$file >> "$target"
196352a38012Sejakowatz	done
196452a38012Sejakowatz}
196552a38012Sejakowatz
196652a38012Sejakowatzrule BuildKernel
196752a38012Sejakowatz{
196852a38012Sejakowatz	# Usage BuildKernel <target> : <config_file> ;
19690c0b2cd0SIngo Weinhold	local kernel = $(1) ;
19700c0b2cd0SIngo Weinhold	local configFile = $(2) ;
19710c0b2cd0SIngo Weinhold	local bootmaker = bootmaker ;
197252a38012Sejakowatz
19739eea4522SIngo Weinhold	LocalDepends all : $(kernel) ;
19740c0b2cd0SIngo Weinhold	Depends $(kernel) : $(configFile) $(bootmaker) ;
19759eea4522SIngo Weinhold	LocalClean clean : $(kernel) ;
19760c0b2cd0SIngo Weinhold	MakeLocate $(kernel) : $(LOCATE_TARGET) ;
197752a38012Sejakowatz
19780c0b2cd0SIngo Weinhold	BOOT_MAKER on $(kernel) = $(bootmaker) ;
197952a38012Sejakowatz}
198052a38012Sejakowatz
19810c0b2cd0SIngo Weinholdactions BuildKernel bind BOOT_MAKER
198252a38012Sejakowatz{
19830c0b2cd0SIngo Weinhold	"$(BOOT_MAKER)" --strip-debug --strip-binary strip "$(2)" -o "$(1)" ;
198452a38012Sejakowatz	echo ""
198552a38012Sejakowatz	echo "Kernel linked!"
198652a38012Sejakowatz	echo ""
198752a38012Sejakowatz}
198852a38012Sejakowatz
198952a38012Sejakowatzrule KernelFloppyImage
199052a38012Sejakowatz{
199152a38012Sejakowatz	# Usage KernelFloppyImage <target> : <kernel> : <bootblock> ;
19920c0b2cd0SIngo Weinhold	local floppy = $(1) ;
19930c0b2cd0SIngo Weinhold	local kernel = $(2) ;
19940c0b2cd0SIngo Weinhold	local bootblock = $(3) ;
19950c0b2cd0SIngo Weinhold	local makeflop = makeflop ;
199652a38012Sejakowatz
19979eea4522SIngo Weinhold	LocalDepends all : $(floppy) ;
19980c0b2cd0SIngo Weinhold	Depends $(floppy) : $(kernel) $(bootblock) $(makeflop) ;
19999eea4522SIngo Weinhold	LocalClean clean : $(floppy) ;
20000c0b2cd0SIngo Weinhold	MakeLocate $(floppy) : $(OBOS_OBJECT_TARGET) ;
200152a38012Sejakowatz
20020c0b2cd0SIngo Weinhold	BOOT_BLOCK on $(floppy) = $(bootblock) ;
20030c0b2cd0SIngo Weinhold	MAKE_FLOP on $(floppy) = $(makeflop) ;
200452a38012Sejakowatz}
200552a38012Sejakowatz
200652a38012Sejakowatz# This may be a bit verbose, but I think it's useful to show what's
200752a38012Sejakowatz# going on, at least in this early stage of development.
20080c0b2cd0SIngo Weinholdactions KernelFloppyImage bind BOOT_BLOCK bind MAKE_FLOP
200952a38012Sejakowatz{
20107378dd7fSAxel Dörfler	"$(MAKE_FLOP)" "-p $(shell expr 18 \* 2 \* 512)" "$(BOOT_BLOCK)" "$(2)" "$(1)" ;
20110c0b2cd0SIngo Weinhold
201252a38012Sejakowatz	echo ""
201352a38012Sejakowatz	echo "*************************************************"
201452a38012Sejakowatz	echo "*         Kernel build completed!               *"
201552a38012Sejakowatz	echo "*    Boot image for a 1.44M floppy created      *"
201652a38012Sejakowatz	echo "*************************************************"
201752a38012Sejakowatz	echo ""
20180c0b2cd0SIngo Weinhold	echo "Floppy image is $(1)"
201952a38012Sejakowatz	echo "The following command will write it to a floppy on BeOS"
20200c0b2cd0SIngo Weinhold	echo "  dd if=$(1) of=/dev/disk/floppy/raw bs=18k"
20210c0b2cd0SIngo Weinhold	echo "Alternatively you can run"
20220c0b2cd0SIngo Weinhold	echo "  ./configure --floppy /dev/disk/floppy/raw"
20230c0b2cd0SIngo Weinhold	echo "once and build + write the image subsequently via"
20240c0b2cd0SIngo Weinhold	echo "  jam installfloppy"
202552a38012Sejakowatz	echo ""
202652a38012Sejakowatz}
202752a38012Sejakowatz
20280c0b2cd0SIngo Weinholdrule InstallFloppy
20290c0b2cd0SIngo Weinhold{
20300c0b2cd0SIngo Weinhold	# InstallFloppy <target> : <floppy>
20310c0b2cd0SIngo Weinhold	# "dd"s <floppy> to $(FLOPPY_PATH).
20320c0b2cd0SIngo Weinhold
20330c0b2cd0SIngo Weinhold	local target = $(1) ;
20340c0b2cd0SIngo Weinhold	local floppy = $(2) ;
20350c0b2cd0SIngo Weinhold
20360c0b2cd0SIngo Weinhold	NotFile $(target) ;
20370c0b2cd0SIngo Weinhold	Always $(target) ;
20380c0b2cd0SIngo Weinhold	Depends $(target) : $(floppy) ;
20390c0b2cd0SIngo Weinhold}
20400c0b2cd0SIngo Weinhold
20410c0b2cd0SIngo Weinholdactions InstallFloppy
20420c0b2cd0SIngo Weinhold{
20430c0b2cd0SIngo Weinhold	if [ -z $(FLOPPY_PATH) ] ; then
20440c0b2cd0SIngo Weinhold		echo "Can't install floppy: FLOPPY_PATH not set."
20450c0b2cd0SIngo Weinhold		echo "run: ./configure --floppy <floppy path>"
20460c0b2cd0SIngo Weinhold		echo
20470c0b2cd0SIngo Weinhold		exit 0
20480c0b2cd0SIngo Weinhold	fi
20490c0b2cd0SIngo Weinhold	dd if=$(2) of=$(FLOPPY_PATH) bs=18k
20500c0b2cd0SIngo Weinhold}
205152a38012Sejakowatz
205221df5945SIngo Weinhold#-------------------------------------------------------------------------------
205321df5945SIngo Weinhold# FreeType 2 specific rules and variables
205421df5945SIngo Weinhold#-------------------------------------------------------------------------------
205521df5945SIngo Weinhold
205621df5945SIngo WeinholdFT2_INCLUDE = [ FDirName $(OBOS_TOP) headers libs freetype2 ] ;
205721df5945SIngo WeinholdFT2_SRC     = [ FDirName $(OBOS_TOP) src libs freetype2 ] ;
205821df5945SIngo Weinhold
205921df5945SIngo WeinholdFT2_LIB     = freetype ;
206021df5945SIngo Weinhold
2061fbd28219SIngo WeinholdFT2_COMPONENTS ?= gzip       # support for gzip-compressed files.
2062fbd28219SIngo Weinhold                  autohint   # auto-hinter
2063fbd28219SIngo Weinhold                  base       # base component (public APIs)
2064fbd28219SIngo Weinhold                  bdf        # BDF font driver
2065fbd28219SIngo Weinhold                  cache      # cache sub-system
2066fbd28219SIngo Weinhold                  cff        # CFF/CEF font driver
2067fbd28219SIngo Weinhold                  cid        # Postscript CID-keyed font driver
20689ec866ccSDarkWyrm		lzw	   # LZW routines
2069fbd28219SIngo Weinhold                  pcf        # PCF font driver
2070fbd28219SIngo Weinhold                  pfr        # PFR/TrueDoc font driver
2071fbd28219SIngo Weinhold                  psaux      # Common Postscript routines module
2072fbd28219SIngo Weinhold                  pshinter   # Postscript hinter module
2073fbd28219SIngo Weinhold                  psnames    # Postscript names handling
2074fbd28219SIngo Weinhold                  raster     # Monochrome rasterizer
2075fbd28219SIngo Weinhold                  smooth     # Anti-aliased rasterizer
2076fbd28219SIngo Weinhold                  sfnt       # SFNT-based format support routines
2077fbd28219SIngo Weinhold                  truetype   # TrueType font driver
2078fbd28219SIngo Weinhold                  type1      # Postscript Type 1 font driver
2079fbd28219SIngo Weinhold                  type42     # Postscript Type 42 (embedded TrueType) driver
2080fbd28219SIngo Weinhold                  winfonts   # Windows FON/FNT font driver
2081fbd28219SIngo Weinhold                  ;
2082fbd28219SIngo Weinhold
208321df5945SIngo Weinholdrule UseFreeTypeHeaders
208421df5945SIngo Weinhold{
208521df5945SIngo Weinhold	SubDirHdrs $(FT2_INCLUDE) ;
208621df5945SIngo Weinhold}
208721df5945SIngo Weinhold
208821df5945SIngo Weinholdrule UseFreeTypeObjectHeaders
208921df5945SIngo Weinhold{
20909b60a208SIngo Weinhold	# UseFreeTypeObjectHeaders <sources> [ : <objects> ] ;
20919b60a208SIngo Weinhold	SourceHdrs $(1) : $(FT2_INCLUDE) : $(2) ;
209221df5945SIngo Weinhold}
209321df5945SIngo Weinhold
209421df5945SIngo Weinholdrule FT2_SubDir
209521df5945SIngo Weinhold{
209621df5945SIngo Weinhold	# FT2_SubDir <dir>
209721df5945SIngo Weinhold	# <dir>: Components of a directory in the original hierarchy.
209821df5945SIngo Weinhold	local dir = $(1) ;
209921df5945SIngo Weinhold	local topDir ;
210021df5945SIngo Weinhold	switch $(dir[1])
210121df5945SIngo Weinhold	{
210221df5945SIngo Weinhold		case "include"	: topDir = $(FT2_INCLUDE) ;
210321df5945SIngo Weinhold		case src		: topDir = $(FT2_SRC) ;
210421df5945SIngo Weinhold		case *			: ECHO "Unknown FreeType2 directory: " $(dir) ;
210521df5945SIngo Weinhold	}
210621df5945SIngo Weinhold	return [ FDirName $(topDir) $(dir[2-]) ] ;
210721df5945SIngo Weinhold}
210821df5945SIngo Weinhold
210921df5945SIngo Weinholdrule FT2_Library
211021df5945SIngo Weinhold{
211121df5945SIngo Weinhold	# FT2_Library <libname> : <sources>
211221df5945SIngo Weinhold	# Builds objects from sources and adds the objects to the list of objects
211321df5945SIngo Weinhold	# to be linked into the library.
211421df5945SIngo Weinhold	# <libname> The name of the library.
211521df5945SIngo Weinhold	# <sources> The sources.
211621df5945SIngo Weinhold
211721df5945SIngo Weinhold	local library = lib$(1).so ;
211821df5945SIngo Weinhold	local sources = $(2) ;
211928d2a30eSDaniel Reinhold	SetupIncludes ;
212021df5945SIngo Weinhold	SetupObjectsDir ;
212121df5945SIngo Weinhold	MakeLocateObjects $(sources) ;
212221df5945SIngo Weinhold	Objects $(sources) ;
212321df5945SIngo Weinhold	LIBRARY_OBJECTS on $(library) += [ FGristFiles $(sources:S=$(SUFOBJ)) ] ;
212421df5945SIngo Weinhold}
212521df5945SIngo Weinhold
212621df5945SIngo Weinholdrule FT2_LinkLibrary
212721df5945SIngo Weinhold{
212821df5945SIngo Weinhold	# FT2_LinkLibrary <libname>
212921df5945SIngo Weinhold	# Links the library from the objects build with FT2_LIBRARY before.
213021df5945SIngo Weinhold
213121df5945SIngo Weinhold	local library = lib$(1).so ;
213221df5945SIngo Weinhold	local objects = [ on $(library) return $(LIBRARY_OBJECTS) ] ;
213321df5945SIngo Weinhold	ObjectReferences $(objects) ;
213421df5945SIngo Weinhold	objects = [ FGristFiles $(objects) ] ;
213521df5945SIngo Weinhold	SharedLibraryFromObjects $(1) : $(objects) ;
213621df5945SIngo Weinhold}
213721df5945SIngo Weinhold
21389b7a4b5dSshatty#-------------------------------------------------------------------------------
21399b7a4b5dSshatty# Packages for OBOS alpha/beta testers
21409b7a4b5dSshatty#-------------------------------------------------------------------------------
21419b7a4b5dSshatty
21429b7a4b5dSshattyrule Copy
21439b7a4b5dSshatty{
21445c413522Sshatty	Depends $(<) : $(>) ;
21459b7a4b5dSshatty	SEARCH on $(>) = $(SEARCH_SOURCE) ;
21469b7a4b5dSshatty}
21479b7a4b5dSshatty
21489b7a4b5dSshattyactions Copy
21499b7a4b5dSshatty{
215015716fddSPhilippe Houdoin	cp -dp "$(>)" "$(<)" ;
215115716fddSPhilippe Houdoin	if [ -f "$(>)" ] ; then copyattr "$(>)" "$(<)" ; fi ;
21529b7a4b5dSshatty}
21539b7a4b5dSshatty
21549b7a4b5dSshattyrule Packages
21559b7a4b5dSshatty{
21569b7a4b5dSshatty	local packagenames = $(1) ;
21579b7a4b5dSshatty	local packagefiles = $(2) ;
21589b7a4b5dSshatty	local path = $(3) ;
21599b7a4b5dSshatty	for name in $(packagenames) {
21609b7a4b5dSshatty		Package $(name) : $(packagefiles) : $(path) ;
21619b7a4b5dSshatty    }
21629b7a4b5dSshatty}
21639b7a4b5dSshatty
21649b7a4b5dSshattyrule Package
21659b7a4b5dSshatty{
21669b7a4b5dSshatty	local packagename = $(1) ;
21679b7a4b5dSshatty    local packagefiles = $(2) ;
21689b7a4b5dSshatty	local path = $(3) ;
21699b7a4b5dSshatty
2170c06f365fSIngo Weinhold	local packagezip = $(packagename:S=.zip:G=_packages) ;
21719b7a4b5dSshatty	local packagedir = [ FDirName $(OBOS_PACKAGE_DIR) $(packagename) ] ;
21729b7a4b5dSshatty
21739b7a4b5dSshatty    local installscript = install.sh ;
2174c06f365fSIngo Weinhold	local packageinstallscript = $(installscript:G=_packages!$(packagename)) ;
21759b7a4b5dSshatty    local installzip = install.zip ;
2176c06f365fSIngo Weinhold	local packageinstallzip = $(installzip:G=_packages!$(packagename)) ;
21779b7a4b5dSshatty
2178c06f365fSIngo Weinhold    local packageobjectdir
2179c06f365fSIngo Weinhold    	= [ FDirName $(OBOS_PACKAGE_OBJECT_DIR) $(packagename) ] ;
21809b7a4b5dSshatty	local packagefiledir =  [ FDirName $(packageobjectdir) $(path) ] ;
2181c06f365fSIngo Weinhold    local packagefileinstallzip
2182c06f365fSIngo Weinhold    	= $(installzip:G=_package_objects!$(packagename)) ;
2183c06f365fSIngo Weinhold
2184c06f365fSIngo Weinhold	# add the files to the install.zip
2185c06f365fSIngo Weinhold	local packagefilegrist = [ FGrist _package_files $(packagename) $(path) ] ;
21869b7a4b5dSshatty    for file in $(packagefiles) {
21879b7a4b5dSshatty		if $(3[0]) = "boot" {
2188c06f365fSIngo Weinhold			local packagefile = $(file:G=$(packagefilegrist)) ;
21899b7a4b5dSshatty			MakeLocate $(packagefile) : $(packagefiledir) ;
21909b7a4b5dSshatty			Copy $(packagefile) : $(file) ;
21919b7a4b5dSshatty			Clean cleanPackages : $(packagefile) ;
21929b7a4b5dSshatty			PackageInstallZip $(packagefileinstallzip) : $(packagefile) ;
21939b7a4b5dSshatty		} else {
2194c06f365fSIngo Weinhold			local packagefile = $(file:G=_packages!$(packagename)) ;
21959b7a4b5dSshatty			MakeLocate $(packagefile) : $(packagedir) ;
219682bec102Sshatty			Copy $(packagefile) : [ FGristFiles $(file) ] ;
21979b7a4b5dSshatty			Clean cleanPackages : $(packagefile) ;
21989b7a4b5dSshatty			Depends $(packagezip) : $(packagefile) ;
21999b7a4b5dSshatty		}
22009b7a4b5dSshatty	}
2201c06f365fSIngo Weinhold
2202c06f365fSIngo Weinhold	# general setup for this packages -- only on first invocation
2203c06f365fSIngo Weinhold	if ! $(_setup_$(packagename)) {
2204c06f365fSIngo Weinhold		_setup_$(packagename) = true ;
2205c06f365fSIngo Weinhold
2206c06f365fSIngo Weinhold		NotFile $(packagename) ;
2207b560211bSshatty		LocalDepends packages : $(packagename) ;
2208c06f365fSIngo Weinhold
2209c06f365fSIngo Weinhold		MakeLocate $(packagezip) : $(OBOS_PACKAGE_DIR) ;
2210c06f365fSIngo Weinhold		MakeLocate $(packageinstallscript) : $(packagedir) ;
2211c06f365fSIngo Weinhold		MakeLocate $(packageinstallzip) : $(packagedir) ;
2212c06f365fSIngo Weinhold		MakeLocate $(packagefileinstallzip) : $(packageobjectdir) ;
2213c06f365fSIngo Weinhold
22149b7a4b5dSshatty		PackageInstallScript $(packageinstallscript) : $(packagedir) ;
22159b7a4b5dSshatty		LinkInstallZip $(packageinstallzip) : $(packagefileinstallzip) ;
22169b7a4b5dSshatty		Depends $(packagename) : $(packagezip) ;
2217c06f365fSIngo Weinhold		PackageZip $(packagezip) : $(packagedir)
2218c06f365fSIngo Weinhold			: $(packageinstallscript) $(packageinstallzip) ;
2219c06f365fSIngo Weinhold	}
2220c06f365fSIngo Weinhold
22219b7a4b5dSshatty}
22229b7a4b5dSshatty
22239b7a4b5dSshattyrule PackageZip
22249b7a4b5dSshatty{
2225c06f365fSIngo Weinhold	local dir = $(2:G=dir) ;
2226c06f365fSIngo Weinhold	Depends $(1) : $(dir) $(3) ;
22279b7a4b5dSshatty	Clean cleanPackages : $(1) ;
2228c06f365fSIngo Weinhold	PackageZip1 $(1) : $(dir) ;
22299b7a4b5dSshatty}
22309b7a4b5dSshatty
2231c06f365fSIngo Weinholdactions together PackageZip1 {
22328042d2a0SPhilippe Houdoin	cd "$(OBOS_PACKAGE_DIR)" ;
22338042d2a0SPhilippe Houdoin	zip -rq "$(1:BS)" "$(2:BS)" ;
22349b7a4b5dSshatty}
22359b7a4b5dSshatty
22369b7a4b5dSshattyrule PackageInstallScript
22379b7a4b5dSshatty{
22389b7a4b5dSshatty	MakeLocate $(1) : $(2) ;
22399b7a4b5dSshatty	Clean cleanPackages : $(1) ;
2240c06f365fSIngo Weinhold	PackageInstallScript1 $(1) : $(2:G=dir) ;
22419b7a4b5dSshatty}
22429b7a4b5dSshatty
2243c06f365fSIngo Weinholdactions together PackageInstallScript1
22449b7a4b5dSshatty{
224551fe1be4Sshattyecho '#!/bin/sh
224651fe1be4Sshattybase=`dirname "$0"`
22478042d2a0SPhilippe Houdoincd "$base"
224851fe1be4Sshattyif [ -n "$TTY" ]
224951fe1be4Sshattythen
225051fe1be4Sshatty    unzip -d / install.zip
225151fe1be4Sshattyelse
225251fe1be4Sshatty    response=`alert "Would you like to automatically overwrite existing files, or receive a prompt?" "Overwrite" "Prompt"`
225351fe1be4Sshatty    if [ $response == "Overwrite" ]
225451fe1be4Sshatty    then
225551fe1be4Sshatty        unzip -od / install.zip
225651fe1be4Sshatty        alert "Finished installing" "Thanks"
225751fe1be4Sshatty    else
225851fe1be4Sshatty        if [ -e /boot/beos/apps/Terminal ]
225951fe1be4Sshatty        then
226051fe1be4Sshatty            terminal=/boot/beos/apps/Terminal
226151fe1be4Sshatty        else
226251fe1be4Sshatty            terminal=`query Terminal | head -1`
226351fe1be4Sshatty        fi
22648042d2a0SPhilippe Houdoin        $terminal -t "installer" /bin/sh "$0"
226551fe1be4Sshatty    fi
22668042d2a0SPhilippe Houdoinfi' > "$(1)" ;
22678042d2a0SPhilippe Houdoin	chmod 755 "$(1)" ;
22689b7a4b5dSshatty}
22699b7a4b5dSshatty
22709b7a4b5dSshattyrule PackageInstallZip
22719b7a4b5dSshatty{
22729b7a4b5dSshatty	Depends $(1) : $(2) ;
22739b7a4b5dSshatty	Clean cleanPackages : $(1) ;
22749b7a4b5dSshatty}
22759b7a4b5dSshatty
22769b7a4b5dSshattyactions together PackageInstallZip
22779b7a4b5dSshatty{
22788042d2a0SPhilippe Houdoin	cd "$(1:P)" ;
22798042d2a0SPhilippe Houdoin	zip -rqy "$(1:BS)" boot ;
22809b7a4b5dSshatty}
22819b7a4b5dSshatty
22829b7a4b5dSshattyrule LinkInstallZip
22839b7a4b5dSshatty{
22849b7a4b5dSshatty	Depends $(1) : $(2) ;
22859b7a4b5dSshatty	Clean cleanPackages : $(1) ;
22869b7a4b5dSshatty}
22879b7a4b5dSshatty
22889b7a4b5dSshattyactions together LinkInstallZip
22899b7a4b5dSshatty{
22908042d2a0SPhilippe Houdoin	ln -sf "`pwd`/$(2)" "$(1)" ;
22919b7a4b5dSshatty}
2292e91f3ca1Sbeveloper
2293e91f3ca1Sbeveloperrule SubIncludeGPL
2294e91f3ca1Sbeveloper{
2295e91f3ca1Sbeveloper	# SubInclude rule that can be used to conditionally include GPL licensed add-ons
2296e91f3ca1Sbeveloper	if $(INCLUDE_GPL_ADDONS) = 1 {
2297e91f3ca1Sbeveloper		SubInclude $(1) ;
2298e91f3ca1Sbeveloper	}
2299e91f3ca1Sbeveloper}
2300