FORTRANの導入
今回は組込みボードに各種のインタープリタ言語を導入する方法について解説しますが、
概要
SH7706LSRボードでは、
FORTRANコンパイラには、
注意が必要なのは、
FORTRANの場合はFORTRAN特有の組込み関数は別途ライブラリとして用意しておき、
導入
FORTRANトランスレータ一式は以下のサイトがオリジナルです。
- The Netlib
- URL:http://
www. netlib. org/
まとまったアーカイブf2c.
- Using gfortran or installing f2c and fort77
- URL:https://
computation. llnl. gov/ casc/ Overture/ henshaw/ install/ node8. html
アーカイブf2c.
まず、
01: # Unix makefile: see README.
02: # For C++, first "make hadd".
03: # If your compiler does not recognize ANSI C, add
04: # -DKR_headers
05: # to the CFLAGS = line below.
06: # On Sun and other BSD systems that do not provide an ANSI sprintf, add
07: # -DUSE_STRLEN
08: # to the CFLAGS = line below.
09: # On Linux systems, add
10: # -DNON_UNIX_STDIO
11: # to the CLFAGS = line below.
12: .SUFFIXES: .c .o
13: CC = gcc
14: SHELL = /bin/sh
15: CFLAGS = -O
16:
17: # compile, then strip unnecessary symbols
18: .c.o:
19: $(CC) -c -DSkip_f2c_Undefs $(CFLAGS) $*.c
20: # wdh ld -r -x -o $*.xxx $*.o
21: ld -r -o $*.xxx $*.o
22: mv $*.xxx $*.o
《以下略》
makefileであるリスト1の13行目と21行目を以下のように変更します。
CC = sh3-linux-gcc
sh3-linux-ld -r -o $*.xxx $*.o
コンパイルは以下のように行います。
# make
できあがったライブラリは、
# cp libf2c.a /usr/sh3-linux/sh3-linux/lib
次に、
# make
できあがったトランスレータは、
# cp f2c /usr/bin # cp xsum /usr/bin
これですべての導入が完了しました。
プログラム実行
PC上でFORTRAN言語のプログラムを作成します。
2つの変数に数値データを入力してから、
01: programme memain
02:
03: write(*,*) 'Input a and b.'
04: write(*,*) 'a ='
05: read(*,*) a
06: write(*,*) 'b ='
07: read(*,*) b
08:
09: c=a+b
10: d=a-b
11: e=a*b
12: f=a/b
13:
14: write(*,*) a,'+',b,'=',c
15: write(*,*) a,'-',b,'=',d
16: write(*,*) a,'*',b,'=',e
17: write(*,*) a,'/',b,'=',f
18:
19: end
FORTRAN言語のソースのコンパイルは以下のようにします。
# f2c sample.f # sh3-linux-gcc -o sample sample.c -lf2c
できあがったSH3アーキテクチャー向けの実行ファイルである sample をSH7706LSRボード向けのファイルシステムの適当な場所にコピーをします。SH7706LSRボードでLinuxを起動し、
~ # ./sample Input a and b. a = 23 b = 15 23.+ 15.= 38. 23.- 15.= 8. 23.* 15.= 345. 23./ 15.= 1.5333333 ~ #
awkインタープリタの導入
awk言語はデータ処理志向のプログラミング言語で、
awk言語はデータ処理志向のプログラミング言語ではありますが、
導入
SH7706LSRのサイトで標準公開しているファイルシステムは、


実行
まず、
~ # awk 'BEGIN {a=20;b=30;printf("[%d]\n", a*b)}' [600] ~ #
次に、
01: BEGIN {
02: printf("Parts\t Unit price\tNumber\tPrices\n");
03: total = 0;
04: }
05: {
06: printf("%s\t%d\t%d\t%d\n", $1, $2, $3, $2 * $3);
07: total = total + $2 * $3;
08: }
09: END {
10: printf("Total prices\t%d\n", total);
11: }
Processor 4600 120
Memory/SDRAM 980 240
Crystal-Unit 120 360
Capacitor 10 12000
Resistor 5 24000
~ # awk -f calc.awk data.dat Parts Unit price Number Prices Processor 4600 120 552000 Memory/SDRAM 980 240 235200 Crystal-Unit 120 360 43200 Capacitor 10 12000 120000 Resistor 5 24000 120000 Total prices 1070400 ~ #
Perlインタープリタの導入
概要
PerlはWebサーバにおけるCGIプログラムのインタープリタ言語として定番ですが、
実は現在のPerlの標準ソースパッケージではBusyBoxのようなコンパクトでシンプルな組込みボード向けの構築もできるようになっています。そのようにして構築したPerlは特にmicroperlという名称になっています。
microperlはフルセットではないですが、
導入
microperlはBusyBoxにも組込み可能なようになってはいますが、
コンパイルは以下のようにします。
# CC=sh3-linux-gcc make -f Makefile.micro
できあがった実行ファイルであるmicroperlは、
実行
SH7706LSRのLinux上でsample.
01: #!/usr/bin/microperl
02:
03: print "Content-type: text/plain\n\n";
04: print "Sample program written by perl.\n";
ためしに、
~ # ./sample.pl Content-type: text/plain Sample program written by perl. ~ #
そして、

次回は、