# You should have received a copy of the GNU General Public License
# along with Mes. If not, see <http://www.gnu.org/licenses/>.
-set -ex
+if [ -n "$BUILD_DEBUG" ]; then
+ set -x
+fi
+
+export BLOOD_ELF GUILE HEX2 M1 MES MESCC
+export M1FLAGS HEX2FLAGS PREPROCESS
-export HEX2=${HEX2-hex2}
-export M1=${M1-M1}
-export BLOOD_ELF=${BLOOD_ELF-blood-elf}
-export MES_SEED=${MES_SEED-../mes-seed}
-export MESCC=${MESCC-$(type -p mescc)}
+HEX2=${HEX2-hex2}
+M1=${M1-M1}
+BLOOD_ELF=${BLOOD_ELF-blood-elf}
+MESCC=${MESCC-$(command -v mescc)}
[ -z "$MESCC" ] && MESCC=scripts/mescc
-export MES=${MES-$(type -p mes)}
+MES=${MES-$(command -v mes)}
[ -z "$MES" ] && MES=src/mes
CPPFLAGS=${CPPFLAGS-"
-I lib
-I include
"}
-
-MESCCLAGS=${MESCCFLAGS-"
+MESCCFLAGS=${MESCCFLAGS-"
"}
-LIBC=${LIBC-lib/libc}
+
+if [ -n "$BUILD_DEBUG" ]; then
+ MESCCFLAGS="$MESCCFLAGS -v"
+fi
c=$1
-if [ -n "$PREPROCESS" ]; then
- sh -x $MESCC\
- -E\
- $CPPFLAGS\
- $MESCCFLAGS\
- -o "$c".E\
- "$c".c
- sh -x $MESCC\
- -c\
- -o "$c".M1\
- "$c".E
+set -e
+
+if [ -z "$ARCHDIR" ]; then
+ o="$c"
+ p="mes-"
else
- sh -x $MESCC\
- -c\
- $CPPFLAGS\
- $MESCCFLAGS\
- -o "$c".M1\
- "$c".c
+ b=${c##*/}
+ d=${c%/*}
+ o="$d/x86-mes/$b"
+ mkdir -p $d/x86-mes
fi
-$M1 --LittleEndian --Architecture=1\
- -f stage0/x86.M1\
- -f "$c".M1\
- -o "$c".hex2
-
-if [ -z "$NOLINK" ]; then
- $BLOOD_ELF\
- -f stage0/x86.M1\
- -f "$c".M1\
- -f $LIBC-mes.M1\
- -o "$c".blood-elf-M1
- $M1 --LittleEndian --Architecture=1\
- -f "$c".blood-elf-M1\
- -o "$c".blood-elf-hex2
- $HEX2 --LittleEndian --Architecture=1 --BaseAddress=0x1000000\
- -f stage0/elf32-header.hex2\
- -f lib/crt1.hex2\
- -f $LIBC-mes.hex2\
- -f "$c".hex2\
- -f "$c".blood-elf-hex2\
- --exec_enable\
- -o "$c".mes-out
+if [ -n "$PREPROCESS" ]; then
+ bash $MESCC $MESCCFLAGS $CPPFLAGS -E -o "$o.E" "$c".c
+ bash $MESCC $MESCCFLAGS -S "$o".E
+ bash $MESCC $MESCCFLAGS -c -o "$o".${p}o "$o".S
+ if [ -z "$NOLINK" ]; then
+ bash $MESCC $MESCCFLAGS -o "$o".${p}out "$o".${p}o $MESCCLIBS
+ fi
+elif [ -n "$COMPILE" ]; then
+ bash $MESCC $MESCCFLAGS $CPPFLAGS -S -o "$o.S" "$c".c
+ bash $MESCC $MESCCFLAGS -c -o "$o".${p}o "$o".S
+ if [ -z "$NOLINK" ]; then
+ bash $MESCC $MESCCFLAGS -o "$o".${p}out "$o".${p}o $MESCCLIBS
+ fi
+elif [ -z "$NOLINK" ]; then
+ bash $MESCC $MESCCFLAGS $CPPFLAGS -o "$o".${p}out "$c".c $MESCCLIBS
+else
+ bash $MESCC $MESCCFLAGS $CPPFLAGS -c -o "$o".${p}o "$c".c
fi