#!/bin/sh
# $Id: buildall,v 1.43 2026/04/25 13:38:46 moko Exp $
install_directory=$HOME/parser3install
sendmail_command="/usr/sbin/sendmail -i -t -f postmaster"
parser3_dir=`pwd`
cd ..
project_dir=`pwd`
build_xml="yes"
build_pcre2="yes"
build_gmime=""
build_apache=""
build_stripped=""
direct_download=""
options="--with-included-ltdl"
options="$options --with-gc=$project_dir/gc/lib"
#options="$options --disable-stringstream"
printf "Building statically linked parser3"
for PARAM in "$@"; do
case "$PARAM" in
"--without-xml")
printf ", without xml"
build_xml=""
;;
"--without-pcre2")
printf ", without pcre2 library"
build_pcre2=""
;;
"--with-apache")
printf ", with apache module"
options="$options --with-apache"
build_apache="yes"
;;
"--with-mailreceive")
printf ", with mail receiving"
options="$options --with-mailreceive=$project_dir/gmime"
build_gmime="yes"
;;
"--with-system-mailreceive")
printf ", with mail receiving"
options="$options --with-mailreceive"
;;
"--with-system-amqp")
printf ", with amqp"
options="$options --with-amqp"
;;
"--strip")
printf ", without debug information"
build_stripped="yes"
;;
"--direct-download")
printf ", download sources from master"
direct_download="yes"
;;
"--help")
echo
echo "Usage: buildall [--without-xml] [--without-pcre2] [--with-apache] [--with-mailreceive] [--with-system-mailreceive] [--strip] [--direct-download] [--disable-safe-mode] [other configure options ...]"
exit 1
;;
*)
options="$options $PARAM"
;;
esac
done
if test "$build_xml" = "yes"; then
options="$options --with-xml=$project_dir/gnome"
fi
bits=`getconf LONG_BIT`
if test "$bits" = "64" -o "$build_apache" = "yes"; then
cflags="$cflags --with-pic"
else
cflags="$cflags --without-pic"
fi
if test ! "$build_apache" = "yes"; then
cflags="$cflags --disable-shared"
fi
download=`which fetch 2>/dev/null`
if test -f "$download"; then
download="fetch -p"
else
download="wget -c --passive-ftp"
fi
############################### Support functions ################################
prepare () {
cd $project_dir/src
if test ! -f "$1"; then
if test "$direct_download" = "yes"; then
echo "Downloading $lib from $2..."
$download $2$1
else
echo "Downloading $lib (master at $2)..."
$download https://www.parser.ru/off-line/download/libs/$1
fi
fi
echo "Unpacking $lib..."
rm -rf $lib
}
prepare_gz () {
prepare $1 $2
gunzip -c $1 | tar xf - >/dev/null
cd $lib
}
prepare_xz () {
prepare $1 $2
xzcat $1 | tar xf - >/dev/null
cd $lib
}
cleanup () {
cd ..
rm -rf $lib
}
#################################### Building ####################################
echo
mkdir src >/dev/null 2>&1
if test ! -f "$project_dir/gc/lib/libgc.a"; then
lib="libatomic_ops-7.6.2"
prepare_gz ${lib}.tar.gz http://www.hboehm.info/gc/gc_source/
lib="gc-8.0.4"
prepare_gz ${lib}.tar.gz http://www.hboehm.info/gc/gc_source/
mv ../libatomic_ops-7.6.2 libatomic_ops
echo "Configuring $lib..."
CPPFLAGS="-DUSE_MMAP -DDONT_ADD_BYTE_AT_END" \
./configure --prefix=$project_dir/gc \
--disable-shared \
--disable-parallel-mark \
--silent $cflags
echo "Building $lib..."
make install
cleanup
fi
if test "$build_pcre2" = "yes"; then
options="$options --with-pcre=$project_dir/pcre2"
if test ! -f "$project_dir/pcre2/lib/libpcre2-8.a"; then
lib="pcre2-10.44"
prepare_gz $lib.tar.gz https://github.com/PCRE2Project/pcre2/releases/download/pcre2-10.44/
echo "Configuring $lib..."
./configure --prefix="$project_dir/pcre2" \
--enable-jit \
--with-match-limit-depth=10000 \
--disable-shared \
--silent $cflags
echo "Building $lib..."
make install
cleanup
fi
else
options="$options --with-pcre=$project_dir/pcre"
if test ! -f "$project_dir/pcre/lib/libpcre.a"; then
lib="pcre-8.45"
prepare_gz $lib.tar.gz https://sourceforge.net/projects/pcre/files/pcre/8.45/
echo "Configuring $lib..."
./configure --prefix="$project_dir/pcre" \
--with-match-limit-recursion=10000 \
--enable-utf8 \
--enable-unicode-properties \
--disable-shared \
--disable-cpp \
--disable-pcregrep-libz \
--disable-pcregrep-libbz2 \
--silent $cflags
echo "Building $lib..."
make install
cleanup
fi
fi
if test "$build_xml" = "yes" -a ! -f "$project_dir/gnome/lib/libxml2.a"; then
lib="libxml2-2.9.9"
prepare_gz $lib.tar.gz http://xmlsoft.org/download/
#sax1, output, tree, xinclude[in libxslt], html[in libxslt, mode=html?], xptr[xinclude], pattern -- needed!
echo "Configuring $lib..."
./configure --prefix=$project_dir/gnome \
--without-catalog \
--without-iconv \
--without-debug \
--without-iso8859x \
--without-legacy \
--without-push \
--without-python \
--without-writer \
--without-readline \
--without-regexps \
--without-schemas \
--without-schematron \
--without-modules \
--without-ftp \
--without-http \
--without-docbook \
--without-zlib \
--without-lzma \
--disable-shared \
--silent $cflags
echo "Building $lib..."
make install
cleanup
fi
if test "$build_xml" = "yes" -a ! -f "$project_dir/gnome/lib/libxslt.a"; then
lib="libxslt-1.1.34"
prepare_gz $lib.tar.gz http://xmlsoft.org/download/
echo "Configuring $lib..."
CFLAGS="$CFLAGS -D__stub_clock_gettime -Dclock_gettime=choke_me" \
./configure --prefix=$project_dir/gnome \
--with-libxml-prefix=$project_dir/gnome \
--without-debug \
--without-debugger \
--without-crypto \
--without-plugins \
--disable-shared \
--silent $cflags
echo "Building $lib..."
make install
cleanup
fi
if test "$build_gmime" = "yes"; then
glib_ldflags=""
gmime_cflags=""
gmime_ldflags="-L$project_dir/gmime/lib/"
os=`uname`
if test "$os" = "FreeBSD"; then
gmime_cflags="CFLAGS=-I/usr/local/include CXXFLAGS=-I/usr/local/include"
glib_ldflags="LDFLAGS=-L/usr/local/lib"
gmime_ldflags="$gmime_ldflags -L/usr/local/lib"
fi
if test ! -f "$project_dir/gmime/lib/libglib-2.0.a"; then
lib="glib-2.28.8"
prepare_xz $lib.tar.xz ftp://ftp.gnome.org/pub/GNOME/sources/glib/2.28/
echo "Configuring $lib..."
./configure --prefix=$project_dir/gmime \
--enable-dtrace=no \
--enable-debug=no \
--enable-iconv-cache=no \
--disable-fam \
--disable-selinux \
--disable-xattr \
--disable-shared \
--enable-static \
--silent $cflags $gmime_cflags $glib_ldflags
echo "Building $lib..."
make install
cleanup
fi
if test ! -f "$project_dir/gmime/lib/libgmime-2.4.a"; then
lib="gmime-2.4.32"
prepare_xz $lib.tar.xz ftp://ftp.gnome.org/pub/GNOME/sources/gmime/2.4/
echo "Configuring $lib..."
./configure --prefix=$project_dir/gmime \
--disable-glibtest \
--disable-mono \
--disable-shared \
--enable-static \
--silent $cflags $gmime_cflags LDFLAGS="$gmime_ldflags" PKG_CONFIG_PATH="$project_dir/gmime/lib/pkgconfig"
echo "Building $lib..."
make install
cleanup
fi
fi
cd $parser3_dir
if test ! -f "Makefile"; then
echo "Configuring parser3..."
./configure --prefix=$install_directory \
--sysconfdir=$install_directory/bin \
--datadir=$install_directory/bin \
--datarootdir="\$confdir" \
--libdir="\$confdir/lib" \
--with-sendmail="$sendmail_command" \
$options $cflags $gmime_cflags
fi
echo "Building parser3..."
make install
if test $? -ne 0; then exit 1; fi
if test "$build_stripped" = "yes"; then
strip ${install_directory}/bin/parser3
fi
echo "DONE"
echo
echo "********************************************************************************************************"
echo "Now you can copy $install_directory/bin to your cgi-bin directory"
echo "Read more about installing Parser here:"
echo " https://www.parser.ru/en/docs/lang/install4apachecgi.htm in English"
echo " https://www.parser.ru/docs/lang/install4apachecgi.htm in Russian"
echo "********************************************************************************************************"
E-mail: