File: build_RQuantLib.sh

package info (click to toggle)
rquantlib 0.4.26-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,312 kB
  • sloc: cpp: 3,560; sh: 69; makefile: 6; ansic: 4
file content (147 lines) | stat: -rw-r--r-- 4,793 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#!/bin/sh
#set -x
set -e

###############################################################################
# NOTES:
#
# All directories must be specified as Windows paths (e.g. C:/Windows)
#
# This file has only been tested using MinGW's msys_1.0. Attempts to use msys2
# were not successful. Use msys.bat to call build_RQuantLib.sh
#
# Download QuantLib and boost sources and unzip them into $BUILD_ROOT/src.
# Update the $BOOST_VERSION and $QL_VERSION environment variables to reflect
# the versions used.
#
# The current RQuantLib Makefile deletes all object files and downloads the
# pre-built QuantLib library from https://github.com/rwinlib/quantlib. Update
# the Makefile to point to your local libQuantLib.a and remove/comment the
# 'make all' commands to prevent the deletion and download.

###############################################################################
# build environment
BOOST_VERSION=1_68_0
QL_VERSION=1.14
RQL_VERSION=0.4.5.2
BUILD_ROOT="E:/build"
R_TOOLS_DIR="E:/R/Rtools35"

BINPREF=$R_TOOLS_DIR/mingw_32/bin/
BINPREF64=$R_TOOLS_DIR/mingw_64/bin/

QUANTLIB_SRC="$BUILD_ROOT/src/QuantLib-$QL_VERSION"
BOOSTLIB="$BUILD_ROOT/src/boost_$BOOST_VERSION"
QUANTLIB_ROOT="$BUILD_ROOT/QuantLib"

###############################################################################
# Check Rtools locations
if [ ! -d "$R_TOOLS_DIR/mingw_32" ]; then
    echo "$R_TOOLS_DIR/mingw_32 not found"
    exit 1
fi
if [ ! -d "$R_TOOLS_DIR/mingw_64" ]; then
    echo "$R_TOOLS_DIR/mingw_64 not found"
    exit 1
fi
# Check for boost headers
if [ ! -d "$BOOSTLIB/boost" ]; then
    echo "Did not find boost headers in $BOOSTLIB/boost"
    exit 1
fi
# Check for quantlib source
if [ ! -d "$QUANTLIB_SRC" ]; then
    echo "Did not find QuantLib source in $QUANTLIB_SRC"
    exit 1
fi
# Ensure there is an /etc/fstab
if [ -n "/etc/fstab" ]; then
    touch /etc/fstab
fi

# Install architecture-specific files into these directories via the
# --exec-prefix argument to QuantLib's configure script
mkdir -p $QUANTLIB_ROOT/lib/i386
mkdir -p $QUANTLIB_ROOT/lib/x64

# Ensure a mount point exists and add bin/ to PATH
mkdir -p /mingw
export PATH="$(cygpath -u $R_TOOLS_DIR)/bin":/mingw/bin:$PATH

# Use ccache if available
if [ -x "$(command -v ccache)" ]; then
	export PATH=/usr/lib/ccache/bin:$PATH
fi

################################################################################
## 32-bit QuantLib
mount --replace $R_TOOLS_DIR/mingw_32 /mingw

    ## Create and change to build directory
    #mkdir -p $BUILD_ROOT/ql32
    #cd $BUILD_ROOT/ql32

# QuantLib 'buglet' prevents building outside source directory
cd $QUANTLIB_SRC

# Clean prior build before (re-)running configure
if [ -f "Makefile" ]; then
  make -j6 distclean
fi

CXXFLAGS="-g0 -O2" $QUANTLIB_SRC/configure --prefix=$QUANTLIB_ROOT \
    --exec-prefix=$QUANTLIB_ROOT/lib/i386 --with-boost-include=$BOOSTLIB \
    --enable-intraday --enable-shared --enable-static --with-gnu-ld
make -j6
make install

# Shrink quantlib library
cp $QUANTLIB_ROOT/lib/i386/libQuantLib.a \
   $QUANTLIB_ROOT/lib/i386/libQuantLib.a.bak
strip --strip-unneeded $QUANTLIB_ROOT/lib/i386/libQuantLib.a

################################################################################
## 64-bit QuantLib
mount --replace $R_TOOLS_DIR/mingw_64 /mingw

  ## Create and change to build directory
  #mkdir -p $BUILD_ROOT/ql64
  #cd $BUILD_ROOT/ql64

# QuantLib 'bug' prevents building outside source directory
cd $QUANTLIB_SRC

# Clean prior build before (re-)running configure
if [ -f "Makefile" ]; then
  make -j6 distclean
fi

CXXFLAGS="-m64 -g0 -O2" $QUANTLIB_SRC/configure --prefix=$QUANTLIB_ROOT \
    --exec-prefix=$QUANTLIB_ROOT/lib/x64 --with-boost-include=$BOOSTLIB \
    --enable-intraday --enable-shared --enable-static --with-gnu-ld
make -j6
make install

## Shrink quantlib library
cp $QUANTLIB_ROOT/lib/x64/libQuantLib.a \
   $QUANTLIB_ROOT/lib/x64/libQuantLib.a.bak
strip --strip-unneeded $QUANTLIB_ROOT/lib/x64/libQuantLib.a

###############################################################################
# Install RQuantLib
#export QUANTLIB_ROOT
#export BOOSTLIB
# RQuantLib expects headers in $QUANTLIB_ROOT/ql, not $QUANTLIB_ROOT/include/ql
#ln -s $QUANTLIB_ROOT/include/ql $QUANTLIB_ROOT/.

#mkdir -p $BUILD_ROOT/library
#R_CMD="Rscript -e 'install.packages(c(\"Rcpp\",\"zoo\"), lib = \"$BUILD_ROOT/library\")'"
#Rscript -e $R_CMD
#
## Need to remove the OS_type: unix from DESCRIPTION
#cd $BUILD_ROOT
#R CMD INSTALL RQuantLib_${RQL_VERSION}.tar.gz --library=$BUILD_ROOT/library --no-clean-on-error --preclean --build
#
## run tests on each system
#Rscript --arch x64 -e 'source(system.file(package=\"RQuantLib\", \"unitTests/runTests.R\"))'
#Rscript --arch i386 -e 'source(system.file(package=\"RQuantLib\", \"unitTests/runTests.R\"))'