SubDir HAIKU_TOP src build libhaikucompat ;

SetSubDirSupportedPlatforms libbe_test r5 dano bone ;

UsePrivateBuildHeaders . kernel [ FDirName system arch $(HOST_ARCH) ] ;
	# the latter for <asm_defs.h>


local libbeTestSources ;
if $(TARGET_PLATFORM) = libbe_test {
	libbeTestSources = misc.cpp syscalls.cpp ;
}

# TODO: This is a temporary kludge. We should actually build libbe_build.so
# and use it for the build tools even on BeOS compatible platforms. For the
# time being we build the classes we need (BAppFileInfo and its dependencies)
# into libhaikucompat_build.a.
local libbePatchSources ;
if $(HOST_PLATFORM) in r5 bone dano {
	libbePatchSources += AppFileInfo.cpp Bitmap.cpp GraphicsDefs.cpp ;
	ObjectSysHdrs $(libbePatchSources)
		: [ FDirName $(HAIKU_TOP) headers build os app ] ;
	ObjectSysHdrs $(libbePatchSources)
		: [ FDirName $(HAIKU_TOP) headers build os interface ] ;
	ObjectSysHdrs $(libbePatchSources)
		: [ FDirName $(HAIKU_TOP) headers build os support ] ;
	ObjectSysHdrs $(libbePatchSources)
		: [ FDirName $(HAIKU_TOP) headers build os storage ] ;
	if $(HOST_PLATFORM) = r5 {
		ObjectDefines $(libbePatchSources) :
			USING_HAIKU_TYPE_CONSTANTS_H= ;
	}
	if $(HOST_PLATFORM) = bone {
		ObjectDefines $(libbePatchSources) :
			USING_HAIKU_TYPE_CONSTANTS_H= ;
	}
	if $(HOST_PLATFORM) = dano {
		ObjectDefines $(libbePatchSources) : _IMPEXP_BE=
			USING_HAIKU_TYPE_CONSTANTS_H= ;
	}
	ObjectC++Flags $(libbePatchSources)
		: -include [ FDirName $(HAIKU_TOP) headers build
			HaikuBuildCompatibility.h ] ;
}

BuildPlatformStaticLibrary libhaikucompat_build.a :
	atomic.S
	strcasestr.c
	strlcat.c
	strlcpy.c
	strnlen.c

	$(libbePatchSources)
;

StaticLibrary libhaikucompat.a :
	strcasestr.o
	strlcat.o
	strlcpy.o
	strnlen.o

	$(libbeTestSources)
;

SEARCH on [ FGristFiles strcasestr.c strlcat.c strlcpy.c strnlen.c ]
	= [ FDirName $(HAIKU_TOP) src system libroot posix string ] ;
SEARCH on [ FGristFiles atomic.S ]
	= [ FDirName $(HAIKU_TOP) src system libroot os arch $(HOST_ARCH) ] ;
SEARCH on [ FGristFiles Bitmap.cpp GraphicsDefs.cpp ]
	= [ FDirName $(HAIKU_TOP) src build libbe interface ] ;
SEARCH on [ FGristFiles AppFileInfo.cpp ]
	= [ FDirName $(HAIKU_TOP) src build libbe storage ] ;
