246tNt
246tNt

Reputation: 2170

Makefile.am - Manual target prerequisite + addprefix?

I have a autotool project where part of the source code is downloaded dynamically from the net (because of IP rights preventing direct redistribution) and then built.

I have a Makefile.am that works but I'm not happy about some of it's aspects.

Here it is:

INCLUDES = $(all_includes) -I$(top_srcdir)/include -I$(top_builddir)
AM_CFLAGS = -fPIC -Wall ${SYMBOL_VISIBILITY}

LIBVERSION=0:0:0

REFSRC_PATH=refsrc
REFSRC_SRC=refsrc/dtx.c refsrc/globdefs.c refsrc/host.c refsrc/mathhalf.c refsrc/sp_enc.c refsrc/sp_rom.c refsrc/vad.c refsrc/err_conc.c refsrc/homing.c refsrc/mathdp31.c refsrc/sp_dec.c refsrc/sp_frm.c refsrc/sp_sfrm.c

${REFSRC_PATH}/.downloaded:
        ./fetch_sources.py "${REFSRC_PATH}"
        for f in `ls -1 "${REFSRC_PATH}"/*.{c,h}`; do   \
                sed -i -e"s/round/round_l2s/" "$$f";    \
        done
        touch $@

${REFSRC_PATH}/dtx.c: ${REFSRC_PATH}/.downloaded

lib_LTLIBRARIES = libgsmhr.la
libgsmhr_la_SOURCES = libgsmhr.c $(REFSRC_SRC)

clean-local:
        -rm -rf ${REFSRC_PATH}

So essentially, libgsmhr.c is my main wrapper, then I download the source code in a refsrc/ subdirectory and patch it a little.

First problem is that in REFSRC_SRC I would have loved to use a $(addprefix ...) instead of repeating refsrc/ in front of each .c file. But that doesn't seem to work and autoreconf complains a little.

Failure details (when removing the refsrc/ prefix from REFSRC_SRC= and using $(addprefix ${REFSRC_PATH}/, ${REFSRC_SRC}) on the dependency list):

bash$ autoreconf -i
libgsmhr/Makefile.am:19: addprefix ${REFSRC_PATH}/, ${REFSRC_SRC}: non-POSIX variable name
libgsmhr/Makefile.am:19: (probably a GNU make extension)

(configure works fine)

bash$ make
...
make[2]: Entering directory `/tmp/ram/gapk.build/libgsmhr'
  CC     libgsmhr.lo
  CCLD   libgsmhr.la
make[2]: Leaving directory `/tmp/ram/gapk.build/libgsmhr'
...

(So as you see it didn't include any of the downloaded .c files, didn't even download them at all. The compile works because libgsmhr.c is a stub that doesn't use the symbols in those file yet)

Second problem is this rule:

${REFSRC_PATH}/dtx.c: ${REFSRC_PATH}/.downloaded

I have to explicitely list the first file (dtx.c) instead of using a wildcard like:

${REFSRC_PATH}/%.c: ${REFSRC_PATH}/.downloaded

If I try to use the wildcard, then autoreconf complains and also it just doesn't work ... (pattern doesn't match somehow).

Failure detail:

bash$ autoreconf -i
libgsmhr/Makefile.am:16: `%'-style pattern rules are a GNU make extension

(configure works fine)

bash$ make
...
make[2]: *** No rule to make target `refsrc/dtx.c', needed by `dtx.lo'.  Stop.
...

Sylvain

Upvotes: 0

Views: 1838

Answers (1)

Beta
Beta

Reputation: 99084

You seem to be writing a makefile in GNUMake style, but actually running some other version of Make. If it's not obvious what autoreconf is calling, you could insert a rule in the makefile:

dummy:
    @echo using $(MAKE)
    $(MAKE) -v

If this theory proves correct, you can either persuade autoconf to use GNUMake, or write for the version it's using.

Upvotes: 1

Related Questions