Bash的另类shellMakefile
文章作者 100test 发表时间 2008:02:01 15:27:54
来源 100Test.Com百考试题网
无赖对 Makefile 不太熟悉,为了编译数量不断增加的独立的 .cpp 文件,只有想个另类的办法了。考虑了好几种方法,最后以 Makefile为壳,用 bash 暗渡陈仓。
  Makefile 如下: 
  QUOTE:
main: null.out
null.out:
./compile.sh 
clean: 
rm *.out  | 
  compile.sh 就是实际执行 make 命令的了:
  QUOTE:
#!/bin/bash
for cpp in *.cpp
do
out="${cpp%.cpp}.out" 
if test ${cpp} -nt ${out} 
then
printf "g   -o %s %s\n" "${out}" "${cpp}" 
g   -o ${out} ${cpp}
fi
done |