correction to gdb-gcc build script
[dev-env-setup.git] / coriolis2-chroot
index f25bf805c0349a7f637a0c6b16e361b156cbf862..752a515249672a89d652f42061912899d9b7fc2e 100755 (executable)
@@ -3,6 +3,7 @@ if [ "$EUID" -ne 0 ]
   then echo "Please run as root"
   exit
 fi
   then echo "Please run as root"
   exit
 fi
+# Setup fstab mount points
 cat <<'EOF' >> /etc/fstab
 /dev      /opt/chroot/coriolis/dev      none   bind   0   0
 /dev/pts  /opt/chroot/coriolis/dev/pts  none   bind   0   0
 cat <<'EOF' >> /etc/fstab
 /dev      /opt/chroot/coriolis/dev      none   bind   0   0
 /dev/pts  /opt/chroot/coriolis/dev/pts  none   bind   0   0
@@ -10,17 +11,20 @@ cat <<'EOF' >> /etc/fstab
 /sys      /opt/chroot/coriolis/sys      none   bind   0   0
 /tmp      /opt/chroot/coriolis/tmp      none   bind   0   0
 EOF
 /sys      /opt/chroot/coriolis/sys      none   bind   0   0
 /tmp      /opt/chroot/coriolis/tmp      none   bind   0   0
 EOF
+# Create coriolis chroot dir in /opt
 mkdir -p /opt/chroot/coriolis
 mkdir -p /opt/chroot/coriolis
+# Install debootstrap and schroot via apt
 apt install -y debootstrap schroot
 apt install -y debootstrap schroot
+# Install debian/buster chroot using debootstrap
 /usr/sbin/debootstrap buster /opt/chroot/coriolis http://ftp.debian.org/debian
 /usr/sbin/debootstrap buster /opt/chroot/coriolis http://ftp.debian.org/debian
+# Mount all chroot mount points from fstab
 mount /opt/chroot/coriolis/dev
 mount /opt/chroot/coriolis/dev/pts
 mount /opt/chroot/coriolis/proc
 mount /opt/chroot/coriolis/sys
 mount /opt/chroot/coriolis/tmp
 echo "coriolis2" > /opt/chroot/coriolis/etc/debian_chroot
 mount /opt/chroot/coriolis/dev
 mount /opt/chroot/coriolis/dev/pts
 mount /opt/chroot/coriolis/proc
 mount /opt/chroot/coriolis/sys
 mount /opt/chroot/coriolis/tmp
 echo "coriolis2" > /opt/chroot/coriolis/etc/debian_chroot
-export MYNAME=`id 1000 | awk '{print $1}' | sed 's/.*(\(.*\))/\1/'`
-export CHU_HOME=/home/$MYNAME
+# Install apt dependencies in the chroot
 chroot /opt/chroot/coriolis /bin/bash << EOF
 echo Installing necessary apt dependencies in the chroot
 apt-get update -y
 chroot /opt/chroot/coriolis /bin/bash << EOF
 echo Installing necessary apt dependencies in the chroot
 apt-get update -y
@@ -28,36 +32,38 @@ apt-get upgrade -y
 apt-get install -y automake binutils-dev bison build-essential \
 ccache clang cmake doxygen dvipng flex gcc git graphviz \
 imagemagick libboost-all-dev libboost-python-dev libbz2-dev \
 apt-get install -y automake binutils-dev bison build-essential \
 ccache clang cmake doxygen dvipng flex gcc git graphviz \
 imagemagick libboost-all-dev libboost-python-dev libbz2-dev \
-libmotif-dev libreadline-dev libqwt-dev libtool libx11-dev \
-libxaw7-dev libxml2-dev libxpm-dev libxt-dev python3.7 \
-python3-jinja2 python3-pip python3-setuptools python-dev \
-python-qt4 python-sphinx qt4-dev-tools rapidjson-dev tcl \
-tcl-dev tcl-tclreadline texlive texlive-fonts-extra \
-texlive-lang-french texlive-latex-extra texlive-pictures \
-xfig yosys zlib1g-dev
+libmpfr-dev libgmp-dev libmotif-dev libreadline-dev \
+libqwt-dev libtool libx11-dev libxaw7-dev libxml2-dev \
+libxpm-dev libxt-dev python3.7 python3-jinja2 python3-pip \
+python3-setuptools python-dev python-qt4 python-sphinx \
+qt4-dev-tools rapidjson-dev tcl tcl-dev tcl-tclreadline \
+texlive texlive-fonts-extra texlive-lang-french \
+texlive-latex-extra texlive-pictures xfig yosys zlib1g-dev
 
 
 
 
-
-useradd -m -p `python -c 'import crypt; print crypt.crypt("1234","Fx")'` -s /bin/bash $MYNAME -k /etc/skel
+# Create user with same UID in the chroot
+useradd -m -p `python -c 'import crypt; print crypt.crypt("1234","Fx")'` -s /bin/bash $SUDO_USER -k /etc/skel
 echo -e "
 echo -e "
-Added user ${MYNAME} with \e[1;91mpassword: 1234\e[0m"
+Added user ${SUDO_USER} with \e[1;91mpassword: 1234\e[0m"
 
 echo -e "
 
 echo -e "
-\e[1;91mPlease use command 'passwd ${MYNAME}' to change this immediately after this script is run for security purposes.\e[0m
+\e[1;91mPlease use command 'passwd ${SUDO_USER}' to change this immediately after this script is run for security purposes.\e[0m
 "
 
 "
 
-echo -e 'export PATH=/usr/lib/ccache:"\044PATH"\nexport DISPLAY=:0.0\nexport ALLIANCE_TOP=$CHU_HOME/alliance/install\nexport LD_LIBRARY_PATH=\044{ALLIANCE_TOP}/lib:\044{LD_LIBRARY_PATH}\nexport LD_LIBRARY_PATH=\044{ALLIANCE_TOP}/lib64:\044{LD_LIBRARY_PATH}' > $CHU_HOME/.bash_profile
-chown $MYNAME $CHU_HOME/.bash_profile
-chgrp $MYNAME $CHU_HOME/.bash_profile
+# Add convenience variable to chroot user .bash_profile
+echo -e 'export PATH=/usr/lib/ccache:"\044PATH"\nexport DISPLAY=:0.0\nexport ALLIANCE_TOP=/home/$SUDO_USER/alliance/install\nexport YOSYS_TOP=/home/$SUDO_USER/yosys\nexport LD_LIBRARY_PATH=\044{ALLIANCE_TOP}/lib:\044{LD_LIBRARY_PATH}\nexport LD_LIBRARY_PATH=\044{ALLIANCE_TOP}/lib64:\044{LD_LIBRARY_PATH}' > /home/$SUDO_USER/.bash_profile
+chown $SUDO_USER /home/$SUDO_USER/.bash_profile
+chgrp $SUDO_USER /home/$SUDO_USER/.bash_profile
 
 
-echo -e "Added 'export PATH=/usr/lib/ccache:\"\044PATH\"\nexport DISPLAY=:0.0' to $CHU_HOME/.bash_profile to speed up rebuilds"
+echo -e "Added 'export PATH=/usr/lib/ccache:\"\044PATH\"\nexport DISPLAY=:0.0' to /home/$SUDO_USER/.bash_profile to speed up rebuilds"
 EOF
 
 EOF
 
+# Add coriolis config to schroot.conf
 cat <<EOF >>/etc/schroot/schroot.conf
 [coriolis]
 description=Debian Buster for Coriolis
 directory=/opt/chroot/coriolis
 cat <<EOF >>/etc/schroot/schroot.conf
 [coriolis]
 description=Debian Buster for Coriolis
 directory=/opt/chroot/coriolis
-groups=sbuild-security,$MYNAME,users
+groups=sbuild-security,$SUDO_USER,users
 EOF
 
 echo "Adding the following coriolis section to /etc/schroot/schroot.conf:
 EOF
 
 echo "Adding the following coriolis section to /etc/schroot/schroot.conf:
@@ -65,66 +71,86 @@ echo "Adding the following coriolis section to /etc/schroot/schroot.conf:
 [coriolis]
 description=Debian Buster for Coriolis
 directory=/opt/chroot/coriolis
 [coriolis]
 description=Debian Buster for Coriolis
 directory=/opt/chroot/coriolis
-groups=sbuild-security,$MYNAME,users
+groups=sbuild-security,$SUDO_USER,users
 
 This enables you to chroot into coriolis as an unprivileged user by running
 'schroot -c coriolis /bin/bash'
 "
 
 
 This enables you to chroot into coriolis as an unprivileged user by running
 'schroot -c coriolis /bin/bash'
 "
 
+# Build and install yosys from source
 chroot /opt/chroot/coriolis /bin/bash << EOF
 apt-get update -y 
 apt-get build-dep yosys -y
 apt-get remove yosys -y
 EOF
 chroot /opt/chroot/coriolis /bin/bash << EOF
 apt-get update -y 
 apt-get build-dep yosys -y
 apt-get remove yosys -y
 EOF
-runuser $MYNAME --preserve-environment -c 'schroot -c coriolis /bin/bash << EOF
-cd $CHU_HOME
+runuser $SUDO_USER --preserve-environment -c 'schroot -c coriolis /bin/bash << EOF
+cd /home/$SUDO_USER
 git clone https://github.com/cliffordwolf/yosys.git
 cd yosys
 make config-clang
 make -j$(nproc)
 EOF'
 git clone https://github.com/cliffordwolf/yosys.git
 cd yosys
 make config-clang
 make -j$(nproc)
 EOF'
+
 chroot /opt/chroot/coriolis /bin/bash << EOF
 chroot /opt/chroot/coriolis /bin/bash << EOF
-cd $CHU_HOME/yosys
+cd /home/$SUDO_USER/yosys
 make install
 EOF
 
 make install
 EOF
 
-runuser $MYNAME --preserve-environment -c 'schroot -c coriolis /bin/bash << EOF
-cd $CHU_HOME
-mkdir -p $CHU_HOME/alliance/build $CHU_HOME/alliance/install
-cd $CHU_HOME/alliance
+# Install coriolis2 from source
+runuser $SUDO_USER --preserve-environment -c 'schroot -c coriolis /bin/bash << EOF
+cd /home/$SUDO_USER
+source .bash_profile
+mkdir -p /home/$SUDO_USER/coriolis-2.x/src
+cd /home/$SUDO_USER/coriolis-2.x/src
+git clone https://gitlab.lip6.fr/vlsi-eda/coriolis.git
+cd coriolis
+git checkout devel
+./bootstrap/ccb.py --project=coriolis --make="-j$(nproc) install"
+
+# Setup and test coriolisenv
+/home/$SUDO_USER/coriolis-2.x/src/coriolis/bootstrap/coriolisEnv.py > /home/$SUDO_USER/coriolisenv
+source /home/$SUDO_USER/.bash_profile
+source /home/$SUDO_USER/coriolisenv
+EOF'
+
+# Install alliance from source
+runuser $SUDO_USER --preserve-environment -c 'schroot -c coriolis /bin/bash <<    EOF
+cd /home/$SUDO_USER
+source coriolisenv
 git clone https://gitlab.lip6.fr/vlsi-eda/alliance.git
 git clone https://gitlab.lip6.fr/vlsi-eda/alliance.git
-cd alliance/alliance/src
+mkdir -p /home/$SUDO_USER/alliance/build /home/$SUDO_USER/alliance/install
+mv alliance/alliance/src alliance
+rm -rf alliance/alliance
+cd alliance/src
 ./autostuff
 ./autostuff
-cd $CHU_HOME/alliance/build
-../alliance/alliance/src/configure --prefix=$ALLIANCE_TOP --enable-alc-shared
+cd /home/$SUDO_USER/alliance/build
+../src/configure --prefix=/home/$SUDO_USER/alliance/install --enable-alc-shared
 EOF'
 
 chroot /opt/chroot/coriolis /bin/bash << EOF
 EOF'
 
 chroot /opt/chroot/coriolis /bin/bash << EOF
-cd $CHU_HOME/alliance/build
+cd /home/$SUDO_USER/alliance/build
+source /home/$SUDO_USER/coriolisenv
 make -j1 install
 EOF
 
 make -j1 install
 EOF
 
-
-echo MYNAME $MYNAME
-echo CHU_HOME $CHU_HOME
-
-
-runuser $MYNAME --preserve-environment -c 'schroot -c coriolis /bin/bash << EOF
-cd $CHU_HOME
-mkdir -p $CHU_HOME/coriolis-2.x/src
-cd $CHU_HOME/coriolis-2.x/src
-git clone https://gitlab.lip6.fr/vlsi-eda/coriolis.git
-cd coriolis
-git checkout devel
-./bootstrap/ccb.py --project=coriolis --make="-j$(nproc) install"
-
-#ln -s $CHU_HOME/coriolis-2.x/Linux.x86_64/Release.Shared/install/lib64 $CHU_HOME/coriolis-2.x/Linux.x86_64/Release.Shared/install/lib
-#./bootstrap/ccb.py --project=coriolis --make="-j$(nproc) install"
-
-$CHU_HOME/coriolis-2.x/src/coriolis/bootstrap/coriolisEnv.py > $CHU_HOME/coriolisenv
-source $CHU_HOME/.bash_profile
-source $CHU_HOME/coriolisenv
-cd ~/coriolis-2.x/Linux.x86_64/Release.Shared/install/bin
-./cgt
+# Install and configure alliance-check-toolkit
+runuser $SUDO_USER --preserve-environment -c 'schroot -c coriolis /bin/bash << EOF
+cd /home/$SUDO_USER
+git clone https://gitlab.lip6.fr/vlsi-eda/alliance-check-toolkit.git
+source coriolisenv
+touch alliance-check-toolkit/etc/mk/users.d/user-$SUDO_USER.mk
+cat <<EOG >>alliance-check-toolkit/etc/mk/users.d/user-$SUDO_USER.mk
+export CORIOLIS_TOP=/home/$SUDO_USER/coriolis-2.x/Linux.x86_64/Release.Shared/install
+export ALLIANCE_TOP=/home/$SUDO_USER/alliance/install
+export CHECK_TOOLKIT=/home/$SUDO_USER/alliance-check-toolkit
+export YOSYS_TOP=/home/$SUDO_USER/yosys
+EOG
+source /home/$SUDO_USER/.bash_profile
+cd alliance-check-toolkit/benchs/ARM/cmos
+make lvx
+echo -e "
+\e[1;91mSelect File -> Open Cell or press CTRL + o then enter as the cell name 'arm_chip_cts_r' without the single quotation marks.\e[0m
+"
+make cgt
 EOF'
 
 EOF'