LoginSignup
1
2

More than 5 years have passed since last update.

馬鹿の一つ覚え: configureおよびMakefileの作り方

Last updated at Posted at 2018-07-20

Autotoolsを利用したconfigureおよびMakefileの作り方、一連の作業のまとめ

$ ls -l
total 4
drwxr-xr-x 2 glire glire 4096 Jul 20 11:15 src
$ ls -l src/
total 36
-rw-r--r-- 1 glire glire  9781 Jul  9 05:26 bar.c
-rw-r--r-- 1 glire glire  3458 Jul 20 11:13 baz.c
-rw-r--r-- 1 glire glire 10505 Jul 20 11:13 foo.c
-rw-r--r-- 1 glire glire  2105 Jul 19 19:27 foo.h
-rw-r--r-- 1 glire glire  1593 Jul 20 11:12 qux.c
$ vi Makefile.am
$ cat Makefile.am
# Makefile.am
SUBDIRS = src
$ vi src/Makefile.am
$ cat src/Makefile.am    # foo_SOURCES foo_LDADD foo_CFLAGS これら3行のfooの書き換えにも注意
# src/Makefile.am
bin_PROGRAMS = foo
foo_SOURCES = foo.c foo.h bar.c baz.c qux.c
foo_LDADD = -lm
foo_CFLAGS = -W -Wall -Werror -pedantic-errors -O
$ autoscan
$ ls -l configure.scan 
-rw-r--r-- 1 glire glire 674 Jul 20 11:30 configure.scan
$ cp configure.scan configure.ac   
$ mv configure.scan /tmp/
$ vi configure.ac    # AC_INIT の後に AM_INIT_AUTOMAKE を書き足す
$ diff /tmp/configure.scan configure.ac
5c5,6
< AC_INIT([FULL-PACKAGE-NAME], [VERSION], [BUG-REPORT-ADDRESS])
---
> AC_INIT([Foo], [1.2], [bug@report.address])
> AM_INIT_AUTOMAKE
$ touch NEWS README AUTHORS ChangeLog
$ autoheader
$ aclocal
$ automake -a -c
$ autoconf
$ ls -l
total 344
-rw-r--r-- 1 glire glire      0 Jul 20 11:31 AUTHORS
-rw-r--r-- 1 glire glire  35147 Jul 20 11:31 COPYING
-rw-r--r-- 1 glire glire      0 Jul 20 11:31 ChangeLog
-rw-r--r-- 1 glire glire  15578 Jul 20 11:31 INSTALL
-rw-r--r-- 1 glire glire     28 Jul 20 11:21 Makefile.am
-rw-r--r-- 1 glire glire  21417 Jul 20 11:31 Makefile.in
-rw-r--r-- 1 glire glire      0 Jul 20 11:31 NEWS
-rw-r--r-- 1 glire glire      0 Jul 20 11:31 README
-rw-r--r-- 1 glire glire  34611 Jul 20 11:31 aclocal.m4
drwxr-xr-x 2 glire glire   4096 Jul 20 11:31 autom4te.cache
-rw-r--r-- 1 glire glire      0 Jul 20 11:30 autoscan.log
-rw-r--r-- 1 glire glire   1514 Jul 20 11:31 config.h.in
-rwxr-xr-x 1 glire glire 167610 Jul 20 11:32 configure
-rw-r--r-- 1 glire glire    673 Jul 20 11:31 configure.ac
-rwxr-xr-x 1 glire glire  18615 Jul 20 11:31 depcomp
-rwxr-xr-x 1 glire glire  13663 Jul 20 11:31 install-sh
-rwxr-xr-x 1 glire glire  11419 Jul 20 11:31 missing
drwxr-xr-x 2 glire glire   4096 Jul 20 11:31 src
$ ls -l src/
total 60
-rw-r--r-- 1 glire glire   144 Jul 20 11:21 Makefile.am
-rw-r--r-- 1 glire glire 20147 Jul 20 11:31 Makefile.in
-rw-r--r-- 1 glire glire  9781 Jul  9 05:26 bar.c
-rw-r--r-- 1 glire glire  3458 Jul 20 11:13 baz.c
-rw-r--r-- 1 glire glire 10505 Jul 20 11:13 foo.c
-rw-r--r-- 1 glire glire  2105 Jul 19 19:27 foo.h
-rw-r--r-- 1 glire glire  1593 Jul 20 11:12 qux.c
$ ./configure
$ ls -l Makefile* src/Makefile*
-rw-r--r-- 1 glire glire 21638 Jul 20 11:32 Makefile
-rw-r--r-- 1 glire glire    28 Jul 20 11:21 Makefile.am
-rw-r--r-- 1 glire glire 21417 Jul 20 11:31 Makefile.in
-rw-r--r-- 1 glire glire 18675 Jul 20 11:32 src/Makefile
-rw-r--r-- 1 glire glire   147 Jul 20 11:21 src/Makefile.am
-rw-r--r-- 1 glire glire 20147 Jul 20 11:31 src/Makefile.in
$ make
$ ls -lF src/foo
-rwxr-xr-x 1 glire glire 36872 Jul 20 11:33 src/foo*
$ make clean   # Making clean in src
$ ls -l src/
total 80
-rw-r--r-- 1 glire glire 18675 Jul 20 11:32 Makefile
-rw-r--r-- 1 glire glire   147 Jul 20 11:21 Makefile.am
-rw-r--r-- 1 glire glire 20147 Jul 20 11:31 Makefile.in
-rw-r--r-- 1 glire glire  9781 Jul  9 05:26 bar.c
-rw-r--r-- 1 glire glire  3458 Jul 20 11:13 baz.c
-rw-r--r-- 1 glire glire 10505 Jul 20 11:13 foo.c
-rw-r--r-- 1 glire glire  2105 Jul 19 19:27 foo.h
-rw-r--r-- 1 glire glire  1593 Jul 20 11:12 qux.c
$ make
$ sudo make install
1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2