Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

With autoconf/automake, how do I specify include file paths?

Let's say I want to have the generate makefile pass some specific header paths to g++.

What do I need to add to configure.ac or Makefile.am to specify this?

(note - I do not want to pass it in the CPPFLAGS with ./configure. I want those paths baked in before that step)

EDIT: Specifically, I want to to include let's say /usr/include/freetype and /mypath/include.

I put AC_CHECK_HEADERS([freetype/config/ftheader.h]) and it passes, but doesn't seem to add it to the -I passed to g++.

I also did try adding CPPFLAGS=-I.:/usr/include/freetype:/mypath/include, but it screws up and puts -I twice, the first as -I. and it ignores the 2nd -I.

like image 513
marathon Avatar asked Sep 19 '11 07:09

marathon


2 Answers

Since the question was about what to put in an automakefile, I would have thought AM_CPPFLAGS was the right variable to use to add includes and defines for all C/C++ compiles. See http://www.gnu.org/software/automake/manual/html_node/Program-Variables.html

Example:

AM_CPPFLAGS = -I/usr/local/custom/include/path
like image 105
dajobe Avatar answered Nov 09 '22 18:11

dajobe


Hard coding paths into the package files is absolutely the wrong thing to do. If you choose to do that, then you need to be aware that you are violating the basic rules of building a package with the autotools. If you specify /mypath/include in your package files, you are specifying things specific to your machine in a package that is intended to work on all machines; clearly that is wrong. It looks like what you want is for your package (when built on your machine) to look for header files in /mypath. That is easy to accomplish without bastardizing your package. There are (at least) 3 ways to do it:

  1. Use a config.site file. In /usr/local/share/config.site (create this file if necessary), add the line:

    CPPFLAGS="$CPPFLAGS -I/mypath/include"
    

    Now any package using an autoconf generated configure script with the default prefix (/usr/local) will append -I/mypath/include to CPPFLAGS and the headers in /mypath/include will be found.

  2. If you want the assignment to be made for all builds (not just those to be installed in /usr/local), you can use this:

    Put the same line specifying CPPFLAGS in $HOME/config.site, and set CONFIG_SITE=$HOME/config.site in the environment of your default shell. Now, whenever you run an autoconf generated configure script, the assignments from $HOME/config.site will be made.

  3. Simply specify CPPFLAGS in the environment of your default shell.

All of these solutions have two primary advantages over modifying your build files. First, they will work for all autoconf generated packages (as long as they follow the rules and don't do things like assigning user variables such as CPPFLAGS in the build files). Second, they do not put your machine specific information into a package that ought to work on all machines.

like image 30
William Pursell Avatar answered Nov 09 '22 18:11

William Pursell