Skip to content

Commit

Permalink
Build package for windows and mac
Browse files Browse the repository at this point in the history
  • Loading branch information
Obijuan committed Jul 18, 2021
1 parent a4bad6d commit ed33059
Showing 1 changed file with 219 additions and 63 deletions.
282 changes: 219 additions & 63 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,18 @@ YEAR=2021
MONTH=06
DAY=27

# -- Base URL for oss-cad-suite package
SRC_URL_BASE="https://github.com/YosysHQ/oss-cad-suite-build/releases/download"

# -- Target package version: Read from the VERSION text file
# -- Set the version in that file first
VERSION=$(cat VERSION)
echo "Package version: $VERSION"

# -- Version of the tool-system package
# -- This tool is were the ftdi-eeprom program is stored
TOOL_SYSTEM_VERSION=1.1.2

# -- Target architectures
ARCH=$1
TARGET_ARCHS="linux_x86_64 windows_amd64 darwin"
Expand Down Expand Up @@ -80,6 +87,34 @@ echo "******* Building tools-$NAME apio package"
echo ">>> ARCHITECTURE \"$ARCH\""
echo ""

# ---------------------------------------------------------------------
# - Create the folders to use for downloading the upstreams package
# - and creating the packages
# ---------------------------------------------------------------------

# -- Store the current dir
WORK_DIR=$PWD

# -- Folder for storing the upstream packages
UPSTREAM_DIR=$WORK_DIR/_upstream/$ARCH

# -- Folder for storing the generated packages
PACKAGE_DIR=$WORK_DIR/_packages/$ARCH

# -- Create the upstream directory
mkdir -p "$UPSTREAM_DIR"

# -- Create the packages directory
mkdir -p $PACKAGE_DIR

echo ""
echo "* UPSTREAM DIR:"
echo " $UPSTREAM_DIR"
echo ""
echo "* PACKAGE DIR:"
echo " $PACKAGE_DIR"
echo ""

# ----------------------------------------------------------------------------
# - Create variables from the INPUT parameters
# -
Expand All @@ -101,86 +136,100 @@ echo ""

if [ "${ARCH}" == "linux_x86_64" ]; then
ARCH_SRC="linux-x64"
EXT_SRC="tgz"
fi

if [ "${ARCH}" == "windows_amd64" ]; then
ARCH_SRC="windows-x64"
EXT_SRC="exe"
fi

if [ "${ARCH}" == "darwin" ]; then
ARCH_SRC="darwin-x64"
EXT_SRC="tgz"
fi

echo "Src architecture: $ARCH_SRC"

exit 1
# -- Create the UPSTREAM package name
# -- These are examples of oss-cad-suite package names for
# -- the different archs
# --
# -- Arquitecture package name
# -- Linux-64: oss-cad-suite-linux-x64-20210718.tgz
# -- Windows-64: oss-cad-suite-windows-x64-20210718.exe
# -- MAC: oss-cad-suite-darwin-x64-20210718.tgz

RELEASE_TAG=$YEAR-$MONTH-$DAY
FILE_TAG=$YEAR$MONTH$DAY
EXT="tgz"
# -- Filename sintaxis:
# -- oss-cad-suite-<ARCH_SRC>-<YEAR><MONTH><DAY>.<EXT_SRC>

PACKAGE_NAME=tools-oss-cad-suite-$ARCH-$VERSION.tar.gz
# -- Create the DATE tag
FILE_DATE=$YEAR$MONTH$DAY

URL_BASE="https://github.com/YosysHQ/oss-cad-suite-build/releases/download"
FILENAME_SRC="oss-cad-suite-$ARCH_SRC-$FILE_TAG.$EXT"
URL=$URL_BASE/$RELEASE_TAG/$FILENAME_SRC
# -- Upstream filename
FILENAME_SRC="oss-cad-suite-$ARCH_SRC-$FILE_DATE.$EXT_SRC"

TOOL_SYSTEM_VERSION=1.1.2
TOOL_SYSTEM_URL_BASE=https://github.com/FPGAwars/tools-system/releases/download/v$TOOL_SYSTEM_VERSION
TOOL_SYSTEM_ARCH=linux_x86_64
TOOL_SYSTEM_TAR="tools-system-$TOOL_SYSTEM_ARCH-$TOOL_SYSTEM_VERSION.tar.gz"
TOOL_SYSTEM_URL=$TOOL_SYSTEM_URL_BASE/$TOOL_SYSTEM_TAR
echo "> Upstream package name:"
echo " $FILENAME_SRC"
echo ""

# -- Store current dir
WORK_DIR=$PWD
# -- Create the complete URL for downloading the upstream package
# -- Example or URL:
# -- https://github.com/YosysHQ/oss-cad-suite-build/releases/download/2021-07-18/oss-cad-suite-linux-x64-20210718.tgz
# --
# -- Sintax: <URL_BASE><RELEASE_DATE><FILENAME_SRC>
# --
RELEASE_TAG=$YEAR-$MONTH-$DAY
SRC_URL=$SRC_URL_BASE/$RELEASE_TAG/$FILENAME_SRC

# -- Folder for storing the upstream packages
UPSTREAM_DIR=$WORK_DIR/_upstream
# -- Folder for storing the generated packages
PACKAGE_DIR=$WORK_DIR/_packages
echo "---> DOWNLOADING UPSTREAM PACKAGES"
echo "* URL: "
echo " $SRC_URL"
echo ""

# -- Create the upstream directory and enter into it
mkdir -p "$UPSTREAM_DIR"
# -- Create the packages directory
mkdir -p $PACKAGE_DIR/$ARCH
# --------------------------------------------------
# ---- DOWNLOAD THE UPSTREAM oss-cad-suite PACKAGE
# --------------------------------------------------

# -- Download the release packages if it has not already
# -- been downloaded previously
echo "---> Download upstream package: "
echo "URL: $UPSTREAM_DIR"
echo "FILE: $FILENAME_SRC"
echo ""
# -- Change to the upstream folder
cd "$UPSTREAM_DIR"

# -- Download the source package (non verbose)
test -e $FILENAME_SRC || wget -nv $URL
# -- If it has not already downloaded yet
test -e $FILENAME_SRC || wget -nv $SRC_URL

# --- Uncompress the release file
echo "--> Extracting the upstream package"
# --- Uncompress the upstream file
# --- if it has not already been done previously
echo "---> EXTRACTING the upstream package"
echo ""
test -d oss-cad-suite || tar vzxf $FILENAME_SRC > /dev/null

# -- Create the folders of the target package
TARGET_DIR=$PACKAGE_DIR/$ARCH
SOURCE_DIR=$UPSTREAM_DIR/oss-cad-suite
# -- On windows platforms we use 7z, as it is an self-extract .exe file
if [ "${ARCH:0:7}" == "windows" ]; then
test -d oss-cad-suite || 7z x $FILENAME_SRC > /dev/null

mkdir -p $TARGET_DIR/bin
mkdir -p $TARGET_DIR/lib
mkdir -p $TARGET_DIR/libexec
else
# -- tar for the other platforms
test -d oss-cad-suite || tar vzxf $FILENAME_SRC > /dev/null
fi

# -- Copy the selected files to the target dir
echo "--> Copying files"
# -------------------------------------------------------
# -- DOWNLOAD the TOOL-SYSTEM package
# -------------------------------------------------------
# -- (for getting the eeprom-ftdi executable)
# -- (not available in the oss-cad-suite)
TOOL_SYSTEM_URL_BASE=https://github.com/FPGAwars/tools-system/releases/download/v$TOOL_SYSTEM_VERSION
TOOL_SYSTEM_TAR="tools-system-$ARCH-$TOOL_SYSTEM_VERSION.tar.gz"
TOOL_SYSTEM_URL=$TOOL_SYSTEM_URL_BASE/$TOOL_SYSTEM_TAR
TOOL_SYSTEM_SRC="$UPSTREAM_DIR/tools-system"

echo "---> DOWNLOADING the TOOL-SYSTEM Package"
echo "* Package:"
echo " $TOOL_SYSTEM_TAR"
echo "* URL: "
echo " $TOOL_SYSTEM_URL"
echo ""
install $SOURCE_DIR/bin/lsusb $TARGET_DIR/bin
install $SOURCE_DIR/bin/lsftdi $TARGET_DIR/bin
install $SOURCE_DIR/lib/ld-linux-x86-64.so.2 $TARGET_DIR/lib
install $SOURCE_DIR/lib/libc.so.6 $TARGET_DIR/lib
install $SOURCE_DIR/lib/libftdi1.so.2 $TARGET_DIR/lib
install $SOURCE_DIR/libexec/lsusb $TARGET_DIR/libexec
install $SOURCE_DIR/libexec/lsftdi $TARGET_DIR/libexec

# -- Download the tools-system package
# -- (for getting the eeprom-ftdi executable)
# -- (not available in the oss-cad-suite)
# -- If it has already been downloaded yet

echo "--> Download tool-system package"
echo ""
cd "$UPSTREAM_DIR"
Expand All @@ -193,22 +242,129 @@ echo "--> Extracting the tool-system package"
echo ""
test -d bin || tar vzxf $TOOL_SYSTEM_TAR

# -- Copy the ftdi_eeprom file
install bin/ftdi_eeprom $TARGET_DIR/bin
# -----------------------------------------------------------
# -- Create the TARGET package
# -----------------------------------------------------------
PACKAGE_NAME=tools-oss-cad-suite-$ARCH-$VERSION.tar.gz
echo ""
echo "---> CREATE THE TARGET PACKAGE"
echo ""
echo "* Package:"
echo " $PACKAGE_NAME"
echo ""

# -- Create the folders of the target package
SOURCE_DIR=$UPSTREAM_DIR/oss-cad-suite

mkdir -p $PACKAGE_DIR/bin
mkdir -p $PACKAGE_DIR/lib
mkdir -p $PACKAGE_DIR/libexec

# -- Copy the selected files to the target dir
echo "--> Copying files"
echo ""

# -- The executable files ends in .exe on Windows platforms

# -- On windows platforms we use 7z, as it is an self-extract .exe file
if [ "${ARCH:0:7}" == "windows" ]; then
EXE=".exe"

else
# -- No exe extension for the other platoforms
EXE=""
fi

# --- Files to copy for the Linux platforms
if [ "$ARCH" == "linux_x86_64" ]; then

echo "* Copying Linux files..."
echo ""
# -- System tools

# -- Executables
install $SOURCE_DIR/bin/lsusb $PACKAGE_DIR/bin
install $SOURCE_DIR/bin/lsftdi $PACKAGE_DIR/bin
install $SOURCE_DIR/libexec/lsusb $PACKAGE_DIR/libexec
install $SOURCE_DIR/libexec/lsftdi $PACKAGE_DIR/libexec

# -- Copy the ftdi_eeprom file
install $TOOL_SYSTEM_SRC/bin/ftdi_eeprom $PACKAGE_DIR/bin

# -- Libraries
install $SOURCE_DIR/lib/ld-linux-x86-64.so.2 $PACKAGE_DIR/lib
install $SOURCE_DIR/lib/libc.so.6 $PACKAGE_DIR/lib
install $SOURCE_DIR/lib/libftdi1.so.2 $PACKAGE_DIR/lib

fi

# --- Files to copy for the MAC platforms
if [ "$ARCH" == "darwin" ]; then

echo "* Copying MAC files..."
echo ""
# -- System tools

# -- Executables
install $SOURCE_DIR/bin/lsusb $PACKAGE_DIR/bin
install $SOURCE_DIR/bin/lsftdi $PACKAGE_DIR/bin
install $SOURCE_DIR/libexec/lsusb $PACKAGE_DIR/libexec
install $SOURCE_DIR/libexec/lsftdi $PACKAGE_DIR/libexec

# -- Copy the ftdi_eeprom file
install $TOOL_SYSTEM_SRC/bin/ftdi_eeprom $PACKAGE_DIR/bin

# -- Libraries
install $SOURCE_DIR/lib/libusb-1.0.0.dylib $PACKAGE_DIR/lib
install $SOURCE_DIR/lib/libftdi1.2.5.0.dylib $PACKAGE_DIR/lib

fi


# --- Files to copy for the Linux platforms
if [ "$ARCH" == "windows_amd64" ]; then
echo "* Copying Windows files..."
echo ""

# -- System tools

# -- Executables
install $SOURCE_DIR/bin/lsusb.exe $PACKAGE_DIR/bin
install $SOURCE_DIR/bin/lsftdi.exe $PACKAGE_DIR/bin

# -- Copy the ftdi_eeprom file
install $TOOL_SYSTEM_SRC/bin/ftdi_eeprom.exe $PACKAGE_DIR/bin

# -- Libraries
install $SOURCE_DIR/lib/libusb-1.0.dll $PACKAGE_DIR/lib
install $SOURCE_DIR/lib/libftdi1.dll $PACKAGE_DIR/lib

# -- Is this really needed?
install $SOURCE_DIR/lib/libftdipp1.dll $PACKAGE_DIR/lib

fi


# -----------------------------------------------------------
# -- Create the TARGET package
# -----------------------------------------------------------
echo ""
echo "---> CREATE THE TARGET PACKAGE"
echo ""

# -- Creating the package
# -- Copy templates/package-template.json
echo "--> Creating the package"
echo ""
PACKAGE_JSON="$PACKAGE_DIR"/"$ARCH"/package.json
PACKAGE_JSON="$PACKAGE_DIR"/package.json
cp -r "$WORK_DIR"/build-data/templates/package-template.json $PACKAGE_JSON
echo "ARCH: $ARCH"
if [ "$ARCH" == "linux-x64" ]; then
sed -i "s/%VERSION%/\"$VERSION\"/;" "$PACKAGE_DIR"/"$ARCH"/package.json
sed -i "s/%SYSTEM%/\"linux_x86_64\"/;" "$PACKAGE_DIR"/"$ARCH"/package.json
fi
cd $PACKAGE_DIR/$ARCH
sed -i "s/%VERSION%/\"$VERSION\"/;" "$PACKAGE_DIR"/package.json
sed -i "s/%SYSTEM%/\"$ARCH\"/;" "$PACKAGE_DIR"/package.json

cd $PACKAGE_DIR

tar vzcf ../$PACKAGE_NAME ./*
echo "--> Package created: $PACKAGE_NAME"





0 comments on commit ed33059

Please sign in to comment.