Earnie Boyd wrote:
> --- William Kempf <sirwillard@...> wrote:
> > >--- William Kempf <sirwillard@...> wrote:
[makefiles with autodependencies]
> > >> just offering mine for others that might be in the same boat I was in.
> > >
> > >And such contributions are just what we need.
> > Is there some central repository for contributions?
> The current method for contributions is to use the patch manager at
I'll offer something below that seems inappropriate there, since it
doesn't patch anything.
> > One problem with the makefile that I've found... it doesn't like Win98. Some
> > of the commands I use aren't available in command.com (such as del /s). This
> > would be easiest to work around if I had some Unix command line utilities
> > such as cp, mv, rm, etc. Does anyone have a link to some mingw versions of
> > these commands?
> See the http://www.mingw.org website for links to these.
Hint: 'Ported Software'
> > Another problem is that for some reason the following command fails:
> > @sed -e "s/\(.*\.o\)/$(OUTDIR)\/\1/" < $*.d > $(of).d
> > After make replaces some of the macros above the command results in something
> > similar to this:
> > sed -e "s/\(.*\.o\)/debug\/\1/" < main.d > debug/main.d
> > Win98 complains that it can't create the file. Why this sed command works on
> > the Win2k machine but not the Win98 machine is a mystery to me at this point.
> > If anyone has any ideas I'd be grateful. Otherwise it's some hacking to be
> > done before I get it to work on Win98.
On Thu, 21 Sep 2000 18:58:45 -0400 I posted to this list my reason for
preferring sed -e 'w whatever.d' instead of redirection: briefly,
an empty .d file is created (or written over) if the sed
command fails. The dependency file is incorrect, so targets that need
to be rebuilt may be ignored the next time I run make.
You may find some additional clues if you remove the '@' from the sed
command while debugging it. It might also help to do
redir -eo make -d my_target | less
on win9x, where you can't otherwise redirect stderr.
Perhaps you have different versions of sed on the two machines, even if
'sed --version' says the same thing on both.
Does it make any difference if you enclose the -e option in single
rather than double quotes? Seems unlikely, but I've seen stranger things.
Here is the autodependencies section of a makefile I'm using in actual
production. It is designed to work with gnu make version 3.77 or later,
and either mingw gcc-2.95.2-1 or borland c++5.02 . I don't claim it's
perfect, but it has served me well.
# Automatic dependencies
# See Paul D. Smith's discussion at this URL:
# First I tell GNU CPP to remember that it's GNU:
# -undef -no-gcc -D __GNUG__ \
# Then I tell it to ignore my pch files,
# which gcc doesn't yet support
# -D MY_PRECOMPILED_HEADERS \
# I changed Paul's sed commands to work with
# win95. Here's a line by line explanation:
# Concatenate all lines continued with '\'
# -e :a -e '/\\$$/N; s/\\\n//; ta' \
# Note that sed commands in a makefile must double any
# dollar sign.
# GNU CPP -M FOO.cpp gives us FOO.cpp.o: FOO.cpp ...
# ??? If the tools see FOO.cpp.obj: FOO.cpp FOO.hpp ...
# and FOO.HPP is newer, they try to compile FOO.hpp as
# though it were a .cpp file.
# Therefore, change the rule to FOO.obj: FOO.cpp FOO.hpp ...
# -e 's/\.cpp\.o:/\.o:/' \
# If we've suppressed the .cpp.o: default rule and
# provided our own %.obj : %.cpp rule instead, then
# we get FOO.o: FOO.cpp FOO.hpp ... and need to change
# .o to .obj .
# -e 's/\.o:/\.obj:/' \
# Here's a problem. If we use both these lines:
# -e 's/\.cpp\.o:/\.obj:/' \
# -e 's/\.o:/\.obj:/' \
# then sed fails. ?? Need to look into that someday.
# For now, we just remove the first line.
# Paul's sed script copies the original output of CPP to
# a file, then appends to it with >> . The worst problem
# here is that DOS creates the file even if sed fails.
# Therefore, we'll store what we've got so far in the hold
# space with 'h', then later append it with 'G', and write
# it with 'w'.
# -e 'h' \
# This is what Paul does to prevent ugly errors when a file
# previously in the dependency list has been erased or renamed.
# Remove the target at the beginning,
# -e 's/^[^:]*: *//' \
# and place a colon at the end. We can skip his steps to delete
# blank lines because we started out by making the whole
# expression one single line.
# -e 's/$$/ :/' \
# As described above, append the contents of the hold space
# that we saved above,
# -e 'G' \
# then write the whole thing to the target file
# (stem plus .d extension). If sed terminated early due to
# an error, the 'w' command will not be reached, and no file
# will be written. Redirect the sed output to /dev/nul so
# that it doesn't clutter the screen.
# -e 'w $*.d' > $(non-posix-devnul)
# We make the dependency files in a separate step. If we're
# sure we're never going to use any other compiler than gcc,
# then we can combine this into the compile step e.g. with -MM .
# If the GNU preprocessor isn't what you get when you type
# cpp --version
# then you'll have to give its specific location here.
GNU_PREPROCESSOR = CPP
#GNU_PREPROCESSOR = redir -e $*.e CPP
# The ms shell does not recognize the nul device with a POSIX pathname.
#non-posix-devnul := nul
non-posix-devnul := \dev\nul
# On 21 Sep 2000 19:53:12 -0700, Earnie Boyd (mingw.org mailing list)
# mkdir /dev
# sed -e 'some sed command' > /dev/null
# We should look into this.
MAKEDEPEND = \
-x c++ \
-D MY_PRECOMPILED_HEADERS \
-e :a -e '/\\$$/N; s/\\\n//; ta' \
-e 's/\.o:/\.obj:/' \
-e 'h' \
-e 's/^[^:]*: *//' \
-e 's/$$/ :/' \
-e 'G' \
-e 'w $*.d' \
sources := $(wildcard $(srcdir)/*.cpp) # */ close apparent C comment
depends := $(notdir $(sources:.cpp=.d))