1
1
#! /bin/sh
2
2
3
- set -u # error on use of undefined variable
4
3
set -e # exit on error
5
4
6
- install_path=" $HOME /.local/bin"
5
+ usage ()
6
+ {
7
+ echo " Fortran Package Manager Bootstrap Script"
8
+ echo " "
9
+ echo " USAGE:"
10
+ echo " ./install.sh [--help | [--prefix=PREFIX] [--update[=REF]]"
11
+ echo " [--no-openmp] [--static] [--haskell] ]"
12
+ echo " "
13
+ echo " --help Display this help text"
14
+ echo " --prefix=PREFIX Install binary in 'PREFIX/bin'"
15
+ echo " Default prefix='\$ HOME/.local/bin'"
16
+ echo " --update[=REF] Update repository from latest release tag"
17
+ echo " or from git reference REF if specified"
18
+ echo " --no-openmp Don't build fpm with openmp support"
19
+ echo " --static Statically link fpm executable"
20
+ echo " (implies --no-openmp)"
21
+ echo " --haskell Only install Haskell fpm"
22
+ echo " "
23
+ echo " '--no-openmp' and '--static' do not affect the Haskell fpm"
24
+ echo " build."
25
+ echo " "
26
+ }
27
+
28
+ PREFIX=" $HOME /.local"
29
+ UPDATE=false
30
+ OMP=true
31
+ STATIC=false
32
+ HASKELL_ONLY=false
33
+
34
+ STACK_BIN_PATH=" $HOME /.local/bin"
35
+ REF=$( git tag | tail -n1)
36
+ RELEASE_FLAGS=" --flag -g --flag -fbacktrace --flag -O3"
37
+
38
+ while [ " $1 " != " " ]; do
39
+ PARAM=$( echo " $1 " | awk -F= ' {print $1}' )
40
+ VALUE=$( echo " $1 " | awk -F= ' {print $2}' )
41
+ case $PARAM in
42
+ -h | --help)
43
+ usage
44
+ exit
45
+ ;;
46
+ --prefix)
47
+ PREFIX=$VALUE
48
+ ;;
49
+ --update)
50
+ UPDATE=true
51
+ if [ " $VALUE " != " " ]; then
52
+ REF=$VALUE
53
+ fi
54
+ ;;
55
+ --no-openmp)
56
+ OMP=false
57
+ ;;
58
+ --static)
59
+ STATIC=true
60
+ OMP=false
61
+ ;;
62
+ --haskell)
63
+ HASKELL_ONLY=true
64
+ ;;
65
+ * )
66
+ echo " ERROR: unknown parameter \" $PARAM \" "
67
+ usage
68
+ exit 1
69
+ ;;
70
+ esac
71
+ shift
72
+ done
73
+
74
+ set -u # error on use of undefined variable
75
+
76
+ INSTALL_PATH=" $PREFIX /bin"
7
77
8
78
if command -v stack 1> /dev/null 2>&1 ; then
9
- echo " found stack"
79
+ echo " Found stack"
10
80
else
11
81
echo " Haskell stack not found."
12
- echo " Installing Haskell stack to. "
82
+ echo " Installing Haskell stack"
13
83
curl -sSL https://get.haskellstack.org/ | sh
14
84
if command -v stack 1> /dev/null 2>&1 ; then
15
85
echo " Haskell stack installation successful."
16
86
else
17
- echo " Haskell stack installation unsuccessful."
87
+ echo " ERROR: Haskell stack installation unsuccessful."
18
88
exit 1
19
89
fi
20
90
fi
21
91
22
- if [ -x " $install_path /fpm" ]; then
23
- echo " Overwriting existing fpm installation in $install_path "
92
+ if [ -x " $INSTALL_PATH /fpm" ]; then
93
+ echo " Overwriting existing fpm installation in $INSTALL_PATH "
94
+ fi
95
+
96
+ if [ " $UPDATE " = true ]; then
97
+ git checkout " $REF "
98
+ if [ $? != 0 ]; then
99
+ echo " ERROR: Unable to checkout $REF ."
100
+ exit 1
101
+ fi
24
102
fi
25
103
26
104
cd bootstrap
27
105
stack install
28
106
29
- if [ -x " $install_path /fpm" ]; then
30
- echo " fpm installed successfully to $install_path "
31
- else
32
- echo " fpm installation unsuccessful: fpm not found in $install_path "
107
+ if [ " $STACK_BIN_PATH " != " $INSTALL_PATH " ]; then
108
+ mv " $STACK_BIN_PATH /fpm" " $INSTALL_PATH /"
109
+ fi
110
+
111
+ if [ " $HASKELL_ONLY " = true ]; then
112
+ exit
113
+ fi
114
+
115
+ if [ " $STATIC " = true ]; then
116
+ RELEASE_FLAGS=" $RELEASE_FLAGS --flag -static"
33
117
fi
118
+
119
+ if [ " $OMP " = true ]; then
120
+ RELEASE_FLAGS=" $RELEASE_FLAGS --flag -fopenmp"
121
+ fi
122
+
123
+ cd ../fpm
124
+ " $INSTALL_PATH /fpm" run $RELEASE_FLAGS --runner mv -- " $INSTALL_PATH /"
125
+
126
+ if [ -x " $INSTALL_PATH /fpm" ]; then
127
+ echo " fpm installed successfully to $INSTALL_PATH "
128
+ else
129
+ echo " ERROR: fpm installation unsuccessful: fpm not found in $INSTALL_PATH "
130
+ exit 1
131
+ fi
0 commit comments