Skip to content

Instantly share code, notes, and snippets.

@CTXz
Last active January 17, 2023 18:46
Show Gist options
  • Save CTXz/082c90dc9f58dc5387180dbf225e43bc to your computer and use it in GitHub Desktop.
Save CTXz/082c90dc9f58dc5387180dbf225e43bc to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
# Installation and fix script for ModelSim 16.1 on Ubuntu 22.04
# Author: Patrick Pedersen <ctx.xda@gmail.com>
# Date: 2023-01-17
# NOTE: This script has been developed for- and tested on Ubuntu 22.04
# It may or may not work on other distributions
# Usage:
# $ sudo ./modelsim_fix_ubuntu-22.04.sh [install|fix]
# install - Downloads ModelSim 16.1 and launches the installer
# fix - Fixes a ModelSim 16.1 installation (assuming it is in $HOME/intelFPGA*)
#
# Ensure ModelSim is installed (using the install option) before fixing it!
shopt -s extglob
USR=$(who am i | awk '{print $1}')
HOME_DIR=$(getent passwd $USR | cut -d: -f6)
INTEL_FPGA_DIR=$(echo $HOME_DIR/intelFPGA*/*.*) # intelFPGA* because it may also be ending with _pro
MODELSIM_DIR=$INTEL_FPGA_DIR/modelsim_ase
DEPS_64=build-essential
DEPS_32=" \
gcc-multilib \
g++-multilib \
libc6:i386 \
libncurses5:i386 \
libstdc++6:i386 \
libxft2:i386 \
libxtst6:i386 \
lib32stdc++6 \
lib32gcc-s1 \
expat:i386 \
fontconfig:i386 \
libfreetype6:i386 \
libexpat1:i386 \
libgtk-3-0:i386 \
libcanberra0:i386 \
libpng-dev:i386 \
libice6:i386 \
libsm6:i386 \
zlib1g:i386 \
libx11-6:i386 \
libxau6:i386 \
libxdmcp6:i386 \
libxext6:i386 \
libxrender1:i386 \
libxt6:i386 \
"
# Check if user is root
if [ "$EUID" -ne 0 ]; then
echo "Please run as root"
exit 1
fi
# Check if installer option is passed
function install_modelsim() {
echo "Downloading ModelSim installer"
cd /tmp
if [ ! -f ModelSimSetup-16.1.0.196-linux.run ]; then
wget https://profile.iiita.ac.in/bibhas.ghoshal/COA_2020/Lab/ModelSimSetup-16.1.0.196-linux.run
fi
chmod +x ModelSimSetup-16.1.0.196-linux.run
echo "Launching ModelSim installer"
echo "Please complete the installation wizard"
#run in background
runuser -u $USR ./ModelSimSetup-16.1.0.196-linux.run &
cd -
}
function fix_modelsim() {
chmod u+w $MODELSIM_DIR/vco
if [ $? -ne 0 ]; then
echo "Failed to make vco script writable"
exit 1
fi
echo "Backing up vco script to $MODELSIM_DIR/vco.bak"
cp $MODELSIM_DIR/vco $MODELSIM_DIR/vco.bak
if [ $? -ne 0 ]; then
echo "Failed to backup vco script"
exit 1
fi
echo "Patching up vco script"
# Fix vco script
sed -i 's/linux\_rh[[:digit:]]\+/linux/g' $MODELSIM_DIR/vco
sed -i 's/MTI_VCO_MODE:-""/MTI_VCO_MODE:-"32"/g' $MODELSIM_DIR/vco
sed -i '/dir=`dirname "$arg0"`/a export LD_LIBRARY_PATH=${dir}/lib32' $MODELSIM_DIR/vco
if [ $? -ne 0 ]; then
echo "Failed to patch vco script"
exit 1
fi
# Diff vco script
echo "The following changes have been made to vco script:"
diff $MODELSIM_DIR/vco.bak $MODELSIM_DIR/vco
# Download the old 32-bit version of libfreetype
echo "Downloading 32-bit version of libfreetype..."
cd /tmp
if [ ! -f freetype-2.4.12.tar.bz2 ]; then
wget https://ftp.osuosl.org/pub/blfs/conglomeration/freetype/freetype-2.4.12.tar.bz2
fi
tar xjf freetype-2.4.12.tar.bz2
echo "Compiling libfreetype..."
# Compile libfreetype
cd freetype-2.4.12/
./configure --build=i686-pc-linux-gnu "CFLAGS=-m32" "CXXFLAGS=-m32" "LDFLAGS=-m32"
make clean
make
if [ $? -ne 0 ]; then
echo "Failed to compile libfreetype"
exit 1
fi
echo "Copying libfreetype to $MODELSIM_DIR/lib32"
cd $MODELSIM_DIR
mkdir -p lib32
cp /tmp/freetype-2.4.12/objs/.libs/libfreetype.so* lib32/
echo
echo "ModelSim should now be fixed!"
echo
echo "To add ModelSim to path, add the following line to your .bashrc file:"
echo " export PATH=$MODELSIM_DIR/bin:\$PATH"
echo
}
if [ $# -eq 0 ]; then
echo "Usage: $0 [install|fix]"
exit 1
fi
# Download necessary 32bit libs
echo "Downloading build essentials..."
apt install -y $DEPS_64
echo "Downloading necessary 32bit packages..."
dpkg --add-architecture i386
apt update
apt install -y ${DEPS_32}
if [ $? -ne 0 ]; then
echo "Failed to install necessary 32bit libs"
exit 1
fi
if [ "$1" == "install" ]; then
# Check if user is root
install_modelsim
elif [ "$1" == "fix" ]; then
echo "Fixing ModelSim"
fix_modelsim
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment