To take the most trivial points:
1) doesn't take advantage of built-in rules
2) highly non-extensible - should define, say, $(OBJECTS) instead of
listing all the object files in more than one place.
3) should rm -f so that "make clean" doesn't return a non-zero value
when called with no built files present
4) "make install" fails to set permissions sensibly (most likely 755
will be wanted for a program in /usr/local/bin) - and it would be nice
to have a $(PREFIX) variable instead of hard-coding the path
5) WTF is "DFLAGS"? A non-standard variable name, with no comment
explaining what it's for.
See now, that wasn't so hard, was it? You have to spell these
things out for the likes of CFB. I disagree that it falls under
the category of "most amateruish". The only thing I would count
as an error is your point three and that's a fine point. Your
other points are issues of technique - ways of doing things that
really should only be done in throwaway makefiles.
That said, here are a few things that I would do as a matter of
course. First of all I would add makefile to all of the
dependencies. Secondly I would distinguish between the "main"
files and the other files. Thus, assuming that a.c contains the
main entry point, the makefile would contain
OBJ = b.o
prog.exe: a.o $(OBJ) makefile
In this case it doesn't matter, there being, only one main
program, but quite often one wants to build more than one program
sharing the same routines.
Thirdly I would split up the flags by category. Thus
STDFLAGS = -W ...
OPTFLAGS = -O2
DEBUGFLAGS = -g -pg
#DEBUG = $(DEBUGFLAGS)
CFLAGS = $(STDFLAGS) $(OPTFLAGS) $(DEBUG)
The business with DEBUG is to make it convenient to build or not
build a debug version without a lot of fiddling with the
makefile; you can also do this with a command line argument.
Forthly, I would make commands like 'rm -f' a variable, e.g.,
RM = rm -f
as a matter of routine.
Fifthly, I would have an 'all' target as the first target so that
by default make without arguments makes everything.
Finally, I don't always follow all of my good advice.
Etc.
Richard Harter, (e-mail address removed)
http://home.tiac.net/~cri,
http://www.varinoma.com
Save the Earth now!!
It's the only planet with chocolate.