bug-make
[Top][All Lists]
Advanced

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

Guidelines for generating files into the source dir


From: Niels Möller
Subject: Guidelines for generating files into the source dir
Date: 11 Feb 2003 20:26:16 +0100
User-agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2

For a long time, using $(srcdir) in targets and prerequisites in
Makefiles have seemed a little magic to me. It breaks too often,
usually in ways like automatic dependency generation not working.

So I've tried to create a small toy project, and a testscript that
builds the projects in various ways, checking that it behaves as it
should. I've gotten the generated files to work properly, but I'm not
sure I'm doing it in the right way.

The project can be found at
http://www.lysator.liu.se/~nisse/misc/make-example-0.0.tar.gz. The
README file is as follows:

This is a dummy project written to illustrate how to write make rules
for automatically generated files. For now, it uses only
system-independent automatically generated files. The rules are:

* sh-gen.h and c-gen.h are generated by the shell-script sh-gen and C
  progran c-gen.c, respectively.

* These files are generated by the maintainer, in the source directory.

* They should be included when the program is distributed.

* The program foo depends on the generated files. If the sh-gen or
  c-gen.c are modified, foo. and foo must be rebuilt. 

* Everything should work both for builds in the source directory, and
  for builds that use a separate build directory. And in the separate
  build directory case, it should work with both a relative and an
  absolute filename for srcdir.

* When building a from a distribution, the c-gen binary will not be
  built.

The script ./check-example tries to check that the build process works
as intended.


The basic problem with using a target like sh-gen.h rather than
$(srcdir)/sh-gen.h is that dependencies don't work properly when
building in a separate directory. We get the dependencies:

  foo.o: ../sh-gen.h
  sh-gen.h: ../sh-gen

and it doesn't follow that f..o depends on sh-gen.

A workaround is to add the rules

  .PHONY: $(srcdir)/sh-gen.h
  $(srcdir)/sh-gen.h: sh-gen.h

That generates a some warnings

  make: Circular ../sh-gen.h <- ../sh-gen.h dependency dropped.

but it actually seems to work.


Another problem is the c-gen binary. On one system where I tried this,
make distcheck tried to rebuild c-gen.h, which failed because the
source dir is readonly. This was with make 3.79.1, automake 1.6.1. I
have no idea why that happened, the targets built by make should
depend only on c-gen.h, which in turn depends on c-gen.c, not on the
binary. 




reply via email to

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