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

2

5

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.

Baxley answered 19/9, 2011 at 7:58 Comment(2)
This looks like it's the wrong thing to do. ./configure is the step that figures out where things are on the system on which you're compiling, so it's also the step that allows the compiling user to tell it where nondefault locations for header paths are.Wordage
CPPFLAGS is not a colon separated list. You want CPPFLAGS='-I/usr/include/freetype -I/mypath/include'Professionalize
P
10

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.

Professionalize answered 1/10, 2011 at 9:37 Comment(2)
Sounds great but,... The Makefile that gets generated by configure is producing a compile statement that does not refer to the ambient CFLAGS or CPPFLAGS env variable.Carmacarmack
If the package is built using automake, the default rules should have $(CFLAGS) and $(CPPFLAGS) in the appropriate places. If it does not, the package maintainer is seriously abusing automake. Perhaps the package you are looking at uses hand written Makefile.in.Professionalize
I
11

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
Irritable answered 24/9, 2011 at 7:18 Comment(1)
I agree this is the most straight forward actual answer to the question. Just add a line like so in your Makefile.am and you will be able to specify custom include paths for the build target.Thankful
P
10

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.

Professionalize answered 1/10, 2011 at 9:37 Comment(2)
Sounds great but,... The Makefile that gets generated by configure is producing a compile statement that does not refer to the ambient CFLAGS or CPPFLAGS env variable.Carmacarmack
If the package is built using automake, the default rules should have $(CFLAGS) and $(CPPFLAGS) in the appropriate places. If it does not, the package maintainer is seriously abusing automake. Perhaps the package you are looking at uses hand written Makefile.in.Professionalize

© 2022 - 2024 — McMap. All rights reserved.