SubDir TOP ge-drivers vfs_fuse_ntfs_tts ;

LOCATE_TARGET = $(SUBDIR)/$(OBJDIR_PFX).$(BE_HOST_CPU) ;  # "vfs_fuse_ntfs_tts/obj-HoG.x86_64"


# USAGE:
# For testable run scenarios, see e.g. >> $(TOP)/hog-services/indexer <<
# (no run script is provided in here).

# Upstream origin:
# This is inspired by upstream's fuse-server but technically almost a 'new' fork since we are now a vfs plug-in
# (not a server). This was originally tentatively implemented as a gmake file as << world/lib/mk/vfs_fuse_ntfs-3g.mk >>
# but is now done as a (this) Jamfile and hosted in a fossil repository.


#########  Compilation: vfs_fuse_ntfs_tts.lib.so  #########

SetupHeadersHoG ;

SubDirHdrs $(TOP)/hog-libs ;  # for LeakChecker.h

SEARCH_SOURCE +=
	$(SUBDIR)/world-include-fuse  # our tweak of world/include/fuse/fuse_private.h (init_fs() declaration) -- we override here in SEARCH_SOURCE as SubDirHdrs seems to occur too late in the command line
	$(SUBDIR)/world-src-lib-ntfs-3g
	$(SUBDIR)/world-src-lib-vfs-fuse_ntfs_3g
	$(GenodeRepos)/../contrib/$(Contrib_ntfs3g)/src/lib/ntfs-3g/src  # ntfs-3g.c, ntfs-3g_common.c
	$(GenodeRepos)/../contrib/$(Contrib_ntfs3g)/src/lib/ntfs-3g/ntfsprogs  # mkntfs.c
	;

SubDirC++Flags -fpermissive ;  # allow "#define TRUE 1" (int as boolean)

# configure ntfs build
SubDirCcFlags  $(ntfs_config_defines) ;
SubDirC++Flags $(ntfs_config_defines) ;


#///ToDo: this belongs to Jamrules
#//// refactor vfs_indexer, maybe haikulib too? nope, there is already a "HaikuKit"
rule GeSharedLib prefix : sources
{
	# e.g.: SolibFromObjects vfs_indexer.lib.so : vfs_indexer.o etc
	SolibFromObjects $(prefix).lib.so :
		$(sources:S=.o)
		;
	# e.g.: Library vfs_indexer.a : vfs_indexer.cpp etc
	Library $(prefix).a :
		$(sources)
		;
}


#///ToDo: grep -r "vfs_fuse .lib.so" and replace with "vfs_fuse_ntfs_tts.lib.so" !
GeSharedLib vfs_fuse :
	# world-src-lib-ntfs-3g/
	init.cc  # originally "world/src/lib/ntfs-3g/init.cc"		# (genode glue?)
	# world-src-lib-vfs-fuse_ntfs_3g/
	_stubs.cc
	directfs_libc.cc
	vfs_fuse.cc  # adapted/enhanced from world/src/server/...
	# ntfs glue(?) (part of contrib/ntfs* files, but not part of library libntfs-3g)
	ntfs-3g.c
	ntfs-3g_common.c
	;

LinkLibraries vfs_fuse.lib.so :
	libfuse  # consists of just fuse.cc
	libntfs-3g
	hog_lib  # LeakChecker
	;
	#Or do this instead?:
	#Depends vfs_fuse.lib.so : libfuse.a ;
	#NEEDLIBS on vfs_fuse.lib.so += libfuse.a ;


ObjectHdrs  ntfs-3g.c  ntfs-3g_common.c :
	$(GenodeRepos)/../contrib/$(Contrib_ntfs3g)/include/ntfs-3g  # compat.h, inode.h
	;
ObjectHdrs init.cc :
	$(GenodeRepos)/../contrib/$(Contrib_ntfs3g)/include/ntfs-3g
	$(GenodeRepos)/../contrib/$(Contrib_ntfs3g)/src/lib/ntfs-3g/src  # how come this one is needed..?
	;
#xxx this is identical (except for the lone HAVE_TIMESPEC) to what we already do with SubDirCcFlags ?!
#ObjectDefines init.cc :
#	HAVE_TIMESPEC HAVE_CONFIG_H HAVE_SETXATTR RECORD_LOCKING_NOT_IMPLEMENTED
#	;



SubDirHdrs $(GenodeRepos)/../contrib/$(Contrib_ntfs3g)/include/ntfs-3g ;  # for "security.h", "layout.h"

BinCommand mkntfs :
	attrdef.c
	boot.c
	sd.c
	mkntfs.c
	utils.c
	;

#AddStaticLibrary_abiRelocated  mkntfs : libntfs-3g.a ;
#xx Seems the below works again, so rem out the above (also, look around for "Static"Library call on libntfs, might be revertable to "Library" rule too):
LinkLibraries mkntfs :
	libntfs-3g
	;

