4 function detect_platform_type () {
5 local -r canon_name="canon-name/src/canon-name"
7 if ! gmake --question --file="mk/canon-name.mk" >/dev/null 2>&1; then
8 gmake --file="mk/canon-name.mk" >&2
14 function detect_number_of_cpus () {
15 if ! sysctl -n hw.ncpu; then
16 echo "WARNING: I don't know how to detect the number of processors on this platform." >&2
17 echo "WARNING: GHC will be built using only 1 processor. Expect some slowdown." >&2
22 function detect_gnu_tar () {
23 if which gnutar >/dev/null 2>&1; then
25 elif which gtar >/dev/null 2>&1; then
28 echo "We need GNU tar to be installed." >&2
33 function say_hello () {
34 local -r platform=$(detect_platform_type)
35 local -r n_cpus=$(detect_number_of_cpus)
37 echo -n "This is "$(basename "$0")", running on $platform with $n_cpus "
38 if (( $n_cpus == 1 )); then
46 local -r archive="work/archive"
49 if [[ -e "$archive" ]]; then
50 srcpath=$(cat "$archive")
53 if [[ -z "$srcpath" || ! -e "$srcpath" ]]; then
55 read -e -p "Enter the file path to ghc-x.y.z-src.tar.bz2: " srcpath
56 if [[ -e "$srcpath" ]]; then
58 echo "$srcpath" > "$archive"
60 echo "$srcpath not found." >&2
68 function build_hc_pkg () {
69 local -r srcpath="$(srcpath)"
72 -j $(($(detect_number_of_cpus) + 1)) \
75 PLATFORM="$(detect_platform_type)" \
76 GNUTAR="$(detect_gnu_tar)" \
79 echo "If you are done, run \"$0 clean\" to cleanup the working directory."
95 echo "Usage: $0 [clean]" >&2