Debian Codegraph @

Packaging/win/make-portable-package.sh

raw symbols SCIP
1 #!/bin/bash
2
3 #Detect 7-zip version to use
4 WSZIP="/c/Program Files/7-Zip/7z.exe"
5 if [ -f "$WSZIP" ]; then
6 SZIP="$WSZIP"
7 else
8 SZIP="7za"
9 fi
10
11 # Colourful text
12 # Red text
13 function log_error() {
14 echo -e "\e[31m$@\e[0m"
15 }
16
17 # Yellow text
18 function log_status() {
19 echo -e "\e[33m$@\e[0m"
20 }
21
22 # Green text
23 function log_note() {
24 echo -e "\e[32m$@\e[0m"
25 }
26
27 function bail () {
28 echo -e "\e[31m\e[1m!!! Build failed at: ${@}\e[0m"
29 exit 1
30 }
31
32 function check_overwrite() {
33 if [ -f "$1" ]; then
34 read -p "File exists. Overwrite? [y/N]: " overwrite
35 case $overwrite in
36 [Yy]* ) rm -fv "$1" || bail "Could not remove $1"; break;;
37 * ) bail "Not overwriting $1." ;;
38 esac
39 fi
40 }
41
42 function szip_folder() {
43 # Enable dotglob to include hidden files/directories (like .debug)
44 shopt -s dotglob
45 "$SZIP" a -t7z -mx=9 -m0=lzma2 -md=128m "$1" "$2"/*
46 local result=$?
47 shopt -u dotglob
48 return $result
49 }
50
51 if [ -z "$1" ]; then
52 postfix="r1"
53 else
54 postfix="$1"
55 fi
56
57 if [ "$MSYSTEM" = "UCRT64" ]; then
58 MINGVER=ucrt64
59 PMARCH=ucrt-x86_64
60 elif [ "$MSYSTEM" = "CLANGARM64" ]; then
61 MINGVER=clangarm64
62 PMARCH=clang-aarch64
63 else
64 bail "Unknown build system!"
65 fi
66 PKGPREFIX="FontForge-mingw-w64-$PMARCH"
67
68 BASE="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
69 BUILD_DIR=${BUILD_DIR:-$BASE/build}
70 # Convert Windows paths to Unix paths if needed
71 if command -v cygpath &> /dev/null; then
72 BUILD_DIR=$(cygpath -u "$BUILD_DIR")
73 fi
74 SETUP=$BASE/setup
75 WORK=$BUILD_DIR/work/$MINGVER
76 RELEASE=$BUILD_DIR/ReleasePackage
77 DEBUG=$BUILD_DIR/debugging-symbols
78
79 log_note "Packaging $MINGVER release..."
80 pacman -S --noconfirm --needed p7zip > /dev/null 2>&1
81
82 if [ -z "$FFPATH" ]; then
83 FFPATH=$WORK/fontforge
84 fi
85
86 version_hash=`git -C $FFPATH rev-parse master -- || git -C $FFPATH log --pretty=format:%H -n 1`
87 version_hash=${version_hash:0:6}
88 log_status "Version hash is $version_hash"
89 log_status "Working directory: `pwd`"
90
91 log_status "Building the release archive..."
92 filename="$PKGPREFIX-$version_hash-$postfix.7z"
93 log_status "Name is $filename"
94 check_overwrite "$filename"
95 szip_folder "$filename" "$RELEASE"
96
97 log_status "Building the debug archive..."
98 debugname="$PKGPREFIX-$version_hash-$postfix-debugging-symbols.7z"
99 log_status "Name is $debugname"
100 check_overwrite "$debugname"
101 szip_folder "$debugname" "$DEBUG"