-
Notifications
You must be signed in to change notification settings - Fork 0
/
make
60 lines (49 loc) · 1.05 KB
/
make
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/bin/bash
# program to compile assembly program
# program also work for linking two file
# ASSERTIONS
# provided file are in the same directory as this file
# bin contains final executable files
# obj contains the object files
# check argc
if [ $# -lt 1 ]
then
echo "Usage: $0 <src> [file ...]"
exit 1
fi
#directories
readonly BIN="bin"
readonly OBJ="obj"
# parse files
read -ra files <<< ${@:1}
# parse names: filename without extensions
names=()
for file in ${files[@]}
do
IFS='.' read -ra parts <<< $file
names+=("${parts[0]}")
done
# for linking
object_files=()
# compile each to object file
for name in ${names[@]}
do
src_file="$name.asm"
obj_file="./$OBJ/$name.o"
object_files+=("$obj_file")
eval "nasm -f elf32 -o $obj_file $src_file"
if [ $? -ne 0 ]
then
echo "Failed to compile: $src_file"
exit 1
fi
done
# linking files
executable="./$BIN/${names[0]}"
eval "ld -m elf_i386 -o $executable ${object_files[@]}"
if [ $? -ne 0 ]
then
echo "Linking failed!"
exit 1
fi
eval "$executable"