|
set dotenv-load := true |
|
|
|
alias r := rebuild-toolchain |
|
|
|
# TODO: |
|
# * mkdir -p for all build directories (via init recipe?). |
|
# * Recipes to split out ghdl-yosys-plugin and SymbiYosys again? |
|
# * Use more consistent line breaks. |
|
# * openocd, litex, and amaranth recipes? |
|
|
|
# Rebuild order shouldn't matter, but GHDL needs to be built before yosys on |
|
# Windows and I haven't bothered making the dep order match the recipes in this |
|
# file. |
|
# Rebuild all toolchains. |
|
rebuild-toolchains: (rebuild-toolchain "ecp5") (rebuild-toolchain "ice40") (rebuild-toolchain "ghdl") (rebuild-toolchain "iverilog") (rebuild-toolchain "verilator") (rebuild-toolchain "openocd") (rebuild-toolchain "dfu") (rebuild-toolchain "ofl") (rebuild-toolchain "yosys") (rebuild-toolchain "generic") |
|
|
|
# Rebuild a given FOSS FPGA toolchain. |
|
rebuild-toolchain FAMILY DRY="0" SKIP_CHECK="0": |
|
#!/bin/sh |
|
|
|
case {{FAMILY}} in |
|
"ice40") |
|
just -f "{{justfile()}}" _rebuild-ice40 {{DRY}} {{SKIP_CHECK}} |
|
;; |
|
|
|
"ecp5") |
|
just -f "{{justfile()}}" _rebuild-ecp5 {{DRY}} {{SKIP_CHECK}} |
|
;; |
|
|
|
"yosys") |
|
just -f "{{justfile()}}" _rebuild-yosys {{DRY}} {{SKIP_CHECK}} |
|
;; |
|
|
|
"iverilog") |
|
just -f "{{justfile()}}" _rebuild-iverilog {{DRY}} {{SKIP_CHECK}} |
|
;; |
|
|
|
"ghdl") |
|
just -f "{{justfile()}}" _rebuild-ghdl {{DRY}} {{SKIP_CHECK}} |
|
;; |
|
|
|
"generic") |
|
just -f "{{justfile()}}" _rebuild-generic {{DRY}} {{SKIP_CHECK}} |
|
;; |
|
|
|
"openocd") |
|
just -f "{{justfile()}}" _rebuild-openocd {{DRY}} {{SKIP_CHECK}} |
|
;; |
|
|
|
"dfu-util" | "dfu") |
|
just -f "{{justfile()}}" _rebuild-dfu {{DRY}} {{SKIP_CHECK}} |
|
;; |
|
|
|
"openfpgaloader" | "ofl") |
|
just -f "{{justfile()}}" _rebuild-ofl {{DRY}} {{SKIP_CHECK}} |
|
;; |
|
|
|
"verilator") |
|
just -f "{{justfile()}}" _rebuild-verilator {{DRY}} {{SKIP_CHECK}} |
|
;; |
|
|
|
*) |
|
echo "Unrecognized toolchain {{FAMILY}}" |
|
exit 1 |
|
;; |
|
esac |
|
|
|
# Rebuild the ECP5 toolchain |
|
_rebuild-ecp5 DRY="0" SKIP_CHECK="0" CHIPDB="quick": |
|
#!/bin/sh |
|
|
|
set -e |
|
|
|
. "{{justfile_directory()}}/common.sh" |
|
|
|
set_dry {{DRY}} |
|
set_cmake_vars_if_sccache |
|
|
|
if [ {{CHIPDB}} != "none" ]; then |
|
if [ $NEXTPNR_EXTERN_CHIPDB -eq 0 ]; then |
|
cd $FPGA_ROOT/prjtrellis/libtrellis |
|
check_branch {{SKIP_CHECK}} ${TRELLIS_REMOTE-origin} ${TRELLIS_BRANCH-master} |
|
cmake -G"Ninja" -DCMAKE_INSTALL_PREFIX=$PREFIX $CMAKE_SCCACHE_OPTS . |
|
ninja -j${TRELLIS_JOBS-$NUM_JOBS} $MKDRY |
|
ninja $MKDRY install |
|
ninja_clean_if_sccache |
|
build_nextpnr_chipdbs ecp5 {{CHIPDB}} {{SKIP_CHECK}} ${NEXTPNR_REMOTE-origin} ${NEXTPNR_BRANCH-master} |
|
else |
|
get_remote_chipdbs ecp5 |
|
fi |
|
fi |
|
|
|
# build_nextpnr_chipdbs will also make sure remote is up-to-date for you. |
|
if [ {{CHIPDB}} != "only" ] && [ {{CHIPDB}} != "only-full" ]; then |
|
build_nextpnr ecp5 ${ECP5_JOBS-$NUM_JOBS} ${NEXTPNR_LO_MEM-0} {{SKIP_CHECK}} ${NEXTPNR_REMOTE-origin} ${NEXTPNR_BRANCH-master} |
|
fi |
|
|
|
# Rebuild the iCE40 toolchain |
|
_rebuild-ice40 DRY="0" SKIP_CHECK="0" CHIPDB="quick": |
|
#!/bin/sh |
|
|
|
set -e |
|
|
|
. "{{justfile_directory()}}/common.sh" |
|
|
|
set_dry {{DRY}} |
|
set_cmake_vars_if_sccache |
|
|
|
if [ {{CHIPDB}} != "none" ]; then |
|
if [ $NEXTPNR_EXTERN_CHIPDB -eq 0 ]; then |
|
cd $FPGA_ROOT/icestorm |
|
check_branch {{SKIP_CHECK}} ${ICESTORM_REMOTE-origin} ${ICESTORM_BRANCH-master} |
|
make_begin_if_sccache |
|
make -j${ICESTORM_JOBS-$NUM_JOBS} $MKDRY PREFIX=$PREFIX |
|
make_end_if_sccache |
|
make $MKDRY PREFIX=$PREFIX install |
|
make_clean_if_sccache |
|
build_nextpnr_chipdbs ice40 {{CHIPDB}} {{SKIP_CHECK}} ${NEXTPNR_REMOTE-origin} ${NEXTPNR_BRANCH-master} |
|
else |
|
get_remote_chipdbs ice40 |
|
fi |
|
fi |
|
|
|
# build_nextpnr_chipdbs will also make sure remote is up-to-date for you. |
|
if [ {{CHIPDB}} != "only" ] && [ {{CHIPDB}} != "only-full" ]; then |
|
build_nextpnr ice40 ${ICE40_JOBS-$NUM_JOBS} ${NEXTPNR_LO_MEM-0} {{SKIP_CHECK}} ${NEXTPNR_REMOTE-origin} ${NEXTPNR_BRANCH-master} |
|
fi |
|
|
|
# Rebuild the yosys toolchain |
|
_rebuild-yosys DRY="0" SKIP_CHECK="0": |
|
#!/bin/sh |
|
|
|
set -e |
|
|
|
. "{{justfile_directory()}}/common.sh" |
|
|
|
set_dry {{DRY}} |
|
|
|
cd $FPGA_ROOT/yosys |
|
check_branch {{SKIP_CHECK}} ${YOSYS_REMOTE-origin} ${YOSYS_BRANCH-master} |
|
if [ "{{os()}}" = "windows" ]; then |
|
# Invoking just will mess with the environment variable path |
|
# pkg-config- restore it. |
|
export PKG_CONFIG_PATH=/mingw64/lib/pkgconfig:/mingw64/share/pkgconfig |
|
fi |
|
# ENABLE_GHDL not handled here- must be added manually to Makefile.conf. |
|
# Eventually Windows will load it like a plugin. |
|
make -j${YOSYS_JOBS-$NUM_JOBS} $MKDRY PREFIX=$PREFIX ENABLE_SCCACHE=${SCCACHE:-0} |
|
make $MKDRY PREFIX=$PREFIX install |
|
make_clean_if_sccache |
|
|
|
cd $FPGA_ROOT/SymbiYosys |
|
check_branch {{SKIP_CHECK}} ${SYMBIYOSYS_REMOTE-origin} ${SYMBIYOSYS_BRANCH-master} |
|
make $MKDRY PREFIX=$PREFIX install |
|
|
|
# Rebuild the iverilog toolchain |
|
_rebuild-iverilog DRY="0" SKIP_CHECK="0": |
|
#!/bin/sh |
|
|
|
set -e |
|
|
|
. "{{justfile_directory()}}/common.sh" |
|
|
|
set_dry {{DRY}} |
|
|
|
cd $FPGA_ROOT/iverilog |
|
check_branch {{SKIP_CHECK}} ${IVERILOG_REMOTE-origin} ${IVERILOG_BRANCH-master} |
|
cd $FPGA_ROOT/build-iverilog |
|
autoconf_begin_if_sccache |
|
../iverilog/configure --prefix=$PREFIX # --no-create --no-recursion |
|
autoconf_end_if_sccache |
|
make -j${IVERILOG_JOBS-$NUM_JOBS} $MKDRY |
|
make $MKDRY install |
|
make_clean_if_sccache |
|
|
|
# Rebuild the verilator simulator |
|
_rebuild-verilator DRY="0" SKIP_CHECK="0": |
|
#!/bin/sh |
|
|
|
set -e |
|
|
|
. "{{justfile_directory()}}/common.sh" |
|
|
|
set_dry {{DRY}} |
|
|
|
cd $FPGA_ROOT/verilator |
|
check_branch {{SKIP_CHECK}} ${VERILATOR_REMOTE-origin} ${VERILATOR_BRANCH-master} |
|
if [ "{{os()}}" = "windows" ]; then |
|
# Known issue w/ MinGW: |
|
cp /usr/include/FlexLexer.h $PREFIX/include |
|
fi |
|
autoconf |
|
|
|
autoconf_begin_if_sccache |
|
./configure --prefix=$PREFIX |
|
autoconf_end_if_sccache |
|
make -j${VERILATOR_JOBS-$NUM_JOBS} $MKDRY |
|
make $MKDRY install |
|
make_clean_if_sccache |
|
|
|
# Rebuild the GHDL toolchain |
|
_rebuild-ghdl DRY="0" SKIP_CHECK="0": |
|
#!/bin/sh |
|
|
|
set -e |
|
|
|
. "{{justfile_directory()}}/common.sh" |
|
|
|
set_dry {{DRY}} |
|
|
|
cd $FPGA_ROOT/ghdl |
|
check_branch {{SKIP_CHECK}} ${GHDL_REMOTE-origin} ${GHDL_BRANCH-master} |
|
cd $FPGA_ROOT/build-ghdl |
|
# if [ "{{os()}}" = "windows" ]; then |
|
GHDL_BACKEND="--with-llvm-config" |
|
# fi |
|
|
|
# autoconf_begin_if_sccache |
|
../ghdl/configure --prefix=$PREFIX --enable-libghdl $GHDL_BACKEND |
|
# autoconf_end_if_sccache |
|
|
|
make -j${GHDL_JOBS-$NUM_JOBS} $MKDRY |
|
make $MKDRY install |
|
# make_clean_if_sccache # If sccache support ever added, uncomment. |
|
|
|
cd $FPGA_ROOT/ghdl-yosys-plugin |
|
check_branch {{SKIP_CHECK}} ${GHDL_PLUGIN_REMOTE-origin} ${GHDL_PLUGIN_BRANCH-master} |
|
if [ "{{os()}}" = "windows" ]; then |
|
mkdir -p $FPGA_ROOT/yosys/frontends/ghdl |
|
cp src/* $FPGA_ROOT/yosys/frontends/ghdl |
|
else |
|
# Number of ninja jobs is not manually set here. |
|
make $MKDRY |
|
make $MKDRY install |
|
fi |
|
|
|
# Rebuild the generic toolchain |
|
_rebuild-generic DRY="0" SKIP_CHECK="0": |
|
#!/bin/sh |
|
|
|
set -e |
|
|
|
. "{{justfile_directory()}}/common.sh" |
|
|
|
set_dry {{DRY}} |
|
set_cmake_vars_if_sccache |
|
|
|
build_nextpnr generic ${GENERIC_JOBS-$NUM_JOBS} ${NEXTPNR_LO_MEM-0} {{SKIP_CHECK}} ${NEXTPNR_REMOTE-origin} ${NEXTPNR_BRANCH-master} |
|
|
|
# Rebuild openocd |
|
_rebuild-openocd DRY="0" SKIP_CHECK="0": |
|
#!/bin/sh |
|
|
|
set -e |
|
|
|
. "{{justfile_directory()}}/common.sh" |
|
|
|
set_dry {{DRY}} |
|
|
|
cd $FPGA_ROOT/openocd |
|
check_branch {{SKIP_CHECK}} ${OPENOCD_REMOTE-origin} ${OPENOCD_BRANCH-master} |
|
if [ "{{os()}}" = "windows" ]; then |
|
# Invoking just will mess with the paths aclocal looks at- restore it. |
|
export ACLOCAL_PATH="/usr/share/aclocal/" |
|
fi |
|
./bootstrap |
|
|
|
cd $FPGA_ROOT/build-openocd |
|
autoconf_begin_if_sccache |
|
# jimtcl's autosetup consults CCACHE, and won't play nicely w/ sccache. |
|
CCACHE=none ../openocd/configure --prefix=$PREFIX # --no-create --no-recursion |
|
autoconf_end_if_sccache |
|
make -j${OPENOCD_JOBS-$NUM_JOBS} $MKDRY |
|
make $MKDRY install |
|
make_clean_if_sccache |
|
|
|
# Rebuild dfu-util |
|
_rebuild-dfu DRY="0" SKIP_CHECK="0": |
|
#!/bin/sh |
|
|
|
set -e |
|
|
|
. "{{justfile_directory()}}/common.sh" |
|
|
|
set_dry {{DRY}} |
|
|
|
cd $FPGA_ROOT/dfu-util |
|
check_branch {{SKIP_CHECK}} ${DFU_REMOTE-origin} ${DFU_BRANCH-master} |
|
if [ "{{os()}}" = "windows" ]; then |
|
# Invoking just will mess with the paths aclocal looks at- restore it. |
|
export ACLOCAL_PATH="/usr/share/aclocal/" |
|
fi |
|
./autogen.sh |
|
|
|
cd $FPGA_ROOT/build-dfu |
|
autoconf_begin_if_sccache |
|
../dfu-util/configure --prefix=$PREFIX |
|
autoconf_end_if_sccache |
|
make -j${DFU_JOBS-$NUM_JOBS} $MKDRY |
|
make $MKDRY install |
|
make_clean_if_sccache |
|
|
|
# Rebuild openFPGALoader |
|
_rebuild-ofl DRY="0" SKIP_CHECK="0": |
|
#!/bin/sh |
|
|
|
set -e |
|
|
|
. "{{justfile_directory()}}/common.sh" |
|
|
|
set_dry {{DRY}} |
|
set_cmake_vars_if_sccache |
|
|
|
cd $FPGA_ROOT/openFPGALoader |
|
check_branch {{SKIP_CHECK}} ${OFL_REMOTE-origin} ${OFL_BRANCH-master} |
|
cd $FPGA_ROOT/openFPGALoader/build |
|
cmake -G"Ninja" -DCMAKE_INSTALL_PREFIX=$PREFIX $CMAKE_SCCACHE_OPTS .. |
|
ninja -j${OFL_JOBS-$NUM_JOBS} $MKDRY |
|
ninja $MKDRY install |
|
ninja_clean_if_sccache |
|
|
|
# Change all branches to master for the duration of this script (fail if not possible). |
|
prepare CLEAN="0": |
|
#!/bin/sh |
|
|
|
set -e |
|
|
|
# $1- Desired branch |
|
switch_if_not_desired_branch() { |
|
CURR_BR=`git rev-parse --symbolic-full-name --abbrev-ref HEAD` |
|
if [ $CURR_BR = $1 ]; then |
|
echo "Branch set to $1 on `pwd` already" |
|
else |
|
git checkout $1 |
|
fi |
|
} |
|
|
|
# $1- Directory to change to. |
|
make_clean_if_clean() { |
|
if [ {{CLEAN}} -ne 0 ]; then |
|
cd $1 |
|
make clean |
|
fi |
|
} |
|
|
|
# $1- Directory to change to. |
|
ninja_clean_if_clean() { |
|
if [ {{CLEAN}} -ne 0 ]; then |
|
cd $1 |
|
ninja clean |
|
fi |
|
} |
|
|
|
cd $FPGA_ROOT/icestorm |
|
switch_if_not_desired_branch ${ICESTORM_BRANCH-master} |
|
make_clean_if_clean `pwd` |
|
|
|
cd $FPGA_ROOT/prjtrellis/libtrellis |
|
switch_if_not_desired_branch ${TRELLIS_BRANCH-master} |
|
ninja_clean_if_clean `pwd` |
|
|
|
cd $FPGA_ROOT/nextpnr |
|
switch_if_not_desired_branch ${NEXTPNR_BRANCH-master} |
|
ninja_clean_if_clean $FPGA_ROOT/nextpnr/build-ice40 |
|
ninja_clean_if_clean $FPGA_ROOT/nextpnr/build-ecp5 |
|
|
|
cd $FPGA_ROOT/yosys |
|
switch_if_not_desired_branch ${YOSYS_BRANCH-master} |
|
if [ {{CLEAN}} -ne 0 ] && [ "{{os()}}" = "windows" ]; then |
|
# Invoking just will mess with the environment variable path |
|
# pkg-config- restore it. |
|
export PKG_CONFIG_PATH=/mingw64/lib/pkgconfig:/mingw64/share/pkgconfig |
|
fi |
|
make_clean_if_clean `pwd` |
|
|
|
cd $FPGA_ROOT/SymbiYosys |
|
switch_if_not_desired_branch ${SYMBIYOSYS_BRANCH-master} |
|
make_clean_if_clean `pwd` |
|
|
|
cd $FPGA_ROOT/iverilog |
|
switch_if_not_desired_branch ${IVERILOG_BRANCH-master} |
|
make_clean_if_clean $FPGA_ROOT/build-iverilog |
|
|
|
cd $FPGA_ROOT/verilator |
|
switch_if_not_desired_branch ${VERILATOR_BRANCH-master} |
|
make_clean_if_clean `pwd` |
|
|
|
cd $FPGA_ROOT/ghdl |
|
switch_if_not_desired_branch ${GHDL_BRANCH-master} |
|
make_clean_if_clean $FPGA_ROOT/build-ghdl |
|
|
|
cd $FPGA_ROOT/ghdl-yosys-plugin |
|
switch_if_not_desired_branch ${GHDL_YOSYS_PLUGIN_BRANCH-master} |
|
make_clean_if_clean `pwd` |
|
|
|
cd $FPGA_ROOT/dfu-util |
|
switch_if_not_desired_branch ${DFU_BRANCH-master} |
|
make_clean_if_clean $FPGA_ROOT/build-dfu |
|
|
|
cd $FPGA_ROOT/openFPGALoader |
|
switch_if_not_desired_branch ${OFL_BRANCH-master} |
|
ninja_clean_if_clean `pwd`/build |
|
|
|
# Use with caution/not ready yet- need a mechanism to determine whether branch |
|
# was actually changed in prepare. Might be removed completely. |
|
# Change branches back to previous branches after running prepare. |
|
_restore: |
|
#!/bin/sh |
|
|
|
set -e |
|
|
|
# $1- Current branch |
|
switch_to_previous_branch() { |
|
set +e |
|
PREV_REV=`git rev-parse @{-1} 2> /dev/null` |
|
RET=$? |
|
set -e |
|
|
|
if [ $RET -ne 0 ]; then |
|
PREV_BR=`git rev-parse --symbolic-full-name --abbrev-ref HEAD` |
|
else |
|
PREV_BR=`git name-rev $PREV_REV --name-only` |
|
fi |
|
|
|
if [ $PREV_BR=$1 ]; then |
|
echo "Branch was set to $1 (or same commit as $1) on `pwd` previously" |
|
else |
|
git checkout - |
|
fi |
|
} |
|
|
|
cd $FPGA_ROOT/icestorm |
|
switch_to_previous_branch ${ICESTORM_BRANCH-master} |
|
|
|
cd $FPGA_ROOT/prjtrellis |
|
switch_to_previous_branch ${TRELLIS_BRANCH-master} |
|
|
|
cd $FPGA_ROOT/nextpnr |
|
switch_to_previous_branch ${NEXTPNR_BRANCH-master} |
|
|
|
cd $FPGA_ROOT/yosys |
|
switch_to_previous_branch ${YOSYS_BRANCH-master} |
|
|
|
cd $FPGA_ROOT/SymbiYosys |
|
switch_to_previous_branch ${SYMBIYOSYS_BRANCH-master} |
|
|
|
cd $FPGA_ROOT/iverilog |
|
switch_to_previous_branch ${IVERILOG_BRANCH-master} |
|
|
|
cd $FPGA_ROOT/verilator |
|
switch_to_previous_branch ${VERILATOR_BRANCH-master} |
|
|
|
cd $FPGA_ROOT/ghdl |
|
switch_to_previous_branch ${GHDL_BRANCH-master} |
|
|
|
cd $FPGA_ROOT/ghdl-yosys-plugin |
|
switch_to_previous_branch ${GHDL_YOSYS_PLUGIN_BRANCH-master} |
|
|
|
cd $FPGA_ROOT/dfu-util |
|
switch_to_previous_branch ${DFU_BRANCH-master} |
|
|
|
cd $FPGA_ROOT/openFPGALoader |
|
switch_to_previous_branch ${OFL_BRANCH-master} |
|
|
|
# Create pre-built nextpnr chipdbs for a family. |
|
build-chipdbs FAMILY CLEAN="0" PULL="0": |
|
#!/bin/sh |
|
|
|
set -e |
|
|
|
. "{{justfile_directory()}}/common.sh" |
|
|
|
if [ {{PULL}} -ne 0 ]; then SKIP_CHECK=0; fi |
|
if [ {{CLEAN}} -ne 0 ]; then CHIPDB="only-full"; fi |
|
|
|
case {{FAMILY}} in |
|
"ice40") |
|
just -f "{{justfile()}}" _rebuild-ice40 "0" "${SKIP_CHECK=1}" "${CHIPDB=\"only\"}" |
|
;; |
|
"ecp5") |
|
just -f "{{justfile()}}" _rebuild-ecp5 "0" "${SKIP_CHECK=1}" "${CHIPDB=\"only\"}" |
|
;; |
|
*) |
|
echo "Unrecognized chipdb family {{FAMILY}}" |
|
exit 1 |
|
;; |
|
esac |
|
|
|
# Grab pre-built nextpnr chipdbs on a machine that previously ran build-chipdbs. |
|
get-chipdbs FAMILY: |
|
#!/bin/sh |
|
|
|
set -e |
|
|
|
. "{{justfile_directory()}}/common.sh" |
|
|
|
get_remote_chipdbs {{FAMILY}} |