source: azure_iot_hub/trunk/asp3_dcre/tinet/tinet_asp_configure@ 388

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

Azure IoT Hub Device C SDK を使ったサンプルの追加

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