Skip to content
Find file
Fetching contributors…
Cannot retrieve contributors at this time
executable file 59 lines (49 sloc) 1.16 KB
#!/bin/bash
INPUT="$1"
OUTPUT="$2"
if [ $# != 2 ]; then
echo "Usage: ./compile input_file output_file"
else
# Perform some sanity checks
#if [ ! -e "libmalice.asm" ]; then
# echo "Error: libmalice.asm not found."
# exit 1
#fi
if [ ! -e "$INPUT" ]; then
echo "Could not find source file $INPUT."
exit 1
fi
# Assemble the support library
# Now done in the Makefile
#nasm -f elf "libmalice.asm"
#if [ $? != 0 ]; then
# echo "Error: Failed to assemble libmalice."
#fi
# Compile the MAlice program
./malice2asm "$INPUT" "$OUTPUT"
if [ $? != 0 ]; then
echo "Error: Failed to compile the program."
exit 2
fi
# Another sanity check
if [ ! -e "$OUTPUT.asm" ]; then
echo "Error: The compiler succeeded but there is no .asm file!?"
exit 2
fi
# Assemble the MAlice program
nasm -f elf "$OUTPUT.asm"
if [ $? != 0 ]; then
echo "Error: Failed to assemble the program."
exit 3
fi
# Link the program
ld -o "$OUTPUT" "$OUTPUT.o" libmalice.o -lc --dynamic-linker=/lib/ld-linux.so.2 -melf_i386
if [ $? != 0 ]; then
echo "Error: Failed to link the program."
exit 4
fi
# echo "Done."
# Clean up
rm -f "$OUTPUT.o"
# rm -f "$OUTPUT.asm"
fi
Something went wrong with that request. Please try again.