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

include [ FDirName $(HAIKU_TOP) src tests add-ons kernel file_systems fs_shell
				   FSShellRules ] ;

local bfsSourceDir = [ FDirName $(HAIKU_TOP) src tests add-ons kernel
								file_systems bfs r5 ] ;

local oldSubDirHdrs = $(SUBDIRHDRS) ;
local oldSubDirSysHdrs = $(SUBDIRSYSHDRS) ;


# Compile additional_commands.c with the same environment as the fs_shell. That
# is all BeOS headers, but the platform POSIX and STL headers.

SubDirHdrs $(HAIKU_TOP) src tests add-ons kernel file_systems fs_shell ;
SubDirHdrs $(bfsSourceDir) ;

SetupFSShellIncludes ;

ObjectDefines [ FGristFiles additional_commands.c ]
	: _NO_INLINE_ASM _GNU_SOURCE ;

BuildPlatformObjects [ FGristFiles additional_commands.c ] : false ;


# Reset the environment for the FS add-on sources. We build using all BFS
# headers, including the POSIX and STL headers.

SUBDIRHDRS = $(oldSubDirHdrs) ;
SUBDIRSYSHDRS = $(oldSubDirSysHdrs) ;

SubDirHdrs $(bfsSourceDir) ;
UsePrivateHeaders [ FDirName kernel ] ;			# For kernel_cpp.cpp

SYSHDRS = $(HAIKU_HDRS) ;


{
	# 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 ;
	}

	# We need to use a wrapper for some POSIX calls on non-BeOS systems.
	local buildPlatformDefines ;
	if $(OS) != BEOS {
		buildPlatformDefines =
			open=build_platform_open
			close=build_platform_close
			fstat=build_platform_fstat
			read_pos=build_platform_read_pos
			ioctl=build_platform_ioctl
			MEAN_BFS_SHELL_SELECT_HACK=1
		;
	}

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

BuildPlatformMain bfs_shell :
	Volume.cpp BPlusTree.cpp Inode.cpp Index.cpp Query.cpp Journal.cpp
	BlockAllocator.cpp kernel_interface_r5.cpp Utility.cpp BufferPool.cpp
	Debug.cpp

	[ FGristFiles additional_commands$(SUFOBJ) ]
;
LinkAgainst bfs_shell : libfs_shell.a $(HOST_LIBSTDC++) ;

# 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
	] = $(bfsSourceDir) ;
