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 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287
|
#? stdtmpl(subsChar='?') | standard
#proc generateBuildShellScript(c: ConfigData): string =
# result = "#!/bin/sh\n# Generated from niminst\n" &
# "# Template is in tools/niminst/buildsh.nimf\n" &
# "# To regenerate run ``niminst csource`` or ``koch csource``\n"
set -e
while :
do
case "$1" in
--os)
optos=$2
shift 2
;;
--cpu)
optcpu=$2
shift 2
;;
--osname)
optosname=$2
shift 2
;;
--parallel)
parallel=$2
shift 2
;;
--extraBuildArgs)
extraBuildArgs=" $2"
shift 2
;;
-h | --help)
echo "Options:"
echo " --os <OS>"
echo " --cpu <CPU architecture>"
echo " --osname <name> Additional OS specification (used for Android)"
echo " --extraBuildArgs <args> Additional arguments passed to the compiler"
echo " --parallel <number> Multiprocess build. Requires GNU parallel"
exit 0
;;
--) # End of all options
shift
break;
;;
-*)
echo 2>&1 "Error: Unknown option: $1" >&2
exit 1
;;
*) # No more options
break
;;
esac
done
parallel="${parallel:-0}"
CC="${CC:-gcc}"
if [ "$parallel" -gt 1 ]; then
if ! command -v sem > /dev/null; then
echo "Error: GNU parallel is required to use --parallel"
exit 1
fi
CC="sem -j $parallel --id $$ ${CC}"
fi
COMP_FLAGS="${CPPFLAGS:-} ${CFLAGS:-} ?{c.ccompiler.flags}$extraBuildArgs"
LINK_FLAGS="${LDFLAGS:-} ?{c.linker.flags}"
PS4=""
# add(result, "# platform detection\n")
ucpu=`uname -m`
uos=`uname`
uosname=
# add(result, "# bin dir detection\n")
binDir=?{firstBinPath(c).toUnix}
if [ -s ../koch.nim ]; then
binDir="../bin"
fi
if [ ! -d $binDir ]; then
mkdir $binDir
fi
# add(result, "# override OS, CPU and OS Name with command-line arguments\n")
if [ -n "$optos" ]; then
uos="$optos"
fi
if [ -n "$optcpu" ]; then
ucpu="$optcpu"
fi
if [ -n "$optcpu" ]; then
uosname="$optosname"
fi
# add(result, "# convert to lower case:\n")
ucpu=`echo $ucpu | tr "[:upper:]" "[:lower:]"`
uos=`echo $uos | tr "[:upper:]" "[:lower:]"`
uosname=`echo $uosname | tr "[:upper:]" "[:lower:]"`
case $uos in
*linux* )
myos="linux"
LINK_FLAGS="$LINK_FLAGS -ldl -lm -lrt"
;;
*dragonfly* )
myos="dragonfly"
LINK_FLAGS="$LINK_FLAGS -lm"
;;
*freebsd* )
myos="freebsd"
CC="clang"
LINK_FLAGS="$LINK_FLAGS -lm"
;;
*crossos* )
myos="crossos"
CC="clang"
LINK_FLAGS="$LINK_FLAGS -lm"
;;
*openbsd* )
myos="openbsd"
CC="clang"
LINK_FLAGS="$LINK_FLAGS -lm"
;;
*netbsd* )
myos="netbsd"
LINK_FLAGS="$LINK_FLAGS -lm"
ucpu=`uname -p`
;;
*darwin* )
myos="macosx"
CC="clang"
LINK_FLAGS="$LINK_FLAGS -ldl -lm"
if [ "$HOSTTYPE" = "x86_64" ] ; then
ucpu="amd64"
fi
;;
*aix* )
myos="aix"
LINK_FLAGS="$LINK_FLAGS -ldl -lm"
;;
*solaris* | *sun* )
myos="solaris"
LINK_FLAGS="$LINK_FLAGS -ldl -lm -lsocket -lnsl"
;;
*SunOS* )
myos="solaris"
LINK_FLAGS="$LINK_FLAGS -ldl -lm -lsocket -lnsl"
isOpenIndiana="yes"
;;
*haiku* )
myos="haiku"
LINK_FLAGS="$LINK_FLAGS -lroot -lnetwork"
;;
*mingw* | *msys* )
myos="windows"
;;
*android* )
myos="android"
LINK_FLAGS="$LINK_FLAGS -ldl -lm -lrt"
LINK_FLAGS="$LINK_FLAGS -landroid-glob"
;;
*)
echo 2>&1 "Error: unknown operating system: $uos"
exit 1
;;
esac
case $ucpu in
*i386* | *i486* | *i586* | *i686* | *bepc* | *i86pc* )
if [ "$isOpenIndiana" = "yes" ] || [ `uname -o` == "illumos" ] ; then
mycpu="amd64"
else
mycpu="i386"
fi
;;
*amd*64* | *x86-64* | *x86_64* )
mycpu="amd64" ;;
*sparc*|*sun* )
mycpu="sparc"
if [ "$myos" = "linux" ] ; then
if [ "$(getconf LONG_BIT)" = "64" ]; then
mycpu="sparc64"
elif [ "$(isainfo -b)" = "64" ]; then
mycpu="sparc64"
fi
fi
;;
*ppc64le* )
mycpu="powerpc64el" ;;
*ppc64* )
if [ "$myos" = "linux" ] ; then
COMP_FLAGS="$COMP_FLAGS -m64"
LINK_FLAGS="$LINK_FLAGS -m64"
fi
mycpu="powerpc64" ;;
*power*|*ppc* )
if [ "$myos" = "freebsd" ] ; then
if [ "$ucpu" != "powerpc" ] ; then
COMP_FLAGS="$COMP_FLAGS -m64"
LINK_FLAGS="$LINK_FLAGS -m64"
fi
mycpu=`uname -p`
case $mycpu in
powerpc64le)
mycpu="powerpc64el"
esac
else
mycpu="powerpc"
fi
;;
*hppa*)
mycpu="hppa" ;;
*ia64*)
mycpu="ia64" ;;
*m68k*)
mycpu="m68k" ;;
*mips* )
mycpu="$("$CC" -dumpmachine | sed 's/-.*//')"
case $mycpu in
mips|mipsel|mips64|mips64el)
;;
*)
echo 2>&1 "Error: unknown MIPS target: $mycpu"
exit 1
esac
;;
*alpha* )
mycpu="alpha" ;;
*aarch64*|*arm64* )
mycpu="arm64" ;;
*arm*|*armv6l*|*armv7l*|*armv8l* )
mycpu="arm" ;;
*riscv64|riscv* )
mycpu="riscv64" ;;
*e2k* )
mycpu="e2k" ;;
*loongarch64* )
mycpu="loongarch64" ;;
*)
echo 2>&1 "Error: unknown processor: $ucpu"
exit 1
;;
esac
case $uosname in
*android* )
LINK_FLAGS="$LINK_FLAGS -landroid-glob"
myosname="android"
myos="android"
;;
esac
# add(result, "# call the compiler:\n")
echo \# OS: $myos
echo \# CPU: $mycpu
case $myos in
# for osA in 1..c.oses.len:
?{c.oses[osA-1]})
case $mycpu in
# for cpuA in 1..c.cpus.len:
?{c.cpus[cpuA-1]})
set -x
# var linkCmd = ""
# for ff in items(c.cfiles[osA][cpuA]):
# let f = ff.toUnix
$CC $COMP_FLAGS -Ic_code -c ?{f} -o ?{changeFileExt(f, "o")}
# add(linkCmd, " \\\n" & changeFileExt(f, "o"))
# end for
if [ "$parallel" -gt 0 ]; then
sem --wait --id $$
fi
$CC -o ?{"$binDir/" & toLowerAscii(c.name)} ?linkCmd $LINK_FLAGS
;;
# end for
*)
echo 2>&1 "Error: no C code generated for: [$myos: $mycpu]"
exit 1
;;
esac
;;
# end for
*)
echo 2>&1 "Error: no C code generated for: [$myos: $mycpu]"
exit 1
;;
esac
: SUCCESS
|