当前位置: 技术问答>linux和unix
Autotools编写Makefile.am问题
来源: 互联网 发布时间:2017-03-23
本文导语: 利用autotlls工具编译程序,需要自己编写makefile.am文件。我在编写过程中遇到些问题,请教下各位。 我有程序想编译一个并行版本和一个串行版本,我现在只能做到并行版本用一个makefile.am文件,串行版本用另一个makef...
利用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=指定源文件
我有程序想编译一个并行版本和一个串行版本,我现在只能做到并行版本用一个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
试试下面的方法
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" || 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
$ 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" || 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