首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 操作系统 > UNIXLINUX >

Autotools编写Makefile.am有关问题

2012-12-16 
Autotools编写Makefile.am问题利用autotlls工具编译程序,需要自己编写makefile.am文件。我在编写过程中遇到

Autotools编写Makefile.am问题
利用autotlls工具编译程序,需要自己编写makefile.am文件。我在编写过程中遇到些问题,请教下各位。
我有程序想编译一个并行版本和一个串行版本,我现在只能做到并行版本用一个makefile.am文件,串行版本用另一个makefile.am文件,有没有可能做到就只用一个makefile.am文件来实现? 只要在configure的时候指定一下是并行还是串行?
并行版本makefile.am

AUTOMAKE_OPTIONS=foreign
bin_PROGRAMS=test.mpi
FC=mpif90
test_mpi_LDADD=指定库
test_mpi_SOURCES=指定源文件

串行版本makefile.am
AUTOMAKE_OPTIONS=foreign
bin_PROGRAMS=test.nompi
FC=ifort
test_nompi_LDADD=指定库
test_nompi_SOURCES=源文件

串行和并行版本的makefile.am文件都没有问题。但是我没法做到统一到一个makefile.am文件中。

以下我的设想,但是没实现成功,求帮助。
综合版本makefile.am
AUTOMAKE_OPTIONS=foreign
BASIC_NAME=test
如果是并行版本{
ADD_NAME=mpi
FC=mpif90}
如果是串行版本{
ADD_NAME=nompi
FC=ifort}
bin_PROGRAMS=$(BASIC_NAME).$(ADD_NAME)
$(BASIC_NAME)_$(ADD_NAME)_LDADD=指定库
$(BASIC_NAME)_$(ADD_NAME)_SOURCES=指定源文件


[最优解释]
复习了一下autotools,楼主可以AM_CONDITIONAL
试试下面的方法

Makefile.am

AUTOMAKE_OPTIONS = foreign
bin_PROGRAMS = demo
if MPI
demo_SOURCES = demo_mpi.c
else
demo_SOURCES = demo.c
endif

configure.ac
#                                               -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.

AC_INIT(demo, 1.0)
AM_INIT_AUTOMAKE
AC_CONFIG_HEADERS([config.h])

# Checks for programs.
AC_PROG_CC

AC_ARG_ENABLE([mpi],
        [  --enable-mpi Enable MPI],
        [case "${enableval}" in 
                yes) mpi=true ;;
                no)  mpi=false ;;
        esac], [mpi=false])
AM_CONDITIONAL([MPI], [test x$mpi = xtrue])

# Checks for libraries.

# Checks for header files.

# Checks for typedefs, structures, and compiler characteristics.

# Checks for library functions.

AC_CONFIG_FILES([Makefile])
AC_OUTPUT

然后可以用
CC=mpicc ./configure --enable-mpi
CC=cc ./configure --disable-mpi
分别处理MPI启用和禁止的情况

注: 似乎不能在Makefile.am里设置CC
[其他解释]
方法都有了,改改应该可以的。
$ cat Makefile.am

AUTOMAKE_OPTIONS = foreign
if MPI
bin_PROGRAMS = demo_mpi
demo_mpi_SOURCES = demo_mpi.c
else
bin_PROGRAMS = demo
demo_SOURCES = demo.c
endif

$ autoreconf
$ ./configure --enable-mpi
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... ./install-sh -c -d
checking for gawk... no
checking for mawk... no
checking for nawk... nawk
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 config.h
config.status: config.h is unchanged
config.status: executing depfiles commands
$ make clean && make
test -z "demo_mpi" 
[其他解释]
没人回答?
是我问题没有描述清楚么? 
[其他解释]
能不能根据configure时的FC来指定LDADD,至于SOURCES和_PROGRAMS就使用相同的文件呢?
[其他解释]
确实比较复杂,可以参考一些开源项目的makefile看看
[其他解释]
3楼所说的即使现实了,那也是编译不同的源文件,对可执行文件的名字什么没法改变。不过所的启用MPI和禁用MPI的方法,学习了! 谢谢。

我源文件是一样的,唯一的区别即使编译的时候加不加宏-DMPI的问题。
我主要是想让最后的可执行文件的名字不一样,区别并行版本和串行版本。

[其他解释]

引用:
能不能根据configure时的FC来指定LDADD,至于SOURCES和_PROGRAMS就使用相同的文件呢?

恩,我就想着用configure来设置宏开关,sources和programs用的相同文件,但是要求根据开关最后得到的可执行程序的名字不一样。
[其他解释]
 rm -f demo_mpi
rm -f *.o
make  all-am
gcc -DHAVE_CONFIG_H -I.      -g -O2 -MT demo_mpi.o -MD -MP -MF .deps/demo_mpi.Tpo -c -o demo_mpi.o demo_mpi.c
mv -f .deps/demo_mpi.Tpo .deps/demo_mpi.Po
gcc  -g -O2   -o demo_mpi demo_mpi.o  
$ ./configure --disable-mpi
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... ./install-sh -c -d
checking for gawk... no
checking for mawk... no
checking for nawk... nawk
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 config.h
config.status: config.h is unchanged
config.status: executing depfiles commands
$ make clean && make       
test -z "demo" 
[其他解释]
 rm -f demo
rm -f *.o
make  all-am
gcc -DHAVE_CONFIG_H -I.      -g -O2 -MT demo.o -MD -MP -MF .deps/demo.Tpo -c -o demo.o demo.c
mv -f .deps/demo.Tpo .deps/demo.Po
gcc  -g -O2   -o demo demo.o  

[其他解释]
-DMPI自己加吧。
[其他解释]
-DMPI自己改改Makefile.am应该能实现的。
[其他解释]

引用:
……

多谢多谢。 最近出差了,都没上来看看
[其他解释]
引用:
-DMPI自己改改Makefile.am应该能实现的。


在configure.in中添加了如下后,根据你的方法还是不行呢
AC_ARG_ENABLE(mpi,
[ --enable-mpi Build mpi exe [default=no]],
enable_mpi=$enableval,
enable_mpi=no)

热点排行