]> mj.ucw.cz Git - moe.git/blob - mop/public/compile
MO-P: mo-create-public
[moe.git] / mop / public / compile
1 #!/bin/bash
2 # Compile script for MO-P
3 # 2015 - Jan Hadrava <had@kam.mff.cuni.cz>
4
5 die() {
6         echo "$@" >&2
7         exit 1
8 }
9
10 [ -n "$1" ] || die "Usage:  compile <source-file> [<options>]"
11
12 if [ "${1%.*}" == "$1" ]; then
13         die "Source file must have suffix. Can not compile."
14 else
15         src="$1"
16         [ -f "$src" ] || die "File \"$src\" doesn't exist"
17         bin="${1%.*}"
18         ext="${1##*.}"
19
20         shift
21
22         cflags="$@"
23
24         case "$ext" in
25                 c)
26                         comm="gcc -static -DEVAL -O2 -std=gnu11 $cflags $src -o ${bin} -lm" ;;
27                 cpp)
28                         comm="g++ -static -DEVAL -O2 -std=gnu++11 $cflags $src -o ${bin}" ;;
29                 pas)
30                         comm="fpc $cflags -XS -dEVAL -O2 -o${bin} $src";;
31                 *)
32                         die "Unknown suffix \"$ext\"."
33         esac
34
35         echo -e '\e[0;32m'"Compiling..."'\e[0m' >&2
36         echo -e '\e[0;33m'"$comm"'\e[0m' >&2
37         $comm && echo -e '\e[0;32m'"Done."'\e[0m' >&2 || die -e '\e[0;31m'"Compilation failed!"'\e[0m'
38 fi