SubDir HAIKU_TOP src bin findutils locate ;

SubDirSysHdrs [ FDirName $(SUBDIR) $(DOTDOT) gnulib lib ] ;
SubDirSysHdrs [ FDirName $(SUBDIR) $(DOTDOT) lib ] ;
SubDirSysHdrs [ FDirName $(SUBDIR) $(DOTDOT) ] ;

# filter warnings we don't want here
TARGET_WARNING_CCFLAGS = [ FFilter $(TARGET_WARNING_CCFLAGS)
	: -Wall -Wmissing-prototypes -Wsign-compare ] ;

# set some additional defines
{
	SubDirCcFlags -DHAVE_CONFIG_H -DLOCATE_DB='\"/var/locatedb\"' -w ;
}

local findutils_rsrc = [ FGristFiles findutils.rsrc ] ;
ResComp $(findutils_rsrc) : [ FGristFiles findutils.rdef ] ;
SEARCH on [ FGristFiles findutils.rdef ] = [ FDirName $(SUBDIR) $(DOTDOT) ] ;

BinCommand locate :
	locate.c
	: libfindutils.a gnulibfindutils.a : $(findutils_rsrc) ;

BinCommand frcode :
	frcode.c
	: libfindutils.a gnulibfindutils.a : $(findutils_rsrc) ;


rule MkUpdateDb
{
	SEARCH on $(>) = $(SEARCH_SOURCE) ;
	MakeLocatePlatform $(<) ;
	Depends $(<) : $(>) ;
	MkUpdateDb1 $(<) : $(>) ;
	LocalClean clean : $(<) ;
}

actions MkUpdateDb1
{
	sed \
	-e "s,@bindir@,/bin," \
	-e "s,@libexecdir@,/bin," \
	-e "s,@LOCATE_DB@,/var/locatedb," \
	-e "s,@VERSION@,4.2.33," \
	-e "s,@find@,find," \
	-e "s,@frcode@,frcode," \
	-e "s,@bigram@,bigram," \
	-e "s,@code@,code," \
	-e "s,@SORT@,/bin/sort," \
	-e "s,@SORT_SUPPORTS_Z@,true," \
	 $(2[1]) > $(1) ;
}

MkUpdateDb updatedbgen : updatedb.sh ;
MakeLocatePlatform <bin>updatedb ;
Shell <bin>updatedb : updatedbgen ;

