[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: "dynamic" makefile

From: Sylvestre Ledru
Subject: Re: "dynamic" makefile
Date: Thu, 07 Dec 2006 18:23:54 +0100

Le jeudi 30 novembre 2006 à 15:45 +0100, Ralf Wildenhues a écrit :
> * Sylvestre Ledru wrote on Thu, Nov 30, 2006 at 03:02:21PM CET:
> > 
> > I would like to generate a Makefile which will work with source files
> > provided in the command line (parameters) instead of providing them into
> > the
> [...]
> > I would like to be able to produce this kind of line from a 
> > but instead of providing "src/hashtable_localization.c", it will use
> > parameters provided by the user. (ie $1)
> > 
> > I want to do this because I want to provide to the user of my
> > application the possibility to edit C/fortran files, compile, link and
> > load them from the application without touching configure.* or Makefile*
> I don't think this is possible in general.  If the list of files the
> user can choose is a subset of a pre-defined set of source file names,
> you can stuff all of those in some EXTRA_foo_SOURCES variable.
> Otherwise, all you can get is the inference rules.  I.e.,
>   make foo.o
> will look for foo.c (and maybe foo.f, foo.cpp...) and if found use the
> corresponding .c.o (or .f.o, .cpp.o, ...) rule if you have enabled the
> inference rule.  (Automake outputs them as soon as you list some source
> file with that extension in a *_SOURCES variable; an EXTRA_*_SOURCES as
> above would probably come in handy again).  But this won't get you the
> benefit of dependency-tracking of included files.  And you'd still have
> to write a rule for linking (but you can just write one manually and
> make it depend upon a macro name which the user overrides).
> Hope that helps.
Yep, it did help.

I worked on a solution. Some might find it perfectible (and I won't deny
it) :) 
It is a test case.

Here is the procedure :
# autoreconf (just once for the maintainer, just to create
and configure)
# ./configure
#  ./ mygreatlib plop.c plop.f
# make

Here is what I did :

------- -------
libsciexternal_la_SOURCES = foo.c foo2.f foo3.cxx

------- ------- 



------- ------- 



# Check number of parameters
if test $# -lt 2; then
        echo "Syntax : $0 libname sources"
        exit -1

# retrieve parameters

# Check if files exist
for file in $SOURCES; do
        if test ! -s $file; then 
                echo "Cannot find $file"
                exit -2

# Relaunch configure if files are missing
if test ! -s Makefile -o Makefile -ot Makefile.orig ; then 
        echo "Detection of C/C++/Fortran Compilers"
        mv Makefile Makefile.orig       

# Replace fake filenames to the one we want 
sed -s "s|libsciexternal_la_SOURCES = foo.c foo2.f foo3.cxx|
lib"$LIB"_la_SOURCES = $SOURCES|" Makefile.orig > Makefile

##Replace  sources by .lo file
SOURCES=`echo $SOURCES|sed -s 's|\.c|\.lo|'`
SOURCES=`echo $SOURCES|sed -s 's|\.f|\.lo|'`
SOURCES=`echo $SOURCES|sed -s 's|\.cxx|\.lo|'`

### Changes objects in the source code
sed -si "s|am_libsciexternal_la_OBJECTS = foo.lo foo2.lo foo3.lo|
am_lib"$LIB"_la_OBJECTS = $SOURCES|" Makefile

### Changes objects in the source code
sed -si "s|libsciexternal|lib"$LIB"|" Makefile


Comments/criticism are welcome :)


reply via email to

[Prev in Thread] Current Thread [Next in Thread]