1 #!/bin/bash
     
2 
     3 # Usage:
     
4 #
     
5 #   build.sh        Assemble, link
     
6 #   build.sh gdb    Assemble, link, and debug
     
7 #   build.sh test   Assemble, link, and test
     
8 #   build.sh run    Assemble, link, and run
     
9 
    10 set -e # quit on errors
    
11 
    12 F=nasmjf
    
13 
    14 # assemble and link! (-g enables debugging symbols)
    
15 nasm -f elf32 -g -o $F.o $F.asm
    
16 if [ $(uname -m | grep 64) ]; then
    
17   ld -m elf_i386 $F.o -s -o $F
    
18 else
    
19   ld $F.o -o $F
    
20 fi
    
21 rm $F.o
    
22 
    23 if [[ $1 == 'gdb' ]]
    
24 then
    
25     # -q         - skips the verbiage at the beginning
    
26     # --command  - debug it with a script to set everything up
    
27     gdb $F -q --command=gdb.script
    
28     exit
    
29 fi
    
30 
    31 if [[ $1 == 'test' ]]
    
32 then
    
33     ./test.sh
    
34     exit
    
35 fi
    
36 
    37 if [[ $1 == 'run' ]]
    
38 then
    
39     ./$F
    
40     exit
    
41 fi