distributable:
  url: https://archive.apache.org/dist/httpd/httpd-{{version}}.tar.gz
  strip-components: 1

versions:
  url: https://archive.apache.org/dist/httpd/
  match: /httpd-\d+\.\d+\.\d+.tar.gz/
  strip:
    - /^httpd-/
    - /\.tar\.gz$/

dependencies:
  apache.org/apr: '>=1.3.0'
  apache.org/apr-util: '>=1.3.0'
  github.com/google/brotli: '*'
  nghttp2.org: '*'
  openssl.org: '*'
  pcre.org/v2: '*'
  gnome.org/libxml2: '*'
  zlib.net: '*'
  libexpat.github.io: '*'

runtime:
  env:
    HTTPD_ROOT: '{{prefix}}'
    APACHE_CONFDIR: '{{prefix}}/conf'

build:
  dependencies:
    gnu.org/libtool: '*'
    gnu.org/autoconf: '*'
  script:
    - ./configure $ARGS
    - make
    - make install

    - HTTPD_CONF=$({{prefix}}/bin/httpd -V 2>/dev/null | grep SERVER_CONFIG_FILE | sed 's/.*"\(.*\)"/\1/')
    - |
        sed -i.bak 's/#ServerName www.example.com:8080/ServerName localhost:8080/g' {{prefix}}/$HTTPD_CONF
        rm {{prefix}}/$HTTPD_CONF.bak

    - run: |
        sed -i.bak \
          -e "s_{{prefix}}_\$(cd \$(dirname \$0)/.. \&\& pwd)_g" \
          -e 's/^HTTPD='\''\(.*\)'\''$/HTTPD="$(cd $(dirname $0)\/.. \&\& pwd)\/bin\/httpd"/' \
          apachectl envvars envvars-std
        rm apachectl.bak envvars.bak envvars-std.bak
      working-directory: ${{prefix}}/bin

    - run: |
        sed -i.bak \
          -e 's|{{prefix}}|\${HTTPD_ROOT}|' \
          httpd.conf
        rm httpd.conf.bak
      working-directory: ${{prefix}}/conf

  env:
    ARGS:
      - --prefix="{{prefix}}"
      - --enable-layout="Apache"
      - --enable-mpms-shared=all
      - --enable-mods-shared=all
      - --enable-authnz-fcgi
      - --enable-so
      - --enable-ssl
      - --enable-cgi
      - --enable-pie
      - --enable-suexec
      - --with-suexec-caller=_www
      - --with-suexec-bin={{prefix}}/suexec
      - --with-port=8080
      - --with-sslport=8443
      - --with-apr={{deps.apache.org/apr.prefix}}
      - --with-apr-util={{deps.apache.org/apr-util.prefix}}
      - --with-brotli={{deps.github.com/google/brotli.prefix}}
      - --with-libxml2={{deps.gnome.org/libxml2.prefix}}
      - --with-mpm=prefork
      - --with-nghttp2={{deps.nghttp2.org.prefix}}
      - --with-ssl={{deps.openssl.org.prefix}}
      - --with-pcre={{deps.pcre.org/v2.prefix}}
      - --with-z={{deps.zlib.net.prefix}}
      - --disable-lua
      - --disable-luajit

provides:
  - bin/ab
  - bin/apachectl
  - bin/checkgid
  - bin/fcgistarter
  - bin/htcacheclean
  - bin/htdbm
  - bin/htdigest
  - bin/htpasswd
  - bin/httpd
  - bin/httxt2dbm
  - bin/logresolve
  - bin/rotatelogs
  - bin/suexec

test:
  script:
    - httpd -v | grep {{version}}
    - apachectl -t -f "$APACHE_CONFDIR/httpd.conf"
