#!/usr/bin/perl -w

# This script is run from the Xinu Makefile for 'make geninc'
# The script is passed the list of source directories to scan for source names,
# which are used to build the make include file.

# Syntax:  mvs38j-genall <list of source directories>

my $incmk = 'compile/inc.mk';					# name of make include file
my $srcpath = `pwd`;						# path - source
chomp $srcpath;							# remove \n
my $geninc = "../build/perl/mvs38j-geninc";			# geninc perl script
system "clear";
print "--------------------------------------------------------------------------------------------------------------\n";
system "rm -f $incmk";						# remove old make include file
unless (open INCLUDE, ">>$incmk") {die "Open $incmk failed: $!"};
writetext("#\n");
writetext("# This file generated by build/perl/mvs38j-genall and build/perl/mvs38j-geninc\n");
writetext("# from specifications in build/macros.mk\n");
writetext("# Constructed via compile/Makefile\n");
writetext("#\n");
close INCLUDE;
foreach my $path (@ARGV) {
	my $dir = "$path";
	if ($dir =~ /\//) {					# pathname contains slash?
		my @temp = split /\//, $path;			# split into pieces at slash(es)
		$dir = $temp[-1];				# last piece is all we want
	}
	my $src = "$dir";
	my $obj = "$dir" . "OBJ";
	system "$geninc $src $obj $path $incmk";
}


sub writetext {
	print "$_[0]";
	print INCLUDE "$_[0]";
}

