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 299eea4522SIngo Weinhold 3052a38012Sejakowatz# Include BuildConfig 3152a38012Sejakowatz{ 3252a38012Sejakowatz local buildConfig = [ GLOB $(OBOS_TOP) : BuildConfig ] ; 3352a38012Sejakowatz if ! $(buildConfig) 3452a38012Sejakowatz { 3552a38012Sejakowatz EXIT "No BuildConfig!" 3652a38012Sejakowatz "Run ./configure in the source tree's root directory first!" ; 3752a38012Sejakowatz } 3852a38012Sejakowatz include $(buildConfig) ; 3952a38012Sejakowatz} 4052a38012Sejakowatz 4152a38012Sejakowatz# Determine if we're building on PPC or x86 4252a38012Sejakowatz# Determine mimetype of executable 4352a38012Sejakowatz# Cross compiling can come later 4452a38012Sejakowatz 4552a38012Sejakowatzif $(METROWERKS) { 4678599cf0SIngo Weinhold OBOS_TARGET ?= "ppc.R1" ; 4752a38012Sejakowatz OBOS_TARGET_TYPE ?= "application/x-be-executable" ; 4852a38012Sejakowatz OBOS_ARCH ?= "ppc" ; 4952a38012Sejakowatz OBOS_TARGET_DEFINE ?= "ARCH_ppc" ; 5052a38012Sejakowatz} else { 5178599cf0SIngo Weinhold OBOS_TARGET ?= "x86.R1" ; 5252a38012Sejakowatz OBOS_TARGET_TYPE ?= "application/x-vnd.Be-elfexecutable" ; 5352a38012Sejakowatz OBOS_ARCH ?= "x86" ; 5452a38012Sejakowatz OBOS_TARGET_DEFINE ?= "ARCH_x86" ; 5552a38012Sejakowatz OBOS_TARGET_DIR ?= "x86" ; 5652a38012Sejakowatz} 5752a38012Sejakowatz 58e5dc2d93Sbeveloper# Enable warnings only if WARNINGS is defined 59e5dc2d93Sbeveloper# Should be enabled by default later 6096d27465SIngo Weinhold# 61e5dc2d93Sbeveloperif $(WARNINGS) { 62e5dc2d93Sbeveloper # For an explanation of the different warning options, see: 63e5dc2d93Sbeveloper # http://gcc.gnu.org/onlinedocs/gcc-2.95.3/gcc_2.html 64e5dc2d93Sbeveloper # to get even more warnings, add: 65e5dc2d93Sbeveloper # -Wwrite-strings (doesn't work well with some Be headers) 66e5dc2d93Sbeveloper # -Wundef (dito) 67e5dc2d93Sbeveloper # -Wconversion (gets you many warnings about implicit conversions) 68e5dc2d93Sbeveloper # -W (gets you even more warnigs) 69e5dc2d93Sbeveloper CCFLAGS ?= "-Wall -Wno-multichar -Wmissing-prototypes" ; 70e5dc2d93Sbeveloper CCFLAGS += "-Wpointer-arith -Wcast-align -Wsign-compare" ; 71e5dc2d93Sbeveloper C++FLAGS ?= "-Wall -Wno-multichar -Wmissing-prototypes -Wno-ctor-dtor-privacy -Woverloaded-virtual" ; 72e5dc2d93Sbeveloper C++FLAGS += "-Wpointer-arith -Wcast-align -Wsign-compare" ; 73e5dc2d93Sbeveloper} 74e5dc2d93Sbeveloper 759eea4522SIngo Weinhold# We might later want to introduce debug levels or handle the whole issue 769eea4522SIngo Weinhold# differently. For now there's only on or off. 779eea4522SIngo Weinhold# 789eea4522SIngo Weinholdif $(DEBUG) { 799eea4522SIngo Weinhold OPTIM ?= -O0 ; 809eea4522SIngo Weinhold CCFLAGS += -g ; 819eea4522SIngo Weinhold C++FLAGS += -g ; 829eea4522SIngo Weinhold LINKFLAGS += -g ; 839eea4522SIngo Weinhold} else { 849eea4522SIngo Weinhold OPTIM ?= -O2 ; 859eea4522SIngo Weinhold} 8696d27465SIngo Weinhold# 8796d27465SIngo Weinhold# To disable for the tests OPTIM and DEBUG are overridden, set the environment 8896d27465SIngo Weinhold# variable NO_TEST_DEBUG. 899eea4522SIngo Weinhold 9052a38012SejakowatzKERNEL_CCFLAGS ?= "-Wall -Wno-multichar -Wmissing-prototypes -finline -nostdinc" ; 9152a38012SejakowatzKERNEL_CCFLAGS += "-fno-builtin -D$(OBOS_TARGET_DEFINE) " ; 922b94bc7bSlilloKERNEL_CCFLAGS += "-DBOCHS_E9_HACK=$(BOCHS_E9_HACK) " ; 93b1b72e87SBruno G. AlbuquerqueKERNEL_CCFLAGS += "-DBOCHS_INPUT_HACK=$(BOCHS_INPUT_HACK) " ; 9452a38012Sejakowatz 9516fa4445SIngo Weinhold# Instructs the Library rule to not make its object files temporary. 9616fa4445SIngo Weinhold# This is need as some objects are used in a static library and for an 9716fa4445SIngo Weinhold# executable. 9816fa4445SIngo WeinholdKEEPOBJS = true ; 9916fa4445SIngo Weinhold 10052a38012SejakowatzAR = ar r ; 10152a38012Sejakowatz 10252a38012Sejakowatz# If no OBOS_OBJECT_TARGET is not defined yet, use our default directory and 10352a38012Sejakowatz# include our "OBOS_TARGET" as subdirectory in there (to prevent different 10452a38012Sejakowatz# builds mixing objects from different targets). 10552a38012Sejakowatzif ! $(OBOS_OBJECT_TARGET) { 10652a38012Sejakowatz OBOS_OBJECT_TARGET ?= [ FDirName $(OBOS_TOP) objects $(OBOS_TARGET) ] ; 10752a38012Sejakowatz} 10852a38012Sejakowatz 10952a38012Sejakowatz# If no OBOS_DISTRO_TARGET is not defined yet, use our default directory and 11052a38012Sejakowatz# include our "OBOS_TARGET" as subdirectory in there (to prevent different 11152a38012Sejakowatz# builds mixing executables from different targets). 11252a38012Sejakowatzif ! $(OBOS_DISTRO_TARGET) { 11352a38012Sejakowatz OBOS_DISTRO_TARGET ?= [ FDirName $(OBOS_TOP) distro $(OBOS_TARGET) ] ; 11452a38012Sejakowatz} 11552a38012Sejakowatz 11652a38012Sejakowatz# Set our version number if not already set and mark it as a developer build 11752a38012Sejakowatzif ! $(OBOS_BUILD_VERSION) { 11852a38012Sejakowatz OBOS_BUILD_VERSION ?= "1 0 0 a 1" ; 11952a38012Sejakowatz OBOS_BUILD_DESCRIPTION ?= "Developer Build" ; 12052a38012Sejakowatz} 12152a38012Sejakowatz 12252a38012Sejakowatz# If OBOS_BUILD_VERSION is set, but OBOS_BUILD_DESCRIPTION isn't, mark it as 12352a38012Sejakowatz# an unknown build. 12452a38012Sejakowatzif ! $(OBOS_BUILD_DESCRIPTION) { 12552a38012Sejakowatz OBOS_BUILD_DESCRIPTION ?= "Unknown Build" ; 12652a38012Sejakowatz} 12752a38012Sejakowatz 12852a38012Sejakowatz# Relative subdirs for distro dir (these are for *INTERNAL* use by the following rules only!) 1295f281ed5SejakowatzOBOS_APPS_DIR ?= [ FDirName $(OBOS_DISTRO_TARGET) beos apps ] ; 130f06de7f3SIngo WeinholdOBOS_BIN_DIR ?= [ FDirName $(OBOS_DISTRO_TARGET) beos bin ] ; 13152a38012SejakowatzOBOS_PREFS_DIR ?= [ FDirName $(OBOS_DISTRO_TARGET) beos preferences ] ; 13252a38012SejakowatzOBOS_SERVER_DIR ?= [ FDirName $(OBOS_DISTRO_TARGET) beos system servers ] ; 13352a38012SejakowatzOBOS_ADDON_DIR ?= [ FDirName $(OBOS_DISTRO_TARGET) beos system add-ons ] ; 13452a38012SejakowatzOBOS_SHLIB_DIR ?= [ FDirName $(OBOS_DISTRO_TARGET) beos system lib ] ; 13552a38012SejakowatzOBOS_STLIB_DIR ?= [ FDirName $(OBOS_DISTRO_TARGET) beos system lib ] ; 13652a38012SejakowatzOBOS_KERNEL_DIR ?= [ FDirName $(OBOS_DISTRO_TARGET) beos system ] ; 13752a38012SejakowatzOBOS_TEST_DIR ?= [ FDirName $(OBOS_TOP) tests ] ; 13852a38012Sejakowatz 13952a38012SejakowatzOBOS_KERNEL_CONFIG = config.$(OBOS_ARCH).ini ; 14052a38012SejakowatzOBOS_KERNEL = kernel.$(OBOS_ARCH) ; 14152a38012SejakowatzOBOS_FLOPPY = floppy.$(OBOS_ARCH) ; 14252a38012Sejakowatz 14352a38012Sejakowatzrule SetupIncludes 14452a38012Sejakowatz{ 14552a38012Sejakowatz OBOS_INCLUDES ?= . add-ons app be_apps device drivers game interface kernel mail media midi midi2 net opengl storage support translation ; 14652a38012Sejakowatz UsePublicHeaders $(OBOS_INCLUDES) ; 147d25a77b4SIngo Weinhold UsePosixHeaders ; 14852a38012Sejakowatz} 14952a38012Sejakowatz 15052a38012Sejakowatz#------------------------------------------------------------------------------- 15152a38012Sejakowatz# Things Jam needs in order to work :) 15252a38012Sejakowatz#------------------------------------------------------------------------------- 15352a38012Sejakowatz 15452a38012Sejakowatzrule UserObject 15552a38012Sejakowatz{ 15652a38012Sejakowatz switch $(2) 15752a38012Sejakowatz { 15852a38012Sejakowatz case *.S : assemble $(1) : $(2) ; 15908125d07SIngo Weinhold case *.o : return ; 16052a38012Sejakowatz case * : ECHO "unknown suffix on" $(2) ; 16152a38012Sejakowatz } 16252a38012Sejakowatz} 16352a38012Sejakowatz 16452a38012Sejakowatz# Override the default to give "prettier" command lines. 16552a38012Sejakowatzactions Cc 16652a38012Sejakowatz{ 1670931b8f9SIngo Weinhold $(CC) -c "$(2)" $(CCFLAGS) $(CCDEFS) $(CCHDRS) -o "$(1)" ; 16852a38012Sejakowatz} 16952a38012Sejakowatz 17052a38012Sejakowatzactions C++ 17152a38012Sejakowatz{ 1720931b8f9SIngo Weinhold $(C++) -c "$(2)" $(C++FLAGS) $(CCDEFS) $(CCHDRS) -o "$(1)" ; 17352a38012Sejakowatz} 17452a38012Sejakowatz 17552a38012Sejakowatz 17652a38012Sejakowatz#------------------------------------------------------------------------------- 17752a38012Sejakowatz# General High-level OBOS target rules 17852a38012Sejakowatz#------------------------------------------------------------------------------- 17952a38012Sejakowatz 1805f281ed5Sejakowatzrule App 1815f281ed5Sejakowatz{ 1825f281ed5Sejakowatz # App <name> : <sources> ; 1835f281ed5Sejakowatz SetupObjectsDir ; 1845f281ed5Sejakowatz Main $(<) : $(>) ; 1855f281ed5Sejakowatz MakeLocate $(<) : $(OBOS_APPS_DIR) ; 1865f281ed5Sejakowatz} 1875f281ed5Sejakowatz 188f06de7f3SIngo Weinholdrule BinCommand 189f06de7f3SIngo Weinhold{ 190f06de7f3SIngo Weinhold # BinCommand <name> : <sources> : <libraries> ; 191f06de7f3SIngo Weinhold SetupObjectsDir ; 192f06de7f3SIngo Weinhold Main $(1) : $(2) ; 193f06de7f3SIngo Weinhold MakeLocate $(1) : $(OBOS_BIN_DIR) ; 194f06de7f3SIngo Weinhold LinkSharedOSLibs $(1) : $(3) ; 195f06de7f3SIngo Weinhold} 196f06de7f3SIngo Weinhold 197f06de7f3SIngo Weinholdrule StdBinCommands 198f06de7f3SIngo Weinhold{ 199f06de7f3SIngo Weinhold # StdBinCommands <sources> : <libs> ; 200f06de7f3SIngo Weinhold local libs = $(2) ; 2019342c27aSIngo Weinhold local source ; 202f06de7f3SIngo Weinhold for source in $(1) 203f06de7f3SIngo Weinhold { 204f06de7f3SIngo Weinhold local target = $(source:S=) ; 205f06de7f3SIngo Weinhold target = [ FGristFiles $(target) ] ; 206f06de7f3SIngo Weinhold BinCommand $(target) : $(source) : $(libs) ; 207f06de7f3SIngo Weinhold } 208f06de7f3SIngo Weinhold} 209f06de7f3SIngo Weinhold 21052a38012Sejakowatzrule Preference 21152a38012Sejakowatz{ 21252a38012Sejakowatz # Preference <name> : <sources> ; 21352a38012Sejakowatz# SetupIncludes ; 21452a38012Sejakowatz SetupObjectsDir ; 21552a38012Sejakowatz Main $(<) : $(>) ; 21652a38012Sejakowatz MakeLocate $(<) : $(OBOS_PREFS_DIR) ; 21752a38012Sejakowatz} 21852a38012Sejakowatz 21952a38012Sejakowatzrule Server 22052a38012Sejakowatz{ 22152a38012Sejakowatz # Server <name> : <sources> ; 22252a38012Sejakowatz 223f63877e7SIngo Weinhold# SetupIncludes ; 22452a38012Sejakowatz SetupObjectsDir ; 22552a38012Sejakowatz Main $(<) : $(>) ; 22652a38012Sejakowatz MakeLocate $(<) : $(OBOS_SERVER_DIR) ; 22752a38012Sejakowatz} 22852a38012Sejakowatz 22952a38012Sejakowatz# test pseudo targets 23052a38012SejakowatzNOTFILE obostests ; 23152a38012SejakowatzNOTFILE r5tests ; 23252a38012Sejakowatz 233d1f6c38fSTyler Dauwalderrule CommonTestLib 234d1f6c38fSTyler Dauwalder{ 235c5ff4aa6STyler Dauwalder # CommonTestLib <target> : <sources> : <obos libraries> 2369285de51STyler Dauwalder # : <r5 libraries> : <test libraries> : <public headers>; 237d1f6c38fSTyler Dauwalder # Builds a unit test for both OBOS and R5 modules. 238d1f6c38fSTyler Dauwalder # <target> The name of the target. 239d1f6c38fSTyler Dauwalder # <sources> The list of sources. 240d1f6c38fSTyler Dauwalder # <obos libraries> A list of link libraries for the OBOS tests (as passed 241d1f6c38fSTyler Dauwalder # to LinkSharedOSLibs). 242d1f6c38fSTyler Dauwalder # <r5 libraries> A list of link libraries for the R5 tests (as passed 243d1f6c38fSTyler Dauwalder # to LinkSharedOSLibs). 2449285de51STyler Dauwalder # <test libraries> A list of link libraries for both OBOS tests and R5 tests 2459285de51STyler Dauwalder # that have a common name (i.e. specify libx.so and the OBOS tests will link 2469285de51STyler Dauwalder # to libx.so and the R5 tests will link to libx_r5.so). 247d1f6c38fSTyler Dauwalder # <public headers> A list of public header dirs (as passed to 248d1f6c38fSTyler Dauwalder # UsePublicHeaders). 249d1f6c38fSTyler Dauwalder 250c5ff4aa6STyler Dauwalder TestLib $(1) : $(2) : [ FDirName $(OBOS_TEST_DIR) unittester lib ] : $(3) $(5) : $(6) ; 251c5ff4aa6STyler Dauwalder R5TestLib $(1) : $(2) : [ FDirName $(OBOS_TEST_DIR) unittester_r5 lib ] : $(4) [ R5SharedLibraryNames $(5) ] ; 252d1f6c38fSTyler Dauwalder} 253d1f6c38fSTyler Dauwalder 254d1f6c38fSTyler Dauwalderrule TestLib 255d1f6c38fSTyler Dauwalder{ 256d1f6c38fSTyler Dauwalder # TestLib <target> : <sources> : <dest> : <libraries> : <public headers> 257d1f6c38fSTyler Dauwalder # Builds a unit test library for an OBOS module. 258d1f6c38fSTyler Dauwalder # <target> The name of the target. 259d1f6c38fSTyler Dauwalder # <sources> The list of sources. 260d1f6c38fSTyler Dauwalder # <dest> The directory for the target (as passed to FDirName). 261d1f6c38fSTyler Dauwalder # <libraries> A list of link libraries (as passed to LinkSharedOSLibs). 262d1f6c38fSTyler Dauwalder # <public headers> A list of public header dirs (as passed to 263d1f6c38fSTyler Dauwalder # UsePublicHeaders). 264d1f6c38fSTyler Dauwalder 265d1f6c38fSTyler Dauwalder local target = $(1) ; 266d1f6c38fSTyler Dauwalder local sources = $(2) ; 267d1f6c38fSTyler Dauwalder local dest = $(3) ; 268d1f6c38fSTyler Dauwalder local libraries = $(4) ; 269d1f6c38fSTyler Dauwalder local headerDirs = $(5) ; 2709342c27aSIngo Weinhold local objects = [ FGristFiles $(sources:S=$(SUFOBJ)) ] ; 271d1f6c38fSTyler Dauwalder 2729342c27aSIngo Weinhold # Our Main replacement. 2739342c27aSIngo Weinhold MainFromObjects $(target) : $(objects) ; 2749342c27aSIngo Weinhold TestObjects $(sources) : $(headerDirs) ; 275d1f6c38fSTyler Dauwalder 276d1f6c38fSTyler Dauwalder MakeLocate $(target) : $(dest) ; 2770d1cdd94SIngo Weinhold Depends $(target) : libcppunit.so ; 2780d1cdd94SIngo Weinhold Depends obostests : $(target) ; 279d1f6c38fSTyler Dauwalder LinkSharedOSLibs $(target) : libcppunit.so $(libraries) ; 280d1f6c38fSTyler Dauwalder LINKFLAGS on $(target) = $(LINKFLAGS) -nostart -Xlinker -soname=\"$(target)\" ; 281d1f6c38fSTyler Dauwalder} 282d1f6c38fSTyler Dauwalder 283d1f6c38fSTyler Dauwalderrule R5TestLib 284d1f6c38fSTyler Dauwalder{ 285c5ff4aa6STyler Dauwalder # R5TestLib <target> : <sources> : <dest> : <libraries> 286d1f6c38fSTyler Dauwalder # Builds a unit test for an R5 module. "_r5" is appended to the object 287d1f6c38fSTyler Dauwalder # and the target name. 288d1f6c38fSTyler Dauwalder # <target> The name of the target. 289d1f6c38fSTyler Dauwalder # <sources> The list of sources. 290d1f6c38fSTyler Dauwalder # <dest> The directory for the target (as passed to FDirName). 291d1f6c38fSTyler Dauwalder # <libraries> A list of link libraries (as passed to LinkSharedOSLibs). 292d1f6c38fSTyler Dauwalder 293d1f6c38fSTyler Dauwalder local target = $(1:B)_r5$(1:S) ; 294d1f6c38fSTyler Dauwalder local sources = $(2) ; 295c5ff4aa6STyler Dauwalder local dest = $(3) ; 296d1f6c38fSTyler Dauwalder local libraries = $(4) ; 297d1f6c38fSTyler Dauwalder local objects = [ R5ObjectNames $(sources) ] ; 298d1f6c38fSTyler Dauwalder 299d1f6c38fSTyler Dauwalder # Our Main replacement. 300d1f6c38fSTyler Dauwalder MainFromObjects $(target) : $(objects) ; 3019342c27aSIngo Weinhold TestObjects $(sources) : : true ; 302d1f6c38fSTyler Dauwalder 303d1f6c38fSTyler Dauwalder MakeLocate $(target) : $(dest) ; 3040d1cdd94SIngo Weinhold Depends $(target) : libcppunit.so ; 3050d1cdd94SIngo Weinhold Depends r5tests : $(target) ; 306d1f6c38fSTyler Dauwalder LinkSharedOSLibs $(target) : libcppunit.so $(libraries) ; 307d1f6c38fSTyler Dauwalder LINKFLAGS on $(target) = $(LINKFLAGS) -nostart -Xlinker -soname=\"$(target)\" ; 308d1f6c38fSTyler Dauwalder} 309d1f6c38fSTyler Dauwalder 31052a38012Sejakowatzrule CommonUnitTest 31152a38012Sejakowatz{ 31252a38012Sejakowatz # CommonUnitTest <target> : <sources> : <dest> : <obos libraries> 31352a38012Sejakowatz # : <r5 libraries> : <public headers>; 31452a38012Sejakowatz # Builds a unit test for both OBOS and R5 modules. 31552a38012Sejakowatz # <target> The name of the target. 31652a38012Sejakowatz # <sources> The list of sources. 31752a38012Sejakowatz # <dest> The directory for the target (as passed to FDirName). 31852a38012Sejakowatz # <obos libraries> A list of link libraries for the OBOS tests (as passed 31952a38012Sejakowatz # to LinkSharedOSLibs). 32052a38012Sejakowatz # <r5 libraries> A list of link libraries for the R5 tests (as passed 32152a38012Sejakowatz # to LinkSharedOSLibs). 32252a38012Sejakowatz # <public headers> A list of public header dirs (as passed to 32352a38012Sejakowatz # UsePublicHeaders). 32452a38012Sejakowatz 32552a38012Sejakowatz UnitTest $(1) : $(2) : $(3) : $(4) : $(6) ; 32652a38012Sejakowatz R5UnitTest $(1) : $(2) : $(3) : $(5) ; 32752a38012Sejakowatz} 32852a38012Sejakowatz 32952a38012Sejakowatzrule UnitTest 33052a38012Sejakowatz{ 33152a38012Sejakowatz # UnitTest <target> : <sources> : <dest> : <libraries> : <public headers> 33252a38012Sejakowatz # Builds a unit test for an OBOS module. 33352a38012Sejakowatz # <target> The name of the target. 33452a38012Sejakowatz # <sources> The list of sources. 33552a38012Sejakowatz # <dest> The directory for the target (as passed to FDirName). 33652a38012Sejakowatz # <libraries> A list of link libraries (as passed to LinkSharedOSLibs). 33752a38012Sejakowatz # <public headers> A list of public header dirs (as passed to 33852a38012Sejakowatz # UsePublicHeaders). 33952a38012Sejakowatz 34052a38012Sejakowatz local target = $(1) ; 34152a38012Sejakowatz local sources = $(2) ; 34252a38012Sejakowatz local dest = $(3) ; 34352a38012Sejakowatz local libraries = $(4) ; 34452a38012Sejakowatz local headerDirs = $(5) ; 3459342c27aSIngo Weinhold local objects = [ FGristFiles $(sources:S=$(SUFOBJ)) ] ; 34652a38012Sejakowatz 3479342c27aSIngo Weinhold # Our Main replacement. 3489342c27aSIngo Weinhold MainFromObjects $(target) : $(objects) ; 3499342c27aSIngo Weinhold TestObjects $(sources) : $(headerDirs) ; 3503b9eae39SIngo Weinhold 35152a38012Sejakowatz MakeLocate $(target) : [ FDirName $(OBOS_TEST_DIR) $(dest) ] ; 3529eea4522SIngo Weinhold Depends $(target) : libcppunit.so ; 3539eea4522SIngo Weinhold Depends obostests : $(target) ; 35452a38012Sejakowatz LinkSharedOSLibs $(target) : libcppunit.so $(libraries) ; 35552a38012Sejakowatz} 35652a38012Sejakowatz 35752a38012Sejakowatzrule R5UnitTest 35852a38012Sejakowatz{ 35952a38012Sejakowatz # R5UnitTest <target> : <sources> : <dest> : <libraries> 36052a38012Sejakowatz # Builds a unit test for an R5 module. "_r5" is appended to the object 36152a38012Sejakowatz # and the target name. 36252a38012Sejakowatz # <target> The name of the target. 36352a38012Sejakowatz # <sources> The list of sources. 36452a38012Sejakowatz # <dest> The directory for the target (as passed to FDirName). 36552a38012Sejakowatz # <libraries> A list of link libraries (as passed to LinkSharedOSLibs). 36652a38012Sejakowatz 36752a38012Sejakowatz local target = $(1)_r5 ; 36852a38012Sejakowatz local sources = $(2) ; 36952a38012Sejakowatz local dest = $(3) ; 37052a38012Sejakowatz local libraries = $(4) ; 37152a38012Sejakowatz local objects = [ R5ObjectNames $(sources) ] ; 37252a38012Sejakowatz 37352a38012Sejakowatz # Our Main replacement. 37452a38012Sejakowatz MainFromObjects $(target) : $(objects) ; 3759342c27aSIngo Weinhold TestObjects $(sources) : : true ; 37652a38012Sejakowatz 37752a38012Sejakowatz MakeLocate $(target) : [ FDirName $(OBOS_TEST_DIR) $(dest) ] ; 3789eea4522SIngo Weinhold Depends $(target) : libcppunit.so ; 3799eea4522SIngo Weinhold Depends r5tests : $(target) ; 38052a38012Sejakowatz LinkSharedOSLibs $(target) : libcppunit.so $(libraries) ; 38152a38012Sejakowatz} 38252a38012Sejakowatz 38352a38012Sejakowatzrule R5ObjectNames 38452a38012Sejakowatz{ 38552a38012Sejakowatz # R5ObjectNames <sources> ; 38652a38012Sejakowatz # Returns a list of gristed object names given a list of source file names. 38752a38012Sejakowatz # Moreover each object names gets "_r5" inserted before the object suffix. 38852a38012Sejakowatz local objects = $(1:S=)_r5 ; 38952a38012Sejakowatz return [ FGristFiles $(objects:S=$(SUFOBJ)) ] ; 39052a38012Sejakowatz} 39152a38012Sejakowatz 3929342c27aSIngo Weinholdrule R5Objects 3939342c27aSIngo Weinhold{ 3949342c27aSIngo Weinhold # R5Objects <sources> 3959342c27aSIngo Weinhold # Similar to Objects, but appends "_r5" to the object file names. 3969342c27aSIngo Weinhold # <sources> The source files. 3979342c27aSIngo Weinhold 3989342c27aSIngo Weinhold local sources = $(1) ; 3999342c27aSIngo Weinhold local source ; 4009342c27aSIngo Weinhold for source in [ FGristFiles $(sources) ] 4019342c27aSIngo Weinhold { 4029342c27aSIngo Weinhold local object = [ R5ObjectNames $(source) ] ; 4039342c27aSIngo Weinhold Object $(object) : $(source) ; 4049342c27aSIngo Weinhold LocalDepends obj : $(object) ; 4059342c27aSIngo Weinhold } 4069342c27aSIngo Weinhold} 4079342c27aSIngo Weinhold 4089342c27aSIngo Weinholdrule TestObjects 4099342c27aSIngo Weinhold{ 4109342c27aSIngo Weinhold # TestLib <sources> : <public headers> : <r5> 4119342c27aSIngo Weinhold # Compiles objects for tests. 4129342c27aSIngo Weinhold # <sources> The list of sources. 4139342c27aSIngo Weinhold # <public headers> A list of public header dirs (as passed to 4149342c27aSIngo Weinhold # UsePublicHeaders). 4159342c27aSIngo Weinhold # <r5> If set, "_r5" is appended to the object file names and 4169342c27aSIngo Weinhold # <public headers> is ignored. Furthermore the pre-processor macro 4179342c27aSIngo Weinhold # TEST_R5 is defined, TEST_OBOS otherwise. 4189342c27aSIngo Weinhold 4199342c27aSIngo Weinhold local sources = $(1) ; 4209342c27aSIngo Weinhold local headerDirs = $(2) ; 4219342c27aSIngo Weinhold local r5 = $(3) ; 4229342c27aSIngo Weinhold local objects ; 4239342c27aSIngo Weinhold 4249342c27aSIngo Weinhold # Turn optimization off. 42596d27465SIngo Weinhold if ! $(NO_TEST_DEBUG) { 4269342c27aSIngo Weinhold local optim = $(OPTIM) ; 4279342c27aSIngo Weinhold OPTIM = ; 42896d27465SIngo Weinhold } 4299342c27aSIngo Weinhold 4309342c27aSIngo Weinhold SetupObjectsDir ; 4319342c27aSIngo Weinhold 4329342c27aSIngo Weinhold # compile 4339342c27aSIngo Weinhold if $(r5) { 4349342c27aSIngo Weinhold objects = [ R5ObjectNames $(sources) ] ; 4359342c27aSIngo Weinhold R5Objects $(sources) ; 4369342c27aSIngo Weinhold } else { 4379342c27aSIngo Weinhold objects = [ FGristFiles $(sources:S=$(SUFOBJ)) ] ; 4389342c27aSIngo Weinhold Objects $(sources) ; 4399342c27aSIngo Weinhold } 4409342c27aSIngo Weinhold 4419342c27aSIngo Weinhold # set headers/defines 4429342c27aSIngo Weinhold UseCppUnitObjectHeaders $(objects) ; 4439342c27aSIngo Weinhold if $(r5) { 4449342c27aSIngo Weinhold ObjectDefines $(objects) : TEST_R5 ; 4459342c27aSIngo Weinhold } else { 4469342c27aSIngo Weinhold UsePublicObjectHeaders $(objects) : $(headerDirs) ; 4479342c27aSIngo Weinhold ObjectDefines $(objects) : TEST_OBOS ; 4489342c27aSIngo Weinhold } 4499342c27aSIngo Weinhold 45096d27465SIngo Weinhold if ! $(NO_TEST_DEBUG) { 4519342c27aSIngo Weinhold # Turn debugging on. That is usually desired for test code. 4529342c27aSIngo Weinhold ObjectCcFlags $(objects) : "-g" ; 4539342c27aSIngo Weinhold ObjectC++Flags $(objects) : "-g" ; 4549342c27aSIngo Weinhold 4559342c27aSIngo Weinhold # Turn optimization on again. 4569342c27aSIngo Weinhold OPTIM = $(optim) ; 4579342c27aSIngo Weinhold } 45896d27465SIngo Weinhold} 4599342c27aSIngo Weinhold 4609285de51STyler Dauwalderrule R5SharedLibraryNames 4619285de51STyler Dauwalder{ 4629285de51STyler Dauwalder # R5SharedLibraryNames <sources> ; 4639285de51STyler Dauwalder # Returns a list of shared library names given a list of file names. NO 4649285de51STyler Dauwalder # GRISTING IS PERFORMED :-) However, each library names gets "_r5" inserted 4659285de51STyler Dauwalder # before the shared lib suffix. 4669285de51STyler Dauwalder return $(1:S=)_r5.so ; 4679285de51STyler Dauwalder} 4689285de51STyler Dauwalder 4699fc6b2e1SIngo Weinholdrule SimpleTest 4709fc6b2e1SIngo Weinhold{ 4719fc6b2e1SIngo Weinhold # UnitTest <target> : <sources> : <libraries> 4729fc6b2e1SIngo Weinhold # Builds a unit test for an OBOS module. 4739fc6b2e1SIngo Weinhold # <target> The name of the target. 4749fc6b2e1SIngo Weinhold # <sources> The list of sources. 4759fc6b2e1SIngo Weinhold # <dest> The directory for the target (as passed to FDirName). 4769fc6b2e1SIngo Weinhold # <libraries> A list of link libraries (as passed to LinkSharedOSLibs). 4779fc6b2e1SIngo Weinhold # <public headers> A list of public header dirs (as passed to 4789fc6b2e1SIngo Weinhold # UsePublicHeaders). 4799fc6b2e1SIngo Weinhold 4809fc6b2e1SIngo Weinhold local target = $(1) ; 4819fc6b2e1SIngo Weinhold local sources = $(2) ; 4829fc6b2e1SIngo Weinhold local libraries = $(3) ; 4839fc6b2e1SIngo Weinhold local relPath = [ FRelPath src tests : $(SUBDIR_TOKENS) ] ; 4849fc6b2e1SIngo Weinhold 4859fc6b2e1SIngo Weinhold # Turn optimization off. 48696d27465SIngo Weinhold if ! $(NO_TEST_DEBUG) { 4879fc6b2e1SIngo Weinhold local optim = $(OPTIM) ; 4889fc6b2e1SIngo Weinhold OPTIM = ; 48996d27465SIngo Weinhold } 4909fc6b2e1SIngo Weinhold 4919fc6b2e1SIngo Weinhold# SetupIncludes ; 4929fc6b2e1SIngo Weinhold SetupObjectsDir ; 4939fc6b2e1SIngo Weinhold MakeLocateObjects $(sources) ; 4949fc6b2e1SIngo Weinhold Main $(target) : $(sources) ; 4959fc6b2e1SIngo Weinhold MakeLocate $(target) : [ FDirName $(OBOS_TEST_DIR) $(relPath) ] ; 4969eea4522SIngo Weinhold Depends obostests : $(target) ; 4979fc6b2e1SIngo Weinhold LinkSharedOSLibs $(target) : $(libraries) ; 4989fc6b2e1SIngo Weinhold ObjectDefines $(sources) : TEST_OBOS ; 4999fc6b2e1SIngo Weinhold 50096d27465SIngo Weinhold if ! $(NO_TEST_DEBUG) { 5019fc6b2e1SIngo Weinhold # Turn debugging on. That is usually desired for test code. 5029fc6b2e1SIngo Weinhold ObjectCcFlags $(sources) : "-g" ; 5039fc6b2e1SIngo Weinhold ObjectC++Flags $(sources) : "-g" ; 5049fc6b2e1SIngo Weinhold 5059fc6b2e1SIngo Weinhold # Turn optimization on again. 5069fc6b2e1SIngo Weinhold OPTIM = $(optim) ; 5079fc6b2e1SIngo Weinhold } 50896d27465SIngo Weinhold} 5099fc6b2e1SIngo Weinhold 51052a38012Sejakowatzrule Addon 51152a38012Sejakowatz{ 5127a384fdeSIngo Weinhold # Addon <name> : <relpath> : <sources> : <is executable> ; 5137a384fdeSIngo Weinhold # <name>: Name of the add-on. 5147a384fdeSIngo Weinhold # <relpath>: Path where the add-on shall live relative to the add-on dir. 5157a384fdeSIngo Weinhold # <sources>: Source files. 5167a384fdeSIngo Weinhold # <is executable>: true, if the target shall be executable as well 5177a384fdeSIngo Weinhold 5187a384fdeSIngo Weinhold local isExecutable = $(4) ; 51952a38012Sejakowatz 5207d7f280eSIngo Weinhold# SetupIncludes ; 52152a38012Sejakowatz SetupObjectsDir ; 52252a38012Sejakowatz Main $(1) : $(3) ; 52352a38012Sejakowatz 52452a38012Sejakowatz # Create output dir path for addon 52552a38012Sejakowatz local targetdir; 52652a38012Sejakowatz targetdir = [ FDirName $(OBOS_ADDON_DIR) $(2) ] ; 52752a38012Sejakowatz 52852a38012Sejakowatz MakeLocate $(1) : $(targetdir) ; 5297a384fdeSIngo Weinhold 5307a384fdeSIngo Weinhold local linkFlags = -Xlinker -soname=\"$(1)\" ; 5317a384fdeSIngo Weinhold if $(isExecutable) != true { 5327a384fdeSIngo Weinhold linkFlags = -nostart $(linkFlags) ; 5337a384fdeSIngo Weinhold } 5347a384fdeSIngo Weinhold LINKFLAGS on $(1) = [ on $(1) return $(LINKFLAGS) ] $(linkFlags) ; 535af28904fSIngo Weinhold} 536af28904fSIngo Weinhold 53758efc9d8SIngo Weinholdrule R5KernelAddon 538af28904fSIngo Weinhold{ 53958efc9d8SIngo Weinhold # R5KernelAddon <name> : <relpath> : <sources> ; 540af28904fSIngo Weinhold 541af28904fSIngo Weinhold local sources = $(3) ; 542af28904fSIngo Weinhold 543af28904fSIngo Weinhold Addon $(1) : $(2) : $(3) ; 544af28904fSIngo Weinhold ObjectCcFlags $(sources) : -D_KERNEL_MODE=1 -no-fpic ; 545af28904fSIngo Weinhold ObjectC++Flags $(sources) : -D_KERNEL_MODE=1 -no-fpic 546af28904fSIngo Weinhold -fno-exceptions -fno-rtti ; 5479eea4522SIngo Weinhold LINKFLAGS on $(1) = [ on $(1) return $(LINKFLAGS) ] -nostdlib ; 548af28904fSIngo Weinhold LinkSharedOSLibs $(1) : /boot/develop/lib/x86/_KERNEL_ ; 54952a38012Sejakowatz} 55052a38012Sejakowatz 5514fb5add0SMatthew Wilberrule Translator 5524fb5add0SMatthew Wilber{ 5534fb5add0SMatthew Wilber # Translator <name> : <sources> ; 5544fb5add0SMatthew Wilber SetupObjectsDir ; 5554fb5add0SMatthew Wilber Main $(1) : $(2) ; 5564fb5add0SMatthew Wilber 5574fb5add0SMatthew Wilber # Create output dir path for translator 5584fb5add0SMatthew Wilber local targetdir; 5594fb5add0SMatthew Wilber targetdir = [ FDirName $(OBOS_ADDON_DIR) translators ] ; 5604fb5add0SMatthew Wilber MakeLocate $(1) : $(targetdir) ; 5614fb5add0SMatthew Wilber} 5624fb5add0SMatthew Wilber 56352a38012Sejakowatzrule MakeLocateObjects 56452a38012Sejakowatz{ 56552a38012Sejakowatz # MakeLocateObjects <gristed_sources_or_objects> ; 56652a38012Sejakowatz 56752a38012Sejakowatz local _objs = $(1:S=$(SUFOBJ)) ; 56852a38012Sejakowatz 56952a38012Sejakowatz for o in $(_objs) 57052a38012Sejakowatz { 57152a38012Sejakowatz local dir = $(o:D) ; 57252a38012Sejakowatz if $(dir) { 57352a38012Sejakowatz MakeLocate $(o) : [ FDirName $(LOCATE_TARGET) $(dir) ] ; 57452a38012Sejakowatz } else { 57552a38012Sejakowatz MakeLocate $(o) : $(LOCATE_TARGET) ; 57652a38012Sejakowatz } 57752a38012Sejakowatz } 57852a38012Sejakowatz} 57952a38012Sejakowatz 58052a38012Sejakowatzrule StaticLibrary 58152a38012Sejakowatz{ 58252a38012Sejakowatz # StaticLibrary <name> : <sources> ; 58352a38012Sejakowatz 58408125d07SIngo Weinhold# SetupIncludes ; 58552a38012Sejakowatz SetupObjectsDir ; 58652a38012Sejakowatz MakeLocateObjects $(2) ; 58752a38012Sejakowatz Library lib$(<).a : $(>) ; 58852a38012Sejakowatz MakeLocate lib$(<).a : $(OBOS_STLIB_DIR) ; 58952a38012Sejakowatz} 59052a38012Sejakowatz 59152a38012Sejakowatzrule SharedLibrary 59252a38012Sejakowatz{ 59352a38012Sejakowatz # SharedLibrary <name> : <sources> ; 59452a38012Sejakowatz local _lib = lib$(1).so ; 59552a38012Sejakowatz 59652a38012Sejakowatz# SetupIncludes ; 59752a38012Sejakowatz SetupObjectsDir ; 59852a38012Sejakowatz MakeLocateObjects $(2) ; 59952a38012Sejakowatz Main $(_lib) : $(2) ; 60052a38012Sejakowatz MakeLocate $(_lib) : $(OBOS_SHLIB_DIR) ; 6019eea4522SIngo Weinhold LINKFLAGS on $(_lib) = [ on $(_lib) return $(LINKFLAGS) ] 6029eea4522SIngo Weinhold -nostart -Xlinker -soname=\"$(_lib)\" ; 60352a38012Sejakowatz} 60452a38012Sejakowatz 60552a38012Sejakowatzrule LinkSharedOSLibs 60652a38012Sejakowatz{ 60752a38012Sejakowatz # LinkSharedOSLibs <name> : <libs> ; 60852a38012Sejakowatz # Valid elements for <libs> are e.g. "be" or "libopenbeos.so" or 6094236d490SIngo Weinhold # "/boot/.../libfoo.so". If the basename starts with "lib" or the thingy 6104236d490SIngo Weinhold # has a dirname or grist, it is added to the NEEDLIBS variable (i.e. the 6114236d490SIngo Weinhold # file will be bound!), otherwise it is prefixed "-l" and added to 6124236d490SIngo Weinhold # LINKLIBS. 61352a38012Sejakowatz 61452a38012Sejakowatz for i in $(>) 61552a38012Sejakowatz { 6164236d490SIngo Weinhold local isfile = ; 6174236d490SIngo Weinhold if $(i:D) || $(i:G) { 6184236d490SIngo Weinhold isfile = true ; 6194236d490SIngo Weinhold } else { 62052a38012Sejakowatz switch $(i:B) 62152a38012Sejakowatz { 6224236d490SIngo Weinhold case lib* : isfile = true ; 6234236d490SIngo Weinhold case * : isfile = ; 6244236d490SIngo Weinhold } 6254236d490SIngo Weinhold } 6264236d490SIngo Weinhold if $(isfile) { 6279eea4522SIngo Weinhold NEEDLIBS on $(1) = [ on $(1) return $(NEEDLIBS) ] $(i) ; 6289eea4522SIngo Weinhold Depends $(1) : $(i) ; 6294236d490SIngo Weinhold } else { 6309eea4522SIngo Weinhold LINKLIBS on $(1) = [ on $(1) return $(LINKLIBS) ] -l$(i) ; 63152a38012Sejakowatz } 63252a38012Sejakowatz } 63352a38012Sejakowatz} 63452a38012Sejakowatz 63552a38012Sejakowatzrule LinkStaticOSLibs 63652a38012Sejakowatz{ 63752a38012Sejakowatz # LinkStaticOSLibs <name> : <libs> ; 63852a38012Sejakowatz 63952a38012Sejakowatz for i in $(>) 64052a38012Sejakowatz { 64152a38012Sejakowatz LINKLIBS on $(<) = $(LINKLIBS) -l $(i) ; 64252a38012Sejakowatz } 64352a38012Sejakowatz} 64452a38012Sejakowatz 64552a38012Sejakowatzrule AddResources 64652a38012Sejakowatz{ 64752a38012Sejakowatz # AddResources <name> : <resourcefiles> ; 64852a38012Sejakowatz 6499fc6b2e1SIngo Weinhold SEARCH on $(2) += $(SEARCH_SOURCE) ; 65078599cf0SIngo Weinhold RESFILES on $(1) += $(2) ; 65152a38012Sejakowatz} 65252a38012Sejakowatz 6537d7f280eSIngo Weinholdrule PublicHeaders 65452a38012Sejakowatz{ 6557d7f280eSIngo Weinhold # PublicHeaders <group list> 65652a38012Sejakowatz # 6577d7f280eSIngo Weinhold # Returns the directory names for the public header dirs identified by 6587d7f280eSIngo Weinhold # <group list>. 65952a38012Sejakowatz 66052a38012Sejakowatz local list = $(1) ; 661b005dbe3SAxel Dörfler local dirs = [ FDirName $(OBOS_TOP) headers os ] ; 662b005dbe3SAxel Dörfler 66352a38012Sejakowatz for i in $(list) { 6647d7f280eSIngo Weinhold dirs += [ FDirName $(OBOS_TOP) headers os $(i) ] ; 6657d7f280eSIngo Weinhold } 6667d7f280eSIngo Weinhold return $(dirs) ; 66752a38012Sejakowatz} 66852a38012Sejakowatz 6697d7f280eSIngo Weinholdrule PrivateHeaders 6707d7f280eSIngo Weinhold{ 6717d7f280eSIngo Weinhold # PrivateHeaders <group list> 6727d7f280eSIngo Weinhold # 6737d7f280eSIngo Weinhold # Returns the directory names for the private header dirs identified by 6747d7f280eSIngo Weinhold # <group list>. 6757d7f280eSIngo Weinhold 6767d7f280eSIngo Weinhold local list = $(1) ; 6777d7f280eSIngo Weinhold local dirs ; 6787d7f280eSIngo Weinhold for i in $(list) { 6797d7f280eSIngo Weinhold dirs += [ FDirName $(OBOS_TOP) headers private $(i) ] ; 6807d7f280eSIngo Weinhold } 6817d7f280eSIngo Weinhold return $(dirs) ; 6827d7f280eSIngo Weinhold} 6837d7f280eSIngo Weinhold 6847d7f280eSIngo Weinholdrule ArchHeaders 6857d7f280eSIngo Weinhold{ 6867d7f280eSIngo Weinhold # usage: ArchHeaders <arch> ; 6877d7f280eSIngo Weinhold # 6887d7f280eSIngo Weinhold # <arch> specifies the architecture (e.g. x86). 6897d7f280eSIngo Weinhold 6907d7f280eSIngo Weinhold return [ FDirName $(OBOS_TOP) headers private kernel arch $(1) ] ; 6917d7f280eSIngo Weinhold} 6927d7f280eSIngo Weinhold 6937d7f280eSIngo Weinholdrule UsePublicHeaders 6947d7f280eSIngo Weinhold{ 6957d7f280eSIngo Weinhold # UsePublicHeaders <group list> ; 6967d7f280eSIngo Weinhold # 6977d7f280eSIngo Weinhold # Adds the public C header dirs given by <group list> to the header search 6987d7f280eSIngo Weinhold # dirs of the subdirectory. 6997d7f280eSIngo Weinhold # NOTE: This rule must be invoked *before* the rule that builds the objects. 7007d7f280eSIngo Weinhold 7017d7f280eSIngo Weinhold UseHeaders [ PublicHeaders $(1) ] ; 7027d7f280eSIngo Weinhold} 7037d7f280eSIngo Weinhold 7047d7f280eSIngo Weinholdrule UsePublicObjectHeaders 7057d7f280eSIngo Weinhold{ 7067d7f280eSIngo Weinhold # UsePublicObjectHeaders <sources_or_objects> : <group list> ; 7077d7f280eSIngo Weinhold # 7087d7f280eSIngo Weinhold # Adds the public C header dirs given by <group list> to the header search 7097d7f280eSIngo Weinhold # dirs of <sources_or_objects>. 7107d7f280eSIngo Weinhold # NOTE: This rule must be invoked *after* the rule that builds the objects. 7117d7f280eSIngo Weinhold 7127d7f280eSIngo Weinhold ObjectHdrs $(1) : [ PublicHeaders $(2) ] ; 71352a38012Sejakowatz} 71452a38012Sejakowatz 71552a38012Sejakowatzrule UsePrivateHeaders 71652a38012Sejakowatz{ 7177d7f280eSIngo Weinhold # UsePrivateHeaders <group list> ; 71852a38012Sejakowatz # 71952a38012Sejakowatz # Adds the private C header dirs given by <group list> to the header search 7207d7f280eSIngo Weinhold # dirs of the subdirectory. 7217d7f280eSIngo Weinhold # NOTE: This rule must be invoked *before* the rule that builds the objects. 72252a38012Sejakowatz 7237d7f280eSIngo Weinhold UseHeaders [ PrivateHeaders $(1) ] ; 72452a38012Sejakowatz} 72552a38012Sejakowatz 7267d7f280eSIngo Weinholdrule UsePrivateObjectHeaders 7277d7f280eSIngo Weinhold{ 7287d7f280eSIngo Weinhold # UsePrivateObjectHeaders <sources_or_objects> : <group list> ; 7297d7f280eSIngo Weinhold # 7307d7f280eSIngo Weinhold # Adds the private C header dirs given by <group list> to the header search 7317d7f280eSIngo Weinhold # dirs of <sources_or_objects>. 7327d7f280eSIngo Weinhold # NOTE: This rule must be invoked *after* the rule that builds the objects. 7337d7f280eSIngo Weinhold 7347d7f280eSIngo Weinhold ObjectHdrs $(1) : [ PrivateHeaders $(2) ] ; 73552a38012Sejakowatz} 73652a38012Sejakowatz 73752a38012Sejakowatzrule UseHeaders 73852a38012Sejakowatz{ 7397d7f280eSIngo Weinhold # UseHeaders <headers> ; 74052a38012Sejakowatz # 74152a38012Sejakowatz # Adds the C header dirs <headers> to the header search 7427d7f280eSIngo Weinhold # dirs of the subdirectory. 7437d7f280eSIngo Weinhold # NOTE: This rule must be invoked *before* the rule that builds the objects. 74452a38012Sejakowatz 7457d7f280eSIngo Weinhold local header ; 7467d7f280eSIngo Weinhold for header in $(1) { 74752a38012Sejakowatz SubDirHdrs $(header) ; 74852a38012Sejakowatz } 74952a38012Sejakowatz} 75052a38012Sejakowatz 75152a38012Sejakowatzrule UseCppUnitHeaders 75252a38012Sejakowatz{ 7537d7f280eSIngo Weinhold SubDirHdrs [ FDirName $(OBOS_TOP) headers tools cppunit ] ; 75452a38012Sejakowatz} 75552a38012Sejakowatz 756be5af1baSIngo Weinholdrule UseCppUnitObjectHeaders 757be5af1baSIngo Weinhold{ 758be5af1baSIngo Weinhold ObjectHdrs $(1) : [ FDirName $(OBOS_TOP) headers tools cppunit ] ; 759be5af1baSIngo Weinhold} 760be5af1baSIngo Weinhold 76152a38012Sejakowatzrule UseArchHeaders 76252a38012Sejakowatz{ 7637d7f280eSIngo Weinhold # usage: UseArchHeaders <arch> ; 7647d7f280eSIngo Weinhold # 76552a38012Sejakowatz # <arch> specifies the architecture (e.g. x86). 7667d7f280eSIngo Weinhold # NOTE: This rule must be invoked *before* the rule that builds the objects. 7677d7f280eSIngo Weinhold 7687d7f280eSIngo Weinhold local headers = [ ArchHeaders $(1) ] ; 76952a38012Sejakowatz local opt = -D$(OBOS_TARGET_DEFINE) ; 770c633961aSIngo Weinhold 77152a38012Sejakowatz SubDirCcFlags $(opt) ; 77252a38012Sejakowatz SubDirC++Flags $(opt) ; 773c633961aSIngo Weinhold SubDirHdrs $(headers) ; 774c633961aSIngo Weinhold} 775c633961aSIngo Weinhold 7767d7f280eSIngo Weinholdrule UseArchObjectHeaders 7777d7f280eSIngo Weinhold{ 7787d7f280eSIngo Weinhold # usage: UseArchObjectHeaders <sources_or_objects> : <arch> ; 7797d7f280eSIngo Weinhold # 7807d7f280eSIngo Weinhold # <arch> specifies the architecture (e.g. x86). 7817d7f280eSIngo Weinhold # <sources_or_objects> Source or object files. 7827d7f280eSIngo Weinhold # NOTE: This rule must be invoked *after* the rule that builds the objects. 7837d7f280eSIngo Weinhold 7847d7f280eSIngo Weinhold local targets = $(1) ; 7857d7f280eSIngo Weinhold local headers = [ ArchHeaders $(2) ] ; 7867d7f280eSIngo Weinhold local opt = -D$(OBOS_TARGET_DEFINE) ; 7877d7f280eSIngo Weinhold 7887d7f280eSIngo Weinhold ObjectCcFlags $(targets) : $(opt) ; 7897d7f280eSIngo Weinhold ObjectC++Flags $(targets) : $(opt) ; 7907d7f280eSIngo Weinhold ObjectHdrs $(targets) : $(headers) ; 79152a38012Sejakowatz} 79252a38012Sejakowatz 793d25a77b4SIngo Weinholdrule UsePosixHeaders 794d25a77b4SIngo Weinhold{ 795d25a77b4SIngo Weinhold # UsePrivateHeaders <group list> ; 796d25a77b4SIngo Weinhold # 797d25a77b4SIngo Weinhold # Adds the POSIX header dir to the header search 798d25a77b4SIngo Weinhold # dirs of the subdirectory. 799d25a77b4SIngo Weinhold # NOTE: This rule must be invoked *before* the rule that builds the objects. 800d25a77b4SIngo Weinhold 801d25a77b4SIngo Weinhold SubDirHdrs [ FDirName $(OBOS_TOP) headers posix ] ; 802d25a77b4SIngo Weinhold} 803d25a77b4SIngo Weinhold 804d25a77b4SIngo Weinholdrule UsePosixObjectHeaders 805d25a77b4SIngo Weinhold{ 806d25a77b4SIngo Weinhold # UsePosixObjectHeaders <sources_or_objects> ; 807d25a77b4SIngo Weinhold # 808d25a77b4SIngo Weinhold # Adds the POSIX header dir to the header search 809d25a77b4SIngo Weinhold # dirs of <sources_or_objects>. 810d25a77b4SIngo Weinhold # NOTE: This rule must be invoked *after* the rule that builds the objects. 811d25a77b4SIngo Weinhold 812d25a77b4SIngo Weinhold ObjectHdrs $(1) : [ FDirName $(OBOS_TOP) headers posix ] ; 813d25a77b4SIngo Weinhold} 814d25a77b4SIngo Weinhold 8153b9eae39SIngo Weinholdrule SplitPath 8163b9eae39SIngo Weinhold{ 8173b9eae39SIngo Weinhold # SplitPath <path> ; 8183b9eae39SIngo Weinhold # Decomposes a path into its components. 8193b9eae39SIngo Weinhold local path = $(1:G=) ; 8203b9eae39SIngo Weinhold local components ; 8218c27f58dSIngo Weinhold # $(path:D) for "/" is "/". Therefore the second condition. 8228c27f58dSIngo Weinhold while $(path:D) && $(path:D) != $(path) 8233b9eae39SIngo Weinhold { 8243b9eae39SIngo Weinhold # Note: $(path:B) returns "." for "..", but $(path:D=) is fine. 8253b9eae39SIngo Weinhold components = $(path:D=) $(components) ; 8263b9eae39SIngo Weinhold path = $(path:D) ; 8273b9eae39SIngo Weinhold } 8283b9eae39SIngo Weinhold components = $(path) $(components) ; 8293b9eae39SIngo Weinhold return $(components) ; 8303b9eae39SIngo Weinhold} 8313b9eae39SIngo Weinhold 8329fc6b2e1SIngo Weinholdrule PrependObjectHdrs 8339fc6b2e1SIngo Weinhold{ 8349fc6b2e1SIngo Weinhold # PrependObjectHdrs <objects_or_sources> : <dirs> ; 8359fc6b2e1SIngo Weinhold # Prepends <dirs> to the list of header search dirs of the objects 8369fc6b2e1SIngo Weinhold # specified by <objects_or_sources>. The HDRS variable will not be 8379fc6b2e1SIngo Weinhold # changed, only CCHDRS. 8389fc6b2e1SIngo Weinhold # Note: A subsequent ObjectHdrs invocation will therefore undo the 8399fc6b2e1SIngo Weinhold # effect of this rule. 8409fc6b2e1SIngo Weinhold # NOTE: This is a hack. 8419fc6b2e1SIngo Weinhold 8429fc6b2e1SIngo Weinhold local objects = [ FGristFiles $(1:S=$(SUFOBJ)) ] ; 8439fc6b2e1SIngo Weinhold local dirs = $(2) ; 8449fc6b2e1SIngo Weinhold for object in $(objects) { 8459fc6b2e1SIngo Weinhold # Don't change HDRS to avoid screwing up the header scanning. 8469fc6b2e1SIngo Weinhold PREPENDED_HDRS on $(object) 8479fc6b2e1SIngo Weinhold = $(dirs) [ on $(object) return $(PREPENDED_HDRS) ] ; 8489fc6b2e1SIngo Weinhold CCHDRS on $(object) 8499fc6b2e1SIngo Weinhold = [ FIncludes [ on $(object) return $(PREPENDED_HDRS) $(HDRS) ] ] ; 8509fc6b2e1SIngo Weinhold } 8519fc6b2e1SIngo Weinhold} 8529fc6b2e1SIngo Weinhold 8533b9eae39SIngo Weinholdrule SymLink 8543b9eae39SIngo Weinhold{ 8553b9eae39SIngo Weinhold # SymLink <target> : <source> ; 8563b9eae39SIngo Weinhold # Links <target> to <source>. 8573b9eae39SIngo Weinhold # <source> is the exact link contents. No binding is done. 8583b9eae39SIngo Weinhold LINKCONTENTS on $(1) = $(2) ; 8593b9eae39SIngo Weinhold SymLink1 $(1) ; 8609eea4522SIngo Weinhold LocalDepends all : $(target) ; 8613b9eae39SIngo Weinhold} 8623b9eae39SIngo Weinhold 8633b9eae39SIngo Weinholdactions SymLink1 8643b9eae39SIngo Weinhold{ 8650931b8f9SIngo Weinhold $(RM) "$(1)" && $(LN) -s "$(LINKCONTENTS)" "$(1)" 8660931b8f9SIngo Weinhold} 8670931b8f9SIngo Weinhold 8680931b8f9SIngo Weinholdrule RelSymLink 8690931b8f9SIngo Weinhold{ 8700931b8f9SIngo Weinhold # RelSymLink <link> : <link target> 8710931b8f9SIngo Weinhold # Creates a relative symbolic link from <link> to <link target>. 8720931b8f9SIngo Weinhold # <link> and <link target> can be usual targets. They may have a grist 8730931b8f9SIngo Weinhold # and don't need to have any dirname. Their LOCATE variables are used to 8740931b8f9SIngo Weinhold # find their locations. 8750931b8f9SIngo Weinhold 8760931b8f9SIngo Weinhold local target = $(1) ; 8770931b8f9SIngo Weinhold local source = $(2) ; 8780931b8f9SIngo Weinhold local targetDir = [ on $(target) FDirName $(LOCATE[1]) $(target:D) ] ; 8790931b8f9SIngo Weinhold local sourceDir = [ on $(source) FDirName $(LOCATE[1]) $(source:D) ] ; 8800931b8f9SIngo Weinhold local sourcePath = $(source:G=) ; 8810931b8f9SIngo Weinhold sourcePath = $(sourcePath:D=$(sourceDir)) ; 8820931b8f9SIngo Weinhold local targetDirComponents = [ SplitPath $(targetDir) ] ; 8830931b8f9SIngo Weinhold local sourceComponents = [ SplitPath $(sourcePath) ] ; 8840931b8f9SIngo Weinhold 8850931b8f9SIngo Weinhold SymLink $(target) 8860931b8f9SIngo Weinhold : [ FRelPath $(targetDirComponents) : $(sourceComponents) ] ; 8870931b8f9SIngo Weinhold NOUPDATE $(target); 8889eea4522SIngo Weinhold Depends $(target) : $(source) ; 889*6991af8cSIngo Weinhold LocalClean clean : $(target) ; 8903b9eae39SIngo Weinhold} 8913b9eae39SIngo Weinhold 89252a38012Sejakowatz#------------------------------------------------------------------------------- 89352a38012Sejakowatz# Low-level OBOS utility rules 89452a38012Sejakowatz#------------------------------------------------------------------------------- 89552a38012Sejakowatzrule SetupObjectsDir 89652a38012Sejakowatz{ 89752a38012Sejakowatz local rel_objectsdir; 89852a38012Sejakowatz 89952a38012Sejakowatz # Copy subdir tokens except the first, as that will be "sources", and we 90052a38012Sejakowatz # do not want to include that :) 90152a38012Sejakowatz rel_objectsdir = [ FDirName $(SUBDIR_TOKENS[2-]) ] ; 90252a38012Sejakowatz LOCATE_TARGET = [ FDirName $(OBOS_OBJECT_TARGET) $(rel_objectsdir) ] ; 90352a38012Sejakowatz} 90452a38012Sejakowatz 90552a38012Sejakowatz#------------------------------------------------------------------------------- 90652a38012Sejakowatz# Link rule/action are overwritten as they don't handle linking files who's name 90752a38012Sejakowatz# contain spaces very well. Also adds resources and version to executable. 90852a38012Sejakowatz#------------------------------------------------------------------------------- 90952a38012Sejakowatzrule Link 91052a38012Sejakowatz{ 91152a38012Sejakowatz # Note: RESFILES must be set before invocation. 91252a38012Sejakowatz MODE on $(<) = $(EXEMODE) ; 91352a38012Sejakowatz on $(1) XRes $(1) : $(RESFILES) ; 91452a38012Sejakowatz SetVersion $(1) ; 91552a38012Sejakowatz Chmod $(<) ; 91652a38012Sejakowatz SetType $(1) ; 91752a38012Sejakowatz MimeSet $(1) ; 91852a38012Sejakowatz} 91952a38012Sejakowatz 92052a38012Sejakowatzactions Link bind NEEDLIBS 92152a38012Sejakowatz{ 9221eb18edfSIngo Weinhold $(LINK) $(LINKFLAGS) -o "$(1)" $(UNDEFS) "$(2)" "$(NEEDLIBS)" $(LINKLIBS) ; 92352a38012Sejakowatz} 92452a38012Sejakowatz 92552a38012Sejakowatz# BeOS specific rules 92652a38012Sejakowatz 92752a38012Sejakowatzrule XRes 92852a38012Sejakowatz{ 92952a38012Sejakowatz # XRes <target> : <resource files> 93052a38012Sejakowatz if $(2) 93152a38012Sejakowatz { 9329eea4522SIngo Weinhold Depends $(1) : $(2) ; 93352a38012Sejakowatz XRes1 $(1) : $(2) ; 93452a38012Sejakowatz } 93552a38012Sejakowatz} 93652a38012Sejakowatz 93752a38012Sejakowatzrule XRes1 { } 93852a38012Sejakowatz 93952a38012Sejakowatzrule SetVersion 94052a38012Sejakowatz{ 94152a38012Sejakowatz # SetVersion <target> 94252a38012Sejakowatz} 94352a38012Sejakowatz 94452a38012Sejakowatzrule SetType 94552a38012Sejakowatz{ 94652a38012Sejakowatz # SetType <target> 94752a38012Sejakowatz} 94852a38012Sejakowatz 94952a38012Sejakowatzrule MimeSet 95052a38012Sejakowatz{ 95152a38012Sejakowatz # SetType <target> 95252a38012Sejakowatz} 95352a38012Sejakowatz 95452a38012Sejakowatz 95552a38012Sejakowatzif $(OS) = BEOS 95652a38012Sejakowatz{ 95752a38012Sejakowatz 95852a38012Sejakowatzactions XRes1 95952a38012Sejakowatz{ 9600931b8f9SIngo Weinhold xres -o "$(1)" "$(2)" ; 96152a38012Sejakowatz} 96252a38012Sejakowatz 96352a38012Sejakowatzactions SetVersion 96452a38012Sejakowatz{ 96552a38012Sejakowatz setversion "$(1)" -system $(OBOS_BUILD_VERSION) -short "$(OBOS_BUILD_DESCRIPTION)" ; 96652a38012Sejakowatz} 96752a38012Sejakowatz 96852a38012Sejakowatzactions SetType 96952a38012Sejakowatz{ 97052a38012Sejakowatz settype -t $(OBOS_TARGET_TYPE) "$(1)" ; 97152a38012Sejakowatz} 97252a38012Sejakowatz 97352a38012Sejakowatzactions MimeSet 97452a38012Sejakowatz{ 97552a38012Sejakowatz mimeset -f "$(1)" ; 97652a38012Sejakowatz} 97752a38012Sejakowatz 97852a38012Sejakowatz} # if BEOS 97952a38012Sejakowatz 98052a38012Sejakowatz 98152a38012Sejakowatzrule assemble 98252a38012Sejakowatz{ 98394782cf7SIngo Weinhold Depends $(<) : $(>) ; 98494782cf7SIngo Weinhold ASFLAGS on $(<) += $(ASFLAGS) $(SUBDIRASFLAGS) ; 98594782cf7SIngo Weinhold ASHDRS on $(<) = [ FIncludes $(SEARCH_SOURCE) $(SUBDIRHDRS) $(HDRS) ] ; 98652a38012Sejakowatz} 98752a38012Sejakowatz 98852a38012Sejakowatzactions assemble 98952a38012Sejakowatz{ 99094782cf7SIngo Weinhold $(CC) -c "$(2)" -O2 $(ASFLAGS) $(KERNEL_CCFLAGS) $(ASHDRS) -o "$(1)" ; 99152a38012Sejakowatz} 99252a38012Sejakowatz 9930931b8f9SIngo Weinhold# Overridden to allow spaces in file names. 9940931b8f9SIngo Weinholdactions Chmod1 9950931b8f9SIngo Weinhold{ 9960931b8f9SIngo Weinhold $(CHMOD) "$(MODE)" "$(1)" 9970931b8f9SIngo Weinhold} 9980931b8f9SIngo Weinhold 999*6991af8cSIngo Weinhold# Overridden to allow spaces in file names. 1000*6991af8cSIngo Weinholdactions piecemeal together existing Clean 1001*6991af8cSIngo Weinhold{ 1002*6991af8cSIngo Weinhold $(RM) "$(>)" 1003*6991af8cSIngo Weinhold} 1004*6991af8cSIngo Weinhold 100508125d07SIngo Weinholdrule ObjectReference 100608125d07SIngo Weinhold{ 100708125d07SIngo Weinhold # ObjectReference <reference object> : <source object> 100808125d07SIngo Weinhold # Makes <reference object> refer to the same file as <source object>. 100908125d07SIngo Weinhold # The filenames must of course be identical. 101008125d07SIngo Weinhold # <source object> must have already been LOCATEd. 101108125d07SIngo Weinhold 101208125d07SIngo Weinhold local ref = $(1) ; 101308125d07SIngo Weinhold local source = $(2) ; 101408125d07SIngo Weinhold if $(ref) != $(source) { 10159eea4522SIngo Weinhold Depends $(ref) : $(source) ; 101608125d07SIngo Weinhold on $(ref) LOCATE = [ on $(source) return $(LOCATE) ] ; 101708125d07SIngo Weinhold } 101808125d07SIngo Weinhold} 101908125d07SIngo Weinhold 102008125d07SIngo Weinholdrule ObjectReferences 102108125d07SIngo Weinhold{ 102208125d07SIngo Weinhold # ObjectReferences <source objects> 102308125d07SIngo Weinhold # Creates local references to <source objects>, i.e. identifiers with the 102408125d07SIngo Weinhold # current grist referring to the same files. <source objects> must have 102508125d07SIngo Weinhold # already been LOCATEd. 102608125d07SIngo Weinhold 102708125d07SIngo Weinhold local source ; 102808125d07SIngo Weinhold for source in $(1) { 102908125d07SIngo Weinhold ObjectReference [ FGristFiles $(source) ] : $(source) ; 103008125d07SIngo Weinhold } 103108125d07SIngo Weinhold} 103208125d07SIngo Weinhold 10339fc6b2e1SIngo Weinholdrule Filter 10349fc6b2e1SIngo Weinhold{ 10359fc6b2e1SIngo Weinhold # Filter <list> : <excludes> ; 10369fc6b2e1SIngo Weinhold # Removes all occurrences of <excludes> in <list>. 10379fc6b2e1SIngo Weinhold 10389fc6b2e1SIngo Weinhold local list = $(1) ; 10399fc6b2e1SIngo Weinhold local excludes = $(2) ; 10409fc6b2e1SIngo Weinhold local newList ; 10419fc6b2e1SIngo Weinhold local item ; 10429fc6b2e1SIngo Weinhold for item in $(list) { 10439fc6b2e1SIngo Weinhold local skip ; 10449fc6b2e1SIngo Weinhold local exclude ; 10459fc6b2e1SIngo Weinhold for exclude in $(excludes) { 10469fc6b2e1SIngo Weinhold if $(item) = $(exclude) { 10479fc6b2e1SIngo Weinhold skip = true ; 10489fc6b2e1SIngo Weinhold } 10499fc6b2e1SIngo Weinhold } 10509fc6b2e1SIngo Weinhold if ! $(skip) { 10519fc6b2e1SIngo Weinhold newList += item ; 10529fc6b2e1SIngo Weinhold } 10539fc6b2e1SIngo Weinhold } 10549fc6b2e1SIngo Weinhold return $(newList) ; 10559fc6b2e1SIngo Weinhold} 10569fc6b2e1SIngo Weinhold 10570931b8f9SIngo Weinhold 105852a38012Sejakowatz## Kernel stuff! 105952a38012Sejakowatz 106052a38012Sejakowatzrule SetupKernel 106152a38012Sejakowatz{ 106252a38012Sejakowatz # Usage SetupKernel <sources_or_objects> : <extra_cc_flags>; 106352a38012Sejakowatz 106452a38012Sejakowatz local _objs = $(1:S=$(SUFOBJ)) ; 106552a38012Sejakowatz 106613be4911SDavid Reid UsePublicHeaders kernel support drivers ; 1067c633961aSIngo Weinhold UsePublicHeaders [ FDirName os kernel ] ; 106852a38012Sejakowatz UsePrivateHeaders kernel ; 10698059752eSDavid Reid UsePosixHeaders ; 107052a38012Sejakowatz UseArchHeaders $(OBOS_ARCH) ; 107152a38012Sejakowatz 107252a38012Sejakowatz SetupObjectsDir ; 107352a38012Sejakowatz 107452a38012Sejakowatz CCFLAGS on $(_objs) = $(KERNEL_CCFLAGS) $(2) ; 107552a38012Sejakowatz C++FLAGS on $(_objs) = $(KERNEL_CCFLAGS) $(2) ; 107652a38012Sejakowatz} 107752a38012Sejakowatz 107852a38012Sejakowatzrule KernelObjects 107952a38012Sejakowatz{ 108052a38012Sejakowatz SetupKernel $(1) : $(2) ; 108152a38012Sejakowatz 108252a38012Sejakowatz Objects $(1) ; 108352a38012Sejakowatz} 108452a38012Sejakowatz 108552a38012Sejakowatzrule KernelLd 108652a38012Sejakowatz{ 108752a38012Sejakowatz # KernelLd <name> : <objs> : <linkerscript> : <args> : <gcc_off> ; 108852a38012Sejakowatz 108952a38012Sejakowatz SetupKernel $(2) ; 109052a38012Sejakowatz LINK on $(1) = ld ; 109152a38012Sejakowatz 109252a38012Sejakowatz LINKFLAGS on $(1) = $(4) ; 109352a38012Sejakowatz if $(3) { LINKFLAGS on $(1) += --script=$(3) ; } 109452a38012Sejakowatz 109552a38012Sejakowatz # Remove any preset LINKLIBS 109652a38012Sejakowatz LINKLIBS on $(1) = ; 109752a38012Sejakowatz 109852a38012Sejakowatz # Show that we depend on the libraries we need 10999eea4522SIngo Weinhold LocalClean clean : $(1) ; 11009eea4522SIngo Weinhold LocalDepends all : $(1) ; 110152a38012Sejakowatz Depends $(1) : $(2) ; 110252a38012Sejakowatz 110352a38012Sejakowatz if $(6) { 110452a38012Sejakowatz for i in $(6) { 11052a83bfb4SIngo Weinhold KernelConfigSection $(i) : elf32 : $(1) ; 110652a38012Sejakowatz } 110752a38012Sejakowatz } 110852a38012Sejakowatz 110952a38012Sejakowatz MakeLocate $(1) : $(LOCATE_TARGET) ; 111052a38012Sejakowatz 111152a38012Sejakowatz # Add libgcc.a - NB this should be detected not hard coded! 111252a38012Sejakowatz if ! $(5) { 11131eb18edfSIngo Weinhold LINKLIBS on $(1) += -L $(GCC_PATH) -lgcc ; 111452a38012Sejakowatz } 111552a38012Sejakowatz} 111652a38012Sejakowatz 111752a38012Sejakowatzactions KernelLd 111852a38012Sejakowatz{ 11191eb18edfSIngo Weinhold $(LINK) $(LINKFLAGS) -o "$(1)" "$(2)" $(LINKLIBS) ; 112052a38012Sejakowatz} 112152a38012Sejakowatz 112252a38012Sejakowatzrule KernelStaticLibrary 112352a38012Sejakowatz{ 112452a38012Sejakowatz # Usage KernelStaticLibrary <name> : <sources> : <extra cc flags> ; 112552a38012Sejakowatz # This is designed to take a set of sources and libraries and create 112652a38012Sejakowatz # a file called lib<name>.a 112752a38012Sejakowatz 112852a38012Sejakowatz SetupKernel $(2) : $(3) ; 112952a38012Sejakowatz 113052a38012Sejakowatz MakeLocateObjects $(2) ; 113152a38012Sejakowatz Library $(1) : $(2) ; 113252a38012Sejakowatz} 113352a38012Sejakowatz 113452a38012Sejakowatzrule KernelStaticLibraryObjects 113552a38012Sejakowatz{ 113652a38012Sejakowatz # Usage KernelStaticLibrary <name> : <sources> ; 113752a38012Sejakowatz # This is designed to take a set of sources and libraries and create 113852a38012Sejakowatz # a file called <name> 113952a38012Sejakowatz 114052a38012Sejakowatz SetupKernel $(2) ; 114152a38012Sejakowatz 114252a38012Sejakowatz # Show that we depend on the libraries we need 11439eea4522SIngo Weinhold LocalClean clean : $(1) ; 11449eea4522SIngo Weinhold LocalDepends all : $(1) ; 114552a38012Sejakowatz Depends $(1) : $(2) ; 114652a38012Sejakowatz 114752a38012Sejakowatz MakeLocate $(1) : $(LOCATE_TARGET) ; 114852a38012Sejakowatz} 114952a38012Sejakowatz 115052a38012Sejakowatzactions KernelStaticLibraryObjects 115152a38012Sejakowatz{ 11520931b8f9SIngo Weinhold ar -r "$(1)" "$(2)" ; 115352a38012Sejakowatz} 115452a38012Sejakowatz 115552a38012Sejakowatzrule SystemMain 115652a38012Sejakowatz{ 11570c0b2cd0SIngo Weinhold # Usage SystemMain <target> : <sources> ; 115852a38012Sejakowatz SetupObjectsDir ; 115952a38012Sejakowatz 11600c0b2cd0SIngo Weinhold LINKLIBS on $(1) = ; 116152a38012Sejakowatz 116252a38012Sejakowatz Main $(1) : $(2) ; 116352a38012Sejakowatz} 116452a38012Sejakowatz 116552a38012Sejakowatzrule KernelConfigSection 116652a38012Sejakowatz{ 116752a38012Sejakowatz # KernelConfigSection <section> : <type> : <file> ; 11682a83bfb4SIngo Weinhold 11692a83bfb4SIngo Weinhold SECTION_NAMES on $(OBOS_KERNEL_CONFIG) += $(1) ; 11702a83bfb4SIngo Weinhold SECTION_TYPES on $(OBOS_KERNEL_CONFIG) += $(2) ; 11712a83bfb4SIngo Weinhold SECTION_FILES on $(OBOS_KERNEL_CONFIG) += $(3) ; 11722a83bfb4SIngo Weinhold 11732a83bfb4SIngo Weinhold Depends $(OBOS_KERNEL_CONFIG) : $(3) ; 117452a38012Sejakowatz} 117552a38012Sejakowatz 117652a38012Sejakowatzrule WriteKernelConfig 117752a38012Sejakowatz{ 117852a38012Sejakowatz # usage: WriteKernelConfig <target> ; 117952a38012Sejakowatz 11809eea4522SIngo Weinhold LocalDepends files : $(1) ; 118152a38012Sejakowatz 11822a83bfb4SIngo Weinhold MakeLocate $(1) : $(OBOS_OBJECT_TARGET) ; 118352a38012Sejakowatz 11849eea4522SIngo Weinhold LocalClean clean : $(1) ; 118552a38012Sejakowatz} 118652a38012Sejakowatz 11872a83bfb4SIngo Weinholdactions WriteKernelConfig bind SECTION_FILES 118852a38012Sejakowatz{ 11890931b8f9SIngo Weinhold target="$(1)" 11900931b8f9SIngo Weinhold echo "# OpenBeOS Kernel Config File" > "$target" 11910931b8f9SIngo Weinhold echo "# Automatically generated - do not edit!" >> "$target" 11922a83bfb4SIngo Weinhold count=0 11932a83bfb4SIngo Weinhold for section in "$(SECTION_NAMES)" ; do 11942a83bfb4SIngo Weinhold count=`expr $count + 1` 11952a83bfb4SIngo Weinhold eval section$count="$section" 11962a83bfb4SIngo Weinhold done 11972a83bfb4SIngo Weinhold i=1 11982a83bfb4SIngo Weinhold for type in "$(SECTION_TYPES)" ; do 11992a83bfb4SIngo Weinhold eval type$i="$type" 12002a83bfb4SIngo Weinhold i=`expr $i + 1` 12012a83bfb4SIngo Weinhold done 12022a83bfb4SIngo Weinhold i=1 12032a83bfb4SIngo Weinhold for file in "$(SECTION_FILES)" ; do 12042a83bfb4SIngo Weinhold eval file$i="$file" 12052a83bfb4SIngo Weinhold i=`expr $i + 1` 12062a83bfb4SIngo Weinhold done 12072a83bfb4SIngo Weinhold for i in `seq $count` ; do 12082a83bfb4SIngo Weinhold eval section="\$section$i" 12092a83bfb4SIngo Weinhold eval type="\$type$i" 12102a83bfb4SIngo Weinhold eval file="\$file$i" 12110931b8f9SIngo Weinhold echo "" >> "$target" 12122a83bfb4SIngo Weinhold echo "["$section"]" >> "$target" 12132a83bfb4SIngo Weinhold echo "type="$type >> "$target" 12140931b8f9SIngo Weinhold case "$file" in 121552a38012Sejakowatz /*) ;; 12160931b8f9SIngo Weinhold *) file=`pwd`/"$file";; 121752a38012Sejakowatz esac 12182a83bfb4SIngo Weinhold echo "file="$file >> "$target" 121952a38012Sejakowatz done 122052a38012Sejakowatz} 122152a38012Sejakowatz 122252a38012Sejakowatzrule BuildKernel 122352a38012Sejakowatz{ 122452a38012Sejakowatz # Usage BuildKernel <target> : <config_file> ; 12250c0b2cd0SIngo Weinhold local kernel = $(1) ; 12260c0b2cd0SIngo Weinhold local configFile = $(2) ; 12270c0b2cd0SIngo Weinhold local bootmaker = bootmaker ; 122852a38012Sejakowatz 12299eea4522SIngo Weinhold LocalDepends all : $(kernel) ; 12300c0b2cd0SIngo Weinhold Depends $(kernel) : $(configFile) $(bootmaker) ; 12319eea4522SIngo Weinhold LocalClean clean : $(kernel) ; 12320c0b2cd0SIngo Weinhold MakeLocate $(kernel) : $(LOCATE_TARGET) ; 123352a38012Sejakowatz 12340c0b2cd0SIngo Weinhold BOOT_MAKER on $(kernel) = $(bootmaker) ; 123552a38012Sejakowatz} 123652a38012Sejakowatz 12370c0b2cd0SIngo Weinholdactions BuildKernel bind BOOT_MAKER 123852a38012Sejakowatz{ 12390c0b2cd0SIngo Weinhold "$(BOOT_MAKER)" --strip-debug --strip-binary strip "$(2)" -o "$(1)" ; 124052a38012Sejakowatz echo "" 124152a38012Sejakowatz echo "Kernel linked!" 124252a38012Sejakowatz echo "" 124352a38012Sejakowatz} 124452a38012Sejakowatz 124552a38012Sejakowatzrule KernelFloppyImage 124652a38012Sejakowatz{ 124752a38012Sejakowatz # Usage KernelFloppyImage <target> : <kernel> : <bootblock> ; 12480c0b2cd0SIngo Weinhold local floppy = $(1) ; 12490c0b2cd0SIngo Weinhold local kernel = $(2) ; 12500c0b2cd0SIngo Weinhold local bootblock = $(3) ; 12510c0b2cd0SIngo Weinhold local makeflop = makeflop ; 125252a38012Sejakowatz 12539eea4522SIngo Weinhold LocalDepends all : $(floppy) ; 12540c0b2cd0SIngo Weinhold Depends $(floppy) : $(kernel) $(bootblock) $(makeflop) ; 12559eea4522SIngo Weinhold LocalClean clean : $(floppy) ; 12560c0b2cd0SIngo Weinhold MakeLocate $(floppy) : $(OBOS_OBJECT_TARGET) ; 125752a38012Sejakowatz 12580c0b2cd0SIngo Weinhold BOOT_BLOCK on $(floppy) = $(bootblock) ; 12590c0b2cd0SIngo Weinhold MAKE_FLOP on $(floppy) = $(makeflop) ; 126052a38012Sejakowatz} 126152a38012Sejakowatz 126252a38012Sejakowatz# This may be a bit verbose, but I think it's useful to show what's 126352a38012Sejakowatz# going on, at least in this early stage of development. 12640c0b2cd0SIngo Weinholdactions KernelFloppyImage bind BOOT_BLOCK bind MAKE_FLOP 126552a38012Sejakowatz{ 12667378dd7fSAxel Dörfler "$(MAKE_FLOP)" "-p $(shell expr 18 \* 2 \* 512)" "$(BOOT_BLOCK)" "$(2)" "$(1)" ; 12670c0b2cd0SIngo Weinhold 126852a38012Sejakowatz echo "" 126952a38012Sejakowatz echo "*************************************************" 127052a38012Sejakowatz echo "* Kernel build completed! *" 127152a38012Sejakowatz echo "* Boot image for a 1.44M floppy created *" 127252a38012Sejakowatz echo "*************************************************" 127352a38012Sejakowatz echo "" 12740c0b2cd0SIngo Weinhold echo "Floppy image is $(1)" 127552a38012Sejakowatz echo "The following command will write it to a floppy on BeOS" 12760c0b2cd0SIngo Weinhold echo " dd if=$(1) of=/dev/disk/floppy/raw bs=18k" 12770c0b2cd0SIngo Weinhold echo "Alternatively you can run" 12780c0b2cd0SIngo Weinhold echo " ./configure --floppy /dev/disk/floppy/raw" 12790c0b2cd0SIngo Weinhold echo "once and build + write the image subsequently via" 12800c0b2cd0SIngo Weinhold echo " jam installfloppy" 128152a38012Sejakowatz echo "" 128252a38012Sejakowatz} 128352a38012Sejakowatz 12840c0b2cd0SIngo Weinholdrule InstallFloppy 12850c0b2cd0SIngo Weinhold{ 12860c0b2cd0SIngo Weinhold # InstallFloppy <target> : <floppy> 12870c0b2cd0SIngo Weinhold # "dd"s <floppy> to $(FLOPPY_PATH). 12880c0b2cd0SIngo Weinhold 12890c0b2cd0SIngo Weinhold local target = $(1) ; 12900c0b2cd0SIngo Weinhold local floppy = $(2) ; 12910c0b2cd0SIngo Weinhold 12920c0b2cd0SIngo Weinhold NotFile $(target) ; 12930c0b2cd0SIngo Weinhold Always $(target) ; 12940c0b2cd0SIngo Weinhold Depends $(target) : $(floppy) ; 12950c0b2cd0SIngo Weinhold} 12960c0b2cd0SIngo Weinhold 12970c0b2cd0SIngo Weinholdactions InstallFloppy 12980c0b2cd0SIngo Weinhold{ 12990c0b2cd0SIngo Weinhold if [ -z $(FLOPPY_PATH) ] ; then 13000c0b2cd0SIngo Weinhold echo "Can't install floppy: FLOPPY_PATH not set." 13010c0b2cd0SIngo Weinhold echo "run: ./configure --floppy <floppy path>" 13020c0b2cd0SIngo Weinhold echo 13030c0b2cd0SIngo Weinhold exit 0 13040c0b2cd0SIngo Weinhold fi 13050c0b2cd0SIngo Weinhold dd if=$(2) of=$(FLOPPY_PATH) bs=18k 13060c0b2cd0SIngo Weinhold} 130752a38012Sejakowatz 1308