source: EcnlProtoTool/trunk/asp3_dcre/tinet/tinet_asp_configure@ 270

Last change on this file since 270 was 270, checked in by coas-nagasima, 7 years ago

mruby版ECNLプロトタイピング・ツールを追加

File size: 12.1 KB
Line 
1#! /usr/bin/perl
2#
3# TINET (TCP/IP Protocol Stack)
4#
5# Copyright (C) 2001-2003 by Embedded and Real-Time Systems Laboratory
6# Toyohashi Univ. of Technology, JAPAN
7# Copyright (C) 2006-2008 by Embedded and Real-Time Systems Laboratory
8# Graduate School of Information Science, Nagoya Univ., JAPAN
9# Copyright (C) 2001-2007 by Dep. of Computer Science and Engineering
10# Tomakomai National College of Technology, JAPAN
11#
12# 上記著作権者は,以下の(1)〜(4)の条件を満たす場合に限り,本ソフトウェ
13# ア(本ソフトウェアを改変したものを含む.以下同じ)を使用・複製・改
14# 変・再配布(以下,利用と呼ぶ)することを無償で許諾する.
15# (1) 本ソフトウェアをソースコードの形で利用する場合には,上記の著作
16# 権表示,この利用条件および下記の無保証規定が,そのままの形でソー
17# スコード中に含まれていること.
18# (2) 本ソフトウェアを,ライブラリ形式など,他のソフトウェア開発に使
19# 用できる形で再配布する場合には,再配布に伴うドキュメント(利用
20# 者マニュアルなど)に,上記の著作権表示,この利用条件および下記
21# の無保証規定を掲載すること.
22# (3) 本ソフトウェアを,機器に組み込むなど,他のソフトウェア開発に使
23# 用できない形で再配布する場合には,次のいずれかの条件を満たすこ
24# と.
25# (a) 再配布に伴うドキュメント(利用者マニュアルなど)に,上記の著
26# 作権表示,この利用条件および下記の無保証規定を掲載すること.
27# (4) 本ソフトウェアの利用により直接的または間接的に生じるいかなる損
28# 害からも,上記著作権者およびTOPPERSプロジェクトを免責すること.
29# また,本ソフトウェアのユーザまたはエンドユーザからのいかなる理
30# 由に基づく請求からも,上記著作権者およびTOPPERSプロジェクトを
31# 免責すること.
32#
33# 本ソフトウェアは,無保証で提供されているものである.上記著作権者お
34# よびTOPPERSプロジェクトは,本ソフトウェアに関して,特定の使用目的
35# に対する適合性も含めて,いかなる保証も行わない.また,本ソフトウェ
36# アの利用により直接的または間接的に生じたいかなる損害に関しても,そ
37# の責任を負わない.
38#
39# @(#) $Id: tinet_asp_configure,v 1.5 2009/12/24 06:42:46 abe Exp abe $
40#
41
42require "getopt.pl";
43
44# オプションの定義
45#
46# -T <target> ターゲット名(必須)
47# -A <applname> アプリケーションプログラム名
48# -a <appldir> アプリケーションのディレクトリ名
49# -U <applobjs> 他のアプリケーションプログラムファイル
50# (.oファイル名で指定.複数指定可)
51# -L <kernel_lib> カーネルライブラリ(libkernel.a)のディレクトリ名
52# (省略した場合,カーネルライブラリもmakeする)
53# -f カーネルを関数単位でコンパイルするかどうかの指定
54# -D <srcdir> カーネル等のソースの置かれているディレクトリ
55# -l <srclang> プログラミング言語(現時点ではcとc++のみサポート)
56# -t <templatedir> テンプレートディレクトリを指定(デフォルトはtinet/asp_sample)
57# -d <dbgenv> 実行環境の名称
58# -r トレースログ記録のサンプルコードを使用するかどうかの指定
59# -p <perl> perlのパス名(明示的に指定する場合)
60# -g <cfg> コンフィギュレータ(cfg)のパス名
61# -e <tinetdir> TINET のソースの置かれているディレクトリ
62# -i <net_if> ネットワークインタフェース(必須)
63# ether、ppp、loop の何れかを指定する。
64# -v <net_dev> イーサネット・ディバイスドライバ
65# (ネットワークインタフェースに ether を指定した場合は必須)
66# -n <net_proto> ネットワーク層プロトコル(必須)
67# inet4、inet6 の何れかを指定する。
68# -s <trans_proto> トランスポート層プロトコル(必須)
69# tcp、udp、tcp/udp の何れかを指定する。
70
71# 使用例(1)
72#
73# % ../tinet/tinet_asp_configure -T akih8_3069f_gcc -A echos4 -i ether -v if_ed -n inet4 -s tcp
74
75#
76# オプションの処理
77#
78do Getopt("TAaULDltdpgiensv");
79
80#
81# 変数の初期化
82#
83
84$target = $opt_T;
85$applname = $opt_A ? $opt_A : "";
86$appldir = $opt_a ? $opt_a : "";
87$applobjs = $opt_U ? $opt_U : "";
88$kernel_lib = $opt_L ? $opt_L : "";
89$kernel_funcobjs = $opt_f ? "true" : "";
90$srclang = $opt_l ? $opt_l : "c";
91$templatedir = $opt_t ? $opt_t : "asp_sample";
92$dbgenv = $opt_d ? "TOPPERS_".$opt_d : "";
93$enable_trace = $opt_r ? "true" : "";
94$net_if = $opt_i;
95$net_dev = $opt_v;
96$net_proto = $opt_n;
97$trans_proto = $opt_s;
98$aspsampledir = "sample";
99
100#
101# オブジェクトファイル名の拡張子を返す
102#
103sub get_objext {
104 local(@uname);
105
106 use POSIX;
107 @uname = do uname();
108 if ($uname[0] =~ /^cygwin/i) {
109 return("exe");
110 }
111 else {
112 return("");
113 }
114}
115
116#
117# プログラムの場所を検索する
118#
119sub get_path {
120 local($progname, @pathlist) = @_;
121 local($path);
122
123 foreach $path (@pathlist) {
124 if (-x $path."/".$progname) {
125 return($path."/".$progname);
126 }
127 }
128 return("");
129}
130
131#
132# Makefile を変換する
133#
134sub convMakefileSub {
135 local($infile, $outfile) = @_;
136 local($line, $varname, $varval);
137
138 unless (open(INFILE, $infile)) {
139 print STDERR "tinet_asp_configure: can't open $infile\n";
140 exit(1);
141 }
142 unless (open(OUTFILE, ">> ".$outfile)) {
143 print STDERR "tinet_asp_configure: can't open $outfile\n";
144 exit(1);
145 }
146
147 while ($line = <INFILE>) {
148 chop $line;
149 while ($line =~ /^(.*)\@\(([A-Za-z0-9_]+)\)(.*)$/) {
150 $line = $1.$vartable{$2}.$3;
151 }
152 print OUTFILE $line,"\n";
153 }
154
155 close(INFILE);
156 close(OUTFILE);
157}
158
159#
160# Makefile を変換する
161#
162sub convMakefile {
163 local($infile, $copyright, $outfile) = @_;
164 local($aspMakefile);
165
166 # Mekfile 有ればリネームする。
167 print STDERR "tinet_asp_configure: Generating $outfile from $infile.\n";
168 if (-f $outfile) {
169 print STDERR "tinet_asp_configure: $outfile exists.",
170 " Save as $outfile.bak.\n";
171 rename($outfile, $outfile.".bak");
172 }
173
174 # TINET のコピーライトを書き込む
175 &convMakefileSub($copyright, $outfile);
176
177 # 出力する Makefile をオープンする
178 unless (open(OUTFILE, ">> ".$outfile)) {
179 print STDERR "tinet_asp_configure: can't open $outfile\n";
180 exit(1);
181 }
182
183 # 参照する sample/Makefile をオープンする。
184 $aspMakefile = $aspsampledir."/Makefile";
185 unless (open(ASPFILE, $aspMakefile)) {
186 print STDERR "tinet_asp_configure: can't open $aspMakefile\n";
187 exit(1);
188 }
189
190 # 参照する sample/Makefile のコピーライトを読み飛ばす。
191 while ($line = <ASPFILE>) {
192 chop $line;
193 if ($line !~ /^#/) {
194 print OUTFILE $line,"\n";
195 last;
196 }
197 }
198
199 # 'APPLNAME = @(APPLNAME)' の行まで書き込む
200 while ($line = <ASPFILE>) {
201 chop $line;
202 while ($line =~ /^(.*)\@\(([A-Za-z0-9_]+)\)(.*)$/) {
203 $line = $1.$vartable{$2}.$3;
204 }
205 print OUTFILE $line,"\n";
206 if ($line =~ /^APPLNAME = /) {
207 last;
208 }
209 }
210
211 # '#' 前の行まで書き込む
212 while ($line = <ASPFILE>) {
213 chop $line;
214 while ($line =~ /^(.*)\@\(([A-Za-z0-9_]+)\)(.*)$/) {
215 $line = $1.$vartable{$2}.$3;
216 }
217 if ($line =~ /^#/) {
218 last;
219 }
220 print OUTFILE $line,"\n";
221 }
222
223 # 一度出力する Makefile をクローズする。
224 close(OUTFILE);
225
226 # TINET の Makefile を書き込む
227 &convMakefileSub($infile, $outfile);
228
229 # もう一度出力する Makefile をオープンする
230 unless (open(OUTFILE, ">> ".$outfile)) {
231 print STDERR "tinet_asp_configure: can't open $outfile\n";
232 exit(1);
233 }
234
235 # 参照する sample/Makefile の最終行まで書き込む
236 while ($line = <ASPFILE>) {
237 chop $line;
238 while ($line =~ /^(.*)\@\(([A-Za-z0-9_]+)\)(.*)$/) {
239 $line = $1.$vartable{$2}.$3;
240 }
241 print OUTFILE $line,"\n";
242 }
243
244 close(OUTFILE);
245 close(ASPFILE);
246}
247
248#
249# Makefile を生成する
250#
251sub genMakefile {
252 local($file, $mandatory) = @_;
253 local($path, $copyright);
254
255 $path = $sampledir.$file.".".$applname;
256 $copyright = $sampledir.$file.".copyright";
257 if (-f $path) {
258 &convMakefile($path, $copyright, $file);
259 return;
260 }
261
262 $path = $sampledir.$file;
263 if ($mandatory || -f $path) {
264 &convMakefile($path, $copyright, $file);
265 }
266}
267
268#
269# ファイルを変換する
270#
271sub convert {
272 local($infile, $outfile) = @_;
273 local($line, $varname, $varval);
274
275 print STDERR "tinet_asp_configure: Generating $outfile from $infile.\n";
276 if (-f $outfile) {
277 print STDERR "tinet_asp_configure: $outfile exists.",
278 " Save as $outfile.bak.\n";
279 rename($outfile, $outfile.".bak");
280 }
281 unless (open(INFILE, $infile)) {
282 print STDERR "tinet_asp_configure: can't open $infile\n";
283 exit(1);
284 }
285 unless (open(OUTFILE, "> ".$outfile)) {
286 print STDERR "tinet_asp_configure: can't open $outfile\n";
287 exit(1);
288 }
289
290 while ($line = <INFILE>) {
291 chop $line;
292 while ($line =~ /^(.*)\@\(([A-Za-z0-9_]+)\)(.*)$/) {
293 $line = $1.$vartable{$2}.$3;
294 }
295 print OUTFILE $line,"\n";
296 }
297
298 close(INFILE);
299 close(OUTFILE);
300}
301
302#
303# サンプルを見つけてファイルを生成する
304#
305sub generate {
306 local($file, $mandatory) = @_;
307 local($path);
308
309 $path = $sampledir.$file.".".$applname;
310 if (-f $path) {
311 do convert($path, $file);
312 return;
313 }
314
315 $path = $sampledir.$file;
316 if ($mandatory || -f $path) {
317 do convert($path, $file);
318 }
319}
320
321#
322# TINET のソースディレクトリ名を取り出す
323#
324$pwd = `pwd`; chop $pwd;
325if ($opt_e) {
326 $tinetabsdir = $tinetdir = $opt_e;
327}
328elsif ($0 =~ /(.*)\/tinet_asp_configure/) {
329 $tinetdir = $1;
330 if ($tinetdir =~ /^\//) {
331 $tinetabsdir = $tinetdir;
332 }
333 else {
334 $tinetabsdir = $pwd."/".$tinetdir;
335 }
336}
337else {
338 $tinetabsdir = $tinetdir = $pwd;
339}
340$sampledir = $tinetdir."/".$templatedir."/";
341
342#
343# ソースディレクトリ名を取り出す
344#
345$pwd = `pwd`; chop $pwd;
346if ($opt_D) {
347 $srcabsdir = $srcdir = $opt_D;
348}
349elsif ($0 =~ /(.*)\/tinet\/tinet_asp_configure/) {
350 $srcdir = $1;
351 if ($srcdir =~ /^\//) {
352 $srcabsdir = $srcdir;
353 }
354 else {
355 $srcabsdir = $pwd."/".$srcdir;
356 }
357}
358else {
359 $srcabsdir = $srcdir = $pwd;
360}
361$aspsampledir = $srcdir."/".$aspsampledir;
362
363$perl = $opt_p ? $opt_p : do get_path("perl", ("/usr/local/bin", "/usr/bin"));
364$cfg = $opt_g ? $opt_g : "\$(SRCDIR)/cfg/cfg/cfg";
365$cfgfile = $opt_g ? $opt_g : $srcdir."/cfg/cfg/cfg";
366
367#
368# オプションの確認
369#
370unless ($opt_T) {
371 print STDERR "tinet_asp_configure: -T option is mandatory\n";
372 print STDERR "Installed targets are:\n";
373 foreach $targetname (<$srcdir/target/[a-zA-Z1-9]*>) {
374 $targetname =~ s|$srcdir/target/||;
375 print STDERR "\t$targetname\n";
376 }
377 exit(1);
378}
379unless ($opt_i) {
380 print STDERR "tinet_jsp_configure: -i option is mandatory\n";
381 exit(1);
382}
383else {
384 unless ($opt_v) {
385 print STDERR "tinet_jsp_configure: -v option is mandatory\n";
386 exit(1);
387 }
388}
389if ($opt_n) {
390 unless ($opt_n eq "inet4" || $opt_n eq "inet6") {
391 print STDERR "tinet_jsp_configure: inet4 or inet6 expected in -n option\n";
392 exit(1);
393 }
394}
395else {
396 print STDERR "tinet_jsp_configure: -n option is mandatory\n";
397 exit(1);
398}
399if ($opt_s) {
400 unless ($opt_s eq "tcp" || $opt_s eq "udp" || $opt_s eq "tcp/udp") {
401 print STDERR "tinet_jsp_configure: tcp, udp or tcp/udp expected in -s option\n";
402 exit(1);
403 }
404}
405else {
406 print STDERR "tinet_jsp_configure: -s option is mandatory\n";
407 exit(1);
408}
409
410#
411# 変数テーブルの作成
412#
413%vartable = ();
414$vartable{"TARGET"} = $target;
415$vartable{"APPLNAME"} = $applname;
416$vartable{"APPLDIR"} = $appldir;
417$vartable{"APPLOBJS"} = $applobjs;
418$vartable{"KERNEL_LIB"} = $kernel_lib;
419$vartable{"KERNEL_FUNCOBJS"} = $kernel_funcobjs;
420$vartable{"SRCDIR"} = $srcdir;
421$vartable{"SRCABSDIR"} = $srcabsdir;
422$vartable{"SRCLANG"} = $srclang;
423$vartable{"DBGENV"} = $dbgenv;
424$vartable{"ENABLE_TRACE"} = $enable_trace;
425$vartable{"PERL"} = $perl;
426$vartable{"CFG"} = $cfg;
427$objext = do get_objext();
428$vartable{"OBJEXT"} = $objext;
429$vartable{"TINETDIR"} = $tinetdir;
430$vartable{"TINETABSDIR"} = $tinetabsdir;
431$vartable{"NET_IF"} = $net_if;
432$vartable{"NET_DEV"} = $net_dev;
433
434#
435# -n オプションの処理
436#
437
438$vartable{"SUPPORT_INET4"} = "#SUPPORT_INET4 = true";
439$vartable{"SUPPORT_INET6"} = "#SUPPORT_INET6 = true";
440if ($net_proto eq "inet4") {
441 $vartable{"SUPPORT_INET4"} = "SUPPORT_INET4 = true";
442}
443if ($net_proto eq "inet6") {
444 $vartable{"SUPPORT_INET6"} = "SUPPORT_INET6 = true";
445}
446
447#
448# -s オプションの処理
449#
450
451$vartable{"SUPPORT_TCP"} = "#SUPPORT_TCP = true";
452$vartable{"SUPPORT_UDP"} = "#SUPPORT_UDP = true";
453if ($trans_proto eq "tcp" || $trans_proto eq "tcp/udp") {
454 $vartable{"SUPPORT_TCP"} = "SUPPORT_TCP = true";
455}
456if ($trans_proto eq "udp" || $trans_proto eq "tcp/udp") {
457 $vartable{"SUPPORT_UDP"} = "SUPPORT_UDP = true";
458}
459
460#
461# ターゲットディレクトリのチェック
462#
463
464if (! -d $srcdir."/target/".$target) {
465 print STDERR "tinet_asp_configure: $srcdir/target/$target not exist\n";
466 exit(1);
467}
468
469#
470# Makefile とアプリケーションファイルの生成
471#
472
473&genMakefile("Makefile", 1);
474do generate($applname.".c", 0);
475do generate($applname.".cpp", 0);
476do generate($applname.".h", 0);
477do generate($applname.".cfg", 0);
478do generate("tinet_".$applname.".cfg", 0);
479do generate("route_cfg.c", 0);
480do generate("tinet_app_config.h", 0);
481
482#
483# cfg ができているかのチェック
484#
485
486if (!(-x ($objext == "" ? $cfgfile : $cfgfile.".".$objext))) {
487 print STDERR "Please compile the configurator (cfg).\n";
488}
Note: See TracBrowser for help on using the repository browser.