Fix correct commit hash for release 0.7.0 of openXC7
[dev-env-setup.git] / coriolis2-chroot
1 #!/bin/bash
2 if [ "$EUID" -ne 0 ]
3 then echo "Please run as root"
4 exit
5 fi
6 # Setup fstab mount points
7 cat <<'EOF' >> /etc/fstab
8 /dev /opt/chroot/coriolis/dev none bind 0 0
9 /dev/pts /opt/chroot/coriolis/dev/pts none bind 0 0
10 /proc /opt/chroot/coriolis/proc none bind 0 0
11 /sys /opt/chroot/coriolis/sys none bind 0 0
12 /tmp /opt/chroot/coriolis/tmp none bind 0 0
13 EOF
14 # Create coriolis chroot dir in /opt
15 mkdir -p /opt/chroot/coriolis
16 # Install debootstrap and schroot via apt
17 apt install -y debootstrap schroot
18 # Install debian/buster chroot using debootstrap
19 /usr/sbin/debootstrap buster /opt/chroot/coriolis http://ftp.debian.org/debian
20 # Mount all chroot mount points from fstab
21 mount /opt/chroot/coriolis/dev
22 mount /opt/chroot/coriolis/dev/pts
23 mount /opt/chroot/coriolis/proc
24 mount /opt/chroot/coriolis/sys
25 mount /opt/chroot/coriolis/tmp
26 echo "coriolis2" > /opt/chroot/coriolis/etc/debian_chroot
27 # Install apt dependencies in the chroot
28 chroot /opt/chroot/coriolis /bin/bash << EOF
29 echo Installing necessary apt dependencies in the chroot
30 apt-get update -y
31 apt-get upgrade -y
32 apt-get install -y automake binutils-dev bison build-essential \
33 sysvinit-utils sysvinit-core \
34 ccache clang cmake doxygen dvipng flex gcc git graphviz \
35 imagemagick libboost-all-dev libboost-python-dev libbz2-dev \
36 libmpfr-dev libgmp-dev libmotif-dev libreadline-dev \
37 libqwt-dev libtool libx11-dev libxaw7-dev libxml2-dev \
38 libxpm-dev libxt-dev python3.7 python3-jinja2 python3-pip \
39 python3-setuptools python-dev python-qt4 python-sphinx \
40 qt4-dev-tools rapidjson-dev tcl tcl-dev tcl-tclreadline \
41 texlive texlive-fonts-extra texlive-lang-french \
42 texlive-latex-extra texlive-pictures xfig yosys zlib1g-dev
43
44 # yeah don't add systemd in a chroot. not funny joke
45 apt-get remove -y systemd
46
47 # Create user with same UID in the chroot
48 useradd -m -p `python -c 'import crypt; print crypt.crypt("1234","Fx")'` -s /bin/bash $SUDO_USER -k /etc/skel
49 echo -e "
50 Added user ${SUDO_USER} with \e[1;91mpassword: 1234\e[0m"
51
52 echo -e "
53 \e[1;91mPlease use command 'passwd ${SUDO_USER}' to change this immediately after this script is run for security purposes.\e[0m
54 "
55
56 # Add convenience variable to chroot user .bash_profile
57 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
58 chown $SUDO_USER /home/$SUDO_USER/.bash_profile
59 chgrp $SUDO_USER /home/$SUDO_USER/.bash_profile
60
61 echo -e "Added 'export PATH=/usr/lib/ccache:\"\044PATH\"\nexport DISPLAY=:0.0' to /home/$SUDO_USER/.bash_profile to speed up rebuilds"
62 EOF
63
64 # Add coriolis config to schroot.conf
65 cat <<EOF >>/etc/schroot/schroot.conf
66 [coriolis]
67 description=Debian Buster for Coriolis
68 directory=/opt/chroot/coriolis
69 groups=sbuild-security,$SUDO_USER,users
70 EOF
71
72 echo "Adding the following coriolis section to /etc/schroot/schroot.conf:
73
74 [coriolis]
75 description=Debian Buster for Coriolis
76 directory=/opt/chroot/coriolis
77 groups=sbuild-security,$SUDO_USER,users
78
79 This enables you to chroot into coriolis as an unprivileged user by running
80 'schroot -c coriolis /bin/bash'
81 "
82
83 # Build and install yosys from source
84 # note that a specific version of yosys is needed for ls180 at the moment
85 chroot /opt/chroot/coriolis /bin/bash << EOF
86 apt-get update -y
87 apt-get build-dep yosys -y
88 apt-get remove yosys -y
89 EOF
90 runuser $SUDO_USER --preserve-environment -c 'schroot -c coriolis /bin/bash << EOF
91 cd /home/$SUDO_USER
92 git clone https://github.com/cliffordwolf/yosys.git
93 cd yosys
94 git checkout 049e3abf9baf795e69b9ecb9c4f19de6131f8418
95 make config-clang
96 make -j$(nproc)
97 EOF'
98
99 chroot /opt/chroot/coriolis /bin/bash << EOF
100 cd /home/$SUDO_USER/yosys
101 make install
102 EOF
103
104 # Install coriolis2 from source
105 runuser $SUDO_USER --preserve-environment -c 'schroot -c coriolis /bin/bash << EOF
106 cd /home/$SUDO_USER
107 source .bash_profile
108 mkdir -p /home/$SUDO_USER/coriolis-2.x/src
109 cd /home/$SUDO_USER/coriolis-2.x/src
110 git clone https://gitlab.lip6.fr/vlsi-eda/coriolis.git
111 cd coriolis
112 git checkout devel
113 ./bootstrap/ccb.py --project=coriolis --make="-j$(nproc) install"
114
115 # Setup and test coriolisenv
116 /home/$SUDO_USER/coriolis-2.x/src/coriolis/bootstrap/coriolisEnv.py > /home/$SUDO_USER/coriolisenv
117 source /home/$SUDO_USER/.bash_profile
118 source /home/$SUDO_USER/coriolisenv
119 EOF'
120
121 # Install alliance from source
122 runuser $SUDO_USER --preserve-environment -c 'schroot -c coriolis /bin/bash << EOF
123 cd /home/$SUDO_USER
124 source coriolisenv
125 git clone https://gitlab.lip6.fr/vlsi-eda/alliance.git
126 mkdir -p /home/$SUDO_USER/alliance/build /home/$SUDO_USER/alliance/install
127 mv alliance/alliance/src alliance
128 rm -rf alliance/alliance
129 cd alliance/src
130 ./autostuff
131 cd /home/$SUDO_USER/alliance/build
132 ../src/configure --prefix=/home/$SUDO_USER/alliance/install --enable-alc-shared
133 EOF'
134
135 chroot /opt/chroot/coriolis /bin/bash << EOF
136 cd /home/$SUDO_USER/alliance/build
137 source /home/$SUDO_USER/coriolisenv
138 make -j1 install
139 EOF
140
141 # Install and configure alliance-check-toolkit
142 runuser $SUDO_USER --preserve-environment -c 'schroot -c coriolis /bin/bash << EOF
143 cd /home/$SUDO_USER
144 git clone https://gitlab.lip6.fr/vlsi-eda/alliance-check-toolkit.git
145 source coriolisenv
146 touch alliance-check-toolkit/etc/mk/users.d/user-$SUDO_USER.mk
147 cat <<EOG >>alliance-check-toolkit/etc/mk/users.d/user-$SUDO_USER.mk
148 export CORIOLIS_TOP=/home/$SUDO_USER/coriolis-2.x/Linux.x86_64/Release.Shared/install
149 export ALLIANCE_TOP=/home/$SUDO_USER/alliance/install
150 export CHECK_TOOLKIT=/home/$SUDO_USER/alliance-check-toolkit
151 export YOSYS_TOP=/home/$SUDO_USER/yosys
152 EOG
153 source /home/$SUDO_USER/.bash_profile
154 cd alliance-check-toolkit/benchs/ARM/cmos
155 make lvx
156 echo -e "
157 \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
158 "
159 make cgt
160 EOF'
161