xref: /haiku/Jamrules (revision 11fa3682945c2af4f9200e4e3b5a749407507f82)
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
73a6c008e1Sbeveloper# We do not include any local BeOS system headers by default
74dd9f8062SIngo WeinholdCCFLAGS += -nostdinc ;
75dd9f8062SIngo WeinholdC++FLAGS += -nostdinc ;
76a6c008e1Sbeveloper
7752a38012Sejakowatz# Determine if we're building on PPC or x86
7852a38012Sejakowatz# Determine mimetype of executable
7952a38012Sejakowatz# Cross compiling can come later
8052a38012Sejakowatz
81c9882d9eSAxel DörflerTARGET_CPU ?= $(OSPLAT:L) ;
821f622a7bSAxel DörflerOBOS_VERSION ?= R1 ;
831f622a7bSAxel Dörfler
841f622a7bSAxel Dörflerswitch $(TARGET_CPU) {
851f622a7bSAxel Dörfler	case ppc :
861f622a7bSAxel Dörfler	{
8752a38012Sejakowatz		if $(METROWERKS) {
881f622a7bSAxel Dörfler			# at least parts of OpenBeOS still can be compiled with
891f622a7bSAxel Dörfler			# the Metrowerks compiler on BeOS/PPC
9052a38012Sejakowatz			OBOS_TARGET_TYPE ?= "application/x-be-executable" ;
9152a38012Sejakowatz		} else {
9252a38012Sejakowatz			OBOS_TARGET_TYPE ?= "application/x-vnd.Be-elfexecutable" ;
931f622a7bSAxel Dörfler		}
94dd22481eSAxel Dörfler		DEFINES += __POWERPC__ ;
95e29d8533SAxel Dörfler		OBOS_BOOT_PLATFORM = openfirmware ;
961f622a7bSAxel Dörfler	}
971f622a7bSAxel Dörfler	case x86 :
981f622a7bSAxel Dörfler	{
991f622a7bSAxel Dörfler		# nothing special to do here...
100aa19f785SStefano Ceccherini		DEFINES += __INTEL__ ;
101e29d8533SAxel Dörfler		OBOS_BOOT_PLATFORM = bios_ia32 ;
1021f622a7bSAxel Dörfler	}
1031f622a7bSAxel Dörfler	case * :
1041f622a7bSAxel Dörfler		Exit "Currently unsupported build platform:" $(TARGET_CPU) ;
1051f622a7bSAxel Dörfler}
1061f622a7bSAxel Dörfler
1071f622a7bSAxel Dörfler# set target specific variables
1081f622a7bSAxel Dörfler{
1091f622a7bSAxel Dörfler	#Echo "Building for" $(TARGET_CPU) ;
1101f622a7bSAxel Dörfler
1111f622a7bSAxel Dörfler	OBOS_TARGET ?= $(TARGET_CPU).$(OBOS_VERSION) ;
1121f622a7bSAxel Dörfler	OBOS_TARGET_TYPE ?= "application/x-vnd.Be-elfexecutable" ;
1131f622a7bSAxel Dörfler	OBOS_ARCH ?= $(TARGET_CPU) ;
1141f622a7bSAxel Dörfler	OBOS_TARGET_DEFINE ?= "ARCH_"$(TARGET_CPU) ;
11552a38012Sejakowatz}
11652a38012Sejakowatz
11765c62a01SIngo Weinhold# Disable warnings only if WARNINGS is set to 0
118e5dc2d93Sbeveloper# Should be enabled by default later
11996d27465SIngo Weinhold#
12065c62a01SIngo WeinholdWARNINGS ?= 1 ;
12165c62a01SIngo Weinholdif $(WARNINGS) = 1 {
122e5dc2d93Sbeveloper	# For an explanation of the different warning options, see:
123e5dc2d93Sbeveloper	# http://gcc.gnu.org/onlinedocs/gcc-2.95.3/gcc_2.html
124e5dc2d93Sbeveloper	# to get even more warnings, add:
125e5dc2d93Sbeveloper	# -Wwrite-strings  	(doesn't work well with some Be headers)
126e5dc2d93Sbeveloper	# -Wundef			(dito)
127e5dc2d93Sbeveloper	# -Wconversion		(gets you many warnings about implicit conversions)
128e5dc2d93Sbeveloper	# -W				(gets you even more warnigs)
129dd9f8062SIngo Weinhold	CCFLAGS += -Wall -Wno-multichar -Wmissing-prototypes ;
130dd9f8062SIngo Weinhold	CCFLAGS += -Wpointer-arith -Wcast-align -Wsign-compare ;
131dd9f8062SIngo Weinhold	C++FLAGS += -Wall -Wno-multichar -Wmissing-prototypes -Wno-ctor-dtor-privacy -Woverloaded-virtual ;
132dd9f8062SIngo Weinhold	C++FLAGS += -Wpointer-arith -Wcast-align -Wsign-compare ;
13398cc804cSAxel Dörfler} else {
13498cc804cSAxel Dörfler	CCFLAGS += -Wno-multichar ;
13598cc804cSAxel Dörfler	C++FLAGS += -Wno-multichar ;
136e5dc2d93Sbeveloper}
137e5dc2d93Sbeveloper
13898cc804cSAxel Dörfler# standard kernel C/C++ flags
1390ff867c2SbeveloperKERNEL_CCFLAGS ?= -Wall -Wno-multichar -Wmissing-prototypes -finline -nostdinc ;
1400ff867c2SbeveloperKERNEL_CCFLAGS += -fno-builtin -D$(OBOS_TARGET_DEFINE) ;
141ea7627e5SAxel DörflerKERNEL_CCFLAGS += -DBOCHS_DEBUG_HACK=$(BOCHS_DEBUG_HACK) -D_KERNEL_MODE ;
14298cc804cSAxel DörflerKERNEL_C++FLAGS ?= -Wall -Wno-multichar -Wmissing-prototypes -finline -nostdinc ;
14398cc804cSAxel DörflerKERNEL_C++FLAGS += -fno-builtin -fno-exceptions -fno-rtti -D$(OBOS_TARGET_DEFINE) ;
144ea7627e5SAxel DörflerKERNEL_C++FLAGS += -DBOCHS_DEBUG_HACK=$(BOCHS_DEBUG_HACK) -D_KERNEL_MODE ;
145bbb6f2d4SAxel Dörflerif $(GCC_VERSION[1]) >= 3 {
146bbb6f2d4SAxel Dörfler	KERNEL_C++FLAGS += -fno-use-cxa-atexit ;
147bbb6f2d4SAxel Dörfler}
1480ff867c2Sbeveloper
1499eea4522SIngo Weinhold# We might later want to introduce debug levels or handle the whole issue
1509eea4522SIngo Weinhold# differently. For now there's only on or off.
1519eea4522SIngo Weinhold#
15265c62a01SIngo WeinholdDEBUG ?= 0 ;
15365c62a01SIngo Weinholdif $(DEBUG) != 0 {
1549eea4522SIngo Weinhold	OPTIM ?= -O0 ;
15565c62a01SIngo Weinhold	CCFLAGS += -g [ FDefines DEBUG=$(DEBUG) ] ;
15665c62a01SIngo Weinhold	C++FLAGS += -g [ FDefines DEBUG=$(DEBUG) ] ;
15765c62a01SIngo Weinhold	KERNEL_CCFLAGS += -g [ FDefines DEBUG=$(DEBUG) ] ;
15865c62a01SIngo Weinhold	KERNEL_C++FLAGS += -g [ FDefines DEBUG=$(DEBUG) ] ;
1599eea4522SIngo Weinhold	LINKFLAGS += -g ;
1609eea4522SIngo Weinhold} else {
1619eea4522SIngo Weinhold	OPTIM ?= -O2 ;
1629eea4522SIngo Weinhold}
16396d27465SIngo Weinhold#
16496d27465SIngo Weinhold# To disable for the tests OPTIM and DEBUG are overridden, set the environment
16596d27465SIngo Weinhold# variable NO_TEST_DEBUG.
1669eea4522SIngo Weinhold
16716fa4445SIngo Weinhold# Instructs the Library rule to not make its object files temporary.
168f1e077f8SIngo Weinhold# This is needed as some objects are used in a static library and for an
16916fa4445SIngo Weinhold# executable.
17016fa4445SIngo WeinholdKEEPOBJS = true ;
17116fa4445SIngo Weinhold
1727bc56df1SIngo Weinhold# under BeOS use copyattr instead of cp
1737bc56df1SIngo Weinholdif $(OS) = BEOS
1747bc56df1SIngo Weinhold{
1757bc56df1SIngo Weinhold	CP = copyattr --data ;
1767bc56df1SIngo Weinhold}
1777bc56df1SIngo Weinhold
17852a38012Sejakowatz# If no OBOS_OBJECT_TARGET is not defined yet, use our default directory and
17952a38012Sejakowatz# include our "OBOS_TARGET" as subdirectory in there (to prevent different
18052a38012Sejakowatz# builds mixing objects from different targets).
18152a38012Sejakowatzif ! $(OBOS_OBJECT_TARGET) {
18252a38012Sejakowatz	OBOS_OBJECT_TARGET ?= [ FDirName $(OBOS_TOP) objects $(OBOS_TARGET) ] ;
18352a38012Sejakowatz}
18452a38012Sejakowatz
18552a38012Sejakowatz# If no OBOS_DISTRO_TARGET is not defined yet, use our default directory and
18652a38012Sejakowatz# include our "OBOS_TARGET" as subdirectory in there (to prevent different
18752a38012Sejakowatz# builds mixing executables from different targets).
18852a38012Sejakowatzif ! $(OBOS_DISTRO_TARGET) {
18952a38012Sejakowatz	OBOS_DISTRO_TARGET ?= [ FDirName $(OBOS_TOP) distro $(OBOS_TARGET) ] ;
19052a38012Sejakowatz}
19152a38012Sejakowatz
19252a38012Sejakowatz# Set our version number if not already set and mark it as a developer build
19352a38012Sejakowatzif ! $(OBOS_BUILD_VERSION) {
19452a38012Sejakowatz	OBOS_BUILD_VERSION ?= "1 0 0 a 1" ;
19552a38012Sejakowatz	OBOS_BUILD_DESCRIPTION ?= "Developer Build" ;
19652a38012Sejakowatz}
19752a38012Sejakowatz
19852a38012Sejakowatz# If OBOS_BUILD_VERSION is set, but OBOS_BUILD_DESCRIPTION isn't, mark it as
19952a38012Sejakowatz# an unknown build.
20052a38012Sejakowatzif ! $(OBOS_BUILD_DESCRIPTION) {
20152a38012Sejakowatz	OBOS_BUILD_DESCRIPTION ?= "Unknown Build" ;
20252a38012Sejakowatz}
20352a38012Sejakowatz
204505554b4SIngo Weinhold# Relative subdirs for distro dir
205505554b4SIngo WeinholdOBOS_ADDON_DIR  ?= [ FDirName $(OBOS_DISTRO_TARGET) beos system add-ons ] ;
2065f281ed5SejakowatzOBOS_APPS_DIR   ?= [ FDirName $(OBOS_DISTRO_TARGET) beos apps ] ;
207f06de7f3SIngo WeinholdOBOS_BIN_DIR    ?= [ FDirName $(OBOS_DISTRO_TARGET) beos bin ] ;
208505554b4SIngo WeinholdOBOS_ETC_DIR    ?= [ FDirName $(OBOS_DISTRO_TARGET) beos etc ] ;
209505554b4SIngo WeinholdOBOS_FONTS_DIR  ?= [ FDirName $(OBOS_ETC_DIR) fonts ] ;
210505554b4SIngo WeinholdOBOS_KERNEL_DIR ?= [ FDirName $(OBOS_DISTRO_TARGET) beos system ] ;
21152a38012SejakowatzOBOS_PREFS_DIR  ?= [ FDirName $(OBOS_DISTRO_TARGET) beos preferences ] ;
21252a38012SejakowatzOBOS_SERVER_DIR ?= [ FDirName $(OBOS_DISTRO_TARGET) beos system servers ] ;
21352a38012SejakowatzOBOS_SHLIB_DIR  ?= [ FDirName $(OBOS_DISTRO_TARGET) beos system lib ] ;
214e9230d05SIngo WeinholdOBOS_STLIB_DIR  ?= [ FDirName $(OBOS_DISTRO_TARGET) develop lib
215e9230d05SIngo Weinhold							  $(OBOS_ARCH) ] ;
21652a38012SejakowatzOBOS_TEST_DIR   ?= [ FDirName $(OBOS_TOP) tests ] ;
21752a38012Sejakowatz
218c06f365fSIngo WeinholdOBOS_PACKAGE_DIR ?= [ FDirName $(OBOS_TOP) packages $(OBOS_TARGET) ] ;
219c06f365fSIngo WeinholdOBOS_PACKAGE_OBJECT_DIR ?= [ FDirName $(OBOS_OBJECT_TARGET) packages ] ;
220c06f365fSIngo Weinhold
22152a38012SejakowatzOBOS_KERNEL_CONFIG = config.$(OBOS_ARCH).ini ;
22252a38012SejakowatzOBOS_KERNEL = kernel.$(OBOS_ARCH) ;
22352a38012SejakowatzOBOS_FLOPPY = floppy.$(OBOS_ARCH) ;
22452a38012Sejakowatz
22552a38012Sejakowatzrule SetupIncludes
22652a38012Sejakowatz{
227cfc7b456Sshatty	# XXX add "opengl" later
228cfc7b456Sshatty	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 ;
229a6c008e1Sbeveloper
23028d2a30eSDaniel Reinhold	# Overwrite any exiting content when changing HDRS. This rule may be invoked multiple times.
231a6c008e1Sbeveloper
232a6c008e1Sbeveloper	# Use headers directory, to allow to do things like include <posix/string.h>
23328d2a30eSDaniel Reinhold	HDRS = [ FDirName $(OBOS_TOP) headers ] ;
234a6c008e1Sbeveloper
235a6c008e1Sbeveloper	# Use posix headers directory
23628d2a30eSDaniel Reinhold	HDRS += [ FDirName $(OBOS_TOP) headers posix ] ;
237a6c008e1Sbeveloper
238a6c008e1Sbeveloper	# Use public OS header directories
23928d2a30eSDaniel Reinhold	HDRS += [ PublicHeaders $(os_includes) ] ;
240a6c008e1Sbeveloper
241a6c008e1Sbeveloper	# Used as a fallback, the R5 header directories (we should remove this as soon as possible)
24228d2a30eSDaniel Reinhold	HDRS += /boot/develop/headers/posix /boot/develop/headers/cpp ;
24309c5682dSIngo Weinhold
24409c5682dSIngo Weinhold	# The platform dependent headers.
24509c5682dSIngo Weinhold	HDRS += $(PLATFORM_HEADERS) ;
24652a38012Sejakowatz}
24752a38012Sejakowatz
248dd9f8062SIngo Weinholdrule SetupR5Includes
249dd9f8062SIngo Weinhold{
250dd9f8062SIngo Weinhold	# Unsets HDRS, so that the OBOS headers do not `shadow' the system headers.
251dd9f8062SIngo Weinhold	HDRS = ;
252dd9f8062SIngo Weinhold}
253dd9f8062SIngo Weinhold
2545dc4e1efSIngo Weinholdrule SetupDefaultIncludes
2555dc4e1efSIngo Weinhold{
2565dc4e1efSIngo Weinhold	# Resets HDRS to the default headers for the build platform.
2575dc4e1efSIngo Weinhold	HDRS = $(PLATFORM_DEFAULT_HEADERS) ;
2585dc4e1efSIngo Weinhold}
2595dc4e1efSIngo Weinhold
26052a38012Sejakowatz#-------------------------------------------------------------------------------
26152a38012Sejakowatz# Things Jam needs in order to work :)
26252a38012Sejakowatz#-------------------------------------------------------------------------------
26352a38012Sejakowatz
264c06f365fSIngo Weinhold# TODO: back-ported from jam 2.5: remove when not longer needed
265c06f365fSIngo Weinholdrule MakeLocate
266c06f365fSIngo Weinhold{
267c06f365fSIngo Weinhold	if $(>)
268c06f365fSIngo Weinhold	{
269c06f365fSIngo Weinhold	    LOCATE on $(<) = $(>) ;
270c06f365fSIngo Weinhold	    Depends $(<) : $(>[1]:G=dir) ;
271c06f365fSIngo Weinhold	    MkDir $(>[1]:G=dir) ;
272c06f365fSIngo Weinhold	}
273c06f365fSIngo Weinhold}
274c06f365fSIngo Weinhold
2758d3308d9SIngo Weinholdrule Object
2768d3308d9SIngo Weinhold{
2778d3308d9SIngo Weinhold	# This is basically the original Jambase 2.4 Object rule stripped by
2788d3308d9SIngo Weinhold	# comments. Only the final switch statement has been changed to allow
2798d3308d9SIngo Weinhold	# intermediate C++ files for Yacc and Lex.
2808d3308d9SIngo Weinhold
2818d3308d9SIngo Weinhold	LocalClean clean : $(<) ;
2828d3308d9SIngo Weinhold
2838d3308d9SIngo Weinhold	MakeLocate $(<) : $(LOCATE_TARGET) ;
2848d3308d9SIngo Weinhold	SEARCH on $(>) = $(SEARCH_SOURCE) ;
2858d3308d9SIngo Weinhold
2868d3308d9SIngo Weinhold	HDRS on $(<) = $(SEARCH_SOURCE) $(SUBDIRHDRS) $(HDRS) ;
2878d3308d9SIngo Weinhold
2888d3308d9SIngo Weinhold	HDRRULE on $(>) = HdrRule ;
2898d3308d9SIngo Weinhold	HDRSCAN on $(>) = $(HDRPATTERN) ;
2908d3308d9SIngo Weinhold	HDRSEARCH on $(>) =
2918d3308d9SIngo Weinhold		$(SEARCH_SOURCE:E) $(SUBDIRHDRS) $(HDRS) $(STDHDRS) ;
2928d3308d9SIngo Weinhold
2938d3308d9SIngo Weinhold	HDRGRIST on $(>) = $(HDRGRIST) ;
2948d3308d9SIngo Weinhold
2958d3308d9SIngo Weinhold	DEFINES on $(<) += $(DEFINES) ;
2968d3308d9SIngo Weinhold
2978d3308d9SIngo Weinhold	# if source is not .c, generate .c with specific rule
2988d3308d9SIngo Weinhold
2998d3308d9SIngo Weinhold	switch $(>:S)
3008d3308d9SIngo Weinhold	{
3018d3308d9SIngo Weinhold	    case .asm : As $(<) : $(>) ;
3028d3308d9SIngo Weinhold	    case .c :	Cc $(<) : $(>) ;
3038d3308d9SIngo Weinhold	    case .C :	C++ $(<) : $(>) ;
3048d3308d9SIngo Weinhold	    case .cc :	C++ $(<) : $(>) ;
3058d3308d9SIngo Weinhold	    case .cpp : C++ $(<) : $(>) ;
3068d3308d9SIngo Weinhold	    case .f :	Fortran $(<) : $(>) ;
3078d3308d9SIngo Weinhold	    case .l :	if [ on $(2) return $(GENERATE_C++) ] {
3088d3308d9SIngo Weinhold						C++ $(<) : $(<:S=.cpp) ;
3098d3308d9SIngo Weinhold						LexC++ $(<:S=.cpp) : $(>) ;
3108d3308d9SIngo Weinhold					} else {
3118d3308d9SIngo Weinhold						Cc $(<) : $(<:S=.c) ;
3128d3308d9SIngo Weinhold						Lex $(<:S=.c) : $(>) ;
3138d3308d9SIngo Weinhold					}
3148d3308d9SIngo Weinhold	    case .s :	As $(<) : $(>) ;
3158d3308d9SIngo Weinhold	    case .y :	if [ on $(2) return $(GENERATE_C++) ] {
3168d3308d9SIngo Weinhold						C++ $(<) : $(<:S=.cpp) ;
3178d3308d9SIngo Weinhold						Bison $(<:S=.cpp) : $(>) ;
3188d3308d9SIngo Weinhold					} else {
3198d3308d9SIngo Weinhold						Cc $(<) : $(<:S=$(YACCGEN)) ;
3208d3308d9SIngo Weinhold						Yacc $(<:S=$(YACCGEN)) : $(>) ;
3218d3308d9SIngo Weinhold					}
3228d3308d9SIngo Weinhold	    case * :	UserObject $(<) : $(>) ;
3238d3308d9SIngo Weinhold	}
3248d3308d9SIngo Weinhold}
3258d3308d9SIngo Weinhold
32652a38012Sejakowatzrule UserObject
32752a38012Sejakowatz{
32852a38012Sejakowatz	switch $(2)
32952a38012Sejakowatz	{
33052a38012Sejakowatz	case *.S    : assemble $(1) : $(2) ;
33108125d07SIngo Weinhold	case *.o    : return ;
33252a38012Sejakowatz	case *      : ECHO "unknown suffix on" $(2) ;
33352a38012Sejakowatz	}
33452a38012Sejakowatz}
33552a38012Sejakowatz
33652a38012Sejakowatz# Override the default to give "prettier" command lines.
33752a38012Sejakowatzactions Cc
33852a38012Sejakowatz{
3390931b8f9SIngo Weinhold	$(CC) -c "$(2)" $(CCFLAGS) $(CCDEFS) $(CCHDRS) -o "$(1)" ;
34052a38012Sejakowatz}
34152a38012Sejakowatz
34252a38012Sejakowatzactions C++
34352a38012Sejakowatz{
3440931b8f9SIngo Weinhold	$(C++) -c "$(2)" $(C++FLAGS) $(CCDEFS) $(CCHDRS) -o "$(1)" ;
34552a38012Sejakowatz}
34652a38012Sejakowatz
34752a38012Sejakowatz
34852a38012Sejakowatz#-------------------------------------------------------------------------------
34952a38012Sejakowatz# General High-level OBOS target rules
35052a38012Sejakowatz#-------------------------------------------------------------------------------
35152a38012Sejakowatz
3525f281ed5Sejakowatzrule App
3535f281ed5Sejakowatz{
354007eb5f2SIngo Weinhold	# App <name> : <sources> : <libraries> ;
355a6c008e1Sbeveloper	SetupIncludes ;
3565f281ed5Sejakowatz	SetupObjectsDir ;
357007eb5f2SIngo Weinhold	Main $(1) : $(2) ;
358007eb5f2SIngo Weinhold	MakeLocate $(1) : $(OBOS_APPS_DIR) ;
359007eb5f2SIngo Weinhold	LinkSharedOSLibs $(1) : $(3) ;
360007eb5f2SIngo Weinhold	LINKFLAGS on $(1) = [ on $(1) return $(LINKFLAGS) ]
361007eb5f2SIngo Weinhold						-Xlinker -soname=_APP_ ;
3625f281ed5Sejakowatz}
3635f281ed5Sejakowatz
364f06de7f3SIngo Weinholdrule BinCommand
365f06de7f3SIngo Weinhold{
366*11fa3682SJérôme Duval	# BinCommand <name> : <sources> : <libraries> : <res> ;
367a6c008e1Sbeveloper	SetupIncludes ;
368f06de7f3SIngo Weinhold	SetupObjectsDir ;
369*11fa3682SJérôme Duval	AddResources $(1) : $(4) ;
370f06de7f3SIngo Weinhold	Main $(1) : $(2) ;
371f06de7f3SIngo Weinhold	MakeLocate $(1) : $(OBOS_BIN_DIR) ;
372f06de7f3SIngo Weinhold	LinkSharedOSLibs $(1) : $(3) ;
373007eb5f2SIngo Weinhold	LINKFLAGS on $(1) = [ on $(1) return $(LINKFLAGS) ]
374007eb5f2SIngo Weinhold						-Xlinker -soname=_APP_ ;
375f06de7f3SIngo Weinhold}
376f06de7f3SIngo Weinhold
377f06de7f3SIngo Weinholdrule StdBinCommands
378f06de7f3SIngo Weinhold{
379*11fa3682SJérôme Duval	# StdBinCommands <sources> : <libs> : <res> ;
380a6c008e1Sbeveloper	SetupIncludes ;
381a6c008e1Sbeveloper	SetupObjectsDir ;
382f06de7f3SIngo Weinhold	local libs = $(2) ;
383*11fa3682SJérôme Duval	local ress = $(3) ;
3849342c27aSIngo Weinhold	local source ;
385f06de7f3SIngo Weinhold	for source in $(1)
386f06de7f3SIngo Weinhold	{
387f06de7f3SIngo Weinhold		local target = $(source:S=) ;
388f06de7f3SIngo Weinhold		target = [ FGristFiles $(target) ] ;
389a6c008e1Sbeveloper
390*11fa3682SJérôme Duval		BinCommand $(target) : $(source) : $(libs) : $(ress) ;
391f06de7f3SIngo Weinhold	}
392f06de7f3SIngo Weinhold}
393f06de7f3SIngo Weinhold
39452a38012Sejakowatzrule Preference
39552a38012Sejakowatz{
396007eb5f2SIngo Weinhold	# Preference <name> : <sources> : <libraries> ;
397a6c008e1Sbeveloper	SetupIncludes ;
39852a38012Sejakowatz	SetupObjectsDir ;
399007eb5f2SIngo Weinhold	Main $(1) : $(2) ;
400007eb5f2SIngo Weinhold	MakeLocate $(1) : $(OBOS_PREFS_DIR) ;
401007eb5f2SIngo Weinhold	LinkSharedOSLibs $(1) : $(3) ;
402007eb5f2SIngo Weinhold	LINKFLAGS on $(1) = [ on $(1) return $(LINKFLAGS) ]
403007eb5f2SIngo Weinhold						-Xlinker -soname=_APP_ ;
40452a38012Sejakowatz}
40552a38012Sejakowatz
40652a38012Sejakowatzrule Server
40752a38012Sejakowatz{
408007eb5f2SIngo Weinhold	# Server <name> : <sources> : <libraries> ;
40952a38012Sejakowatz
410a6c008e1Sbeveloper	SetupIncludes ;
41152a38012Sejakowatz	SetupObjectsDir ;
412007eb5f2SIngo Weinhold	Main $(1) : $(2) ;
413007eb5f2SIngo Weinhold	MakeLocate $(1) : $(OBOS_SERVER_DIR) ;
414007eb5f2SIngo Weinhold	LinkSharedOSLibs $(1) : $(3) ;
415007eb5f2SIngo Weinhold	LINKFLAGS on $(1) = [ on $(1) return $(LINKFLAGS) ]
416007eb5f2SIngo Weinhold						-Xlinker -soname=_APP_ ;
41752a38012Sejakowatz}
41852a38012Sejakowatz
41952a38012Sejakowatz# test pseudo targets
42052a38012SejakowatzNOTFILE obostests ;
42152a38012SejakowatzNOTFILE r5tests ;
42252a38012Sejakowatz
423d1f6c38fSTyler Dauwalderrule CommonTestLib
424d1f6c38fSTyler Dauwalder{
425c5ff4aa6STyler Dauwalder	# CommonTestLib <target> : <sources> : <obos libraries>
4269285de51STyler Dauwalder	#	: <r5 libraries> : <test libraries> : <public headers>;
427d1f6c38fSTyler Dauwalder	# Builds a unit test for both OBOS and R5 modules.
428d1f6c38fSTyler Dauwalder	# <target> The name of the target.
429d1f6c38fSTyler Dauwalder	# <sources> The list of sources.
430d1f6c38fSTyler Dauwalder	# <obos libraries> A list of link libraries for the OBOS tests (as passed
431d1f6c38fSTyler Dauwalder	# to LinkSharedOSLibs).
432d1f6c38fSTyler Dauwalder	# <r5 libraries> A list of link libraries for the R5 tests (as passed
433d1f6c38fSTyler Dauwalder	# to LinkSharedOSLibs).
4349285de51STyler Dauwalder	# <test libraries> A list of link libraries for both OBOS tests and R5 tests
4359285de51STyler Dauwalder	# that have a common name (i.e. specify libx.so and the OBOS tests will link
4369285de51STyler Dauwalder	# to libx.so and the R5 tests will link to libx_r5.so).
437d1f6c38fSTyler Dauwalder	# <public headers> A list of public header dirs (as passed to
438d1f6c38fSTyler Dauwalder	# UsePublicHeaders).
439d1f6c38fSTyler Dauwalder
440c5ff4aa6STyler Dauwalder	TestLib $(1) : $(2) : [ FDirName $(OBOS_TEST_DIR) unittester lib ] : $(3) $(5) : $(6) ;
441c5ff4aa6STyler Dauwalder	R5TestLib $(1) : $(2) : [ FDirName $(OBOS_TEST_DIR) unittester_r5 lib ] : $(4) [ R5SharedLibraryNames $(5) ] ;
442d1f6c38fSTyler Dauwalder}
443d1f6c38fSTyler Dauwalder
444d1f6c38fSTyler Dauwalderrule TestLib
445d1f6c38fSTyler Dauwalder{
446d1f6c38fSTyler Dauwalder	# TestLib <target> : <sources> : <dest> : <libraries> : <public headers>
447d1f6c38fSTyler Dauwalder	# Builds a unit test library for an OBOS module.
448d1f6c38fSTyler Dauwalder	# <target> The name of the target.
449d1f6c38fSTyler Dauwalder	# <sources> The list of sources.
450d1f6c38fSTyler Dauwalder	# <dest> The directory for the target (as passed to FDirName).
451d1f6c38fSTyler Dauwalder	# <libraries> A list of link libraries (as passed to LinkSharedOSLibs).
452d1f6c38fSTyler Dauwalder	# <public headers> A list of public header dirs (as passed to
453d1f6c38fSTyler Dauwalder	# UsePublicHeaders).
454d1f6c38fSTyler Dauwalder
455d1f6c38fSTyler Dauwalder	local target = $(1) ;
456d1f6c38fSTyler Dauwalder	local sources = $(2) ;
457d1f6c38fSTyler Dauwalder	local dest = $(3) ;
458d1f6c38fSTyler Dauwalder	local libraries = $(4) ;
459d1f6c38fSTyler Dauwalder	local headerDirs = $(5) ;
4609342c27aSIngo Weinhold	local objects = [ FGristFiles $(sources:S=$(SUFOBJ)) ] ;
461d1f6c38fSTyler Dauwalder
4629342c27aSIngo Weinhold	# Our Main replacement.
4639342c27aSIngo Weinhold	MainFromObjects $(target) : $(objects) ;
4649342c27aSIngo Weinhold	TestObjects $(sources) : $(headerDirs) ;
465d1f6c38fSTyler Dauwalder
466d1f6c38fSTyler Dauwalder	MakeLocate $(target) : $(dest) ;
4670d1cdd94SIngo Weinhold	Depends $(target) : libcppunit.so ;
4680d1cdd94SIngo Weinhold	Depends obostests : $(target) ;
469d1f6c38fSTyler Dauwalder	LinkSharedOSLibs $(target) : libcppunit.so $(libraries) ;
470d1f6c38fSTyler Dauwalder	LINKFLAGS on $(target) = $(LINKFLAGS) -nostart -Xlinker -soname=\"$(target)\" ;
471d1f6c38fSTyler Dauwalder}
472d1f6c38fSTyler Dauwalder
473d1f6c38fSTyler Dauwalderrule R5TestLib
474d1f6c38fSTyler Dauwalder{
475c5ff4aa6STyler Dauwalder	# R5TestLib <target> : <sources> : <dest> : <libraries>
476d1f6c38fSTyler Dauwalder	# Builds a unit test for an R5 module. "_r5" is appended to the object
477d1f6c38fSTyler Dauwalder	# and the target name.
478d1f6c38fSTyler Dauwalder	# <target> The name of the target.
479d1f6c38fSTyler Dauwalder	# <sources> The list of sources.
480d1f6c38fSTyler Dauwalder	# <dest> The directory for the target (as passed to FDirName).
481d1f6c38fSTyler Dauwalder	# <libraries> A list of link libraries (as passed to LinkSharedOSLibs).
482d1f6c38fSTyler Dauwalder
483d1f6c38fSTyler Dauwalder	local target = $(1:B)_r5$(1:S) ;
484d1f6c38fSTyler Dauwalder	local sources = $(2) ;
485c5ff4aa6STyler Dauwalder	local dest = $(3) ;
486d1f6c38fSTyler Dauwalder	local libraries = $(4) ;
487d1f6c38fSTyler Dauwalder	local objects = [ R5ObjectNames $(sources) ] ;
488d1f6c38fSTyler Dauwalder
489d1f6c38fSTyler Dauwalder	# Our Main replacement.
490d1f6c38fSTyler Dauwalder	MainFromObjects $(target) : $(objects) ;
4919342c27aSIngo Weinhold	TestObjects $(sources) : : true ;
492d1f6c38fSTyler Dauwalder
493d1f6c38fSTyler Dauwalder	MakeLocate $(target) : $(dest) ;
4940d1cdd94SIngo Weinhold	Depends $(target) : libcppunit.so ;
4950d1cdd94SIngo Weinhold	Depends r5tests : $(target) ;
496d1f6c38fSTyler Dauwalder	LinkSharedOSLibs $(target) : libcppunit.so $(libraries) ;
497d1f6c38fSTyler Dauwalder	LINKFLAGS on $(target) = $(LINKFLAGS) -nostart -Xlinker -soname=\"$(target)\" ;
498d1f6c38fSTyler Dauwalder}
499d1f6c38fSTyler Dauwalder
50052a38012Sejakowatzrule CommonUnitTest
50152a38012Sejakowatz{
50252a38012Sejakowatz	# CommonUnitTest <target> : <sources> : <dest> : <obos libraries>
50352a38012Sejakowatz	#	: <r5 libraries> : <public headers>;
50452a38012Sejakowatz	# Builds a unit test for both OBOS and R5 modules.
50552a38012Sejakowatz	# <target> The name of the target.
50652a38012Sejakowatz	# <sources> The list of sources.
50752a38012Sejakowatz	# <dest> The directory for the target (as passed to FDirName).
50852a38012Sejakowatz	# <obos libraries> A list of link libraries for the OBOS tests (as passed
50952a38012Sejakowatz	# to LinkSharedOSLibs).
51052a38012Sejakowatz	# <r5 libraries> A list of link libraries for the R5 tests (as passed
51152a38012Sejakowatz	# to LinkSharedOSLibs).
51252a38012Sejakowatz	# <public headers> A list of public header dirs (as passed to
51352a38012Sejakowatz	# UsePublicHeaders).
51452a38012Sejakowatz
51552a38012Sejakowatz	UnitTest $(1) : $(2) : $(3) : $(4) : $(6) ;
51652a38012Sejakowatz	R5UnitTest $(1) : $(2) : $(3) : $(5) ;
51752a38012Sejakowatz}
51852a38012Sejakowatz
51952a38012Sejakowatzrule UnitTest
52052a38012Sejakowatz{
52152a38012Sejakowatz	# UnitTest <target> : <sources> : <dest> : <libraries> : <public headers>
52252a38012Sejakowatz	# Builds a unit test for an OBOS module.
52352a38012Sejakowatz	# <target> The name of the target.
52452a38012Sejakowatz	# <sources> The list of sources.
52552a38012Sejakowatz	# <dest> The directory for the target (as passed to FDirName).
52652a38012Sejakowatz	# <libraries> A list of link libraries (as passed to LinkSharedOSLibs).
52752a38012Sejakowatz	# <public headers> A list of public header dirs (as passed to
52852a38012Sejakowatz	# UsePublicHeaders).
52952a38012Sejakowatz
53052a38012Sejakowatz	local target = $(1) ;
53152a38012Sejakowatz	local sources = $(2) ;
53252a38012Sejakowatz	local dest = $(3) ;
53352a38012Sejakowatz	local libraries = $(4) ;
53452a38012Sejakowatz	local headerDirs = $(5) ;
5359342c27aSIngo Weinhold	local objects = [ FGristFiles $(sources:S=$(SUFOBJ)) ] ;
53652a38012Sejakowatz
5379342c27aSIngo Weinhold	# Our Main replacement.
5389342c27aSIngo Weinhold	MainFromObjects $(target) : $(objects) ;
5399342c27aSIngo Weinhold	TestObjects $(sources) : $(headerDirs) ;
5403b9eae39SIngo Weinhold
54152a38012Sejakowatz	MakeLocate $(target) : [ FDirName $(OBOS_TEST_DIR) $(dest) ] ;
5429eea4522SIngo Weinhold	Depends $(target) : libcppunit.so ;
5439eea4522SIngo Weinhold	Depends obostests : $(target) ;
54452a38012Sejakowatz	LinkSharedOSLibs $(target) : libcppunit.so $(libraries) ;
54552a38012Sejakowatz}
54652a38012Sejakowatz
54752a38012Sejakowatzrule R5UnitTest
54852a38012Sejakowatz{
54952a38012Sejakowatz	# R5UnitTest <target> : <sources> : <dest> : <libraries>
55052a38012Sejakowatz	# Builds a unit test for an R5 module. "_r5" is appended to the object
55152a38012Sejakowatz	# and the target name.
55252a38012Sejakowatz	# <target> The name of the target.
55352a38012Sejakowatz	# <sources> The list of sources.
55452a38012Sejakowatz	# <dest> The directory for the target (as passed to FDirName).
55552a38012Sejakowatz	# <libraries> A list of link libraries (as passed to LinkSharedOSLibs).
55652a38012Sejakowatz
55752a38012Sejakowatz	local target = $(1)_r5 ;
55852a38012Sejakowatz	local sources = $(2) ;
55952a38012Sejakowatz	local dest = $(3) ;
56052a38012Sejakowatz	local libraries = $(4) ;
56152a38012Sejakowatz	local objects = [ R5ObjectNames $(sources) ] ;
56252a38012Sejakowatz
56352a38012Sejakowatz	# Our Main replacement.
56452a38012Sejakowatz	MainFromObjects $(target) : $(objects) ;
5659342c27aSIngo Weinhold	TestObjects $(sources) : : true ;
56652a38012Sejakowatz
56752a38012Sejakowatz	MakeLocate $(target) : [ FDirName $(OBOS_TEST_DIR) $(dest) ] ;
5689eea4522SIngo Weinhold	Depends $(target) : libcppunit.so ;
5699eea4522SIngo Weinhold	Depends r5tests : $(target) ;
57052a38012Sejakowatz	LinkSharedOSLibs $(target) : libcppunit.so $(libraries) ;
57152a38012Sejakowatz}
57252a38012Sejakowatz
57352a38012Sejakowatzrule R5ObjectNames
57452a38012Sejakowatz{
57552a38012Sejakowatz	# R5ObjectNames <sources> ;
57652a38012Sejakowatz	# Returns a list of gristed object names given a list of source file names.
57752a38012Sejakowatz	# Moreover each object names gets "_r5" inserted before the object suffix.
57852a38012Sejakowatz	local objects = $(1:S=)_r5 ;
57952a38012Sejakowatz	return [ FGristFiles $(objects:S=$(SUFOBJ)) ] ;
58052a38012Sejakowatz}
58152a38012Sejakowatz
5829342c27aSIngo Weinholdrule R5Objects
5839342c27aSIngo Weinhold{
5849342c27aSIngo Weinhold	# R5Objects <sources>
585dd9f8062SIngo Weinhold	# Similar to Objects, but appends "_r5" to the object file names and
586dd9f8062SIngo Weinhold	# removes `-nostdinc' from the CC and C++ flags to enable system headers.
5879342c27aSIngo Weinhold	# <sources> The source files.
5889342c27aSIngo Weinhold
589dd9f8062SIngo Weinhold	# Remove `-nostdinc' from CCFLAGS and C++FLAGS.
590dd9f8062SIngo Weinhold	local oldCCFLAGS = $(CCFLAGS) ;
591dd9f8062SIngo Weinhold	local oldC++FLAGS = $(C++FLAGS) ;
592dd9f8062SIngo Weinhold	CCFLAGS = [ Filter $(CCFLAGS) : -nostdinc ] ;
593dd9f8062SIngo Weinhold	C++FLAGS = [ Filter $(C++FLAGS) : -nostdinc ] ;
594dd9f8062SIngo Weinhold
5959342c27aSIngo Weinhold	local sources = $(1) ;
5969342c27aSIngo Weinhold	local source ;
5979342c27aSIngo Weinhold	for source in [ FGristFiles $(sources) ]
5989342c27aSIngo Weinhold	{
5999342c27aSIngo Weinhold		local object = [ R5ObjectNames $(source) ] ;
6009342c27aSIngo Weinhold		Object $(object) : $(source) ;
6019342c27aSIngo Weinhold		LocalDepends obj : $(object) ;
6029342c27aSIngo Weinhold	}
603dd9f8062SIngo Weinhold
604dd9f8062SIngo Weinhold	# Reset CCFLAGS and C++FLAGS to original values.
605dd9f8062SIngo Weinhold	CCFLAGS = $(oldCCFLAGS) ;
606dd9f8062SIngo Weinhold	C++FLAGS = $(oldC++FLAGS) ;
6079342c27aSIngo Weinhold}
6089342c27aSIngo Weinhold
6099342c27aSIngo Weinholdrule TestObjects
6109342c27aSIngo Weinhold{
6119342c27aSIngo Weinhold	# TestLib <sources> : <public headers> : <r5>
6129342c27aSIngo Weinhold	# Compiles objects for tests.
6139342c27aSIngo Weinhold	# <sources> The list of sources.
6149342c27aSIngo Weinhold	# <public headers> A list of public header dirs (as passed to
6159342c27aSIngo Weinhold	# UsePublicHeaders).
6169342c27aSIngo Weinhold	# <r5> If set, "_r5" is appended to the object file names and
6179342c27aSIngo Weinhold	# <public headers> is ignored. Furthermore the pre-processor macro
6189342c27aSIngo Weinhold	# TEST_R5 is defined, TEST_OBOS otherwise.
6199342c27aSIngo Weinhold
6209342c27aSIngo Weinhold	local sources = $(1) ;
6219342c27aSIngo Weinhold	local headerDirs = $(2) ;
6229342c27aSIngo Weinhold	local r5 = $(3) ;
6239342c27aSIngo Weinhold	local objects ;
6249342c27aSIngo Weinhold
6259342c27aSIngo Weinhold	# Turn optimization off.
62696d27465SIngo Weinhold	if ! $(NO_TEST_DEBUG) {
6279342c27aSIngo Weinhold		local optim = $(OPTIM) ;
6289342c27aSIngo Weinhold		OPTIM = ;
62996d27465SIngo Weinhold	}
6309342c27aSIngo Weinhold
6319342c27aSIngo Weinhold	SetupObjectsDir ;
6329342c27aSIngo Weinhold
6339342c27aSIngo Weinhold	# compile
6349342c27aSIngo Weinhold	if $(r5) {
635dd9f8062SIngo Weinhold		SetupR5Includes ;
6369342c27aSIngo Weinhold		objects = [ R5ObjectNames $(sources) ] ;
6379342c27aSIngo Weinhold		R5Objects $(sources) ;
6389342c27aSIngo Weinhold	} else {
639dd9f8062SIngo Weinhold		SetupIncludes ;
6409342c27aSIngo Weinhold		objects = [ FGristFiles $(sources:S=$(SUFOBJ)) ] ;
6419342c27aSIngo Weinhold		Objects $(sources) ;
6429342c27aSIngo Weinhold	}
6439342c27aSIngo Weinhold
6449342c27aSIngo Weinhold	# set headers/defines
6459b60a208SIngo Weinhold	UseCppUnitObjectHeaders $(sources) : $(objects) ;
6469342c27aSIngo Weinhold	if $(r5) {
647728b5725SIngo Weinhold		ObjectsDefines $(objects) : TEST_R5 ;
6489342c27aSIngo Weinhold	} else {
6499b60a208SIngo Weinhold		UsePublicObjectHeaders $(sources) : $(headerDirs) : $(objects) ;
650728b5725SIngo Weinhold		ObjectsDefines $(objects) : TEST_OBOS ;
6519342c27aSIngo Weinhold	}
6529342c27aSIngo Weinhold
65396d27465SIngo Weinhold	if ! $(NO_TEST_DEBUG) {
6549342c27aSIngo Weinhold		# Turn debugging on. That is usually desired for test code.
6559342c27aSIngo Weinhold		ObjectCcFlags $(objects) : "-g" ;
6569342c27aSIngo Weinhold		ObjectC++Flags $(objects) : "-g" ;
6579342c27aSIngo Weinhold
6589342c27aSIngo Weinhold		# Turn optimization on again.
6599342c27aSIngo Weinhold		OPTIM = $(optim) ;
6609342c27aSIngo Weinhold	}
66196d27465SIngo Weinhold}
6629342c27aSIngo Weinhold
6639285de51STyler Dauwalderrule R5SharedLibraryNames
6649285de51STyler Dauwalder{
6659285de51STyler Dauwalder	# R5SharedLibraryNames <sources> ;
6669285de51STyler Dauwalder	# Returns a list of shared library names given a list of file names. NO
6679285de51STyler Dauwalder	# GRISTING IS PERFORMED :-) However, each library names gets "_r5" inserted
6689285de51STyler Dauwalder	# before the shared lib suffix.
6699285de51STyler Dauwalder	return $(1:S=)_r5.so ;
6709285de51STyler Dauwalder}
6719285de51STyler Dauwalder
6729fc6b2e1SIngo Weinholdrule SimpleTest
6739fc6b2e1SIngo Weinhold{
6749fc6b2e1SIngo Weinhold	# UnitTest <target> : <sources> : <libraries>
6759fc6b2e1SIngo Weinhold	# Builds a unit test for an OBOS module.
6769fc6b2e1SIngo Weinhold	# <target> The name of the target.
6779fc6b2e1SIngo Weinhold	# <sources> The list of sources.
6789fc6b2e1SIngo Weinhold	# <dest> The directory for the target (as passed to FDirName).
6799fc6b2e1SIngo Weinhold	# <libraries> A list of link libraries (as passed to LinkSharedOSLibs).
6809fc6b2e1SIngo Weinhold	# <public headers> A list of public header dirs (as passed to
6819fc6b2e1SIngo Weinhold	# UsePublicHeaders).
6829fc6b2e1SIngo Weinhold
6839fc6b2e1SIngo Weinhold	local target = $(1) ;
6849fc6b2e1SIngo Weinhold	local sources = $(2) ;
6859fc6b2e1SIngo Weinhold	local libraries = $(3) ;
6869fc6b2e1SIngo Weinhold	local relPath = [ FRelPath src tests : $(SUBDIR_TOKENS) ] ;
6879fc6b2e1SIngo Weinhold
6889fc6b2e1SIngo Weinhold	# Turn optimization off.
68996d27465SIngo Weinhold	if ! $(NO_TEST_DEBUG) {
6909fc6b2e1SIngo Weinhold		local optim = $(OPTIM) ;
6919fc6b2e1SIngo Weinhold		OPTIM = ;
69296d27465SIngo Weinhold	}
6939fc6b2e1SIngo Weinhold
694a6c008e1Sbeveloper	SetupIncludes ;
6959fc6b2e1SIngo Weinhold	SetupObjectsDir ;
6969fc6b2e1SIngo Weinhold	MakeLocateObjects $(sources) ;
6979fc6b2e1SIngo Weinhold	Main $(target) : $(sources) ;
6989fc6b2e1SIngo Weinhold	MakeLocate $(target) : [ FDirName $(OBOS_TEST_DIR) $(relPath) ] ;
6999eea4522SIngo Weinhold	Depends obostests : $(target) ;
7009fc6b2e1SIngo Weinhold	LinkSharedOSLibs $(target) : $(libraries) ;
701728b5725SIngo Weinhold	ObjectsDefines $(sources) : TEST_OBOS ;
70296d27465SIngo Weinhold	if ! $(NO_TEST_DEBUG) {
7039fc6b2e1SIngo Weinhold		# Turn debugging on. That is usually desired for test code.
7049fc6b2e1SIngo Weinhold		ObjectCcFlags $(sources) : "-g" ;
7059fc6b2e1SIngo Weinhold		ObjectC++Flags $(sources) : "-g" ;
7069fc6b2e1SIngo Weinhold
7079fc6b2e1SIngo Weinhold		# Turn optimization on again.
7089fc6b2e1SIngo Weinhold		OPTIM = $(optim) ;
7099fc6b2e1SIngo Weinhold	}
71096d27465SIngo Weinhold}
7119fc6b2e1SIngo Weinhold
71252a38012Sejakowatzrule Addon
71352a38012Sejakowatz{
71483b3b0dfSIngo Weinhold	# Addon <name> : <relpath> : <sources> : <is executable> : <libraries> ;
7157a384fdeSIngo Weinhold	# <name>: Name of the add-on.
7167a384fdeSIngo Weinhold	# <relpath>: Path where the add-on shall live relative to the add-on dir.
7177a384fdeSIngo Weinhold	# <sources>: Source files.
71883b3b0dfSIngo Weinhold	# <is executable>: true, if the target shall be executable as well.
71983b3b0dfSIngo Weinhold	# <libraries>: Libraries to be linked against.
7207a384fdeSIngo Weinhold
7217a384fdeSIngo Weinhold	local isExecutable = $(4) ;
72252a38012Sejakowatz
723a6c008e1Sbeveloper	SetupIncludes ;
72452a38012Sejakowatz	SetupObjectsDir ;
72552a38012Sejakowatz	Main $(1) : $(3) ;
72652a38012Sejakowatz
72752a38012Sejakowatz	# Create output dir path for addon
72852a38012Sejakowatz	local targetdir;
72952a38012Sejakowatz	targetdir = [ FDirName $(OBOS_ADDON_DIR) $(2) ] ;
73052a38012Sejakowatz
73152a38012Sejakowatz	MakeLocate $(1) : $(targetdir) ;
7327a384fdeSIngo Weinhold
7337a384fdeSIngo Weinhold	local linkFlags = -Xlinker -soname=\"$(1)\" ;
7347a384fdeSIngo Weinhold	if $(isExecutable) != true {
7357a384fdeSIngo Weinhold		linkFlags = -nostart $(linkFlags) ;
7367a384fdeSIngo Weinhold	}
7377a384fdeSIngo Weinhold	LINKFLAGS on $(1) = [ on $(1) return $(LINKFLAGS) ] $(linkFlags) ;
73883b3b0dfSIngo Weinhold	LinkSharedOSLibs $(1) : $(5) ;
739af28904fSIngo Weinhold}
740af28904fSIngo Weinhold
74158efc9d8SIngo Weinholdrule R5KernelAddon
742af28904fSIngo Weinhold{
74358efc9d8SIngo Weinhold	# R5KernelAddon <name> : <relpath> : <sources> ;
744af28904fSIngo Weinhold
745af28904fSIngo Weinhold	local sources = $(3) ;
746af28904fSIngo Weinhold
747af28904fSIngo Weinhold	Addon $(1) : $(2) : $(3) ;
748af28904fSIngo Weinhold	ObjectCcFlags $(sources) : -D_KERNEL_MODE=1 -no-fpic ;
749af28904fSIngo Weinhold	ObjectC++Flags $(sources) : -D_KERNEL_MODE=1 -no-fpic
750af28904fSIngo Weinhold								-fno-exceptions -fno-rtti ;
7519eea4522SIngo Weinhold	LINKFLAGS on $(1) = [ on $(1) return $(LINKFLAGS) ] -nostdlib ;
752af28904fSIngo Weinhold	LinkSharedOSLibs $(1) : /boot/develop/lib/x86/_KERNEL_ ;
75352a38012Sejakowatz}
75452a38012Sejakowatz
7554fb5add0SMatthew Wilberrule Translator
7564fb5add0SMatthew Wilber{
757007eb5f2SIngo Weinhold	# Translator <name> : <sources> : <libraries> ;
758a6c008e1Sbeveloper	SetupIncludes ;
7594fb5add0SMatthew Wilber	SetupObjectsDir ;
7604fb5add0SMatthew Wilber	Main $(1) : $(2) ;
761007eb5f2SIngo Weinhold	LinkSharedOSLibs $(1) : $(3) ;
7624fb5add0SMatthew Wilber
7634fb5add0SMatthew Wilber	# Create output dir path for translator
7644fb5add0SMatthew Wilber	local targetdir;
765d5b07cf2Sshatty	targetdir = [ FDirName $(OBOS_ADDON_DIR) Translators ] ;
7664fb5add0SMatthew Wilber	MakeLocate $(1) : $(targetdir) ;
7674fb5add0SMatthew Wilber}
7684fb5add0SMatthew Wilber
76952a38012Sejakowatzrule MakeLocateObjects
77052a38012Sejakowatz{
77121df5945SIngo Weinhold	# MakeLocateObjects <sources_or_objects> ;
77252a38012Sejakowatz
77321df5945SIngo Weinhold	local _objs = [ FGristFiles $(1:S=$(SUFOBJ)) ] ;
77452a38012Sejakowatz
77552a38012Sejakowatz	for o in $(_objs)
77652a38012Sejakowatz	{
77752a38012Sejakowatz		local dir = $(o:D) ;
77852a38012Sejakowatz		if $(dir) {
77952a38012Sejakowatz			MakeLocate $(o) : [ FDirName $(LOCATE_TARGET) $(dir) ] ;
78052a38012Sejakowatz		} else {
78152a38012Sejakowatz			MakeLocate $(o) : $(LOCATE_TARGET) ;
78252a38012Sejakowatz		}
78352a38012Sejakowatz	}
78452a38012Sejakowatz}
78552a38012Sejakowatz
78652a38012Sejakowatzrule StaticLibrary
78752a38012Sejakowatz{
788e9230d05SIngo Weinhold	# StaticLibrary <name> : <sources> [ : <target dir> ] ;
789e9230d05SIngo Weinhold	# Creates a static library from sources.
790e9230d05SIngo Weinhold	# <name>: Basename of the library, without leading "lib" and trailing ".a".
79160c9c40fSIngo Weinhold	#         Grist is allowed -- it will be re-prepended after constructing
79260c9c40fSIngo Weinhold	#         the complete library name.
793e9230d05SIngo Weinhold	# <source>: List of source files.
794e9230d05SIngo Weinhold	# <target dir>: Directory into which the library shall be placed. Defaults
79560c9c40fSIngo Weinhold	#               to the objects directory for this subdir. If
79660c9c40fSIngo Weinhold	#               STATIC_LIBRARY_DIR is supplied (the literal string)
79760c9c40fSIngo Weinhold	#               the standard directory for static libs is used, otherwise
79860c9c40fSIngo Weinhold	#               the parameter is interpreted as directory path.
799e9230d05SIngo Weinhold	#
80060c9c40fSIngo Weinhold	local lib = lib$(1:B)$(SUFLIB) ;
80160c9c40fSIngo Weinhold	lib = $(lib:G=$(1:G)) ;
802a6c008e1Sbeveloper	SetupIncludes ;
80352a38012Sejakowatz	SetupObjectsDir ;
80452a38012Sejakowatz	MakeLocateObjects $(2) ;
805e9230d05SIngo Weinhold	Library $(lib) : $(2) ;
806e9230d05SIngo Weinhold	local targetDir = $(3) ;
80760c9c40fSIngo Weinhold	if $(targetDir) {
80860c9c40fSIngo Weinhold		if $(targetDir) = STATIC_LIBRARY_DIR {
809e9230d05SIngo Weinhold			targetDir = $(OBOS_STLIB_DIR) ;
810e9230d05SIngo Weinhold		}
811e9230d05SIngo Weinhold		MakeLocate $(lib) : $(targetDir) ;
81260c9c40fSIngo Weinhold	} else {
81360c9c40fSIngo Weinhold		# nothing to do, since the Library rule already located the library
81460c9c40fSIngo Weinhold		# in $(LOCATE_TARGET)
81560c9c40fSIngo Weinhold	}
816f1e077f8SIngo Weinhold
817f1e077f8SIngo Weinhold	# If KEEPOBJS is set, Library doesn't make the library depend on
818f1e077f8SIngo Weinhold	# `lib'.
819f1e077f8SIngo Weinhold	if $(KEEPOBJS) {
820f1e077f8SIngo Weinhold		LocalDepends lib : $(lib) ;
821f1e077f8SIngo Weinhold	}
82252a38012Sejakowatz}
82352a38012Sejakowatz
824dbf96817SIngo Weinholdrule R5KernelStaticLibrary
825dbf96817SIngo Weinhold{
826dbf96817SIngo Weinhold	# R5KernelStaticLibrary <name> : <sources> ;
827dbf96817SIngo Weinhold
828f1e077f8SIngo Weinhold	local lib = lib$(1)$(SUFLIB) ;
829dbf96817SIngo Weinhold	local sources = $(2) ;
830dbf96817SIngo Weinhold
831dbf96817SIngo Weinhold	SetupIncludes ;
832dbf96817SIngo Weinhold	SetupObjectsDir ;
833dbf96817SIngo Weinhold	MakeLocateObjects $(sources) ;
834dbf96817SIngo Weinhold	Library $(lib) : $(sources) ;
835dbf96817SIngo Weinhold	ObjectCcFlags $(sources) : -D_KERNEL_MODE=1 -no-fpic ;
836dbf96817SIngo Weinhold	ObjectC++Flags $(sources) : -D_KERNEL_MODE=1 -no-fpic
837dbf96817SIngo Weinhold								-fno-exceptions -fno-rtti ;
838dbf96817SIngo Weinhold}
839dbf96817SIngo Weinhold
84080721244SAxel Dörflerrule MergeObjectFromObjects
84180721244SAxel Dörfler{
8422fbd7065SIngo Weinhold	# MergeObjectFromObjects <name> : <objects> : <other objects> ;
8432fbd7065SIngo Weinhold	# Merges object files to an object file.
8442fbd7065SIngo Weinhold	# <name>: Name of the object file to create. No grist will be added.
8452fbd7065SIngo Weinhold	# <objects>: Object files to be merged. Grist will be added.
8462fbd7065SIngo Weinhold	# <other objects>: Object files or static libraries to be merged. No grist
8472fbd7065SIngo Weinhold	#                  will be added.
8482fbd7065SIngo Weinhold	#
849c8aa252aSIngo Weinhold	local objects = [ FGristFiles $(2) ] ;
85080721244SAxel Dörfler	MakeLocate $(1) : $(LOCATE_TARGET) ;
851c8aa252aSIngo Weinhold	Depends $(1) : $(objects) ;
8522fbd7065SIngo Weinhold	Depends $(1) : $(3) ;
85380721244SAxel Dörfler	LINK on $(1) = ld ;
8542fbd7065SIngo Weinhold	MergeObjectFromObjects1 $(1) : $(objects) $(3) ;
85580721244SAxel Dörfler}
85680721244SAxel Dörfler
85754b7cbe1SIngo Weinholdactions MergeObjectFromObjects1
85880721244SAxel Dörfler{
85980721244SAxel Dörfler	$(LINK) -r $(2) -o $(1) ;
86080721244SAxel Dörfler}
86180721244SAxel Dörfler
86280721244SAxel Dörflerrule MergeObject
86380721244SAxel Dörfler{
8642fbd7065SIngo Weinhold	# MergeObject <name> : <sources> : <other objects> ;
8652fbd7065SIngo Weinhold	# Compiles source files and merges the object files to an object file.
8662fbd7065SIngo Weinhold	# <name>: Name of the object file to create. No grist will be added.
8672fbd7065SIngo Weinhold	# <sources>: Sources to be compiled. Grist will be added.
8682fbd7065SIngo Weinhold	# <other objects>: Object files or static libraries to be merged. No grist
8692fbd7065SIngo Weinhold	#                  will be added.
8702fbd7065SIngo Weinhold	#
87180721244SAxel Dörfler	SetupIncludes ;
87280721244SAxel Dörfler	SetupObjectsDir ;
87380721244SAxel Dörfler	MakeLocateObjects $(2) ;
87480721244SAxel Dörfler	Objects $(2) ;
8752fbd7065SIngo Weinhold	MergeObjectFromObjects $(1) : $(2:S=$(SUFOBJ)) : $(3) ;
87680721244SAxel Dörfler}
87780721244SAxel Dörfler
87821df5945SIngo Weinholdrule SharedLibraryFromObjects
87952a38012Sejakowatz{
8808d3308d9SIngo Weinhold	# SharedLibraryFromObjects <name> : <objects> : <libraries> ;
88160c9c40fSIngo Weinhold	local _lib = lib$(1:B).so ;
88260c9c40fSIngo Weinhold	_lib = $(_lib:G=$(1:G)) ;
88321df5945SIngo Weinhold	MainFromObjects $(_lib) : $(2) ;
88452a38012Sejakowatz	MakeLocate $(_lib) : $(OBOS_SHLIB_DIR) ;
8859eea4522SIngo Weinhold	LINKFLAGS on $(_lib) = [ on $(_lib) return $(LINKFLAGS) ]
8869eea4522SIngo Weinhold						   -nostart -Xlinker -soname=\"$(_lib)\" ;
8878d3308d9SIngo Weinhold	LinkSharedOSLibs $(_lib) : $(3) ;
88852a38012Sejakowatz}
88952a38012Sejakowatz
89021df5945SIngo Weinholdrule SharedLibrary
89121df5945SIngo Weinhold{
8928d3308d9SIngo Weinhold	# SharedLibrary <name> : <sources> : <libraries> ;
893a6c008e1Sbeveloper	SetupIncludes ;
89421df5945SIngo Weinhold	SetupObjectsDir ;
89521df5945SIngo Weinhold	MakeLocateObjects $(2) ;
89621df5945SIngo Weinhold	Objects $(2) ;
8978d3308d9SIngo Weinhold	SharedLibraryFromObjects $(1) : $(2:S=$(SUFOBJ)) : $(3) ;
89821df5945SIngo Weinhold}
89921df5945SIngo Weinhold
90052a38012Sejakowatzrule LinkSharedOSLibs
90152a38012Sejakowatz{
90252a38012Sejakowatz	# LinkSharedOSLibs <name> : <libs> ;
90352a38012Sejakowatz	# Valid elements for <libs> are e.g. "be" or "libopenbeos.so" or
9044236d490SIngo Weinhold	# "/boot/.../libfoo.so". If the basename starts with "lib" or the thingy
9054236d490SIngo Weinhold	# has a dirname or grist, it is added to the NEEDLIBS variable (i.e. the
9064236d490SIngo Weinhold	# file will be bound!), otherwise it is prefixed "-l" and added to
907a8cd0719SIngo Weinhold	# LINKLIBS. If you want to specify a target that isn't a library and
908a8cd0719SIngo Weinhold	# also has neither grist nor a dirname, you can prepend "<nogrist>" as
909a8cd0719SIngo Weinhold	# grist; it will be stripped by this rule.
91052a38012Sejakowatz
91152a38012Sejakowatz	for i in $(>)
91252a38012Sejakowatz	{
9134236d490SIngo Weinhold		local isfile = ;
9144236d490SIngo Weinhold		if $(i:D) || $(i:G) {
9154236d490SIngo Weinhold			isfile = true ;
916a8cd0719SIngo Weinhold			if $(i:G) = <nogrist> {
917a8cd0719SIngo Weinhold				i = $(i:G=) ;
918a8cd0719SIngo Weinhold			}
9194236d490SIngo Weinhold		} else {
92052a38012Sejakowatz			switch $(i:B)
92152a38012Sejakowatz			{
922007eb5f2SIngo Weinhold				# XXX: _APP_ and _KERNEL_ should not be needed for ELF.
923f7901247SPhilippe Houdoin				case _APP_ : isfile = true ;
924f7901247SPhilippe Houdoin				case _KERNEL_ : isfile = true ;
9254236d490SIngo Weinhold				case lib*	: isfile = true ;
9264236d490SIngo Weinhold				case *	: isfile = ;
9274236d490SIngo Weinhold			}
928b8baf385SIngo Weinhold			if ! $(isfile) && ( $(i:S) = .so || $(i:S) = .a ) {
929b8baf385SIngo Weinhold				isfile = true ;
930b8baf385SIngo Weinhold			}
9314236d490SIngo Weinhold		}
9324236d490SIngo Weinhold		if $(isfile) {
9339eea4522SIngo Weinhold			NEEDLIBS on $(1) = [ on $(1) return $(NEEDLIBS) ] $(i) ;
9349eea4522SIngo Weinhold			Depends $(1) : $(i) ;
9354236d490SIngo Weinhold		} else {
9369eea4522SIngo Weinhold			LINKLIBS on $(1) = [ on $(1) return $(LINKLIBS) ] -l$(i) ;
93752a38012Sejakowatz		}
93852a38012Sejakowatz	}
93952a38012Sejakowatz}
94052a38012Sejakowatz
94152a38012Sejakowatzrule LinkStaticOSLibs
94252a38012Sejakowatz{
94352a38012Sejakowatz	# LinkStaticOSLibs <name> : <libs> ;
94452a38012Sejakowatz
94552a38012Sejakowatz	for i in $(>)
94652a38012Sejakowatz	{
94752a38012Sejakowatz		LINKLIBS on $(<) = $(LINKLIBS) -l $(i) ;
94852a38012Sejakowatz	}
94952a38012Sejakowatz}
95052a38012Sejakowatz
95152a38012Sejakowatzrule AddResources
95252a38012Sejakowatz{
95352a38012Sejakowatz	# AddResources <name> : <resourcefiles> ;
95452a38012Sejakowatz
9558d3308d9SIngo Weinhold	local resfiles = [ FGristFiles $(2) ] ;
9568d3308d9SIngo Weinhold	SEARCH on $(resfiles) += $(SEARCH_SOURCE) ;
9578d3308d9SIngo Weinhold
9588d3308d9SIngo Weinhold	for file in $(resfiles) {
9598d3308d9SIngo Weinhold		if $(file:S) = .rdef {
9608d3308d9SIngo Weinhold			local rdef = $(file) ;
9618d3308d9SIngo Weinhold			file = $(rdef:S=.rsrc) ;
9628d3308d9SIngo Weinhold			ResComp $(file) : $(rdef) ;
9638d3308d9SIngo Weinhold		}
9648d3308d9SIngo Weinhold		RESFILES on $(1) += $(file) ;
9658d3308d9SIngo Weinhold	}
9668d3308d9SIngo Weinhold}
9678d3308d9SIngo Weinhold
9688d3308d9SIngo Weinholdrule ResComp
9698d3308d9SIngo Weinhold{
9708d3308d9SIngo Weinhold	# ResComp <resource file> : <rdef file> ;
9718d3308d9SIngo Weinhold	#
9728d3308d9SIngo Weinhold	# <resource file> and <rdef file> must be gristed.
9738d3308d9SIngo Weinhold
9748d3308d9SIngo Weinhold	SetupObjectsDir ;
9758d3308d9SIngo Weinhold
9769fc6b2e1SIngo Weinhold	SEARCH on $(2) += $(SEARCH_SOURCE) ;
9778d3308d9SIngo Weinhold	MakeLocate $(1) : $(LOCATE_TARGET) ;
9788d3308d9SIngo Weinhold	Depends $(1) : $(2) rc ;
9798d3308d9SIngo Weinhold	LocalClean clean : $(1) ;
9808d3308d9SIngo Weinhold	ResComp1 $(1) : rc $(2) ;
9818d3308d9SIngo Weinhold}
9828d3308d9SIngo Weinhold
9838d3308d9SIngo Weinholdactions ResComp1
9848d3308d9SIngo Weinhold{
9856af76074SIngo Weinhold	$(2[1]) -o $(1) $(2[2-])
98652a38012Sejakowatz}
98752a38012Sejakowatz
988728b5725SIngo Weinholdrule ObjectsDefines
989728b5725SIngo Weinhold{
990728b5725SIngo Weinhold	# Like ObjectDefines, but allows multiple files to be supplied
991728b5725SIngo Weinhold	local file ;
992728b5725SIngo Weinhold	for file in $(1) {
993728b5725SIngo Weinhold		ObjectDefines $(file) : $(2) ;
994728b5725SIngo Weinhold	}
995728b5725SIngo Weinhold}
996728b5725SIngo Weinhold
9979b60a208SIngo Weinholdrule SourceHdrs
9989b60a208SIngo Weinhold{
9999b60a208SIngo Weinhold	# SourceHdrs <sources> : <headers> [ : <gristed objects> ] ;
10009b60a208SIngo Weinhold	#
10019b60a208SIngo Weinhold	# Is a wrapper for ObjectHdrs, that passes <sources> and <headers> or,
10029b60a208SIngo Weinhold	# if supplied <objects> and <headers>, and also adjusts HDRSEARCH (not
10039b60a208SIngo Weinhold	# done by ObjectHdrs).
10049b60a208SIngo Weinhold
10059b60a208SIngo Weinhold	local sources = [ FGristFiles $(1) ] ;
10069b60a208SIngo Weinhold	local headers = $(2) ;
10079b60a208SIngo Weinhold	local objects = $(3) ;
10089b60a208SIngo Weinhold
1009728b5725SIngo Weinhold	local file ;
10109b60a208SIngo Weinhold	if $(objects) {
1011728b5725SIngo Weinhold		for file in $(objects) {
1012728b5725SIngo Weinhold			ObjectHdrs $(file) : $(headers) ;
1013728b5725SIngo Weinhold		}
10149b60a208SIngo Weinhold	} else {
1015728b5725SIngo Weinhold		for file in $(sources) {
1016728b5725SIngo Weinhold			ObjectHdrs $(file) : $(headers) ;
1017728b5725SIngo Weinhold		}
10189b60a208SIngo Weinhold	}
10199b60a208SIngo Weinhold
10209b60a208SIngo Weinhold	# Also add the header search dirs to HDRSEARCH. Note, that these dirs
10219b60a208SIngo Weinhold	# will be listed after the STDHDRS (if any), but that's better than not
10229b60a208SIngo Weinhold	# being listed at all.
10239b60a208SIngo Weinhold	HDRSEARCH on $(sources) += $(headers) ;
10249b60a208SIngo Weinhold}
10259b60a208SIngo Weinhold
10267d7f280eSIngo Weinholdrule PublicHeaders
102752a38012Sejakowatz{
10287d7f280eSIngo Weinhold	# PublicHeaders <group list>
102952a38012Sejakowatz	#
10307d7f280eSIngo Weinhold	# Returns the directory names for the public header dirs identified by
10317d7f280eSIngo Weinhold	# <group list>.
103252a38012Sejakowatz
103352a38012Sejakowatz	local list = $(1) ;
1034b005dbe3SAxel Dörfler	local dirs = [ FDirName $(OBOS_TOP) headers os ] ;
1035b005dbe3SAxel Dörfler
103652a38012Sejakowatz	for i in $(list) {
10377d7f280eSIngo Weinhold		dirs += [ FDirName $(OBOS_TOP) headers os $(i) ] ;
10387d7f280eSIngo Weinhold	}
10397d7f280eSIngo Weinhold	return $(dirs) ;
104052a38012Sejakowatz}
104152a38012Sejakowatz
10427d7f280eSIngo Weinholdrule PrivateHeaders
10437d7f280eSIngo Weinhold{
10447d7f280eSIngo Weinhold	# PrivateHeaders <group list>
10457d7f280eSIngo Weinhold	#
10467d7f280eSIngo Weinhold	# Returns the directory names for the private header dirs identified by
10477d7f280eSIngo Weinhold	# <group list>.
10487d7f280eSIngo Weinhold
10497d7f280eSIngo Weinhold	local list = $(1) ;
10507d7f280eSIngo Weinhold	local dirs ;
10517d7f280eSIngo Weinhold	for i in $(list) {
10527d7f280eSIngo Weinhold		dirs += [ FDirName $(OBOS_TOP) headers private $(i) ] ;
10537d7f280eSIngo Weinhold	}
10547d7f280eSIngo Weinhold	return $(dirs) ;
10557d7f280eSIngo Weinhold}
10567d7f280eSIngo Weinhold
10570f434a0aSDarkWyrmrule LibraryHeaders
10580f434a0aSDarkWyrm{
10590f434a0aSDarkWyrm	# LibraryHeaders <group list>
10600f434a0aSDarkWyrm	#
10610f434a0aSDarkWyrm	# Returns the directory names for the library header dirs identified by
10620f434a0aSDarkWyrm	# <group list>.
10630f434a0aSDarkWyrm
10640f434a0aSDarkWyrm	local list = $(1) ;
10650f434a0aSDarkWyrm	local dirs ;
10660f434a0aSDarkWyrm	for i in $(list) {
10670f434a0aSDarkWyrm		dirs += [ FDirName $(OBOS_TOP) headers libs $(i) ] ;
10680f434a0aSDarkWyrm	}
10690f434a0aSDarkWyrm	return $(dirs) ;
10700f434a0aSDarkWyrm}
10710f434a0aSDarkWyrm
10727d7f280eSIngo Weinholdrule ArchHeaders
10737d7f280eSIngo Weinhold{
10747d7f280eSIngo Weinhold	# usage: ArchHeaders <arch> ;
10757d7f280eSIngo Weinhold	#
10767d7f280eSIngo Weinhold	# <arch> specifies the architecture (e.g. x86).
10777d7f280eSIngo Weinhold
10787d7f280eSIngo Weinhold	return [ FDirName $(OBOS_TOP) headers private kernel arch $(1) ] ;
10797d7f280eSIngo Weinhold}
10807d7f280eSIngo Weinhold
10817d7f280eSIngo Weinholdrule UsePublicHeaders
10827d7f280eSIngo Weinhold{
1083966528dcSIngo Weinhold	# UsePublicHeaders <group list> ;
1084966528dcSIngo Weinhold	#
1085966528dcSIngo Weinhold	# Adds the public C header dirs given by <group list> to the header search
1086966528dcSIngo Weinhold	# dirs of the subdirectory.
1087966528dcSIngo Weinhold	# NOTE: This rule must be invoked *before* the rule that builds the
1088966528dcSIngo Weinhold	# objects.
1089966528dcSIngo Weinhold
1090966528dcSIngo Weinhold	UseHeaders [ PublicHeaders $(1) ] ;
10917d7f280eSIngo Weinhold}
10927d7f280eSIngo Weinhold
10937d7f280eSIngo Weinholdrule UsePublicObjectHeaders
10947d7f280eSIngo Weinhold{
10959b60a208SIngo Weinhold	# UsePublicObjectHeaders <sources> : <group list> [ : <objects> ] ;
10967d7f280eSIngo Weinhold	#
10977d7f280eSIngo Weinhold	# Adds the public C header dirs given by <group list> to the header search
10989b60a208SIngo Weinhold	# dirs of either the object targets of <sources> or if supplied to
10999b60a208SIngo Weinhold	# <objects>. Also adjusts HDRSEARCH of <sources>.
11007d7f280eSIngo Weinhold	# NOTE: This rule must be invoked *after* the rule that builds the objects.
11017d7f280eSIngo Weinhold
11029b60a208SIngo Weinhold	SourceHdrs $(1) : [ PublicHeaders $(2) ] : $(3) ;
110352a38012Sejakowatz}
110452a38012Sejakowatz
110552a38012Sejakowatzrule UsePrivateHeaders
110652a38012Sejakowatz{
11077d7f280eSIngo Weinhold	# UsePrivateHeaders <group list> ;
110852a38012Sejakowatz	#
110952a38012Sejakowatz	# Adds the private C header dirs given by <group list> to the header search
11107d7f280eSIngo Weinhold	# dirs of the subdirectory.
11117d7f280eSIngo Weinhold	# NOTE: This rule must be invoked *before* the rule that builds the objects.
111252a38012Sejakowatz
11137d7f280eSIngo Weinhold	UseHeaders [ PrivateHeaders $(1) ] ;
111452a38012Sejakowatz}
111552a38012Sejakowatz
11167d7f280eSIngo Weinholdrule UsePrivateObjectHeaders
11177d7f280eSIngo Weinhold{
11189b60a208SIngo Weinhold	# UsePrivateObjectHeaders <sources> : <group list> [ : <objects> ] ;
11197d7f280eSIngo Weinhold	#
11207d7f280eSIngo Weinhold	# Adds the private C header dirs given by <group list> to the header search
11219b60a208SIngo Weinhold	# dirs of either the object targets of <sources> or if supplied to
11229b60a208SIngo Weinhold	# <objects>. Also adjusts HDRSEARCH of <sources>.
11237d7f280eSIngo Weinhold	# NOTE: This rule must be invoked *after* the rule that builds the objects.
11247d7f280eSIngo Weinhold
11259b60a208SIngo Weinhold	SourceHdrs $(1) : [ PrivateHeaders $(2) ] : $(3) ;
112652a38012Sejakowatz}
112752a38012Sejakowatz
112852a38012Sejakowatzrule UseHeaders
112952a38012Sejakowatz{
11307d7f280eSIngo Weinhold	# UseHeaders <headers> ;
113152a38012Sejakowatz	#
113252a38012Sejakowatz	# Adds the C header dirs <headers> to the header search
11337d7f280eSIngo Weinhold	# dirs of the subdirectory.
11347d7f280eSIngo Weinhold	# NOTE: This rule must be invoked *before* the rule that builds the objects.
113552a38012Sejakowatz
11367d7f280eSIngo Weinhold	local header ;
11377d7f280eSIngo Weinhold	for header in $(1) {
113852a38012Sejakowatz		SubDirHdrs $(header) ;
113952a38012Sejakowatz	}
114052a38012Sejakowatz}
114152a38012Sejakowatz
114252a38012Sejakowatzrule UseCppUnitHeaders
114352a38012Sejakowatz{
11447d7f280eSIngo Weinhold	SubDirHdrs [ FDirName $(OBOS_TOP) headers tools cppunit ] ;
114552a38012Sejakowatz}
114652a38012Sejakowatz
1147be5af1baSIngo Weinholdrule UseCppUnitObjectHeaders
1148be5af1baSIngo Weinhold{
11499b60a208SIngo Weinhold	# UseCppUnitObjectHeaders <sources> [ : <objects> ] ;
11509b60a208SIngo Weinhold	SourceHdrs $(1) : [ FDirName $(OBOS_TOP) headers tools cppunit ] : $(2) ;
1151be5af1baSIngo Weinhold}
1152be5af1baSIngo Weinhold
115352a38012Sejakowatzrule UseArchHeaders
115452a38012Sejakowatz{
11557d7f280eSIngo Weinhold	# usage: UseArchHeaders <arch> ;
11567d7f280eSIngo Weinhold	#
115752a38012Sejakowatz	# <arch> specifies the architecture (e.g. x86).
11587d7f280eSIngo Weinhold	# NOTE: This rule must be invoked *before* the rule that builds the objects.
11597d7f280eSIngo Weinhold
11607d7f280eSIngo Weinhold	local headers = [ ArchHeaders $(1) ] ;
116152a38012Sejakowatz	local opt = -D$(OBOS_TARGET_DEFINE) ;
1162c633961aSIngo Weinhold
116352a38012Sejakowatz	SubDirCcFlags $(opt)  ;
116452a38012Sejakowatz	SubDirC++Flags $(opt)  ;
1165089a0629Sbeveloper	HDRS += $(headers) ;
1166c633961aSIngo Weinhold}
1167c633961aSIngo Weinhold
11687d7f280eSIngo Weinholdrule UseArchObjectHeaders
11697d7f280eSIngo Weinhold{
11709b60a208SIngo Weinhold	# usage: UseArchObjectHeaders <sources> : <arch> : [ <objects> ] ;
11717d7f280eSIngo Weinhold	#
11727d7f280eSIngo Weinhold	# <arch> specifies the architecture (e.g. x86).
11737d7f280eSIngo Weinhold	# <sources_or_objects> Source or object files.
11747d7f280eSIngo Weinhold	# NOTE: This rule must be invoked *after* the rule that builds the objects.
11757d7f280eSIngo Weinhold
11769b60a208SIngo Weinhold	local sources = $(1) ;
11777d7f280eSIngo Weinhold	local headers = [ ArchHeaders $(2) ] ;
11789b60a208SIngo Weinhold	local objects = $(3) ;
11799b60a208SIngo Weinhold	local targets ;
11809b60a208SIngo Weinhold	if $(objects) {
11819b60a208SIngo Weinhold		targets = $(objects) ;
11829b60a208SIngo Weinhold	} else {
11839b60a208SIngo Weinhold		targets = $(sources) ;
11849b60a208SIngo Weinhold	}
11857d7f280eSIngo Weinhold	local opt = -D$(OBOS_TARGET_DEFINE) ;
11867d7f280eSIngo Weinhold
11877d7f280eSIngo Weinhold	ObjectCcFlags $(targets) : $(opt)  ;
11887d7f280eSIngo Weinhold	ObjectC++Flags $(targets) : $(opt)  ;
11899b60a208SIngo Weinhold	SourceHdrs $(sources) : $(headers) : $(objects) ;
119052a38012Sejakowatz}
119152a38012Sejakowatz
1192d25a77b4SIngo Weinholdrule UsePosixHeaders
1193d25a77b4SIngo Weinhold{
1194a6c008e1Sbeveloper	# XXX changed to do nothing
1195d25a77b4SIngo Weinhold}
1196d25a77b4SIngo Weinhold
1197d25a77b4SIngo Weinholdrule UsePosixObjectHeaders
1198d25a77b4SIngo Weinhold{
11999b60a208SIngo Weinhold	# UsePosixObjectHeaders <sources> [ : <objects> ] ;
1200d25a77b4SIngo Weinhold	#
1201d25a77b4SIngo Weinhold	# Adds the POSIX header dir to the header search
12029b60a208SIngo Weinhold	# dirs of either the object targets of <sources> or if supplied to
12039b60a208SIngo Weinhold	# <objects>. Also adjusts HDRSEARCH of <sources>.
1204d25a77b4SIngo Weinhold	# NOTE: This rule must be invoked *after* the rule that builds the objects.
1205d25a77b4SIngo Weinhold
12069b60a208SIngo Weinhold	SourceHdrs $(1) : [ FDirName $(OBOS_TOP) headers posix ] : $(2) ;
1207d25a77b4SIngo Weinhold}
1208d25a77b4SIngo Weinhold
12090f434a0aSDarkWyrmrule UseLibraryHeaders
12100f434a0aSDarkWyrm{
12110f434a0aSDarkWyrm	# UseLibraryHeaders <group list> ;
12120f434a0aSDarkWyrm	#
12130f434a0aSDarkWyrm	# Adds the library header dirs given by <group list> to the header search
12140f434a0aSDarkWyrm	# dirs of the subdirectory.
12150f434a0aSDarkWyrm	# NOTE: This rule must be invoked *before* the rule that builds the objects.
12160f434a0aSDarkWyrm
12170f434a0aSDarkWyrm	UseHeaders [ LibraryHeaders $(1) ] ;
12180f434a0aSDarkWyrm}
12190f434a0aSDarkWyrm
12203b9eae39SIngo Weinholdrule SplitPath
12213b9eae39SIngo Weinhold{
12223b9eae39SIngo Weinhold	# SplitPath <path> ;
12233b9eae39SIngo Weinhold	# Decomposes a path into its components.
12243b9eae39SIngo Weinhold	local path = $(1:G=) ;
12253b9eae39SIngo Weinhold	local components ;
12268c27f58dSIngo Weinhold	# $(path:D) for "/" is "/". Therefore the second condition.
12278c27f58dSIngo Weinhold	while $(path:D) && $(path:D) != $(path)
12283b9eae39SIngo Weinhold	{
12293b9eae39SIngo Weinhold		# Note: $(path:B) returns "." for "..", but $(path:D=) is fine.
12303b9eae39SIngo Weinhold		components = $(path:D=) $(components) ;
12313b9eae39SIngo Weinhold		path = $(path:D) ;
12323b9eae39SIngo Weinhold	}
12333b9eae39SIngo Weinhold	components = $(path) $(components) ;
12343b9eae39SIngo Weinhold	return $(components) ;
12353b9eae39SIngo Weinhold}
12363b9eae39SIngo Weinhold
12379fc6b2e1SIngo Weinholdrule PrependObjectHdrs
12389fc6b2e1SIngo Weinhold{
12399fc6b2e1SIngo Weinhold	# PrependObjectHdrs <objects_or_sources> : <dirs> ;
12409fc6b2e1SIngo Weinhold	# Prepends <dirs> to the list of header search dirs of the objects
12419fc6b2e1SIngo Weinhold	# specified by <objects_or_sources>. The HDRS variable will not be
12429fc6b2e1SIngo Weinhold	# changed, only CCHDRS.
12439fc6b2e1SIngo Weinhold	# Note: A subsequent ObjectHdrs invocation will therefore undo the
12449fc6b2e1SIngo Weinhold	# effect of this rule.
12459fc6b2e1SIngo Weinhold	# NOTE: This is a hack.
12469fc6b2e1SIngo Weinhold
12479fc6b2e1SIngo Weinhold	local objects = [ FGristFiles $(1:S=$(SUFOBJ)) ] ;
12489fc6b2e1SIngo Weinhold	local dirs = $(2) ;
12499fc6b2e1SIngo Weinhold	for object in $(objects) {
12509fc6b2e1SIngo Weinhold		# Don't change HDRS to avoid screwing up the header scanning.
12519fc6b2e1SIngo Weinhold		PREPENDED_HDRS on $(object)
12529fc6b2e1SIngo Weinhold			= $(dirs) [ on $(object) return $(PREPENDED_HDRS) ] ;
12539fc6b2e1SIngo Weinhold		CCHDRS on $(object)
12549fc6b2e1SIngo Weinhold			= [ FIncludes [ on $(object) return $(PREPENDED_HDRS) $(HDRS) ] ] ;
12559fc6b2e1SIngo Weinhold	}
12569fc6b2e1SIngo Weinhold}
12579fc6b2e1SIngo Weinhold
12583b9eae39SIngo Weinholdrule SymLink
12593b9eae39SIngo Weinhold{
12607669b69fSIngo Weinhold	# SymLink <target> : <source> : <makeDefaultDependencies> ;
12613b9eae39SIngo Weinhold	# Links <target> to <source>.
12623b9eae39SIngo Weinhold	# <source> is the exact link contents. No binding is done.
12637669b69fSIngo Weinhold	# <makeDefaultDependencies> If true, <target> will be made a dependency
12647669b69fSIngo Weinhold	# of the `all' pseudo target, i.e. it will be made by default, and removed
12657669b69fSIngo Weinhold	# on `jam clean'.
12667669b69fSIngo Weinhold
12677669b69fSIngo Weinhold	local target = $(1) ;
12687669b69fSIngo Weinhold	local source = $(2) ;
12697669b69fSIngo Weinhold	local makeDefaultDependencies = $(3) ;
12707669b69fSIngo Weinhold	if ! $(makeDefaultDependencies) {
12717669b69fSIngo Weinhold		makeDefaultDependencies = true ;
12727669b69fSIngo Weinhold	}
12737669b69fSIngo Weinhold	LINKCONTENTS on $(target) = $(source) ;
12747669b69fSIngo Weinhold	SymLink1 $(target) ;
12757669b69fSIngo Weinhold	if $(makeDefaultDependencies) = true {
12767669b69fSIngo Weinhold		LocalDepends files : $(target) ;
12777669b69fSIngo Weinhold		LocalClean clean : $(target) ;
12787669b69fSIngo Weinhold	}
12793b9eae39SIngo Weinhold}
12803b9eae39SIngo Weinhold
12813b9eae39SIngo Weinholdactions SymLink1
12823b9eae39SIngo Weinhold{
12830931b8f9SIngo Weinhold	$(RM) "$(1)" && $(LN) -s "$(LINKCONTENTS)" "$(1)"
12840931b8f9SIngo Weinhold}
12850931b8f9SIngo Weinhold
12860931b8f9SIngo Weinholdrule RelSymLink
12870931b8f9SIngo Weinhold{
12887669b69fSIngo Weinhold	# RelSymLink <link> : <link target> : <makeDefaultDependencies> ;
12890931b8f9SIngo Weinhold	# Creates a relative symbolic link from <link> to <link target>.
12900931b8f9SIngo Weinhold	# <link> and <link target> can be usual targets. They may have a grist
12910931b8f9SIngo Weinhold	# and don't need to have any dirname. Their LOCATE variables are used to
12920931b8f9SIngo Weinhold	# find their locations.
12937669b69fSIngo Weinhold	# <makeDefaultDependencies> If true (which is the default), <link> will be
12947669b69fSIngo Weinhold	# made a dependency of the `files' pseudo target, i.e. it will be made by
12957669b69fSIngo Weinhold	# default, and removed on `jam clean'.
12960931b8f9SIngo Weinhold
12970931b8f9SIngo Weinhold	local target = $(1) ;
12980931b8f9SIngo Weinhold	local source = $(2) ;
12997669b69fSIngo Weinhold	local makeDefaultDependencies = $(3) ;
13000931b8f9SIngo Weinhold	local targetDir = [ on $(target) FDirName $(LOCATE[1]) $(target:D) ] ;
13010931b8f9SIngo Weinhold	local sourceDir = [ on $(source) FDirName $(LOCATE[1]) $(source:D) ] ;
13020931b8f9SIngo Weinhold	local sourcePath = $(source:G=) ;
13030931b8f9SIngo Weinhold	sourcePath = $(sourcePath:D=$(sourceDir)) ;
13040931b8f9SIngo Weinhold	local targetDirComponents = [ SplitPath $(targetDir) ] ;
13050931b8f9SIngo Weinhold	local sourceComponents = [ SplitPath $(sourcePath) ] ;
13060931b8f9SIngo Weinhold
13070931b8f9SIngo Weinhold	SymLink $(target)
13087669b69fSIngo Weinhold		: [ FRelPath $(targetDirComponents) : $(sourceComponents) ]
13097669b69fSIngo Weinhold		: $(makeDefaultDependencies) ;
13100931b8f9SIngo Weinhold	NOUPDATE $(target) ;
13119eea4522SIngo Weinhold	Depends $(target) : $(source) ;
13123b9eae39SIngo Weinhold}
13133b9eae39SIngo Weinhold
1314d391d2ebSIngo Weinholdrule AbsSymLink
1315d391d2ebSIngo Weinhold{
13167bc56df1SIngo Weinhold	# AbsSymLink <link> : <link target> : <link dir>
13177669b69fSIngo Weinhold	#			: <makeDefaultDependencies> ;
1318d391d2ebSIngo Weinhold	# Creates an absolute symbolic link from <link> to <link target>.
1319d391d2ebSIngo Weinhold	# <link> and <link target> must be usual targets. If <link dir> is
1320d391d2ebSIngo Weinhold	# given, then it is set as LOCATE directory on <link>.
13217669b69fSIngo Weinhold	# <makeDefaultDependencies> If true (which is the default), <link> will be
13227669b69fSIngo Weinhold	# made a dependency of the `files' pseudo target, i.e. it will be made by
13237669b69fSIngo Weinhold	# default, and removed on `jam clean'.
1324d391d2ebSIngo Weinhold
13257669b69fSIngo Weinhold	local makeDefaultDependencies = $(4) ;
13267669b69fSIngo Weinhold	if ! $(makeDefaultDependencies) {
13277669b69fSIngo Weinhold		makeDefaultDependencies = true ;
13287669b69fSIngo Weinhold	}
13297669b69fSIngo Weinhold
1330d391d2ebSIngo Weinhold	Depends $(1) : $(2) ;
1331d391d2ebSIngo Weinhold	if $(3) {
1332d391d2ebSIngo Weinhold		MakeLocate $(1) : $(3) ;
1333d391d2ebSIngo Weinhold	}
1334d391d2ebSIngo Weinhold	SEARCH on $(2) += $(SEARCH_SOURCE) ;
13357669b69fSIngo Weinhold	if $(makeDefaultDependencies) = true {
13367669b69fSIngo Weinhold		LocalDepends files : $(1) ;
1337d391d2ebSIngo Weinhold		LocalClean clean : $(1) ;
1338d391d2ebSIngo Weinhold	}
13397669b69fSIngo Weinhold}
1340d391d2ebSIngo Weinhold
1341d391d2ebSIngo Weinholdactions AbsSymLink
1342d391d2ebSIngo Weinhold{
1343d391d2ebSIngo Weinhold	target="$(2)"
1344d391d2ebSIngo Weinhold	case "$target" in
1345d391d2ebSIngo Weinhold		/*) ;;
1346d391d2ebSIngo Weinhold		*) target=`pwd`/"$target";;
1347d391d2ebSIngo Weinhold	esac
1348d391d2ebSIngo Weinhold	$(RM) "$(1)" && $(LN) -s "$target" "$(1)"
1349d391d2ebSIngo Weinhold}
1350d391d2ebSIngo Weinhold
13517bc56df1SIngo Weinholdrule OBOSInstall
13527bc56df1SIngo Weinhold{
13537bc56df1SIngo Weinhold	# Usage: OBOSInstall <[ install [ and uninstall ] pseudotarget ]>
13547bc56df1SIngo Weinhold	#					 : <directory> : <sources to install>
13557bc56df1SIngo Weinhold	#					 : [ <installgrist> ] : [ <install rule> ] ;
13567bc56df1SIngo Weinhold	local install = $(1[1]) ;
13577bc56df1SIngo Weinhold	install ?= install ;
13587bc56df1SIngo Weinhold	local uninstall = $(1[2]) ;
13597bc56df1SIngo Weinhold	uninstall ?= un$(install) ;
13607bc56df1SIngo Weinhold	local dir = $(2) ;
13617bc56df1SIngo Weinhold	local sources = $(3) ;
13627bc56df1SIngo Weinhold	local installgrist = $(4) ;
13637bc56df1SIngo Weinhold	installgrist ?= $(INSTALLGRIST) ;
13647bc56df1SIngo Weinhold	local installRule = $(5) ;
13657bc56df1SIngo Weinhold	installRule ?= Install ;
13667bc56df1SIngo Weinhold	local targets = $(sources:G=$(installgrist)) ;
13677bc56df1SIngo Weinhold
1368bacf6872Sshatty	NotFile $(install) ;
1369bacf6872Sshatty	NotFile $(uninstall) ;
13707bc56df1SIngo Weinhold	Depends $(install) : $(targets) ;
13717bc56df1SIngo Weinhold	Clean $(uninstall) : $(targets) ;
13727bc56df1SIngo Weinhold
13737bc56df1SIngo Weinhold	SEARCH on $(sources) += $(SEARCH_SOURCE) ;
13747bc56df1SIngo Weinhold	MakeLocate $(targets) : $(dir) ;
13757bc56df1SIngo Weinhold
13767bc56df1SIngo Weinhold	local source ;
13777bc56df1SIngo Weinhold	for source in $(sources) {
13787bc56df1SIngo Weinhold		local target = $(source:G=$(installgrist)) ;
13797bc56df1SIngo Weinhold
13807bc56df1SIngo Weinhold		Depends $(target) : $(source) ;
13817bc56df1SIngo Weinhold		$(installRule) $(target) : $(source) ;
13827bc56df1SIngo Weinhold
13837bc56df1SIngo Weinhold		if [ on $(target) return $(MODE) ] {
13847bc56df1SIngo Weinhold			Chmod $(target) ;
13857bc56df1SIngo Weinhold		}
13867bc56df1SIngo Weinhold
13877bc56df1SIngo Weinhold		if $(OWNER) && $(CHOWN) {
13887bc56df1SIngo Weinhold			Chown $(target) ;
13897bc56df1SIngo Weinhold			OWNER on $(target) = $(OWNER) ;
13907bc56df1SIngo Weinhold		}
13917bc56df1SIngo Weinhold
13927bc56df1SIngo Weinhold		if $(GROUP) && $(CHGRP) {
13937bc56df1SIngo Weinhold			Chgrp $(target) ;
13947bc56df1SIngo Weinhold			GROUP on $(target) = $(GROUP) ;
13957bc56df1SIngo Weinhold		}
13967bc56df1SIngo Weinhold	}
13977bc56df1SIngo Weinhold}
13987bc56df1SIngo Weinhold
13997669b69fSIngo Weinholdrule InstallAbsSymLinkAdapter
14007669b69fSIngo Weinhold{
14017669b69fSIngo Weinhold	# InstallAbsSymLinkAdapter <link> : <link target>
14027669b69fSIngo Weinhold	if ! [ on $(2) return $(TARGET) ] {
14037669b69fSIngo Weinhold		TARGET on $(2) = [ on $(2) return $(SEARCH) ] ;
14047669b69fSIngo Weinhold	}
14057669b69fSIngo Weinhold	AbsSymLink $(1) : $(2) : : false ;
14067669b69fSIngo Weinhold}
14077669b69fSIngo Weinhold
14087bc56df1SIngo Weinholdrule OBOSInstallAbsSymLink
14097bc56df1SIngo Weinhold{
14107bc56df1SIngo Weinhold	# Usage: OBOSInstallAbsSymLink <[ install [ and uninstall ] pseudotarget ]>
14117bc56df1SIngo Weinhold	#							   : <directory> : <sources to install>
14127bc56df1SIngo Weinhold	#							   : [ <installgrist> ] ;
14137669b69fSIngo Weinhold	OBOSInstall $(1) : $(2) : $(3) : $(4) : InstallAbsSymLinkAdapter ;
14147bc56df1SIngo Weinhold}
14157bc56df1SIngo Weinhold
14167bc56df1SIngo Weinholdrule InstallRelSymLinkAdapter
14177bc56df1SIngo Weinhold{
14187bc56df1SIngo Weinhold	# InstallRelSymLinkAdapter <link> : <link target>
14197bc56df1SIngo Weinhold	if ! [ on $(2) return $(TARGET) ] {
14207bc56df1SIngo Weinhold		TARGET on $(2) = [ on $(2) return $(SEARCH) ] ;
14217bc56df1SIngo Weinhold	}
14227669b69fSIngo Weinhold	RelSymLink $(1) : $(2) : false ;
14237bc56df1SIngo Weinhold}
14247bc56df1SIngo Weinhold
14257bc56df1SIngo Weinholdrule OBOSInstallRelSymLink
14267bc56df1SIngo Weinhold{
14277bc56df1SIngo Weinhold	# Usage: OBOSInstallRelSymLink <[ install [ and uninstall ] pseudotarget ]>
14287bc56df1SIngo Weinhold	#							   : <directory> : <sources to install>
14297bc56df1SIngo Weinhold	#							   : [ <installgrist> ] ;
14307bc56df1SIngo Weinhold	OBOSInstall $(1) : $(2) : $(3) : $(4) : InstallRelSymLinkAdapter ;
14317bc56df1SIngo Weinhold}
14327bc56df1SIngo Weinhold
14337bc56df1SIngo Weinhold
143452a38012Sejakowatz#-------------------------------------------------------------------------------
143552a38012Sejakowatz# Low-level OBOS utility rules
143652a38012Sejakowatz#-------------------------------------------------------------------------------
143752a38012Sejakowatzrule SetupObjectsDir
143852a38012Sejakowatz{
143952a38012Sejakowatz	local rel_objectsdir;
144052a38012Sejakowatz
144152a38012Sejakowatz	# Copy subdir tokens except the first, as that will be "sources", and we
144252a38012Sejakowatz	# do not want to include that :)
144352a38012Sejakowatz	rel_objectsdir = [ FDirName $(SUBDIR_TOKENS[2-]) ] ;
144452a38012Sejakowatz	LOCATE_TARGET = [ FDirName $(OBOS_OBJECT_TARGET) $(rel_objectsdir) ] ;
14458d3308d9SIngo Weinhold	LOCATE_SOURCE = $(LOCATE_TARGET) ;
14468d3308d9SIngo Weinhold	SEARCH_SOURCE = [ Filter $(SEARCH_SOURCE) : $(LOCATE_TARGET) ]
14478d3308d9SIngo Weinhold					$(LOCATE_TARGET) ;
144852a38012Sejakowatz}
144952a38012Sejakowatz
145052a38012Sejakowatz#-------------------------------------------------------------------------------
145152a38012Sejakowatz# Link rule/action are overwritten as they don't handle linking files who's name
145252a38012Sejakowatz# contain spaces very well. Also adds resources and version to executable.
145352a38012Sejakowatz#-------------------------------------------------------------------------------
145452a38012Sejakowatzrule Link
145552a38012Sejakowatz{
145652a38012Sejakowatz	# Note: RESFILES must be set before invocation.
145752a38012Sejakowatz	MODE on $(<) = $(EXEMODE) ;
145852a38012Sejakowatz	on $(1) XRes $(1) : $(RESFILES) ;
145952a38012Sejakowatz	Chmod $(<) ;
146052a38012Sejakowatz	SetType $(1) ;
146152a38012Sejakowatz	MimeSet $(1) ;
14621419ae2bSshatty	SetVersion $(1) ;
146352a38012Sejakowatz}
146452a38012Sejakowatz
146552a38012Sejakowatzactions Link bind NEEDLIBS
146652a38012Sejakowatz{
14671eb18edfSIngo Weinhold	$(LINK) $(LINKFLAGS) -o "$(1)" $(UNDEFS) "$(2)" "$(NEEDLIBS)" $(LINKLIBS) ;
146852a38012Sejakowatz}
146952a38012Sejakowatz
14708d3308d9SIngo Weinholdrule LexC++
14718d3308d9SIngo Weinhold{
14728d3308d9SIngo Weinhold	Depends $(1) : $(2) ;
14738d3308d9SIngo Weinhold	MakeLocate $(1) : $(LOCATE_SOURCE) ;
14748d3308d9SIngo Weinhold	LocalClean clean : $(1) ;
14758d3308d9SIngo Weinhold}
14768d3308d9SIngo Weinhold
14778d3308d9SIngo Weinholdactions LexC++
14788d3308d9SIngo Weinhold{
14798d3308d9SIngo Weinhold	$(LEX) -o$(1) $(2)
14808d3308d9SIngo Weinhold}
14818d3308d9SIngo Weinhold
14828d3308d9SIngo Weinholdrule Bison
14838d3308d9SIngo Weinhold{
14848d3308d9SIngo Weinhold	local _h ;
14858d3308d9SIngo Weinhold
14868d3308d9SIngo Weinhold	_h = $(1).h ;
14878d3308d9SIngo Weinhold
14888d3308d9SIngo Weinhold	MakeLocate $(<) $(_h) : $(LOCATE_SOURCE) ;
14898d3308d9SIngo Weinhold
14908d3308d9SIngo Weinhold    Depends $(<) $(_h) : $(>) ;
14918d3308d9SIngo Weinhold    Bison1 $(<) $(_h) : $(>) ;
14928d3308d9SIngo Weinhold    LocalClean clean : $(<) $(_h) ;
14938d3308d9SIngo Weinhold
14948d3308d9SIngo Weinhold	# make sure someone includes $(_h) else it will be
14958d3308d9SIngo Weinhold	# a deadly independent target
14968d3308d9SIngo Weinhold
14978d3308d9SIngo Weinhold	Includes $(<) : $(_h) ;
14988d3308d9SIngo Weinhold}
14998d3308d9SIngo Weinhold
15008d3308d9SIngo Weinholdactions Bison1
15018d3308d9SIngo Weinhold{
15028d3308d9SIngo Weinhold	bison $(YACCFLAGS) -o $(1[1]) $(2)
15038d3308d9SIngo Weinhold}
15048d3308d9SIngo Weinhold
150552a38012Sejakowatz# BeOS specific rules
150652a38012Sejakowatz
150752a38012Sejakowatzrule XRes
150852a38012Sejakowatz{
150952a38012Sejakowatz	# XRes <target> : <resource files>
151052a38012Sejakowatz	if $(2)
151152a38012Sejakowatz	{
15129eea4522SIngo Weinhold		Depends $(1) : $(2) ;
151352a38012Sejakowatz		XRes1 $(1) : $(2) ;
151452a38012Sejakowatz	}
151552a38012Sejakowatz}
151652a38012Sejakowatz
151752a38012Sejakowatzrule XRes1 { }
151852a38012Sejakowatz
151952a38012Sejakowatzrule SetVersion
152052a38012Sejakowatz{
152152a38012Sejakowatz	# SetVersion <target>
152252a38012Sejakowatz}
152352a38012Sejakowatz
152452a38012Sejakowatzrule SetType
152552a38012Sejakowatz{
152652a38012Sejakowatz	# SetType <target>
152752a38012Sejakowatz}
152852a38012Sejakowatz
152952a38012Sejakowatzrule MimeSet
153052a38012Sejakowatz{
153152a38012Sejakowatz	# SetType <target>
153252a38012Sejakowatz}
153352a38012Sejakowatz
153452a38012Sejakowatz
153552a38012Sejakowatzif $(OS) = BEOS
153652a38012Sejakowatz{
153752a38012Sejakowatz
153852a38012Sejakowatzactions XRes1
153952a38012Sejakowatz{
15400931b8f9SIngo Weinhold	xres -o "$(1)" "$(2)" ;
154152a38012Sejakowatz}
154252a38012Sejakowatz
154352a38012Sejakowatzactions SetVersion
154452a38012Sejakowatz{
154552a38012Sejakowatz	setversion "$(1)" -system $(OBOS_BUILD_VERSION) -short "$(OBOS_BUILD_DESCRIPTION)" ;
154652a38012Sejakowatz}
154752a38012Sejakowatz
154852a38012Sejakowatzactions SetType
154952a38012Sejakowatz{
155052a38012Sejakowatz	settype -t $(OBOS_TARGET_TYPE) "$(1)" ;
155152a38012Sejakowatz}
155252a38012Sejakowatz
155352a38012Sejakowatzactions MimeSet
155452a38012Sejakowatz{
155552a38012Sejakowatz	mimeset -f "$(1)" ;
155652a38012Sejakowatz}
155752a38012Sejakowatz
155852a38012Sejakowatz}	# if BEOS
155952a38012Sejakowatz
156052a38012Sejakowatz
156152a38012Sejakowatzrule assemble
156252a38012Sejakowatz{
156394782cf7SIngo Weinhold	Depends $(<) : $(>) ;
156494782cf7SIngo Weinhold	ASFLAGS on $(<) += $(ASFLAGS) $(SUBDIRASFLAGS) ;
156594782cf7SIngo Weinhold	ASHDRS on $(<) = [ FIncludes $(SEARCH_SOURCE) $(SUBDIRHDRS) $(HDRS) ] ;
156652a38012Sejakowatz}
156752a38012Sejakowatz
156852a38012Sejakowatzactions assemble
156952a38012Sejakowatz{
1570a8687de4SAxel Dörfler	$(CC) -c "$(2)" -O2 $(ASFLAGS) -D_ASSEMBLER $(KERNEL_CCFLAGS) $(ASHDRS) -o "$(1)" ;
157152a38012Sejakowatz}
157252a38012Sejakowatz
15730931b8f9SIngo Weinhold# Overridden to allow spaces in file names.
15740931b8f9SIngo Weinholdactions Chmod1
15750931b8f9SIngo Weinhold{
15760931b8f9SIngo Weinhold	$(CHMOD) "$(MODE)" "$(1)"
15770931b8f9SIngo Weinhold}
15780931b8f9SIngo Weinhold
15796991af8cSIngo Weinhold# Overridden to allow spaces in file names.
15806991af8cSIngo Weinholdactions piecemeal together existing Clean
15816991af8cSIngo Weinhold{
15826991af8cSIngo Weinhold	$(RM) "$(>)"
15836991af8cSIngo Weinhold}
15846991af8cSIngo Weinhold
158508125d07SIngo Weinholdrule ObjectReference
158608125d07SIngo Weinhold{
158708125d07SIngo Weinhold	# ObjectReference <reference object> : <source object>
158808125d07SIngo Weinhold	# Makes <reference object> refer to the same file as <source object>.
158908125d07SIngo Weinhold	# The filenames must of course be identical.
159008125d07SIngo Weinhold	# <source object> must have already been LOCATEd.
159108125d07SIngo Weinhold
159208125d07SIngo Weinhold	local ref = $(1) ;
159308125d07SIngo Weinhold	local source = $(2) ;
159408125d07SIngo Weinhold	if $(ref) != $(source) {
15959eea4522SIngo Weinhold		Depends $(ref) : $(source) ;
159621df5945SIngo Weinhold		LOCATE on $(ref) = [ on $(source) return $(LOCATE) ] ;
159708125d07SIngo Weinhold	}
159808125d07SIngo Weinhold}
159908125d07SIngo Weinhold
160008125d07SIngo Weinholdrule ObjectReferences
160108125d07SIngo Weinhold{
160208125d07SIngo Weinhold	# ObjectReferences <source objects>
160308125d07SIngo Weinhold	# Creates local references to <source objects>, i.e. identifiers with the
160408125d07SIngo Weinhold	# current grist referring to the same files. <source objects> must have
160508125d07SIngo Weinhold	# already been LOCATEd.
160608125d07SIngo Weinhold
160708125d07SIngo Weinhold	local source ;
160808125d07SIngo Weinhold	for source in $(1) {
160908125d07SIngo Weinhold		ObjectReference [ FGristFiles $(source) ] : $(source) ;
161008125d07SIngo Weinhold	}
161108125d07SIngo Weinhold}
161208125d07SIngo Weinhold
16139fc6b2e1SIngo Weinholdrule Filter
16149fc6b2e1SIngo Weinhold{
16159fc6b2e1SIngo Weinhold	# Filter <list> : <excludes> ;
16169fc6b2e1SIngo Weinhold	# Removes all occurrences of <excludes> in <list>.
16179fc6b2e1SIngo Weinhold
16189fc6b2e1SIngo Weinhold	local list = $(1) ;
16199fc6b2e1SIngo Weinhold	local excludes = $(2) ;
16209fc6b2e1SIngo Weinhold	local newList ;
16219fc6b2e1SIngo Weinhold	local item ;
16229fc6b2e1SIngo Weinhold	for item in $(list) {
16239fc6b2e1SIngo Weinhold		local skip ;
16249fc6b2e1SIngo Weinhold		local exclude ;
16259fc6b2e1SIngo Weinhold		for exclude in $(excludes) {
16269fc6b2e1SIngo Weinhold			if $(item) = $(exclude) {
16279fc6b2e1SIngo Weinhold				skip = true ;
16289fc6b2e1SIngo Weinhold			}
16299fc6b2e1SIngo Weinhold		}
16309fc6b2e1SIngo Weinhold		if ! $(skip) {
1631dd9f8062SIngo Weinhold			newList += $(item) ;
16329fc6b2e1SIngo Weinhold		}
16339fc6b2e1SIngo Weinhold	}
16349fc6b2e1SIngo Weinhold	return $(newList) ;
16359fc6b2e1SIngo Weinhold}
16369fc6b2e1SIngo Weinhold
16370931b8f9SIngo Weinhold
163852a38012Sejakowatz## Kernel stuff!
163952a38012Sejakowatz
164052a38012Sejakowatzrule SetupKernel
164152a38012Sejakowatz{
164252a38012Sejakowatz	# Usage SetupKernel <sources_or_objects> : <extra_cc_flags>;
164352a38012Sejakowatz
16442dd47f63SIngo Weinhold	local _objs = [ FGristFiles $(1:S=$(SUFOBJ)) ] ;
164552a38012Sejakowatz
164628d2a30eSDaniel Reinhold	#Setup Kernel header directories
1647089a0629Sbeveloper	local public_kernel_includes = add-ons/file_system add-ons/graphics device drivers kernel storage support ;
1648b8b44e7aSAxel Dörfler	local private_kernel_includes = kernel libroot kernel/boot/platform/$(OBOS_BOOT_PLATFORM) ;
1649a6c008e1Sbeveloper	# Use posix headers directory
165028d2a30eSDaniel Reinhold	HDRS = [ FDirName $(OBOS_TOP) headers posix ] ;
1651a6c008e1Sbeveloper	# Use public OS header directories
1652089a0629Sbeveloper	HDRS += [ PublicHeaders $(public_kernel_includes) ] ;
1653089a0629Sbeveloper	# Use private directories
1654089a0629Sbeveloper	HDRS += [ PrivateHeaders $(private_kernel_includes) ] ;
165509c5682dSIngo Weinhold	# The platform dependent headers.
165609c5682dSIngo Weinhold	HDRS += $(PLATFORM_HEADERS) ;
1657a6c008e1Sbeveloper
165852a38012Sejakowatz	UseArchHeaders $(OBOS_ARCH) ;
165952a38012Sejakowatz
166052a38012Sejakowatz	SetupObjectsDir ;
166152a38012Sejakowatz
166252a38012Sejakowatz	CCFLAGS on $(_objs) = $(KERNEL_CCFLAGS) $(2) ;
166398cc804cSAxel Dörfler	C++FLAGS on $(_objs) = $(KERNEL_C++FLAGS) $(2) ;
166452a38012Sejakowatz}
166552a38012Sejakowatz
166652a38012Sejakowatzrule KernelObjects
166752a38012Sejakowatz{
166852a38012Sejakowatz	SetupKernel $(1) : $(2) ;
166952a38012Sejakowatz
167052a38012Sejakowatz	Objects $(1) ;
167152a38012Sejakowatz}
167252a38012Sejakowatz
167352a38012Sejakowatzrule KernelLd
167452a38012Sejakowatz{
167580721244SAxel Dörfler	# KernelLd <name> : <objs> : <linkerscript> : <args> : <gcc_off> : <config_section> ;
167652a38012Sejakowatz
167752a38012Sejakowatz	SetupKernel $(2) ;
167852a38012Sejakowatz	LINK on $(1) = ld ;
167952a38012Sejakowatz
168052a38012Sejakowatz	LINKFLAGS on $(1) = $(4) ;
168152a38012Sejakowatz	if $(3) { LINKFLAGS on $(1) += --script=$(3) ; }
168252a38012Sejakowatz
168352a38012Sejakowatz	# Remove any preset LINKLIBS
168452a38012Sejakowatz	LINKLIBS on $(1) =  ;
168552a38012Sejakowatz
168652a38012Sejakowatz	# Show that we depend on the libraries we need
16879eea4522SIngo Weinhold	LocalClean clean : $(1) ;
16889eea4522SIngo Weinhold	LocalDepends all : $(1) ;
168952a38012Sejakowatz	Depends $(1) : $(2) ;
169052a38012Sejakowatz
169152a38012Sejakowatz	if $(6) {
169252a38012Sejakowatz		for i in $(6) {
16932a83bfb4SIngo Weinhold			KernelConfigSection $(i) : elf32 : $(1) ;
169452a38012Sejakowatz		}
169552a38012Sejakowatz	}
169652a38012Sejakowatz
169752a38012Sejakowatz	MakeLocate $(1) : $(LOCATE_TARGET) ;
169852a38012Sejakowatz
169909c5682dSIngo Weinhold	# Add the platform specific static libs (libgcc.a).
170052a38012Sejakowatz	if ! $(5) {
170109c5682dSIngo Weinhold		LINKLIBS on $(1) += $(PLATFORM_LINKLIBS) ;
170252a38012Sejakowatz	}
170352a38012Sejakowatz}
170452a38012Sejakowatz
170552a38012Sejakowatzactions KernelLd
170652a38012Sejakowatz{
17071eb18edfSIngo Weinhold	$(LINK) $(LINKFLAGS) -o "$(1)" "$(2)" $(LINKLIBS) ;
170852a38012Sejakowatz}
170952a38012Sejakowatz
1710811903d1SAxel Dörflerrule KernelAddon
1711811903d1SAxel Dörfler{
1712811903d1SAxel Dörfler	# KernelAddon <name> : <relpath> : <sources> ;
1713811903d1SAxel Dörfler
1714811903d1SAxel Dörfler	local sources = $(3) ;
1715811903d1SAxel Dörfler
1716811903d1SAxel Dörfler	SetupKernel $(3) ;
1717811903d1SAxel Dörfler	Addon $(1) : $(2) : $(3) ;
1718811903d1SAxel Dörfler	ObjectCcFlags $(sources) : -D_KERNEL_MODE=1 -no-fpic ;
1719811903d1SAxel Dörfler	ObjectC++Flags $(sources) : -D_KERNEL_MODE=1 -no-fpic
1720811903d1SAxel Dörfler								-fno-exceptions -fno-rtti ;
1721811903d1SAxel Dörfler	LINKFLAGS on $(1) = [ on $(1) return $(LINKFLAGS) ] -nostdlib ;
1722811903d1SAxel Dörfler	LinkSharedOSLibs $(1) : $(OBOS_TOP)/objects/$(OBOS_ARCH).$(OBOS_VERSION)/kernel/kernel.so ;
1723811903d1SAxel Dörfler		# ToDo this has to be changed!
1724811903d1SAxel Dörfler}
1725811903d1SAxel Dörfler
172680721244SAxel Dörflerrule KernelMergeObject
172780721244SAxel Dörfler{
17282fbd7065SIngo Weinhold	# KernelMergeObject <name> : <sources> : <extra CFLAGS> : <other objects> ;
17292fbd7065SIngo Weinhold	# Compiles source files and merges the object files to an object file.
17302fbd7065SIngo Weinhold	# <name>: Name of the object file to create. No grist will be added.
17312fbd7065SIngo Weinhold	# <sources>: Sources to be compiled. Grist will be added.
17322fbd7065SIngo Weinhold	# <extra CFLAGS>: Additional flags for compilation.
17332fbd7065SIngo Weinhold	# <other objects>: Object files or static libraries to be merged. No grist
17342fbd7065SIngo Weinhold	#                  will be added.
17352fbd7065SIngo Weinhold	#
173680721244SAxel Dörfler
173780721244SAxel Dörfler	SetupKernel $(2) : $(3) ;
173880721244SAxel Dörfler
173980721244SAxel Dörfler	MakeLocateObjects $(2) ;
174080721244SAxel Dörfler	Objects $(2) ;
17412fbd7065SIngo Weinhold	MergeObjectFromObjects $(1) : $(2:S=$(SUFOBJ)) : $(4) ;
174280721244SAxel Dörfler}
174380721244SAxel Dörfler
174452a38012Sejakowatzrule KernelStaticLibrary
174552a38012Sejakowatz{
174652a38012Sejakowatz	# Usage KernelStaticLibrary <name> : <sources> : <extra cc flags>  ;
174752a38012Sejakowatz	# This is designed to take a set of sources and libraries and create
174852a38012Sejakowatz	# a file called lib<name>.a
174952a38012Sejakowatz
175052a38012Sejakowatz	SetupKernel $(2) : $(3) ;
175152a38012Sejakowatz
175252a38012Sejakowatz	MakeLocateObjects $(2) ;
175352a38012Sejakowatz	Library $(1) : $(2) ;
175452a38012Sejakowatz}
175552a38012Sejakowatz
175652a38012Sejakowatzrule KernelStaticLibraryObjects
175752a38012Sejakowatz{
175852a38012Sejakowatz	# Usage KernelStaticLibrary <name> : <sources> ;
175952a38012Sejakowatz	# This is designed to take a set of sources and libraries and create
176052a38012Sejakowatz	# a file called <name>
176152a38012Sejakowatz
176252a38012Sejakowatz	SetupKernel $(2) ;
176352a38012Sejakowatz
176452a38012Sejakowatz	# Show that we depend on the libraries we need
17659eea4522SIngo Weinhold	LocalClean clean : $(1) ;
17669eea4522SIngo Weinhold	LocalDepends all : $(1) ;
176752a38012Sejakowatz	Depends $(1) : $(2) ;
176852a38012Sejakowatz
176952a38012Sejakowatz	MakeLocate $(1) : $(LOCATE_TARGET) ;
177052a38012Sejakowatz}
177152a38012Sejakowatz
177252a38012Sejakowatzactions KernelStaticLibraryObjects
177352a38012Sejakowatz{
17740931b8f9SIngo Weinhold	ar -r "$(1)" "$(2)" ;
177552a38012Sejakowatz}
177652a38012Sejakowatz
17775dc4e1efSIngo Weinholdrule BuildPlatformMain
177852a38012Sejakowatz{
17795dc4e1efSIngo Weinhold	# Usage BuildPlatformMain <target> : <sources> ;
178052a38012Sejakowatz	SetupObjectsDir ;
17815dc4e1efSIngo Weinhold	SetupDefaultIncludes ;
178252a38012Sejakowatz
17835dc4e1efSIngo Weinhold	# Remove `-nostdinc' from CCFLAGS and C++FLAGS.
17845dc4e1efSIngo Weinhold	local oldCCFLAGS = $(CCFLAGS) ;
17855dc4e1efSIngo Weinhold	local oldC++FLAGS = $(C++FLAGS) ;
17865dc4e1efSIngo Weinhold	CCFLAGS = [ Filter $(CCFLAGS) : -nostdinc ] ;
17875dc4e1efSIngo Weinhold	C++FLAGS = [ Filter $(C++FLAGS) : -nostdinc ] ;
178852a38012Sejakowatz
178952a38012Sejakowatz	Main $(1) : $(2) ;
17905dc4e1efSIngo Weinhold
17915dc4e1efSIngo Weinhold	# Reset CCFLAGS and C++FLAGS to original values.
17925dc4e1efSIngo Weinhold	CCFLAGS = $(oldCCFLAGS) ;
17935dc4e1efSIngo Weinhold	C++FLAGS = $(oldC++FLAGS) ;
179452a38012Sejakowatz}
179552a38012Sejakowatz
17969fcaa61dSIngo Weinholdrule BuildPlatformTest
17979fcaa61dSIngo Weinhold{
17989fcaa61dSIngo Weinhold	# Usage BuildPlatformTest <target> : <sources> ;
17999fcaa61dSIngo Weinhold
18009fcaa61dSIngo Weinhold	local target = $(1) ;
18019fcaa61dSIngo Weinhold	local sources = $(2) ;
18029fcaa61dSIngo Weinhold
18039fcaa61dSIngo Weinhold	BuildPlatformMain $(target) : $(sources) ;
18049fcaa61dSIngo Weinhold	local relPath ;
18059fcaa61dSIngo Weinhold	if [ FIsPrefix src tests : $(SUBDIR_TOKENS) ] {
18069fcaa61dSIngo Weinhold		relPath = $(SUBDIR_TOKENS[3-]) ;
18079fcaa61dSIngo Weinhold	} else {
18089fcaa61dSIngo Weinhold		relPath = $(SUBDIR_TOKENS[2-]) ;
18099fcaa61dSIngo Weinhold	}
18109fcaa61dSIngo Weinhold	MakeLocate $(target) : [ FDirName $(OBOS_TEST_DIR) $(relPath) ] ;
18119fcaa61dSIngo Weinhold}
18129fcaa61dSIngo Weinhold
181352a38012Sejakowatzrule KernelConfigSection
181452a38012Sejakowatz{
181552a38012Sejakowatz	# KernelConfigSection <section> : <type> : <file>  ;
18162a83bfb4SIngo Weinhold
18172a83bfb4SIngo Weinhold	SECTION_NAMES on $(OBOS_KERNEL_CONFIG) += $(1) ;
18182a83bfb4SIngo Weinhold	SECTION_TYPES on $(OBOS_KERNEL_CONFIG) += $(2) ;
18192a83bfb4SIngo Weinhold	SECTION_FILES on $(OBOS_KERNEL_CONFIG) += $(3) ;
18202a83bfb4SIngo Weinhold
18212a83bfb4SIngo Weinhold	Depends $(OBOS_KERNEL_CONFIG) : $(3) ;
182252a38012Sejakowatz}
182352a38012Sejakowatz
182452a38012Sejakowatzrule WriteKernelConfig
182552a38012Sejakowatz{
182652a38012Sejakowatz	# usage: WriteKernelConfig <target> ;
182752a38012Sejakowatz
18289eea4522SIngo Weinhold	LocalDepends files : $(1) ;
182952a38012Sejakowatz
18302a83bfb4SIngo Weinhold	MakeLocate $(1) : $(OBOS_OBJECT_TARGET) ;
183152a38012Sejakowatz
18329eea4522SIngo Weinhold	LocalClean clean : $(1) ;
183352a38012Sejakowatz}
183452a38012Sejakowatz
18352a83bfb4SIngo Weinholdactions WriteKernelConfig bind SECTION_FILES
183652a38012Sejakowatz{
18370931b8f9SIngo Weinhold	target="$(1)"
18380931b8f9SIngo Weinhold	echo "# OpenBeOS Kernel Config File" > "$target"
18390931b8f9SIngo Weinhold	echo "# Automatically generated - do not edit!" >> "$target"
18402a83bfb4SIngo Weinhold	count=0
18412a83bfb4SIngo Weinhold	for section in "$(SECTION_NAMES)" ; do
18422a83bfb4SIngo Weinhold		count=`expr $count + 1`
18432a83bfb4SIngo Weinhold		eval section$count="$section"
18442a83bfb4SIngo Weinhold	done
18452a83bfb4SIngo Weinhold	i=1
18462a83bfb4SIngo Weinhold	for type in "$(SECTION_TYPES)" ; do
18472a83bfb4SIngo Weinhold		eval type$i="$type"
18482a83bfb4SIngo Weinhold		i=`expr $i + 1`
18492a83bfb4SIngo Weinhold	done
18502a83bfb4SIngo Weinhold	i=1
18512a83bfb4SIngo Weinhold	for file in "$(SECTION_FILES)" ; do
18522a83bfb4SIngo Weinhold		eval file$i="$file"
18532a83bfb4SIngo Weinhold		i=`expr $i + 1`
18542a83bfb4SIngo Weinhold	done
18552a83bfb4SIngo Weinhold	for i in `seq $count` ; do
18562a83bfb4SIngo Weinhold		eval section="\$section$i"
18572a83bfb4SIngo Weinhold		eval type="\$type$i"
18582a83bfb4SIngo Weinhold		eval file="\$file$i"
18590931b8f9SIngo Weinhold		echo "" >> "$target"
18602a83bfb4SIngo Weinhold		echo "["$section"]" >> "$target"
18612a83bfb4SIngo Weinhold		echo "type="$type >> "$target"
18620931b8f9SIngo Weinhold		case "$file" in
186352a38012Sejakowatz			/*) ;;
18640931b8f9SIngo Weinhold			*) file=`pwd`/"$file";;
186552a38012Sejakowatz		esac
18662a83bfb4SIngo Weinhold		echo "file="$file >> "$target"
186752a38012Sejakowatz	done
186852a38012Sejakowatz}
186952a38012Sejakowatz
187052a38012Sejakowatzrule BuildKernel
187152a38012Sejakowatz{
187252a38012Sejakowatz	# Usage BuildKernel <target> : <config_file> ;
18730c0b2cd0SIngo Weinhold	local kernel = $(1) ;
18740c0b2cd0SIngo Weinhold	local configFile = $(2) ;
18750c0b2cd0SIngo Weinhold	local bootmaker = bootmaker ;
187652a38012Sejakowatz
18779eea4522SIngo Weinhold	LocalDepends all : $(kernel) ;
18780c0b2cd0SIngo Weinhold	Depends $(kernel) : $(configFile) $(bootmaker) ;
18799eea4522SIngo Weinhold	LocalClean clean : $(kernel) ;
18800c0b2cd0SIngo Weinhold	MakeLocate $(kernel) : $(LOCATE_TARGET) ;
188152a38012Sejakowatz
18820c0b2cd0SIngo Weinhold	BOOT_MAKER on $(kernel) = $(bootmaker) ;
188352a38012Sejakowatz}
188452a38012Sejakowatz
18850c0b2cd0SIngo Weinholdactions BuildKernel bind BOOT_MAKER
188652a38012Sejakowatz{
18870c0b2cd0SIngo Weinhold	"$(BOOT_MAKER)" --strip-debug --strip-binary strip "$(2)" -o "$(1)" ;
188852a38012Sejakowatz	echo ""
188952a38012Sejakowatz	echo "Kernel linked!"
189052a38012Sejakowatz	echo ""
189152a38012Sejakowatz}
189252a38012Sejakowatz
189352a38012Sejakowatzrule KernelFloppyImage
189452a38012Sejakowatz{
189552a38012Sejakowatz	# Usage KernelFloppyImage <target> : <kernel> : <bootblock> ;
18960c0b2cd0SIngo Weinhold	local floppy = $(1) ;
18970c0b2cd0SIngo Weinhold	local kernel = $(2) ;
18980c0b2cd0SIngo Weinhold	local bootblock = $(3) ;
18990c0b2cd0SIngo Weinhold	local makeflop = makeflop ;
190052a38012Sejakowatz
19019eea4522SIngo Weinhold	LocalDepends all : $(floppy) ;
19020c0b2cd0SIngo Weinhold	Depends $(floppy) : $(kernel) $(bootblock) $(makeflop) ;
19039eea4522SIngo Weinhold	LocalClean clean : $(floppy) ;
19040c0b2cd0SIngo Weinhold	MakeLocate $(floppy) : $(OBOS_OBJECT_TARGET) ;
190552a38012Sejakowatz
19060c0b2cd0SIngo Weinhold	BOOT_BLOCK on $(floppy) = $(bootblock) ;
19070c0b2cd0SIngo Weinhold	MAKE_FLOP on $(floppy) = $(makeflop) ;
190852a38012Sejakowatz}
190952a38012Sejakowatz
191052a38012Sejakowatz# This may be a bit verbose, but I think it's useful to show what's
191152a38012Sejakowatz# going on, at least in this early stage of development.
19120c0b2cd0SIngo Weinholdactions KernelFloppyImage bind BOOT_BLOCK bind MAKE_FLOP
191352a38012Sejakowatz{
19147378dd7fSAxel Dörfler	"$(MAKE_FLOP)" "-p $(shell expr 18 \* 2 \* 512)" "$(BOOT_BLOCK)" "$(2)" "$(1)" ;
19150c0b2cd0SIngo Weinhold
191652a38012Sejakowatz	echo ""
191752a38012Sejakowatz	echo "*************************************************"
191852a38012Sejakowatz	echo "*         Kernel build completed!               *"
191952a38012Sejakowatz	echo "*    Boot image for a 1.44M floppy created      *"
192052a38012Sejakowatz	echo "*************************************************"
192152a38012Sejakowatz	echo ""
19220c0b2cd0SIngo Weinhold	echo "Floppy image is $(1)"
192352a38012Sejakowatz	echo "The following command will write it to a floppy on BeOS"
19240c0b2cd0SIngo Weinhold	echo "  dd if=$(1) of=/dev/disk/floppy/raw bs=18k"
19250c0b2cd0SIngo Weinhold	echo "Alternatively you can run"
19260c0b2cd0SIngo Weinhold	echo "  ./configure --floppy /dev/disk/floppy/raw"
19270c0b2cd0SIngo Weinhold	echo "once and build + write the image subsequently via"
19280c0b2cd0SIngo Weinhold	echo "  jam installfloppy"
192952a38012Sejakowatz	echo ""
193052a38012Sejakowatz}
193152a38012Sejakowatz
19320c0b2cd0SIngo Weinholdrule InstallFloppy
19330c0b2cd0SIngo Weinhold{
19340c0b2cd0SIngo Weinhold	# InstallFloppy <target> : <floppy>
19350c0b2cd0SIngo Weinhold	# "dd"s <floppy> to $(FLOPPY_PATH).
19360c0b2cd0SIngo Weinhold
19370c0b2cd0SIngo Weinhold	local target = $(1) ;
19380c0b2cd0SIngo Weinhold	local floppy = $(2) ;
19390c0b2cd0SIngo Weinhold
19400c0b2cd0SIngo Weinhold	NotFile $(target) ;
19410c0b2cd0SIngo Weinhold	Always $(target) ;
19420c0b2cd0SIngo Weinhold	Depends $(target) : $(floppy) ;
19430c0b2cd0SIngo Weinhold}
19440c0b2cd0SIngo Weinhold
19450c0b2cd0SIngo Weinholdactions InstallFloppy
19460c0b2cd0SIngo Weinhold{
19470c0b2cd0SIngo Weinhold	if [ -z $(FLOPPY_PATH) ] ; then
19480c0b2cd0SIngo Weinhold		echo "Can't install floppy: FLOPPY_PATH not set."
19490c0b2cd0SIngo Weinhold		echo "run: ./configure --floppy <floppy path>"
19500c0b2cd0SIngo Weinhold		echo
19510c0b2cd0SIngo Weinhold		exit 0
19520c0b2cd0SIngo Weinhold	fi
19530c0b2cd0SIngo Weinhold	dd if=$(2) of=$(FLOPPY_PATH) bs=18k
19540c0b2cd0SIngo Weinhold}
195552a38012Sejakowatz
195621df5945SIngo Weinhold#-------------------------------------------------------------------------------
195721df5945SIngo Weinhold# FreeType 2 specific rules and variables
195821df5945SIngo Weinhold#-------------------------------------------------------------------------------
195921df5945SIngo Weinhold
196021df5945SIngo WeinholdFT2_INCLUDE = [ FDirName $(OBOS_TOP) headers libs freetype2 ] ;
196121df5945SIngo WeinholdFT2_SRC     = [ FDirName $(OBOS_TOP) src libs freetype2 ] ;
196221df5945SIngo Weinhold
196321df5945SIngo WeinholdFT2_LIB     = freetype ;
196421df5945SIngo Weinhold
1965fbd28219SIngo WeinholdFT2_COMPONENTS ?= gzip       # support for gzip-compressed files.
1966fbd28219SIngo Weinhold                  autohint   # auto-hinter
1967fbd28219SIngo Weinhold                  base       # base component (public APIs)
1968fbd28219SIngo Weinhold                  bdf        # BDF font driver
1969fbd28219SIngo Weinhold                  cache      # cache sub-system
1970fbd28219SIngo Weinhold                  cff        # CFF/CEF font driver
1971fbd28219SIngo Weinhold                  cid        # Postscript CID-keyed font driver
1972fbd28219SIngo Weinhold                  pcf        # PCF font driver
1973fbd28219SIngo Weinhold                  pfr        # PFR/TrueDoc font driver
1974fbd28219SIngo Weinhold                  psaux      # Common Postscript routines module
1975fbd28219SIngo Weinhold                  pshinter   # Postscript hinter module
1976fbd28219SIngo Weinhold                  psnames    # Postscript names handling
1977fbd28219SIngo Weinhold                  raster     # Monochrome rasterizer
1978fbd28219SIngo Weinhold                  smooth     # Anti-aliased rasterizer
1979fbd28219SIngo Weinhold                  sfnt       # SFNT-based format support routines
1980fbd28219SIngo Weinhold                  truetype   # TrueType font driver
1981fbd28219SIngo Weinhold                  type1      # Postscript Type 1 font driver
1982fbd28219SIngo Weinhold                  type42     # Postscript Type 42 (embedded TrueType) driver
1983fbd28219SIngo Weinhold                  winfonts   # Windows FON/FNT font driver
1984fbd28219SIngo Weinhold                  ;
1985fbd28219SIngo Weinhold
198621df5945SIngo Weinholdrule UseFreeTypeHeaders
198721df5945SIngo Weinhold{
198821df5945SIngo Weinhold	SubDirHdrs $(FT2_INCLUDE) ;
198921df5945SIngo Weinhold}
199021df5945SIngo Weinhold
199121df5945SIngo Weinholdrule UseFreeTypeObjectHeaders
199221df5945SIngo Weinhold{
19939b60a208SIngo Weinhold	# UseFreeTypeObjectHeaders <sources> [ : <objects> ] ;
19949b60a208SIngo Weinhold	SourceHdrs $(1) : $(FT2_INCLUDE) : $(2) ;
199521df5945SIngo Weinhold}
199621df5945SIngo Weinhold
199721df5945SIngo Weinholdrule FT2_SubDir
199821df5945SIngo Weinhold{
199921df5945SIngo Weinhold	# FT2_SubDir <dir>
200021df5945SIngo Weinhold	# <dir>: Components of a directory in the original hierarchy.
200121df5945SIngo Weinhold	local dir = $(1) ;
200221df5945SIngo Weinhold	local topDir ;
200321df5945SIngo Weinhold	switch $(dir[1])
200421df5945SIngo Weinhold	{
200521df5945SIngo Weinhold		case "include"	: topDir = $(FT2_INCLUDE) ;
200621df5945SIngo Weinhold		case src		: topDir = $(FT2_SRC) ;
200721df5945SIngo Weinhold		case *			: ECHO "Unknown FreeType2 directory: " $(dir) ;
200821df5945SIngo Weinhold	}
200921df5945SIngo Weinhold	return [ FDirName $(topDir) $(dir[2-]) ] ;
201021df5945SIngo Weinhold}
201121df5945SIngo Weinhold
201221df5945SIngo Weinholdrule FT2_Library
201321df5945SIngo Weinhold{
201421df5945SIngo Weinhold	# FT2_Library <libname> : <sources>
201521df5945SIngo Weinhold	# Builds objects from sources and adds the objects to the list of objects
201621df5945SIngo Weinhold	# to be linked into the library.
201721df5945SIngo Weinhold	# <libname> The name of the library.
201821df5945SIngo Weinhold	# <sources> The sources.
201921df5945SIngo Weinhold
202021df5945SIngo Weinhold	local library = lib$(1).so ;
202121df5945SIngo Weinhold	local sources = $(2) ;
202228d2a30eSDaniel Reinhold	SetupIncludes ;
202321df5945SIngo Weinhold	SetupObjectsDir ;
202421df5945SIngo Weinhold	MakeLocateObjects $(sources) ;
202521df5945SIngo Weinhold	Objects $(sources) ;
202621df5945SIngo Weinhold	LIBRARY_OBJECTS on $(library) += [ FGristFiles $(sources:S=$(SUFOBJ)) ] ;
202721df5945SIngo Weinhold}
202821df5945SIngo Weinhold
202921df5945SIngo Weinholdrule FT2_LinkLibrary
203021df5945SIngo Weinhold{
203121df5945SIngo Weinhold	# FT2_LinkLibrary <libname>
203221df5945SIngo Weinhold	# Links the library from the objects build with FT2_LIBRARY before.
203321df5945SIngo Weinhold
203421df5945SIngo Weinhold	local library = lib$(1).so ;
203521df5945SIngo Weinhold	local objects = [ on $(library) return $(LIBRARY_OBJECTS) ] ;
203621df5945SIngo Weinhold	ObjectReferences $(objects) ;
203721df5945SIngo Weinhold	objects = [ FGristFiles $(objects) ] ;
203821df5945SIngo Weinhold	SharedLibraryFromObjects $(1) : $(objects) ;
203921df5945SIngo Weinhold}
204021df5945SIngo Weinhold
20419b7a4b5dSshatty#-------------------------------------------------------------------------------
20429b7a4b5dSshatty# Packages for OBOS alpha/beta testers
20439b7a4b5dSshatty#-------------------------------------------------------------------------------
20449b7a4b5dSshatty
20459b7a4b5dSshattyrule Copy
20469b7a4b5dSshatty{
20475c413522Sshatty	Depends $(<) : $(>) ;
20489b7a4b5dSshatty	SEARCH on $(>) = $(SEARCH_SOURCE) ;
20499b7a4b5dSshatty}
20509b7a4b5dSshatty
20519b7a4b5dSshattyactions Copy
20529b7a4b5dSshatty{
205315716fddSPhilippe Houdoin	cp -dp "$(>)" "$(<)" ;
205415716fddSPhilippe Houdoin	if [ -f "$(>)" ] ; then copyattr "$(>)" "$(<)" ; fi ;
20559b7a4b5dSshatty}
20569b7a4b5dSshatty
20579b7a4b5dSshattyrule Packages
20589b7a4b5dSshatty{
20599b7a4b5dSshatty	local packagenames = $(1) ;
20609b7a4b5dSshatty	local packagefiles = $(2) ;
20619b7a4b5dSshatty	local path = $(3) ;
20629b7a4b5dSshatty	for name in $(packagenames) {
20639b7a4b5dSshatty		Package $(name) : $(packagefiles) : $(path) ;
20649b7a4b5dSshatty    }
20659b7a4b5dSshatty}
20669b7a4b5dSshatty
20679b7a4b5dSshattyrule Package
20689b7a4b5dSshatty{
20699b7a4b5dSshatty	local packagename = $(1) ;
20709b7a4b5dSshatty    local packagefiles = $(2) ;
20719b7a4b5dSshatty	local path = $(3) ;
20729b7a4b5dSshatty
2073c06f365fSIngo Weinhold	local packagezip = $(packagename:S=.zip:G=_packages) ;
20749b7a4b5dSshatty	local packagedir = [ FDirName $(OBOS_PACKAGE_DIR) $(packagename) ] ;
20759b7a4b5dSshatty
20769b7a4b5dSshatty    local installscript = install.sh ;
2077c06f365fSIngo Weinhold	local packageinstallscript = $(installscript:G=_packages!$(packagename)) ;
20789b7a4b5dSshatty    local installzip = install.zip ;
2079c06f365fSIngo Weinhold	local packageinstallzip = $(installzip:G=_packages!$(packagename)) ;
20809b7a4b5dSshatty
2081c06f365fSIngo Weinhold    local packageobjectdir
2082c06f365fSIngo Weinhold    	= [ FDirName $(OBOS_PACKAGE_OBJECT_DIR) $(packagename) ] ;
20839b7a4b5dSshatty	local packagefiledir =  [ FDirName $(packageobjectdir) $(path) ] ;
2084c06f365fSIngo Weinhold    local packagefileinstallzip
2085c06f365fSIngo Weinhold    	= $(installzip:G=_package_objects!$(packagename)) ;
2086c06f365fSIngo Weinhold
2087c06f365fSIngo Weinhold	# add the files to the install.zip
2088c06f365fSIngo Weinhold	local packagefilegrist = [ FGrist _package_files $(packagename) $(path) ] ;
20899b7a4b5dSshatty    for file in $(packagefiles) {
20909b7a4b5dSshatty		if $(3[0]) = "boot" {
2091c06f365fSIngo Weinhold			local packagefile = $(file:G=$(packagefilegrist)) ;
20929b7a4b5dSshatty			MakeLocate $(packagefile) : $(packagefiledir) ;
20939b7a4b5dSshatty			Copy $(packagefile) : $(file) ;
20949b7a4b5dSshatty			Clean cleanPackages : $(packagefile) ;
20959b7a4b5dSshatty			PackageInstallZip $(packagefileinstallzip) : $(packagefile) ;
20969b7a4b5dSshatty		} else {
2097c06f365fSIngo Weinhold			local packagefile = $(file:G=_packages!$(packagename)) ;
20989b7a4b5dSshatty			MakeLocate $(packagefile) : $(packagedir) ;
209982bec102Sshatty			Copy $(packagefile) : [ FGristFiles $(file) ] ;
21009b7a4b5dSshatty			Clean cleanPackages : $(packagefile) ;
21019b7a4b5dSshatty			Depends $(packagezip) : $(packagefile) ;
21029b7a4b5dSshatty		}
21039b7a4b5dSshatty	}
2104c06f365fSIngo Weinhold
2105c06f365fSIngo Weinhold	# general setup for this packages -- only on first invocation
2106c06f365fSIngo Weinhold	if ! $(_setup_$(packagename)) {
2107c06f365fSIngo Weinhold		_setup_$(packagename) = true ;
2108c06f365fSIngo Weinhold
2109c06f365fSIngo Weinhold		NotFile $(packagename) ;
2110c06f365fSIngo Weinhold		Depends packages : $(packagename) ;
2111c06f365fSIngo Weinhold
2112c06f365fSIngo Weinhold		MakeLocate $(packagezip) : $(OBOS_PACKAGE_DIR) ;
2113c06f365fSIngo Weinhold		MakeLocate $(packageinstallscript) : $(packagedir) ;
2114c06f365fSIngo Weinhold		MakeLocate $(packageinstallzip) : $(packagedir) ;
2115c06f365fSIngo Weinhold		MakeLocate $(packagefileinstallzip) : $(packageobjectdir) ;
2116c06f365fSIngo Weinhold
21179b7a4b5dSshatty		PackageInstallScript $(packageinstallscript) : $(packagedir) ;
21189b7a4b5dSshatty		LinkInstallZip $(packageinstallzip) : $(packagefileinstallzip) ;
21199b7a4b5dSshatty		Depends $(packagename) : $(packagezip) ;
2120c06f365fSIngo Weinhold		PackageZip $(packagezip) : $(packagedir)
2121c06f365fSIngo Weinhold			: $(packageinstallscript) $(packageinstallzip) ;
2122c06f365fSIngo Weinhold	}
2123c06f365fSIngo Weinhold
21249b7a4b5dSshatty}
21259b7a4b5dSshatty
21269b7a4b5dSshattyrule PackageZip
21279b7a4b5dSshatty{
2128c06f365fSIngo Weinhold	local dir = $(2:G=dir) ;
2129c06f365fSIngo Weinhold	Depends $(1) : $(dir) $(3) ;
21309b7a4b5dSshatty	Clean cleanPackages : $(1) ;
2131c06f365fSIngo Weinhold	PackageZip1 $(1) : $(dir) ;
21329b7a4b5dSshatty}
21339b7a4b5dSshatty
2134c06f365fSIngo Weinholdactions together PackageZip1 {
21358042d2a0SPhilippe Houdoin	cd "$(OBOS_PACKAGE_DIR)" ;
21368042d2a0SPhilippe Houdoin	zip -rq "$(1:BS)" "$(2:BS)" ;
21379b7a4b5dSshatty}
21389b7a4b5dSshatty
21399b7a4b5dSshattyrule PackageInstallScript
21409b7a4b5dSshatty{
21419b7a4b5dSshatty	MakeLocate $(1) : $(2) ;
21429b7a4b5dSshatty	Clean cleanPackages : $(1) ;
2143c06f365fSIngo Weinhold	PackageInstallScript1 $(1) : $(2:G=dir) ;
21449b7a4b5dSshatty}
21459b7a4b5dSshatty
2146c06f365fSIngo Weinholdactions together PackageInstallScript1
21479b7a4b5dSshatty{
214851fe1be4Sshattyecho '#!/bin/sh
214951fe1be4Sshattybase=`dirname "$0"`
21508042d2a0SPhilippe Houdoincd "$base"
215151fe1be4Sshattyif [ -n "$TTY" ]
215251fe1be4Sshattythen
215351fe1be4Sshatty    unzip -d / install.zip
215451fe1be4Sshattyelse
215551fe1be4Sshatty    response=`alert "Would you like to automatically overwrite existing files, or receive a prompt?" "Overwrite" "Prompt"`
215651fe1be4Sshatty    if [ $response == "Overwrite" ]
215751fe1be4Sshatty    then
215851fe1be4Sshatty        unzip -od / install.zip
215951fe1be4Sshatty        alert "Finished installing" "Thanks"
216051fe1be4Sshatty    else
216151fe1be4Sshatty        if [ -e /boot/beos/apps/Terminal ]
216251fe1be4Sshatty        then
216351fe1be4Sshatty            terminal=/boot/beos/apps/Terminal
216451fe1be4Sshatty        else
216551fe1be4Sshatty            terminal=`query Terminal | head -1`
216651fe1be4Sshatty        fi
21678042d2a0SPhilippe Houdoin        $terminal -t "installer" /bin/sh "$0"
216851fe1be4Sshatty    fi
21698042d2a0SPhilippe Houdoinfi' > "$(1)" ;
21708042d2a0SPhilippe Houdoin	chmod 755 "$(1)" ;
21719b7a4b5dSshatty}
21729b7a4b5dSshatty
21739b7a4b5dSshattyrule PackageInstallZip
21749b7a4b5dSshatty{
21759b7a4b5dSshatty	Depends $(1) : $(2) ;
21769b7a4b5dSshatty	Clean cleanPackages : $(1) ;
21779b7a4b5dSshatty}
21789b7a4b5dSshatty
21799b7a4b5dSshattyactions together PackageInstallZip
21809b7a4b5dSshatty{
21818042d2a0SPhilippe Houdoin	cd "$(1:P)" ;
21828042d2a0SPhilippe Houdoin	zip -rqy "$(1:BS)" boot ;
21839b7a4b5dSshatty}
21849b7a4b5dSshatty
21859b7a4b5dSshattyrule LinkInstallZip
21869b7a4b5dSshatty{
21879b7a4b5dSshatty	Depends $(1) : $(2) ;
21889b7a4b5dSshatty	Clean cleanPackages : $(1) ;
21899b7a4b5dSshatty}
21909b7a4b5dSshatty
21919b7a4b5dSshattyactions together LinkInstallZip
21929b7a4b5dSshatty{
21938042d2a0SPhilippe Houdoin	ln -sf "`pwd`/$(2)" "$(1)" ;
21949b7a4b5dSshatty}
2195e91f3ca1Sbeveloper
2196e91f3ca1Sbeveloperrule SubIncludeGPL
2197e91f3ca1Sbeveloper{
2198e91f3ca1Sbeveloper	# SubInclude rule that can be used to conditionally include GPL licensed add-ons
2199e91f3ca1Sbeveloper	if $(INCLUDE_GPL_ADDONS) = 1 {
2200e91f3ca1Sbeveloper		SubInclude $(1) ;
2201e91f3ca1Sbeveloper	}
2202e91f3ca1Sbeveloper}
2203