From: Michael D. Lowis Date: Sat, 2 Feb 2019 03:01:06 +0000 (-0500) Subject: updated compiler flags and runtime header X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=refs%2Fheads%2Fmaster;p=proto%2Facc.git updated compiler flags and runtime header --- diff --git a/acc b/acc index acdf06b..82be42e 100755 --- a/acc +++ b/acc @@ -1,15 +1,56 @@ #!/usr/bin/env bash +# +# Copyright 2019 Michael D. Lowis +#------------------------------------------------------------------------------- +# Permission to use, copy, modify, and/or distribute this software for any +# purpose with or without fee is hereby granted, provided that the above +# copyright notice and this permission notice appear in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH +# REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY +# AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, +# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM +# LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR +# OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR +# PERFORMANCE OF THIS SOFTWARE. + +# Wrapper script for system compiler that enables some flags by default and scans +# for library dependencies. +# +# Compilation Features: +# * Enables --std=c99 -pedantic +# * Enables -Wall -Wextra -Werror +# * Defines AUTOLIB() macro to specify dependencies in sources and headers +# * Auto-includes commonly include headers such as stddef.h, stdio.h, etc. +# +# Linking Features: +# * Scans objects for AUTOLIB()-ed libs, and adds the -l flags for them # predeclare our variables declare -a objects declare -a libpaths -declare -a libraries compile=false runtime=' #define _POSIX_C_SOURCE 200809L #define _XOPEN_SOURCE 700 #define AUTOLIB(n) \ - int __autolib_##n __attribute__ ((weak));' + int __autolib_##n __attribute__ ((weak)); +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +' # end of runtime definition # scan the rest of the options for lib paths, libs and objects for i do @@ -20,7 +61,7 @@ for i do -L*) # Add libpaths to the search list libpaths+=("${i#-L}") ;; - -c) # Mark this as compilation only + -c|-E) # Mark this as compilation/preprocess only compile=true ;; esac done @@ -29,7 +70,7 @@ done if $compile; then genfile=$(mktemp) printf '%s\n' "$runtime" > "$genfile" - cc -include "$genfile" "$@" + cc -isystem "${genfile%/*}" -include "${genfile##*/}" --std=c99 -pedantic -Wall -Wextra -Werror "$@" status=$? rm "$genfile" exit "$status" @@ -37,7 +78,7 @@ fi # scan objects/libs for referenced libraries scan_for_libs(){ - nm "$@" | sed -n '/__autolib/ s/.*_\+autolib_// p' | sort -u + [[ $# -ne 0 ]] && nm "$@" | sed -n '/__autolib/ s/.*_\+autolib_// p' | sort -u } # if we made it here, we must be linking. scan for dependencies