-
Notifications
You must be signed in to change notification settings - Fork 19
Compiling from source for WSL2 on Windows 10 (Ubuntu)
Chris Grandin edited this page Nov 24, 2022
·
22 revisions
Run this bash script in Ubuntu terminal from Windows 10. It will download the latest source, and install ADMB from source.
To run, save the script in a file called install_admb in your ~ directory and type:
chmod +x install_admb
./install_admb -d
#!/bin/bash
# https://stackoverflow.com/questions/192249/how-do-i-parse-command-line-arguments-in-bash
POSITIONAL=()
while [[ $# -gt 0 ]]; do
key="$1"
case $key in
-h|--help)
echo "Install ADMB from source. Also builds the ad2csv utility which allows you to convert ADMB binary files to CSV files."
echo
echo "Add the following to your ~/.bashrc file before running this script:"
echo 'export ADMB_HOME=~/admb/build/admb'
echo 'export ADMB_AD2CSV=~/admb/contrib/ad2csv'
echo 'export PATH=$ADMB_AD2CSV:$ADMB_HOME/bin:$HOME:$PATH'
echo
echo "Syntax: install_admb [-d|h]"
echo "Options:"
echo " -d, --download Download the source from GitHub first, then build."
echo " -h, --help Print this help."
shift
exit
;;
-d|--download)
DOWNLOAD=1
shift
;;
esac
done
set -- "${POSITIONAL[@]}" # restore positional parameters
cwd=$(pwd)
cd ~
if [[ -n "${DOWNLOAD}" ]]; then
rm -rf admb
echo "Removed ~/admb directory and all its contents."
git clone https://github.com/admb-project/admb
fi
cd admb
admb_dir=$(pwd)
# Add semicolons to the end of all lines in all sedflex files,
# and then remove ^M's which were added by the adding of semicolons step
sed -i '/[^;] *$/s/$/;/' src/df1b2-separable/sedflex
sed -i 's/\r//' src/df1b2-separable/sedflex
sed -i '/[^;] *$/s/$/;/' src/nh99/sedflex
sed -i 's/\r//' src/nh99/sedflex
sed -i '/[^;] *$/s/$/;/' tests/xml/sedflex
sed -i 's/\r//' tests/xml/sedflex
# Remove ^M's from admb, adcomp, and adlink scripts
sed -i 's/\r//' scripts/admb/adcomp
sed -i 's/\r//' scripts/admb/adlink
sed -i 's/\r//' scripts/admb/admb
num_cpus=`cat /proc/cpuinfo | grep processor | wc -l`
num_cpus_minus1=$((num_cpus-1))
make -j $num_cpus_minus1
# This link is required for the examples to build
ln -s build/admb/bin/admb admb || true
ll
# Contrib libraries need to be renamed, use symbolic links instead
cd $admb_dir/build/admb/lib
ln -s libadmb-x86_64-linux-g++11.a libadmb.a || true
ln -s libadmbo-x86_64-linux-g++11.a libadmbo.a || true
ln -s libadmb-contrib-x86_64-linux-g++11.a libadmb-contrib.a || true
ln -s libadmb-contribo-x86_64-linux-g++11.a libadmb-contribo.a || true
cd $admb_dir
# Now, build ad2csv
cd contrib/ad2csv
make
cd $cwd