Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Split make.sh build, fix lints, cleanup #751

Merged
merged 11 commits into from
Feb 23, 2022
4 changes: 2 additions & 2 deletions contrib/dockerfiles/arm-linux-gnueabihf.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ LABEL org.defichain.arch=${TARGET}

WORKDIR /work/depends
COPY ./depends .
# XREF: #depends-make
RUN make HOST=${TARGET} NO_QT=1 -j $(nproc)
# XREF: #make-deps
RUN make HOST=${TARGET} -j $(nproc)

# -----------
FROM builder-base as builder
Expand Down
4 changes: 2 additions & 2 deletions contrib/dockerfiles/x86_64-apple-darwin11.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ LABEL org.defichain.arch=${TARGET}

WORKDIR /work/depends
COPY ./depends .
# XREF: #depends-make
RUN make HOST=${TARGET} NO_QT=1 -j $(nproc)
# XREF: #make-deps
RUN make HOST=${TARGET} -j $(nproc)

# -----------
FROM builder-base as builder
Expand Down
4 changes: 2 additions & 2 deletions contrib/dockerfiles/x86_64-pc-linux-gnu.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ LABEL org.defichain.arch=${TARGET}

WORKDIR /work/depends
COPY ./depends .
# XREF: #depends-make
RUN make HOST=${TARGET} NO_QT=1 -j $(nproc)
# XREF: #make-deps
RUN make HOST=${TARGET} -j $(nproc)

# -----------
FROM builder-base as builder
Expand Down
4 changes: 2 additions & 2 deletions contrib/dockerfiles/x86_64-w64-mingw32.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ LABEL org.defichain.arch=${TARGET}

WORKDIR /work/depends
COPY ./depends .
# XREF: #depends-make
RUN make HOST=${TARGET} NO_QT=1 -j $(nproc)
# XREF: #make-deps
RUN make HOST=${TARGET} -j $(nproc)

# -----------
FROM builder-base as builder
Expand Down
78 changes: 53 additions & 25 deletions make.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,15 @@ setup_vars() {
DOCKERFILES_DIR=${DOCKERFILES_DIR:-"./contrib/dockerfiles"}
RELEASE_DIR=${RELEASE_DIR:-"./build"}

EXTRA_CONF_ARGS=${EXTRA_CONF_ARGS:-}
EXTRA_MAKE_ARGS=${EXTRA_MAKE_ARGS:-}
EXTRA_MAKE_DEPENDS_ARGS=${EXTRA_MAKE_DEPENDS_ARGS:-}
MAKE_JOBS=${MAKE_JOBS:-$(nproc)}
MAKE_COMPILER=${MAKE_COMPILER:-"CC=clang-11 CXX=clang++-11"}
MAKE_CONF_ARGS="${MAKE_COMPILER} ${MAKE_CONF_ARGS:-}"
MAKE_ARGS=${MAKE_ARGS:-}
MAKE_DEPS_ARGS=${MAKE_DEPS_ARGS:-}
MAKE_DEBUG=${MAKE_DEBUG:-"0"}
if [[ "${MAKE_DEBUG}" == "1" ]]; then
MAKE_CONF_ARGS="${MAKE_CONF_ARGS} --enable-debug";
fi

# shellcheck disable=SC2206
# This intentionally word-splits the array as env arg can only be strings.
Expand Down Expand Up @@ -73,28 +79,47 @@ help() {

# ----------- Direct builds ---------------


build_prepare() {
build_deps() {
local target=${1:-"x86_64-pc-linux-gnu"}
local extra_conf_opts=${EXTRA_CONF_ARGS:-}
local extra_make_depends_args=${EXTRA_MAKE_DEPENDS_ARGS:--j $(nproc)}
local make_deps_args=${MAKE_DEPS_ARGS:-}
local make_jobs=${MAKE_JOBS}

echo "> build: ${target}"
echo "> build-deps: target: ${target} / deps_args: ${make_deps_args} / jobs: ${make_jobs}"
pushd ./depends >/dev/null
# XREF: #depends-make
make NO_QT=1 ${extra_make_depends_args}
# XREF: #make-deps
# shellcheck disable=SC2086
make HOST="${target}" -j${make_jobs} ${make_deps_args}
popd >/dev/null
}

build_conf() {
local target=${1:-"x86_64-pc-linux-gnu"}
local make_conf_opts=${MAKE_CONF_ARGS:-}
local make_jobs=${MAKE_JOBS}

echo "> build-conf: target: ${target} / conf_args: ${make_conf_opts} / jobs: ${make_jobs}"

./autogen.sh
# XREF: #make-configure
# ./configure CC=clang-11 CXX=clang++-11 --prefix="$(pwd)/depends/x86_64-pc-linux-gnu"
./configure CC=clang-11 CXX=clang++-11 --prefix="$(pwd)/depends/${target}" ${extra_conf_opts}
# ./configure --prefix="$(pwd)/depends/x86_64-pc-linux-gnu"
# shellcheck disable=SC2086
./configure --prefix="$(pwd)/depends/${target}" ${make_conf_opts}
}

build() {
local extra_make_args=${EXTRA_MAKE_ARGS:--j $(nproc)}
build_make() {
local target=${1:-"x86_64-pc-linux-gnu"}
local make_args=${MAKE_ARGS:-}
local make_jobs=${MAKE_JOBS}

build_prepare "$@"
make ${extra_make_args}
echo "> build: target: ${target} / args: ${make_args} / jobs: ${make_jobs}"
# shellcheck disable=SC2086
make -j${make_jobs} ${make_args}
}

build() {
build_deps "$@"
build_conf "$@"
build_make "$@"
}

deploy() {
Expand All @@ -113,7 +138,7 @@ deploy() {
echo "> deploy into: ${release_dir} from ${versioned_release_path}"

pushd "${release_dir}" >/dev/null
rm -rf ./${versioned_name} && mkdir "${versioned_name}"
rm -rf "./${versioned_name}" && mkdir "${versioned_name}"
popd >/dev/null

make prefix=/ DESTDIR="${versioned_release_path}" install && cp README.md "${versioned_release_path}/"
Expand All @@ -134,7 +159,7 @@ package() {
local pkg_tar_file_name="${pkg_name}.tar.gz"

local pkg_path
pkg_path="$(readlink -m ${release_dir}/${pkg_tar_file_name})"
pkg_path="$(readlink -m "${release_dir}/${pkg_tar_file_name}")"

local versioned_name="${img_prefix}-${img_version}"
local versioned_release_dir="${release_dir}/${versioned_name}"
Expand Down Expand Up @@ -317,11 +342,11 @@ git_version() {
# Replace `/` in branch names with `-` as / is trouble
IMAGE_VERSION="${current_branch//\//-}-${current_commit}"
if [[ "${current_branch}" == "hotfix" ]]; then
# If the current branch is hotfix branch,
# prefix it with the last available tag.
# If the current branch is hotfix branch,
# prefix it with the last available tag.
git fetch --tags
local last_tag
last_tag="$(git describe --tags $(git rev-list --tags --max-count=1))"
last_tag="$(git describe --tags "$(git rev-list --tags --max-count=1)")"
echo "> last tag: ${last_tag}"
if [[ -n "${last_tag}" ]]; then
IMAGE_VERSION="${last_tag}-${IMAGE_VERSION}"
Expand All @@ -340,20 +365,23 @@ git_version() {

if [[ -n "${GITHUB_ACTIONS-}" ]]; then
# GitHub Actions
echo "BUILD_VERSION=${IMAGE_VERSION}" >> $GITHUB_ENV
echo "BUILD_VERSION=${IMAGE_VERSION}" >> "$GITHUB_ENV"
fi
}

pkg_install_deps() {
sudo apt update && sudo apt dist-upgrade -y
sudo apt install -y software-properties-common build-essential libtool autotools-dev automake \
apt update && apt install -y \
software-properties-common build-essential libtool autotools-dev automake \
pkg-config bsdmainutils python3 libssl-dev libevent-dev libboost-system-dev \
libboost-filesystem-dev libboost-chrono-dev libboost-test-dev libboost-thread-dev \
libminiupnpc-dev libzmq3-dev libqrencode-dev wget \
curl cmake
}

pkg_install_llvm() {
wget https://apt.llvm.org/llvm.sh
chmod +x llvm.sh
sudo ./llvm.sh 11
./llvm.sh 11
}

pkg_ensure_mac_sdk() {
Expand Down