summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoakim Sindholt <opensource@zhasha.com>2017-03-06 22:00:06 +0100
committerJoakim Sindholt <opensource@zhasha.com>2017-03-06 22:00:06 +0100
commit81fef56d35e86d374b2ff8ea1be2f3ff5aa774c2 (patch)
tree15b35bdd54ddfc43a0cc0bfadb53c1cb3daaf53b
parentaeb1cbba8469786403708b1f049685baeb247ef9 (diff)
make scripts less god awful
-rwxr-xr-xbin/0a4
-rwxr-xr-xbin/0c4
-rwxr-xr-xbin/0l4
-rwxr-xr-xbin/5a4
-rwxr-xr-xbin/5c4
-rwxr-xr-xbin/5l4
-rwxr-xr-xbin/6a4
-rwxr-xr-xbin/6c4
-rwxr-xr-xbin/6l4
-rwxr-xr-xbin/8a4
-rwxr-xr-xbin/8c4
-rwxr-xr-xbin/8l4
-rwxr-xr-xbin/9a4
-rwxr-xr-xbin/9c4
-rwxr-xr-xbin/9l4
-rw-r--r--bin/arch.sh23
-rw-r--r--bin/build-libc.sh76
-rwxr-xr-xbin/ka4
-rwxr-xr-xbin/kc4
-rwxr-xr-xbin/kl4
-rw-r--r--bin/p9a.sh60
-rw-r--r--bin/p9c.sh204
-rw-r--r--bin/p9l.sh246
-rwxr-xr-xbin/qa4
-rwxr-xr-xbin/qc4
-rwxr-xr-xbin/ql4
-rwxr-xr-xbin/va4
-rwxr-xr-xbin/vc4
-rwxr-xr-xbin/vl4
29 files changed, 337 insertions, 368 deletions
diff --git a/bin/0a b/bin/0a
index 08b342b..db89c14 100755
--- a/bin/0a
+++ b/bin/0a
@@ -1,2 +1,4 @@
#!/bin/bash
-objtype=spim source "$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )/p9a.sh"
+DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
+objtype=spim
+. "$DIR/p9a.sh"
diff --git a/bin/0c b/bin/0c
index 9688e05..1e4607b 100755
--- a/bin/0c
+++ b/bin/0c
@@ -1,2 +1,4 @@
#!/bin/bash
-objtype=spim source "$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )/p9c.sh"
+DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
+objtype=spim
+. "$DIR/p9c.sh"
diff --git a/bin/0l b/bin/0l
index a8c6828..657bea0 100755
--- a/bin/0l
+++ b/bin/0l
@@ -1,2 +1,4 @@
#!/bin/bash
-objtype=spim source "$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )/p9l.sh"
+DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
+objtype=spim
+. "$DIR/p9l.sh"
diff --git a/bin/5a b/bin/5a
index 4f6fcd7..3096101 100755
--- a/bin/5a
+++ b/bin/5a
@@ -1,2 +1,4 @@
#!/bin/bash
-objtype=arm source "$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )/p9a.sh"
+DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
+objtype=arm
+. "$DIR/p9a.sh"
diff --git a/bin/5c b/bin/5c
index 9e472c2..ef168dc 100755
--- a/bin/5c
+++ b/bin/5c
@@ -1,2 +1,4 @@
#!/bin/bash
-objtype=arm source "$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )/p9c.sh"
+DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
+objtype=arm
+. "$DIR/p9c.sh"
diff --git a/bin/5l b/bin/5l
index 4b577f9..099d237 100755
--- a/bin/5l
+++ b/bin/5l
@@ -1,2 +1,4 @@
#!/bin/bash
-objtype=arm source "$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )/p9l.sh"
+DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
+objtype=arm
+. "$DIR/p9l.sh"
diff --git a/bin/6a b/bin/6a
index 94dc94a..de9b810 100755
--- a/bin/6a
+++ b/bin/6a
@@ -1,2 +1,4 @@
#!/bin/bash
-objtype=amd64 source "$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )/p9a.sh"
+DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
+objtype=amd64
+. "$DIR/p9a.sh"
diff --git a/bin/6c b/bin/6c
index f5ab5d4..5433529 100755
--- a/bin/6c
+++ b/bin/6c
@@ -1,2 +1,4 @@
#!/bin/bash
-objtype=amd64 source "$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )/p9c.sh"
+DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
+objtype=amd64
+. "$DIR/p9c.sh"
diff --git a/bin/6l b/bin/6l
index dc57340..a93032a 100755
--- a/bin/6l
+++ b/bin/6l
@@ -1,2 +1,4 @@
#!/bin/bash
-objtype=amd64 source "$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )/p9l.sh"
+DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
+objtype=amd64
+. "$DIR/p9l.sh"
diff --git a/bin/8a b/bin/8a
index 6df46c5..847b251 100755
--- a/bin/8a
+++ b/bin/8a
@@ -1,2 +1,4 @@
#!/bin/bash
-objtype=386 source "$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )/p9a.sh"
+DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
+objtype=386
+. "$DIR/p9a.sh"
diff --git a/bin/8c b/bin/8c
index 6f44b45..45c5373 100755
--- a/bin/8c
+++ b/bin/8c
@@ -1,2 +1,4 @@
#!/bin/bash
-objtype=386 source "$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )/p9c.sh"
+DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
+objtype=386
+. "$DIR/p9c.sh"
diff --git a/bin/8l b/bin/8l
index 1a7c740..9f4d54c 100755
--- a/bin/8l
+++ b/bin/8l
@@ -1,2 +1,4 @@
#!/bin/bash
-objtype=386 source "$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )/p9l.sh"
+DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
+objtype=386
+. "$DIR/p9l.sh"
diff --git a/bin/9a b/bin/9a
index 3590d4f..46dd42a 100755
--- a/bin/9a
+++ b/bin/9a
@@ -1,2 +1,4 @@
#!/bin/bash
-objtype=power64 source "$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )/p9a.sh"
+DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
+objtype=power64
+. "$DIR/p9a.sh"
diff --git a/bin/9c b/bin/9c
index 2503b6b..82ee524 100755
--- a/bin/9c
+++ b/bin/9c
@@ -1,2 +1,4 @@
#!/bin/bash
-objtype=power64 source "$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )/p9c.sh"
+DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
+objtype=power64
+. "$DIR/p9c.sh"
diff --git a/bin/9l b/bin/9l
index ec2f729..1edc701 100755
--- a/bin/9l
+++ b/bin/9l
@@ -1,2 +1,4 @@
#!/bin/bash
-objtype=power64 source "$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )/p9l.sh"
+DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
+objtype=power64
+. "$DIR/p9l.sh"
diff --git a/bin/arch.sh b/bin/arch.sh
index 8fb22a5..0e0d0f6 100644
--- a/bin/arch.sh
+++ b/bin/arch.sh
@@ -1,15 +1,16 @@
#!/bin/bash
case "$objtype" in
- spim) O=0; MARCH="mipsel" CLANGARCH="mipsel-none-gnu" ;;
- arm) O=5; MARCH="armv7a" CLANGARCH="armv7a-none-eabihf" ;;
- amd64) O=6; MARCH="generic" CLANGARCH="x86_64-pc-gnu" ;;
- 386) O=8; MARCH="i686" CLANGARCH="i686-pc-gnu" ;;
- power64) O=9; MARCH="ppc64" CLANGARCH="ppc64-none-gnu" ;;
- sparc) O=k; MARCH="sparc" CLANGARCH="sparc-none-gnu" ;;
- power) O=q; MARCH="ppc" CLANGARCH="powerpc-ellcc-gnu" ;;
- mips) O=v; MARCH="mips" CLANGARCH="mips-none-gnu" ;;
- *)
- echo "unknown object type ${objtype}"
- exit 1
+spim) O=0; MARCH="mipsel"; CLANGARCH="mipsel-none-gnu" ;;
+arm) O=5; MARCH="armv7a"; CLANGARCH="armv7a-none-eabihf" ;;
+amd64) O=6; MARCH="generic"; CLANGARCH="x86_64-pc-gnu" ;;
+386) O=8; MARCH="i686"; CLANGARCH="i686-pc-gnu" ;;
+power64) O=9; MARCH="ppc64"; CLANGARCH="ppc64-none-gnu" ;;
+sparc) O=k; MARCH="sparc"; CLANGARCH="sparc-none-gnu" ;;
+power) O=q; MARCH="ppc"; CLANGARCH="powerpc-ellcc-gnu" ;;
+mips) O=v; MARCH="mips"; CLANGARCH="mips-none-gnu" ;;
+*)
+ echo "unknown object type $objtype" >&2
+ exit 1
+ ;;
esac
diff --git a/bin/build-libc.sh b/bin/build-libc.sh
index 02ddee9..079a9e5 100644
--- a/bin/build-libc.sh
+++ b/bin/build-libc.sh
@@ -1,23 +1,17 @@
#!/bin/bash
-DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
-
-source "${DIR}/arch.sh"
-
case "$(uname -s)" in
Linux)
- SRCDIR="${DIR}/../src"
- OBJDIR="${DIR}/../${objtype}"
+ DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
+ SRCDIR="$DIR/../src"
+ OBJDIR="$DIR/../$objtype"
- COMPILERRTREV=$(cd "${SRCDIR}/compiler-rt" && git rev-parse --verify HEAD)
- MUSLREV=$(cd "${SRCDIR}/musl" && git rev-parse --verify HEAD)
- if [[ -e "${OBJDIR}/compiler-rt-revision" &&
- -e "${OBJDIR}/musl-revision" ]]
- then
- if [[ "$(cat "${OBJDIR}/compiler-rt-revision")" == "$COMPILERRTREV" &&
- "$(cat "${OBJDIR}/musl-revision")" == "$MUSLREV" ]]
- then
- exit 0
- fi
+ COMPILERRTREV=$(cd "$SRCDIR/compiler-rt" && git rev-parse --verify HEAD)
+ MUSLREV=$(cd "$SRCDIR/musl" && git rev-parse --verify HEAD)
+ if [[ -f "$OBJDIR/compiler-rt-revision" &&
+ -f "$OBJDIR/musl-revision" &&
+ "$(cat "$OBJDIR/compiler-rt-revision")" == "$COMPILERRTREV" &&
+ "$(cat "$OBJDIR/musl-revision")" == "$MUSLREV" ]]; then
+ exit 0
fi
case "$objtype" in
@@ -32,51 +26,51 @@ Linux)
*) MUSLARCH="" ;;
esac
- if [ "$MUSLARCH" == "" ]
- then
- exit 1;
+ if [[ "$MUSLARCH" == "" ]]; then
+ echo "unsupported object type $objtype" >&2
+ exit 1
fi
(
flock -x 200
- NCPU=$(cat /proc/cpuinfo | grep processor | wc -l)
- let NJOBS=${NCPU}*2
+ NCPU=$(($(cat /proc/cpuinfo | grep processor | wc -l) * 2))
- if [[ ! -e "${OBJDIR}/musl-revision" ||
- "$(cat "${OBJDIR}/musl-revision")" != "$MUSLREV" ]]
- then
- cd "${SRCDIR}/musl" && \
- make distclean ARCH=bug && \
- CC="clang --target=${CLANGARCH} -integrated-as" \
+ if [[ ! -e "$OBJDIR/musl-revision" ||
+ "$(cat "$OBJDIR/musl-revision")" != "$MUSLREV" ]]; then
+ . "$DIR/arch.sh"
+ cd "$SRCDIR/musl" && \
+ make distclean && \
+ CC="clang --target=$CLANGARCH -integrated-as" \
CFLAGS="-ggdb3 -Os -pipe -fPIE -ftls-model=local-exec -fomit-frame-pointer -fstack-protector-strong" \
- GNUTARGET="${CLANGARCH}" ./configure \
- --target="${MUSLARCH}" \
- --prefix="${OBJDIR}" \
+ GNUTARGET="$CLANGARCH" ./configure \
+ --target="$MUSLARCH" \
+ --build="$MUSLARCH" \
+ --prefix="$OBJDIR" \
--disable-shared \
--disable-gcc-wrapper \
--enable-visibility && \
echo 'obj/src/stdio/vfprintf.o obj/src/stdio/vfprintf.lo: CFLAGS += -fno-inline' >> config.mak && \
- make -j${NJOBS} && \
+ make -j$NJOBS && \
make install && \
- echo "${MUSLREV}" > "${OBJDIR}/musl-revision"
- if [ ! $? -eq 0 ]; then exit 2; fi
+ echo "$MUSLREV" > "$OBJDIR/musl-revision" || exit 2
- make distclean ARCH=bug
+ make distclean
fi
if [[ ! -e "$OBJDIR/compiler-rt-revision" ||
- "$(cat "$OBJDIR/compiler-rt-revision")" != "$COMPILERRTREV" ]]
- then
- make -C "${SRCDIR}" -f compiler-rt.mk -j${NJOBS} install &&
- echo "$COMPILERRTREV" > "$OBJDIR/compiler-rt-revision"
- if [ ! $? -eq 0 ]; then exit 2; fi
+ "$(cat "$OBJDIR/compiler-rt-revision")" != "$COMPILERRTREV" ]]; then
+ cd "$SRCDIR" &&
+ make -f compiler-rt.mk clean &&
+ make -f compiler-rt.mk -j$NJOBS &&
+ make -f compiler-rt.mk install &&
+ echo "$COMPILERRTREV" > "$OBJDIR/compiler-rt-revision" || exit 2
- make -C "${SRCDIR}" -f compiler-rt.mk clean
+ make -f compiler-rt.mk clean
fi
exit 0
- ) 200>"${SRCDIR}/build-lock"
+ ) 200>"$SRCDIR/build-lock"
exit $?
;;
*)
diff --git a/bin/ka b/bin/ka
index e7ed236..de22967 100755
--- a/bin/ka
+++ b/bin/ka
@@ -1,2 +1,4 @@
#!/bin/bash
-objtype=sparc source "$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )/p9a.sh"
+DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
+objtype=sparc
+. "$DIR/p9a.sh"
diff --git a/bin/kc b/bin/kc
index 5883d41..f39d347 100755
--- a/bin/kc
+++ b/bin/kc
@@ -1,2 +1,4 @@
#!/bin/bash
-objtype=sparc source "$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )/p9c.sh"
+DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
+objtype=sparc
+. "$DIR/p9c.sh"
diff --git a/bin/kl b/bin/kl
index bf46ad9..6786ef2 100755
--- a/bin/kl
+++ b/bin/kl
@@ -1,2 +1,4 @@
#!/bin/bash
-objtype=sparc source "$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )/p9l.sh"
+DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
+objtype=sparc
+. "$DIR/p9l.sh"
diff --git a/bin/p9a.sh b/bin/p9a.sh
index 726840a..38d0aa9 100644
--- a/bin/p9a.sh
+++ b/bin/p9a.sh
@@ -1,11 +1,8 @@
#!/bin/bash
-DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
-
-source "${DIR}/arch.sh"
+. "$DIR/arch.sh"
USE_RENAME=true
-FILES=()
OPTS=()
while getopts :o:D:I: opt
@@ -13,9 +10,8 @@ do
case "$opt" in
o)
# output file
- if [ $USE_RENAME == false ]
- then
- echo "${O}a: cannot specify -o more than once."
+ if [[ $USE_RENAME == false ]]; then
+ echo "${O}a: cannot specify -o more than once." >&2
exit 1
fi
@@ -37,54 +33,38 @@ do
;;
esac
done
+shift $(($OPTIND - 1))
case "$objtype" in
- amd64 | 386)
- # intel asm syntax for intel processors
- OPTS+=("-mllvm" "--x86-asm-syntax=intel")
- ;;
+amd64 | 386)
+ # intel asm syntax for intel processors
+ OPTS+=("-mllvm" "--x86-asm-syntax=intel")
+ ;;
esac
-shift $(($OPTIND - 1))
-# mark the rest as files
-while [ "$1" != "" ]
-do
- FILES+=("$1")
- shift
-done
-
# do some error checking
-if [ ${#FILES[@]} -eq 0 ]
-then
- echo "${O}a: no source files given."
+if [[ $# -eq 0 ]]; then
+ echo "${O}a: no source files given." >&2
exit 1
-elif [[ ${#FILES[@]} -gt 1 && $USE_RENAME == false ]]
-then
- echo "${O}a: cannot use -o with multiple files."
+elif [[ $# -gt 1 && $USE_RENAME == false ]]; then
+ echo "${O}a: cannot use -o with multiple files." >&2
exit 1
fi
-for f in ${FILES[@]}
-do
+for f in "$@"; do
RNOPTS=()
- if [ $USE_RENAME == true ]
- then
+ if [[ $USE_RENAME == true ]]; then
# check that we only got .s files
- bn=$(basename "${f}")
- if [ "${bn##*.}" != "s" ]
- then
- echo "${O}a: only .s files are allowed."
+ if [[ "${f##*.}" != "s" ]]; then
+ echo "${O}a: only .s files are allowed." >&2
exit 1
fi
- obj=$(echo "${f}" | sed -e"s/\.s$/\.$O/")
-
- RNOPTS=("-o" "${obj}")
+ RNOPTS=("-o" "${f%.*}.$O")
fi
clang \
- -target "${CLANGARCH}" -integrated-as \
+ -target "$CLANGARCH" -integrated-as \
-nostdinc -ggdb3 -fPIE -ftls-model=local-exec -Wa,--noexecstack \
- -include "${DIR}/../src/assembly.h" \
- "${OPTS[@]}" "${RNOPTS[@]}" -c -x assembler-with-cpp "${f}"
- if [ $? -ne 0 ]; then exit 1; fi
+ -include "$DIR/../src/assembly.h" \
+ "${OPTS[@]}" "${RNOPTS[@]}" -c -x assembler-with-cpp "$f" || exit 1
done
diff --git a/bin/p9c.sh b/bin/p9c.sh
index c940185..19210f3 100644
--- a/bin/p9c.sh
+++ b/bin/p9c.sh
@@ -1,157 +1,133 @@
#!/bin/bash
-DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
-
-source "${DIR}/arch.sh"
-
-bash "${DIR}/build-libc.sh" &> /dev/null
-if [ ! $? -eq 0 ]
-then
- echo "${O}c: ${objtype} is not supported"
+if ! bash "$DIR/build-libc.sh" &>/dev/null; then
+ echo "${O}c: $objtype is not supported" >&2
exit 1
fi
+. "$DIR/arch.sh"
+
USE_RENAME=true
USE_MISSINGPROTO=true
USE_OPTIMIZATION=true
USE_ASM=false
USE_LTO=false
-FILES=()
OPTS=()
-while getopts :o:wBD:FI:.NSTVpa opt
-do
+while getopts :o:wBD:FI:.NSTVpa opt; do
case "$opt" in
- o)
- # output file
- if [ $USE_RENAME == false ]
- then
- echo "${O}c: cannot specify -o more than once."
- exit 1
- fi
-
- OPTS+=("-o" "$OPTARG")
- USE_RENAME=false
- ;;
- w)
- # Print warning messages about unused variables, etc.
- OPTS+=("-Wall" "-Wextra" "-Wconversion" "-Wformat-security")
- ;;
- B)
- # Allow functions without prototypes
- USE_MISSINGPROTO=false
- ;;
- D)
- # Define a macro
- OPTS+=("-D$OPTARG")
- ;;
- F)
- # check format strings
- OPTS+=("-Wformat=2")
- ;;
- I)
- # include dir
- OPTS+=("-I$OPTARG")
- ;;
- .)
- # not handled
- ;;
- N)
- USE_OPTIMIZATION=false
- USE_LTO=false
- ;;
- S)
- OPTS+=("-S")
- USE_ASM=true
- ;;
- T)
- # not handled
- ;;
- V)
- OPTS+=("-pedantic")
- ;;
- p)
- # not handled
- ;;
- a|n)
- echo "${O}c: -a and -n are not supported."
+ o)
+ # output file
+ if [[ $USE_RENAME == false ]]; then
+ echo "${O}c: cannot specify -o more than once." >&2
exit 1
- ;;
- *)
- # unknown arg
- echo "${O}c: unknown argument -$OPTARG" >&2
- exit 1
- ;;
+ fi
+
+ OPTS+=("-o" "$OPTARG")
+ USE_RENAME=false
+ ;;
+ w)
+ # Print warning messages about unused variables, etc.
+ OPTS+=("-Wall" "-Wextra" "-Wconversion" "-Wformat-security")
+ ;;
+ B)
+ # Allow functions without prototypes
+ USE_MISSINGPROTO=false
+ ;;
+ D)
+ # Define a macro
+ OPTS+=("-D$OPTARG")
+ ;;
+ F)
+ # check format strings
+ OPTS+=("-Wformat=2")
+ ;;
+ I)
+ # include dir
+ OPTS+=("-I$OPTARG")
+ ;;
+ .)
+ # not handled
+ ;;
+ N)
+ USE_OPTIMIZATION=false
+ USE_LTO=false
+ ;;
+ S)
+ OPTS+=("-S")
+ USE_ASM=true
+ ;;
+ T)
+ # not handled
+ ;;
+ V)
+ OPTS+=("-pedantic")
+ ;;
+ p)
+ # not handled
+ ;;
+ a|n)
+ echo "${O}c: -a and -n are not supported." >&2
+ exit 1
+ ;;
+ *)
+ # unknown arg
+ echo "${O}c: unknown argument -$OPTARG" >&2
+ exit 1
+ ;;
esac
done
+shift $(($OPTIND - 1))
# missing prototypes
-if [ $USE_MISSINGPROTO == true ]
-then
+if [[ $USE_MISSINGPROTO == true ]]; then
OPTS+=("-Wmissing-prototypes")
fi
# optimization level
-if [ $USE_OPTIMIZATION == true ]
-then
+if [[ $USE_OPTIMIZATION == true ]]; then
OPTS+=("-Os")
else
OPTS+=("-O0")
fi
# asm syntax
case "$objtype" in
- amd64 | 386)
- # intel asm syntax for intel processors
- OPTS+=("-mllvm" "--x86-asm-syntax=intel")
- ;;
+amd64|386)
+ # intel asm syntax for intel processors
+ OPTS+=("-mllvm" "--x86-asm-syntax=intel")
+ ;;
esac
# asm-dependent options
-if [ $USE_ASM == false ]
-then
+if [[ $USE_ASM == false ]]; then
# don't spam debug info on -S
OPTS+=("-ggdb3")
# use LTO
- if [ $USE_LTO == true ]
- then
+ if [[ $USE_LTO == true ]]; then
OPTS+=("-flto")
fi
fi
-shift $(($OPTIND - 1))
-# mark the rest as files
-while [ "$1" != "" ]
-do
- FILES+=("$1")
- shift
-done
-
# do some error checking
-if [ ${#FILES[@]} -eq 0 ]
-then
- echo "${O}c: no source files given."
+if [[ $# -eq 0 ]]; then
+ echo "${O}c: no source files given." >&2
exit 1
-elif [[ ${#FILES[@]} -gt 1 && $USE_RENAME == false ]]
-then
- echo "${O}c: cannot use -o with multiple files."
+elif [[ $# -gt 1 && $USE_RENAME == false ]]; then
+ echo "${O}c: cannot use -o with multiple files." >&2
exit 1
fi
-for f in ${FILES[@]}
-do
+for f in "$@"; do
RNOPTS=()
- if [ $USE_RENAME == true ]
- then
+ if [[ $USE_RENAME == true ]]; then
# check that we only got C files
- bn=$(basename "$f")
- if [ "${bn##*.}" != "c" ]
- then
- echo "${O}c: only .c files are allowed."
+ if [[ "${f##*.}" != "c" ]]; then
+ echo "${O}c: only .c files are allowed." >&2
exit 1
fi
- obj=$(echo "$f" | sed -e"s/\.c$/\.$O/")
- if [ $USE_ASM == true ]; then obj="-"; fi
+ obj="${f%.*}.$O"
+ if [[ $USE_ASM == true ]]; then obj="-"; fi
# add output option
- RNOPTS+=("-o" "${obj}")
+ RNOPTS+=("-o" "$obj")
fi
clang \
@@ -161,15 +137,15 @@ do
-fno-unwind-tables -fno-asynchronous-unwind-tables \
-fomit-frame-pointer \
-fstack-protector-strong \
+ -fno-trigraphs -Wno-trigraphs \
-nostdlibinc \
- -isystem "${DIR}/../src/fortify-headers/include" \
- -isystem "${DIR}/../${objtype}/include" \
- -I "${DIR}/../include" \
+ -isystem "$DIR/../src/fortify-headers/include" \
+ -isystem "$DIR/../$objtype/include" \
+ -I "$DIR/../include" \
-idirafter "/usr/include" \
- -include "${DIR}/../src/visibility.h" \
+ -include "$DIR/../src/visibility.h" \
-Werror=declaration-after-statement \
-D_POSIX_SOURCE=1 -D_POSIX_C_SOURCE=200809L -D_BSD_SOURCE \
- -D_XOPEN_SOURCE -D_FORTIFY_SOURCE=1 \
- "${OPTS[@]}" "${RNOPTS[@]}" -c "${f}"
- if [ $? -ne 0 ]; then exit 1; fi
+ -D_XOPEN_SOURCE=700 -D_FORTIFY_SOURCE=1 \
+ "${OPTS[@]}" "${RNOPTS[@]}" -c "$f" || exit 1
done
diff --git a/bin/p9l.sh b/bin/p9l.sh
index 8f03f9a..2f04f98 100644
--- a/bin/p9l.sh
+++ b/bin/p9l.sh
@@ -1,197 +1,167 @@
#!/bin/bash
-DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
-
-source "${DIR}/arch.sh"
-
-bash "${DIR}/build-libc.sh" &> /dev/null
-if [ ! $? -eq 0 ]
-then
- echo "${O}c: ${objtype} is not supported"
+if ! bash "$DIR/build-libc.sh" &>/dev/null; then
+ echo "${O}l: $objtype is not supported" >&2
exit 1
fi
-OUTPUT_NAME="${O}.out"
+. "$DIR/arch.sh"
+
+OUTPUT_NAME="$O.out"
START_SYM="_start"
STRIP_FLAG=""
USE_LTO=false
-FILES=()
FARGS=()
OPTS=()
LIBS=()
-while getopts :l:o:psavNME:x:u:H:T:D:R:L: opt
-do
+while getopts :l:o:psavNME:x:u:H:T:D:R:L: opt; do
case "$opt" in
- l)
- # repurposed for dynamic linking
- LIBS+=("-l$OPTARG")
- ;;
- o)
- # output file
- OUTPUT_NAME="$OPTARG"
- ;;
- p)
- # insert profiling code (not implemented)
- ;;
- s)
- # strip symbol tabels
- STRIP_FLAG="-s"
- ;;
- a)
- # print assembly
- echo "${O}l: -a not implemented."
- exit 1
- ;;
- v)
- # print debug output (not implemented)
- ;;
- N)
- # (our own) disable optimization
- USE_LTO=false
- ;;
- M)
- # see docs (not implemented)
- ;;
- E)
- START_SYM="$OPTARG"
- ;;
- x)
- # write export table (not implemented)
- ;;
- u)
- # write export table and dynamic something (not implemented)
- ;;
- H)
- # gracefully
- ;;
- T)
- # ignore
- ;;
- D)
- # all
- ;;
- R)
- # these
- ;;
- L)
- # link dir
- OPTS+=("-L$OPTARG")
- ;;
- *)
- # unknown arg
- echo "${O}l: unknown argument -$OPTARG" >&2
- exit 1
- ;;
+ l)
+ # repurposed for dynamic linking
+ LIBS+=("-l$OPTARG")
+ ;;
+ o)
+ # output file
+ OUTPUT_NAME="$OPTARG"
+ ;;
+ p)
+ # insert profiling code (not implemented)
+ ;;
+ s)
+ # strip symbol tabels
+ STRIP_FLAG="-s"
+ ;;
+ a)
+ # print assembly
+ echo "${O}l: -a not implemented." >&2
+ exit 1
+ ;;
+ v)
+ # print debug output (not implemented)
+ ;;
+ N)
+ # (our own) disable optimization
+ USE_LTO=false
+ ;;
+ M)
+ # see docs (not implemented)
+ ;;
+ E)
+ START_SYM="$OPTARG"
+ ;;
+ x)
+ # write export table (not implemented)
+ ;;
+ u)
+ # write export table and dynamic something (not implemented)
+ ;;
+ H)
+ # gracefully
+ ;;
+ T)
+ # ignore
+ ;;
+ D)
+ # all
+ ;;
+ R)
+ # these
+ ;;
+ L)
+ # link dir
+ OPTS+=("-L$OPTARG")
+ ;;
+ *)
+ # unknown arg
+ echo "${O}l: unknown argument -$OPTARG" >&2
+ exit 1
+ ;;
esac
done
-
shift $(($OPTIND - 1))
-# mark the rest as files
-while [ "$1" != "" ]
-do
- FILES+=("$1")
- shift
-done
# do some error checking
-if [ ${#FILES[@]} -eq 0 ]
-then
- echo "${O}l: no source files given."
+if [[ $# -eq 0 ]]; then
+ echo "${O}l: no source files given." >&2
exit 1
else
# check that we only got .$O and .a files
- for f in ${FILES[@]}
- do
- FILEBASE=$(basename "$f")
- if [[ "${FILEBASE##*.}" != "$O" &&
- "${FILEBASE##*.}" != "a" ]]
+ for f in "$@"; do
+ if [[ "${f##*.}" != "$O" &&
+ "${f##*.}" != "a" ]]
then
- echo "${O}l: only .$O and .a files are allowed."
+ echo "${O}l: only .$O and .a files are allowed." >&2
exit 1
fi
- #FARGS[${#FARGS[@]}]='-x'
- #if [ "${FILEBASE##*.}" == "$O" ]
- #then
- # FARGS[${#FARGS[@]}]='ir'
+ #if [[ "${f##*.}" == "$O" ]]; then
+ # FARGS+=("-x" "ir")
#else
- # FARGS[${#FARGS[@]}]='none'
+ # FARGS+=("-x" "none")
#fi
FARGS+=("$f")
done
fi
autolinks() {
- for f in ${FILES[@]}
- do
- nm "$f" 2>/dev/null | grep '__p9l_autolink_' | while read ln
- do
- echo "$ln" | sed -e's/^.*\s\+__p9l_autolink_\(.\+\)$/\1/'
+ for f in "$@"; do
+ nm "$f" 2>/dev/null | grep '__p9l_autolink_' | while read ln; do
+ echo "${ln##*__p9l_autolink_}"
done
done
}
-LIBDIR="${DIR}/../${objtype}/lib"
+LIBDIR="$DIR/../$objtype/lib"
-for ln in $(autolinks | sort | uniq)
-do
+saveifs="$IFS"
+IFS=$':\n'
+SEARCH=("." "$LIBDIR" $(clang -print-search-dirs 2>/dev/null | awk 'match($0, /^libraries\s*:\s*=\s*/) { print substr($0, RSTART + RLENGTH) }'))
+IFS=$'\n'
+AUTOLINKS=($(autolinks "$@" | sort | uniq))
+IFS="$saveifs"
+
+for ln in "${AUTOLINKS[@]}"; do
# sort away the global libs that are asked to be linked locally
haslib=false
- for lib in ${FILES[@]}
- do
- if [ "$(basename "${lib}")" == "$O.lib${ln}.a" ]
- then
+ for lib in "$@"; do
+ if [[ "${lib##*/}" == "$O.lib${ln}.a" ]]; then
haslib=true
break
fi
done
- if [ $haslib == true ]; then continue; fi
-
- lib="${LIBDIR}/lib${ln}.a"
- if [ -e "$lib" ]
- then
+ # or find the lib in the search path
+ if [[ $haslib == false ]]; then
+ lib=$(find "${SEARCH[@]}" -maxdepth 1 -type f -name "lib$ln.a" | sed 1q)
+ if [[ "$lib" == "" ]]; then
+ echo "can't find lib$ln.a" >&2
+ exit 1
+ fi
LIBS+=("$lib")
- continue
fi
-
- saveifs="$IFS"
- IFS=':'
- for d in $(clang -print-search-dirs 2>/dev/null | grep '^libraries:' | sed -e's/^libraries: *=\?//')
- do
- lib="${d}/lib${ln}.a"
- if [ -e "$lib" ]
- then
- LIBS+=("$lib")
- break;
- fi
- done
- IFS="$saveifs"
done
# add compiler-rt regardless
-LIBS+=("${LIBDIR}/libcompiler_rt.a")
+LIBS+=("$LIBDIR/libcompiler_rt.a")
CRTSTART=()
CRTEND=()
-if [ -e "${LIBDIR}/crti.o" ]; then CRTSTART+=("${LIBDIR}/crti.o"); fi
-if [ -e "${LIBDIR}/rcrt1.o" ]; then CRTSTART+=("${LIBDIR}/rcrt1.o"); fi
-if [ -e "${LIBDIR}/crtn.o" ]; then CRTEND+=("${LIBDIR}/crtn.o"); fi
+if [[ -e "$LIBDIR/crti.o" ]]; then CRTSTART+=("$LIBDIR/crti.o"); fi
+if [[ -e "$LIBDIR/rcrt1.o" ]]; then CRTSTART+=("$LIBDIR/rcrt1.o"); fi
+if [[ -e "$LIBDIR/crtn.o" ]]; then CRTEND+=("$LIBDIR/crtn.o"); fi
-if [ $USE_LTO == true ]
-then
+if [[ $USE_LTO == true ]]; then
OPTS+=("--plugin" "$(clang -print-file-name=LLVMgold.so)")
- OPTS+=("-plugin-opt=-march=${MARCH}")
+ OPTS+=("-plugin-opt=-march=$MARCH")
fi
ld.gold \
- --gc-sections -pie -Bstatic -Bsymbolic -E -X -e "${START_SYM}" \
+ --gc-sections -pie -Bstatic -Bsymbolic -E -X -e "$START_SYM" \
-z now -z nodlopen -z nodump -z nodelete -z noexecstack -z text \
- -nostdlib -L"${LIBDIR}" "${OPTS[@]}" $STRIP_FLAG -o "${OUTPUT_NAME}" \
- "${CRTSTART[@]}" '-(' "${FARGS[@]}" "${LIBS[@]}" '-)' "${CRTEND[@]}"
-if [ $? -ne 0 ]; then exit 1; fi
+ -nostdlib -L"$LIBDIR" "${OPTS[@]}" $STRIP_FLAG -o "$OUTPUT_NAME" \
+ "${CRTSTART[@]}" '-(' "${FARGS[@]}" "${LIBS[@]}" '-)' "${CRTEND[@]}" ||
+ exit 1
-perl -- "${DIR}/nuke-pt_interp.pl" "${OUTPUT_NAME}"
-if [ $? -ne 0 ]; then exit 1; fi
-objcopy -R .interp "${OUTPUT_NAME}" &>/dev/null
+perl -- "$DIR/nuke-pt_interp.pl" "$OUTPUT_NAME" || exit 1
+objcopy -R .interp "$OUTPUT_NAME" &>/dev/null
exit 0
diff --git a/bin/qa b/bin/qa
index 7110f04..57454c9 100755
--- a/bin/qa
+++ b/bin/qa
@@ -1,2 +1,4 @@
#!/bin/bash
-objtype=power source "$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )/p9a.sh"
+DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
+objtype=power
+. "$DIR/p9a.sh"
diff --git a/bin/qc b/bin/qc
index 72fc3a3..64da34d 100755
--- a/bin/qc
+++ b/bin/qc
@@ -1,2 +1,4 @@
#!/bin/bash
-objtype=power source "$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )/p9c.sh"
+DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
+objtype=power
+. "$DIR/p9c.sh"
diff --git a/bin/ql b/bin/ql
index 72d1ac8..2446307 100755
--- a/bin/ql
+++ b/bin/ql
@@ -1,2 +1,4 @@
#!/bin/bash
-objtype=power source "$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )/p9l.sh"
+DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
+objtype=power
+. "$DIR/p9l.sh"
diff --git a/bin/va b/bin/va
index 7597cc0..fda9dfe 100755
--- a/bin/va
+++ b/bin/va
@@ -1,2 +1,4 @@
#!/bin/bash
-objtype=mips source "$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )/p9a.sh"
+DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
+objtype=mips
+. "$DIR/p9a.sh"
diff --git a/bin/vc b/bin/vc
index 586673d..e8ce3b3 100755
--- a/bin/vc
+++ b/bin/vc
@@ -1,2 +1,4 @@
#!/bin/bash
-objtype=mips source "$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )/p9c.sh"
+DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
+objtype=mips
+. "$DIR/p9c.sh"
diff --git a/bin/vl b/bin/vl
index be943d4..54d6579 100755
--- a/bin/vl
+++ b/bin/vl
@@ -1,2 +1,4 @@
#!/bin/bash
-objtype=mips source "$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )/p9l.sh"
+DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
+objtype=mips
+. "$DIR/p9l.sh"