Hex Artifact Content

Artifact bda883498cbd98a9cdf58f891236a7c14e284050:


0000: 23 21 20 2f 75 73 72 2f 62 69 6e 2f 65 6e 76 20  #! /usr/bin/env 
0010: 62 61 73 68 0a 0a 23 20 45 6e 73 75 72 65 20 77  bash..# Ensure w
0020: 65 20 61 72 65 20 69 6e 20 74 68 65 20 63 6f 72  e are in the cor
0030: 72 65 63 74 20 77 6f 72 6b 69 6e 67 20 64 69 72  rect working dir
0040: 65 63 74 6f 72 79 0a 63 64 20 22 24 28 64 69 72  ectory.cd "$(dir
0050: 6e 61 6d 65 20 22 24 28 77 68 69 63 68 20 22 24  name "$(which "$
0060: 30 22 29 22 29 2f 2e 2e 22 20 7c 7c 20 65 78 69  0")")/.." || exi
0070: 74 20 31 0a 0a 23 20 44 65 74 65 72 6d 69 6e 65  t 1..# Determine
0080: 20 74 68 65 20 76 65 72 73 69 6f 6e 20 6f 66 20   the version of 
0090: 46 69 6c 65 64 0a 76 65 72 73 69 6f 6e 3d 27 27  Filed.version=''
00a0: 0a 65 76 61 6c 20 22 24 28 28 20 67 72 65 70 20  .eval "$(( grep 
00b0: 27 5e 23 20 2a 64 65 66 69 6e 65 20 20 2a 46 49  '^# *define  *FI
00c0: 4c 45 44 5f 56 45 52 53 49 4f 4e 27 20 66 69 6c  LED_VERSION' fil
00d0: 65 64 2e 63 3b 20 65 63 68 6f 20 27 7c 76 65 72  ed.c; echo '|ver
00e0: 73 69 6f 6e 3d 46 49 4c 45 44 5f 56 45 52 53 49  sion=FILED_VERSI
00f0: 4f 4e 27 20 29 20 7c 20 63 70 70 20 2d 45 20 7c  ON' ) | cpp -E |
0100: 20 67 72 65 70 20 27 5e 7c 27 20 7c 20 73 65 64   grep '^|' | sed
0110: 20 27 73 40 5e 7c 40 40 27 29 22 0a 69 66 20 5b   's@^|@@')".if [
0120: 20 2d 7a 20 22 24 7b 76 65 72 73 69 6f 6e 7d 22   -z "${version}"
0130: 20 5d 3b 20 74 68 65 6e 0a 09 65 63 68 6f 20 22   ]; then..echo "
0140: 55 6e 61 62 6c 65 20 74 6f 20 64 65 74 65 72 6d  Unable to determ
0150: 69 6e 65 20 77 68 69 63 68 20 76 65 72 73 69 6f  ine which versio
0160: 6e 20 6f 66 20 46 69 6c 65 64 20 77 65 20 61 72  n of Filed we ar
0170: 65 20 63 6f 6d 70 69 6c 69 6e 67 2e 20 20 41 62  e compiling.  Ab
0180: 6f 72 74 69 6e 67 2e 22 20 3e 26 32 0a 0a 09 65  orting." >&2...e
0190: 78 69 74 20 31 0a 66 69 0a 0a 23 20 43 6c 65 61  xit 1.fi..# Clea
01a0: 6e 75 70 0a 72 6d 20 2d 72 66 20 77 6f 72 6b 64  nup.rm -rf workd
01b0: 69 72 2d 62 75 69 6c 64 50 72 65 63 6f 6d 70 69  ir-buildPrecompi
01c0: 6c 65 64 2d 2a 0a 0a 23 20 43 6f 6d 70 69 6c 65  led-*..# Compile
01d0: 20 65 76 65 72 79 74 68 69 6e 67 2c 20 61 6c 6c   everything, all
01e0: 20 61 74 20 6f 6e 63 65 0a 69 64 78 3d 2d 31 0a   at once.idx=-1.
01f0: 66 6f 72 20 74 72 79 43 6f 6d 70 69 6c 65 72 44  for tryCompilerD
0200: 69 72 20 69 6e 20 22 24 28 72 65 61 64 6c 69 6e  ir in "$(readlin
0210: 6b 20 2d 66 20 7e 2f 72 6f 6f 74 2f 63 72 6f 73  k -f ~/root/cros
0220: 73 2d 63 6f 6d 70 69 6c 65 72 73 29 22 20 22 24  s-compilers)" "$
0230: 28 72 65 61 64 6c 69 6e 6b 20 2d 66 20 7e 2f 64  (readlink -f ~/d
0240: 65 76 65 6c 2f 62 75 69 6c 64 2d 63 63 2f 54 4d  evel/build-cc/TM
0250: 50 29 22 3b 20 64 6f 0a 09 73 65 74 75 70 5f 63  P)"; do..setup_c
0260: 63 3d 22 24 7b 74 72 79 43 6f 6d 70 69 6c 65 72  c="${tryCompiler
0270: 44 69 72 7d 2f 73 65 74 75 70 2d 63 63 22 0a 0a  Dir}/setup-cc"..
0280: 09 70 6c 61 74 66 6f 72 6d 73 3d 28 0a 09 09 24  .platforms=(...$
0290: 28 22 24 7b 73 65 74 75 70 5f 63 63 7d 22 20 7c  ("${setup_cc}" |
02a0: 20 74 61 69 6c 20 2d 6e 20 2b 32 29 0a 09 29 0a   tail -n +2)..).
02b0: 0a 09 66 6f 72 20 70 6c 61 74 66 6f 72 6d 20 69  ..for platform i
02c0: 6e 20 22 24 7b 70 6c 61 74 66 6f 72 6d 73 5b 40  n "${platforms[@
02d0: 5d 7d 22 3b 20 64 6f 0a 09 09 69 64 78 3d 24 5b  ]}"; do...idx=$[
02e0: 24 69 64 78 20 2b 20 31 5d 0a 09 09 28 0a 09 09  $idx + 1]...(...
02f0: 09 77 6f 72 6b 64 69 72 3d 22 77 6f 72 6b 64 69  .workdir="workdi
0300: 72 2d 62 75 69 6c 64 50 72 65 63 6f 6d 70 69 6c  r-buildPrecompil
0310: 65 64 2d 24 7b 69 64 78 7d 2d 24 28 6f 70 65 6e  ed-${idx}-$(open
0320: 73 73 6c 20 72 61 6e 64 20 32 30 20 2d 68 65 78  ssl rand 20 -hex
0330: 29 2d 70 6c 61 74 66 6f 72 6d 2d 24 7b 70 6c 61  )-platform-${pla
0340: 74 66 6f 72 6d 7d 22 20 7c 7c 20 65 78 69 74 20  tform}" || exit 
0350: 31 0a 09 09 09 6d 6b 64 69 72 20 22 24 7b 77 6f  1....mkdir "${wo
0360: 72 6b 64 69 72 7d 22 20 7c 7c 20 65 78 69 74 20  rkdir}" || exit 
0370: 31 0a 09 09 09 63 64 20 22 24 7b 77 6f 72 6b 64  1....cd "${workd
0380: 69 72 7d 22 20 7c 7c 20 65 78 69 74 20 31 0a 0a  ir}" || exit 1..
0390: 09 09 09 65 76 61 6c 20 24 28 22 24 7b 73 65 74  ...eval $("${set
03a0: 75 70 5f 63 63 7d 22 20 22 24 7b 70 6c 61 74 66  up_cc}" "${platf
03b0: 6f 72 6d 7d 22 29 0a 09 09 09 6d 61 6b 65 5f 65  orm}")....make_e
03c0: 78 74 72 61 3d 28 0a 09 09 09 09 2d 66 20 2e 2e  xtra=(.....-f ..
03d0: 2f 4d 61 6b 65 66 69 6c 65 0a 09 09 09 09 73 72  /Makefile.....sr
03e0: 63 64 69 72 3d 2e 2e 0a 09 09 09 09 43 43 3d 22  cdir=.......CC="
03f0: 24 7b 43 43 7d 22 0a 09 09 09 29 0a 0a 09 09 09  ${CC}"....).....
0400: 63 61 73 65 20 22 24 7b 70 6c 61 74 66 6f 72 6d  case "${platform
0410: 7d 22 20 69 6e 0a 09 09 09 09 2a 2d 6d 75 73 6c  }" in.....*-musl
0420: 2d 2a 7c 2a 2d 6d 75 73 6c 29 0a 09 09 09 09 09  -*|*-musl)......
0430: 6d 61 6b 65 5f 65 78 74 72 61 3d 28 22 24 7b 6d  make_extra=("${m
0440: 61 6b 65 5f 65 78 74 72 61 5b 40 5d 7d 22 20 46  ake_extra[@]}" F
0450: 49 4c 45 44 5f 45 58 54 52 41 5f 4c 44 46 4c 41  ILED_EXTRA_LDFLA
0460: 47 53 3d 22 2d 73 74 61 74 69 63 22 29 0a 09 09  GS="-static")...
0470: 09 09 09 3b 3b 0a 09 09 09 65 73 61 63 0a 0a 09  ...;;....esac...
0480: 09 09 6d 61 6b 65 20 22 24 7b 6d 61 6b 65 5f 65  ..make "${make_e
0490: 78 74 72 61 5b 40 5d 7d 22 20 3e 20 66 69 6c 65  xtra[@]}" > file
04a0: 64 2e 6c 6f 67 20 32 3e 26 31 20 3c 2f 64 65 76  d.log 2>&1 </dev
04b0: 2f 6e 75 6c 6c 20 7c 7c 20 6d 76 20 66 69 6c 65  /null || mv file
04c0: 64 2e 6c 6f 67 20 66 69 6c 65 64 2d 66 61 69 6c  d.log filed-fail
04d0: 65 64 2e 6c 6f 67 0a 09 09 29 20 26 0a 09 64 6f  ed.log...) &..do
04e0: 6e 65 0a 64 6f 6e 65 0a 0a 23 20 57 61 69 74 20  ne.done..# Wait 
04f0: 66 6f 72 20 74 68 61 74 20 74 6f 20 67 65 74 20  for that to get 
0500: 64 6f 6e 65 0a 77 61 69 74 0a 0a 23 20 52 65 6e  done.wait..# Ren
0510: 61 6d 65 20 74 68 65 20 66 69 6c 65 73 20 69 6e  ame the files in
0520: 74 6f 20 70 6c 61 63 65 0a 6d 6b 64 69 72 20 2d  to place.mkdir -
0530: 70 20 63 6f 6d 70 69 6c 65 64 0a 66 6f 72 20 62  p compiled.for b
0540: 69 6e 61 72 79 20 69 6e 20 77 6f 72 6b 64 69 72  inary in workdir
0550: 2d 62 75 69 6c 64 50 72 65 63 6f 6d 70 69 6c 65  -buildPrecompile
0560: 64 2d 2a 2f 66 69 6c 65 64 3b 20 64 6f 0a 09 70  d-*/filed; do..p
0570: 6c 61 74 66 6f 72 6d 3d 22 24 28 65 63 68 6f 20  latform="$(echo 
0580: 22 24 7b 62 69 6e 61 72 79 7d 22 20 7c 20 73 65  "${binary}" | se
0590: 64 20 27 73 40 5e 2e 2a 2d 70 6c 61 74 66 6f 72  d 's@^.*-platfor
05a0: 6d 2d 40 40 3b 73 40 2f 2e 2a 24 40 40 27 29 22  m-@@;s@/.*$@@')"
05b0: 0a 09 6d 76 20 22 24 7b 62 69 6e 61 72 79 7d 22  ..mv "${binary}"
05c0: 20 22 63 6f 6d 70 69 6c 65 64 2f 66 69 6c 65 64   "compiled/filed
05d0: 2d 24 7b 76 65 72 73 69 6f 6e 7d 2d 24 7b 70 6c  -${version}-${pl
05e0: 61 74 66 6f 72 6d 7d 22 0a 64 6f 6e 65 0a 66 6f  atform}".done.fo
05f0: 72 20 65 72 72 6f 72 4c 6f 67 20 69 6e 20 77 6f  r errorLog in wo
0600: 72 6b 64 69 72 2d 62 75 69 6c 64 50 72 65 63 6f  rkdir-buildPreco
0610: 6d 70 69 6c 65 64 2d 2a 2f 66 69 6c 65 64 2d 66  mpiled-*/filed-f
0620: 61 69 6c 65 64 2e 6c 6f 67 3b 20 64 6f 0a 09 70  ailed.log; do..p
0630: 6c 61 74 66 6f 72 6d 3d 22 24 28 65 63 68 6f 20  latform="$(echo 
0640: 22 24 7b 65 72 72 6f 72 4c 6f 67 7d 22 20 7c 20  "${errorLog}" | 
0650: 73 65 64 20 27 73 40 5e 2e 2a 2d 70 6c 61 74 66  sed 's@^.*-platf
0660: 6f 72 6d 2d 40 40 3b 73 40 2f 2e 2a 24 40 40 27  orm-@@;s@/.*$@@'
0670: 29 22 0a 09 6d 76 20 22 24 7b 65 72 72 6f 72 4c  )"..mv "${errorL
0680: 6f 67 7d 22 20 22 63 6f 6d 70 69 6c 65 64 2f 66  og}" "compiled/f
0690: 69 6c 65 64 2d 24 7b 76 65 72 73 69 6f 6e 7d 2d  iled-${version}-
06a0: 24 7b 70 6c 61 74 66 6f 72 6d 7d 2d 65 72 72 6f  ${platform}-erro
06b0: 72 2e 6c 6f 67 22 0a 64 6f 6e 65 0a 0a 23 20 43  r.log".done..# C
06c0: 6c 65 61 6e 75 70 0a 72 6d 20 2d 72 66 20 77 6f  leanup.rm -rf wo
06d0: 72 6b 64 69 72 2d 62 75 69 6c 64 50 72 65 63 6f  rkdir-buildPreco
06e0: 6d 70 69 6c 65 64 2d 2a 0a 0a 65 78 69 74 20 30  mpiled-*..exit 0
06f0: 0a                                               .