mkPCmake.pl 2.88 KB
#! /usr/sbin/perl
# --------------------------------------------------------------------
#        Copyright (C) 1998 Nintendo.
#        
#        $RCSfile: mkPCmake.pl,v $
#        $Revision: 1.1.1.2 $
#        $Date: 2002/10/29 08:06:05 $
# --------------------------------------------------------------------
#

# 元の MakePC ファイルから必要なデータを取ってくる
open(IN, "PCmake") || die "PCmake: $!";
while(<IN>){
    if (/^\s*ERASELINE\s*=\s(.+)$/) {
	@eraseline = split(/\s*\,\s*/, $1);
	grep(s/\'//g, @eraseline);
    } elsif (/^\s*ENDLINE\s*=\s(.+)$/) {
	$endline = $1;
	$endline =~ s/\'//g;
    } elsif (/^\s*LDIRTV\s*=\s(.+)$/) {
	@ldirtv = split(/\s*\,\s*/, $1);
	grep(s/\'//g, @ldirtv);
    }
}
close(IN);

# メインループ
$nomkmsk = 0;
while(<>) {
    foreach $i (@eraseline) {
	if (/^$i/){
	    $_="";
	    while (!/^\s+$/) {
		$_ = <>;
	    }
	}
    }
    if (/^$endline/ && $a != 999) {
	$a = 999;			# ここ以降は全削除
    } elsif (/^APP[\s\t]*=[\s\t]*(\w+)/) {
	$APPNAME = $1;
	s/$APPNAME/$APPNAME.out/;
    } elsif (/^TARGETS/) {
	if ($APPNAME ne NULL) {
	    s/rom/$APPNAME.n64/;
	} else {
	    print STDERR "ERROR: アプリケーション名が見つかりません\n";
	    exit;
	}
    } elsif (/^LCOPTS/) {
	$_="LCOPTS =\t-G 0\n";
	print;
	$_=<>;
	$_="" if(/^[\s\t]/);	# 次の行もそうだと、つなげる
    }
    if (/^LDFLAGS/) {
	s/\-nostdlib//;
	s/\-lultra_d/\-lgultra_d \-L\$\(GCCDIR\)\/mipse\/lib \-lkmc/;
    } elsif (/\#ifdef[\s\t]+(\w+)/){
	$_="ifeq (\$($1), YES)\n";
    } elsif(/^\$\(TARGETS\)/) {
	s/\$\(MAKEROM\)//;
	print;
	$_ = <>;
	s/\-r \$\(TARGETS\)/\-r \$(TARGETS) -e \$(APP)/;
    } elsif (/^LDIRT/) {
	foreach $i (@ldirtv) {
	    s/$i //;
	    s/$i//;
	}
    } elsif (/^SUBDIRS/) {
	$_="";
    }
    if (/makedisk/) {
	s/\$\(ROOT\)\/usr\/sbin\/makedisk/\$\(MAKEROM\) \-DD64/;
	s/\-R/\-r/;
    }
    # "#ifndef NOMAKEMASK" の行を削除する。
    if (/#ifndef[\s\t]+NOMAKEMASK[\s\t]/) {
	s/#ifndef[\s\t]+NOMAKEMASK[\s\t]*$//;
	$nomkmsk = 1;
    }
    # NOMAKEMASKの "#endif" を削除
    if (($nomkmsk == 1)&&(/#endif/)) {
	s/#endif[\s\t]*$//;
	$nomkmsk = 0;
    }
    s/#else/else/;
    s/#endif/endif/;
    s/^\#DEBUG =/\#DEBUG = YES/;
    s/^\#FINAL =/\#FINAL = YES/;
    s/N64LIB\)$/N64LIB\) -L\$\(GCCDIR\)\/mipse\/lib -lkmc/;
    s/\-lultra/\-lgultra/;
    s/\-ln_audio/\-lgn_audio/;
    s/\$\(LD\) \-m/\$\(LD\)/;
    s/\> load.map//;

    s/\s+$/\n/;

    if ($a == 0) {
	if (/^\#/) {
	    $a = 2;
	    $comment .= $_;
	}
    } elsif ($a == 2) {
	if (/^\#/) {
	    $comment .= $_;
	} else {
	    if (!($comment =~/^\#$/)) {
		print "$comment";
	    }
	    $a = 0;
	    $comment ="";
	}
    }
    if ($a==0) {
	if (!(/^$/ && $old eq $_)) {
	    print;
	}
	$old = $_;
    }
}

print "\n# for exeGCC CELF\n";
print "ifeq (\$(GCC_CELF), ON)\n";
print "ifneq (\$(FINAL), YES)\n";
print "CELFDIR = .\n";
print "include \$(CELFRULES)\n";
print "\$(CODEOBJECTS) \$(DATAOBJECTS) :\t\$(CELFINFOFILES)\n";
print "endif\n";
print "endif\n";