Kodama's home / tips.

M2F Modula2 用 Makefile

M2F Modula2 用の Makefile の雛形を作るスクリプト. Modula2 のソ−スがあるディレクトリで このスクリプトを実行する.

コンパイラを起動して そのメッセ−ジを参照しているだけの 超手抜きだけど大体は大丈夫.

*.mod と *.def に関する ル−ルで十分だが, Modula2 と link する C のソ−スが含まれる場合もあるので, *.c のル−ルも出す事にした.

make も gcc の -MM オプションも知らないで, 毎回 cc ... とか打ってコンパイルしている人もいる. っていうかそういう風に教えられてるのかな? なんだかねぇ〜

#! /bin/bash
# m2depend
# For M2F Modula2,
# this script output a rule suitable for make 
# describing the dependencies of .def, .mod and .c sources
#
# K.Kodama 1999.12.5

if [ "$1" = "-h" ];then
cat <<'EOF'
 For m2f Modula2,
 this script output a rule suitable for make 
 describing the dependencies of .def, .mod and .c sources

    -h , This text.
    -m , output default rule for m2f Modula2
    none, output rule for make
EOF
exit
elif [ "$1" = "-m" ];then
cat <<'EOF'
# Makefile for m2f Modula-2

M2PATH=-M "/usr/m2/libs ."
M2OPTION=$(M2PATH) -bounds -return -v -verbose -O
MLOPTION=$(M2OPTION) -m -l
# -g
M2C=m2f $(M2OPTION)
M2L=m2f $(MLOPTION)

%.o : %.mod
	$(M2C) $<

%.o : %.c
	cc -O2 -c $< -o $@

% : %.o
	$(M2L) -o $@ $<

# all: 

clean:
	rm *.o

#install:

depend:
	m2depend -m

EOF
fi

echo "####### m2depend #######"

for m in *.mod;do
mod=`echo ${m}|sed 's/\.mod$//'`
modules=`m2f ${mod}|gawk '$1=="Module"{print $2}'|grep -v '^'${mod}'$'`
defs=`(for i in $modules;do if [ -f ${i}.def ];then echo $i;fi;done)|gawk '{printf "%s.def ",$1}'`
obj=`echo $defs|sed 's/\.def/.o/g'`
if [ -f ${mod}.def ];then 
	defs="${mod}.def ${defs}"
else
	echo "${mod} : ${mod}.o ${obj}" ;echo 
fi 
echo "${mod}.o : ${mod}.mod ${defs}" ; echo
done


for c in *.c ;do
mod=`echo $c|gawk '{sub(/\.c$/,"");print}'`
if [ -f ${mod}.def ];then
	echo "`cc -MM ${mod}.c` ${mod}.def";echo
	# -MM -MG
fi
done

# end

Kodama's home / tips.