@@ -5,6 +5,7 @@ RUST_LIB="rust/release/libccx_rust.a"
55RUST_PROFILE=" --release"
66RUST_FEATURES=" "
77
8+ # Parse command line arguments
89while [[ $# -gt 0 ]]; do
910 case $1 in
1011 OCR)
3132
3233BLD_FLAGS=" -std=gnu99 -Wno-write-strings -Wno-pointer-sign -D_FILE_OFFSET_BITS=64 -DVERSION_FILE_PRESENT -Dfopen64=fopen -Dopen64=open -Dlseek64=lseek -DFT2_BUILD_LIBRARY -DGPAC_DISABLE_VTT -DGPAC_DISABLE_OD_DUMP -DGPAC_DISABLE_REMOTERY -DNO_GZIP"
3334
35+ # Add debug flags if needed
3436if [[ " $DEBUG " == " true" ]]; then
3537 BLD_FLAGS=" $BLD_FLAGS -g -fsanitize=address"
3638fi
3739
40+ # Add OCR support if requested
3841if [[ " $ENABLE_OCR " == " true" ]]; then
3942 BLD_FLAGS=" $BLD_FLAGS -DENABLE_OCR"
4043fi
4144
45+ # Add hardsubx support if requested
4246if [[ " $HARDSUBX " == " true" ]]; then
4347 BLD_FLAGS=" $BLD_FLAGS -DENABLE_HARDSUBX"
4448fi
4549
46- BLD_INCLUDE=" -I../src/ -I../src/lib_ccx -I../src/lib_hash -I../src/thirdparty/libpng -I../src/thirdparty -I../src/thirdparty/
47- -c -I../src/thirdparty/zlib -I../src/thirdparty/freetype/include ` pkg-config --cflags --silence-errors gpac` "
50+ BLD_INCLUDE=" -I../src/ -I../src/lib_ccx -I../src/lib_hash -I../src/thirdparty/libpng -I../src/thirdparty -I../src/thirdparty/zlib -I../src/thirdparty/freetype/include ` pkg-config --cflags --silence-errors gpac` "
4851
4952if [[ " $ENABLE_OCR " == " true" ]]; then
5053 BLD_INCLUDE=" $BLD_INCLUDE ` pkg-config --cflags --silence-errors tesseract` "
@@ -97,7 +100,7 @@ SRC_FREETYPE="../src/thirdparty/freetype/autofit/autofit.c \
97100 ../src/thirdparty/freetype/type42/type42.c \
98101 ../src/thirdparty/freetype/winfonts/winfnt.c"
99102
100- BLD_SOURCES=" ../src/ccextractor.c $SRC_API $ SRC_CCX $SRC_LIB_HASH $SRC_LIBPNG $SRC_UTF8 $SRC_ZLIB $SRC_ZVBI $SRC_FREETYPE "
103+ BLD_SOURCES=" ../src/ccextractor.c $SRC_CCX $SRC_LIB_HASH $SRC_LIBPNG $SRC_UTF8 $SRC_ZLIB $SRC_FREETYPE "
101104
102105BLD_LINKER=" -lm -liconv -lpthread -ldl ` pkg-config --libs --silence-errors gpac` "
103106
@@ -113,12 +116,14 @@ echo "Running pre-build script..."
113116./pre-build.sh
114117echo " Trying to compile..."
115118
119+ # Check for cargo
116120echo " Checking for cargo..."
117121if ! [ -x " $( command -v cargo) " ]; then
118122 echo ' Error: cargo is not installed.' >&2
119123 exit 1
120124fi
121125
126+ # Check rust version
122127rustc_version=" $( rustc --version) "
123128semver=( ${rustc_version// ./ } )
124129version=" ${semver[1]} .${semver[2]} .${semver[3]} "
133138echo " Building rust files..."
134139(cd ../src/rust && CARGO_TARGET_DIR=../../mac/rust cargo build $RUST_PROFILE $RUST_FEATURES ) || { echo " Failed building Rust components." ; exit 1; }
135140
141+ # Copy the Rust library
136142cp $RUST_LIB ./libccx_rust.a
137143
144+ # Add Rust library to linker flags
138145BLD_LINKER=" $BLD_LINKER ./libccx_rust.a"
139146
140147echo " Building ccextractor"
141- out=$( (LC_ALL=C gcc $BLD_FLAGS $BLD_INCLUDE -o ccextractor $BLD_SOURCES $BLD_LINKER ) 2>&1 )
148+ out=$(( LC_ALL= C gcc $BLD_FLAGS $BLD_INCLUDE - o ccextractor $BLD_SOURCES $BLD_LINKER ) 2 >& 1 )
142149res=$?
143150
151+ # Handle common error cases
144152if [[ $out == *"gcc: command not found"* ]]; then
145153 echo "Error: please install gcc or Xcode command line tools"
146154 exit 1
@@ -161,7 +169,7 @@ if [[ $out == *"allheaders.h: No such file or directory"* ]]; then
161169 exit 4
162170fi
163171
164- if [[ $res -ne 0 ]]; then
172+ if [[ $res -ne 0 ]]; then # Unknown error
165173 echo "Compiled with errors"
166174 >&2 echo "$out "
167175 exit 5
0 commit comments