4 function detect_platform_type () {
5 local -r canon_name="canon-name/src/canon-name"
7 if [[ ! -x "$canon_name" ]]; then
8 gmake -f mk/canon-name.mk
14 function detect_number_of_cpus () {
15 local -r platform=$(detect_platform_type)
19 ioreg -r -c IOCPU | fgrep -c \"IOCPUNumber\"
22 cat /proc/cpuinfo | grep -cE 'processor[[:space:]]*:'
25 echo "WARNING: I don't know how to detect the number of processors on this platform." >&2
26 echo "WARNING: GHC will be built using only 1 processor. Expect some slowdown." >&2
32 function detect_gnu_tar () {
33 if which gnutar >/dev/null 2>&1; then
35 elif which gtar >/dev/null 2>&1; then
38 echo "We need GNU tar to be installed." >&2
43 function say_hello () {
44 local -r platform=$(detect_platform_type)
45 local -r n_cpus=$(detect_number_of_cpus)
47 echo "This is build-hc-pkg, running on $platform with $n_cpus processors."
51 local -r archive="work/archive"
54 if [[ -e "$archive" ]]; then
55 srcpath=$(cat "$archive")
58 if [[ -z "$srcpath" || ! -e "$srcpath" ]]; then
60 read -e -p "Enter the file path to ghc-x.y.z-src.tar.bz2: " srcpath
61 if [[ -e "$srcpath" ]]; then
63 echo "$srcpath" > "$archive"
65 echo "$srcpath not found." >&2
73 function build_hc_pkg () {
74 local -r srcpath="$(srcpath)"
77 -j $(($(detect_number_of_cpus) + 1)) \
80 PLATFORM="$(detect_platform_type)" \
81 GNUTAR="$(detect_gnu_tar)" \
84 echo "If you are done, run \"$0 clean\" to cleanup the working directory."
100 echo "Usage: $0 [clean]" >&2