[comp.os.minix] mkmf - make makefile

n62@np1.hep.nl (Klamer Schutte) (03/29/89)

This program extracts dependencies for a makefile.
Its is a shell script and thus not to fast under MINIX.
It is only tested under MINIX-ST; but i don't see any reason it shouldn't 
work on a PC. 
The programs date echo grep mv rm sed sort test and uniq are used;
for grep & sed at least the minix-st version has to be patched.
These patches do i send simultanious.

See the program as a exercise in sed programming for me; those who know how
to program sed will not find it very valuable; but those who don't will!

Please mail any bugs to me: it is still in beta-test phase

Klamer Schutte --> n62@nikhefh.hep.nl <--preferred-- schutte@thoff.uucp 
		  {backbone}!mcvax!nikhefh!n62
			    !mcvax!uva!thoff!schutte
(.signature at end)

PS When tabs doesn't make it through: in the .sed files is used [ 	];
   this is a '[', a space, a tab and a ']'.
----------------------------------------------------------------------------
echo x - mkmf.1
sed '/^X/s///' > mkmf.1 << 'Shar_Of_mkmf.1_Eof'
XMKMF(1) 								MKMF(1)
X
X
XNAME
X	
X	mkmf - make a makefile
X
X
XSYNTAX
X	
X	mkmf files
X
X
XDESCRIPTION
X	
X	mkmf extracts depencies from C source files based on information
X	retrieved from the #include statements in the files.
X	The output, meant to be part of a Makefile is written to stdout.
X
X	Any comments (C style) or embedded newlines escaped by \ are
X	ignored
X
X	The following two forms of include syntax are supported:
X	
X	- When the filename is inside double qoutation (#include "fnm") the
X	  filename is assumed to be either an absolute pathname or a
X	  pathname valid at the time of running make.	
X
X	- When the filename is in brackets (#include <fnm>) the filename
X	  is assumed relative to a system include directory.
X	  In the makefile the variable $(SYSINCL) must be set to this 
X	  directory.
X
X	Included files in "" are recursively searched for other included
X	files; a check is made to prevent looping.
X
XFILES
X
X	/tmp/mkmf[0-3]	
X
XSEE ALSO
X	
X	make(1), cc(1)
X	
X	"Make - A Program for Maintaining Computer Programs"
X		in some UNIX(*) tutorials
X
XAUTHOR
X
X	Klamer Schutte -- n62@nikhefh.hep.nl
X
XBUGS
X	
X	The name promesses too much: The program only makes the dependencies
X	and not as some other mkmf a complete makefile
X
XSTATUS & DISCLAIMER
X
X	No responsibility is taken for the program or for its results.
X
X	mkmf and its associated files are not public domain; the current
X	release can be freely used and distributed when and only when
X	1 Nobody except me (Klamer Schutte) claims to be the author.
X	2 It is not sold or part of a package sold.
X	3 Its usage will make me responsible for any of its results.
X
X(*)	UNIX is a trademark of AT&T Bell Laboraties.
X
X
X
X
X
X
XMINIX manual - Commands		29 march 1989				1 
Shar_Of_mkmf.1_Eof
echo x - mkmf
sed '/^X/s///' > mkmf << 'Shar_Of_mkmf_Eof'
X#!/bin/sh
X# mkmf : make dependencies for a makefile
X# Klamer Schutte 3/'89
Xmkmf="mkmf V1.1"
Xscript1="/lib/mkmf/mkmf1.sed"
Xscript2="/lib/mkmf/mkmf2.sed"
Xecho "#	dependecies for $@" 
Xecho -n "#	extracted by $mkmf on " 
Xdate
X# for all files in the command line
Xfor i in $@
Xdo
X  sed -n -f $script1 $i > /tmp/mkmf0
X  # as a side effect is the file /tmp/mkmf1 produced
X  while test -s /tmp/mkmf1
X  do
X    mv /tmp/mkmf1 /tmp/mkmf2
X    ( while read file
X      do
X	# extract include files from the included files
X        sed -n -f $script1 $file >> /tmp/mkmf0
X	# make /tmp/mkmf3 exist and have zero length
X	echo -n > /tmp/mkmf3
X	( while read file2
X	  do
X	    # if $file2 not already in /tmp/mkmf0 process the file
X	    grep -s "^$file2\$" /tmp/mkmf0 || \
X	    echo $file2 >> /tmp/mkmf3 
X	  done 
X	) < /tmp/mkmf1
X      done
X    ) < /tmp/mkmf2 
X    # one file only have to be processed once
X    sort /tmp/mkmf3 | uniq > /tmp/mkmf1
X  done
X  echo "$i:" > /tmp/mkmf2
X  sort /tmp/mkmf0 | uniq >> /tmp/mkmf2
X  sed -f $script2 /tmp/mkmf2
Xdone
Xrm -f /tmp/mkmf[0123]
X
Shar_Of_mkmf_Eof
echo x - mkmf1.sed
sed '/^X/s///' > mkmf1.sed << 'Shar_Of_mkmf1.sed_Eof'
X# mkmf1.sed 	Klamer Schutte 3/89
X: start
X# check for \ \n
X/\\$/!b no_esc
XN
Xs/\\\n//
Xb start
X# OK, no \ \n
X: no_esc
X# delete any occurance of @
Xs/@/ /g
X# make */ one character ( @ )
Xs/\*\//@/g
X# delete a comment
Xs/\/\*[^@]*@//g
X# only end of a comment ?
X/@/{
Xs/^/ERROR\: only the end of a comment seen/w /dev/tty
Xs/^[^s]seen//
Xs/@/ /g
X}
X# only start of a comment ?
X/\/\*/!b no_com
X# delete garbage following comment start
Xs/\/\*.*$/\/\*/
XN
X# check on error condition
X/\/\*$/{ 
Xs/.*/ERROR\: Comment not terminated/w /dev/tty
Xq 
X}
Xb start
X: no_com
X# do the work now
X/^#[ 	]*include[ 	]*"\([^"]*\)"[ 	]*$/{
Xs//\1/p
Xw /tmp/mkmf1
X}
Xs/^#[ 	]*include[ 	]*<\([^>]*\)>[ 	]*$/\$(SYSINCL)\/\1/p
X# check on error condition
Xs/^#[ 	]*include/@/p
Xs/@.*/ERROR\: Illegal include statement/w /dev/tty
X
Shar_Of_mkmf1.sed_Eof
echo x - mkmf2.sed
sed '/^X/s///' > mkmf2.sed << 'Shar_Of_mkmf2.sed_Eof'
X# mkmf2.sed Klamer Schutte 3/89
X# first echo an empty line
X/:$/i\
X
Xs/\.c\:$/\.o:/
X: start
Xs/\([^\\]\)\(\n\)/\1	\\\2	/
XN
X/[^\\]\n/b start
Shar_Of_mkmf2.sed_Eof
exit 0
-- 
________________________________________________________________________________
Klamer Schutte			mcvax!nikhefh!n62	      n62@nikhefh.hep.nl