LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-17-2008, 06:15 AM   #1
binarybob0001
Member
 
Registered: Dec 2004
Distribution: Debian Wheezy
Posts: 444

Rep: Reputation: 30
Autoconf and Selecting which Program to Compile?


I would like to generate a configure script that allows me to select which program I want to compile. I have a directory that contains source code for a library and another directory that contains a test program that tests the library. The library directory is named libfileinfo and the test directory is named test. How do I write a configure.ac file that allows me to select between the two programs. This is my configure.ac file:
Code:
#                                               -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.

AC_PREREQ(2.61)
AC_INIT([libfileinfo], [0.1])
AC_CONFIG_SRCDIR([libfileinfo/fileinfo.h]) #Can I combine these into one line?
AC_CONFIG_SRCDIR([libfileinfo/fileinfo.cpp])

# Test for file in the test project

AC_CONFIG_HEADER([config.h])
AM_INIT_AUTOMAKE

# Checks for programs.
AC_PROG_CXX
AC_PROG_CC

# Checks for libraries.

# Checks for header files.
AC_HEADER_DIRENT
AC_CHECK_HEADERS([unistd.h])

# Checks for typedefs, structures, and compiler characteristics.
AC_HEADER_STDBOOL
AC_C_CONST
AC_TYPE_UID_T
AC_TYPE_MODE_T
AC_TYPE_SIZE_T

# Checks for library functions.
AC_FUNC_CLOSEDIR_VOID
AC_FUNC_STAT
AC_CHECK_FUNCS([getcwd])

AC_PROG_LIBTOOL

AC_CONFIG_FILES([Makefile])
AC_OUTPUT
I have tried using the AC_ARG_WITH so I could write something like --with-libfileinfo and --with-test. Does anyone know how to make this happen?
 
Old 03-17-2008, 11:31 AM   #2
osor
HCL Maintainer
 
Registered: Jan 2006
Distribution: (H)LFS, Gentoo
Posts: 2,450

Rep: Reputation: 78
I don’t understand. Why don’t you just make them different targets in your Makefile.am?
 
Old 03-17-2008, 11:44 PM   #3
binarybob0001
Member
 
Registered: Dec 2004
Distribution: Debian Wheezy
Posts: 444

Original Poster
Rep: Reputation: 30
That's exactly what I want to do. How do I specify different targets and how do I pass which target I want to build to configure or make?
 
Old 03-18-2008, 01:22 AM   #4
binarybob0001
Member
 
Registered: Dec 2004
Distribution: Debian Wheezy
Posts: 444

Original Poster
Rep: Reputation: 30
I figured it out. All I had to do was look up conditionals in the automake manual. I edited my file to look like this.
configure.ac
Code:
#                                               -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.

AC_PREREQ(2.61)
AC_INIT([libfileinfo], [0.1])
AC_CONFIG_SRCDIR([libfileinfo/fileinfo.h]) #Can I combine these into one line?
AC_CONFIG_SRCDIR([libfileinfo/fileinfo.cpp])
AC_CONFIG_HEADER([config.h])
AM_INIT_AUTOMAKE

# Checks for programs.
AC_PROG_CXX
AC_PROG_CC

# Checks for libraries.

# Checks for header files.
AC_HEADER_DIRENT
AC_CHECK_HEADERS([unistd.h])

# Checks for typedefs, structures, and compiler characteristics.
AC_HEADER_STDBOOL
AC_C_CONST
AC_TYPE_UID_T
AC_TYPE_MODE_T
AC_TYPE_SIZE_T

# Checks for library functions.
AC_FUNC_CLOSEDIR_VOID
AC_FUNC_STAT
AC_CHECK_FUNCS([getcwd])

AC_PROG_LIBTOOL

AC_CONFIG_FILES([
  Makefile
  libfileinfo/Makefile
  test/Makefile
  ])

AC_ARG_WITH([libfileinfo], 
  AC_HELP_STRING([--with-libfileinfo], [compile library]),
  [case "${withval}" in
    yes) makelib=true ;;
    no) makelib=false ;;
    *) AC_MSG_ERROR([bad value ${withval} for --with-libfileinfo]) ;;
  esac], [makelib=true])
  AM_CONDITIONAL([MAKELIB], [test x$makelib = xtrue])

AC_ARG_WITH([test],
  AC_HELP_STRING([--with-test], [compile test program]),
  [case "${withval}" in
    yes) maketest=true ;;
    no) maketest=false ;;
    *) AC_MSG_ERROR([bad value ${withval} for --with-test]) ;;
  esac], [maketest=false]) 
  AM_CONDITIONAL([MAKETEST], [test x$maketest = xtrue])

AC_OUTPUT
Makefile.am
Code:
# not a GNU package. You can remove this line, if
# have all needed files, that a GNU package needs
AUTOMAKE_OPTIONS = foreign 1.4

if MAKELIB
LIB = libfileinfo
else
LIB =
endif

if MAKETEST
SAMPLE = test
else
SAMPLE =
endif

SUBDIRS = $(LIB) $(SAMPLE)
Now, I can move forward with the more important things in life. Can someone please tell me what the x is for in test x$maketest = xtrue?
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
*** YOU'RE USING autoconf (GNU Autoconf) 2.60. KDE requires autoconf 2.52, 2.53 or 2. arubin Slackware 6 09-24-2008 03:31 AM
autoconf-2.59 compile problems? jlgreer1 Linux From Scratch 4 11-19-2007 05:27 AM
Why I can't compile my c program? zhuqlfeixia Programming 6 12-12-2005 09:13 PM
Want to compile kernel, missing include/linux/autoconf.h pjz Linux - Software 4 06-17-2005 08:06 AM
Can't compile c++ program eg_wwkaa Programming 34 06-18-2003 08:59 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:51 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration