
# usage: kmake DIRECTORY COMPILER TYPE

print "Directory=$ARGV[0], Compiler=$ARGV[1], Type=$ARGV[2]\n";
print "output written to makefile\n";

if ($ENV{"TYPE"} =~ /JIT/i) {
	$type = "jit";
} else {
	$type = "intrp";
}
if ($ENV{"COMPILER"} =~ /MSVC/i) {
	$compiler = "msvc";
	$infile = "make.vc.in";
} else {
	$compiler = "bc";
	$infile = "make.bc.in";
}

if ($ARGV[0] =~ /KAFFEVM/i) {
	$dir = "kaffevm";
	$srcdir = "../../kaffevm";
} elsif ($ARGV[0] =~ /KAFFE/i) {
	$dir = "kaffe";
	$srcdir = "../../kaffe";
} elsif ($ARGV[0] =~ /KAFFEH/i) {
	$dir = "kaffeh";
	$srcdir = "../../kaffeh";
} elsif ($ARGV[0] =~ /NATIVE/i) {
	$dir = "native";
	$srcdir = "../../../lib/native";
} elsif ($ARGV[0] =~ /TAWT/i) {
	$dir = "tawt";
	$srcdir = "../../../lib/awt";
}

if ($ARGV[1] =~ /MSVC/i) {
	$compiler = "msvc";
	$infile = "make.vc.in";
} else {
	$compiler = "bc";
	$infile = "make.bc.in";
}

if ($ARGV[2] =~ /JIT/i) {
	$type = "jit";
} else {
	$type = "intrp";
}

if ($compiler eq "bc") {
	$srcdir =~ tr#/#\\#
}
open(INFILE, $infile) || die "Can't open $infile : $!\n";
open(OUTFILE, ">makefile");

while (<INFILE>) {
if ($compiler eq "bc") {
#s#@srcdir@#..\\..\\..\\lib\\native#g;
#s#@srcdir@#..\\..\\kaffevm#g;

s#@CC@#bcc32#g;
s#@CFLAGS@#-v -y#g;
s#@KAFFEVMFLAGS@#-tWD#g;
s#@libdir@#c:\\kaffe\\lib#g;

} else {

#s#@srcdir@#../../../lib/native#g;
#s#@srcdir@#../../kaffevm#g;

s#@CC@#cl#g;
s#@CFLAGS@#/nologo /Zp1 /MDd /W3 /Gm /GX /Zi /Od \\
 /D "_DEBUG" /D "WIN32" /D "_WINDOWS" /YX \\
 /c /Fo./#g;
s#@KAFFEVMFLAGS@##g;
s#@libdir@#c:/kaffe/lib#g;
}

s#@srcdir@#$srcdir#g;
s#@TYPE@#$type#g;
s#@prefix@##g;
s#@exec_prefix@##g;
s#@INSTALL@##g;
s#@INSTALL_DATA@#copy#g;
s#@LDFLAGS@##g;
s#@LDTAIL@##g;
s#@KVER@#0.5p3#g;
s#@OBJEXT@#.obj#g;
s#@LIBEXT@#.dll#g;
s#@PIC@##g;
s#@LIBSHARE@##g;


s#@CC@#bcc32#g;
s#@CFLAGS@#-v -y#g;
s#@KAFFEVMFLAGS@#-tWD#g;

print OUTFILE;
}
