binutilsのbin2cをビルド

前回見つけたbin2c.cをビルドしてみます。

まず、bin2c.cが単体でビルドできるか確認します。メイクファイル(makefileやmakefile等)の依存ファイルにbin2c.cがあるか確認。もしかしたらメイクのターゲットからコマンド名も分かるかもしれません。

takk@deb9:~/src/binutils-2.28$ grep -rn bin2c.c *
binutils/po/da.po:426:#: bin2c.c:59
binutils/po/da.po:431:#: bin2c.c:60
binutils/po/sk.po:377:#: bin2c.c:59
binutils/po/sk.po:382:#: bin2c.c:60
binutils/po/id.po:413:#: bin2c.c:59
binutils/po/id.po:418:#: bin2c.c:60
binutils/po/POTFILES.in:5:bin2c.c
binutils/Makefile.am:130:	addr2line.c ar.c arsup.c bin2c.c binemul.c bucomm.c \
binutils/Makefile.am:319:bin2c$(EXEEXT_FOR_BUILD): bin2c.c
binutils/Makefile.am:320:	$(CC_FOR_BUILD) -o $@ $(AM_CPPFLAGS) $(AM_CFLAGS_FOR_BUILD) $(CFLAGS_FOR_BUILD) $(LDFLAGS_FOR_BUILD) $(srcdir)/bin2c.c
binutils/ChangeLog-2008:269:	* bin2c.c (O_BINARY, O_TEXT, SET_BINARY): Don't define here.
binutils/ChangeLog-2007:418:	* ar.c, arlex.l, arparse.y, arsup.c, arsup.h, bin2c.c, binemul.c,
binutils/ChangeLog-2007:991:	* bin2c.c: New file.
binutils/ChangeLog-2007:993:	(CFILES): Add bin2c.c.
binutils/Makefile.in:537:	addr2line.c ar.c arsup.c bin2c.c binemul.c bucomm.c \
binutils/Makefile.in:1384:bin2c$(EXEEXT_FOR_BUILD): bin2c.c
binutils/Makefile.in:1385:	$(CC_FOR_BUILD) -o $@ $(AM_CPPFLAGS) $(AM_CFLAGS_FOR_BUILD) $(CFLAGS_FOR_BUILD) $(LDFLAGS_FOR_BUILD) $(srcdir)/bin2c.c
binutils/ChangeLog-2010:224:	* bin2c.c: Remove internationalization and version report.
binutils/bin2c.c:1:/* bin2c.c -- dump binary file in hex format
md5.sum:608:4b78318422244153c00d3bf5a55c84ca  binutils/bin2c.c
takk@deb9:~/src/binutils-2.28$ 

ありました。
この2行がそうですね。

binutils/Makefile.am:319:bin2c$(EXEEXT_FOR_BUILD): bin2c.c
binutils/Makefile.am:320:	$(CC_FOR_BUILD) -o $@ $(AM_CPPFLAGS) $(AM_CFLAGS_FOR_BUILD) $(CFLAGS_FOR_BUILD) $(LDFLAGS_FOR_BUILD) $(srcdir)/bin2c.c

ターゲットbin2cは、依存ファイルがbin2c.cで、実行するコマンドが、#(CC_FOR_BUILD)です。
binutilsディレクトリ内で、ビルドするようです。
binutilsディレクトリへcdして、configureを実行します。

takk@deb9:~/src/binutils-2.28$ cd binutils
takk@deb9:~/src/binutils-2.28/binutils$ ./configure

省略

takk@deb9:~/src/binutils-2.28/binutils$ grep -n bin2c.c *
ChangeLog-2007:418:	* ar.c, arlex.l, arparse.y, arsup.c, arsup.h, bin2c.c, binemul.c,
ChangeLog-2007:991:	* bin2c.c: New file.
ChangeLog-2007:993:	(CFILES): Add bin2c.c.
ChangeLog-2008:269:	* bin2c.c (O_BINARY, O_TEXT, SET_BINARY): Don't define here.
ChangeLog-2010:224:	* bin2c.c: Remove internationalization and version report.
Makefile:537:	addr2line.c ar.c arsup.c bin2c.c binemul.c bucomm.c \
Makefile:1384:bin2c$(EXEEXT_FOR_BUILD): bin2c.c
Makefile:1385:	$(CC_FOR_BUILD) -o $@ $(AM_CPPFLAGS) $(AM_CFLAGS_FOR_BUILD) $(CFLAGS_FOR_BUILD) $(LDFLAGS_FOR_BUILD) $(srcdir)/bin2c.c
Makefile.am:130:	addr2line.c ar.c arsup.c bin2c.c binemul.c bucomm.c \
Makefile.am:319:bin2c$(EXEEXT_FOR_BUILD): bin2c.c
Makefile.am:320:	$(CC_FOR_BUILD) -o $@ $(AM_CPPFLAGS) $(AM_CFLAGS_FOR_BUILD) $(CFLAGS_FOR_BUILD) $(LDFLAGS_FOR_BUILD) $(srcdir)/bin2c.c
Makefile.in:537:	addr2line.c ar.c arsup.c bin2c.c binemul.c bucomm.c \
Makefile.in:1384:bin2c$(EXEEXT_FOR_BUILD): bin2c.c
Makefile.in:1385:	$(CC_FOR_BUILD) -o $@ $(AM_CPPFLAGS) $(AM_CFLAGS_FOR_BUILD) $(CFLAGS_FOR_BUILD) $(LDFLAGS_FOR_BUILD) $(srcdir)/bin2c.c
bin2c.c:1:/* bin2c.c -- dump binary file in hex format
grep: doc: ディレクトリです
grep: po: ディレクトリです
grep: testsuite: ディレクトリです
takk@deb9:~/src/binutils-2.28/binutils$ 

次に、ターゲット、bin2cを指定してmakeします。

takk@deb9:~/src/binutils-2.28/binutils$ make bin2c
gcc -o bin2c -I. -I. -I../bfd -I./../bfd -I./../include -DLOCALEDIR="\"/usr/local/share/locale\"" -Dbin_dummy_emulation=bin_vanilla_emulation -W -Wall -Wstrict-prototypes -Wmissing-prototypes -Wshadow -Wstack-usage=262144 -I./../zlib   ./bin2c.c
takk@deb9:~/src/binutils-2.28/binutils$ 

ビルドできました。
実行ファイルを確認しましょう。

takk@deb9:~/src/binutils-2.28/binutils$ ls -l bin2c
-rwxr-xr-x 1 takk takk 9016  8月 24 22:35 bin2c
takk@deb9:~/src/binutils-2.28/binutils$ 

使い方を確認します。

takk@deb9:~/src/binutils-2.28/binutils$ ./bin2c -h
Usage: ./bin2c < input_file > output_file
Prints bytes from stdin in hex format.
takk@deb9:~/src/binutils-2.28/binutils$ 

使ってみましょう。bin2c自身をダンプしてみました。

takk@deb9:~/src/binutils-2.28/binutils$ ./bin2c < bin2c | head
0x7f,0x45,0x4c,0x46,0x02,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x03,0x00,0x3e,0x00,0x01,0x00,0x00,0x00,0xa0,0x07,0x00,0x00,0x00,0x00,0x00,0x00,
0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x78,0x1b,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x40,0x00,0x38,0x00,0x09,0x00,0x40,0x00,0x1f,0x00,0x1e,0x00,
0x06,0x00,0x00,0x00,0x05,0x00,0x00,0x00,0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0xf8,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0xf8,0x01,0x00,0x00,0x00,0x00,0x00,0x00,
0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x04,0x00,0x00,0x00,
0x38,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x38,0x02,0x00,0x00,0x00,0x00,0x00,0x00,
0x38,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x1c,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
takk@deb9:~/src/binutils-2.28/binutils$ 

Leave a Reply

Your email address will not be published. Required fields are marked *

CAPTCHA