4834150 [rkeene@sledge /home/rkeene/tmp]$ cat -n crystal-bootstrap-prepare-source.sh
  1 #! /bin/bash
  2 
  3 ourdir="$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")"
  4 
  5 _download="${ourdir}/download"
  6 _extract="${ourdir}/extract"
  7 version="0.20.5"
  8 bootstrap_release='1'
  9 source_url="https://github.com/crystal-lang/crystal/archive/${version}.tar.gz"
 10 source_hash="ee1e5948c6e662ccb1e62671cf2c91458775b559b23d74ab226dc2a2d23f7707"
 11 
 12 case "$(uname -s)-$(uname -m)" in
 13     Linux-x86_64)
 14        
	binary_url="https://github.com/crystal-lang/crystal/releases/download/${version}/crystal-${version}-1-linux-x86_64.tar.
	gz"
 15         binary_hash="fd077c0a727419e131b1be6198a5aa5820ecbdaafd2d2bb38be5716ba75b5100"
 16         ;;
 17     *)
 18         echo "Unable to prepare on this platform, sorry !" >&2
 19         exit 1
 20         ;;
 21 esac
 22 source_archive="${ourdir}/archive/crystal-${version}-source.tar.gz"
 23 binary_archive="${ourdir}/archive/crystal-${version}-${binary_hash}-binary.tar.gz"
 24 workdir="$(TMPDIR='' mktemp -d -p "${ourdir}" workdir-XXXXXX)"
 25 source_dir="${workdir}/source"
 26 output_dir="${workdir}/output"
 27 test_dir="${workdir}/test"
 28 binary_dir="${workdir}/binary"
 29 bootstrap_tarball_base="crystal-bootstrap-${version}-${bootstrap_release}"
 30 
 31 function download_source() {
 32     "${_download}" "${source_url}" "${source_archive}" "${source_hash}" || return 1
 33 }
 34 
 35 function download_binary() {
 36     "${_download}" "${binary_url}" "${binary_archive}" "${binary_hash}" || return 1
 37 }
 38 
 39 function download() {
 40     download_source || return 1
 41     download_binary || return 1
 42 }
 43 
 44 function extract_source() {
 45     "${_extract}" "${source_archive}" "${source_dir}" || return 1
 46     "${_extract}" "${source_archive}" "${output_dir}" || return 1
 47 }
 48 
 49 function extract_binary() {
 50     "${_extract}" "${binary_archive}" "${binary_dir}" || return 1
 51 }
 52 
 53 function extract() {
 54     extract_source || return 1
 55     extract_binary || return 1
 56 }
 57 
 58 function build() {
 59     PATH="${binary_dir}/bin:$PATH"
 60 
 61     (
 62         cd "${source_dir}" || exit 1
 63 
 64         sed -i 's@^FLAGS .*@& --emit llvm-bc@' Makefile || exit 1
 65 
 66         make CXX=clang++ || exit 1
 67     ) || return 1
 68 
 69     cp "${source_dir}/crystal.bc" "${output_dir}/" || return 1
 70 
 71     (
 72         cd "${output_dir}" || exit 1
 73 
 74         sed -i 's@^SOURCES .*@SOURCES := @' Makefile
 75         sed -i 's|.* src/compiler/crystal.cr .*|\tllc --filetype=obj -o crystal.o crystal.bc \&\& $(CXX) -o $@ crystal.o
	$(DEPS) -lgc -lpcre -levent $(shell $(LLVM_CONFIG) --ldflags) $(shell $(LLVM_CONFIG) --libs) $(shell $(LLVM_CONFIG)
	--system-libs) |' Makefile
 76     ) || return 1
 77 
 78     rm -rf "${test_dir}" || return 1
 79     cp -a "${output_dir}" "${test_dir}" || return 1
 80 
 81     (
 82         cd "${test_dir}" || exit 1
 83 
 84         make CXX=clang++ || exit 1
 85 
 86         ./bin/crystal build ./samples/wordcount.cr || exit 1
 87 
 88         if [ "$(echo test | ./wordcount | awk '{ print $1 }')" != '1' ]; then
 89             exit 1
 90         fi
 91 
 92         cat << \_EOF_ > Makefile.local
 93 llvm-version:
 94     echo $(shell $(LLVM_CONFIG) --version) > llvm-version.new
 95     mv llvm-version.new llvm-version
 96 _EOF_
 97 
 98         make llvm-version || exit 1
 99     ) || return 1
100 
101     # Remove the Dockerfiles -- they specify different versions of LLVM and probably won't work
102     rm -f "${output_dir}"/Dockerfile*
103 
104     mv "${output_dir}/Makefile" "${output_dir}/Makefile.in" || return 1
105     sed 's|@@LLVM_BUILD_VERSION@@|'"$(cat "${test_dir}/llvm-version")"'|' "${ourdir}/configure.in" >
	"${output_dir}/configure" || return 1
106     chmod 755 "${output_dir}/configure" || return 1
107 
108     return 0
109 }
110 
111 function create_output() {
112     local bootstrap_tarball_dir
113 
114     bootstrap_tarball_dir="${workdir}/${bootstrap_tarball_base}"
115     rm -rf "${bootstrap_tarball_dir}" || return 1
116     cp -a "${output_dir}" "${bootstrap_tarball_dir}" || return 1
117 
118     (
119         cd "${workdir}" || exit 1
120 
121         tar -cf - "${bootstrap_tarball_base}" | gzip -9c > "${bootstrap_tarball_base}.tar.gz"
122     ) || return 1
123 
124     cp "${workdir}/${bootstrap_tarball_base}.tar.gz" .
125 
126     return 0
127 }
128 
129 function clean() {
130     rm -rf "${workdir}"
131 }
132 
133 download || exit 1
134 
135 extract || exit 1
136 
137 build || exit 1
138 
139 create_output || exit 1
140 
141 clean || exit 1
142 
143 exit 0
4834151 [rkeene@sledge /home/rkeene/tmp]$

Click here to go back to the directory listing.
Click here to download this file.
last modified: 2017-01-25 08:55:31