当前位置: 动力学知识库 > 问答 > 编程问答 >

autoconf - What's the best way to start a C program for multiple Unix Flavors?

问题描述:

It's been a while so be gentle. The last C program I wrote was in the early 90's. I am wanting to start a project in C that will compile for the dominant Unix flavors out there, i.e. Mac, Linux, CentOS. I am looking for pointers on the best way to start the project that will generate all the necessary configuration files for the various systems.

Is Autoconf still the standard or would you mind introducing me to the latest methods for doing this? Are there standard templates I should be looking at?

网友答案:

There are a few templates for the autotools out there, but I haven't found any worth using. Here's a simple script to set up a new project:

#!/bin/sh

set -e
DIR=${1:-$HOME/new-project}
mkdir $DIR
cd $DIR
mkdir tests
mkdir src
cat > tests/basic.in << EOF
#!/bin/sh
set -e
@[email protected]/../src/hello
EOF

: ${EMAIL=$( id -un )@$( hostname )}
echo TESTS = basic > tests/Makefile.am
echo bin_PROGRAMS = hello > src/Makefile.am
echo SUBDIRS = src tests > Makefile.am
echo 'int main( void ) { return 1; }' > src/hello.c
touch configure.ac
autoscan
sed -e [email protected]@$(basename $1)@ \
    -e s/VERSION/0.0.0/ \
    -e s/BUG-REPORT-ADDRESS/$EMAIL/ \
    -e '/AC_CONFIG_HEADERS/a\
: ${enable_silent_rules=yes} ' \
    -e '/AC_CONFIG_HEADERS/a\
AM_INIT_AUTOMAKE([foreign color-tests silent-rules])' \
    -e '/AC_OUTPUT/i\
AC_CONFIG_FILES([tests/basic],[chmod +x tests/basic])' \
    configure.scan > configure.ac

Note that this looks more complicated than it is, and by design creates a project in which the test suite fails ( or, rather the test suite succeeds by catching the fact that the program fails!) You basically need one line in each Makefile.am, and you need to add project specific data to the autogenerated configure.ac. From this foundation you can do whatever you need.

网友答案:

autotools are still the most widely used building system on unices. I guess lots of people have a template ready somewhere, here's mine:

http://damien.lespiau.name/blog/2011/09/17/a-simple-autotool-template/

分享给朋友:
您可能感兴趣的文章:
随机阅读: