/autotools/automake.html_node/Creating-amhello.html
HTML | 235 lines | 173 code | 21 blank | 41 comment | 0 complexity | 58bf4b5e44f6e4d95950d86c3bf374dc MD5 | raw file
- <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
- <html>
- <!--
- This manual is for GNU Automake (version 1.15,
- 31 December 2014), a program that creates GNU standards-compliant
- Makefiles from template files.
- Copyright (C) 1995-2014 Free Software Foundation, Inc.
- Permission is granted to copy, distribute and/or modify this document
- under the terms of the GNU Free Documentation License,
- Version 1.3 or any later version published by the Free Software
- Foundation; with no Invariant Sections, with no Front-Cover texts,
- and with no Back-Cover Texts. A copy of the license is included in the
- section entitled "GNU Free Documentation License."
- -->
- <!-- Created by GNU Texinfo 5.2, http://www.gnu.org/software/texinfo/ -->
- <head>
- <title>automake: Creating amhello</title>
- <meta name="description" content="automake: Creating amhello">
- <meta name="keywords" content="automake: Creating amhello">
- <meta name="resource-type" content="document">
- <meta name="distribution" content="global">
- <meta name="Generator" content="makeinfo">
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
- <link href="index.html#Top" rel="start" title="Top">
- <link href="Indices.html#Indices" rel="index" title="Indices">
- <link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
- <link href="Hello-World.html#Hello-World" rel="up" title="Hello World">
- <link href="amhello_0027s-configure_002eac-Setup-Explained.html#amhello_0027s-configure_002eac-Setup-Explained" rel="next" title="amhello's configure.ac Setup Explained">
- <link href="Hello-World.html#Hello-World" rel="prev" title="Hello World">
- <style type="text/css">
- <!--
- a.summary-letter {text-decoration: none}
- blockquote.smallquotation {font-size: smaller}
- div.display {margin-left: 3.2em}
- div.example {margin-left: 3.2em}
- div.indentedblock {margin-left: 3.2em}
- div.lisp {margin-left: 3.2em}
- div.smalldisplay {margin-left: 3.2em}
- div.smallexample {margin-left: 3.2em}
- div.smallindentedblock {margin-left: 3.2em; font-size: smaller}
- div.smalllisp {margin-left: 3.2em}
- kbd {font-style:oblique}
- pre.display {font-family: inherit}
- pre.format {font-family: inherit}
- pre.menu-comment {font-family: serif}
- pre.menu-preformatted {font-family: serif}
- pre.smalldisplay {font-family: inherit; font-size: smaller}
- pre.smallexample {font-size: smaller}
- pre.smallformat {font-family: inherit; font-size: smaller}
- pre.smalllisp {font-size: smaller}
- span.nocodebreak {white-space:nowrap}
- span.nolinebreak {white-space:nowrap}
- span.roman {font-family:serif; font-weight:normal}
- span.sansserif {font-family:sans-serif; font-weight:normal}
- ul.no-bullet {list-style: none}
- -->
- </style>
- </head>
- <body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000">
- <a name="Creating-amhello"></a>
- <div class="header">
- <p>
- Next: <a href="amhello_0027s-configure_002eac-Setup-Explained.html#amhello_0027s-configure_002eac-Setup-Explained" accesskey="n" rel="next">amhello's configure.ac Setup Explained</a>, Up: <a href="Hello-World.html#Hello-World" accesskey="u" rel="up">Hello World</a> [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Indices.html#Indices" title="Index" rel="index">Index</a>]</p>
- </div>
- <hr>
- <a name="Creating-amhello_002d1_002e0_002etar_002egz"></a>
- <h4 class="subsection">2.4.1 Creating <samp>amhello-1.0.tar.gz</samp></h4>
- <p>Here is how we can recreate <samp>amhello-1.0.tar.gz</samp> from scratch.
- The package is simple enough so that we will only need to write 5
- files. (You may copy them from the final <samp>amhello-1.0.tar.gz</samp>
- that is distributed with Automake if you do not want to write them.)
- </p>
- <p>Create the following files in an empty directory.
- </p>
- <ul>
- <li> <samp>src/main.c</samp> is the source file for the <samp>hello</samp> program. We
- store it in the <samp>src/</samp> subdirectory, because later, when the package
- evolves, it will ease the addition of a <samp>man/</samp> directory for man
- pages, a <samp>data/</samp> directory for data files, etc.
- <div class="example">
- <pre class="example">~/amhello % <kbd>cat src/main.c</kbd>
- #include <config.h>
- #include <stdio.h>
- int
- main (void)
- {
- puts ("Hello World!");
- puts ("This is " PACKAGE_STRING ".");
- return 0;
- }
- </pre></div>
- </li><li> <samp>README</samp> contains some very limited documentation for our little
- package.
- <div class="example">
- <pre class="example">~/amhello % <kbd>cat README</kbd>
- This is a demonstration package for GNU Automake.
- Type 'info Automake' to read the Automake manual.
- </pre></div>
- </li><li> <samp>Makefile.am</samp> and <samp>src/Makefile.am</samp> contain Automake
- instructions for these two directories.
- <div class="example">
- <pre class="example">~/amhello % <kbd>cat src/Makefile.am</kbd>
- bin_PROGRAMS = hello
- hello_SOURCES = main.c
- ~/amhello % <kbd>cat Makefile.am</kbd>
- SUBDIRS = src
- dist_doc_DATA = README
- </pre></div>
- </li><li> Finally, <samp>configure.ac</samp> contains Autoconf instructions to
- create the <code>configure</code> script.
- <div class="example">
- <pre class="example">~/amhello % <kbd>cat configure.ac</kbd>
- AC_INIT([amhello], [1.0], [bug-automake@gnu.org])
- AM_INIT_AUTOMAKE([-Wall -Werror foreign])
- AC_PROG_CC
- AC_CONFIG_HEADERS([config.h])
- AC_CONFIG_FILES([
- Makefile
- src/Makefile
- ])
- AC_OUTPUT
- </pre></div>
- </li></ul>
- <a name="index-autoreconf_002c-example"></a>
- <p>Once you have these five files, it is time to run the Autotools to
- instantiate the build system. Do this using the <code>autoreconf</code>
- command as follows:
- </p>
- <div class="example">
- <pre class="example">~/amhello % <kbd>autoreconf --install</kbd>
- configure.ac: installing './install-sh'
- configure.ac: installing './missing'
- configure.ac: installing './compile'
- src/Makefile.am: installing './depcomp'
- </pre></div>
- <p>At this point the build system is complete.
- </p>
- <p>In addition to the three scripts mentioned in its output, you can see
- that <code>autoreconf</code> created four other files: <samp>configure</samp>,
- <samp>config.h.in</samp>, <samp>Makefile.in</samp>, and <samp>src/Makefile.in</samp>.
- The latter three files are templates that will be adapted to the
- system by <code>configure</code> under the names <samp>config.h</samp>,
- <samp>Makefile</samp>, and <samp>src/Makefile</samp>. Let’s do this:
- </p>
- <div class="example">
- <pre class="example">~/amhello % <kbd>./configure</kbd>
- checking for a BSD-compatible install... /usr/bin/install -c
- checking whether build environment is sane... yes
- checking for gawk... no
- checking for mawk... mawk
- checking whether make sets $(MAKE)... yes
- checking for gcc... gcc
- checking for C compiler default output file name... a.out
- checking whether the C compiler works... yes
- checking whether we are cross compiling... no
- checking for suffix of executables...
- checking for suffix of object files... o
- checking whether we are using the GNU C compiler... yes
- checking whether gcc accepts -g... yes
- checking for gcc option to accept ISO C89... none needed
- checking for style of include used by make... GNU
- checking dependency style of gcc... gcc3
- configure: creating ./config.status
- config.status: creating Makefile
- config.status: creating src/Makefile
- config.status: creating config.h
- config.status: executing depfiles commands
- </pre></div>
- <a name="index-distcheck"></a>
- <a name="index-distcheck-example"></a>
- <p>You can see <samp>Makefile</samp>, <samp>src/Makefile</samp>, and <samp>config.h</samp>
- being created at the end after <code>configure</code> has probed the
- system. It is now possible to run all the targets we wish
- (see <a href="Standard-Targets.html#Standard-Targets">Standard Targets</a>). For instance:
- </p>
- <div class="example">
- <pre class="example">~/amhello % <kbd>make</kbd>
- …
- ~/amhello % <kbd>src/hello</kbd>
- Hello World!
- This is amhello 1.0.
- ~/amhello % <kbd>make distcheck</kbd>
- …
- =============================================
- amhello-1.0 archives ready for distribution:
- amhello-1.0.tar.gz
- =============================================
- </pre></div>
- <p>Note that running <code>autoreconf</code> is only needed initially when
- the GNU Build System does not exist. When you later change some
- instructions in a <samp>Makefile.am</samp> or <samp>configure.ac</samp>, the
- relevant part of the build system will be regenerated automatically
- when you execute <code>make</code>.
- </p>
- <p><code>autoreconf</code> is a script that calls <code>autoconf</code>,
- <code>automake</code>, and a bunch of other commands in the right order.
- If you are beginning with these tools, it is not important to figure
- out in which order all of these tools should be invoked and why. However,
- because Autoconf and Automake have separate manuals, the important
- point to understand is that <code>autoconf</code> is in charge of
- creating <samp>configure</samp> from <samp>configure.ac</samp>, while
- <code>automake</code> is in charge of creating <samp>Makefile.in</samp>s from
- <samp>Makefile.am</samp>s and <samp>configure.ac</samp>. This should at least
- direct you to the right manual when seeking answers.
- </p>
- <hr>
- <div class="header">
- <p>
- Next: <a href="amhello_0027s-configure_002eac-Setup-Explained.html#amhello_0027s-configure_002eac-Setup-Explained" accesskey="n" rel="next">amhello's configure.ac Setup Explained</a>, Up: <a href="Hello-World.html#Hello-World" accesskey="u" rel="up">Hello World</a> [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Indices.html#Indices" title="Index" rel="index">Index</a>]</p>
- </div>
- </body>
- </html>