mkdep program for SysV (Xenix/Unix)

mkdep program for SysV (Xenix/Unix)

Post by Ronald S H Kh » Sat, 15 Dec 1990 11:38:42



[ OK guys, where *do* you ask about things like makefile makers ?
  comp.unix.programmer ?  alt.sport.toe.wrestling ?  I'll try the former :-) ]

[ Now I'm going to *expect* a followup telling me what the current crop of
  mkdeps do that cc -M doesn't.  Or do people distribute makedepend
  just because some people don't have cc -M ?  Answers on a postcard to
  Craig Shergold, please, or follow up :-) ]


> Hi. I have alot of Makefiles that call a "makedep" or "mkdep" program, which
> I assume adds to the end a zillion dependencies [ to the end of Makefiles ]
> Anyway, I could really use [ mkdep ], or one which does
> something similar, for those Makefiles and as a general utility.

One fast and accurate way to make dependencies for makefiles is to use gcc -M.
(Doug's asking about Xenix/Sys V, so he'd need gcc.  BSD cc has -M doesn't it?)

For example, you could add something like

        depend:
                sed "/^# DELETE ME/q" Makefile > Makefile.new
                gcc $(CFLAGS) -M $(OBJS:.o=.c) >> Makefile.new
                mv Makefile.new Makefile

        # DELETE ME

to the end of your makefile.  Then "make depend" would do just that.
This works especially well when your dependencies change a lot depending
on what -I and -D flags you change in CFLAGS, just run make depend again.

Just make sure you haven't got a file called "depend" in the current
directory :-)
--

 
 
 

mkdep program for SysV (Xenix/Unix)

Post by Doug McCall » Sun, 16 Dec 1990 01:02:31



...
Quote:>One fast and accurate way to make dependencies for makefiles is to use gcc -M.
>(Doug's asking about Xenix/Sys V, so he'd need gcc.  BSD cc has -M doesn't it?)

...
The System V.3 cc has an option similar to the -M option.  
        cc -P -H $CFLAGS file.c 2>&1 | sed "s;^;file.c:;"
is almost what -M does.

 
 
 

mkdep program for SysV (Xenix/Unix)

Post by Brandon S. Allbery KB8J » Mon, 17 Dec 1990 11:04:14



+---------------

|
| > Hi. I have alot of Makefiles that call a "makedep" or "mkdep" program, which
| > I assume adds to the end a zillion dependencies [ to the end of Makefiles ]
| > Anyway, I could really use [ mkdep ], or one which does
| > something similar, for those Makefiles and as a general utility.
|
| One fast and accurate way to make dependencies for makefiles is to use gcc -M.
| (Doug's asking about Xenix/Sys V, so he'd need gcc.  BSD cc has -M doesn't it?)
+---------------

If I remember correctly, BSD cc has -M but it has to be massaged to produce
dependencies.  gcc has -M and -E -M (I think that's correct); the latter
produces dependencies in Makefile format.

I have a Perl script that computes dependencies, which I use in preference to
gcc.  Part of the reason is that it doesn't feel as weird as running a C
compiler on random non-C source [ ;-) ] and part of the reason is some
misgivings about letting gcc anywhere near my Unify ACCELL 4GL scripts,
copyleft notwithstanding.  Neither is a hard-and-fast reason, and little would
change if I made my mkdep script call gcc -E -M, except that my mkdep does
a little cleanup on the resulting filenames.  In particular, I seem to
remember it keeping an eye on Makefile macro definitions and substituting them
in place of leading pathname components.  (It's been a while since I bothered
to look at the output; once you trust a tool, you don't worry it to death.)

++Brandon
--
Me: Brandon S. Allbery                      VHF/UHF: KB8JRR on 220, 2m, 440

America OnLine: KB8JRR                      AMPR: KB8JRR.AmPR.ORG [44.70.4.88]
uunet!usenet.ins.cwru.edu!ncoast!allbery    Delphi: ALLBERY

 
 
 

mkdep program for SysV (Xenix/Unix)

Post by Scott Merrile » Tue, 18 Dec 1990 12:22:20



> Hi. I have alot of Makefiles that call a "makedep" or "mkdep" program, which
> I assume adds to the end a zillion dependencies [ to the end of Makefiles ]
> Anyway, I could really use [ mkdep ], or one which does
> something similar, for those Makefiles and as a general utility.

I got a makedepend program from the X11 tapes, which seems to work
well.  I had a mkdep program, but it worked less well.  The makedepend
program is quite modest in size, and is a shell/awk/sed script.

Sm
--
Scott Merrilees, BHP Information Technology, Newcastle, Australia

 
 
 

mkdep program for SysV (Xenix/Unix)

Post by Ronald S H Kh » Wed, 19 Dec 1990 02:19:06



Quote:> If I remember correctly, BSD cc has -M but it has to be massaged to produce
> dependencies.  gcc has -M and -E -M (I think that's correct); the latter
> produces dependencies in Makefile format.

Maybe gcc's changed since you last looked at its options.  I quote the
relevant portion of "man gcc" (which says 1.36 on it, but is the one
distributed with gcc 1.37.1, ie the current gcc)

Quote:> once you trust a tool, you don't worry it to death.)

An excellent point.

Begin excerpt from /usr/man/cat.G/gcc.G:-----------------------------------
          -M   Tell the preprocessor to output a rule suitable for
               make(1) describing the dependencies of each source
               file.  For each source file, the preprocessor outputs
               one make-rule whose target is the object file name for
               that source file and whose dependencies are all the
               files #included in it.  This rule may be a single line
               or may be continued with \-newline if it is long.

               -M implies -E.

          -MM  Like -M but the output mentions only the user-header
               files included with #include "file".  System header
               files included with #include <file> are omitted.

               -MM implies -E.
End   excerpt from /usr/man/cat.G/gcc.G:-----------------------------------
--

 
 
 

mkdep program for SysV (Xenix/Unix)

Post by Ned Nowot » Sun, 23 Dec 1990 04:17:02



Quote:>One fast and accurate way to make dependencies for makefiles is to use gcc -M.
>(Doug's asking about Xenix/Sys V, so he'd need gcc.  BSD cc has -M doesn't it?)

>For example, you could add something like

>    depend:
>            sed "/^# DELETE ME/q" Makefile > Makefile.new
>            gcc $(CFLAGS) -M $(OBJS:.o=.c) >> Makefile.new
>            mv Makefile.new Makefile

>    # DELETE ME

Or,

Makefile.depend: $(SRCS) $(HDRS)
        for src in $(SRCS) ; \
        do \
            $(CC) $(CFLAGS) -E $${src}             | \
                grep '^# *1 '                      | \

                grep -v "$${src}"                  | \


        done

if your compiler does not have -M but does have -E.

Ned Nowotny, MCC CAD Program, Box 200195, Austin, TX  78720  Ph: (512) 338-3715

-------------------------------------------------------------------------------
"We have ways to make you scream." - Intel adverti*t in the June 1989 DDJ.

 
 
 

mkdep program for SysV (Xenix/Unix)

Post by Ned Nowot » Sat, 05 Jan 1991 05:02:00



=>>One fast and accurate way to make dependencies for makefiles is to use
=>>gcc -M.  (Doug's asking about Xenix/Sys V, so he'd need gcc.  BSD cc has
=>>-M doesn't it?)
=>>
=>>For example, you could add something like
=>>
=>>       depend:
=>>               sed "/^# DELETE ME/q" Makefile > Makefile.new
=>>               gcc $(CFLAGS) -M $(OBJS:.o=.c) >> Makefile.new
=>>               mv Makefile.new Makefile
=>>
Quote:>>        # DELETE ME

=>>
=>
=>Or,
=>
=>Makefile.depend: $(SRCS) $(HDRS)
=>   for src in $(SRCS) ; \
=>   do \
=>       $(CC) $(CFLAGS) -E $${src}             | \
=>           grep '^# *1 '                      | \

=>           grep -v "$${src}"                  | \


=>   done
=>
=>
=>if your compiler does not have -M but does have -E.
=>

To which Gilles Courcoux at the Unisys Network Computing Group responded via
email:

=>You're overloading your system with processes and your file system
=>with numerous open, lseek and close. Take a closer look at sed(1)
=>and sh(1). Worse, you don't give the left handside member of the
=>dependency (ending here in .o). Try:
=>
=>Makefile.depend: $(SRCS) $(HDRS)
=>        for src in $(SRCS) ; \
=>        do \
=>            obj=`expr $$src : '\([^.]*\)\..*' \| $$src`.o export obj; \
=>            $(CC) $(CFLAGS)  -E $${src} \

=>            | sort -u; \

=>

He is quite right that I failed to provide the left-hand side of the dependency.
I cut the text from a make dependency which included a case statement so that
dependencies could be generated for both C and C++.  The following line is the
missing part which should immediately follow the "do" in my example:


To give credit where credit is due, my example is based on a pipeline
written by Steven P. Reiss at Brown University.  The pipeline is
used in the Field Environment.

In any case, Gilles Courcoux has provided a better pipeline for
generating dependencies from the more common -E C compiler flag.

Ned Nowotny, MCC CAD Program, Box 200195, Austin, TX  78720  Ph: (512) 338-3715

-------------------------------------------------------------------------------
"We have ways to make you scream." - Intel adverti*t in the June 1989 DDJ.