Secondary Compilation with ServBay
ServBay provides a complete compilation environment, allowing users to recompile accompanying tools, add new modules, recompile PHP modules, compile PostgreSQL modules, and more effortlessly.
To proceed with the steps below, users need some basic knowledge of compilation and understand how to compile code in a Unix/Linux environment.
Install ServBay Development Library
For secondary compilation, users first need to install the ServBay Development Library. This library includes all necessary files (e.g., .so, .a), header files (e.g., .h), etc., required during the compilation process. The ServBay Development Library can be installed through ServBay's Services panel.
Additionally, users must install Xcode Command Line Tools. You can install it with the following command:
xcode-select --install
Set Up the Compilation Environment
After the ServBay Development Library is installed, users also need to set up the compilation parameters and initialize the compilation environment. Depending on the user's CPU architecture, be it Intel (x86_64) or Apple Silicon (M1/M2/M3). Users can check the current architecture of the ServBay Runtime through the following command and choose the appropriate initialization command.
Check CPU Architecture
# Arm64 (M1/M2/M3)
$ file /Applications/ServBay/bin/bison
/Applications/ServBay/bin/bison: Mach-O 64-bit executable arm64
2
3
# x86_64 (Intel)
$ file /Applications/ServBay/bin/bison
/Applications/ServBay/bin/bison: Mach-O 64-bit executable x86_64
2
3
Initialize the Compilation Environment
According to the CPU architecture obtained above, the environment initialization commands are as follows:
SERVBAY_BASE_FULL_PATH="/Applications/ServBay"
SERVBAY_PACKAGE_DIR_NAME="package"
SERVBAY_PACKAGE_FULL_PATH="${SERVBAY_BASE_FULL_PATH}/${SERVBAY_PACKAGE_DIR_NAME}"
SERVBAY_BIN_PATH="${SERVBAY_PACKAGE_FULL_PATH}/bin"
SERVBAY_SBIN_PATH="${SERVBAY_PACKAGE_FULL_PATH}/sbin"
SERVBAY_ETC_PATH="${SERVBAY_PACKAGE_FULL_PATH}/etc"
SERVBAY_VAR_PATH="${SERVBAY_PACKAGE_FULL_PATH}/var"
SERVBAY_COMMON_PATH="${SERVBAY_PACKAGE_FULL_PATH}/common"
SERVBAY_COMMON_INCLUDE_PATH="${SERVBAY_COMMON_PATH}/include"
SERVBAY_COMMON_LIB_PATH="${SERVBAY_COMMON_PATH}/lib"
SERVBAY_COMMON_LIBEXEC_PATH="${SERVBAY_COMMON_PATH}/libexec"
SERVBAY_COMMON_SHARE_PATH="${SERVBAY_COMMON_PATH}/share"
SERVBAY_COMMON_MAN_PATH="${SERVBAY_COMMON_PATH}/man"
SERVBAY_COMMON_DOC_PATH="${SERVBAY_COMMON_PATH}/doc"
SERVBAY_BUILD_DIR=$(pwd)
SERVBAY_BUILD_SRC_DIR=${SERVBAY_BUILD_DIR}/src
OPENSSL_SELECTED_VERSION="3.2"
OPENSSL_VERSION="3.2.1"
BUILD_OS_MIN_VERSION="12.00"
BUILD_CPU_ARCH="-arch arm64"
BUILD_CPU_ARCH_CMAKE="arm64"
BUILD_MACOS_TARGET=""
export CFLAGS="-Qunused-arguments -O3 -mmacosx-version-min=${BUILD_OS_MIN_VERSION} ${BUILD_CPU_ARCH} ${BUILD_MACOS_TARGET}"
export LDFLAGS="-Wl,-rpath -Wl,${SERVBAY_COMMON_LIB_PATH} -L${SERVBAY_COMMON_LIB_PATH} -L${SERVBAY_PACKAGE_FULL_PATH} -mmacosx-version-min=${BUILD_OS_MIN_VERSION} ${BUILD_CPU_ARCH} ${BUILD_MACOS_TARGET}"
export CPPFLAGS="-I${SERVBAY_COMMON_INCLUDE_PATH}"
export CXXFLAGS="-Qunused-arguments -O3 -mmacosx-version-min=${BUILD_OS_MIN_VERSION} ${BUILD_CPU_ARCH} ${BUILD_MACOS_TARGET}"
export PATH="${SERVBAY_BIN_PATH}:${SERVBAY_SBIN_PATH}:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin"
export PKG_CONFIG_PATH="${SERVBAY_COMMON_LIB_PATH}/pkgconfig"
export PKG_CONFIG="${SERVBAY_BIN_PATH}/pkg-config"
export PKG_CONFIG_LIBDIR="${SERVBAY_COMMON_LIB_PATH}/pkgconfig"
export PATH=$PATH:"/usr/local/bin:/usr/local/sbin"
export PATH=$PATH:"/opt/homebrew/bin/"
export LDFLAGS="-L${SERVBAY_COMMON_PATH}/openssl/${OPENSSL_SELECTED_VERSION}/lib ${LDFLAGS}"
export CPPFLAGS="-I${SERVBAY_COMMON_PATH}/openssl/${OPENSSL_SELECTED_VERSION}/include ${CPPFLAGS}"
export PKG_CONFIG_PATH="${PKG_CONFIG_PATH}:${SERVBAY_COMMON_PATH}/openssl/${OPENSSL_SELECTED_VERSION}/lib/pkgconfig"
export PKG_CONFIG_LIBDIR="${PKG_CONFIG_LIBDIR}:${SERVBAY_COMMON_PATH}/openssl/${OPENSSL_SELECTED_VERSION}/lib/pkgconfig"
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
SERVBAY_BASE_FULL_PATH="/Applications/ServBay"
SERVBAY_PACKAGE_DIR_NAME="package"
SERVBAY_PACKAGE_FULL_PATH="${SERVBAY_BASE_FULL_PATH}/${SERVBAY_PACKAGE_DIR_NAME}"
SERVBAY_BIN_PATH="${SERVBAY_PACKAGE_FULL_PATH}/bin"
SERVBAY_SBIN_PATH="${SERVBAY_PACKAGE_FULL_PATH}/sbin"
SERVBAY_ETC_PATH="${SERVBAY_PACKAGE_FULL_PATH}/etc"
SERVBAY_VAR_PATH="${SERVBAY_PACKAGE_FULL_PATH}/var"
SERVBAY_COMMON_PATH="${SERVBAY_PACKAGE_FULL_PATH}/common"
SERVBAY_COMMON_INCLUDE_PATH="${SERVBAY_COMMON_PATH}/include"
SERVBAY_COMMON_LIB_PATH="${SERVBAY_COMMON_PATH}/lib"
SERVBAY_COMMON_LIBEXEC_PATH="${SERVBAY_COMMON_PATH}/libexec"
SERVBAY_COMMON_SHARE_PATH="${SERVBAY_COMMON_PATH}/share"
SERVBAY_COMMON_MAN_PATH="${SERVBAY_COMMON_PATH}/man"
SERVBAY_COMMON_DOC_PATH="${SERVBAY_COMMON_PATH}/doc"
SERVBAY_BUILD_DIR=$(pwd)
SERVBAY_BUILD_SRC_DIR=${SERVBAY_BUILD_DIR}/src
OPENSSL_SELECTED_VERSION="1.1.1u"
OPENSSL_VERSION="1.1.1u"
BUILD_OS_MIN_VERSION="12.00"
BUILD_CPU_ARCH="-arch x86_64"
BUILD_CPU_ARCH_CMAKE="x86_64"
BUILD_MACOS_TARGET="-target x86_64-apple-macos${BUILD_OS_MIN_VERSION}"
export CFLAGS="-Qunused-arguments -O3 -mmacosx-version-min=${BUILD_OS_MIN_VERSION} ${BUILD_CPU_ARCH} ${BUILD_MACOS_TARGET}"
export LDFLAGS="-Wl,-rpath -Wl,${SERVBAY_COMMON_LIB_PATH} -L${SERVBAY_COMMON_LIB_PATH} -L${SERVBAY_PACKAGE_FULL_PATH} -mmacosx-version-min=${BUILD_OS_MIN_VERSION} ${BUILD_CPU_ARCH} ${BUILD_MACOS_TARGET}"
export CPPFLAGS="-I${SERVBAY_COMMON_INCLUDE_PATH}"
export CXXFLAGS="-Qunused-arguments -O3 -mmacosx-version-min=${BUILD_OS_MIN_VERSION} ${BUILD_CPU_ARCH} ${BUILD_MACOS_TARGET}"
export PATH="${SERVBAY_BIN_PATH}:${SERVBAY_SBIN_PATH}:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin"
export PKG_CONFIG_PATH="${SERVBAY_COMMON_LIB_PATH}/pkgconfig"
export PKG_CONFIG="${SERVBAY_BIN_PATH}/pkg-config"
export PKG_CONFIG_LIBDIR="${SERVBAY_COMMON_LIB_PATH}/pkgconfig"
export PATH=$PATH:"/usr/local/bin:/usr/local/sbin"
export PATH=$PATH:"/opt/homebrew/bin/"
export LDFLAGS="-L${SERVBAY_COMMON_PATH}/openssl/${OPENSSL_SELECTED_VERSION}/lib ${LDFLAGS}"
export CPPFLAGS="-I${SERVBAY_COMMON_PATH}/openssl/${OPENSSL_SELECTED_VERSION}/include ${CPPFLAGS}"
export PKG_CONFIG_PATH="${PKG_CONFIG_PATH}:${SERVBAY_COMMON_PATH}/openssl/${OPENSSL_SELECTED_VERSION}/lib/pkgconfig"
export PKG_CONFIG_LIBDIR="${PKG_CONFIG_LIBDIR}:${SERVBAY_COMMON_PATH}/openssl/${OPENSSL_SELECTED_VERSION}/lib/pkgconfig"
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
Compilation Examples
After setting up the compilation environment, you can proceed with code recompilation. Here are some examples:
Compile ImageMagick
ImageMagick is a dependency of the PHP imagick module. ImageMagick comes pre-installed with ServBay, so users don't need to compile it themselves. The following example is just to illustrate the process of compiling a package.
wget https://imagemagick.org/archive/releases/ImageMagick-7.1.1-33.tar.gz
tar zxvf ImageMagick-7.1.1-33.tar.gz
cd ImageMagick-7.1.1-33
./configure --prefix=${SERVBAY_COMMON_PATH} --libdir=${SERVBAY_COMMON_LIB_PATH} --includedir=${SERVBAY_COMMON_INCLUDE_PATH} --oldincludedir=${SERVBAY_COMMON_INCLUDE_PATH} --bindir=${SERVBAY_BIN_PATH} --sbindir=${SERVBAY_SBIN_PATH} --sysconfdir=${SERVBAY_ETC_PATH} --datarootdir=${SERVBAY_COMMON_SHARE_PATH} --enable-osx-universal-binary=no --disable-silent-rules --disable-opencl --enable-shared --enable-static --with-freetype=yes --with-gvc=no --with-modules --with-webp=yes --with-heic=no --without-gslib --with-fpx=no --without-openexr --with-raw=yes --without-lqr --without-djvu --without-fftw --without-pango --without-wmf --without-x --with-gs-font-dir=${SERVBAY_COMMON_SHARE_PATH}/ghostscript/10.02.1/Resource/Font
make -j ${CPU_NUMBER}
make install
2
3
4
5
6
Compile Packages Using cmake
For packages using cmake
for compilation, you can refer to the following method. Below is an example with protobuf
:
cmake -S . -B builddir -DCMAKE_INSTALL_PREFIX=${SERVBAY_COMMON_PATH} -DCMAKE_INSTALL_LIBDIR=${SERVBAY_COMMON_LIB_PATH} -DCMAKE_INSTALL_INCLUDEDIR=${SERVBAY_COMMON_INCLUDE_PATH} -DCMAKE_INSTALL_BINDIR=${SERVBAY_BIN_PATH} -DCMAKE_INSTALL_SBINDIR=${SERVBAY_SBIN_PATH} -DCMAKE_INSTALL_SYSCONFDIR=${SERVBAY_ETC_PATH} -DCMAKE_INSTALL_DATAROOTDIR=${SERVBAY_COMMON_SHARE_PATH} -DCMAKE_MACOSX_RPATH=1 -DCMAKE_INSTALL_RPATH=${SERVBAY_COMMON_LIB_PATH} -DCMAKE_BUILD_WITH_INSTALL_RPATH=TRUE -DCMAKE_PREFIX_PATH=${SERVBAY_COMMON_PATH} -DBUILD_SHARED_LIBS=ON -Dprotobuf_BUILD_LIBPROTOC=ON -Dprotobuf_BUILD_SHARED_LIBS=ON -Dprotobuf_INSTALL_EXAMPLES=OFF -Dprotobuf_BUILD_TESTS=OFF -Dprotobuf_ABSL_PROVIDER=package -Dprotobuf_JSONCPP_PROVIDER=module -DCMAKE_CXX_STANDARD=17
cmake --build builddir -j ${CPU_NUMBER}
cmake --install builddir
2
3
Compile PHP Modules
Refer to the article How to Compile PHP Modules
Compile PostgreSQL Modules
Refer to the article How to Compile PostgreSQL Modules
By following the above methods, users can customize ServBay to meet business needs.