Skip to content

Commit

Permalink
Improve build script (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
devfacet committed Apr 5, 2024
1 parent a42f90e commit 5ec7ca8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 16 deletions.
6 changes: 3 additions & 3 deletions scripts/docker/Dockerfile.generic
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# Example usage:
# Build:
# docker buildx build --platform linux/amd64 -f scripts/docker/Dockerfile.generic -t nntbn:generic . --load
# docker buildx build --platform linux/arm64 -f scripts/docker/Dockerfile.generic -t nntbn:generic . --load
# Run:
# docker run --rm -it --platform linux/amd64 nntbn:generic /nn/build/tests/arch/generic/neuron
# docker run --rm -it --platform linux/amd64 nntbn:generic /nn/build/examples/arch/generic/dot_product
# docker run --rm -it --platform linux/arm64 nntbn:generic /nn/build/tests/arch/generic/neuron
# docker run --rm -it --platform linux/arm64 nntbn:generic /nn/build/examples/arch/generic/dot_product

# Build
FROM ubuntu:latest as build
Expand Down
31 changes: 18 additions & 13 deletions scripts/shell/build_artifact.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,20 @@ ARCH="${ARCH-}"
TECH="${TECH-}"
ARTIFACT="${ARTIFACT-}"
CC="${CC:-clang}"
CFLAGS+=(-Wall -fdiagnostics-color=always)
CFLAGS_ARRAY=(-Wall -fdiagnostics-color=always)

# Check and add CFLAGS to CFLAGS_ARRAY
if [ -n "${CFLAGS-}" ]; then
IFS=' ' read -ra CFLAGS_PARTS <<< "$CFLAGS"
CFLAGS_ARRAY+=("${CFLAGS_PARTS[@]}")
fi

# Check and add LDFLAGS to LDFLAGS_ARRAY
if [ -n "${LDFLAGS-}" ]; then
IFS=' ' read -ra LDFLAGS_ARRAY <<< "$LDFLAGS"
else
LDFLAGS_ARRAY=()
fi

# If the ARCH environment variable is not set then
if [ -z "$ARCH" ]; then
Expand All @@ -21,13 +34,6 @@ if [ -z "$ARTIFACT" ] || [ "$ARTIFACT" = "examples/" ] || [ "$ARTIFACT" = "tests
exit 1
fi

# If the DEFINES environment variable is set then
if declare -p DEFINES &>/dev/null; then
DEFINES_FLAGS=$(printf -- '-D%s ' "${DEFINES[@]}")
else
DEFINES_FLAGS=""
fi

# Ensure that the build directory exists
mkdir -p "$(pwd)/build/$(dirname "$ARTIFACT")"

Expand All @@ -46,12 +52,11 @@ for tech in "${TECHS[@]:-}"; do
fi
done

# set -x
$CC "${CFLAGS[@]}" \
"$DEFINES_FLAGS" \
#set -x
$CC "${CFLAGS_ARRAY[@]}" \
-Iinclude/ \
"${CC_PARTS[@]:-}" \
src/*.c \
"$(pwd)/$ARTIFACT"/main.c \
-o "$(pwd)/build/$ARTIFACT" "${LDFLAGS[@]:-}"
# set +x
-o "$(pwd)/build/$ARTIFACT" "${LDFLAGS_ARRAY[@]}"
#set +x

0 comments on commit 5ec7ca8

Please sign in to comment.