From 7b96c0630492c8fe89ab304cccb9ee8bb6ce8a72 Mon Sep 17 00:00:00 2001 From: Stefano Zaghi Date: Wed, 5 Oct 2016 14:19:19 +0200 Subject: [PATCH 1/2] add install script --- install.sh | 184 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 184 insertions(+) create mode 100755 install.sh diff --git a/install.sh b/install.sh new file mode 100755 index 00000000..627f7848 --- /dev/null +++ b/install.sh @@ -0,0 +1,184 @@ +#!/bin/bash - +# +# File: intstall.sh +# +# Description: A utility script that builds FLAP project +# +# License: GPL3+ +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +# + +# DEBUGGING +set -e +set -C # noclobber + +# INTERNAL VARIABLES AND INITIALIZATIONS +readonly USERNAME="szaghi" +readonly PROJECT="FLAP" +readonly GITHUB="https://github.com/$USERNAME/$PROJECT" +readonly PROGRAM=`basename "$0"` + +function projectdownload () { + if [ $VERBOSE -eq 1 ]; then + echo "download project" + fi + + if command -v $DOWNLOAD >/dev/null 2>&1; then + if [ $VERBOSE -eq 1 ]; then + echo " using $DOWNLOAD" + fi + else + echo "error: $DOWNLOAD tool (to download project) not found" + exit 1 + fi + + if [ "$DOWNLOAD" == "git" ]; then + git clone --recursive $GITHUB + cd $PROJECT + git submodule update --init --recursive + cd - + elif [ "$DOWNLOAD" == "wget" ]; then + wget $(curl -s https://api.github.com/repos/$USERNAME/$PROJECT/releases/latest | grep 'browser_' | cut -d\" -f4) + tar xf $PROJECT.tar.gz + rm -f $PROJECT.tar.gz + fi + + if [ $VERBOSE -eq 1 ]; then + echo "project downloaded into: $PROJECT" + fi +} + +function projectbuild () { + if [ $VERBOSE -eq 1 ]; then + echo "build project" + fi + + if [ "$BUILD" == "fobis" ]; then + BUILD="FoBiS.py" + fi + + if command -v $BUILD >/dev/null 2>&1; then + if [ $VERBOSE -eq 1 ]; then + echo " using $BUILD" + fi + else + echo "error: $BUILD tool (to build project) not found" + exit 1 + fi + + if [ "$BUILD" == "FoBiS.py" ]; then + FoBiS.py build -mode static-gnu + elif [ "$BUILD" == "make" ]; then + make -j 1 STATIC=yes + elif [ "$BUILD" == "cmake" ]; then + mkdir -p static + cd static + cmake ../ + make + cd ../ + fi +} + +function usage () { + echo "Install script of $PROJECT" + echo "Usage:" + echo + echo "$PROGRAM --help|-?" + echo " Print this usage output and exit" + echo + echo "$PROGRAM --download|-d [--verbose|-v]" + echo " Download the project" + echo + echo " --download|-d [arg] Download the project, arg=git|wget to download with git or wget respectively" + echo " --verbose|-v Output verbose mode activation" + echo + echo "$PROGRAM --build|-b [--verbose|-v]" + echo " Build the project" + echo + echo " --build|-b [arg] Build the project, arg=fobis|make|cmake to build with FoBiS.py, GNU Make or CMake respectively" + echo " --verbose|-v Output verbose mode activation" + echo + echo "Examples:" + echo + echo "$PROGRAM --download git" + echo "$PROGRAM --build make" + echo "$PROGRAM --download wget --build cmake" +} + +DOWNLOAD=0 +BUILD=0 +VERBOSE=0 + +# RETURN VALUES/EXIT STATUS CODES +readonly E_BAD_OPTION=254 + +# PROCESS COMMAND-LINE ARGUMENTS +if [ $# -eq 0 ]; then + usage + exit 0 +fi +while test $# -gt 0; do + if [ x"$1" == x"--" ]; then + # detect argument termination + shift + break + fi + case $1 in + --download | -d ) + shift + DOWNLOAD="$1" + shift + ;; + + --build | -b ) + shift + BUILD="$1" + shift + ;; + + --verbose | -v ) + shift + VERBOSE=1 + ;; + + -? | --help ) + usage + exit + ;; + + -* ) + echo "Unrecognized option: $1" >&2 + usage + exit $E_BAD_OPTION + ;; + + * ) + break + ;; + esac +done + +if [ "$DOWNLOAD" != "0" ] && [ "$BUILD" == "0" ]; then + projectdownload +elif [ "$DOWNLOAD" == "0" ] && [ "$BUILD" != "0" ]; then + projectbuild +elif [ "$DOWNLOAD" != "0" ] && [ "$BUILD" != "0" ]; then + projectdownload + cd $PROJECT + projectbuild +fi + +exit 0 From e48da854c9989f61c85744fdcf7cff2569e4cc61 Mon Sep 17 00:00:00 2001 From: Stefano Zaghi Date: Wed, 5 Oct 2016 14:38:45 +0200 Subject: [PATCH 2/2] update README with install script doc --- README.md | 88 +++++++++++++++++++++++++++++++++---------------------- 1 file changed, 53 insertions(+), 35 deletions(-) diff --git a/README.md b/README.md index 58a7cbba..0b62ca0a 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,7 @@ A KISS pure Fortran Library for building powerful, easy-to-use, elegant command --- -| [What is FLAP?](#what-is-flap) | [Main features](#main-features) | [Copyrights](#copyrights) | [Documentation](#documentation) | [Download & Compile](#download-and-compile) | +| [What is FLAP?](#what-is-flap) | [Main features](#main-features) | [Copyrights](#copyrights) | [Documentation](#documentation) | [Download & Compile](#download-and-build) | --- @@ -257,42 +257,17 @@ Go to [Top](#top) --- -## Download and Compile +## Download and Build FLAP is a Fortran library composed by several modules. -Before download and compile the library you must check the [requirements](https://github.com/szaghi/FLAP/wiki/Requirements). +> Before download and compile the library you must check the [requirements](https://github.com/szaghi/FLAP/wiki/Requirements). -### Download ++ [Download](#download) ++ [Build](#build) ++ [Install script](#install-script) -The tree structure of the FLAP project is the following: -```bash -. -├── CONTRIBUTING.md -├── fobos -├── LICENSE.bsd-2.md -├── LICENSE.bsd-3.md -├── LICENSE.gpl3.md -├── LICENSE.mit.md -├── makedoc.sh -├── makefile -├── README.md -└── src - ├── lib - │   ├── flap_command_line_arguments_group_t.f90 - │   ├── flap_command_line_argument_t.F90 - │   ├── flap_command_line_interface_t.F90 - │   ├── flap.f90 - │   ├── flap_object_t.f90 - │   └── flap_utils_m.f90 - ├── tests - │   ├── test_basic.f90 - │   ├── test_choices_logical.f90 - │   ├── test_nested.f90 - │   └── test_string.f90 - └── third_party - └── PENF -``` +### Download To download all the available releases and utilities (fobos, license, readme, etc...), it can be convenient to _clone_ whole the project: @@ -302,7 +277,7 @@ git clone --recursive https://github.com/szaghi/FLAP Alternatively, you can directly download a release from GitHub server, see the [ChangeLog](https://github.com/szaghi/FLAP/wiki/ChangeLog). -### Compile +### Build The most easy way to compile FLAP is to use [FoBiS.py](https://github.com/szaghi/FoBiS) within the provided fobos file. @@ -418,7 +393,7 @@ It is convenient to clone the whole FLAP repository and run a *standard* make: ```shell git clone --recursive https://github.com/szaghi/FLAP cd FLAP -make +make -j 1 ``` This commands build all tests (executables are in `exe/` directory). To build only the library (statically linked) type: @@ -426,7 +401,7 @@ This commands build all tests (executables are in `exe/` directory). To build on ```shell git clone --recursive https://github.com/szaghi/FLAP cd FLAP -make STATIC=yes +make -j 1 STATIC=yes ``` ### Build by means of CMake @@ -456,4 +431,47 @@ make ctest ``` +### Install script + +FLAP ships a bash script that is able to automatize the download and build steps. The script, `install.sh` has the following usage: + +```shell +→ ./install.sh +Install script of FLAP +Usage: + +install.sh --help|-? + Print this usage output and exit + +install.sh --download|-d [--verbose|-v] + Download the project + + --download|-d [arg] Download the project, arg=git|wget to download with git or wget respectively + --verbose|-v Output verbose mode activation + +install.sh --build|-b [--verbose|-v] + Build the project + + --build|-b [arg] Build the project, arg=fobis|make|cmake to build with FoBiS.py, GNU Make or CMake respectively + --verbose|-v Output verbose mode activation + +Examples: + +install.sh --download git +install.sh --build make +install.sh --download wget --build cmake +``` + +> The script does not cover all possibilities. + +The script is able to: + ++ download a new fresh-clone of the latest master-release by means of: + + git + + wget ++ build a fresh-clone project as static-linked library by means of: + + FoBiS.py + + GNU Make + + CMake + Go to [Top](#top)