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" 2>/dev/null; then
16 # This works for most BSDs.
18 elif grep -qF processor /proc/cpuinfo 2>/dev/null; then
20 grep -cF processor /proc/cpuinfo
22 echo "WARNING: I don't know how to detect the number of processors on this platform." >&2
23 echo "WARNING: GHC will be built using only 1 processor. Expect some slowdown." >&2
28 function detect_gnu_tar () {
29 if which gnutar >/dev/null 2>&1; then
31 elif which gtar >/dev/null 2>&1; then
34 echo "We need GNU tar to be installed." >&2
39 function detect_gnu_sed () {
40 if which gsed >/dev/null 2>&1; then
42 elif sed --version | grep -qF GNU; then
45 echo "We need GNU sed to be installed." >&2
50 function say_hello () {
51 local -r self=$(basename "$0")
52 local -r platform=$(detect_platform_type)
53 local -r n_cpus=$(detect_number_of_cpus)
55 echo -n "This is $self, running on $platform with $n_cpus "
56 if (( $n_cpus == 1 )); then
64 local -r archive="work/archive"
67 if [[ -e "$archive" ]]; then
68 srcpath=$(cat "$archive")
71 if [[ -z "$srcpath" || ! -e "$srcpath" ]]; then
73 read -e -p "Enter the file path to ghc-x.y.z-src.tar.bz2: " srcpath
74 if [[ -e "$srcpath" ]]; then
76 echo "$srcpath" > "$archive"
78 echo "$srcpath not found." >&2
86 function build_hc_pkg () {
87 local -r srcpath="$(srcpath)"
90 -j $(($(detect_number_of_cpus) + 1)) \
93 PLATFORM="$(detect_platform_type)" \
94 GNUTAR="$(detect_gnu_tar)" \
95 GNUSED="$(detect_gnu_sed)" \
98 echo "If you are done, run \"$0 clean\" to cleanup the working directory."
114 echo "Usage: $0 [clean]" >&2