Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Build dynamic program list with autotools

I have the following regular (hand-written) makefile:

all: $(patsubst %.c,%.so,$(wildcard *.c))

%.so: %.c
     $(CC) $(CFLAGS) $(LDFLAGS) -rdynamic -o $@ $^

I need to convert this makefile to autotools (primary for populating CFLAGS and LDFLAGS with good stuff) My first reading of autotools documentation made me thought that this is impossible since autotools need to know all its targets in advance... but i may be wrong.

Any idea ?

like image 593
binarym Avatar asked May 01 '26 23:05

binarym


1 Answers

Automake certainly wants to know all of the filenames, but it is quite common to have a bootstrap script that creates Makefile.am prior to running automake. Here's a fairly naive example:

#!/bin/sh

cat Makefile.am.head > Makefile.am
ls *.c | sed 's/$/ \\/' >> Makefile.am
cat Makefile.am.tail >> Makefile.am
autoreconf -ivf

Note that if you are going to use the autotools, you probably do not want to write rules to generate a *.so anyway, but should use libtool and the LTLIBRARIES primary.

like image 109
William Pursell Avatar answered May 04 '26 11:05

William Pursell