script build
This commit is contained in:
parent
165ef2cf59
commit
437d33ecf3
1 changed files with 78 additions and 0 deletions
78
script/build
Executable file
78
script/build
Executable file
|
@ -0,0 +1,78 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Options...
|
||||
build_options='-g -f elf64'
|
||||
link_options=''
|
||||
clear_obj=1
|
||||
|
||||
# Usage...
|
||||
usage='Uso: build <arquivo|arquivo.asm>'
|
||||
|
||||
# Error strings...
|
||||
error[1]='Número incorreto de argumentos!'
|
||||
error[2]='Nome de arquivo inválido!'
|
||||
error[3]='Arquivo-fonte não encontrado!'
|
||||
error[4]='Erro de montagem!'
|
||||
error[5]='Erro de ligação!'
|
||||
|
||||
# Functions...
|
||||
|
||||
die() {
|
||||
printf '\n\e[31m%s\e[0m\n%s\n\n' "${error[$1]}" "$usage" >&2
|
||||
exit $1
|
||||
}
|
||||
|
||||
cprint() {
|
||||
printf '\e[32;1m%s\e[0m\n' "$*"
|
||||
}
|
||||
|
||||
iprint() {
|
||||
printf '\e[2;3m%b\e[0m' "$*"
|
||||
}
|
||||
|
||||
draw_line() {
|
||||
local line
|
||||
printf -v line '%40s'
|
||||
echo ${line// /-}
|
||||
}
|
||||
|
||||
# Check for file name...
|
||||
[[ $1 ]] || die 1
|
||||
|
||||
# Check for .asm extension...
|
||||
[[ $1 != *.* || $1 == *.asm ]] || die 2
|
||||
|
||||
# Main...
|
||||
|
||||
# Trim .asm extension...
|
||||
name=${1%.asm}
|
||||
|
||||
if [[ -f $name.asm ]]; then
|
||||
# Remove old executable...
|
||||
rm $name 2> /dev/null
|
||||
|
||||
draw_line
|
||||
printf '%s\e[35;1m%s\e[0m%s\n' 'Compilando ' $name.asm ':'
|
||||
draw_line
|
||||
|
||||
# Build object file...
|
||||
iprint '• Montando objeto binário... '
|
||||
nasm $build_options $name.asm && cprint ok || die 4
|
||||
|
||||
# Link executable file...
|
||||
iprint '• Ligando binário executável... '
|
||||
ld $link_options $name.o -o $name && cprint ok || die 5
|
||||
|
||||
# Remove object file...
|
||||
((clear_obj)) && { iprint '• Removendo arquivo objeto... '; rm $name.o && cprint ok; }
|
||||
|
||||
echo -n '• '
|
||||
iprint 'Sucesso!\n'
|
||||
|
||||
draw_line
|
||||
ls -lh ${name}* | awk '{printf "\033[36;1m%-'$((${#name}+4))'s\033[0m%8s%4s %02d%6s\n", $9, $5, $6, $7, $8 }'
|
||||
draw_line
|
||||
else
|
||||
die 3
|
||||
fi
|
||||
|
Loading…
Add table
Reference in a new issue