Skip to content

Commit

Permalink
update mac and linux build script; make some clean;
Browse files Browse the repository at this point in the history
  • Loading branch information
benjaminwan committed Jul 19, 2024
1 parent dea98a5 commit f66b247
Show file tree
Hide file tree
Showing 9 changed files with 150 additions and 310 deletions.
51 changes: 26 additions & 25 deletions .github/workflows/linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ jobs:
name: ubuntu-${{ matrix.list.os_ver }}-${{ matrix.arch }}

env:
BUILD_SCRIPT: build-opencv3-linux.sh
BUILD_OPTIONS: opencv3_cmake_options.txt
PKG_NAME: opencv-${{ matrix.ver.cv }}-ubuntu-${{ matrix.list.os_ver }}-${{ matrix.arch }}
JAVA_PKG_NAME: opencv-${{ matrix.ver.cv }}-ubuntu-${{ matrix.list.os_ver }}-${{ matrix.arch }}-java

Expand All @@ -57,9 +59,8 @@ jobs:
# 复制
- name: copy
run: |
cp build-opencv3-linux.sh opencv-${{ matrix.ver.cv }}
cp build-opencv3-linux-java.sh opencv-${{ matrix.ver.cv }}
cp opencv3_cmake_options.txt opencv-${{ matrix.ver.cv }}
cp ${{ env.BUILD_SCRIPT }} opencv-${{ matrix.ver.cv }}
cp ${{ env.BUILD_OPTIONS }} opencv-${{ matrix.ver.cv }}
- name: Host - update
run: sudo apt-get update
Expand Down Expand Up @@ -114,24 +115,24 @@ jobs:
- name: Docker - build
run: |
docker exec --env-file env.custom -w /root ${{ matrix.os_name }} git config --global --add safe.directory "*"
docker exec --env-file env.custom -w /root/opencv-${{ matrix.ver.cv }} ${{ matrix.os_name }} chmod a+x build-opencv3-linux.sh
docker exec --env-file env.custom -w /root/opencv-${{ matrix.ver.cv }} ${{ matrix.os_name }} ./build-opencv3-linux.sh "${{ matrix.arch }}"
docker exec --env-file env.custom -w /root/opencv-${{ matrix.ver.cv }} ${{ matrix.os_name }} chmod a+x ${{ env.BUILD_SCRIPT }}
docker exec --env-file env.custom -w /root/opencv-${{ matrix.ver.cv }} ${{ matrix.os_name }} ./${{ env.BUILD_SCRIPT }} -n '${{ matrix.arch }}'
# install文件夹改名linux,并使用7z压缩
- name: 7zip
run: |
cp -r opencv-${{ matrix.ver.cv }}/build-Release/install linux
cp -r opencv-${{ matrix.ver.cv }}/build-Release-${{ matrix.arch }}/install linux
7z a ${{ env.PKG_NAME }}.7z linux
rm -r -f linux
- name: Docker - build
run: |
docker exec --env-file env.custom -w /root/opencv-${{ matrix.ver.cv }} ${{ matrix.os_name }} chmod a+x build-opencv3-linux-java.sh
docker exec --env-file env.custom -w /root/opencv-${{ matrix.ver.cv }} ${{ matrix.os_name }} ./build-opencv3-linux-java.sh "${{ matrix.arch }}"
docker exec --env-file env.custom -w /root/opencv-${{ matrix.ver.cv }} ${{ matrix.os_name }} chmod a+x ${{ env.BUILD_SCRIPT }}
docker exec --env-file env.custom -w /root/opencv-${{ matrix.ver.cv }} ${{ matrix.os_name }} ./${{ env.BUILD_SCRIPT }} -n '${{ matrix.arch }}' -j
- name: 7zip java
run: |
cp -r opencv-${{ matrix.ver.cv }}/build-Release/install/share/OpenCV/java ${{ env.JAVA_PKG_NAME }}
cp -r opencv-${{ matrix.ver.cv }}/build-Release-${{ matrix.arch }}/install/share/OpenCV/java ${{ env.JAVA_PKG_NAME }}
7z a ${{ env.JAVA_PKG_NAME }}.7z ${{ env.JAVA_PKG_NAME }}
# 上传artifact
Expand All @@ -148,33 +149,33 @@ jobs:
# path: ${{ env.JAVA_PKG_NAME }}.7z

# 获取所有的git log和tag
- name: Unshallow
run: git fetch --prune --unshallow
# - name: Unshallow
# run: git fetch --prune --unshallow

# 获取git log 从 previousTag 到 lastTag
- name: Get git log
id: git-log
run: |
previousTag=$(git describe --abbrev=0 --tags `git rev-list --tags --skip=1 --max-count=1`)
lastTag=$(git describe --abbrev=0 --tags)
echo "previousTag:$previousTag ~ lastTag:$lastTag"
log=$(git log $previousTag..$lastTag --pretty=format:'- %cd %an: %s\n' --date=format:'%Y-%m-%d %H:%M:%S')
echo "$log"
echo "log_state="$log"" >> $GITHUB_ENV
# - name: Get git log
# id: git-log
# run: |
# previousTag=$(git describe --abbrev=0 --tags `git rev-list --tags --skip=1 --max-count=1`)
# lastTag=$(git describe --abbrev=0 --tags)
# echo "previousTag:$previousTag ~ lastTag:$lastTag"
# log=$(git log $previousTag..$lastTag --pretty=format:'- %cd %an: %s\n' --date=format:'%Y-%m-%d %H:%M:%S')
# echo "$log"
# echo "log_state="$log"" >> $GITHUB_ENV

# 创建Changelog文件 triggered by git tag push
- name: Generate Changelog
if: startsWith(github.ref, 'refs/tags/')
run: |
echo -e '${{ env.log_state }}' > release.md
# - name: Generate Changelog
# if: startsWith(github.ref, 'refs/tags/')
# run: |
# echo -e '${{ env.log_state }}' > release.md

# 创建release 上传release
# https://github.com/marketplace/actions/create-release
- name: Create release and upload-archive
uses: ncipollo/release-action@v1
with:
prerelease: false
bodyFile: release.md
# bodyFile: release.md
artifacts: 'opencv-*.7z'
allowUpdates: true
artifactContentType: application/x-7z-compressed
Expand Down
13 changes: 7 additions & 6 deletions .github/workflows/macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,12 @@ jobs:
runs-on: macos-${{ matrix.list.os_ver }}

env:
BUILD_SCRIPT: build-opencv3-mac.sh
BUILD_OPTIONS: opencv3_cmake_options.txt
PKG_NAME: opencv-${{ matrix.ver.cv }}-macos-${{ matrix.list.os_ver }}-${{ matrix.arch }}
JAVA_PKG_NAME: opencv-${{ matrix.ver.cv }}-macos-${{ matrix.list.os_ver }}-${{ matrix.arch }}-java

steps:
# Setup JDK
- name: Set up JDK
uses: actions/setup-java@v4
with:
Expand Down Expand Up @@ -63,27 +64,27 @@ jobs:
# 复制
- name: copy
run: |
cp build-opencv3-mac.sh opencv-${{ matrix.ver.cv }}
cp build-opencv3-mac-java.sh opencv-${{ matrix.ver.cv }}
cp opencv3_cmake_options.txt opencv-${{ matrix.ver.cv }}
cp ${{ env.BUILD_SCRIPT }} opencv-${{ matrix.ver.cv }}
cp ${{ env.BUILD_OPTIONS }} opencv-${{ matrix.ver.cv }}
# 编译
- name: build
run: |
cd opencv-${{ matrix.ver.cv }}
chmod a+x build-opencv3-mac.sh &&./build-opencv3-mac.sh "${{ matrix.arch }}"
chmod a+x ${{ env.BUILD_SCRIPT }} &&./${{ env.BUILD_SCRIPT }} -n '${{ matrix.arch }}'
# 7z压缩
- name: 7zip
run: |
cp -r opencv-${{ matrix.ver.cv }}/build-Release-${{ matrix.arch }}/install macos
7z a ${{ env.PKG_NAME }}.7z macos
rm -r -f macos
# 编译
- name: build java
run: |
cd opencv-${{ matrix.ver.cv }}
chmod a+x build-opencv3-mac-java.sh &&./build-opencv3-mac-java.sh "${{ matrix.arch }}"
chmod a+x ${{ env.BUILD_SCRIPT }} &&./${{ env.BUILD_SCRIPT }} -n '${{ matrix.arch }}' -j
# 7z压缩
- name: 7zip
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/musl-gcc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ jobs:
]
exclude:
- target: loongarch64-linux-musl
- target: sh2-linux-muslfdpic
- target: sh2eb-linux-muslfdpic

name: opencv-${{ matrix.ver.cv }}-${{ matrix.target }}

Expand Down
52 changes: 0 additions & 52 deletions build-opencv3-linux-java.sh

This file was deleted.

102 changes: 64 additions & 38 deletions build-opencv3-linux.sh
Original file line number Diff line number Diff line change
@@ -1,48 +1,74 @@
#!/usr/bin/env bash
# ./build-opencv3-linux.sh "386"
# ./build-opencv3-linux.sh "amd64"
# ./build-opencv3-linux.sh "arm"
# ./build-opencv3-linux.sh "arm64"
# ./build-opencv3-linux.sh "ppc64le"

if [ "$1" ]; then
echo "TARGET_ARCH=$1"
export TARGET_ARCH="$1"
# ./build-opencv3-linux.sh -n 386
# ./build-opencv3-linux.sh -n amd64
# ./build-opencv3-linux.sh -n arm
# ./build-opencv3-linux.sh -n arm64
# ./build-opencv3-linux.sh -n ppc64le

HOST_OS=$(uname -s)
NUM_THREADS=1
BUILD_TYPE=Release

if [ "$HOST_OS" == "Linux" ]; then
NUM_THREADS=$(nproc)
else
echo "Default target: amd64"
export TARGET_ARCH="amd64"
echo "Unsupported OS: $HOST_OS"
exit 0
fi

HOST_OS=$(uname -s)
NUM_THREADS=$(grep ^processor /proc/cpuinfo | wc -l)
BUILD_TYPE="Release"
JAVA_FLAG=""
TARGET_ARCH=""

while getopts "n:j" arg; do
case $arg in
n)
echo "n(TARGET_ARCH):$OPTARG"
TARGET_ARCH="$OPTARG"
;;
j)
echo "j's arg:$OPTARG"
JAVA_FLAG="-DBUILD_FAT_JAVA_LIB=ON -DBUILD_JAVA=ON -DBUILD_opencv_java=ON -DBUILD_opencv_flann=ON"
;;
?)
echo -e "unkonw argument."
exit 1
;;
esac
done

if [ -z "$TARGET_ARCH" ]; then
echo -e "empty TARGET_ARCH."
echo -e "usage: ./build-opencv3-linux.sh -n amd64"
exit 1
fi

# get gcc version
export compiler=$(which gcc)
MAJOR=$(echo __GNUC__ | $compiler -E -xc - | tail -n 1)
MINOR=$(echo __GNUC_MINOR__ | $compiler -E -xc - | tail -n 1)
PATCHLEVEL=$(echo __GNUC_PATCHLEVEL__ | $compiler -E -xc - | tail -n 1)

if [ $HOST_OS == "Linux" ] && [ $TARGET_ARCH == "arm64" ] && [ "$MAJOR.$MINOR.$PATCHLEVEL" == "4.8.4" ]; then
echo "Linux arm64 gcc version is 4.8.4, turn off libwebp"
DISABLE_OPTION="-DBUILD_WEBP=OFF -DWITH_WEBP=OFF"
elif [ $HOST_OS == "Linux" ] && [ $TARGET_ARCH == "386" ] && [ "$MAJOR.$MINOR.$PATCHLEVEL" == "4.8.4" ]; then
echo "Linux 386 gcc version is 4.8.4, turn off openexr"
DISABLE_OPTION="-DBUILD_OPENEXR=OFF -DWITH_OPENEXR=OFF"
export _compiler=$(which gcc)
MAJOR=$(echo __GNUC__ | $_compiler -E -xc - | tail -n 1)
MINOR=$(echo __GNUC_MINOR__ | $_compiler -E -xc - | tail -n 1)
PATCH_LEVEL=$(echo __GNUC_PATCHLEVEL__ | $_compiler -E -xc - | tail -n 1)

if [ "$HOST_OS" == "Linux" ] && [ "$TARGET_ARCH" == "arm64" ] && [ "$MAJOR.$MINOR.$PATCH_LEVEL" == "4.8.4" ]; then
echo "Linux arm64 gcc version is 4.8.4, turn off libwebp"
DISABLE_OPTION="-DBUILD_WEBP=OFF -DWITH_WEBP=OFF"
elif [ "$HOST_OS" == "Linux" ] && [ "$TARGET_ARCH" == "386" ] && [ "$MAJOR.$MINOR.$PATCH_LEVEL" == "4.8.4" ]; then
echo "Linux 386 gcc version is 4.8.4, turn off openexr"
DISABLE_OPTION="-DBUILD_OPENEXR=OFF -DWITH_OPENEXR=OFF"
else
echo "Other gcc version"
DISABLE_OPTION=""
echo "Other gcc version"
DISABLE_OPTION=""
fi

mkdir -p "build-$BUILD_TYPE"
pushd "build-$BUILD_TYPE"
cmake -DCMAKE_BUILD_TYPE=$BUILD_TYPE \
-DCMAKE_CONFIGURATION_TYPES=$BUILD_TYPE \
-DCMAKE_INSTALL_PREFIX=install \
$(cat ../opencv3_cmake_options.txt) \
$DISABLE_OPTION \
..
cmake --build . -j $NUM_THREADS
cmake --build . --target install
popd
BUILD_OUTPUT_PATH="build-$BUILD_TYPE-$TARGET_ARCH"
BUILD_INSTALL_PATH="$BUILD_OUTPUT_PATH/install"
mkdir -p "$BUILD_OUTPUT_PATH"

cmake --compile-no-warning-as-error \
-B"$BUILD_OUTPUT_PATH" \
-DCMAKE_INSTALL_PREFIX="$BUILD_INSTALL_PATH" \
-DCMAKE_BUILD_TYPE=$BUILD_TYPE -DCMAKE_CONFIGURATION_TYPES=$BUILD_TYPE \
$(cat opencv3_cmake_options.txt) \
$DISABLE_OPTION \
$JAVA_FLAG

cmake --build $BUILD_OUTPUT_PATH --config $BUILD_TYPE --parallel $NUM_THREADS --target install
30 changes: 0 additions & 30 deletions build-opencv3-mac-java.sh

This file was deleted.

Loading

0 comments on commit f66b247

Please sign in to comment.