SubDir TOP ;

# import SetSimulationBuild etc
include $(HoG_TOP)/jam/jamfile-support/jam-build-levels ;



rule ShowHelp
{
	Echo "No build target provided, displaying help:" ;
	Echo "To build individual targets or pseudo-targets, pass them to jam as-is." ;
	Echo "To build tests and run them in qemu, invoke jam t<x>, where <x> is a layer number between 1 and 9." ;
	Echo ;
	Echo "Usage examples:" ;
	Echo "  jam t1  # tests layer 1 (half of Support Kit)" ;
	Echo "  jam t3  # tests layers 1 to 3 (most of Storage+Support kits)" ;
	Echo "  jam t6  # aka 'the motherlode' ; allows building the demos" ;
	Echo "  jam t7  # MediaKit's core, DeviceKit, TranslationKit" ;
	Echo "  jam t8  # All of the above, plus enough to build Tracker and Deskbar" ;
	Echo "  jam t9  # All of the above, plus networking" ;
	Echo ;
	Echo "That will build a variant of haiku.lib.so reduced to the selected layer, build the test harness, invoke qemu to run the harness and output pass/fail results." ;
	Echo ;
	Echo "To build and run a full-fledged scenario, just pass its name to jam:" ;
	Echo "  jam hog-demos.emu6  # builds Clock/Mandelbrot/Pulse and runs in Qemu" ;
	Echo "  jam hog-demos.iso6  # same but with more drivers, for running on bare metal" ;
	#///+   Echo "  jam audio-demos.run  # xx " ;
	Echo ;
	Echo "A scenario's bootable ISO image can also be written to a USB thumbdrive with /bin/dd to run it on bare metal, e.g.:" ;
	Echo "  dd if=hog-demos.iso of=/dev/disk/usb/something bs=1M conv=fsync" ;
	#Echo "For more details, read xxx" ;
	
	Exit ;  # do *not* proceed with building "all"
}


switch $(JAM_TARGETS[1])
{
	case all :  {  ShowHelp ;  }
	case help : {  ShowHelp ;  }
	
	case clean : {
		# don't leave anything out of target:"clean"
		LayerLevel = 9 ;
	}
	
	case *.run* : {
		Echo "*** Do not invoke *.run targets directly, go through *.emu or *.iso instead." ;
		Echo "    Thus instead of e.g. 'jam hog-demos.run', invoke 'jam hog-demos.emu6', which will get mapped to .run with build configuration flags producing a small, fast image for emulation at build-level-6, or *.iso6 for build flags suitable for bare-metal (more drivers, etc)." ;
		
		# !
		Exit ;
	}
	
	case t1 : {
		JAM_TARGETS = hog-test.emu1 ;
		SetSimulationBuild ;
	}
	case t2 : {
		JAM_TARGETS = hog-test.emu2 ;
		SetSimulationBuild ;
	}
	case t3 : {
		JAM_TARGETS = hog-test.emu3 ;
		SetSimulationBuild ;
	}
#	case t5 : {
#		JAM_TARGETS = hog-test.emu5 ;
#		SetSimulationBuild ;
#	}
	case t6 : {
		JAM_TARGETS = hog-test.emu6 ;
		SetSimulationBuild ;
	}
	case t7 : {
		JAM_TARGETS = hog-test.emu7 ;
		SetSimulationBuild ;
	}
	case t8 : {
		JAM_TARGETS = hog-test.emu8 ;
		SetSimulationBuild ;
	}
	case t9 : {
		JAM_TARGETS = hog-test.emu9 ;
		SetSimulationBuild ;
	}
	
	# handle targets *.emu6 and *.emu7 (e.g. "hog-demos.emu6")
	#
	case *.emu? : {
		SetSimulationBuild ;
	}
	
	case *.iso? : {
		SetBareMetalBuild ;
	}
	
	case haiku.lib.so : {
		# invoking "jam haiku.lib.so" (instead of a full-fledged runnable system) is probably
		# done for Sculpt-integration purposes -> make sure to build the appropriate level:
		#
		DEFINES += hog_TEST_LEVEL=8 ;
		LayerLevel = 8 ;
		# (don't call SetBuild, it would nul-out $JAM_TARGETS)
	}
	
	case * : {
		# We're being called on an individual build target (Sudoku, DeskCalc, etc):
		# proceed the same way as for haiku.lib.so:
		
		DEFINES += hog_TEST_LEVEL=8 ;
		LayerLevel = 8 ;
		
		ECHO ".. No .emuX layer provided, building target < $(JAM_TARGETS) > with default layer level $(LayerLevel)" ;
	}
}

#
Always haiku.lib.so ;  #xxxxx
#///ToDo-2: re. the "Always link" temporary hack : let's get rid of it, it slows
# down the build already now with a reduced-size haiku.lib.so...
# Maybe have _2_ different haiku.lib.so,
# a "haiku-light" and "haiku" ?




if $(JAM_TARGETS)
{
	#echo "JAM_TARGETS exists, we're fine" ;
}
else
{
	echo "--------------------" ;
	echo "Warning: the version of JAM you are using does not implement the JAM_TARGETS variable. Thus the build system is unable to parse the command-line to determine the completeness level you're aiming at, which thus needs to be hardcoded to its maximum (6'th) level. As a consequence :" ;
	echo "- the build system hardcodes LayerLevel=6 (to make sure BView, BHandler etc are compiled) : you cannot start off gently with testlevel=1, at least not without modifying ./Jamfile" ;
	echo "- official build instructions like 'jam t1' will not work, instead use these:" ;
	echo "- 'jam hog-test.run' (when the documentation mentions jam t1 or jam t6), or " ;
	echo "- 'jam hog-demos.run' (when the documentation mentions jam hog-demos.run : no change here)" ;
	echo "- 'jam haiku.lib.so' (no change here either) " ;
	Echo "If you run 'jam t1' as per the build instructions, jam will just reply 'don't know how to make t1' and give up." ;
	echo "--------------------" ;
	echo "" ;
	
	# hard-code level 6:
	#
	SetSimulationBuild 6 ;
}




#SubInclude TOP bfs-on-genode ;
SubInclude TOP ge-drivers ;
SubInclude TOP ge-services ;
SubInclude TOP hai-ports ;
SubInclude TOP hai-src ;
SubInclude TOP haiku-on-genode ;
SubInclude TOP hog-apps ;
SubInclude TOP hog-libs ;
SubInclude TOP hog-services ;
SubInclude TOP misc-apps ;
SubInclude TOP misc-tests ;

