[comp.sources.misc] Desperately Seeking Makefile Maker

dg@wrs.UUCP (David Goodenough) (12/26/87)

Apologies for posting to comp.lang.c; I don't know what the original
was in here for, this has been cross posted to comp.sources.misc
I suspect that any followups would be best directed there.
[Moderator's note:  He suspects wrongly.  Followups to comp.sources.d please.
++bsa]

>    Is there a program available that creates makefiles...

I use the following shell script to create "self generating" makefiles.

Basically you create a directory, put all the .c's into it that will
make up your program, then say

% mkmake prog >makefile

where prog is the output program name.
Then say

% make source

to generate the list of .c and .o files that make up the program, and
then say

% make depend

to make the dependancy list at the bottom. Sadly this is not too clever:
it can't handle special awk / yacc / lex / assembler / etc. etc. etc.
runs, but for starters I find it useful.

The things you will be able to make are:

prog - full bore program creation;
clean - remove .o files, core images and other junk;
lintout - do a lint job on the source files;
errs - run a normal 'make prog' but put output in makeout;
tags - create a tags file for vi;
source - rebuild the list of .c and .o files that constitute the program;
depend - build dependancies for the source files.
--
		dg@wrs.UUCP - David Goodenough

	..... !rtech!--\			+---+
			>--!wrs!dg		| +-+-+
	....... !sun!--/			+-+-+ |
						  +---+

--- cut here --- cut here --- cut here --- cut here --- cut here ---
#! /bin/sh
# mkmake - create a makefile
echo '# makefile for' $1
echo ''
echo CFLAGS= -O
echo LFLAGS= -hbx
echo SRC=
echo OBJ=
echo ''
echo -n $1
echo ':	${OBJ}'
echo '	cc ${CFLAGS} -o' $1 '${OBJ}'
echo ''
echo clean:
echo '	rm -f core lintout makeout tags makefile.bak *.o'
echo ''
echo 'lintout: ${SRC}'
echo '	\@rm -f lintout'
echo '	lint ${LFLAGS} ${SRC} >lintout'
echo ''
echo errs:
echo '	\@rm -f makeout'
echo "	make $1 >makeout"
echo ''
echo 'tags:	${SRC}'
echo '	\@rm -f tags'
echo '	ctags ${SRC}'
echo ''
echo 'source:'
echo '	mv makefile makefile.bak'
echo '	head -4 makefile.bak >makefile'
echo '	echo SRC= `ls *.c` >>makefile'
echo '	echo OBJ= `ls *.c | sed s/c$$/o/` >>makefile'
echo '	tail +7 <makefile.bak >>makefile'
echo ''
echo 'depend: ${SRC}'
echo '	for i in ${SRC}; do\'
echo -n '	    cc -M $$i | sed -e '
echo "'s, \./, ,' | \"
echo -n "	    awk '"
echo '{ if ($$1 != prev) { if (rec != "") print rec; \'
echo '		rec = $$0; prev = $$1; } \'
echo '		else { if (length(rec $$2) > 78) { print rec; rec = $$0; } \'
echo '		else rec = rec " " $$2 } } \'
echo "		END { print rec }'; done >makedep"
echo -n "	echo '/^# DO NOT DELETE THIS LINE/+2,"
echo -n '$$d'
echo "' >eddep"
echo -n "	echo '"
echo -n '$$r '
echo "makedep' >>eddep"
echo "	echo 'w' >>eddep"
echo '	cp makefile makefile.bak'
echo '	ed - makefile <eddep'
echo '	rm eddep makedep'
echo "	echo '' >>makefile"
echo "	echo '# DEPENDENCIES MUST END AT END OF FILE' >>makefile"
echo "	echo '# IF YOU PUT STUFF HERE IT WILL GO AWAY' >>makefile"
echo "	echo '# see make depend above' >>makefile"
echo ''
echo '.c.o:'
echo '	cc ${CFLAGS} -c $*.c'
echo ''
echo '# DO NOT DELETE THIS LINE -- make depend uses it'
echo ''
echo ''