#! /usr/bin/perl # # TINET (TCP/IP Protocol Stack) # # Copyright (C) 2001-2003 by Embedded and Real-Time Systems Laboratory # Toyohashi Univ. of Technology, JAPAN # Copyright (C) 2006-2008 by Embedded and Real-Time Systems Laboratory # Graduate School of Information Science, Nagoya Univ., JAPAN # Copyright (C) 2001-2007 by Dep. of Computer Science and Engineering # Tomakomai National College of Technology, JAPAN # # 上記著作権者は,以下の(1)~(4)の条件を満たす場合に限り,本ソフトウェ # ア(本ソフトウェアを改変したものを含む.以下同じ)を使用・複製・改 # 変・再配布(以下,利用と呼ぶ)することを無償で許諾する. # (1) 本ソフトウェアをソースコードの形で利用する場合には,上記の著作 # 権表示,この利用条件および下記の無保証規定が,そのままの形でソー # スコード中に含まれていること. # (2) 本ソフトウェアを,ライブラリ形式など,他のソフトウェア開発に使 # 用できる形で再配布する場合には,再配布に伴うドキュメント(利用 # 者マニュアルなど)に,上記の著作権表示,この利用条件および下記 # の無保証規定を掲載すること. # (3) 本ソフトウェアを,機器に組み込むなど,他のソフトウェア開発に使 # 用できない形で再配布する場合には,次のいずれかの条件を満たすこ # と. # (a) 再配布に伴うドキュメント(利用者マニュアルなど)に,上記の著 # 作権表示,この利用条件および下記の無保証規定を掲載すること. # (4) 本ソフトウェアの利用により直接的または間接的に生じるいかなる損 # 害からも,上記著作権者およびTOPPERSプロジェクトを免責すること. # また,本ソフトウェアのユーザまたはエンドユーザからのいかなる理 # 由に基づく請求からも,上記著作権者およびTOPPERSプロジェクトを # 免責すること. # # 本ソフトウェアは,無保証で提供されているものである.上記著作権者お # よびTOPPERSプロジェクトは,本ソフトウェアに関して,特定の使用目的 # に対する適合性も含めて,いかなる保証も行わない.また,本ソフトウェ # アの利用により直接的または間接的に生じたいかなる損害に関しても,そ # の責任を負わない. # # @(#) $Id$ # require "getopt.pl"; # オプションの定義 # # -T ターゲット名(必須) # -A アプリケーションプログラム名 # -a アプリケーションのディレクトリ名 # -U 他のアプリケーションプログラムファイル # (.oファイル名で指定.複数指定可) # -L カーネルライブラリ(libkernel.a)のディレクトリ名 # (省略した場合,カーネルライブラリもmakeする) # -f カーネルを関数単位でコンパイルするかどうかの指定 # -D カーネル等のソースの置かれているディレクトリ # -l プログラミング言語(現時点ではcとc++のみサポート) # -t テンプレートディレクトリを指定(デフォルトはtinet/asp_sample) # -d 実行環境の名称 # -r トレースログ記録のサンプルコードを使用するかどうかの指定 # -p perlのパス名(明示的に指定する場合) # -g コンフィギュレータ(cfg)のパス名 # -e TINET のソースの置かれているディレクトリ # -i ネットワークインタフェース(必須) # ether、ppp、loop の何れかを指定する。 # -v イーサネット・ディバイスドライバ # (ネットワークインタフェースに ether を指定した場合は必須) # -n ネットワーク層プロトコル(必須) # inet6、inet4、inet6/inet4、inet6m、inet6m/inet4 の何れかを指定する。 # -s トランスポート層プロトコル(必須) # tcp、udp、tcp/udp の何れかを指定する。 # -m ASPテンプレートディレクトリを指定(デフォルトはsample) # 使用例(1) # # % ../tinet/tinet_asp_configure -T akih8_3069f_gcc -A echos4 -i ether -v if_ed -n inet4 -s tcp # # オブジェクトファイル名の拡張子を返す # sub get_objext { local(@uname); use POSIX; @uname = &uname(); if ($uname[0] =~ /^cygwin/i) { return("exe"); } else { return(""); } } # # プログラムの場所を検索する # sub get_path { local($progname, @pathlist) = @_; local($path); foreach $path (@pathlist) { if (-x $path."/".$progname) { return($path."/".$progname); } } return(""); } # # Makefile を変換する # sub convMakefileSub { local($infile, $outfile) = @_; local($line, $varname, $varval); unless (open(INFILE, $infile)) { print STDERR "tinet_asp_configure: can't open $infile\n"; exit(1); } unless (open(OUTFILE, ">> ".$outfile)) { print STDERR "tinet_asp_configure: can't open $outfile\n"; exit(1); } while ($line = ) { chop $line; while ($line =~ /^(.*)\@\(([A-Za-z0-9_]+)\)(.*)$/) { $line = $1.$vartable{$2}.$3; } print OUTFILE $line,"\n"; } close(INFILE); close(OUTFILE); } # # Makefile を変換する # sub convMakefile { local($infile, $copyright, $outfile) = @_; local($aspMakefile); # Mekfile 有ればリネームする。 print STDERR "tinet_asp_configure: Generating $outfile from $infile.\n"; if (-f $outfile) { print STDERR "tinet_asp_configure: $outfile exists.", " Save as $outfile.bak.\n"; rename($outfile, $outfile.".bak"); } # TINET のコピーライトを書き込む &convMakefileSub($copyright, $outfile); # 出力する Makefile をオープンする unless (open(OUTFILE, ">> ".$outfile)) { print STDERR "tinet_asp_configure: can't open $outfile\n"; exit(1); } # 参照する sample/Makefile をオープンする。 $aspMakefile = $aspsampledir."/Makefile"; unless (open(ASPFILE, $aspMakefile)) { print STDERR "tinet_asp_configure: can't open $aspMakefile\n"; exit(1); } # 参照する sample/Makefile のコピーライトを読み飛ばす。 while ($line = ) { chop $line; if ($line !~ /^#/) { print OUTFILE $line,"\n"; last; } } # 'APPLNAME = @(APPLNAME)' の行まで書き込む while ($line = ) { chop $line; while ($line =~ /^(.*)\@\(([A-Za-z0-9_]+)\)(.*)$/) { $line = $1.$vartable{$2}.$3; } print OUTFILE $line,"\n"; if ($line =~ /^APPLNAME = /) { last; } } # '#' 前の行まで書き込む while ($line = ) { chop $line; while ($line =~ /^(.*)\@\(([A-Za-z0-9_]+)\)(.*)$/) { $line = $1.$vartable{$2}.$3; } if ($line =~ /^#/) { last; } print OUTFILE $line,"\n"; } # 一度出力する Makefile をクローズする。 close(OUTFILE); # TINET の Makefile を書き込む &convMakefileSub($infile, $outfile); # もう一度出力する Makefile をオープンする unless (open(OUTFILE, ">> ".$outfile)) { print STDERR "tinet_asp_configure: can't open $outfile\n"; exit(1); } # 参照する sample/Makefile の最終行まで書き込む while ($line = ) { chop $line; while ($line =~ /^(.*)\@\(([A-Za-z0-9_]+)\)(.*)$/) { $line = $1.$vartable{$2}.$3; } print OUTFILE $line,"\n"; } close(OUTFILE); close(ASPFILE); } # # Makefile を生成する # sub genMakefile { local($file, $mandatory) = @_; local($path, $copyright); $path = $sampledir.$file.".".$applname; $copyright = $sampledir.$file.".copyright"; if (-f $path) { &convMakefile($path, $copyright, $file); return; } $path = $sampledir.$file; if ($mandatory || -f $path) { &convMakefile($path, $copyright, $file); } } # # ファイルを変換する # sub convert { local($infile, $outfile) = @_; local($line, $varname, $varval); print STDERR "tinet_asp_configure: Generating $outfile from $infile.\n"; if (-f $outfile) { print STDERR "tinet_asp_configure: $outfile exists.", " Save as $outfile.bak.\n"; rename($outfile, $outfile.".bak"); } unless (open(INFILE, $infile)) { print STDERR "tinet_asp_configure: can't open $infile\n"; exit(1); } unless (open(OUTFILE, "> ".$outfile)) { print STDERR "tinet_asp_configure: can't open $outfile\n"; exit(1); } while ($line = ) { chop $line; while ($line =~ /^(.*)\@\(([A-Za-z0-9_]+)\)(.*)$/) { $line = $1.$vartable{$2}.$3; } print OUTFILE $line,"\n"; } close(INFILE); close(OUTFILE); } # # サンプルを見つけてファイルを生成する # sub generate { local($file, $mandatory) = @_; local($path); $path = $sampledir.$file.".".$applname; if (-f $path) { &convert($path, $file); return; } $path = $sampledir.$file; if ($mandatory || -f $path) { &convert($path, $file); } } # # メイン処理 # # オプションの処理 # &Getopt("TAaULDltdpgiensv"); # # 変数の初期化 # $perl = $opt_p ? $opt_p : &get_path("perl", ("/usr/local/bin", "/usr/bin")); $target = $opt_T; $applname = $opt_A ? $opt_A : ""; $appldir = $opt_a ? $opt_a : ""; $applobjs = $opt_U ? $opt_U : ""; $kernel_lib = $opt_L ? $opt_L : ""; $kernel_funcobjs = $opt_f ? "true" : ""; $srclang = $opt_l ? $opt_l : "c"; $templatedir = $opt_t ? $opt_t : "asp_sample"; $dbgenv = $opt_d ? "TOPPERS_".$opt_d : ""; $enable_trace = $opt_r ? "true" : ""; $net_if = $opt_i; $net_dev = $opt_v; $net_proto = $opt_n; $trans_proto = $opt_s; $aspsampledir = $opt_m ? $opt_m : "sample"; $cfg = $opt_g ? $opt_g : "\$(SRCDIR)/cfg/cfg/cfg"; $cfgfile = $opt_g ? $opt_g : $srcdir."/cfg/cfg/cfg"; # # オプションの確認 # unless ($opt_T) { print STDERR "tinet_asp_configure: -T option is mandatory\n"; print STDERR "Installed targets are:\n"; foreach $targetname (<$srcdir/target/[a-zA-Z1-9]*>) { $targetname =~ s|$srcdir/target/||; print STDERR "\t$targetname\n"; } exit(1); } unless ($opt_i) { print STDERR "tinet_asp_configure: -i option is mandatory\n"; exit(1); } else { unless ($opt_v) { print STDERR "tinet_asp_configure: -v option is mandatory\n"; exit(1); } } if ($opt_n) { unless ($opt_n eq "inet6" || $opt_n eq "inet4" || $opt_n eq "inet6/inet4" || $opt_n eq "inet6m" || $opt_n eq "inet6m/inet4") { print STDERR "tinet_asp_configure: inet6, inet4, inet6/inet4, inet6m or inet6m/inet4 expected in -n option\n"; exit(1); } } else { print STDERR "tinet_asp_configure: -n option is mandatory\n"; exit(1); } if ($opt_s) { unless ($opt_s eq "tcp" || $opt_s eq "udp" || $opt_s eq "tcp/udp") { print STDERR "tinet_asp_configure: tcp, udp or tcp/udp expected in -s option\n"; exit(1); } } else { print STDERR "tinet_asp_configure: -s option is mandatory\n"; exit(1); } # # TINET のソースディレクトリ名を取り出す # $pwd = `pwd`; chop $pwd; if ($opt_e) { $tinetabsdir = $tinetdir = $opt_e; } elsif ($0 =~ /(.*)\/tinet_asp_configure/) { $tinetdir = $1; if ($tinetdir =~ /^\//) { $tinetabsdir = $tinetdir; } else { $tinetabsdir = $pwd."/".$tinetdir; } } else { $tinetabsdir = $tinetdir = $pwd; } $sampledir = $tinetdir."/".$templatedir."/"; # # ソースディレクトリ名を取り出す # $pwd = `pwd`; chop $pwd; if ($opt_D) { $srcabsdir = $srcdir = $opt_D; } elsif ($0 =~ /(.*)\/tinet\/tinet_asp_configure/) { $srcdir = $1; if ($srcdir =~ /^\//) { $srcabsdir = $srcdir; } else { $srcabsdir = $pwd."/".$srcdir; } } else { $srcabsdir = $srcdir = $pwd; } $aspsampledir = $srcdir."/".$aspsampledir; # # 変数テーブルの作成 # %vartable = (); $vartable{"TARGET"} = $target; $vartable{"APPLNAME"} = $applname; $vartable{"APPLDIR"} = $appldir; $vartable{"APPLOBJS"} = $applobjs; $vartable{"KERNEL_LIB"} = $kernel_lib; $vartable{"KERNEL_FUNCOBJS"} = $kernel_funcobjs; $vartable{"SRCDIR"} = $srcdir; $vartable{"SRCABSDIR"} = $srcabsdir; $vartable{"SRCLANG"} = $srclang; $vartable{"DBGENV"} = $dbgenv; $vartable{"ENABLE_TRACE"} = $enable_trace; $vartable{"OBJEXT"} = &get_objext(); $vartable{"PERL"} = $perl; $vartable{"CFG"} = $cfg; $vartable{"TINETDIR"} = $tinetdir; $vartable{"TINETABSDIR"} = $tinetabsdir; $vartable{"NET_IF"} = $net_if; $vartable{"NET_DEV"} = $net_dev; # # -n オプションの処理 # $vartable{"SUPPORT_INET6"} = "#SUPPORT_INET6 = true"; $vartable{"SUPPORT_INET4"} = "#SUPPORT_INET4 = true"; if ($net_proto eq "inet6" || $net_proto eq "inet6/inet4" || $net_proto eq "inet6m" || $net_proto eq "inet6m/inet4") { $vartable{"SUPPORT_INET6"} = "SUPPORT_INET6 = true"; } if ($net_proto eq "inet4" || $net_proto eq "inet6/inet4" || $net_proto eq "inet6m/inet4") { $vartable{"SUPPORT_INET4"} = "SUPPORT_INET4 = true"; } $vartable{"API_CFG_IP4MAPPED_ADDR"} = "#API_CFG_IP4MAPPED_ADDR = true"; if ($net_proto eq "inet6m" || $net_proto eq "inet6m/inet4") { $vartable{"API_CFG_IP4MAPPED_ADDR"} = "API_CFG_IP4MAPPED_ADDR = true"; } # # -s オプションの処理 # $vartable{"SUPPORT_TCP"} = "#SUPPORT_TCP = true"; $vartable{"SUPPORT_UDP"} = "#SUPPORT_UDP = true"; if ($trans_proto eq "tcp" || $trans_proto eq "tcp/udp") { $vartable{"SUPPORT_TCP"} = "SUPPORT_TCP = true"; } if ($trans_proto eq "udp" || $trans_proto eq "tcp/udp") { $vartable{"SUPPORT_UDP"} = "SUPPORT_UDP = true"; } # # ターゲットディレクトリのチェック # if (! -d $srcdir."/target/".$target) { print STDERR "tinet_asp_configure: $srcdir/target/$target not exist\n"; exit(1); } # # Makefile とアプリケーションファイルの生成 # &genMakefile("Makefile", 1); &generate($applname.".c", 0); &generate($applname.".cpp", 0); &generate($applname.".h", 0); &generate($applname.".cfg", 0); &generate("tinet_".$applname.".cfg", 0); &generate("route_cfg.c", 0); &generate("tinet_app_config.h", 0); # # cfg ができているかのチェック # if (!(-x ($objext == "" ? $cfgfile : $cfgfile.".".$objext))) { print STDERR "Please compile the configurator (cfg).\n"; }