Feature idea for GCC: link dependencies

Fergus Henderson fjh@cs.mu.OZ.AU
Tue Jul 15 05:29:00 GMT 2003


On 14-Jul-2003, Martin Schaffner <maschaffner@gmx.ch> wrote:
> GCC is already able to create makefile fragments containing compile
> dependencies of source files.
> 
> I propose an extension to enable it to add link dependencies to such
> makefile fragments. A file main.c has a link dependency on foo.c if a function
> defined in main.c calls a function defined in foo.c. The idea is to maintain such
> link dependencies in the source code instead of in "makefile" or
> "makefile.am". If foo.h contains a line `#pragma linkdep "foo.c"', then the compiler
> knows that every source file with a line `#include "foo.h"' has a link dependency
> on foo.c. If it links main.o into an executable, it has to link it with
> foo.o.
> 
> I created a patch which implements the above proposition:
> http://in3www.epfl.ch/~schaffne/use/gcc-cvs-3-7-14-linkdep.ptch
> Please comment and criticize.

Please post the documentation for the new feature.
It's much easier to review documentation without code
than code without documentation.

If such a feature is to be added, IMHO it should also be able to handle
dependencies on external libraries, e.g. `-lm'.

> diff -u -r1.20 mkdeps.c
> --- gcc/mkdeps.c        13 Jul 2003 17:34:18 -0000      1.20
> +++ gcc/mkdeps.c        14 Jul 2003 15:01:48 -0000
> @@ -105,6 +110,27 @@
>    return buffer;
>  }
>  
> +/* convert the name of a source file to the name of the corresponding
> +   object file.  It is the responsability of the caller to free the
> +   returned string.  */

s/convert/Convert/

s/responsability/responsibility/
bar responsability responsibility foo

> +static char *
> +obj_of (src)
> +     const char *src;

That should use the ANSI/ISO prototype style rather than the old style,
I believe.

> +{
> +#ifndef TARGET_OBJECT_SUFFIX
> +# define TARGET_OBJECT_SUFFIX ".o"
> +#endif
> +  const char *start = lbasename (src); \
> +  char *obj = (char *) xmalloc (strlen (start) + strlen (TARGET_OBJECT_SUFFIX)
>  + 1); \

The backslashes are unnecessary and confusing.

>  void
> +deps_write_linkdeps (d, fp, colmax, linktarget)
> +     const struct deps *d;
> +     FILE *fp;
> +     unsigned int colmax;
> +     const char * linktarget;
> +{
> +  unsigned int size, i, column;
> +
> +  column = 0;
> +  if (colmax && colmax < 34)
> +    colmax = 34;

What's the magic number 34?

> +++ gcc/mkdeps.h        14 Jul 2003 15:01:48 -0000
> @@ -52,6 +52,17 @@
>     is the number of columns to word-wrap at (0 means don't wrap).  */
>  extern void deps_write (const struct deps *, FILE *, unsigned int);
>  
> +/* As deps_add_dep, except that the dependency is added to the set of
> +   link dependencies instead of the set of compile dependencies.
> +   Takes a boolean indicating wether to change the dependecy's suffix
> +   into an object file suffix.  */
> +extern void deps_add_linkdep   PARAMS ((struct deps *, const char *, int));

s/wether/whether/
s/dependecy/dependency/
s/int/bool/   (and likewise in the function definition)

-- 
Fergus Henderson <fjh@cs.mu.oz.au>  |  "I have always known that the pursuit
The University of Melbourne         |  of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh>  |     -- the last words of T. S. Garp.



More information about the Gcc mailing list