mkPCmake.pl
2.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#! /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";