简体   繁体   English

两个程序的autotools

[英]autotools for 2 programs

I have a program main.c which calls header.c with the help of header.h in its program. 我有一个程序main.c,在程序中使用header.h调用header.c。 I know how to compile it in GCC but now i would like to use autotools for it. 我知道如何在GCC中编译它,但现在我想使用autotools。 I would like to know what should be written in Makefile.am to compile main.c? 我想知道应该在Makefile.am中编写什么来编译main.c?

so for example if i have two c files main.c and header.c as given below 例如,如果我有两个c文件main.c和header.c,如下所示

main.c:- main.c中: -

#include<stdio.h>
#include"header.h"
int main(int argc, char* argv[])
{

   printf("\n Hello");
  function1();

   return 0;
}

and my header.c file contains 和我的header.c文件包含

#include<stdio.h>
void function1()
{
  printf("\n Hi");
}

so my header.h file will contain 所以我的header.h文件将包含

void function1();

then in this case what should be written in the makefile.am and configure.ac 那么在这种情况下应该在makefile.am和configure.ac中写入什么

Here is a minimal example of what you need for the situation that you describe. 以下是您描述的情况所需的最小示例。

You need a makefile.am containing the name of the binary to build, and the source files used to build it (you do not have to list header files, they will be detected automatically): 你需要一个makefile.am包含要构建的二进制makefile.am的名称,以及用于构建它的源文件(你不必列出头文件,它们将被自动检测到):

bin_PROGRAMS = example
example_SOURCES = main.c header.c

And you need a configure.ac . 你需要一个configure.ac Here you set up the name and version number of the program, initialize Automake with the foreign argument so that it won't complain to you about missing files that the GNU project requires, tell it that you require a C compiler, tell it to build your Makefile , and finally tell it to output the results of the previous configuration. 在这里设置程序的名称和版本号,使用foreign参数初始化Automake,这样它就不会抱怨GNU项目需要丢失的文件,告诉它你需要一个C编译器,告诉它构建你的Makefile ,最后告诉它输出以前配置的结果。

AC_INIT([example], [1.0])
AM_INIT_AUTOMAKE([foreign])
AC_PROG_CC
AC_CONFIG_FILES([Makefile])
AC_OUTPUT

If your existing program has any kind of library dependencies, you can run autoscan to detect possible dependencies. 如果现有程序具有任何类型的库依赖项,则可以运行autoscan来检测可能的依赖项。 It produces a file configure.scan , which contains a template that can be used to help build your configure.ac ; 它生成一个文件configure.scan ,其中包含一个可用于帮助构建configure.ac的模板; but if your program is simple, you can skip this step and use the minimal example above. 但是如果你的程序很简单,你可以跳过这一步并使用上面的最小例子。

Now run autoreconf --install to copy in some files that are necessary and build Makefile.in and configure from the above configuration files. 现在运行autoreconf --install在一些文件是必要的,建立复制Makefile.inconfigure从上面的配置文件。 Then, run ./configure to configure your script, generating a Makefile . 然后,运行./configure来配置脚本,生成Makefile Finally, run make to build your program. 最后,运行make来构建程序。

Once you have done these steps, the Makefile that you have generated will detect changes to your makefile.am and run the steps again, so from now on, you should be able to just run make without having to go through all these steps again. 完成这些步骤后, Makefile将检测对makefile.am更改并再次运行这些步骤,因此从现在开始,您应该能够运行make而无需再次执行所有这些步骤。

See the Automake and Autoconf manuals for more information. 有关详细信息,请参阅AutomakeAutoconf手册。

A minimal Makefile.am: 一个最小的Makefile.am:

SHELL = /bin/sh

prefix = /usr/local
exec_prefix = @prefix@
bindir = ${exec_prefix}/bin

AM_CFLAGS = -I./

bin_PROGRAMS = your_program_name

niue_SOURCES = main.c


install-exec-local:
    cp ./your_program_name ${bindir}

uninstall-local:
    rm ${bindir}/your_program_name

You may need a configure.ac as well: 您可能还需要configure.ac:

# Process this file with autoconf to produce a configure script.

AC_PREREQ(2.59)
AC_INIT(your_program_name, 0.1, you@yourdomain.com)
AM_INIT_AUTOMAKE
AC_CONFIG_SRCDIR([main.c])
AC_CONFIG_HEADER([config.h])

# Checks for programs.
AC_PROG_CC

# Checks for additional libraries.
# AC_CHECK_LIB([pthread], [pthread_create])

# Checks for additional header files.
# AC_CHECK_HEADERS([getopt.h])

# Checks for typedefs, structures, and compiler characteristics.
AC_HEADER_STDBOOL
AC_C_CONST
AC_TYPE_SIZE_T
AC_HEADER_TIME
AC_C_VOLATILE

# Checks for library functions.
AC_HEADER_STDC
AC_FUNC_SELECT_ARGTYPES
#AC_CHECK_FUNCS([getopt_long])

AC_CONFIG_FILES([Makefile])
AC_OUTPUT

so for example if i have two c files main.c and header.c as given below 例如,如果我有两个c文件main.c和header.c,如下所示

main.c:- main.c中: -

include 包括

include"header.h" 包括“header.h”

int main(int argc, char* argv[]) { int main(int argc,char * argv []){

printf("\\n Hello"); printf(“\\ n你好”); function1(); 功能1();

return 0; 返回0; } }

and my header.c file contains 和我的header.c文件包含

include 包括

void function1() { printf("\\n Hi"); void function1(){printf(“\\ n嗨”); } }

so my header.h file will contain void function1(); 所以我的header.h文件将包含void function1();

then in this case what should be written in the makefile.am and configure.ac 那么在这种情况下应该在makefile.am和configure.ac中写入什么

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM