4 Commits

6 changed files with 183 additions and 37 deletions

View File

@@ -65,8 +65,8 @@ All local fixes are provided as a linear patch series:
0001-Fix-utime-usage-for-modern-glibc.patch 0001-Fix-utime-usage-for-modern-glibc.patch
0002-Fix-scandir-callback-signatures.patch 0002-Fix-scandir-callback-signatures.patch
0003-Replace-gets-with-fgets.patch 0003-Replace-gets-with-fgets.patch
0004 -Add-missing-headers-for-modern-toolchains.patch 0004-Add-missing-headers-for-modern-toolchains.patch
`
## Build ## Build

View File

@@ -1,16 +1,17 @@
#!/usr/bin/env bash #!/usr/bin/env bash
set -euo pipefail set -euo pipefail
# Convenience wrapper:
# apply patches -> build -> install
#
# Env:
# SSLTYPE, TARGET, JOBS (see build.sh)
# PREFIX (see install.sh)
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
cd "$ROOT" cd "$ROOT"
# Defaults suitable for automation
: "${CLEAN:=1}"
: "${PREFIX:=/usr/local/imap}"
: "${DEPS_AUTO:=1}"
# Install deps first (Debian/Ubuntu)
./scripts/deps-debian.sh
./scripts/apply-patches.sh ./scripts/apply-patches.sh
./scripts/build.sh CLEAN="$CLEAN" ./scripts/build.sh
./scripts/install.sh PREFIX="$PREFIX" ./scripts/install.sh

View File

@@ -7,7 +7,7 @@ PATCHDIR="${ROOT}/patches"
usage() { usage() {
cat <<USAGE cat <<USAGE
Usage: $0 Usage: $0
Applies patches/*.patch to the working tree (idempotent). Applies patches 00010004 to the working tree (idempotent).
USAGE USAGE
} }
@@ -23,18 +23,16 @@ if [[ ! -d "$PATCHDIR" ]]; then
exit 1 exit 1
fi fi
# Apply patches only if they are not already applied.
# We use --dry-run to test applicability; if it fails, we assume it's already applied.
shopt -s nullglob shopt -s nullglob
patches=( "$PATCHDIR"/000[1-4]-*.patch ) patches=( "$PATCHDIR"/000[1-4]-*.patch )
#patches=( "$PATCHDIR"/*.patch )
if (( ${#patches[@]} == 0 )); then if (( ${#patches[@]} == 0 )); then
echo "ERROR: no patches found in $PATCHDIR" >&2 echo "ERROR: no 00010004 patches found in $PATCHDIR" >&2
exit 1 exit 1
fi fi
for p in "${patches[@]}"; do for p in "${patches[@]}"; do
echo "==> Checking $p" echo "==> Checking $(basename "$p")"
if patch --dry-run -p1 < "$p" >/dev/null 2>&1; then if patch --dry-run -p1 < "$p" >/dev/null 2>&1; then
echo "==> Applying $(basename "$p")" echo "==> Applying $(basename "$p")"
patch -p1 < "$p" patch -p1 < "$p"

View File

@@ -3,21 +3,25 @@ set -euo pipefail
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
SSLTYPE="${SSLTYPE:-unix.nopwd}" # recommended SSLTYPE="${SSLTYPE:-unix.nopwd}" # recommended for RFC 3501 compliance
TARGET="${TARGET:-lnp}" # lnp is what you used successfully TARGET="${TARGET:-lnp}" # what you used successfully
JOBS="${JOBS:-$(getconf _NPROCESSORS_ONLN 2>/dev/null || echo 1)}" CLEAN="${CLEAN:-0}" # set to 1 for a clean build
usage() { usage() {
cat <<USAGE cat <<USAGE
Usage: $0 Usage: $0
Build UW-IMAP in a deterministic, legacy-compatible order.
Environment: Environment:
SSLTYPE (default: unix.nopwd) SSLTYPE (default: unix.nopwd)
TARGET (default: lnp) TARGET (default: lnp)
JOBS (default: detected CPU count) CLEAN (default: 0) set to 1 to remove build artifacts before building
Example: Examples:
SSLTYPE=unix.nopwd JOBS=8 $0 $0
CLEAN=1 $0
SSLTYPE=unix.nopwd TARGET=lnp CLEAN=1 $0
USAGE USAGE
} }
@@ -28,23 +32,40 @@ fi
cd "$ROOT" cd "$ROOT"
# Make sure patches are applied before building (but don't force it here).
if [[ -d patches ]]; then if [[ -d patches ]]; then
echo "Hint: run ./scripts/apply-patches.sh before building if needed." echo "Hint: run ./scripts/apply-patches.sh before building if needed."
fi fi
CLEAN="${CLEAN:-0}"
if [[ "$CLEAN" == "1" ]]; then if [[ "$CLEAN" == "1" ]]; then
echo "==> Cleaning previous build artifacts" echo "==> Cleaning previous build artifacts"
make clean || true make clean || true
rm -f OSTYPE CFLAGS CCTYPE LDFLAGS OSCFLAGS ARCHIVE SPECIALS
rm -rf c-client mtest ipopd imapd mailutil mlock dmail tmail rebuild tools/an # Remove common UW-IMAP build byproducts/symlink trees that can break rebuilds
rm -f OSTYPE CFLAGS CCTYPE LDFLAGS OSCFLAGS ARCHIVE SPECIALS an 2>/dev/null || true
rm -rf c-client mtest ipopd imapd mailutil mlock dmail tmail rebuild 2>/dev/null || true
fi fi
echo "==> Building UW-IMAP: make ${TARGET} SSLTYPE=${SSLTYPE}" # Ensure tools/an exists and is executable (should be part of the repo)
# UW-IMAP makefiles are not always parallel-safe in all subdirs; use -j carefully. if [[ ! -f tools/an ]]; then
# We'll still allow -j, but you can set JOBS=1 if you see race issues. echo "ERROR: tools/an not found. Repository checkout seems incomplete." >&2
make -j"${JOBS}" "${TARGET}" "SSLTYPE=${SSLTYPE}" exit 1
fi
chmod +x tools/an 2>/dev/null || true
echo "==> Step 1/3: Prepare symlinks (make an)"
# This creates the symlink layout expected by the rest of the build (c-client/, mtest/, ...)
make an
echo "==> Step 2/3: Build core (make ${TARGET} SSLTYPE=${SSLTYPE})"
# IMPORTANT: do NOT use -j here; UW-IMAP's legacy build is not reliably parallel-safe.
make "${TARGET}" "SSLTYPE=${SSLTYPE}"
echo "==> Step 3/3: Build bundled tools (make bundled)"
# Bundled tools depend on generated headers like c-client/osdep.h.
#make bundled || true
make bundled
echo "Build done." echo "Build done."
echo "Artifacts:"
echo " c-client/c-client.a: $(test -f c-client/c-client.a && echo OK || echo MISSING)"
echo " c-client/osdep.h: $(test -f c-client/osdep.h && echo OK || echo MISSING)"

101
scripts/deps-debian.sh Executable file
View File

@@ -0,0 +1,101 @@
#!/usr/bin/env bash
set -euo pipefail
usage() {
cat <<USAGE
Usage: $0
Installs required build dependencies on Debian/Ubuntu using apt.
Environment:
DEPS_AUTO (default: 1) set to 0 to only print missing packages and exit non-zero
APT_YES (default: 1) set to 0 to run apt without -y
USAGE
}
if [[ "${1:-}" == "-h" || "${1:-}" == "--help" ]]; then
usage
exit 0
fi
DEPS_AUTO="${DEPS_AUTO:-1}"
APT_YES="${APT_YES:-1}"
# Must have apt
if ! command -v apt-get >/dev/null 2>&1; then
echo "ERROR: apt-get not found. This script supports Debian/Ubuntu only." >&2
exit 1
fi
# Basic distro check (soft)
if [[ -r /etc/os-release ]]; then
. /etc/os-release
case "${ID:-}" in
debian|ubuntu|linuxmint|pop) : ;;
*)
echo "WARN: Detected ID=${ID:-unknown}. Proceeding anyway (apt-based system assumed)." >&2
;;
esac
fi
# Packages needed to build UW-IMAP 2007f with modern toolchains
PKGS=(
build-essential
autoconf
automake
libtool
pkg-config
libssl-dev
libpam0g-dev
libc6-dev
libcrypt-dev
bison
flex
patch
ca-certificates
)
missing=()
for p in "${PKGS[@]}"; do
if dpkg -s "$p" >/dev/null 2>&1; then
continue
fi
missing+=( "$p" )
done
if (( ${#missing[@]} == 0 )); then
echo "==> Dependencies already satisfied."
exit 0
fi
echo "==> Missing packages:"
printf ' - %s\n' "${missing[@]}"
if [[ "$DEPS_AUTO" != "1" ]]; then
echo "DEPS_AUTO=0 -> not installing automatically." >&2
exit 2
fi
# Choose privilege escalation
SUDO=""
if [[ "$(id -u)" -ne 0 ]]; then
if command -v sudo >/dev/null 2>&1; then
SUDO="sudo"
else
echo "ERROR: Not running as root and sudo not found." >&2
exit 1
fi
fi
yesflag=()
if [[ "$APT_YES" == "1" ]]; then
yesflag=( -y )
fi
echo "==> Updating apt index"
$SUDO apt-get update
echo "==> Installing dependencies"
$SUDO apt-get install "${yesflag[@]}" "${missing[@]}"
echo "==> Done."

View File

@@ -14,9 +14,7 @@ Environment:
Installs: Installs:
- headers to: \$PREFIX/include - headers to: \$PREFIX/include
- static lib to: \$PREFIX/lib/libc-client.a - static lib to: \$PREFIX/lib/libc-client.a
- binaries to: \$PREFIX/bin (if present)
Note:
Requires a successful build (c-client/c-client.a exists).
USAGE USAGE
} }
@@ -36,16 +34,43 @@ if [[ ! -f "$SRC_LIB" ]]; then
fi fi
echo "==> Installing to PREFIX=$PREFIX" echo "==> Installing to PREFIX=$PREFIX"
install -d -m 0755 "$PREFIX/include" "$PREFIX/lib" install -d -m 0755 "$PREFIX/include" "$PREFIX/lib" "$PREFIX/bin"
echo "==> Installing headers" echo "==> Installing headers"
# Only install the public headers (all .h in c-client/)
install -m 0644 "$SRC_HDR_DIR"/*.h "$PREFIX/include/" install -m 0644 "$SRC_HDR_DIR"/*.h "$PREFIX/include/"
echo "==> Installing libc-client.a" echo "==> Installing libc-client.a"
install -m 0644 "$SRC_LIB" "$PREFIX/lib/libc-client.a" install -m 0644 "$SRC_LIB" "$PREFIX/lib/libc-client.a"
echo "==> Installing binaries (if present)"
# Common outputs after 'make bundled'
bins=(
"$ROOT/mtest/mtest"
"$ROOT/imapd/imapd"
"$ROOT/ipopd/ipopd"
"$ROOT/mailutil/mailutil"
"$ROOT/mlock/mlock"
"$ROOT/dmail/dmail"
"$ROOT/tmail/tmail"
)
installed_any=0
for b in "${bins[@]}"; do
if [[ -x "$b" ]]; then
install -m 0755 "$b" "$PREFIX/bin/"
echo " installed: $(basename "$b")"
installed_any=1
else
echo " skipped: $(basename "$b") (not found/executable)"
fi
done
echo "==> Done." echo "==> Done."
echo "Installed:" echo "Installed:"
echo " Headers: $PREFIX/include/*.h" echo " Headers: $PREFIX/include/*.h"
echo " Library: $PREFIX/lib/libc-client.a" echo " Library: $PREFIX/lib/libc-client.a"
if [[ "$installed_any" -eq 1 ]]; then
echo " Binaries: $PREFIX/bin/"
else
echo " Binaries: none (run ./scripts/build.sh to build bundled tools)"
fi