help-make
[Top][All Lists]
Advanced

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

Re: generating makefile/Generating prequisities auto?


From: Martin Sebor
Subject: Re: generating makefile/Generating prequisities auto?
Date: Mon, 15 Sep 2003 09:51:56 -0600
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.4) Gecko/20030624 Netscape/7.1 (ax)

Frank wrote:

Can anyone provide a working example of using the generating perquisites
automatically?  It's from section 4.14?  I want to generate the depends
for each .cpp/.o automatically i.e. generate a .d

This rule is lifted from our infrastructure. It's being used with
GNU make 3.70 through 3.80 on about a dozen operating systems and
compilers.

ifneq ($(DEPENDFLAGS),)

# generate dependencies only if they don't yet exist, removing anything
# not under $(TOPDIR) or $(BUILDDIR) (e.g., system headers) from the
# list; this is done by splitting up dependencies using tr so that there
# is just one per line and then replacing the values of $(TOPDIR) and
# $(BUILDDIR) with the actual make variable names themselves
# move IBM xlC generated .u files to the respective .d files

define makedep
        -@(if [ ! -f $@ ] ; then                                       \
            echo "generating dependencies for $<" ;                    \
                                                                       \
            stripexp="s:/$$::;s:[^/]*$$::";                            \
            RWTSRCDIR=`echo $(TOPDIR) | sed "$$stripexp"`rwtest;       \
                                                                       \
            sedexp1="s:\([^ :]\)\(  */\):\1 address@hidden:" ;                 \
            sedexp2="/:[^/]*$$/p;                                      \
                    s:$$RWTSRCDIR:$$""(TOPDIR)/\.\./rwtest:gp;         \
                    s:$(TOPDIR):$$""(TOPDIR):gp;                       \
                    s:$(BUILDDIR):$$""(BUILDDIR):gp" ;                 \
                                                                       \
            echo "$(CXX) $(DEPENDFLAGS) $(CPPFLAGS) $(CXXFLAGS) $<"    \
                 >>$(LOGFILE) ;                                        \
            $(CXX) $(DEPENDFLAGS) $(CPPFLAGS) $(CXXFLAGS) $<           \
                | sed "$$sedexp1" | tr "@" "\n" | sed -n "$$sedexp2"   \
                  >$@ ;                                                \
            if [ ! -s $@ -a -f $*.u ] ; then                           \
                sed "$$sedexp1" $*.u | tr "@" "\n" | sed -n "$$sedexp2"\
                    > $@ ;                                             \
                rm -f $.i $*.u ;                                       \
            fi ;                                                       \
       fi)
endef

%.d: %.cpp
        $(makedep)

%.d: %.$(AS_EXT)
        $(makedep)

else

%.d:

endif


The .d file for assert.cpp might look like this:

$ cat /build/sebor/gcc-11s/lib/assert.d
assert.o: $(TOPDIR)/src/assert.cpp \
 $(TOPDIR)/include/ansi/stdio.h \
 $(TOPDIR)/include/rw/_defs.h \
 $(TOPDIR)/include/rw/_config.h \
 $(BUILDDIR)/include/config.h \
 $(TOPDIR)/include/ansi/stddef.h \
 $(TOPDIR)/include/ansi/stdarg.h \
 $(TOPDIR)/include/ansi/stdlib.h \
 $(TOPDIR)/include/ansi/time.h \

Regards
Martin






reply via email to

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