# FROM efabless/dv:latest
# FROM efabless/dv_setup:latest
# Use the latest Ubuntu as the base image
FROM ubuntu:22.04


# Install essential packages
RUN apt-get update && \
    DEBIAN_FRONTEND=noninteractive apt-get install -y \
    python3 \
    python3-tk \
    python3-pip \
    git \
    help2man \
    perl \
    make \
    autoconf \
    g++ \
    flex \
    bison \
    ccache \
    libgoogle-perftools-dev \
    numactl \
    perl-doc \
    libfl2 \
    libfl-dev \
    zlib1g-dev\
    build-essential \
    wget\
    automake\
    autotools-dev\
    curl\
    libmpc-dev\
    libmpfr-dev\
    libgmp-dev\
    gawk\
    texinfo\
    libtool\
    patchutils\
    bc\
    libexpat-dev\
    ninja-build\
    cmake\
    libglib2.0-dev\
    gperf

# Upgrade pip
RUN pip3 install --upgrade pip

# Install Python packages using pip
RUN pip3 install --upgrade\
    cocotb \
    cocotb_coverage \
    cocotb-bus \
    coverage \
    loremipsum \
    oyaml \
    prettytable \
    anytree\
    caravel-cocotb

# Install Verilator from source v5.012
RUN git clone https://github.com/verilator/verilator && \
    cd verilator && \
    git pull && \
    git checkout v5.012 && \
    autoconf && \
    ./configure && \
    make -j $(nproc) && \
    make install && \
    cd .. && rm -rf verilator


# Clone and build open-src-cvc commit b3e7fded6d4d79491886de40aec3a780efdd9d4e
RUN git clone https://github.com/cambridgehackers/open-src-cvc.git && \
    cd open-src-cvc/ && git checkout b3e7fded6d4d79491886de40aec3a780efdd9d4e && \
    cd src && make -f makefile.cvc64 && \
    cp cvc64 /bin/cvc64 && \
    cd ../.. && rm -rf open-src-cvc

# Clone and build iverilog v12
RUN git clone https://github.com/steveicarus/iverilog.git && cd iverilog && \
    git checkout v12_0 && sh autoconf.sh && \
    ./configure && make && make install && \
    cd .. && rm -rf iverilog

# clone and install RISC-V toolchain v 2023.07.07
RUN git clone https://github.com/riscv/riscv-gnu-toolchain && \
    cd riscv-gnu-toolchain && git checkout 2023.07.07 && \
    ./configure --prefix=/opt/riscv --enable-multilib --with-arch=rv32gc --with-abi=ilp32 && \
    make && \
    cd .. && rm -rf riscv-gnu-toolchain

# Add toolchain to PATH
ENV PATH="/opt/riscv/bin:${PATH}"



# Clean up unnecessary files and packages
RUN apt-get clean && \
    rm -rf /var/lib/apt/lists/*

# Set the working directory
WORKDIR /app

# Default command when the container starts
CMD ["bash"]

# Add uvm-python
RUN git clone https://github.com/tpoikela/uvm-python.git && \
cd uvm-python && \
python3 -m pip install . && \
cd ../ && rm -rf uvm-python 
