Skip to content

Commit

Permalink
Migrate to flipper openocd fork, darwin
Browse files Browse the repository at this point in the history
  • Loading branch information
drunkbatya committed Mar 21, 2024
1 parent 6097e18 commit 0c1b34f
Show file tree
Hide file tree
Showing 4 changed files with 226 additions and 16 deletions.
21 changes: 8 additions & 13 deletions darwin/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ RUN bash /toolchain/src/build-mac-gcc.sh
RUN bash /toolchain/src/move_newlib_to_nano.sh

FROM flipperzero-toolchain-binutils AS flipperzero-toolchain-tools
RUN brew install cmake automake autoconf
RUN brew install cmake automake autoconf libtool pkg-config
ADD https://github.com/protocolbuffers/protobuf/releases/download/v21.7/protobuf-cpp-3.21.7.tar.gz /toolchain/src/src/archives/
RUN tar -xvf /toolchain/src/src/archives/protobuf-cpp-3.21.7.tar.gz -C /toolchain/src/src/
RUN mv /toolchain/src/src/protobuf-3.21.7 /toolchain/src/src/protobuf
Expand All @@ -69,20 +69,15 @@ RUN mv /toolchain/src/src/clang-format/cmake-17.0.6.src /toolchain/src/src/clang
ADD https://github.com/llvm/llvm-project/releases/download/llvmorg-17.0.6/third-party-17.0.6.src.tar.xz /toolchain/src/src/archives/
RUN tar -xvf /toolchain/src/src/archives/third-party-17.0.6.src.tar.xz -C /toolchain/src/src/clang-format/
RUN mv /toolchain/src/src/clang-format/third-party-17.0.6.src /toolchain/src/src/clang-format/third-party
ADD https://github.com/libusb/libusb/releases/download/v1.0.24/libusb-1.0.24.tar.bz2 /toolchain/src/src/archives/
RUN tar -xvf /toolchain/src/src/archives/libusb-1.0.24.tar.bz2 -C /toolchain/src/src/
RUN mv /toolchain/src/src/libusb-1.0.24 /toolchain/src/src/libusb
ADD https://github.com/libusb/hidapi/archive/refs/tags/hidapi-0.14.0.tar.gz /toolchain/src/src/archives/
RUN tar -xvf /toolchain/src/src/archives/hidapi-0.14.0.tar.gz -C /toolchain/src/src/
RUN mv /toolchain/src/src/hidapi-hidapi-0.14.0 /toolchain/src/src/hidapi
RUN git clone https://github.com/flipperdevices/openocd.git /toolchain/src/src/openocd
ADD scripts/build-mac-flipper-tools.sh /toolchain/src/
RUN bash /toolchain/src/build-mac-flipper-tools.sh
ADD https://github.com/xpack-dev-tools/openocd-xpack/releases/download/v0.12.0-2/xpack-openocd-0.12.0-2-darwin-arm64.tar.gz /toolchain/src/src/archives/
ADD https://github.com/xpack-dev-tools/openocd-xpack/releases/download/v0.12.0-2/xpack-openocd-0.12.0-2-darwin-x64.tar.gz /toolchain/src/src/archives/
RUN tar -xvf /toolchain/src/src/archives/xpack-openocd-0.12.0-2-darwin-arm64.tar.gz -C /toolchain/src/src/
RUN mv /toolchain/src/src/xpack-openocd-0.12.0-2 /toolchain/src/src/xpack-openocd-0.12.0-2-arm64
RUN tar -xvf /toolchain/src/src/archives/xpack-openocd-0.12.0-2-darwin-x64.tar.gz -C /toolchain/src/src/
RUN mv /toolchain/src/src/xpack-openocd-0.12.0-2 /toolchain/src/src/xpack-openocd-0.12.0-2-x86_64
RUN rm -rf /toolchain/src/src/xpack-openocd-0.12.0-2-arm64/distro-info
RUN rm -rf /toolchain/src/src/xpack-openocd-0.12.0-2-x86_64/distro-info
RUN rm -rf /toolchain/src/src/xpack-openocd-0.12.0-2-arm64/README.md
RUN rm -rf /toolchain/src/src/xpack-openocd-0.12.0-2-x86_64/README.md
RUN rsync -av /toolchain/src/src/xpack-openocd-0.12.0-2-arm64/ /toolchain/mac-arm64-output-root
RUN rsync -av /toolchain/src/src/xpack-openocd-0.12.0-2-x86_64/ /toolchain/mac-x86_64-output-root
ADD scripts/relink.sh /usr/bin/
RUN relink.sh /toolchain/mac-x86_64-output-root
RUN relink.sh /toolchain/mac-arm64-output-root
Expand Down
215 changes: 215 additions & 0 deletions darwin/scripts/build-mac-flipper-tools.sh
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,222 @@ function build_clang_format_arm64() {
--component clang-format;
popd;
}

function build_libusb_x86_64() {
export PKG_CONFIG_PATH="$MAC_X86_64_OUTPUT_ROOT/lib/pkgconfig";
rm -rf "$MAC_X86_64_CONFIGURE_ROOT/libusb";
mkdir -p "$MAC_X86_64_CONFIGURE_ROOT/libusb";
pushd "$MAC_X86_64_CONFIGURE_ROOT/libusb";
CPPFLAGS="$MAC_X86_64_FLAGS" \
CXXFLAGS="$MAC_X86_64_FLAGS" \
CFLAGS="$MAC_X86_64_FLAGS" \
LDFLAGS="$MAC_X86_64_FLAGS" \
DYLD_LIBRARY_PATH="$MAC_X86_64_OUTPUT_ROOT/lib" \
PATH="$MAC_X86_64_OUTPUT_ROOT/bin:$PATH" \
/toolchain/src/src/libusb/configure \
"--host=x86_64-apple-darwin" \
"--target=x86_64-apple-darwin" \
--prefix="$MAC_X86_64_OUTPUT_ROOT";
CPPFLAGS="$MAC_X86_64_FLAGS" \
CXXFLAGS="$MAC_X86_64_FLAGS" \
CFLAGS="$MAC_X86_64_FLAGS" \
LDFLAGS="$MAC_X86_64_FLAGS" \
DYLD_LIBRARY_PATH="$MAC_X86_64_OUTPUT_ROOT/lib" \
PATH="$MAC_X86_64_OUTPUT_ROOT/bin:$PATH" \
make "-j$CPUS";
make install;
popd;
}

function build_libusb_arm64() {
export PKG_CONFIG_PATH="$MAC_ARM64_OUTPUT_ROOT/lib/pkgconfig";
rm -rf "$MAC_ARM64_CONFIGURE_ROOT/libusb";
mkdir -p "$MAC_ARM64_CONFIGURE_ROOT/libusb";
pushd "$MAC_ARM64_CONFIGURE_ROOT/libusb";
CPPFLAGS="$MAC_ARM64_FLAGS" \
CXXFLAGS="$MAC_ARM64_FLAGS" \
CFLAGS="$MAC_ARM64_FLAGS" \
LDFLAGS="$MAC_ARM64_FLAGS" \
DYLD_LIBRARY_PATH="$MAC_ARM64_OUTPUT_ROOT/lib" \
PATH="$MAC_ARM64_OUTPUT_ROOT/bin:$PATH" \
/toolchain/src/src/libusb/configure \
"--host=aarch64-apple-darwin" \
"--target=aarch64-apple-darwin" \
--prefix="$MAC_ARM64_OUTPUT_ROOT";
CPPFLAGS="$MAC_ARM64_FLAGS" \
CXXFLAGS="$MAC_ARM64_FLAGS" \
CFLAGS="$MAC_ARM64_FLAGS" \
LDFLAGS="$MAC_ARM64_FLAGS" \
DYLD_LIBRARY_PATH="$MAC_ARM64_OUTPUT_ROOT/lib" \
PATH="$MAC_ARM64_OUTPUT_ROOT/bin:$PATH" \
make "-j$CPUS";
make install;
popd;
}

function build_hidapi_x86_64() {
export PKG_CONFIG_PATH="$MAC_X86_64_OUTPUT_ROOT/lib/pkgconfig";
rm -rf "$MAC_X86_64_CONFIGURE_ROOT/hidapi";
mkdir -p "$MAC_X86_64_CONFIGURE_ROOT/hidapi";
pushd "$MAC_X86_64_CONFIGURE_ROOT/hidapi";
CPPFLAGS="$MAC_X86_64_FLAGS" \
CXXFLAGS="$MAC_X86_64_FLAGS" \
CFLAGS="$MAC_X86_64_FLAGS" \
LDFLAGS="$MAC_X86_64_FLAGS" \
DYLD_LIBRARY_PATH="$MAC_X86_64_OUTPUT_ROOT/lib" \
PATH="$MAC_X86_64_OUTPUT_ROOT/bin:$PATH" \
cmake \
-S "/toolchain/src/src/hidapi" \
"-DLLVM_EXTERNAL_PROJECTS=clang" \
"-DCMAKE_OSX_ARCHITECTURES=x86_64" \
"-DCMAKE_INSTALL_PREFIX=$MAC_X86_64_OUTPUT_ROOT";
CPPFLAGS="$MAC_X86_64_FLAGS" \
CXXFLAGS="$MAC_X86_64_FLAGS" \
CFLAGS="$MAC_X86_64_FLAGS" \
LDFLAGS="$MAC_X86_64_FLAGS" \
DYLD_LIBRARY_PATH="$MAC_X86_64_OUTPUT_ROOT/lib" \
PATH="$MAC_X86_64_OUTPUT_ROOT/bin:$PATH" \
make "-j$CPUS";
make install;
popd;
}

function build_hidapi_arm64() {
export PKG_CONFIG_PATH="$MAC_ARM64_OUTPUT_ROOT/lib/pkgconfig";
rm -rf "$MAC_ARM64_CONFIGURE_ROOT/hidapi";
mkdir -p "$MAC_ARM64_CONFIGURE_ROOT/hidapi";
pushd "$MAC_ARM64_CONFIGURE_ROOT/hidapi";
CPPFLAGS="$MAC_ARM64_FLAGS" \
CXXFLAGS="$MAC_ARM64_FLAGS" \
CFLAGS="$MAC_ARM64_FLAGS" \
LDFLAGS="$MAC_ARM64_FLAGS" \
DYLD_LIBRARY_PATH="$MAC_ARM64_OUTPUT_ROOT/lib" \
PATH="$MAC_ARM64_OUTPUT_ROOT/bin:$PATH" \
cmake \
-S "/toolchain/src/src/hidapi" \
"-DLLVM_EXTERNAL_PROJECTS=clang" \
"-DCMAKE_OSX_ARCHITECTURES=arm64" \
"-DCMAKE_INSTALL_PREFIX=$MAC_ARM64_OUTPUT_ROOT";
CPPFLAGS="$MAC_ARM64_FLAGS" \
CXXFLAGS="$MAC_ARM64_FLAGS" \
CFLAGS="$MAC_ARM64_FLAGS" \
LDFLAGS="$MAC_ARM64_FLAGS" \
DYLD_LIBRARY_PATH="$MAC_ARM64_OUTPUT_ROOT/lib" \
PATH="$MAC_ARM64_OUTPUT_ROOT/bin:$PATH" \
make "-j$CPUS";
make install;
popd;
}

function build_openocd_x86_64() {
export PKG_CONFIG_PATH="$MAC_X86_64_OUTPUT_ROOT/lib/pkgconfig";
rm -rf "$MAC_X86_64_CONFIGURE_ROOT/openocd";
mkdir -p "$MAC_X86_64_CONFIGURE_ROOT/openocd";
pushd "/toolchain/src/src/openocd";
./bootstrap;
popd;
pushd "$MAC_X86_64_CONFIGURE_ROOT/openocd";
CPPFLAGS="$MAC_X86_64_FLAGS" \
CXXFLAGS="$MAC_X86_64_FLAGS" \
CFLAGS="$MAC_X86_64_FLAGS" \
LDFLAGS="$MAC_X86_64_FLAGS" \
DYLD_LIBRARY_PATH="$MAC_X86_64_OUTPUT_ROOT/lib" \
PATH="$MAC_X86_64_OUTPUT_ROOT/bin:$PATH" \
/toolchain/src/src/openocd/configure \
"--prefix=$MAC_X86_64_OUTPUT_ROOT" \
"--datarootdir=$MAC_X86_64_OUTPUT_ROOT" \
"--localedir=$MAC_X86_64_OUTPUT_ROOT/share/locale" \
"--disable-wextra" \
"--disable-werror" \
"--disable-gccwarnings" \
"--disable-doxygen-html" \
"--disable-doxygen-pdf" \
"--disable-debug" \
"--disable-dependency-tracking" \
"--enable-cmsis-dap" \
"--enable-dummy" \
"--enable-stlink" \
"--enable-buspirate" \
"--disable-gw16012" \
"--disable-zy1000-master" \
"--disable-zy1000" \
"--disable-ioutil" \
"--disable-minidriver-dummy" \
"--disable-parport-ppdev" \
"--disable-amtjtagaccel" \
"--disable-parport" \
"--disable-parport-giveio" \
"--disable-oocd_trace" \
"--disable-sysfsgpio";
CPPFLAGS="$MAC_X86_64_FLAGS" \
CXXFLAGS="$MAC_X86_64_FLAGS" \
CFLAGS="$MAC_X86_64_FLAGS" \
LDFLAGS="$MAC_X86_64_FLAGS" \
DYLD_LIBRARY_PATH="$MAC_X86_64_OUTPUT_ROOT/lib" \
PATH="$MAC_X86_64_OUTPUT_ROOT/bin:$PATH" \
make "-j$CPUS";
make install-strip;
popd;
}

function build_openocd_arm64() {
export PKG_CONFIG_PATH="$MAC_ARM64_OUTPUT_ROOT/lib/pkgconfig";
rm -rf "$MAC_ARM64_CONFIGURE_ROOT/openocd";
mkdir -p "$MAC_ARM64_CONFIGURE_ROOT/openocd";
pushd "/toolchain/src/src/openocd";
./bootstrap;
popd;
pushd "$MAC_ARM64_CONFIGURE_ROOT/openocd";
CPPFLAGS="$MAC_ARM64_FLAGS" \
CXXFLAGS="$MAC_ARM64_FLAGS" \
CFLAGS="$MAC_ARM64_FLAGS" \
LDFLAGS="$MAC_ARM64_FLAGS" \
DYLD_LIBRARY_PATH="$MAC_ARM64_OUTPUT_ROOT/lib" \
PATH="$MAC_ARM64_OUTPUT_ROOT/bin:$PATH" \
/toolchain/src/src/openocd/configure \
"--prefix=$MAC_ARM64_OUTPUT_ROOT" \
"--datarootdir=$MAC_ARM64_OUTPUT_ROOT" \
"--localedir=$MAC_ARM64_OUTPUT_ROOT/share/locale" \
"--disable-wextra" \
"--disable-werror" \
"--disable-gccwarnings" \
"--disable-doxygen-html" \
"--disable-doxygen-pdf" \
"--disable-debug" \
"--disable-dependency-tracking" \
"--enable-cmsis-dap" \
"--enable-dummy" \
"--enable-stlink" \
"--enable-buspirate" \
"--disable-gw16012" \
"--disable-zy1000-master" \
"--disable-zy1000" \
"--disable-ioutil" \
"--disable-minidriver-dummy" \
"--disable-parport-ppdev" \
"--disable-amtjtagaccel" \
"--disable-parport" \
"--disable-parport-giveio" \
"--disable-oocd_trace" \
"--disable-sysfsgpio";
CPPFLAGS="$MAC_ARM64_FLAGS" \
CXXFLAGS="$MAC_ARM64_FLAGS" \
CFLAGS="$MAC_ARM64_FLAGS" \
LDFLAGS="$MAC_ARM64_FLAGS" \
DYLD_LIBRARY_PATH="$MAC_ARM64_OUTPUT_ROOT/lib" \
PATH="$MAC_ARM64_OUTPUT_ROOT/bin:$PATH" \
make "-j$CPUS";
make install-strip;
popd;
}

build_protobuf_x86_64;
build_protobuf_arm64;
build_clang_format_x86_64;
build_clang_format_arm64;
build_libusb_x86_64;
build_libusb_arm64;
build_hidapi_x86_64;
build_hidapi_arm64;
build_openocd_x86_64;
build_openocd_arm64;
2 changes: 1 addition & 1 deletion darwin/scripts/relink.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function check_library() {
LIB_CURRENT_FULL_PATH="$1";
OBJECT="$2";
# excluding paths
if grep -qE "^@" <<< "$LIB_CURRENT_FULL_PATH"; then
if grep -qE "^@loader_path" <<< "$LIB_CURRENT_FULL_PATH"; then
return 0;
fi
# bazel-out - is a prefix to protobuf shared libaries id, id name isn't match lib name, there is no way to catch it
Expand Down
4 changes: 2 additions & 2 deletions windows/scripts/build-windows-flipper-tools.sh
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,8 @@ function cleanup() {
find "$WINDOWS_OUTPUT_ROOT" \( -name "*.a" -or -name "*.la" \) -delete;
}

#build_protobuf;
#build_clang_format;
build_protobuf;
build_clang_format;
build_libusb;
build_hidapi;
build_openocd;
Expand Down

0 comments on commit 0c1b34f

Please sign in to comment.