2

I have different subdirectories that need to be compiled in different ways. For example, some files needs to include some others using CFLAGS. However, CFLAGS can only be set in configuration files, so I guess I need multiple configure.ac's.

Is it a good idea to use nested packages (as described on gnu.org) for this, or is this an overkill?

Note: I call it overkill because the solution from gnu.org adds a README etc. into every subdirectory. Can this be avoided?

  • The title says, just autoconf. But your tags include both /autoconf and /automake. Which is it? – rocky Jun 21 '15 at 21:23
0

If you don't want README,etc included add the foreign option. For example in your configure.ac file add:

AM_INIT_AUTOMAKE([foreign])

See Strictness in the Automake manual

It is possible to have one configuration file that sets many kinds of C flags which are used in the subdirectories. But unless you want to start to become a serious automake hacker, I'd start with the simple solution and use foreign.

Here is a little example to show how CFLAGScan be set from other things. For simplicity I'll just set CFLAGS based on another environment variable so I don't have to deal with configure args. And I'll set CFLAGS in the main file while what you want to do that is in a subdirectory file. I hope all of this will be straightforward to change.

My configure.ac file is:

AC_INIT([foo], [1.0], [https://example.com])
AM_INIT_AUTOMAKE()
AC_SUBST(PROJ1_CFLAGS)
AC_CONFIG_FILES([Makefile])
AC_OUTPUT

My Makefile.am file is:

CFLAGS=@PROJ1_CFLAGS@

Now to build everything:

$ autoreconf -fi
$ autoconf
$ CFLAGS='-g' PROJ1_CFLAGS='-Wall' ./configure
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... /bin/mkdir -p
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking whether make supports nested variables... yes
checking that generated files are newer than configure... done
configure: creating ./config.status
config.status: creating Makefile
$

If you look in Makefile, you'll see:

CFLAGS='-Wall'

which was in fact set from the PROJ1_CFLAGS environment variable, not the CFLAGS environment variable.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.