18 Star 39 Fork 1

mathmhb / Makefile

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
mhb.sh 1.62 KB
AI 代码解读
一键复制 编辑 原始数据 按行查看 历史
mathmhb 提交于 2023-04-10 01:51 . mhb.sh now works to build c/cpp
#!/bin/sh
#The real sh not with bash extensions
#for testing use dash as interpreter because sh is often simlinked to bash
HELP(){ echo "$0 [-h] [-f 'file'] [-c 'cflags'] [-l 'ldflags'] [-x 'cross_compiler_prefix-'] cmd ";exit; }
ARG(){ echo $*; }
EXT(){ echo ${1##*.}; }
BASE(){ basename $1 .${1##*.}; }
LS(){ ls $* 2> /dev/null; }
LS1(){ for f in `LS $*`;do echo $f;done }
LS2(){ for e in $*;do LS *.$e;done }
OBJ(){ for f in $*;do echo `basename $f .${f##*.}`.o;done }
EXE(){ for f in $*;do echo `basename $f .${f##*.}`.exe;done }
MAIN(){ grep -sl "^.*[[:space:]]*main[[:space:]]*[^.[:alnum:]]" $*; }
RM(){ rm $* 2>/dev/null; }
CC(){ for f in $*;do echo $CC -c $f;$CC -c $f;done }
LD(){ echo $LD -o $*;$LD -o $*; }
AR(){ echo $AR rcs $*;$AR rcs $*; }
RUN(){ [ -f ./$1 ] && time ./$*; }
mode_gcc(){ echo "mode: gcc";CC=gcc;AR=ar;LD=g++; }
mode_tcc(){ echo "mode: tcc";CC=tcc;AR=tcc -ar;LD=tcc; }
mode_clang(){ echo "mode: clang";CC=clang; }
_init(){
mode_gcc
ext="c cpp"
src=`LS2 $ext`
obj=`OBJ $src`
main=`MAIN $src`
exe=`EXE $main`
files=`LS -t $src $obj $exe`
echo src: $src
echo obj: $obj
echo main: $main
echo exe: $exe
echo files orded by time: $files
}
_build(){ CC $src;LD $exe $obj; }
_run(){ RUN $exe; }
_build_run(){ _build;_run; }
_clean(){ RM $obj; }
_list(){ LS2 "c cpp cxx h hpp"; }
#HELP
while getopts "hf:c:l:x:m:" opt; do
case $opt in
h) HELP;;
f) F="$OPTARG";;
c) CFLAGS="$CFLAGS $OPTARG";;
l) LDFLAGS+="$OPTARG";;
x) X="$OPTARG";;
m) eval "mode_$OPTARG";;
?) echo "Invalid option: -$OPTARG";;
esac
#echo $opt: $OPTARG
done
shift $(($OPTIND - 1))
CMD=$1
shift
[ -z $CMD ] && CMD=_build_run
echo cmd: $CMD [$*]
_init
eval "$CMD"
其他
1
https://gitee.com/imbit_mathmhb/Makefile.git
git@gitee.com:imbit_mathmhb/Makefile.git
imbit_mathmhb
Makefile
Makefile
master

搜索帮助