PageRenderTime 48ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/autotools/automake.html_node/Creating-amhello.html

https://gitlab.com/Gentio/my-pdf
HTML | 235 lines | 173 code | 21 blank | 41 comment | 0 complexity | 58bf4b5e44f6e4d95950d86c3bf374dc MD5 | raw file
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  2. <html>
  3. <!--
  4. This manual is for GNU Automake (version 1.15,
  5. 31 December 2014), a program that creates GNU standards-compliant
  6. Makefiles from template files.
  7. Copyright (C) 1995-2014 Free Software Foundation, Inc.
  8. Permission is granted to copy, distribute and/or modify this document
  9. under the terms of the GNU Free Documentation License,
  10. Version 1.3 or any later version published by the Free Software
  11. Foundation; with no Invariant Sections, with no Front-Cover texts,
  12. and with no Back-Cover Texts. A copy of the license is included in the
  13. section entitled "GNU Free Documentation License."
  14. -->
  15. <!-- Created by GNU Texinfo 5.2, http://www.gnu.org/software/texinfo/ -->
  16. <head>
  17. <title>automake: Creating amhello</title>
  18. <meta name="description" content="automake: Creating amhello">
  19. <meta name="keywords" content="automake: Creating amhello">
  20. <meta name="resource-type" content="document">
  21. <meta name="distribution" content="global">
  22. <meta name="Generator" content="makeinfo">
  23. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  24. <link href="index.html#Top" rel="start" title="Top">
  25. <link href="Indices.html#Indices" rel="index" title="Indices">
  26. <link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
  27. <link href="Hello-World.html#Hello-World" rel="up" title="Hello World">
  28. <link href="amhello_0027s-configure_002eac-Setup-Explained.html#amhello_0027s-configure_002eac-Setup-Explained" rel="next" title="amhello's configure.ac Setup Explained">
  29. <link href="Hello-World.html#Hello-World" rel="prev" title="Hello World">
  30. <style type="text/css">
  31. <!--
  32. a.summary-letter {text-decoration: none}
  33. blockquote.smallquotation {font-size: smaller}
  34. div.display {margin-left: 3.2em}
  35. div.example {margin-left: 3.2em}
  36. div.indentedblock {margin-left: 3.2em}
  37. div.lisp {margin-left: 3.2em}
  38. div.smalldisplay {margin-left: 3.2em}
  39. div.smallexample {margin-left: 3.2em}
  40. div.smallindentedblock {margin-left: 3.2em; font-size: smaller}
  41. div.smalllisp {margin-left: 3.2em}
  42. kbd {font-style:oblique}
  43. pre.display {font-family: inherit}
  44. pre.format {font-family: inherit}
  45. pre.menu-comment {font-family: serif}
  46. pre.menu-preformatted {font-family: serif}
  47. pre.smalldisplay {font-family: inherit; font-size: smaller}
  48. pre.smallexample {font-size: smaller}
  49. pre.smallformat {font-family: inherit; font-size: smaller}
  50. pre.smalllisp {font-size: smaller}
  51. span.nocodebreak {white-space:nowrap}
  52. span.nolinebreak {white-space:nowrap}
  53. span.roman {font-family:serif; font-weight:normal}
  54. span.sansserif {font-family:sans-serif; font-weight:normal}
  55. ul.no-bullet {list-style: none}
  56. -->
  57. </style>
  58. </head>
  59. <body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000">
  60. <a name="Creating-amhello"></a>
  61. <div class="header">
  62. <p>
  63. 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> &nbsp; [<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>
  64. </div>
  65. <hr>
  66. <a name="Creating-amhello_002d1_002e0_002etar_002egz"></a>
  67. <h4 class="subsection">2.4.1 Creating <samp>amhello-1.0.tar.gz</samp></h4>
  68. <p>Here is how we can recreate <samp>amhello-1.0.tar.gz</samp> from scratch.
  69. The package is simple enough so that we will only need to write 5
  70. files. (You may copy them from the final <samp>amhello-1.0.tar.gz</samp>
  71. that is distributed with Automake if you do not want to write them.)
  72. </p>
  73. <p>Create the following files in an empty directory.
  74. </p>
  75. <ul>
  76. <li> <samp>src/main.c</samp> is the source file for the <samp>hello</samp> program. We
  77. store it in the <samp>src/</samp> subdirectory, because later, when the package
  78. evolves, it will ease the addition of a <samp>man/</samp> directory for man
  79. pages, a <samp>data/</samp> directory for data files, etc.
  80. <div class="example">
  81. <pre class="example">~/amhello % <kbd>cat src/main.c</kbd>
  82. #include &lt;config.h&gt;
  83. #include &lt;stdio.h&gt;
  84. int
  85. main (void)
  86. {
  87. puts (&quot;Hello World!&quot;);
  88. puts (&quot;This is &quot; PACKAGE_STRING &quot;.&quot;);
  89. return 0;
  90. }
  91. </pre></div>
  92. </li><li> <samp>README</samp> contains some very limited documentation for our little
  93. package.
  94. <div class="example">
  95. <pre class="example">~/amhello % <kbd>cat README</kbd>
  96. This is a demonstration package for GNU Automake.
  97. Type 'info Automake' to read the Automake manual.
  98. </pre></div>
  99. </li><li> <samp>Makefile.am</samp> and <samp>src/Makefile.am</samp> contain Automake
  100. instructions for these two directories.
  101. <div class="example">
  102. <pre class="example">~/amhello % <kbd>cat src/Makefile.am</kbd>
  103. bin_PROGRAMS = hello
  104. hello_SOURCES = main.c
  105. ~/amhello % <kbd>cat Makefile.am</kbd>
  106. SUBDIRS = src
  107. dist_doc_DATA = README
  108. </pre></div>
  109. </li><li> Finally, <samp>configure.ac</samp> contains Autoconf instructions to
  110. create the <code>configure</code> script.
  111. <div class="example">
  112. <pre class="example">~/amhello % <kbd>cat configure.ac</kbd>
  113. AC_INIT([amhello], [1.0], [bug-automake@gnu.org])
  114. AM_INIT_AUTOMAKE([-Wall -Werror foreign])
  115. AC_PROG_CC
  116. AC_CONFIG_HEADERS([config.h])
  117. AC_CONFIG_FILES([
  118. Makefile
  119. src/Makefile
  120. ])
  121. AC_OUTPUT
  122. </pre></div>
  123. </li></ul>
  124. <a name="index-autoreconf_002c-example"></a>
  125. <p>Once you have these five files, it is time to run the Autotools to
  126. instantiate the build system. Do this using the <code>autoreconf</code>
  127. command as follows:
  128. </p>
  129. <div class="example">
  130. <pre class="example">~/amhello % <kbd>autoreconf --install</kbd>
  131. configure.ac: installing './install-sh'
  132. configure.ac: installing './missing'
  133. configure.ac: installing './compile'
  134. src/Makefile.am: installing './depcomp'
  135. </pre></div>
  136. <p>At this point the build system is complete.
  137. </p>
  138. <p>In addition to the three scripts mentioned in its output, you can see
  139. that <code>autoreconf</code> created four other files: <samp>configure</samp>,
  140. <samp>config.h.in</samp>, <samp>Makefile.in</samp>, and <samp>src/Makefile.in</samp>.
  141. The latter three files are templates that will be adapted to the
  142. system by <code>configure</code> under the names <samp>config.h</samp>,
  143. <samp>Makefile</samp>, and <samp>src/Makefile</samp>. Let&rsquo;s do this:
  144. </p>
  145. <div class="example">
  146. <pre class="example">~/amhello % <kbd>./configure</kbd>
  147. checking for a BSD-compatible install... /usr/bin/install -c
  148. checking whether build environment is sane... yes
  149. checking for gawk... no
  150. checking for mawk... mawk
  151. checking whether make sets $(MAKE)... yes
  152. checking for gcc... gcc
  153. checking for C compiler default output file name... a.out
  154. checking whether the C compiler works... yes
  155. checking whether we are cross compiling... no
  156. checking for suffix of executables...
  157. checking for suffix of object files... o
  158. checking whether we are using the GNU C compiler... yes
  159. checking whether gcc accepts -g... yes
  160. checking for gcc option to accept ISO C89... none needed
  161. checking for style of include used by make... GNU
  162. checking dependency style of gcc... gcc3
  163. configure: creating ./config.status
  164. config.status: creating Makefile
  165. config.status: creating src/Makefile
  166. config.status: creating config.h
  167. config.status: executing depfiles commands
  168. </pre></div>
  169. <a name="index-distcheck"></a>
  170. <a name="index-distcheck-example"></a>
  171. <p>You can see <samp>Makefile</samp>, <samp>src/Makefile</samp>, and <samp>config.h</samp>
  172. being created at the end after <code>configure</code> has probed the
  173. system. It is now possible to run all the targets we wish
  174. (see <a href="Standard-Targets.html#Standard-Targets">Standard Targets</a>). For instance:
  175. </p>
  176. <div class="example">
  177. <pre class="example">~/amhello % <kbd>make</kbd>
  178. &hellip;
  179. ~/amhello % <kbd>src/hello</kbd>
  180. Hello World!
  181. This is amhello 1.0.
  182. ~/amhello % <kbd>make distcheck</kbd>
  183. &hellip;
  184. =============================================
  185. amhello-1.0 archives ready for distribution:
  186. amhello-1.0.tar.gz
  187. =============================================
  188. </pre></div>
  189. <p>Note that running <code>autoreconf</code> is only needed initially when
  190. the GNU Build System does not exist. When you later change some
  191. instructions in a <samp>Makefile.am</samp> or <samp>configure.ac</samp>, the
  192. relevant part of the build system will be regenerated automatically
  193. when you execute <code>make</code>.
  194. </p>
  195. <p><code>autoreconf</code> is a script that calls <code>autoconf</code>,
  196. <code>automake</code>, and a bunch of other commands in the right order.
  197. If you are beginning with these tools, it is not important to figure
  198. out in which order all of these tools should be invoked and why. However,
  199. because Autoconf and Automake have separate manuals, the important
  200. point to understand is that <code>autoconf</code> is in charge of
  201. creating <samp>configure</samp> from <samp>configure.ac</samp>, while
  202. <code>automake</code> is in charge of creating <samp>Makefile.in</samp>s from
  203. <samp>Makefile.am</samp>s and <samp>configure.ac</samp>. This should at least
  204. direct you to the right manual when seeking answers.
  205. </p>
  206. <hr>
  207. <div class="header">
  208. <p>
  209. 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> &nbsp; [<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>
  210. </div>
  211. </body>
  212. </html>