SubDir HAIKU_TOP src data timezones ;

NotFile timezone_files ;
Depends files : timezone_files ;

rule MkZicComp
{
	local source = $(1:G=timezone-source) ;
	local binaries = [ FTimeZoneBinaries $(source) : true ] ;

	SEARCH on $(source) = $(SEARCH_SOURCE) ;

	local targetDir = $(TARGET_COMMON_DEBUG_LOCATE_TARGET) ;
	targetDir = $(targetDir:G=dir) ;

	# introduce a pseudo target all binaries depend on
	local pseudoBinary = $(source:G=timezone-binary) ;
	NotFile $(pseudoBinary) ;
	Depends $(pseudoBinary) : $(binaries) ;
	LocalDepends timezone_files : $(pseudoBinary) ;

	Depends $(binaries) : $(source) zic $(targetDir) ;

	MkZicComp1 $(binaries) : zic $(source) $(targetDir) ;
	LocalClean clean : $(binaries) ;
}

actions MkZicComp1
{
	$(2[1]) -d "$(2[3])" -L /dev/null "$(2[2])" ;
}

actions MkZicCompDummy
{
}

# generate the binary files for the timezone files
MkDir $(TARGET_COMMON_DEBUG_LOCATE_TARGET) ;
local tzFile ;
local backward = [ FGristFiles backward ] ;
for tzFile in $(HAIKU_TIME_ZONE_SOURCES) {
	MkZicComp $(tzFile) ;
}

# The "backward" source file causes links to files generated from
# other sources to be created. Therefore we introduce dependencies here.
local nonBackwardBinaries = [ FFilter $(HAIKU_TIME_ZONE_SOURCES) : backward ] ;
nonBackwardBinaries = $(nonBackwardBinaries:G=timezone-binary) ;
Depends [ FTimeZoneBinaries [ FGristFiles backward ] ]
	: $(nonBackwardBinaries) ;

# "pacificnew" links to a file from "northamerica".
Depends [ FTimeZoneBinaries [ FGristFiles pacificnew ] ]
	: <timezone-binary>northamerica ;
