Skip to content

Commit 23aca98

Browse files
committed
Corrected build script for Linux.
1 parent 66194a2 commit 23aca98

File tree

3 files changed

+136
-39
lines changed

3 files changed

+136
-39
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
php-firebird-build/
12
.vscode
23
.deps
34
.libs

build_scripts/README.md

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Scripts building php-firebird extension on Windows
1+
# Scripts building php-firebird extension (Windows + Linux)
22

33
## How it works
44

@@ -21,3 +21,46 @@ Make sure ``git`` is in you PATH
2121
PFB_SOURCE_DIR=D:\php-firebird\ then your source should reside in D:\php-firebird\php-firebird\
2222
``
2323
6. cd into php-sdk and from there run ``<path_to>\php-fb-build-all.bat`` to build for all PHP versions or run ``php-fb-build.bat 7.4 vc15`` to build for particular version.
24+
25+
---
26+
27+
# Build on Linux
28+
29+
Linux builds are handled by `php-fb-build-linux.sh`. It clones the extension source into a local build folder and builds one `.so` per configured PHP version.
30+
31+
## Prerequisites
32+
33+
- A working C/C++ build toolchain: `build-essential`, `autoconf`, `automake`, `libtool`, `pkg-config`, `g++`
34+
- Firebird client headers + library (`fbclient`) installed
35+
- Default script paths assume a Firebird install under `/opt/firebird/`:
36+
- headers: `/opt/firebird/include`
37+
- library: `/opt/firebird/lib`
38+
- For each PHP version you want to build, the corresponding packages must exist (Debian/Ubuntu naming):
39+
- `phpX.Y-dev`, `phpX.Y-cli`, `phpX.Y-common`
40+
41+
Note: the script will try to install missing PHP packages via `sudo apt-get`. On non-Debian-based distros, install the equivalents manually and make sure `phpX.Y`, `phpizeX.Y` and `php-configX.Y` exist in `/usr/bin/`.
42+
43+
## Configure
44+
45+
Open `php-fb-build-linux.sh` and adjust if needed:
46+
47+
- `FIREBIRD_INCLUDE_DIR` (default: `/opt/firebird/include`)
48+
- `PHP_VERSIONS` (default: `("7.4" "8.0" "8.1" "8.2" "8.3" "8.4")`)
49+
- `INSTALL_DIR` (default: `../ext` relative to the repo root)
50+
51+
## Run
52+
53+
From the repository root:
54+
55+
```bash
56+
./build_scripts/php-fb-build-linux.sh
57+
```
58+
59+
## Output
60+
61+
Successful builds are copied into the install directory (default: `../ext`) and named like:
62+
63+
`php_<PHP_FULL_VERSION>-interbase-<DRIVER_VERSION>-<os>-<arch>.so`
64+
65+
If a particular PHP version fails to build, the script continues with the next one and reports all failed versions at the end.
66+

build_scripts/php-fb-build-linux.sh

100644100755
Lines changed: 91 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -9,56 +9,109 @@ PHP_VERSIONS=("7.4" "8.0" "8.1" "8.2" "8.3" "8.4") # Adjust as needed
99
BUILD_DIR="php-firebird-build"
1010

1111
set -e
12+
set -o pipefail
1213

13-
mkdir -p "$INSTALL_DIR"
14-
rm -rf "$BUILD_DIR"
14+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
15+
ROOT_DIR="$(cd "$SCRIPT_DIR/.." && pwd)"
16+
INSTALL_DIR_ABS="$(realpath -m "$ROOT_DIR/$INSTALL_DIR")"
17+
BUILD_DIR_ABS="$ROOT_DIR/$BUILD_DIR"
18+
19+
mkdir -p "$INSTALL_DIR_ABS"
20+
rm -rf "$BUILD_DIR_ABS"
1521
echo "Cloning repository from $REPO_URL (branch: $BRANCH_OR_COMMIT)..."
16-
git clone --depth 1 --branch "$BRANCH_OR_COMMIT" "$REPO_URL" "$BUILD_DIR"
17-
18-
# Read version from driver
19-
if [[ -f "$BUILD_DIR/php_interbase.h" ]]; then
20-
DRIVER_VERSION=$(grep -Eo 'PHP_INTERBASE_VERSION\s+"[0-9.]+"' "$BUILD_DIR/php_interbase.h" | grep -Eo '[0-9.]+')
21-
elif [[ -f "$BUILD_DIR/package.xml" ]]; then
22-
DRIVER_VERSION=$(grep -oPm1 "(?<=<version>)[^<]+" "$BUILD_DIR/package.xml")
23-
else
24-
DRIVER_VERSION="unknown"
25-
fi
22+
git clone --depth 1 --branch "$BRANCH_OR_COMMIT" "$REPO_URL" "$BUILD_DIR_ABS"
23+
24+
extract_driver_version() {
25+
local header="$1"
26+
local pkgxml="$2"
27+
28+
if [[ -f "$header" ]]; then
29+
# Legacy style (if present)
30+
local legacy
31+
legacy="$(awk '$1=="#define" && $2=="PHP_INTERBASE_VERSION" { gsub(/\"/,"",$3); print $3; exit }' "$header" 2>/dev/null || true)"
32+
if [[ -n "$legacy" ]]; then
33+
echo "$legacy"
34+
return 0
35+
fi
36+
37+
# Current style: parse MAJOR/MINOR/REV and optional PRE
38+
local major minor rev pre
39+
major="$(awk '/^#define[[:space:]]+PHP_INTERBASE_VER_MAJOR[[:space:]]+/{print $3; exit}' "$header" 2>/dev/null || true)"
40+
minor="$(awk '/^#define[[:space:]]+PHP_INTERBASE_VER_MINOR[[:space:]]+/{print $3; exit}' "$header" 2>/dev/null || true)"
41+
rev="$(awk '/^#define[[:space:]]+PHP_INTERBASE_VER_REV[[:space:]]+/{print $3; exit}' "$header" 2>/dev/null || true)"
42+
pre="$(awk '/^#define[[:space:]]+PHP_INTERBASE_VER_PRE[[:space:]]+/{print $3; exit}' "$header" 2>/dev/null || true)"
43+
pre="${pre%\"}"
44+
pre="${pre#\"}"
45+
46+
if [[ -n "$major" && -n "$minor" && -n "$rev" ]]; then
47+
echo "${major}.${minor}.${rev}${pre}"
48+
return 0
49+
fi
50+
fi
51+
52+
if [[ -f "$pkgxml" ]]; then
53+
local v
54+
v="$(grep -oPm1 '(?<=<version>)[^<]+' "$pkgxml" 2>/dev/null || true)"
55+
if [[ -n "$v" ]]; then
56+
echo "$v"
57+
return 0
58+
fi
59+
fi
60+
61+
echo "unknown"
62+
}
63+
64+
DRIVER_VERSION="$(extract_driver_version "$BUILD_DIR_ABS/php_interbase.h" "$BUILD_DIR_ABS/package.xml")"
65+
66+
FAILED_VERSIONS=()
2667

2768
for VERSION in "${PHP_VERSIONS[@]}"; do
2869
echo "==> Building for PHP $VERSION"
2970

30-
PHP_BIN="/usr/bin/php$VERSION"
31-
PHPIZE="/usr/bin/phpize$VERSION"
32-
PHP_CONFIG="/usr/bin/php-config$VERSION"
71+
if (
72+
PHP_BIN="/usr/bin/php$VERSION"
73+
PHPIZE="/usr/bin/phpize$VERSION"
74+
PHP_CONFIG="/usr/bin/php-config$VERSION"
3375

34-
if [[ ! -x "$PHP_BIN" || ! -x "$PHPIZE" || ! -x "$PHP_CONFIG" ]]; then
35-
echo "--> Installing missing PHP $VERSION packages..."
36-
sudo apt-get install -y "php$VERSION-dev" "php$VERSION-cli" "php$VERSION-common"
37-
fi
76+
if [[ ! -x "$PHP_BIN" || ! -x "$PHPIZE" || ! -x "$PHP_CONFIG" ]]; then
77+
echo "--> Installing missing PHP $VERSION packages..."
78+
sudo apt-get install -y "php$VERSION-dev" "php$VERSION-cli" "php$VERSION-common"
79+
fi
3880

39-
cd "$BUILD_DIR"
81+
cd "$BUILD_DIR_ABS"
4082

41-
echo "--> Cleaning previous build (if any)..."
42-
make clean || true
43-
echo "--> Running phpize..."
44-
"$PHPIZE"
45-
echo "--> Configuring build..."
46-
CPPFLAGS="-I$FIREBIRD_INCLUDE_DIR" ./configure --with-php-config="$PHP_CONFIG"
47-
echo "--> Compiling..."
48-
make -j"$(nproc)"
83+
echo "--> Cleaning previous build (if any)..."
84+
make clean || true
85+
echo "--> Running phpize..."
86+
"$PHPIZE"
87+
echo "--> Configuring build..."
88+
CPPFLAGS="-I$FIREBIRD_INCLUDE_DIR" ./configure --with-php-config="$PHP_CONFIG"
89+
echo "--> Compiling..."
90+
make -j"$(nproc)"
4991

50-
PHP_FULL_VERSION=$("$PHP_BIN" -r 'echo PHP_VERSION;')
51-
ARCH=$(uname -m)
52-
OS=$(uname -s | tr '[:upper:]' '[:lower:]')
92+
PHP_FULL_VERSION=$("$PHP_BIN" -r 'echo PHP_VERSION;')
93+
ARCH=$(uname -m)
94+
OS=$(uname -s | tr '[:upper:]' '[:lower:]')
5395

54-
OUTPUT_FILE="php_${PHP_FULL_VERSION}-interbase-${DRIVER_VERSION}-${OS}-${ARCH}.so"
55-
mkdir -p "$INSTALL_DIR"
56-
echo "--> Copying output to $INSTALL_DIR/$OUTPUT_FILE"
57-
cp modules/interbase.so "$INSTALL_DIR/$OUTPUT_FILE"
96+
OUTPUT_FILE="php_${PHP_FULL_VERSION}-interbase-${DRIVER_VERSION}-${OS}-${ARCH}.so"
97+
mkdir -p "$INSTALL_DIR_ABS"
98+
echo "--> Copying output to $INSTALL_DIR_ABS/$OUTPUT_FILE"
99+
cp modules/interbase.so "$INSTALL_DIR_ABS/$OUTPUT_FILE"
58100

59-
echo "Build complete for PHP $VERSION: $OUTPUT_FILE"
60-
cd ..
101+
echo "Build complete for PHP $VERSION: $OUTPUT_FILE"
102+
); then
103+
:
104+
else
105+
echo "Build FAILED for PHP $VERSION" >&2
106+
FAILED_VERSIONS+=("$VERSION")
107+
fi
61108
done
62109

63-
echo "All builds completed. Files are located in: $INSTALL_DIR"
110+
if (( ${#FAILED_VERSIONS[@]} > 0 )); then
111+
echo "Some builds failed: ${FAILED_VERSIONS[*]}" >&2
112+
echo "Artifacts (successful builds) are located in: $INSTALL_DIR_ABS"
113+
exit 1
114+
fi
115+
116+
echo "All builds completed. Files are located in: $INSTALL_DIR_ABS"
64117

0 commit comments

Comments
 (0)