Skip to content

Commit 32c96e5

Browse files
authored
Merge pull request #357 from LKedward/update-install-script
Update: install script for Fortran fpm
2 parents 5546685 + 50390f3 commit 32c96e5

File tree

2 files changed

+117
-25
lines changed

2 files changed

+117
-25
lines changed

README.md

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -72,32 +72,26 @@ $ cd fpm/
7272

7373
#### Build a bootstrap version of fpm
7474

75-
You can use the install script to perform the build of the Haskell version of *fpm* with:
75+
You can use the install script to bootstrap and install *fpm*:
7676

7777
```bash
7878
$ ./install.sh
7979
```
8080

81-
On Linux, the above command installs `fpm` to `${HOME}/.local/bin/`.
82-
83-
Now you can build the Fortran *fpm* version with
81+
By default, the above command installs `fpm` to `${HOME}/.local/bin/`.
82+
To specify an alternative destination use the `--prefix=` flag, for example:
8483

8584
```bash
86-
$ cd fpm/
87-
$ fpm build
85+
$ ./install.sh --prefix=/usr/local
8886
```
8987

90-
Test that everything is working as expected
88+
which will install *fpm* to `/usr/local/bin`.
9189

92-
```bash
93-
$ fpm test
94-
```
95-
96-
Finally, install the Fortran *fpm* version with
90+
To test that everything is working as expected you can now build *fpm*
91+
with itself and run the tests with:
9792

9893
```bash
99-
$ fpm run --runner mv -- ~/.local/bin
94+
$ cd fpm
95+
$ fpm test
10096
```
10197

102-
Or choose another location if you do not want to overwrite the bootstrapping version.
103-
From now on you can rebuild *fpm* with your Fortran *fpm* version.

install.sh

Lines changed: 108 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,131 @@
11
#!/bin/sh
22

3-
set -u # error on use of undefined variable
43
set -e # exit on error
54

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 describe --tag --abbrev=0)
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"
777

878
if command -v stack 1> /dev/null 2>&1 ; then
9-
echo "found stack"
79+
echo "Found stack"
1080
else
1181
echo "Haskell stack not found."
12-
echo "Installing Haskell stack to."
82+
echo "Installing Haskell stack"
1383
curl -sSL https://get.haskellstack.org/ | sh
1484
if command -v stack 1> /dev/null 2>&1 ; then
1585
echo "Haskell stack installation successful."
1686
else
17-
echo "Haskell stack installation unsuccessful."
87+
echo "ERROR: Haskell stack installation unsuccessful."
1888
exit 1
1989
fi
2090
fi
2191

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
24102
fi
25103

26104
cd bootstrap
27105
stack install
28106

29-
if [ -x "$install_path/fpm" ]; then
30-
echo "fpm installed successfully to $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"
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"
31128
else
32-
echo "fpm installation unsuccessful: fpm not found in $install_path"
129+
echo "ERROR: fpm installation unsuccessful: fpm not found in $INSTALL_PATH"
130+
exit 1
33131
fi

0 commit comments

Comments
 (0)