#!/bin/sh # File: mm # Date: Mon Apr 21 12:49:07 MDT 2003 # Whom: Erik Huizing # # Synopsis: # Automatically generate a Makefile, from the arguments on the command line # This is a rewrite of an older version written in csh. This new version # takes advantage of the fact that gcc will do dependency generating # automatically # # $eriktools$ if [ "$#" -lt "2" ]; then me=`basename $0` echo "Usage: $me target [ source files ]" echo "Creates makefiles automatically" echo 'eg: mm a.out *.cpp' exit 1 fi DATE=`date` NAME=`finger $USER | grep Name: | cut -d: -f3 | cut -c 2-` TAG=`basename $PWD` # # defaults: # CXX=gcc LD=gcc LIBS="" LIBPATH="" INCL="" CXXFLAGS="-O3 -Wall -g \${INCL}" TARGET=$1 shift if [ -f libs ]; then LIBS=`cat libs` fi if [ -f libpath ]; then LIBPATH=`cat libpath` fi if [ -f includes ]; then INCL=`cat includes` fi # # if Makefile already exists, save a copy of it # if [ -e Makefile ]; then echo Saving backup as Makefile.old /bin/mv Makefile Makefile.old fi # # start with a brand spankin' new file # /bin/cp /dev/null Makefile # # extract the list of source files/objects # while [ "$#" -gt "0" ]; do f=`echo $1 | sed 's/\.[cC][cC+p]*//'` SRCS="${SRCS} $1" OBJS="${OBJS} $f.o" shift done # # Build the Makefile # cat <>Makefile # File: Makefile # # Date created: ${DATE} # Whom: ${NAME} # # \$${TAG}\$ CXX=gcc LD=gcc LIBS=${LIBS} LIBPATH=${LIBS} INCL=${INCL} CFLAGS=-O3 -Wall -g \${INCL} TARGET = ${TARGET} SRCS=${SRCS} OBJS=${OBJS} \${TARGET}: \${OBJS} \${LD} \${OBJS} -o \${TARGET} \${LIBS} \${LIBPATH} clean: /bin/rm -f \${TARGET} \${OBJS} *core depend: ${CXX} -E ${INCL} -MM \${SRCS} > .depend EOF #