1 #!/bin/bash
2
3 # Usage:
4 #
5 # build.sh Assemble, link
6 # build.sh gdb Assemble, link, and debug
7 # build.sh run Assemble, link, and run
8 # build.sh bytes Assemble, link, and run to count bytes
9
10 set -e # quit on errors
11
12 F=meow5
13
14 # assemble and link!
15 # -w+all turns on all warnings
16 # -g enables debugging symbols
17 # -f assembled output type
18 # -o output filename
19 nasm -w+all -g -f elf32 -o $F.o $F.asm
20 ld -m elf_i386 $F.o -o $F
21 rm $F.o
22
23 if [[ $1 == 'gdb' ]]
24 then
25 # -q - skips the verbiage at the beginning
26 gdb $F -q
27 exit
28 fi
29
30 if [[ $1 == 'run' ]]
31 then
32 ./$F
33 exit
34 fi
35
36 if [[ $1 == 'bytes' ]]
37 then
38 AWK='/^.*: [0-9]+/ {t=t+$2} END{print "Total bytes:", t}'
39 echo 'inspect_all' | ./$F | awk -e "$AWK"
40 exit
41 fi