SubDir OBOS_TOP src tests add-ons kernel file_systems bfs bfs_shell ;

SubDirHdrs $(OBOS_TOP) src tests add-ons kernel file_systems fs_shell ;
SubDirHdrs $(OBOS_TOP) src tests add-ons kernel file_systems bfs r5 ;

# Same as SetupIncludes, but doesn't include the posix headers.
rule SetupFSShellIncludes
{
	# XXX add "opengl" later
	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 ;

	# Overwrite any exiting content when changing HDRS. This rule may be invoked multiple times.

	# Use headers directory, to allow to do things like include <posix/string.h>
	HDRS = [ FDirName $(OBOS_TOP) headers ] ;

	# Use public OS header directories
	HDRS += [ PublicHeaders $(os_includes) ] ;

	# Use the root of the private headers -- not so nice, but simplifies things.
	HDRS += [ PrivateHeaders $(DOT) ] ;

	# The platform dependent headers.
	HDRS += $(PLATFORM_HEADERS) ;
}

SetupFSShellIncludes ;

UsePrivateHeaders [ FDirName kernel ] ;			# For kernel_cpp.cpp

{
	# set CHECK_MALLOC to something when doing tests against memory corruption
	local malloc_debug_defines ;
	local malloc_debug_flags ;
	if $(CHECK_MALLOC) {
		malloc_debug_defines = _NO_INLINE_ASM ;
		malloc_debug_flags = -fcheck-memory-usage ;
	}

	local defines = [ FDefines USER
		#DEBUG
		USED_IN_FS_SHELL NO_FILE_UNCACHED_IO
		UNSAFE_GET_VNODE
		#BFS_BIG_ENDIAN_ONLY
		$(malloc_debug_defines) ] ;
	SubDirCcFlags $(defines) -fno-exceptions -fno-rtti $(malloc_debug_flags) ;
	SubDirC++Flags $(defines) -fno-exceptions -fno-rtti $(malloc_debug_flags) -include [ FDirName $(SUBDIR) Debug.h ] ;
}

local fsShellSources = 
	fsh.cpp rootfs.c initfs.c kernel.c cache.c external_commands.cpp sl.c
	stub.c tracker.cpp sysdep.c hexdump.c argv.c
;

BuildPlatformMain bfs_shell :
	$(fsShellSources)

	Volume.cpp BPlusTree.cpp Inode.cpp Index.cpp Query.cpp Journal.cpp
	BlockAllocator.cpp kernel_interface_r5.cpp Utility.cpp BufferPool.cpp
	Debug.cpp kernel_cpp.cpp

	additional_commands.c

	: false # don't reset header search dirs
;

# Tell Jam where to find these sources
SEARCH on [ FGristFiles
		Volume.cpp BPlusTree.cpp Inode.cpp Index.cpp Query.cpp Journal.cpp
		BlockAllocator.cpp kernel_interface_r5.cpp Utility.cpp BufferPool.cpp
		Debug.cpp cpp.cpp
	] = [ FDirName $(OBOS_TOP) src tests add-ons kernel file_systems bfs r5 ] ;

SEARCH on [ FGristFiles
		kernel_cpp.cpp
	] = [ FDirName $(OBOS_TOP) src kernel core util ] ;

SEARCH on [ FGristFiles
		$(fsShellSources)
	] = [ FDirName $(OBOS_TOP) src tests add-ons kernel file_systems fs_shell ] ;
