Saturday, December 31, 2016

How to create bootable PIXEL USB stick for Mac

The Debian+PIXEL is for x86 platforms. The PIXEL ISO, which is a 1.3GB download.


The latest RASPBERRY PI DESKTOP image is DEBIAN STRETCH (add nomodeset in enterprise.cfg) https://downloads.raspberrypi.org/rpd_x86/images/rpd_x86-2017-12-01/2017-11-16-rpd-x86-stretch.iso

Reference : Fixing booting of the x86 image on Macs

Instructions to create EFI bootable USB stick for Mac. (tested working on my old MacBook Air 11-inch, Late 2010, Intel Core 2 Duo)

shell script    Select all
And here are the instructions to create EFI bootable USB stick on Mac # Running on Mac # list disk volumes diskutil list # assume format USB stick (64G) on /dev/disk1 with 2 partitions 8g and remaining 55g respectively # if for 32G USB stick, the 2 partition sizes can be divided into 4g and remaining 27g respectively sudo diskutil partitionDisk /dev/disk1 MBRFormat FAT32 LINUX 8g FAT32 PERSISTENCE 0b # for older Mac OSX 10.6, the partition type is "MS-DOS FAT32" # sudo diskutil partitionDisk /dev/disk1 MBRFormat "MS-DOS FAT32" LINUX 8g "MS-DOS FAT32" PERSISTENCE 0b mkdir -p /Volumes/LINUX/efi/boot # Download Enterprise-0.4.0.tar.gz to ~/Download # from https://github.com/SevenBits/Enterprise/releases cd ~/Downloads curl -OL https://github.com/SevenBits/Enterprise/releases/download/v0.4.0/Enterprise-0.4.0.tar.gz tar xzvf Enterprise-0.4.0.tar.gz cp ~/Downloads/Enterprise-0.4.0/*.efi /Volumes/LINUX/efi/boot/ cp ~/Downloads/2016-12-13-pixel-x86-jessie.iso /Volumes/LINUX/efi/boot/boot.iso # create enterprise.cfg cat > /Volumes/LINUX/efi/boot/enterprise.cfg << EOF autoboot 0 entry Debian family Debian initrd /live/initrd1.img kernel /live/vmlinuz1 findiso=/efi/boot/boot.iso boot=live config live-config quiet splash EOF # umount disk sudo diskutil unmountDisk disk1 # Reboot Mac and press Option key on restart and select EFI Boot for boot menu # Running on Debian PIXEL sudo fdisk -l #assume /dev/sdb is the USB stick sudo fdisk /dev/sdb # (d) (2) to delete partition 2 # and then (n) (p) (2) to recreate primary partition 2 for Linux in fdisk # (w) to write to partition table and quit fdisk # Reboot to let partition table effective # Running on Debian PIXEL # unmount /dev/sdb2 sudo umount /dev/sdb2 # format and label /dev/sdb2 sudo mkfs.ext4 -L persistence /dev/sdb2 # rename /dev/sdb2 if manually # sudo e2label /dev/sdb2 "persistence" # create persistence.conf sudo mkdir -p /mnt/persistence sudo mount -t ext4 /dev/sdb2 /mnt/persistence echo / union | sudo tee /mnt/persistence/persistence.conf #unmount /dev/sdb2 sudo umount /dev/sdb2 # Reboot # Running on Mac # recreate enterprise.cfg with persistence cat > /Volumes/LINUX/efi/boot/enterprise.cfg << EOF autoboot 0 entry Debian family Debian initrd /live/initrd1.img kernel /live/vmlinuz1 findiso=/efi/boot/boot.iso boot=live config live-config quiet splash persistence EOF # Reboot and Running on Debian PIXEL to verify the persistence mounting df -h


Additional configurations or installation for PIXEL using Terminal
shell script    Select all
# username of this image is pi # password is raspberry #keyboard configuration #Preferences -> Mouse and Keyboard Settings -> Keyboard -> Keyboard Layout... sudo dpkg-reconfigure keyboard-configuration #reload the keymap (need reboot to be effective) sudo invoke-rc.d keyboard-setup start #reset timezone sudo dpkg-reconfigure tzdata #generate locale sudo dpkg-reconfigure locales sudo locale-gen en_US.UTF-8 # requires reboot sudo update-locale LC_ALL="en_US.UTF-8" #scan private hidden SSID network sudo iwlist wlan0 scanning essid "yourSSID" # then edit /etc/wpa_supplicant/wpa_supplicant.conf and add scan_ssid=1 in the network block for auto scan #reset wireless interface sudo ifdown wlan0 sudo ifup wlan0 # or sudo service network-manager restart # For Buster or above sudo vi /etc/network/interfaces.d/wlan0 wpa-scan-ssid 1 wpa-ssid "Your SSID network" wpa-key-mgmt WPA-PSK wpa-psk "password" # then reboot #reinstall sshd on the system sudo apt-get update sudo apt-get purge openssh-server sudo apt-get install -y openssh-server ssh # List available upgrade sudo apt-get update sudo apt-get -V -u --assume-no upgrade #two fingers tap on touch pad for Right Click synclient tapbutton2=3 #node.js x86 (32 bit) download cd $HOME wget --no-check-certificate https://nodejs.org/dist/v6.9.2/node-v6.9.2-linux-x86.tar.xz tar xJvf node-v6.9.2-linux-x86.tar.xz # put this in $HOME/.bashrc export PATH=$HOME/node-v6.9.2-linux-x86/bin:$PATH #google app engine for python download cd $HOME wget --no-check-certificate https://storage.googleapis.com/appengine-sdks/featured/google_appengine_1.9.49.zip unzip google_appengine_1.9.49.zip # put this in $HOME/.bashrc export PATH=$HOME/google_appengine:$PATH #Traditional Chinese input method, need reboot to be effective and control+space to activate #Choose Auto in Preferences -> Input Method sudo apt-get install -y scim-tables-zh im-config # install additional Chinese fonts sudo apt-get install -y ttf-wqy-microhei ttf-wqy-zenhei xfonts-wqy # install vlc sudo apt-get install -y vlc browser-plugin-vlc # restart control panel lxpanelctl restart #install spotify #add repo and certificate see instructions here https://www.spotify.com/download/linux/ sudo apt-get update sudo apt-get install -y spotify-client Here is Visual Studio Code (32 bits) for Debian https://go.microsoft.com/fwlink/?LinkID=760680








EFI bootable USB stick for Ubuntu 16.10 Exton x64 platforms (PC or Mac)

exton-os-64bit-mate-refracta-1840mb-161231.iso (which is Ubuntu 16.10 for x64 platforms) can be downloaded from here https://sourceforge.net/projects/exton-os/ and copy to /Volumes/LINUX/efi/boot/ as boot.iso

or alternatively use the exton-os-light-64bit-isohybrid-970mb-161021.iso image from https://sourceforge.net/projects/exton-os/files/

The setup for this image for persistence in Mac is similar to the Debian PIXEL above
except the enterprise.cfg content should be
shell script    Select all
cat > /Volumes/LINUX/efi/boot/enterprise.cfg << EOF autoboot 0 entry Ubuntu family Ubuntu initrd /live/initrd.img kernel /live/vmlinuz findiso=/efi/boot/boot.iso boot=live username=live config live-config splash persistence EOF


Additional configuration and installation for Ubuntu 16.10 Exton x64 using Terminal
shell script    Select all
# additional installation for swift 3.0 for Exton OS Ubuntu 16.10 # username of this Ubuntu image is root # password is root sudo apt-get update sudo apt-get install -y libicu-dev clang-3.6 git cd $HOME # To download swift 3 release for Ubuntu 16.04 instead as the one for ubuntu1610 has bugs wget --no-check-certificate https://swift.org/builds/swift-3.0.2-release/ubuntu1604/swift-3.0.2-RELEASE/swift-3.0.2-RELEASE-ubuntu16.04.tar.gz tar xzvf $HOME/swift-3.0.2-RELEASE-ubuntu16.04.tar.gz export PATH=$HOME/swift-3.0.2-RELEASE-ubuntu16.04/usr/bin:$PATH #wget --no-check-certificate https://swift.org/builds/development/ubuntu1610/swift-DEVELOPMENT-SNAPSHOT-2017-01-05-a/swift-DEVELOPMENT-SNAPSHOT-2017-01-05-a-ubuntu16.10.tar.gz #tar xzvf $HOME/swift-DEVELOPMENT-SNAPSHOT-2017-01-05-a-ubuntu16.10.tar.gz #export PATH=$HOME/swift-DEVELOPMENT-SNAPSHOT-2017-01-05-a-ubuntu16.10/usr/bin:$PATH sudo update-alternatives --install /usr/bin/clang clang /usr/bin/clang-3.6 100 sudo update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-3.6 100 swift --version #node.js x64 (64 bit) download cd $HOME wget --no-check-certificate https://nodejs.org/dist/v6.9.3/node-v6.9.3-linux-x64.tar.xz tar xJvf node-v6.9.3-linux-x64.tar.xz # put this in $HOME/.bashrc export PATH=$HOME/node-v6.9.3-linux-x64/bin:$PATH node --version npm --version #install spotify sudo apt-get update sudo apt-get install -y spotify-client #Traditional Chinese input method sudo apt-get install -y ibus-cangjie ibus restart #then choose input method in System -> Preferences -> Other # install R # see insturctions here https://cloud.r-project.org/bin/linux/ubuntu/README.html cd $HOME echo deb https://cran.cnr.berkeley.edu//bin/linux/ubuntu yakkety/ | sudo tee /etc/apt/sources.list.d/r.list sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys E084DAB9 gpg --keyserver keyserver.ubuntu.com --recv-key E084DAB9 gpg -a --export E084DAB9 | sudo apt-key add - sudo apt-get update sudo apt-get install -y r-base # download R Studio from https://www.rstudio.com/products/rstudio/download/ and install sudo apt-get install -y libjpeg62 libgstreamer0.10-0 libgstreamer-plugins-base0.10-0 cd ~/Downloads wget --no-check-certificate https://download1.rstudio.org/rstudio-1.0.136-amd64.deb sudo dpkg -i rstudio-1.0.136-amd64.deb # install Quantlib 1.9.1 sudo apt-get update sudo apt-get install -y libboost1.60-all-dev cd $HOME wget https://ncu.dl.sourceforge.net/project/quantlib/QuantLib/1.9.1/QuantLib-1.9.1.tar.gz tar xzvf QuantLib-1.9.1.tar.gz cd QuantLib-1.9.1 ./autogen.sh ./configure --prefix=/usr make -j9 sudo make install # Install RQuantLib Package in R # install.packages("RQuantLib") # install Quantlib-Python cd $HOME wget https://jaist.dl.sourceforge.net/project/quantlib/QuantLib/1.9/other%20languages/QuantLib-SWIG-1.9.tar.gz tar xzvf QuantLib-SWIG-1.9.tar.gz cd QuantLib-SWIG-1.9 ./autogen.sh ./configure make -C Python sudo make -C Python install # upgrade pip sudo apt-get update sudo apt-get install -y python-pip pip install --upgrade pip sudo pip install numpy # install ipython sudo pip install ipython # install jupyter notebook sudo pip install jupyter # List available upgrade sudo apt-get update sudo apt list --upgradeable # test QuantLib and QuantLib-Python cd $HOME cat > $HOME/qlversion.cpp <<EOF #include <iostream> #include <ql/version.hpp> int main() { std::cout << "Current QL Version:" << QL_LIB_VERSION << std::endl; return 0; } EOF g++ qlversion.cpp -o qlversion ./qlversion cat > $HOME/swap.py <<EOF import numpy as np import QuantLib as ql # Set Evaluation Date today = ql.Date(31,3,2015) ql.Settings.instance().setEvaluationDate(today) # Setup the yield termstructure rate = ql.SimpleQuote(0.03) rate_handle = ql.QuoteHandle(rate) dc = ql.Actual365Fixed() disc_curve = ql.FlatForward(today, rate_handle, dc) disc_curve.enableExtrapolation() hyts = ql.YieldTermStructureHandle(disc_curve) discount = np.vectorize(hyts.discount) start = ql.TARGET().advance(today, ql.Period('2D')) end = ql.TARGET().advance(start, ql.Period('10Y')) nominal = 1e7 typ = ql.VanillaSwap.Payer fixRate = 0.03 fixedLegTenor = ql.Period('1y') fixedLegBDC = ql.ModifiedFollowing fixedLegDC = ql.Thirty360(ql.Thirty360.BondBasis) index = ql.Euribor6M(ql.YieldTermStructureHandle(disc_curve)) spread = 0.0 fixedSchedule = ql.Schedule(start, end, fixedLegTenor, index.fixingCalendar(), fixedLegBDC, fixedLegBDC, ql.DateGeneration.Backward, False) floatSchedule = ql.Schedule(start, end, index.tenor(), index.fixingCalendar(), index.businessDayConvention(), index.businessDayConvention(), ql.DateGeneration.Backward, False) swap = ql.VanillaSwap(typ, nominal, fixedSchedule, fixRate, fixedLegDC, floatSchedule, index, spread, index.dayCounter()) engine = ql.DiscountingSwapEngine(ql.YieldTermStructureHandle(disc_curve)) swap.setPricingEngine(engine) print(swap.NPV()) print(swap.fairRate()) EOF python swap.py sudo apt-get install -y git cd $HOME git clone git://github.com/mmport80/QuantLib-with-Python-Blog-Examples.git cd QuantLib-with-Python-Blog-Examples/ python blog_frn_example.py








If for Debian PIXEL-x86 and Ubuntu-16.10 Exton-x64 together in one USB stick with persistence
shell script    Select all
# Running on Mac # copy iso to USB stick rm -f /Volumes/LINUX/efi/boot/boot.iso cp ~/Downloads/2016-12-13-pixel-x86-jessie.iso /Volumes/LINUX/efi/boot/pixel.iso cp ~/Downloads/exton-os-64bit-mate-refracta-1840mb-161231.iso /Volumes/LINUX/efi/boot/exton.iso # set up enterprise.cfg in USB stick and assume persistence is already formatted as ext4 with persistence.conf cat > /Volumes/LINUX/efi/boot/enterprise.cfg << EOF entry Debian PIXEL family Debian iso pixel.iso initrd /live/initrd1.img kernel /live/vmlinuz1 findiso=/efi/boot/pixel.iso boot=live config live-config quiet splash persistence entry Debian STRETCH family Debian iso stretch.iso initrd /live/initrd1.img kernel /live/vmlinuz1 findiso=/efi/boot/stretch.iso boot=live config live-config quiet splash nomodeset persistence entry Ubuntu 16.10 Exton family Ubuntu iso exton.iso initrd /live/initrd.img kernel /live/vmlinuz findiso=/efi/boot/exton.iso boot=live username=live config live-config splash persistence EOF








Add the Original Ubuntu 16.04 from Ubuntu to the EFI bootable USB stick

For the Original ubuntu-16.04.1-desktop-amd64.iso image, add it by copying the downloaded iso image to the LINUX FAT32 partition and create the enterprise.cfg as below
shell script    Select all
# Running on Mac # copy iso to USB stick rm -f /Volumes/LINUX/efi/boot/boot.iso cp ~/Downloads/2016-12-13-pixel-x86-jessie.iso /Volumes/LINUX/efi/boot/pixel.iso cp ~/Downloads/exton-os-64bit-mate-refracta-1840mb-161231.iso /Volumes/LINUX/efi/boot/exton.iso cp ~/Downloads/ubuntu-16.04.1-desktop-amd64.iso /Volumes/LINUX/efi/boot/ubuntu.iso cat > /Volumes/LINUX/efi/boot/enterprise.cfg << EOF entry Debian PIXEL family Debian iso pixel.iso initrd /live/initrd1.img kernel /live/vmlinuz1 findiso=/efi/boot/pixel.iso boot=live config live-config quiet splash persistence entry Debian STRETCH family Debian iso stretch.iso initrd /live/initrd1.img kernel /live/vmlinuz1 findiso=/efi/boot/stretch.iso boot=live config live-config quiet splash nomodeset persistence entry Ubuntu 16.10 Exton family Ubuntu iso exton.iso initrd /live/initrd.img kernel /live/vmlinuz findiso=/efi/boot/exton.iso boot=live username=live config live-config splash persistence entry Ubuntu 16.04-1 family Ubuntu iso ubuntu.iso initrd /casper/initrd.lz kernel /casper/vmlinuz.efi findiso=/efi/boot/ubuntu.iso file=/cdrom/preseed/ubuntu.seed boot=casper persistent quiet splash --- EOF # Reboot and running in the new Ubuntu 16.04-1 # it requires a Linux partition named casper-rw in order to enable the persistent feature. # So we need to create a third partition in Linux and then format it. # Running on Ubuntu 16.04 # First remove the second partition and recreate second partition with smaller size and add a third partition to it sudo fdisk -l #assume /dev/sdb is the USB stick # umount the partition 2 in order to modify it sudo umount /dev/sdb2 # partition the USB stick sudo fdisk /dev/sdb # (d) (2) to delete partition 2 # and then (n) (p) (2) to recreate primary partition 2 for Linux in fdisk # choose size say 20G if for 64G USB stick # and then (n) (p) (3) to recreate primary partition 3 for Linux in fdisk # choose size say remaining sectors # (w) to write to partition table and quit fdisk # Reboot to let partition table effective # Running on Ubuntu 16.04-1 # format the second partition with label persistence and add persistence.conf sudo mkfs.ext4 -L persistence /dev/sdb2 sudo mkdir -p /media/ubuntu/persistence sudo mount /dev/sdb2 /media/ubuntu/persistence echo / union | sudo tee /media/ubuntu/persistence/persistence.conf # format the third partition with label casper-rw sudo mkfs.ext4 -L casper-rw /dev/sdb3 # Reboot to start other configuration and installation


Additional configuration and installation for Ubuntu 16.04-1 using Terminal
shell script    Select all
# additional installation for swift 3.0.2 for Ubuntu 16.04 # username of this Ubuntu image is ubuntu # password is ubuntu # Additional installation needs to add these lines in /etc/apt/sources.list echo "deb http://archive.ubuntu.com/ubuntu/ xenial universe" | sudo tee --append /etc/apt/sources.list echo "deb http://archive.ubuntu.com/ubuntu/ xenial-updates universe" | sudo tee --append /etc/apt/sources.list echo "deb http://security.ubuntu.com/ubuntu/ xenial-security universe" | sudo tee --append /etc/apt/sources.list # To install swift 3.0.2 release for Ubuntu 16.04-1 is sudo apt-get update # for AppStream cache update failed error sudo chmod 777 /var/cache/app-info/xapian/default -R sudo apt-get update sudo apt-get install -y libicu-dev clang-3.6 git cd $HOME wget --no-check-certificate https://swift.org/builds/swift-3.0.2-release/ubuntu1604/swift-3.0.2-RELEASE/swift-3.0.2-RELEASE-ubuntu16.04.tar.gz tar xzvf $HOME/swift-3.0.2-RELEASE-ubuntu16.04.tar.gz export PATH=$HOME/swift-3.0.2-RELEASE-ubuntu16.04/usr/bin:$PATH sudo update-alternatives --install /usr/bin/clang clang /usr/bin/clang-3.6 100 sudo update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-3.6 100 swift --version #node.js x64 (64 bit) download cd $HOME wget --no-check-certificate https://nodejs.org/dist/v6.9.3/node-v6.9.3-linux-x64.tar.xz tar xJvf node-v6.9.3-linux-x64.tar.xz # put this in $HOME/.bashrc export PATH=$HOME/node-v6.9.3-linux-x64/bin:$PATH node --version npm --version #install spotify sudo apt-get update sudo apt-get install -y spotify-client #Traditional Chinese input method sudo apt-get install -y ibus-cangjie ibus restart # install R # see insturctions here https://cloud.r-project.org/bin/linux/ubuntu/README.html cd $HOME echo deb https://cran.cnr.berkeley.edu//bin/linux/ubuntu xenial/ | sudo tee /etc/apt/sources.list.d/r.list sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys E084DAB9 gpg --keyserver keyserver.ubuntu.com --recv-key E084DAB9 gpg -a --export E084DAB9 | sudo apt-key add - sudo apt-get update sudo apt-get install -y r-base # download R Studio from https://www.rstudio.com/products/rstudio/download/ and install sudo apt-get install -y libjpeg62 libgstreamer0.10-0 libgstreamer-plugins-base0.10-0 cd ~/Downloads wget --no-check-certificate https://download1.rstudio.org/rstudio-1.0.136-amd64.deb sudo dpkg -i rstudio-1.0.136-amd64.deb # install Quantlib 1.9.1 sudo apt-get update sudo apt-get install -y libboost1.58-all-dev cd $HOME wget https://ncu.dl.sourceforge.net/project/quantlib/QuantLib/1.9.1/QuantLib-1.9.1.tar.gz tar xzvf QuantLib-1.9.1.tar.gz cd QuantLib-1.9.1 ./autogen.sh ./configure --prefix=/usr make -j9 # uninstall old library # cd ~/Downloads/QuantLib-1.9 # sudo make uninstall sudo make install # Install RQuantLib Package in R # install.packages("RQuantLib") # install Quantlib-Python cd $HOME wget http://jaist.dl.sourceforge.net/project/quantlib/QuantLib/1.9/other%20languages/QuantLib-SWIG-1.9.tar.gz tar xzvf QuantLib-SWIG-1.9.tar.gz cd QuantLib-SWIG-1.9 ./autogen.sh ./configure # if there is "out of memory" error use this below to configure # ./configure CXXFLAGS="--param ggc-min-expand=1 --param ggc-min-heapsize=32768" make -C Python # uninstall old QuantLib-Python package # sudo -H pip uninstall QuantLib-Python sudo make -C Python install # upgrade pip and install numpy sudo apt-get update sudo apt-get install -y python-pip sudo -H pip install --upgrade pip sudo -H pip install numpy # test QuantLib and QuantLib-Python cd $HOME cat > $HOME/qlversion.cpp <<EOF #include <iostream> #include <ql/version.hpp> int main() { std::cout << "Current QL Version:" << QL_LIB_VERSION << std::endl; return 0; } EOF g++ qlversion.cpp -o qlversion ./qlversion sudo apt-get install -y git cd $HOME git clone git://github.com/mmport80/QuantLib-with-Python-Blog-Examples.git cd QuantLib-with-Python-Blog-Examples/ python blog_frn_example.py # List available upgrade sudo apt-get update sudo apt list --upgradeable


install Emscripten SDK for WebAssembly
shell script    Select all
# need Debian Stretch 32 bits image or Ubuntu 64 bits # need cmake for building in Debian Stretch(32 bits) sudo apt-get update sudo apt-get install cmake libxml2-dev ocaml python-yaml # Get the emsdk repo git clone https://github.com/juj/emsdk.git # Enter that directory cd emsdk # Fetch the latest registry of available tools. ./emsdk update # Download and install the latest SDK tools. Need rebuilding libraries in Debian Stretch 32 bits ./emsdk install latest # Make the "latest" SDK "active" for the current user. (writes ~/.emscripten file) ./emsdk activate latest # Activate PATH and other environment variables in the current terminal source ./emsdk_env.sh # Test mkdir $HOME/hello cd $HOME/hello cat > $HOME/hello/hello_world.c <<EOF #include <stdio.h> int main() { printf("hello, world!\n"); return 0; } EOF # compile and test emcc hello_world.c node a.out.js emcc hello_world.c -s WASM=0 -o hello.html # start webserver and test http://localhost:8080/hello.html emrun --no_browser --port 8080 .


Sunday, November 13, 2016

How to build C++ static libraries (boost and QuantLib) for Android Studio

(1) Create standalone toolchain for Android in Mac
shell script    Select all
#create standalone toolchain for x86, x86_64, arm and arm64 #assume ndk is installed in Mac at ~/Library/Android/sdk/ndk-bundle #API level will be set to the minimum supported level for the given architecture (currently 9 for 32-bit architectures and 21 for 64-bit architectures) ~/Library/Android/sdk/ndk-bundle/build/tools/make_standalone_toolchain.py --arch x86 --install-dir ~/Library/Android/sdk/ndk-bundle/sources/android-toolchain-x86 ~/Library/Android/sdk/ndk-bundle/build/tools/make_standalone_toolchain.py --arch x86_64 --install-dir ~/Library/Android/sdk/ndk-bundle/sources/android-toolchain-x86_64 ~/Library/Android/sdk/ndk-bundle/build/tools/make_standalone_toolchain.py --arch arm --install-dir ~/Library/Android/sdk/ndk-bundle/sources/android-toolchain-arm ~/Library/Android/sdk/ndk-bundle/build/tools/make_standalone_toolchain.py --arch arm64 --install-dir ~/Library/Android/sdk/ndk-bundle/sources/android-toolchain-arm64


(2) Download and build boost for Android
shell script    Select all
# download boost source to ndk-bundle cd ~/Library/Android/sdk/ndk-bundle/sources curl -O http://ncu.dl.sourceforge.net/project/boost/boost/1.62.0/boost_1_62_0.tar.bz2 tar xjvf boost_1_62_0.tar.bz2 cd boost_1_62_0 # create the following user-config.jam at ~/Library/Android/sdk/ndk-bundle/sources/boost_1_62_0/tools/build/src/ cat > tools/build/src/user-config.jam << 'EOF' # ------------------ # Android configurations. # ------------------ import os ; local NDK_ROOT = [ os.environ NDK_ROOT ] ; # -------------------------------------------------------------------- local ANDROID_TOOLCHAIN_x86 = /sources/android-toolchain-x86 ; using gcc : x86 : $(NDK_ROOT)$(ANDROID_TOOLCHAIN_x86)/bin/i686-linux-android-g++ : <archiver>$(NDK_ROOT)$(ANDROID_TOOLCHAIN_x86)/bin/i686-linux-android-ar <compileflags>-fexceptions <compileflags>-frtti <compileflags>-fpic <compileflags>-ffunction-sections <compileflags>-funwind-tables <compileflags>-Wno-psabi <compileflags>-Wno-missing-field-initializers <compileflags>-no-canonical-prefixes <linkflags>-no-canonical-prefixes <compileflags>-Os <compileflags>-fomit-frame-pointer <compileflags>-fno-strict-aliasing <compileflags>-funswitch-loops <compileflags>-finline-limit=300 <compileflags>-Wa,--noexecstack <compileflags>-DANDROID <compileflags>-D__ANDROID__ <compileflags>-DNDEBUG <compileflags>-O2 <compileflags>-g <root>$(NDK_ROOT)$(ANDROID_TOOLCHAIN_x86)/sysroot # @Moss - Above are the 'official' android flags <architecture>x86 <compileflags>-fvisibility=hidden <compileflags>-fvisibility-inlines-hidden <compileflags>-fdata-sections <cxxflags>-D_REENTRANT <cxxflags>-D_GLIBCXX__PTHREADS <compileflags>-Wno-long-long <compileflags>-Wno-missing-field-initializers <compileflags>-Wno-unused-variable ; # -------------------------------------------------------------------- local ANDROID_TOOLCHAIN_x86_64 = /sources/android-toolchain-x86_64 ; using gcc : x86_64 : $(NDK_ROOT)$(ANDROID_TOOLCHAIN_x86_64)/bin/x86_64-linux-android-g++ : <archiver>$(NDK_ROOT)$(ANDROID_TOOLCHAIN_x86_64)/bin/x86_64-linux-android-ar <compileflags>-fexceptions <compileflags>-frtti <compileflags>-fpic <compileflags>-ffunction-sections <compileflags>-funwind-tables <compileflags>-Wno-psabi <compileflags>-Wno-missing-field-initializers <compileflags>-no-canonical-prefixes <linkflags>-no-canonical-prefixes <compileflags>-Os <compileflags>-fomit-frame-pointer <compileflags>-fno-strict-aliasing <compileflags>-funswitch-loops <compileflags>-finline-limit=300 <compileflags>-Wa,--noexecstack <compileflags>-DANDROID <compileflags>-D__ANDROID__ <compileflags>-DNDEBUG <compileflags>-O2 <compileflags>-g <root>$(NDK_ROOT)$(ANDROID_TOOLCHAIN_x86_64)/sysroot # @Moss - Above are the 'official' android flags <architecture>x86 <compileflags>-fvisibility=hidden <compileflags>-fvisibility-inlines-hidden <compileflags>-fdata-sections <cxxflags>-D_REENTRANT <cxxflags>-D_GLIBCXX__PTHREADS <compileflags>-Wno-long-long <compileflags>-Wno-missing-field-initializers <compileflags>-Wno-unused-variable ; # -------------------------------------------------------------------- local ANDROID_TOOLCHAIN_ARM = /sources/android-toolchain-arm ; using gcc : armeabi : $(NDK_ROOT)$(ANDROID_TOOLCHAIN_ARM)/bin/arm-linux-androideabi-g++ : <archiver>$(NDK_ROOT)$(ANDROID_TOOLCHAIN_ARM)/bin/arm-linux-androideabi-ar <compileflags>-fexceptions <compileflags>-frtti <compileflags>-fpic <compileflags>-ffunction-sections <compileflags>-funwind-tables <compileflags>-D__ARM_ARCH_5__ <compileflags>-D__ARM_ARCH_5T__ <compileflags>-D__ARM_ARCH_5E__ <compileflags>-D__ARM_ARCH_5TE__ <compileflags>-Wno-psabi <compileflags>-march=armv5te <compileflags>-mtune=xscale <compileflags>-msoft-float <compileflags>-mthumb <linkflags>-march=armv5te <compileflags>-Os <compileflags>-fomit-frame-pointer <compileflags>-fno-strict-aliasing <compileflags>-finline-limit=64 <compileflags>-Wa,--noexecstack <compileflags>-DANDROID <compileflags>-D__ANDROID__ <compileflags>-DNDEBUG <compileflags>-O2 <compileflags>-g <root>$(NDK_ROOT)$(ANDROID_TOOLCHAIN_ARM)/sysroot # @Moss - Above are the 'official' android flags <architecture>arm <compileflags>-fvisibility=hidden <compileflags>-fvisibility-inlines-hidden <compileflags>-fdata-sections <cxxflags>-D_REENTRANT <cxxflags>-D_GLIBCXX__PTHREADS <compileflags>-Wno-long-long <compileflags>-Wno-missing-field-initializers <compileflags>-Wno-unused-variable ; # -------------------------------------------------------------------- using gcc : armeabi_v7a : $(NDK_ROOT)$(ANDROID_TOOLCHAIN_ARM)/bin/arm-linux-androideabi-g++ : <archiver>$(NDK_ROOT)$(ANDROID_TOOLCHAIN_ARM)/bin/arm-linux-androideabi-ar <compileflags>-fexceptions <compileflags>-frtti <compileflags>-fpic <compileflags>-ffunction-sections <compileflags>-funwind-tables <compileflags>-Wno-psabi <compileflags>-march=armv7-a <compileflags>-msoft-float <compileflags>-mfpu=neon <compileflags>-mthumb <linkflags>-march=armv7-a <linkflags>-Wl,--fix-cortex-a8 <compileflags>-Os <compileflags>-fomit-frame-pointer <compileflag>-fno-strict-aliasing <compileflags>-finline-limit=64 <compileflags>-Wa,--noexecstack <compileflags>-DANDROID <compileflags>-D__ANDROID__ <compileflags>-DNDEBUG <compileflags>-O2 <compileflags>-g <root>$(NDK_ROOT)$(ANDROID_TOOLCHAIN_ARM)/sysroot # @Moss - Above are the 'official' android flags <architecture>arm <compileflags>-fvisibility=hidden <compileflags>-fvisibility-inlines-hidden <compileflags>-fdata-sections <cxxflags>-D__arm__ <cxxflags>-D_REENTRANT <cxxflags>-D_GLIBCXX__PTHREADS <compileflags>-Wno-long-long <compileflags>-Wno-missing-field-initializers <compileflags>-Wno-unused-variable ; # -------------------------------------------------------------------- local ANDROID_TOOLCHAIN_ARM64 = /sources/android-toolchain-arm64 ; using gcc : arm64_v8a : $(NDK_ROOT)$(ANDROID_TOOLCHAIN_ARM64)/bin/aarch64-linux-android-g++ : <archiver>$(NDK_ROOT)$(ANDROID_TOOLCHAIN_ARM64)/bin/aarch64-linux-android-ar <compileflags>-fexceptions <compileflags>-frtti <compileflags>-fpic <compileflags>-ffunction-sections <compileflags>-funwind-tables <compileflags>-fstack-protector <compileflags>-Wno-psabi <compileflags>-march=armv8-a <compileflags>-mtune=cortex-a53 <linkflags>-march=armv8-a <compileflags>-Os <compileflags>-fno-short-enums <compileflags>-fomit-frame-pointer <compileflags>-fno-strict-aliasing <compileflags>-finline-limit=64 <compileflags>-DANDROID <compileflags>-D__ANDROID__ <compileflags>-DNDEBUG <compileflags>-O2 <compileflags>-g <root>$(NDK_ROOT)$(ANDROID_TOOLCHAIN_ARM64)/sysroot # @Moss - Above are the 'official' android flags <architecture>arm <compileflags>-fvisibility=hidden <compileflags>-fvisibility-inlines-hidden <compileflags>-fdata-sections <cxxflags>-D_REENTRANT <cxxflags>-D_GLIBCXX__PTHREADS <compileflags>-Wno-long-long <compileflags>-Wno-missing-field-initializers <compileflags>-Wno-unused-variable ; EOF # bootstrap ./bootstrap.sh --with-libraries=atomic,chrono,date_time,exception,filesystem,graph,iostreams,math,program_options,random,regex,serialization,signals,system,test,thread,wave # clean and build for Android, j option is num of cores x 1.5 rm -fr android-build ./b2 -j6 -sNDK_ROOT="$HOME/Library/Android/sdk/ndk-bundle" --build-dir=android-build --stagedir=android-build/x86 toolset=gcc-x86 threading=multi link=static stage ./b2 -j6 -sNDK_ROOT="$HOME/Library/Android/sdk/ndk-bundle" --build-dir=android-build --stagedir=android-build/x86_64 toolset=gcc-x86_64 threading=multi link=static stage ./b2 -j6 -sNDK_ROOT="$HOME/Library/Android/sdk/ndk-bundle" --build-dir=android-build --stagedir=android-build/armeabi toolset=gcc-armeabi threading=multi link=static stage ./b2 -j6 -sNDK_ROOT="$HOME/Library/Android/sdk/ndk-bundle" --build-dir=android-build --stagedir=android-build/armeabi-v7a toolset=gcc-armeabi_v7a threading=multi link=static stage ./b2 -j6 -sNDK_ROOT="$HOME/Library/Android/sdk/ndk-bundle" --build-dir=android-build --stagedir=android-build/arm64-v8a toolset=gcc-arm64_v8a threading=multi link=static stage # create link for include folder cd android-build mkdir -p include cd include ln -s ../../boost .


(3) Create Android.mk at ~/Library/Android/sdk/ndk-bundle/sources/boost_1_62_0/ for ndkBuild in Android Studio
~/Library/Android/sdk/ndk-bundle/sources/boost_1_62_0/Android.mk    Select all
# create the following Android.mk cat > ~/Library/Android/sdk/ndk-bundle/sources/boost_1_62_0/Android.mk << 'EOF' LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) LOCAL_MODULE := libboost_atomic LOCAL_SRC_FILES := android-build/$(TARGET_ARCH_ABI)/lib/libboost_atomic.a LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/android-build/include LOCAL_CPP_FEATURES := rtti exceptions include $(PREBUILT_STATIC_LIBRARY) include $(CLEAR_VARS) LOCAL_MODULE := libboost_chrono LOCAL_SRC_FILES := android-build/$(TARGET_ARCH_ABI)/lib/libboost_chrono.a LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/android-build/include LOCAL_CPP_FEATURES := rtti exceptions include $(PREBUILT_STATIC_LIBRARY) include $(CLEAR_VARS) LOCAL_MODULE := libboost_date_time LOCAL_SRC_FILES := android-build/$(TARGET_ARCH_ABI)/lib/libboost_date_time.a LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/android-build/include LOCAL_CPP_FEATURES := rtti exceptions include $(PREBUILT_STATIC_LIBRARY) include $(CLEAR_VARS) LOCAL_MODULE := libboost_exception LOCAL_SRC_FILES := android-build/$(TARGET_ARCH_ABI)/lib/libboost_exception.a LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/android-build/include LOCAL_CPP_FEATURES := rtti exceptions include $(PREBUILT_STATIC_LIBRARY) include $(CLEAR_VARS) LOCAL_MODULE := libboost_filesystem LOCAL_SRC_FILES := android-build/$(TARGET_ARCH_ABI)/lib/libboost_filesystem.a LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/android-build/include LOCAL_CPP_FEATURES := rtti exceptions include $(PREBUILT_STATIC_LIBRARY) include $(CLEAR_VARS) LOCAL_MODULE := libboost_graph LOCAL_SRC_FILES := android-build/$(TARGET_ARCH_ABI)/lib/libboost_graph.a LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/android-build/include LOCAL_CPP_FEATURES := rtti exceptions include $(PREBUILT_STATIC_LIBRARY) include $(CLEAR_VARS) LOCAL_MODULE := libboost_iostreams LOCAL_SRC_FILES := android-build/$(TARGET_ARCH_ABI)/lib/libboost_iostreams.a LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/android-build/include LOCAL_CPP_FEATURES := rtti exceptions include $(PREBUILT_STATIC_LIBRARY) include $(CLEAR_VARS) LOCAL_MODULE := libboost_math_c99 LOCAL_SRC_FILES := android-build/$(TARGET_ARCH_ABI)/lib/libboost_math_c99.a LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/android-build/include LOCAL_CPP_FEATURES := rtti exceptions include $(PREBUILT_STATIC_LIBRARY) include $(CLEAR_VARS) LOCAL_MODULE := libboost_math_c99f LOCAL_SRC_FILES := android-build/$(TARGET_ARCH_ABI)/lib/libboost_math_c99f.a LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/android-build/include LOCAL_CPP_FEATURES := rtti exceptions include $(PREBUILT_STATIC_LIBRARY) include $(CLEAR_VARS) LOCAL_MODULE := libboost_math_c99l LOCAL_SRC_FILES := android-build/$(TARGET_ARCH_ABI)/lib/libboost_math_c99l.a LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/android-build/include LOCAL_CPP_FEATURES := rtti exceptions include $(PREBUILT_STATIC_LIBRARY) include $(CLEAR_VARS) LOCAL_MODULE := libboost_math_tr1 LOCAL_SRC_FILES := android-build/$(TARGET_ARCH_ABI)/lib/libboost_math_tr1.a LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/android-build/include LOCAL_CPP_FEATURES := rtti exceptions include $(PREBUILT_STATIC_LIBRARY) include $(CLEAR_VARS) LOCAL_MODULE := libboost_math_tr1f LOCAL_SRC_FILES := android-build/$(TARGET_ARCH_ABI)/lib/libboost_math_tr1f.a LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/android-build/include LOCAL_CPP_FEATURES := rtti exceptions include $(PREBUILT_STATIC_LIBRARY) include $(CLEAR_VARS) LOCAL_MODULE := libboost_math_tr1l LOCAL_SRC_FILES := android-build/$(TARGET_ARCH_ABI)/lib/libboost_math_tr1l.a LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/android-build/include LOCAL_CPP_FEATURES := rtti exceptions include $(PREBUILT_STATIC_LIBRARY) include $(CLEAR_VARS) LOCAL_MODULE := libboost_prg_exec_monitor LOCAL_SRC_FILES := android-build/$(TARGET_ARCH_ABI)/lib/libboost_prg_exec_monitor.a LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/android-build/include LOCAL_CPP_FEATURES := rtti exceptions include $(PREBUILT_STATIC_LIBRARY) include $(CLEAR_VARS) LOCAL_MODULE := libboost_program_options LOCAL_SRC_FILES := android-build/$(TARGET_ARCH_ABI)/lib/libboost_program_options.a LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/android-build/include LOCAL_CPP_FEATURES := rtti exceptions include $(PREBUILT_STATIC_LIBRARY) include $(CLEAR_VARS) LOCAL_MODULE := libboost_random LOCAL_SRC_FILES := android-build/$(TARGET_ARCH_ABI)/lib/libboost_random.a LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/android-build/include LOCAL_CPP_FEATURES := rtti exceptions include $(PREBUILT_STATIC_LIBRARY) include $(CLEAR_VARS) LOCAL_MODULE := libboost_regex LOCAL_SRC_FILES := android-build/$(TARGET_ARCH_ABI)/lib/libboost_regex.a LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/android-build/include LOCAL_CPP_FEATURES := rtti exceptions include $(PREBUILT_STATIC_LIBRARY) include $(CLEAR_VARS) LOCAL_MODULE := libboost_serialization LOCAL_SRC_FILES := android-build/$(TARGET_ARCH_ABI)/lib/libboost_serialization.a LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/android-build/include LOCAL_CPP_FEATURES := rtti exceptions include $(PREBUILT_STATIC_LIBRARY) include $(CLEAR_VARS) LOCAL_MODULE := libboost_signals LOCAL_SRC_FILES := android-build/$(TARGET_ARCH_ABI)/lib/libboost_signals.a LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/android-build/include LOCAL_CPP_FEATURES := rtti exceptions include $(PREBUILT_STATIC_LIBRARY) include $(CLEAR_VARS) LOCAL_MODULE := libboost_system LOCAL_SRC_FILES := android-build/$(TARGET_ARCH_ABI)/lib/libboost_system.a LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/android-build/include LOCAL_CPP_FEATURES := rtti exceptions include $(PREBUILT_STATIC_LIBRARY) include $(CLEAR_VARS) LOCAL_MODULE := libboost_test_exec_monitor LOCAL_SRC_FILES := android-build/$(TARGET_ARCH_ABI)/lib/libboost_test_exec_monitor.a LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/android-build/include LOCAL_CPP_FEATURES := rtti exceptions include $(PREBUILT_STATIC_LIBRARY) include $(CLEAR_VARS) LOCAL_MODULE := libboost_thread LOCAL_SRC_FILES := android-build/$(TARGET_ARCH_ABI)/lib/libboost_thread.a LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/android-build/include LOCAL_CPP_FEATURES := rtti exceptions include $(PREBUILT_STATIC_LIBRARY) include $(CLEAR_VARS) LOCAL_MODULE := libboost_timer LOCAL_SRC_FILES := android-build/$(TARGET_ARCH_ABI)/lib/libboost_timer.a LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/android-build/include LOCAL_CPP_FEATURES := rtti exceptions include $(PREBUILT_STATIC_LIBRARY) include $(CLEAR_VARS) LOCAL_MODULE := libboost_unit_test_framework LOCAL_SRC_FILES := android-build/$(TARGET_ARCH_ABI)/lib/libboost_unit_test_framework.a LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/android-build/include LOCAL_CPP_FEATURES := rtti exceptions include $(PREBUILT_STATIC_LIBRARY) include $(CLEAR_VARS) LOCAL_MODULE := libboost_wave LOCAL_SRC_FILES := android-build/$(TARGET_ARCH_ABI)/lib/libboost_wave.a LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/android-build/include LOCAL_CPP_FEATURES := rtti exceptions include $(PREBUILT_STATIC_LIBRARY) include $(CLEAR_VARS) LOCAL_MODULE := libboost_wserialization LOCAL_SRC_FILES := android-build/$(TARGET_ARCH_ABI)/lib/libboost_wserialization.a LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/android-build/include LOCAL_CPP_FEATURES := rtti exceptions include $(PREBUILT_STATIC_LIBRARY) EOF


(4) Download and build QuantLib for Android
shell script    Select all
# download quantlib source to ndk-bundle cd ~/Library/Android/sdk/ndk-bundle/sources curl -O http://nchc.dl.sourceforge.net/project/quantlib/QuantLib/1.9/QuantLib-1.9.tar.gz # for QuantLib-1.10 # curl -O http://nchc.dl.sourceforge.net/project/quantlib/QuantLib/1.10/QuantLib-1.10.tar.gz tar xzvf QuantLib-1.9.tar.gz cd QuantLib-1.9 #Create the following shell script for x86 cat > ~/Library/Android/sdk/ndk-bundle/sources/QuantLib-1.9/build-x86.sh << 'x86EOF' #!/bin/bash # build-x86.sh BUILD_DIR=android-build mkdir -p ${BUILD_DIR} INSTALL_DIR="`pwd`/${BUILD_DIR}" YOUR_PATH_TO_INSTALL_DIR="`cd "${INSTALL_DIR}";pwd`" NDK_DIR="${HOME}/Library/Android/sdk/ndk-bundle" YOUR_PATH_TO_NDK="`cd "${NDK_DIR}";pwd`" YOUR_TOOLCHAIN=${YOUR_PATH_TO_NDK}/sources/android-toolchain-x86 export CC=${YOUR_TOOLCHAIN}/bin/i686-linux-android-gcc export CXX=${YOUR_TOOLCHAIN}/bin/i686-linux-android-g++ export CPP=${YOUR_TOOLCHAIN}/bin/i686-linux-android-cpp export AR=${YOUR_TOOLCHAIN}/bin/i686-linux-android-ar export RANLIB=${YOUR_TOOLCHAIN}/bin/i686-linux-android-ranlib export LD=${YOUR_TOOLCHAIN}/bin/i686-linux-android-ld export CPPFLAGS="-fexceptions -frtti -fpic -ffunction-sections -funwind-tables -fvisibility=hidden -fvisibility-inlines-hidden -fdata-sections" export CXXFLAGS="-DANDROID -D__ANDROID__ -DNDEBUG -O2 -g -D_REENTRANT -D_GLIBCXX__PTHREADS" sysroot=${YOUR_TOOLCHAIN} boost_include="`cd "${YOUR_PATH_TO_NDK}/sources/boost_1_62_0/android-build/include";pwd`" boost_lib="`cd "${YOUR_PATH_TO_NDK}/sources/boost_1_62_0/android-build/x86/lib";pwd`" make distclean ./configure --prefix=/x86 --host=i686-linux-android --with-sysroot=${sysroot} --with-boost-include=${boost_include} --with-boost-lib=${boost_lib} --enable-static --enable-shared=no --enable-examples=no --enable-thread-safe-observer-pattern make -j6 make install DESTDIR=${YOUR_PATH_TO_INSTALL_DIR} x86EOF #Create the following shell script for x86_64 cat > ~/Library/Android/sdk/ndk-bundle/sources/QuantLib-1.9/build-x86_64.sh << 'x86_64EOF' #!/bin/bash # build-x86_64.sh BUILD_DIR=android-build mkdir -p ${BUILD_DIR} INSTALL_DIR="`pwd`/${BUILD_DIR}" YOUR_PATH_TO_INSTALL_DIR="`cd "${INSTALL_DIR}";pwd`" NDK_DIR="${HOME}/Library/Android/sdk/ndk-bundle" YOUR_PATH_TO_NDK="`cd "${NDK_DIR}";pwd`" YOUR_TOOLCHAIN=${YOUR_PATH_TO_NDK}/sources/android-toolchain-x86_64 export CC=${YOUR_TOOLCHAIN}/bin/x86_64-linux-android-gcc export CXX=${YOUR_TOOLCHAIN}/bin/x86_64-linux-android-g++ export CPP=${YOUR_TOOLCHAIN}/bin/x86_64-linux-android-cpp export AR=${YOUR_TOOLCHAIN}/bin/x86_64-linux-android-ar export RANLIB=${YOUR_TOOLCHAIN}/bin/x86_64-linux-android-ranlib export LD=${YOUR_TOOLCHAIN}/bin/x86_64-linux-android-ld export CPPFLAGS="-fexceptions -frtti -fpic -ffunction-sections -funwind-tables -fvisibility=hidden -fvisibility-inlines-hidden -fdata-sections" export CXXFLAGS="-D_REENTRANT -D_GLIBCXX__PTHREADS -DANDROID -D__ANDROID__ -DNDEBUG -O2 -g" sysroot=${YOUR_TOOLCHAIN} boost_include="`cd "${YOUR_PATH_TO_NDK}/sources/boost_1_62_0/android-build/include";pwd`" boost_lib="`cd "${YOUR_PATH_TO_NDK}/sources/boost_1_62_0/android-build/x86_64/lib";pwd`" make distclean ./configure --prefix=/x86_64 --host=x86_64-linux-android --with-sysroot=${sysroot} --with-boost-include=${boost_include} --with-boost-lib=${boost_lib} --enable-static --enable-shared=no --enable-examples=no --enable-thread-safe-observer-pattern make -j6 make install DESTDIR=${YOUR_PATH_TO_INSTALL_DIR} x86_64EOF #Create the following shell script for armeabi cat > ~/Library/Android/sdk/ndk-bundle/sources/QuantLib-1.9/build-armeabi.sh << 'armeabiEOF' #!/bin/bash # build-armeabi.sh BUILD_DIR=android-build mkdir -p ${BUILD_DIR} INSTALL_DIR="`pwd`/${BUILD_DIR}" YOUR_PATH_TO_INSTALL_DIR="`cd "${INSTALL_DIR}";pwd`" NDK_DIR="${HOME}/Library/Android/sdk/ndk-bundle" YOUR_PATH_TO_NDK="`cd "${NDK_DIR}";pwd`" YOUR_TOOLCHAIN=${YOUR_PATH_TO_NDK}/sources/android-toolchain-arm export CC=${YOUR_TOOLCHAIN}/bin/arm-linux-androideabi-gcc export CXX=${YOUR_TOOLCHAIN}/bin/arm-linux-androideabi-g++ export CPP=${YOUR_TOOLCHAIN}/bin/arm-linux-androideabi-cpp export AR=${YOUR_TOOLCHAIN}/bin/arm-linux-androideabi-ar export RANLIB=${YOUR_TOOLCHAIN}/bin/arm-linux-androideabi-ranlib export LD=${YOUR_TOOLCHAIN}/bin/arm-linux-androideabi-ld export CPPFLAGS="-fexceptions -frtti -fpic -ffunction-sections -funwind-tables -fvisibility=hidden -fvisibility-inlines-hidden -fdata-sections" export CXXFLAGS="-D_REENTRANT -D_GLIBCXX__PTHREADS -D__ARM_ARCH_5__ -D__ARM_ARCH_5T__ -D__ARM_ARCH_5E__ -D__ARM_ARCH_5TE__ -march=armv5te -mtune=xscale -msoft-float -mthumb -DANDROID -D__ANDROID__ -DNDEBUG -O2 -g" export LDFLAGS="-march=armv5te" sysroot=${YOUR_TOOLCHAIN} boost_include="`cd "${YOUR_PATH_TO_NDK}/sources/boost_1_62_0/android-build/include";pwd`" boost_lib="`cd "${YOUR_PATH_TO_NDK}/sources/boost_1_62_0/android-build/armeabi/lib";pwd`" make distclean ./configure --prefix=/armeabi --host=arm-linux-androideabi --with-sysroot=${sysroot} --with-boost-include=${boost_include} --with-boost-lib=${boost_lib} --enable-static --enable-shared=no --enable-examples=no --enable-thread-safe-observer-pattern make -j6 make install DESTDIR=${YOUR_PATH_TO_INSTALL_DIR} armeabiEOF #Create the following shell script for armeabi-v7a cat > ~/Library/Android/sdk/ndk-bundle/sources/QuantLib-1.9/build-armeabi-v7a.sh << 'armeabi-v7aEOF' #!/bin/bash # build-armeabi-v7a.sh BUILD_DIR=android-build mkdir -p ${BUILD_DIR} INSTALL_DIR="`pwd`/${BUILD_DIR}" YOUR_PATH_TO_INSTALL_DIR="`cd "${INSTALL_DIR}";pwd`" NDK_DIR="${HOME}/Library/Android/sdk/ndk-bundle" YOUR_PATH_TO_NDK="`cd "${NDK_DIR}";pwd`" YOUR_TOOLCHAIN=${YOUR_PATH_TO_NDK}/sources/android-toolchain-arm export CC=${YOUR_TOOLCHAIN}/bin/arm-linux-androideabi-gcc export CXX=${YOUR_TOOLCHAIN}/bin/arm-linux-androideabi-g++ export CPP=${YOUR_TOOLCHAIN}/bin/arm-linux-androideabi-cpp export AR=${YOUR_TOOLCHAIN}/bin/arm-linux-androideabi-ar export RANLIB=${YOUR_TOOLCHAIN}/bin/arm-linux-androideabi-ranlib export LD=${YOUR_TOOLCHAIN}/bin/arm-linux-androideabi-ld export CPPFLAGS="-fexceptions -frtti -fpic -ffunction-sections -funwind-tables -fvisibility=hidden -fvisibility-inlines-hidden -fdata-sections" export CXXFLAGS="-D_REENTRANT -D_GLIBCXX__PTHREADS -march=armv7-a -msoft-float -mfpu=neon -mthumb -DANDROID -D__ANDROID__ -DNDEBUG -O2 -g" export LDFLAGS="-march=armv7-a -Wl,--fix-cortex-a8" sysroot=${YOUR_TOOLCHAIN} boost_include="`cd "${YOUR_PATH_TO_NDK}/sources/boost_1_62_0/android-build/include";pwd`" boost_lib="`cd "${YOUR_PATH_TO_NDK}/sources/boost_1_62_0/android-build/armeabi-v7a/lib";pwd`" make distclean ./configure --prefix=/armeabi-v7a --host=arm-linux-androideabi --with-sysroot=${sysroot} --with-boost-include=${boost_include} --with-boost-lib=${boost_lib} --enable-static --enable-shared=no --enable-examples=no --enable-thread-safe-observer-pattern make -j6 make install DESTDIR=${YOUR_PATH_TO_INSTALL_DIR} armeabi-v7aEOF #Create the following shell script for arm64-v8a cat > ~/Library/Android/sdk/ndk-bundle/sources/QuantLib-1.9/build-arm64-v8a.sh << 'arm64-v8aEOF' #!/bin/bash # build-arm64-v8a.sh BUILD_DIR=android-build mkdir -p ${BUILD_DIR} INSTALL_DIR="`pwd`/${BUILD_DIR}" YOUR_PATH_TO_INSTALL_DIR="`cd "${INSTALL_DIR}";pwd`" NDK_DIR="${HOME}/Library/Android/sdk/ndk-bundle" YOUR_PATH_TO_NDK="`cd "${NDK_DIR}";pwd`" YOUR_TOOLCHAIN=${YOUR_PATH_TO_NDK}/sources/android-toolchain-arm64 export CC=${YOUR_TOOLCHAIN}/bin/aarch64-linux-android-gcc export CXX=${YOUR_TOOLCHAIN}/bin/aarch64-linux-android-g++ export CPP=${YOUR_TOOLCHAIN}/bin/aarch64-linux-android-cpp export AR=${YOUR_TOOLCHAIN}/bin/aarch64-linux-android-ar export RANLIB=${YOUR_TOOLCHAIN}/bin/aarch64-linux-android-ranlib export LD=${YOUR_TOOLCHAIN}/bin/aarch64-linux-android-ld export CPPFLAGS="-fexceptions -frtti -fpic -ffunction-sections -funwind-tables -fstack-protector -fvisibility=hidden -fvisibility-inlines-hidden -fdata-sections" export CXXFLAGS="-D_REENTRANT -D_GLIBCXX__PTHREADS -march=armv8-a -mtune=cortex-a53 -DANDROID -D__ANDROID__ -DNDEBUG -O2 -g" export LDFLAGS="-march=armv8-a" sysroot=${YOUR_TOOLCHAIN} boost_include="`cd "${YOUR_PATH_TO_NDK}/sources/boost_1_62_0/android-build/include";pwd`" boost_lib="`cd "${YOUR_PATH_TO_NDK}/sources/boost_1_62_0/android-build/arm64-v8a/lib";pwd`" make distclean ./configure --prefix=/arm64-v8a --host=aarch64-linux-android --with-sysroot=${sysroot} --with-boost-include=${boost_include} --with-boost-lib=${boost_lib} --enable-static --enable-shared=no --enable-examples=no --enable-thread-safe-observer-pattern make -j6 make install DESTDIR=${YOUR_PATH_TO_INSTALL_DIR} arm64-v8aEOF #run shell scripts to clean and build for Android cd ~/Library/Android/sdk/ndk-bundle/sources cd QuantLib-1.9 rm -fr android-build sh build-x86.sh sh build-x86_64.sh sh build-armeabi.sh sh build-armeabi-v7a.sh sh build-arm64-v8a.sh


(5) Create Android.mk at ~/Library/Android/sdk/ndk-bundle/sources/QuantLib-1.9/ for ndkBuild in Android Studio
~/Library/Android/sdk/ndk-bundle/sources/QuantLib-1.9/Android.mk    Select all
# create the following Android.mk cat > ~/Library/Android/sdk/ndk-bundle/sources/QuantLib-1.9/Android.mk << 'EOF' LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) LOCAL_MODULE := libQuantLib LOCAL_SRC_FILES := android-build/$(TARGET_ARCH_ABI)/lib/libQuantLib.a LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/android-build/$(TARGET_ARCH_ABI)/include LOCAL_CPP_FEATURES := rtti exceptions include $(PREBUILT_STATIC_LIBRARY) EOF


(6) Demo of using boost c++ libraries for ndkBuild in Android Studio 2.2.2
Assume prebuilt libraries are installed to ~/Library/Android/sdk/ndk-bundle/sources
app/build.gradle    Select all
apply plugin: 'com.android.application' Properties properties = new Properties() properties.load(project.rootProject.file('local.properties').newDataInputStream()) def sdkFolder = properties.getProperty('sdk.dir') def ndkFolder = properties.getProperty('ndk.dir') android { compileSdkVersion 23 buildToolsVersion "23.0.3" defaultConfig { applicationId "com.example.helloboost" minSdkVersion 9 targetSdkVersion 23 versionCode = 1 versionName = '1.0' archivesBaseName = 'HELLOBOOST_' + versionName ndk { moduleName "hello-boost" abiFilters 'armeabi', 'armeabi-v7a', 'arm64-v8a', 'x86', 'x86_64' } externalNativeBuild { ndkBuild { arguments "NDK_APPLICATION_MK=src/main/jni/Application.mk" // default module search path NDK_MODULE_PATH is at ${ndkFolder}/sources } } } buildTypes { debug { minifyEnabled false zipAlignEnabled true debuggable true useProguard false versionNameSuffix 'debug' } release { minifyEnabled false zipAlignEnabled true useProguard true proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt' } } externalNativeBuild { ndkBuild { path "src/main/jni/Android.mk" } } }


app/src/main/jni/Android.mk    Select all
LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) LOCAL_MODULE := hello-boost LOCAL_SRC_FILES := hello-boost.cpp first.cpp LOCAL_STATIC_LIBRARIES := libboost_system libboost_thread libboost_program_options libQuantLib include $(BUILD_SHARED_LIBRARY) $(call import-module, boost_1_62_0) $(call import-module, QuantLib-1.9)


app/src/main/jni/Application.mk    Select all
APP_STL = gnustl_static APP_CPPFLAGS = -Wall


(7) HelloJNI, sample of using cmake CMakeLists.txt after adding Boost and QuantLib libraries
Assume prebuilt libraries are installed to ~/Library/Android/sdk/ndk-bundle/sources
app/src/main/cpp/CMakeLists.txt    Select all
cmake_minimum_required(VERSION 3.4.1) # build native_app_glue as a static lib add_library(app-glue STATIC ${ANDROID_NDK}/sources/android/native_app_glue/android_native_app_glue.c) # now build app's shared lib set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11 -frtti -fexceptions") add_library(hello-jni SHARED hello-jni.c) #BOOST set(Boost_INCLUDE_DIR ${ANDROID_NDK}/sources/boost_1_62_0/android-build/include) set(Boost_LIBRARY_DIR ${ANDROID_NDK}/sources/boost_1_62_0/android-build/${ANDROID_ABI}/lib) set(Boost_USE_STATIC_LIBS ON) # only find static libs set(Boost_USE_MULTITHREADED ON) set(Boost_USE_STATIC_RUNTIME OFF) set(Boost_COMPILER -gcc) find_package(Boost COMPONENTS system thread program_options REQUIRED) #BOOSTEND #QuantLib set(QuantLib_INCLUDE_DIR ${ANDROID_NDK}/sources/QuantLib-1.9/android-build/${ANDROID_ABI}/include) set(QuantLib_LIBRARY_DIR ${ANDROID_NDK}/sources/QuantLib-1.9/android-build/${ANDROID_ABI}/lib) add_library(QuantLib STATIC IMPORTED) set_property(TARGET QuantLib PROPERTY IMPORTED_LOCATION ${QuantLib_LIBRARY_DIR}/libQuantLib.a) #QuantLibEND # if have QuantLibJNI, uncomment below and add QuantLibJNI to target_link_libraries of hello-jni for c++ classes generated from QuantLib-SWIG-1.9 #add_library(QuantLibJNI SHARED quantlib_wrap.cpp) #target_link_libraries(QuantLibJNI ${Boost_LIBRARIES} QuantLib) if(Boost_FOUND) # Include libraries needed include_directories(${Boost_INCLUDE_DIR}) include_directories(${QuantLib_INCLUDE_DIR}) target_link_libraries(hello-jni android app-glue log ${Boost_LIBRARIES} QuantLib) endif()

app/build.gradle    Select all
apply plugin: 'com.android.application' android { compileSdkVersion 23 buildToolsVersion '23.0.3' defaultConfig { applicationId 'com.example.hellojni' minSdkVersion 15 targetSdkVersion 23 versionCode 1 versionName "1.0" archivesBaseName = 'HELLOJNI_' + versionName externalNativeBuild { cmake { arguments '-DANDROID_TOOLCHAIN=clang' cppFlags "" } } } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } debug { debuggable true jniDebuggable true versionNameSuffix 'debug' } } externalNativeBuild { cmake { path "src/main/cpp/CMakeLists.txt" } } productFlavors { arm { ndk { abiFilter 'armeabi' } } arm7 { ndk { abiFilter 'armeabi-v7a' } } arm64 { ndk { abiFilter 'arm64-v8a' } } x86 { ndk { abiFilter 'x86' } } x86_64 { ndk { abiFilter 'x86_64' } } universal { ndk { abiFilters 'armeabi', 'armeabi-v7a', 'arm64-v8a', 'x86', 'x86_64' } } } } dependencies { compile fileTree(include: ['*.jar'], dir: 'libs') compile 'com.android.support:appcompat-v7:23.4.0' compile 'com.android.support.constraint:constraint-layout:1.0.0-alpha7' }


(8) Download & Compile swig and generate java & c++ classes from QuantLib-SWIG-1.9 for Android project
shell scriptSelect all
#download and compile swig cd ~/Downloads curl -O http://nchc.dl.sourceforge.net/project/swig/swig/swig-3.0.10/swig-3.0.10.tar.gz tar xzvf swig-3.0.10.tar.gz curl -O http://nchc.dl.sourceforge.net/project/pcre/pcre/8.39/pcre-8.39.tar.gz tar xzvf pcre-8.39.tar.gz cd ~/Downloads/pcre-8.39 ./configure --enable-utf8 --enable-unicode-properties make sudo make install cd ~/Downloads/swig-3.0.10 ./configure make sudo make install # download QuantLib-SWIG-1.9 cd ~/Library/Android/sdk/ndk-bundle/sources curl -O http://jaist.dl.sourceforge.net/project/quantlib/QuantLib/1.9/other%20languages/QuantLib-SWIG-1.9.tar.gz tar xzvf QuantLib-SWIG-1.9.tar.gz # generate SWIG java & c++ classes to HelloJNI project cd ~/Projects cd HelloJNI/app/src/main mkdir -p cpp mkdir -p java/org/quantlib swig -java -c++ -module QuantLib -package org.quantlib -outdir java/org/quantlib -o cpp/quantlib_wrap.cpp ~/Library/Android/sdk/ndk-bundle/sources/QuantLib-SWIG-1.9/SWIG/quantlib.i



Sunday, September 18, 2016

CSS selector in Chrome using the example of Apple iPhone 7 Plus Availability Monitoring

The iPhone 7 Plus Reserve Page for HK is a dynamic web content as in https://reserve.cdn-apple.com/HK/en_HK/reserve/iPhone/availability

The basic javascript console code in Google Chrome for availability is as below

iPhone7availability    Select all
// proper case string prptotype (JScript 5.5+) String.prototype.toProperCase = function() { return this.toLowerCase().replace(/^(.)|\s(.)/g, function($1) { return $1.toUpperCase(); }); } function testip7plus() { var targetProduct = "Plus" var targetCapacity = "256GB" // "32GB", "128GB", "256GB" var targetColor = "Silver" // "Rose Gold" 玫瑰金色, "Gold" 金色, "Sliver" 銀色, "Black" 黑色, "Jet Black" 亮黑色 var FinalSelectedProduct = false; targetCapacity = targetCapacity.toUpperCase() targetColor = targetColor.toProperCase(); var stores_length = $('form#availabilityForm #selectStore option[disabled!=disabled]').length; for(a=0; a<stores_length; a++) { var enabledStore = $('form#availabilityForm #selectStore option[disabled!=disabled]').eq(a).val(); setTimeout(function() { $('form#availabilityForm div.form-element.select-store select').val(enabledStore); $('form#availabilityForm div.form-element.select-store select').change(); },1800) var enabledStoreText = $('form#availabilityForm #selectStore option[disabled!=disabled]').eq(a).text().replace(/^\s+|\s+$/g, ''); var products_length = $('form#availabilityForm #selectSubfamily option[disabled!=disabled]').length; for(p=0; p<products_length; p++) { var enabledProduct = $('div#productSelectionView #selectSubfamily option[disabled!=disabled]').eq(p).val(); var enabledProductText = $('div#productSelectionView #selectSubfamily option[disabled!=disabled]').eq(p).text(); if (~enabledProductText.toLowerCase().indexOf(targetProduct.toLowerCase())) { console.log("Log " + enabledStoreText + " has " + enabledProductText); $('form#availabilityForm div.form-element.select-product select').val(enabledProduct); $('form#availabilityForm div.form-element.select-product select').change(); var unavailableGB = $('div#capacity-row li.unavailable input[value="'+targetCapacity+'"]').length console.log("Log " + enabledStoreText + " checking for " + targetCapacity) if (unavailableGB == 0) { var sizeAva_length = $('div#capacity-row li').length; for(u=0;u<sizeAva_length;u++) { if ($('div#capacity-row li').eq(u).find('div').attr('id') == targetCapacity) { $('div#capacity-row li').eq(u).find("input").click(); break; } } var unavailableColor = $('div#product-row li.unavailable input[data-color="'+targetColor+'"]').length console.log("Log " + enabledStoreText + " checking for " + targetColor) if (unavailableColor == 0) { var colorAva_length = $('div#product-row li').length; for(v=0;v<colorAva_length;v++) { if ($('div#product-row li').eq(v).find('input').attr('data-color') == targetColor) { setTimeout(function() { $('div#product-row li').eq(v).find("input").click(); },800) FinalSelectedProduct = true; break; } } if (FinalSelectedProduct) { console.log("SUCCESS!!! " + enabledStoreText + " has " + $('div.section-product.product-bottom.hide-for-large.show-only-for-small.with-fade.fade-in div.product div.callout.callout-center.product-specs ul.specs li:first').text().trim() + " " + enabledProductText + $('div.success.row div.success-copy.small-center').text().trim()); break; } } else { console.log("Log " + enabledStoreText + ", sorry no " + targetCapacity + " " + targetColor) } } } else { console.log(enabledStoreText + ", sorry no " + targetProduct) } } if (FinalSelectedProduct) { return; } } } testip7plus()



There is an archive for iPhone 6 Availability script in last year, please click the Chrome CSS Javascript label below


Saturday, September 17, 2016

How to check something that "is not yet implemented" in Swift 3 Linux

How to grep "XXXX is not yet implemented" in Swift 3 Linux
cd $(HOME) git clone --depth=1 https://github.com/apple/swift-corelibs-foundation
cd $(HOME)/swift-corelibs-foundation/Foundation
grep -r "NSUnimplemented() }"



How to grep func or init in Swift 3 Linux
cd $(HOME)/swift-corelibs-foundation/Foundation
grep -r "open func \|public init"



Wednesday, August 24, 2016

How to install Objective C 2.0 and GNUstep under Windows SubSystem for Linux - Bash Shell

Install Objective C 2.0 and GNUstep under Windows 10 bash shell
Follow the steps below (make sure the steps are followed in order, that is build libobjc2 before GNUstep) to install required packages and build scripts

bash    Select all
sudo apt-get update sudo apt-get install build-essential libblocksruntime-dev libkqueue-dev libpthread-workqueue-dev gobjc libxml2-dev libjpeg-dev libtiff-dev libpng12-dev libcups2-dev libfreetype6-dev libcairo2-dev libxt-dev libgl1-mesa-dev sudo apt-get install clang-3.6 cmake git sudo update-alternatives --install /usr/bin/clang clang /usr/bin/clang-3.6 100 sudo update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-3.6 100 cd $HOME git clone --depth=1 https://github.com/gnustep/libobjc2 cd libobjc2 rm -fr Build mkdir Build && cd Build cmake .. -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DLIB_INSTALL_PATH=/usr/local/lib make sudo make install cd $HOME wget ftp://ftp.gnustep.org/pub/gnustep/core/gnustep-make-2.6.7.tar.gz tar xvf gnustep-make*.tar.gz cd gnustep-make* CC=clang CXX=clang++ ./configure --prefix=/usr/local make sudo make install cd $HOME wget ftp://ftp.gnustep.org/pub/gnustep/core/gnustep-base-1.24.8.tar.gz tar xvf gnustep-base*.tar.gz cd gnustep-base* CC=clang CXX=clang++ ./configure --prefix=/usr/local make sudo make install sudo ldconfig -v # no gnustep-gui installation here. sudo apt-get install libdispatch-dev # testing cd $HOME cat > blocktest.m << EOF #include <stdio.h> int main() { void (^hello)(void) = ^(void) { printf("Hello, block!\n"); }; hello(); return 0; } EOF clang `gnustep-config --objc-flags` -fblocks -o blocktest -x objective-c blocktest.m `gnustep-config --base-libs` ./blocktest cat > main.m << EOF // // main.m // Just a little test case for Objective-C 2.0 on Ubuntu // #import <Foundation/Foundation.h> #import <dispatch/dispatch.h> int main(int argc, const char * argv[]) { @autoreleasepool { int multiplier = 7; int (^myBlock)(int) = ^(int num) { return num * multiplier; }; NSLog(@"%d", myBlock(3)); dispatch_queue_t queue = dispatch_queue_create(NULL, NULL); dispatch_sync(queue, ^{ printf("Hello, world from a dispatch queue!\n"); }); dispatch_release(queue); } @autoreleasepool { NSLog(@"Wow it works!"); } return 0; } EOF # command line for locale generation sudo locale-gen en_US.UTF-8 # command line to reset timezone if not yet configured sudo dpkg-reconfigure tzdata clang `gnustep-config --objc-flags` -fblocks -o main -x objective-c main.m `gnustep-config --base-libs` -ldispatch ./main # to compile objective c++, you would need extra parameters and use clang++ clang++ -std=c++11 -stdlib=libc++ -x objective-c++ clang++ -std=c++11 -stdlib=libstdc++ -x objective-c++



GNUstep documentation is here -> http://www.gnustep.org/developers/documentation.html


Wednesday, August 3, 2016

Bash Shell Built Into Windows 10 Anniversary Update 1607 Build 14393.10

After Windows 10 Anniversary Update, you have to enable "Developer mode" on the "Update & Security" page.
Then go to Control Panel -> Program and Features -> Turn Windows Features on or off -> Windows SubSystem for Linux (Beta), and click OK.

Bash Shell is only for 64-bit versions of Windows 10.

Bash Shortcut Keys
There are a number of very useful shortcut keys you can use in the bash shell:

Ctrl + U: Clears the line from the cursor point back to the beginning.
Ctrl + A: Moves the cursor to the beginning of the line.
Ctrl + E: Moves the cursor to the end of the line.
Ctrl + Left / Right: Moves the cursor to one word Left / Right.
Ctrl + R: Allows you to search through the previous commands.

Batch Rename Files
rename –v 's/foo/bar/g' *

Customize command line prompt
function prompt
{
local WHITE="\[\033[1;37m\]"
local GREEN="\[\033[0;32m\]"
local CYAN="\[\033[0;36m\]"
local GRAY="\[\033[0;37m\]"
local BLUE="\[\033[0;34m\]"
export PS1="${GREEN}\u${CYAN}@${BLUE}\h ${CYAN}\w${GRAY}$ "
}
prompt


where
\u refers to the current username
\h refers to the host name
\w refers to the current file path.

or simply uncomment the line force_color_prompt=yes in ~/.bashrc

You can use Docker for Windows as engine and docker client for linux in bash. "Docker for Windows" requires Windows 10 Pro 64-bit and Hyper-V Package.

To install docker client for Linux under bash shell
cd ~/
wget https://get.docker.com/builds/Linux/x86_64/docker-1.12.0.tgz
tar -xzvf docker-1.12.0.tgz
cd docker
./docker -H tcp://0.0.0.0:2375 ps


Or simply add the corresponding variables to ~/.bashrc
export DOCKER_HOST=tcp://0.0.0.0:2375
export PATH=$PATH:~/docker

To detach the docker tty without exiting the shell, use the escape sequence Ctrl-p + Ctrl-q


Install docker-compose and try docker-compose example as per https://docs.docker.com/compose/wordpress/
shell script    Select all
# install dcoker-compose curl -L https://github.com/docker/compose/releases/download/1.8.0/docker-compose-`uname -s`-`uname -m` > ~/docker/docker-compose chmod +x ~/docker/docker-compose docker-compose --version # try docker-compose example on wordpress and mysql images cd $HOME mkdir my-wordpress cd my-wordpress cat > docker-compose.yaml <<EOF version: '2' services: db: image: mysql:5.7 volumes: - "./.data/db:/var/lib/mysql" restart: always environment: MYSQL_ROOT_PASSWORD: wordpress MYSQL_DATABASE: wordpress MYSQL_USER: wordpress MYSQL_PASSWORD: wordpress wordpress: depends_on: - db image: wordpress:latest links: - db ports: - "8000:80" restart: always environment: WORDPRESS_DB_HOST: db:3306 WORDPRESS_DB_PASSWORD: wordpress EOF # start the docker-compose example docker-compose up -d # then try browser http://localhost:8000/ # stop the docker-compose example docker-compose down


Swift 3 on Ubuntu (14.04 LTS trusty) for Windows 10 bash shell

You need to download and extract the development snapshot (Ubuntu 14.04) from swift.org and do these under bash shell.
shell script    Select all
# download and extract swift 3 snapshot cd ~/ wget https://swift.org/builds/development/ubuntu1404/swift-DEVELOPMENT-SNAPSHOT-2016-08-04-a/swift-DEVELOPMENT-SNAPSHOT-2016-08-04-a-ubuntu14.04.tar.gz tar xzvf swift-DEVELOPMENT-SNAPSHOT-2016-08-04-a-ubuntu14.04.tar.gz # the latest snapshot 2016-08-23 has libdispatch cd ~/ wget https://swift.org/builds/development/ubuntu1404/swift-DEVELOPMENT-SNAPSHOT-2016-08-23-a/swift-DEVELOPMENT-SNAPSHOT-2016-08-23-a-ubuntu14.04.tar.gz tar xzvf swift-DEVELOPMENT-SNAPSHOT-2016-08-23-a-ubuntu14.04.tar.gz # Swift 3.0 GM Candidate cd ~/ wget https://swift.org/builds/swift-3.0-GM-CANDIDATE/ubuntu1404/swift-3.0-GM-CANDIDATE/swift-3.0-GM-CANDIDATE-ubuntu14.04.tar.gz tar xzvf swift-3.0-GM-CANDIDATE-ubuntu14.04.tar.gz # Swift 3.0.2 Release cd ~/ wget https://swift.org/builds/swift-3.0.2-release/ubuntu1404/swift-3.0.2-RELEASE/swift-3.0.2-RELEASE-ubuntu14.04.tar.gz tar xzvf swift-3.0.2-RELEASE-ubuntu14.04.tar.gz # install and configure clang plus other tools sudo apt-get update sudo apt-get install -y libicu-dev uuid-dev clang-3.6 sudo update-alternatives --install /usr/bin/clang clang /usr/bin/clang-3.6 100 sudo update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-3.6 100 sudo apt-get install -y git build-essential # clears the executable stack flag of shared library sudo apt-get install -y execstack sudo execstack -c ~/swift-DEVELOPMENT-SNAPSHOT-2016-08-04-a-ubuntu14.04/usr/lib/swift/linux/libFoundation.so sudo execstack -c ~/swift-DEVELOPMENT-SNAPSHOT-2016-08-23-a-ubuntu14.04/usr/lib/swift/linux/libFoundation.so sudo execstack -c ~/swift-3.0-GM-CANDIDATE-ubuntu14.04/usr/lib/swift/linux/libFoundation.so sudo execstack -c ~/swift-3.0.2-RELEASE-ubuntu14.04/usr/lib/swift/linux/libFoundation.so # add path in ~/.bashrc export PATH=$PATH:~/swift-DEVELOPMENT-SNAPSHOT-2016-08-04-a-ubuntu14.04/usr/bin export PATH=$PATH:~/swift-DEVELOPMENT-SNAPSHOT-2016-08-23-a-ubuntu14.04/usr/bin export PATH=$PATH:~/swift-3.0-GM-CANDIDATE-ubuntu14.04/usr/bin export PATH=$PATH:~/swift-3.0.2-RELEASE-ubuntu14.04/usr/bin # test Foundation, libdispatch and swiftc compile cat > hello.swift <<EOF import Foundation let device = "WIN10" print("Hello from Swift on \(device)") //print("\(TimeZone.defaultTimeZone().name) \(NSDate())") // for old snapshot 2016-08-04 //print("\(NSTimeZone.defaultTimeZone().abbreviation()!) \(NSDate())") // for old snapshot 2016-08-23 print("\(NSTimeZone.default.abbreviation()!) \(NSDate())") // for Swift 3.0 GM Candidate // Test libdispatch import Dispatch var my_dispatch_group = DispatchGroup() let concurrentQueue = DispatchQueue(label: "myqueuename", attributes: DispatchQueue.Attributes.concurrent) for a in 1...20 { my_dispatch_group.enter() let block = DispatchWorkItem { print("do something at \(a)") } my_dispatch_group.leave() my_dispatch_group.notify(queue: concurrentQueue, work:block) } let item = DispatchWorkItem { print("PROGRAM ENDED \(NSTimeZone.default.abbreviation()!) \(NSDate())") } my_dispatch_group.notify(queue: DispatchQueue.global(qos:.userInitiated), work:item) print("press enter to exit") let _ = readLine(strippingNewline: true) EOF swiftc hello.swift ./hello # test Swift Package Manager mkdir -p $HOME/test1 cd $HOME/test1 swift package init swift test


Install node.js and mongo shell for Ubuntu
shell script    Select all
# download and extract node.js cd ~/ wget https://nodejs.org/dist/v4.4.7/node-v4.4.7-linux-x64.tar.xz tar xpvf node-v4.4.7-linux-x64.tar.xz # add path in ~/.bashrc export PATH=$PATH:~/node-v4.4.7-linux-x64/bin node --version npm --version # install mongo shell for version 3.2.8 # please refer to instructions here https://docs.mongodb.com/manual/tutorial/install-mongodb-on-ubuntu/ sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv EA312927 echo "deb http://repo.mongodb.org/apt/ubuntu trusty/mongodb-org/3.2 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.2.list sudo apt-get update sudo apt-get install -y mongodb-org-shell=3.2.8 # if you follow the previous post on nodeapi.zip example # you need to install mongodb server on the Windows platform # in order to test that example.


File System Access

Ubuntu filesystem from Windows Explorer
C:\Users\%USERNAME%\AppData\Local\Lxss\rootfs
Ubuntu 16.04 filesystem from Windows Explorer, Fall Creators Update (2017 Oct)
C:\Users\%USERNAME%\AppData\Local\Packages\CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc\LocalState\rootfs\

Windows filesystem from Ubuntu bash
/mnt/c/
/mnt/d/

#edit ~/.bashrc
#add export LS_COLORS=$LS_COLORS:'di=1;44:' ; # dir white on blue background


To upgrade to Ubuntu 16.04 after Windows 10's Creators Update (2017 April)
open the Bash shell and run the following command:


sudo do-release-upgrade

lsb_release -a

However, lxrun /uninstall then lxrun /install is faster.


The lastest installtion of WSL is documented at https://docs.microsoft.com/en-us/windows/wsl/install-win10
where different and multiple distros can be installed via Microsoft Store since Fall Creators Update (2017 Oct).


Installation of Swift 3.1.1 in Ubuntu 16.04
shell script    Select all
# Install related packages and set LLVM 3.8 as the compiler sudo apt-get -q update && sudo apt-get -q install -y make libc6-dev clang-3.8 curl libedit-dev libicu-dev libssl-dev libxml2 git libcurl4-openssl-dev pkg-config sudo update-alternatives --install /usr/bin/clang clang /usr/bin/clang-3.8 100 sudo update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-3.8 100 curl -fSLO https://swift.org/builds/swift-3.1.1-release/ubuntu1604/swift-3.1.1-RELEASE/swift-3.1.1-RELEASE-ubuntu16.04.tar.gz # Swift 4.0 # https://swift.org/builds/swift-4.0-release/ubuntu1604/swift-4.0-RELEASE/swift-4.0-RELEASE-ubuntu16.04.tar.gz tar xzvf swift-3.1.1-RELEASE-ubuntu16.04.tar.gz export PATH=$PATH:$HOME/swift-3.1.1-RELEASE-ubuntu16.04/usr/bin #test Hello mkdir Hello cd Hello/ swiftc --version swift package init --type=executable swift build ./.build/debug/Hello # test Swift Package Manager mkdir -p $HOME/SessionState cd $HOME/SessionState swift package init --type library cat > $HOME/SessionState/Sources/SessionState.swift <<EOF // SessionState.swift import Foundation import Dispatch public class SessionState { private var storage = [String:Any]() // serial access to internal dictionary // private let syncQueue = DispatchQueue(label:"serializationQueue") // change to concurrent queue private let asyncQueue = DispatchQueue(label:"asyncQueue", attributes:.concurrent, target:nil) private init() {} public static let shared:SessionState = { let instance = SessionState() return instance } () public func set( _ value: Any, forKey key: String) { asyncQueue.sync(flags: .barrier) { // change to barrier queue to have serial write access // syncQueue.sync { storage[key] = value } } public func object (forKey key: String) -> Any? { var result: Any? asyncQueue.sync { result = storage[key] ?? nil } return result } } EOF cat > $HOME/SessionState/Tests/SessionStateTests/SessionStateTests.swift <<EOF //SessionStateTests.swift import XCTest import Dispatch @testable import SessionState class SessionStateTests:XCTestCase { override func setUp() { super.setUp() } override func tearDown() { super.tearDown() } func testConcurrentAccess() { let asyncQueue = DispatchQueue( label: "asyncQueue", attributes: .concurrent, target: nil ) let expect = expectation(description: "Storing value in SessionState shall succeed") let MaxIndex = 2000 for index in 0...MaxIndex { asyncQueue.async { SessionState.shared.set ( index, forKey: String(index) ) } } while SessionState.shared.object(forKey: String(MaxIndex)) as? Int != MaxIndex { //nop } expect.fulfill() waitForExpectations(timeout:10) { (error) in XCTAssertNil(error, "Test expectation failed") } } static var allTests = [ ("testConcurrentAccess", testConcurrentAccess), ] } EOF # build and test swift test # Compile and install Boost sudo apt-get -q install -y build-essential cd $HOME curl -O https://nchc.dl.sourceforge.net/project/boost/boost/1.62.0/boost_1_62_0.tar.bz2 tar xjvf boost_1_62_0.tar.bz2 cd boost_1_62_0/ ./bootstrap.sh --with-libraries=atomic,chrono,date_time,exception,filesystem,graph,iostreams,math,program_options,random,regex,serialization,signals,system,test,thread,wave --prefix=/usr ./b2 -j6 toolset=gcc address-model=64 threading=multi link=static sudo ./b2 install # Compile and install QuantLib cd $HOME curl -O https://jaist.dl.sourceforge.net/project/quantlib/QuantLib/1.10/QuantLib-1.10.tar.gz tar xzvf QuantLib-1.10.tar.gz # QuantLib 1.11 download link # https://jaist.dl.sourceforge.net/project/quantlib/QuantLib/1.11/QuantLib-1.11.tar.gz cd QuantLib-1.10/ ./configure --prefix=/usr --enable-static --disable-examples make -j6 sudo make install # to remove -> sudo make uninstall # test QuantLib cd $HOME cat > $HOME/qlversion.cpp <<EOF #include <iostream> #include <ql/version.hpp> int main() { std::cout << "Current QL Version:" << QL_LIB_VERSION << std::endl; return 0; } EOF g++ qlversion.cpp -o qlversion ./qlversion # Following this instruction to install QuantLib Python # http://quantlib.org/install/linux-python.shtml



Installation of Swift 4 for Cygwin64
shell script    Select all
# first install Cygwin64 in Windows # In Cygwin64 Terminal prompt wget -q https://github.com/tinysun212/swift-windows/releases/download/swift-4.0.3%2Bcygwin.20180212/swift-4.0.3.cygwin.20180212-bin.tar.gz tar zxf swift-4.0.3.cygwin.20180212-bin.tar.gz export PATH=$PATH:$(pwd)/usr/bin swift --version # test git clone https://github.com/apple/example-package-dealer.git cd example-package-dealer swift run Dealer



Wednesday, June 22, 2016

How to build Node.js REST APIs in Raspberry Pi 3

This project is based on the "Build a REST API with node.js" video tutorial from Udemy


The project file can be downloaded here : https://mega.nz/#!z9oFlTgJ!geCPHjoXJ3rpm1OdldU8s5RBSJxLKiAxh_axvTbODB4

The node.js ARMv7 version is v4.4.3 and npm 2.15.1
which (ARMv7) can be downloaded from https://nodejs.org/en/download/
The project also use packages like bcryptjs, body-parser, express, jsonwebtoken and mongoose and integrate with mongodb. - No-SQL db.

To install mongodb in Raspberrry Pi, use sudo apt-get install mongodb

The following enhancements were made to the original project code

1. add shell scripts and use curl for API testing (test1.sh ... test6.sh), as POSTMAN is only available in google chrome
2. add js code to avoid creating of duplicated user (test using test2.sh)
3. add test to user login and obtain Authorization sessionToken (test using test3.sh)
4. add js code to check Authorization before CRUD (create, read, update and delete definition record)
5. add js code to check existence of definition id before update and delete record (test using test5.sh)
6. shell script to get sessionToken in each test for instruction to further test on update and delete definition (test using test5.sh)
7. add js code to create log when create, update and delete definition record (test using test4.sh / test5.sh and then test6.sh)

To use mongo to admin user
mongo
> use workouts
> db.addUser({ user: "test", pwd: "test", roles:["readWrite", "dbAdmin"]});

or use createUser as below
> db.createUser({ user: "test", pwd: "test", roles:["readWrite", "dbAdmin"]});

To use mongo to display mongodb info
mongo
> use workouts
> show collections
> db.users.find()
> db.definitions.find().pretty()
> db.logs.find().pretty()

To use mongo to remove object
> db.definitions.remove({_id:ObjectId("573c29c0f11288dc9997d0")})

Instructions to use
-----------------------
1. First install node.js and mongodb and check that if mongod is running successfully in background. (If you use windows / OSX version of mongodb, please make sure the required data path is created before running mongod.exe / mongod)
2. use mongo to create admin user as above
3. Download the project file and unzip and install packages and start
bash    Select all
unzip nodeapi.zip cd nodeapi npm install npm start & # test ./test1.sh ./test2.sh ./test3.sh ... ./test6.sh # kill background job kill $!



Tuesday, June 21, 2016

How to run Docker for macOS

1) Download from here -> https://docs.docker.com/docker-for-mac/

2) Drag to Application Folder and double click to start and then check version in Terminal
docker --version
docker info


3) Search and Pull Docker image
E.g.
docker search kitura
docker pull ibmcom/kitura-ubuntu:latest


4) Run image with port forwarding <local port : container port>
E.g.
docker run --cap-add sys_ptrace -p 8095:8095 -t -i ibmcom/kitura-ubuntu:latest /bin/bash

5) Run / Download (if none) additional images and run as daemon
docker run -d -p 8080:8080 --name nodejs node
docker run -d -p 80:80 --name webserver nginx


6) List all downloaded or committed images
docker images

Download old images from
http://mirror.yandex.ru/mirrors/download.openvz.org/template/precreated/
and using import
cat ~/Downloads/ubuntu-10.04-x86.tar.gz | docker import - ubuntu-x86:10.04
or
docker import ubuntu-10.04-x86.tar.gz ubuntu-x86:10.04

docker run -t -i ubuntu-x86:10.04 bash


7) Run image with port forwarding <local port : container port> and bash shell
docker run -p 8095:8095 -t -i ibmcom/kitura-ubuntu:latest bash
docker run -p 80:80 -t -i nginx:latest bash
docker run -p 3000:3000 -t -i node:latest bash
docker run -t -i lballabio/quantlib:latest bash
docker run -t -i lballabio/quantlib-python:latest bash


8) List all containers with <CONTAINER ID>
docker ps -a
#export container
docker export <CONTAINER ID> > ubuntu.tar


Execute container with bash shell
docker exec -t -i <CONTAINER ID> bash

9) Commit changes to image with <newname:newtag>
docker commit <CONTAINER ID> kitura-ubuntu:v2
docker run -p 8095:8095 -it kitura-ubuntu:v2 /bin/bash

This is useful when you cannot start a container manually after docker upgraded. e.g.
docker start <CONTAINER ID> && docker attach <CONTAINER ID>


10) copy docker file to local docker start <CONTAINER ID>
docker cp <CONTAINER ID>:/root/myfile.tgz .




Docker for Mac OSX data is at
~/Library/Containers/com.docker.docker/Data



To test the kitura docker image for Swift web app
shell script    Select all
mkdir $HOME/play cd $HOME/play #swift build --init swift package init cat > $HOME/play/Package.swift <<EOF import PackageDescription let package = Package( name: "play", dependencies: [ .Package(url: "https://github.com/IBM-Swift/Kitura.git", majorVersion:0, minor:15), .Package(url: "https://github.com/OpenKitten/MongoKitten.git", majorVersion: 1, minor: 1) ] ) EOF mkdir -p $HOME/play/Sources cat > $HOME/play/Sources/main.swift <<EOF import Foundation import Kitura import KituraSys import KituraNet import MongoKitten // All Web apps need a Router instance to define routes let router = Router() // Simple Mongodb instance let dbserver: MongoKitten.Server! do { dbserver = try Server("mongodb://test:test@localhost:27017", automatically: true) let database = dbserver["workouts"] print("MongoDB is available at port 27017") } catch { // Unable to connect print("MongoDB is not available on the given host and port") } // Simple JSON Wrapper Support func JSON<KeyType, ValueType>(_ dictionary: [KeyType: ValueType]) -> String? { let bridgeValue = dictionary.bridge() do { let jsonData = try NSJSONSerialization.data(withJSONObject:bridgeValue, options: NSJSONWritingOptions.PrettyPrinted) let str = String(data:jsonData, encoding: NSUTF8StringEncoding) return(str) } catch let error as NSError{ print(error.description) return(nil) } } // Basic GET request router.get("/hello") { _, response, next in response.headers["Content-Type"] = "text/plain; charset=utf-8" do { try response.status(.OK).send("Hello World").end() } catch { print("ERROR: Failed to send response to client: \(error)") } } router.get("/today") { _, response, next in let now = NSDate() let dayTimePeriodFormatter = NSDateFormatter() dayTimePeriodFormatter.dateFormat = "E, d MMM yyyy" let dateString = dayTimePeriodFormatter.string(from:now) dayTimePeriodFormatter.dateFormat = "HH:mm:ss Z" let timeString = dayTimePeriodFormatter.string(from:now) response.headers["Content-Type"] = "text/plain; charset=utf-8" do { let payload = ["Message": "Hello World", "Date": dateString, "Time": timeString] if let json = JSON(payload) { try response.status(.OK).send(json).end() } else { try response.status(.OK).send("Does anybody really know what time it is ?").end() } } catch { print("ERROR: Failed to send response to client: \(error)") } } // Start server let port = 8095 let server = HTTPServer.listen(port:port, delegate: router) print("starting server on port \(port)") Server.run() EOF cd $HOME/play/Packages/SwiftyJSON-7.0.4/ git pull #there are 3 errors in Packages/Strand-1.4.1/Sources/Strand.swift and need to be changed before build #Strand.swift let pointer = UnsafeMutablePointer<Void>(holder.toOpaque()) #change to let pointer = UnsafeMutablePointer<Void>(OpaquePointer(bitPattern: holder)) let unmanaged = Unmanaged<StrandClosure>.fromOpaque(arg)] #change to let unmanaged = Unmanaged<StrandClosure>.fromOpaque(OpaquePointer(arg)) private func runner(arg: UnsafeMutablePointer<Void>?) -> UnsafeMutablePointer<Void>? { #change to private func runner(arg: UnsafeMutablePointer<Void>!) -> UnsafeMutablePointer<Void>! { and 1 error in Packages/MongoKitten-1.1.0/Sources/Server.swift let port: UInt16 = UInt16(url.port?.int16Value ?? 27017) # change to let port: UInt16 = UInt16(url.port?.shortValue ?? 27017) #build app cd $HOME/play swift build -Xcc -fblocks -Xlinker -rpath -Xlinker .build/debug #install and start mongodb server apt-get update apt-get install mongodb -y apt-get install lsb-release -y service mongodb start #create user in mongodb using mongo client mongo > use workouts > db.createUser( {user: "test", pwd: "test", roles: [ "readWrite", "dbAdmin" ]} ); > show users > exit #run app and use mac browser to localhost:8095/hello .build/debug/play






To test the node docker image for node.js web app
shell script    Select all
#install mongodb apt-get update apt-get install mongodb mongodb-server mongodb-clients -y #start mongdb service if not automatically service mongodb start #mongo shell script create user and to display info mongo > use workouts > db.addUser( {user: "test", pwd: "test", roles: [ "readWrite", "dbAdmin" ]} ); > show users > exit #download project file and copy to the container #the project file can be downloaded from here https://mega.nz/#!z9oFlTgJ!geCPHjoXJ3rpm1OdldU8s5RBSJxLKiAxh_axvTbODB4 docker cp ~/Download/nodeapi.zip 6d8baf06826e:/root #unzip and install apt-get install zip unzip -y cd $HOME unzip nodeapi.zip cd nodeapi npm install npm start #use docker to start another shell access to test docker exec -it 6d8baf06826e bash cd $HOME/nodeapi ./test1.sh ./test2.sh ./test3.sh ./test4.sh ./test5.sh ./test6.sh ...






To test the quantlib or quantlib-python3 docker image
shell script    Select all
apt-get update apt upgrade apt-get install python python-pip -y pip install --upgrade pip # Python 2 installation pip2 install numpy pip2 install QuantLib-Python # Python 3 installation apt-get install python3 python3-pip -y pip3 install numpy pip3 install QuantLib-Python # Install boost 1.71 export boost_version=1.71.0; export boost_dir=boost_1_71_0; wget https://dl.bintray.com/boostorg/release/${boost_version }/source/${boost_dir}.tar.gz && tar xfz ${boost_dir}.tar.gz && rm ${boost_dir}.tar.gz && cd ${boost_dir} && ./bootstrap.sh && ./b2 --without-python --prefix=/usr -j 4 link=shared runtime-link=shared install && cd .. && rm -rf ${boost_dir} && ldconfig # Install quantlib 1.17 export quantlib_version=1.17; wget https://dl.bintray.com/quantlib/releases/QuantLib-${quantlib_version}.tar.gz && tar xfz QuantLib-${quantlib_version}.tar.gz && rm QuantLib-${quantlib_version}.tar.gz && cd QuantLib-${quantlib_version} && ./configure --prefix=/usr --disable-static CXXFLAGS=-O3 && make -j 4 && make check && make install && cd .. && rm -rf QuantLib-${quantlib_version} && ldconfig # Test quantlib 1.17 cd $HOME cat > $HOME/qlversion.cpp <<EOF #include <iostream> #include <ql/version.hpp> int main() { std::cout << "Current QL Version:" << QL_LIB_VERSION << std::endl; return 0; } EOF g++ qlversion.cpp -o qlversion ./qlversion cat > $HOME/swap.py <<EOF import numpy as np import QuantLib as ql # Set Evaluation Date today = ql.Date(31,3,2015) ql.Settings.instance().setEvaluationDate(today) # Setup the yield termstructure rate = ql.SimpleQuote(0.03) rate_handle = ql.QuoteHandle(rate) dc = ql.Actual365Fixed() disc_curve = ql.FlatForward(today, rate_handle, dc) disc_curve.enableExtrapolation() hyts = ql.YieldTermStructureHandle(disc_curve) discount = np.vectorize(hyts.discount) start = ql.TARGET().advance(today, ql.Period('2D')) end = ql.TARGET().advance(start, ql.Period('10Y')) nominal = 1e7 typ = ql.VanillaSwap.Payer fixRate = 0.03 fixedLegTenor = ql.Period('1y') fixedLegBDC = ql.ModifiedFollowing fixedLegDC = ql.Thirty360(ql.Thirty360.BondBasis) index = ql.Euribor6M(ql.YieldTermStructureHandle(disc_curve)) spread = 0.0 fixedSchedule = ql.Schedule(start, end, fixedLegTenor, index.fixingCalendar(), fixedLegBDC, fixedLegBDC, ql.DateGeneration.Backward, False) floatSchedule = ql.Schedule(start, end, index.tenor(), index.fixingCalendar(), index.businessDayConvention(), index.businessDayConvention(), ql.DateGeneration.Backward, False) swap = ql.VanillaSwap(typ, nominal, fixedSchedule, fixRate, fixedLegDC, floatSchedule, index, spread, index.dayCounter()) engine = ql.DiscountingSwapEngine(ql.YieldTermStructureHandle(disc_curve)) swap.setPricingEngine(engine) print(swap.NPV()) print(swap.fairRate()) EOF python swap.py apt-get install git -y git clone git://github.com/mmport80/QuantLib-with-Python-Blog-Examples.git cd QuantLib-with-Python-Blog-Examples/ python2 blog_frn_example.py



Try docker-compose example as per https://docs.docker.com/compose/wordpress/
shell script    Select all
cd $HOME mkdir my-wordpress cd my-wordpress cat > docker-compose.yaml <<EOF version: '2' services: db: image: mysql:5.7 volumes: - "./.data/db:/var/lib/mysql" restart: always environment: MYSQL_ROOT_PASSWORD: wordpress MYSQL_DATABASE: wordpress MYSQL_USER: wordpress MYSQL_PASSWORD: wordpress wordpress: depends_on: - db image: wordpress:latest links: - db ports: - "8000:80" restart: always environment: WORDPRESS_DB_HOST: db:3306 WORDPRESS_DB_PASSWORD: wordpress EOF docker-compose up -d # then try browser http://localhost:8000/ # stop the docker-compose example docker-compose down