#!/bin/bash
# SPDX-License-Identifier: GPL-3.0-or-later
# Copyright (C) 2015-2016, 2026 InterGenJLU
#
# apr 1.7.6 — Apache Portable Runtime
#
# Wave W1 prereq for apache-httpd 2.4.x. The APR project provides an
# OS-abstraction layer (file I/O, threading, networking, memory pools,
# string handling) that the Apache HTTP Server links against. APR's API
# is also consumable by non-Apache projects (subversion, MariaDB columnar
# storage, etc.) but our in-tree consumer at v1.0 is solely apache-httpd.
#
# Why this version (1.7.6, current latest stable in the 1.7.x branch):
#   * Released 2026-01-12 per https://apr.apache.org/news.html
#   * 1.7.6 is the most recent release in the 1.7.x branch (apr.apache.org
#     lists it as the current "latest"). 1.8.x is not yet released; the
#     2.x branch is in long-term development without a public release.
#   * Single SHA-256 anchor pinned in package.yml after local download
#     + sha256sum verification of the upstream archive.apache.org tarball.
#
# License: Apache-2.0. Single LICENSE file at the tarball root carries
# the standard Apache License 2.0 (verified head -5 matches the canonical
# "Apache License Version 2.0, January 2004" header). No additional or
# alternate license components in the package.
#
# Build profile: autotools (configure + make + make install). The tarball
# ships a pre-generated `configure` script; no autogen.sh / autoreconf
# bootstrap step is required.
#
# Configure flags chosen:
#   --prefix=/usr             standard distro layout
#   --libdir=/usr/lib         avoids lib64-vs-lib drift; apr installs
#                             both libapr-1.so + the apr-1-config CLI
#                             helper here
#   --sysconfdir=/etc         standard
#   --enable-threads          threading support enabled (Apache's
#                             mpm_event default consumer requires it)
#   --enable-other-child      reliable child-process support;
#                             load-bearing for Apache's piped-log + CGI
#                             surface
#
# Security-only-alignment posture: apr is a library only — no daemons,
# no setuid binaries, no network listeners, no kernel interfaces. It
# provides cross-platform abstractions over filesystem + process +
# thread + memory-allocation primitives. Privileged surface is
# determined entirely by the consuming program (apache-httpd ships its
# own systemd + AppArmor hardening when it consumes apr at runtime).

configure() {
    set -e
    ./configure                                                            \
        --prefix=/usr                                                      \
        --libdir=/usr/lib                                                  \
        --sysconfdir=/etc                                                  \
        --enable-threads                                                   \
        --enable-other-child
}

build() {
    set -e
    make -j${IGOS_JOBS}
}

do_install() {
    set -e
    make DESTDIR="$DESTDIR" install
}

check() {
    set -e
    # apr's `make check` runs a battery of unit tests requiring the
    # built library to be link-able. Tests assume some POSIX runtime
    # surfaces (writable /tmp, networking loopback) that are awkward
    # to satisfy in a build chroot. Run-time verification is performed
    # at link time by downstream consumers (apr-util's configure +
    # apache-httpd's configure both probe apr-1-config) and at runtime
    # by Apache's mod_lifecycle exercises during its first request.
    return 0
}
