-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathautoCompile
More file actions
54 lines (45 loc) · 1.34 KB
/
autoCompile
File metadata and controls
54 lines (45 loc) · 1.34 KB
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
#!/bin/bash
#### DECLARACION DE METODOS
mensaje () {
echo ""
echo "-----------------------------------"
echo " $1"
echo "-----------------------------------"
}
#### DECLARACION DE METODOS
# esto hace que cuando tenga un error o algo detenga la ejecucion del script
set -e
# tomamos los argumentos y los setemaos a varialbes
PATH=$1
FILE_NAME=$2
# esto esta porque no es necesario compilar los que no son el main
if [ $FILE_NAME != 'main' ] && [ $FILE_NAME != 'Main' ] && [ $FILE_NAME != 'MAIN' ]; then
echo "Este archivo '$FILE_NAME' no se compila"
exit 0
fi
# nos movemos a la carpeta
cd $PATH
# si ya existe un .o es eliminado
if [ -f $FILE_NAME.o ]; then
/bin/rm $FILE_NAME.o
fi
# si ya existe un .sh es eliminado
if [ -f $FILE_NAME.sh ]; then
/bin/rm $FILE_NAME.sh
fi
# hacemos la compilacion de nasm
mensaje "Compilando con nasm"
/usr/bin/nasm -f elf $FILE_NAME.asm
mensaje "Compilado Correcto."
# hacemos una comparacion, si es valida es 64bits si no 32bits
if [ `/usr/bin/getconf LONG_BIT` == '64' ]; then
# compilacion para 64bits
mensaje "Compilando con ld 64bits"
/usr/bin/ld -m elf_i386 -s -o $FILE_NAME.sh $FILE_NAME.o
mensaje "Compilado Correcto."
else
# compilacion para 32bits
mensaje "Compilando con ld 32bits"
/usr/bin/ld -o $FILE_NAME.sh $FILE_NAME.o
mensaje "Compilado Correcto."
fi