# You should have received a copy of the GNU General Public License
# along with Mes. If not, see <http://www.gnu.org/licenses/>.
-set -x
+if [ -n "$BUILD_DEBUG" ]; then
+ set -x
+fi
export BLOOD_ELF GUILE HEX2 M1 MES MESCC
export M1FLAGS HEX2FLAGS PREPROCESS
-export MES_SEED MES_ARENA
HEX2=${HEX2-hex2}
M1=${M1-M1}
BLOOD_ELF=${BLOOD_ELF-blood-elf}
-MES_SEED=${MES_SEED-../mes-seed}
MESCC=${MESCC-$(command -v mescc)}
[ -z "$MESCC" ] && MESCC=scripts/mescc
MES=${MES-$(command -v mes)}
-I lib
-I include
"}
-
-MESCCLAGS=${MESCCFLAGS-"
-"}
-LIBC=${LIBC-lib/libc}
-M1FLAGS=${M1FLAGS-"
---LittleEndian
---Architecture=1
-"}
-HEX2FLAGS=${HEX2FLAGS-"
---LittleEndian
---Architecture=1
---BaseAddress=0x1000000
+MESCCFLAGS=${MESCCFLAGS-"
"}
+if [ -n "$BUILD_DEBUG" ]; then
+ MESCCFLAGS="$MESCCFLAGS -v"
+fi
+
c=$1
set -e
-if [ -n "$PREPROCESS" ]; then
- sh -x $MESCC\
- -E\
- $CPPFLAGS\
- $MESCCFLAGS\
- -o "$c".E\
- "$c".c
- sh -x $MESCC\
- -c\
- -o "$c".M1\
- "$c".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\
- $M1FLAGS\
- -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\
- $M1FLAGS\
- -f "$c".blood-elf-M1\
- -o "$c".blood-elf-hex2
- $HEX2\
- $HEX2FLAGS\
- -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