From 98d1f1da856ab59cf8355c1e2e11e3c0eb954fb2 Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Sun, 1 Jul 2018 15:21:16 -0300 Subject: Unix: new build system * Reworked configure script * Now passes shellcheck * New Makefile for Unix * Simplified `make` and `make install` targets * Simplified `make bootstrap` target * New targets `make binary` and `make install-binary` build and install an all-in-one binary of LuaRocks --- binary/static-gcc | 158 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 158 insertions(+) create mode 100755 binary/static-gcc (limited to 'binary/static-gcc') diff --git a/binary/static-gcc b/binary/static-gcc new file mode 100755 index 00000000..a4d865d5 --- /dev/null +++ b/binary/static-gcc @@ -0,0 +1,158 @@ +#!/usr/bin/env bash + +DIR="$( cd "$( dirname "$0" )" && pwd )" + +function log() { echo -- "$@" >> $DIR/log.txt; } + +function runlog() { log "$@"; "$@"; } + +log "---------------------------" +log INP "$@" + +allargs=() +sources=() +objects=() +etc=() +libdirs=("/usr/lib") +incdirs=() + +linking=0 + +while [ "$1" ] +do + allargs+=("$1") + if [ "$next_libdir" = "1" ] + then + libdirs+=("$1") + next_libdir=0 + elif [ "$next_incdir" = "1" ] + then + incdirs+=("-I$1") + next_incdir=0 + elif [ "$next_lib" = "1" ] + then + libs+=("$1") + next_lib=0 + elif [ "$next_output" = "1" ] + then + output="$1" + next_output=0 + else + case "$1" in + -*) + case "$1" in + -shared) + linking=1 + ;; + -static) + linking=1 + ;; + -o) + next_output=1 + ;; + -c) + object=1 + etc+=("$1") + ;; + -L) + next_libdir=1 + ;; + -L*) + libdirs+=("${1:2}") + ;; + -I) + next_incdir=1 + ;; + -I*) + incdirs+=("$1") + ;; + -l) + next_lib=1 + ;; + -l*) + libs+=("${1:2}") + ;; + *) + etc+=("$1") + ;; + esac + ;; + *.c) + sources+=("$1") + ;; + *.o) + objects+=("$1") + ;; + *) + etc+=("$1") + ;; + esac + fi + shift +done + +staticlibs=() +for lib in "${libs[@]}" +do + for libdir in "${libdirs[@]}" + do + staticlib="$libdir/lib$lib.a" + if [ -e "$staticlib" ] + then + staticlibs+=("$staticlib") + break + fi + done +done + +oflag=() +if [ "$output" != "" ] +then + oflag=("-o" "$output") +fi + +if [ "$linking" = "1" ] +then + log LINK + if [ "${#sources[@]}" -gt 0 ] + then + for source in "${sources[@]}" + do + object="${source%.c}.o" + runlog gcc "${incdirs[@]}" "${etc[@]}" -c -o "$object" "$source" + [ "$?" = 0 ] || runlog exit $? + objects+=("$object") + done + fi + + # runlog ar rcu "${oflag[@]}" "${objects[@]}" "${staticlibs[@]}" + echo "CREATE $output" > ar.script + for o in "${objects[@]}" + do + echo "ADDMOD $o" >> ar.script + done + for o in "${staticlibs[@]}" + do + echo "ADDLIB $o" >> ar.script + done + echo "SAVE" >> ar.script + echo "END" >> ar.script + cat ar.script | ar -M + [ "$?" = 0 ] || runlog exit $? + + [ -e "$output" ] || { + exit 1 + } + + runlog ranlib "$output" + runlog exit $? +elif [ "$object" = 1 ] +then + log OBJECT + runlog gcc "${oflag[@]}" "${incdirs[@]}" "${etc[@]}" "${sources[@]}" + runlog exit $? +else + log EXECUTABLE + runlog gcc "${allargs[@]}" + runlog exit $? +fi -- cgit v1.2.3-55-g6feb