zoukankan      html  css  js  c++  java
  • Automake学习一

    创建"hello-1.0.tar.gz"例子
     
    步骤:
    1. 创建src/main.c
    #include <config.h>
    #include <stdio.h>
    int main ()
    {
         printf("Hello World!\n");
         return 0;
    }
    2. 创建README
    This is a demonstration package for GNU Automake.
    3. 创建‘Makefile.am’ and ‘src/Makefile.am’
    src/Makefile.am:
    bin_PROGRAMS = hello
    hello_SOURCES = main.c
    Makefile.am:
    SUBDIRS = src
    dist_doc_DATA = README
    4. 创建cofigure.ac
    AC_INIT([hello], [1.0], [sinaxy@126.com])
    AM_INIT_AUTOMAKE([-Wall -Werror foreign])
    AC_PROG_CC
    AC_CONFIG_HEADERS([config.h])
    AC_CONFIG_FILES([
    Makefile
    src/Makefile
    ])
    AC_OUTPUT
    5. 输入autoreconf --install
    6. 输入./configure
    7. 输入make
    8. 输入make distcheck
     
    1. 编写configure.ac
    AC_INIT([hello], [1.0], [sinaxyz@126.com])
    AM_INIT_AUTOMAKE([-Wall -Werror foreign])
    AC_PROG_CC
    AC_CONFIG_HEADERS([config.h])
    AC_CONFIG_FILES([
         Makefile
         src/Makefile
    ])
    AC_OUTPUT
     
    • This file is read by both autoconf (to create ‘configure’) and automake (to create the various ‘Makefile.in’s).
    • The macros prefixed with AC_ are Autoconf macros, documented in the Autoconf manual. The macros that start with AM_ are Automake macros.
    • The first two lines of ‘configure.ac’ initialize Autoconf and Automake.The argument to AM_INIT_AUTOMAKE is a list of options for automake.‘-Wall’ and ‘-Werror’ ask automake to turn on all warnings and report them as errors. Using ‘-Wall -Werror’ is a safe setting when starting to work on a package: The ‘foreign’ option tells Automake that this package will not follow the GNU Standards. GNU packages should always distribute additional files such as ‘ChangeLog’, ‘AUTHORS’, etc. We do not want automake to complain about these missing files in our small example.
    • The AC_PROG_CC line causes the configure script to search for a C compiler and define the variable CC with its name. The src/Makefile.in’ file generated by Automake uses the variable CC to build ‘hello’, so when configure creates ‘src/Makefile’ from ‘src/Makefile.in’, it will define CC with the value it has found. If Automake is asked to create a ‘Makefile.in’ that uses CC but ‘configure.ac’ does not define it, it will suggest you add a call to AC_PROG_CC.
    • The AC_CONFIG_HEADERS([config.h]) invocation causes the configure script to create a ‘config.h’ file gathering ‘#define’s defined by other macros in ‘configure.ac’. 
    • The AC_CONFIG_FILES macro declares the list of files that configure should create from their ‘*.in’ templates. Automake also scans this list to find the ‘Makefile.am’ files it must process.
    • Finally, the AC_OUTPUT line is a closing command that actually produces the part of the script in charge of creating the files registered with AC_CONFIG_HEADERS and AC_CONFIG_FILES.
    2. Makefile.am编写
    src/Makefile.am:
    bin_PROGRAMS = hello
    hello_SOURCES = main.c
     
    • When automake processes a ‘Makefile.am’ it copies the entire file into the output ‘Makefile.in’ (that will be later turned into ‘Makefile’ by configure) but will react to certain variable definitions by generating some build rules and other variables. Often ‘Makefile.am’s contain only a list of variable definitions as above, but they can also contain other variable and rule definitions that automake will pass along without interpretation.
    • Variables that end with _PROGRAMS are special variables that list programs that the resulting ‘Makefile’ should build. In Automake speak, this _PROGRAMS suffix is called a primary; Automake recognizes other primaries such as _SCRIPTS, _DATA, _LIBRARIES, etc. corresponding to different types of files.
    • Automake also knows that source files need to be distributed when creating a tarball (unlike built programs). So a side-effect of this hello_SOURCES declaration is that ‘main.c’ will be part of the tarball created by make dist.
     
    Makefile.am:
    SUBDIRS = src
    dist_doc_DATA = README
     
    • SUBDIRS is a special variable listing all directories that make should recurse into before processing the current directory. So this line is responsible for make building ‘src/hello’ even though we run it from the top-level. This line also causes make install to install ‘src/hello’ before installing ‘README’ (not that this order matters).
    • The line dist_doc_DATA = README causes ‘README’ to be distributed and installed in docdir. Files listed with the _DATA primary are not automatically part of the tarball built with make dist, so we add the dist_ prefix so they get distributed. However, for ‘README’ it would not have been necessary: automake automatically distributes any ‘README’ file it encounters (the list of other files automatically distributed is presented by automake -- help). The only important effect of this second line is therefore to install ‘README’ during make install.
     
     
     
     
     
     
  • 相关阅读:
    ftp上传下载
    java生成xml
    Java:删除某文件夹下的所有文件
    java读取某个文件夹下的所有文件
    JFileChooser 中文API
    得到java异常printStackTrace的详细信息
    关于SQL命令中不等号(!=,<>)
    ABP前端保存notify提示在Edge浏览器显示null
    关于MY Sql 查询锁表信息和解锁表
    VS2019 backspace键失效,无法使用
  • 原文地址:https://www.cnblogs.com/sinaxyz/p/3037199.html
Copyright © 2011-2022 走看看