./configure && make && make install && make uninstall 出来るプロジェクトを作る練習記録

# ./configure && make && make install && make uninstall

Step 1.

A simple minimal project that you can only do `./configure` and `make`.

## Environment

* OS: Ubuntu 14.04
* automake: (GNU automake) 1.14.1
* autoconf: (GNU autoconf) 2.69

`sudo apt-get install build-essential automake`

## Experiment log

```bash
mkdir myapp && cd myapp

autoscan
# "configure.scan" is generated.
# It is a template for "configure.ac".
mv configure.scan configure.ac

autoconf
# "configure" is generated from "configure.ac".

# But, this "configure.ac" dosen't include "AC_CONFIG_FILES([Makefile])".
# It is needed for automake.
mv configure.ac configure.ac-without-Makefile.am
touch Makefile.am
autoscan
mv configure.scan configure.ac
diff configure.ac-without-Makefile.am configure.ac
# 16a17
# > AC_CONFIG_FILES([Makefile])
rm configure.ac-without-Makefile.am

automake #=> Error
# configure.ac: error: no proper invocation of AM_INIT_AUTOMAKE was found.
# configure.ac: You should verify that configure.ac invokes AM_INIT_AUTOMAKE,
# configure.ac: that aclocal.m4 is present in the top-level directory,
# configure.ac: and that aclocal.m4 was recently regenerated (using aclocal)
# Makefile.am: error: required file './INSTALL' not found
# Makefile.am:   'automake --add-missing' can install 'INSTALL'
# Makefile.am: error: required file './NEWS' not found
# Makefile.am: error: required file './README' not found
# Makefile.am: error: required file './AUTHORS' not found
# Makefile.am: error: required file './ChangeLog' not found
# Makefile.am: error: required file './COPYING' not found
# Makefile.am:   'automake --add-missing' can install 'COPYING'

# Create necesary files.
touch INSTALL
touch NEWS
touch README
touch AUTHORS
touch ChangeLog
touch COPYING

automake #=> Error
# configure.ac: error: no proper invocation of AM_INIT_AUTOMAKE was found.
# configure.ac: You should verify that configure.ac invokes AM_INIT_AUTOMAKE,
# configure.ac: that aclocal.m4 is present in the top-level directory,
# configure.ac: and that aclocal.m4 was recently regenerated (using aclocal)

# Insert "AM_INIT_AUTOMAKE" after the line of
# "AC_INIT([FULL-PACKAGE-NAME], [VERSION], [BUG-REPORT-ADDRESS])"
X=`grep AC_INIT configure.ac -n | cut -d : -f 1` # Detect the line number
head -${X} configure.ac > temp # Cut the head part
echo AM_INIT_AUTOMAKE >> temp
tail -n +$((X+1)) configure.ac >> temp # Cut the tail part and append it
mv temp configure.ac

automake #=> Error
# configure.ac: error: no proper invocation of AM_INIT_AUTOMAKE was found.
# configure.ac: You should verify that configure.ac invokes AM_INIT_AUTOMAKE,
# configure.ac: that aclocal.m4 is present in the top-level directory,
# configure.ac: and that aclocal.m4 was recently regenerated (using aclocal)

# Need to run "aclocal" and run "autoconf" again.
aclocal
autoconf

automake #=> Error
# configure.ac:6: error: required file './install-sh' not found
# configure.ac:6:   'automake --add-missing' can install 'install-sh'
# configure.ac:6: error: required file './missing' not found
# configure.ac:6:   'automake --add-missing' can install 'missing'

automake --add-missing
# Symbolic links of "install-sh" and "missing" are generated.
# "--add-missing" option can be shortened to "-a"

./configure
# checking for a BSD-compatible install... /usr/bin/install -c
# checking whether build environment is sane... yes
# checking for a thread-safe mkdir -p... /bin/mkdir -p
# checking for gawk... no
# checking for mawk... mawk
# checking whether make sets $(MAKE)... yes
# checking whether make supports nested variables... yes
# checking that generated files are newer than configure... done
# configure: creating ./config.status
# config.status: creating Makefile
make
# make: Nothing to be done for `all'.
```

## Conclusion

```bash
mkdir myapp
cd myapp
touch Makefile.am
autoscan
mv configure.scan configure.ac
autoconf
touch INSTALL
touch NEWS
touch README
touch AUTHORS
touch ChangeLog
touch COPYING
X=`grep AC_INIT configure.ac -n | cut -d : -f 1`
head -${X} configure.ac > temp
echo AM_INIT_AUTOMAKE >> temp
tail -n +$((X+1)) configure.ac >> temp
mv temp configure.ac
aclocal
autoconf
automake -a
./configure
make
```

## Ignore files

`.gitignore` is generated with [this link](http://www.gitignore.io/api/autotools) by [gitignore.io - Create useful .gitignore files for your project](http://www.gitignore.io/).

But, I think that following files should also be ignored.

```
/autoscan.log
/config.log
/config.status
/Makefile
```

So, I create `.gitignore` by following commands.

```bash
curl www.gitignore.io/api/autotools > .gitignore
echo '/autoscan.log'  >> .gitignore
echo '/config.log'    >> .gitignore
echo '/config.status' >> .gitignore
echo '/Makefile'      >> .gitignore
```

## References

### automake, autotools

* [Twitter / cress_cc: @ ka_ automakeだっけ](https://twitter.com/cress_cc/status/463953411881197568)
* [Autotools - Wikipedia](http://ja.wikipedia.org/wiki/Autotools)

### autoscan

* [Twitter / s5yata: @ ka_ @ sunny4381 autoscan ...](https://twitter.com/s5yata/status/463956713121411072)

### automake example

* [GNU Automake By Example](http://socgsa.cs.clemson.edu/seminar/tools06/resources/08_autotools/automake.htm)
* [automake: Built Sources Example](http://www.gnu.org/software/automake/manual/html_node/Built-Sources-Example.html)
* [Automakeでmakeする](http://www.02.246.ne.jp/~torutk/cxx/automake/automake.html)
* [automake: いくつかのパッケージの例](http://www.bookshelf.jp/texi/automake-ja/automake-ja_3.html)

### About "no proper invocation of AM_INIT_AUTOMAKE was found" error

* [transitive.info - autotools でコンパイルする (2. automake)](http://transitive.info/2012/07/21/autotools-tutorial2-automake/)

### About "install-sh" and "missing" missing

* [autotools: small example](http://www.adp-gmbh.ch/misc/tools/configure/small_example.html)

## TODO

* Modify `configure.ac` and `Makefile.am` for my own project
* `./configure --prefix=$HOME/local && make install && make uninstall`