==========[ apache.mk ]==========

#############################################################
#
# apache
#
#############################################################

APACHE_VERSION    = 2.2.23
APACHE_SITE       = http://archive.apache.org/dist/httpd/
APACHE_SOURCE = httpd-$(APACHE_VERSION).tar.bz2
APACHE_INSTALL_STAGING = YES
APACHE_PACKAGE_DIR=$(@D)/../../../package/apache

APACHE_CONF_ENV += \
        ac_cv_file__dev_zero=yes \
        ac_cv_func_setpgrp_void=yes \
        apr_cv_tcp_nodelay_with_cork=yes \
        ac_cv_sizeof_struct_iovec=8 \
        apr_cv_process_shared_works=yes \
        apr_cv_mutex_robust_shared=no \
        ac_cv_struct_rlimit=yes \
        ap_cv_void_ptr_lt_long=no \
        CC=/opt/Marvell_toolchain_201201/armv7-marvell-linux-gnueabi-softfp_i686/bin/arm-marvell-linux-gnueabi-gcc

APACHE_CONF_OPT += \
        --build=i686-pc-linux-gnu \
        --host=arm-marvell-linux-gnueabi \
        --enable-so \
        --enable-module=all

# the stock apache package provides two cross-compile options --host and
# --build that get passed into configure to allow make to distinguish between
# the build machine and the target machine, but they don't work as advertised.
#      http://www.devshed.com/c/a/Apache/Building-Apache-the-Way-You-Want-It/10/
# luckily, I found a patch that allows apache to be built using an additional
# variable CC_FOR_BUILD that fixes this problem. the patch was downloaded from
#      http://people.apache.org/~fuankg/diffs/httpd-2.2.x-cross_compile.diff
# strangely, the patch utility on my build machine would not apply patches
# to files in sub-directories. therefore I've divided the patch diff into
# parts for each directory and applied the patches separately.
# also, I tried using the patch hooks, but it appears that X_PRE_PATCH_HOOKS
# is only executing if X_PATCH is defined -- and X_PATCH requires the patch
# to be located at X_SITE and this patch is not located at the same site
# as the apache package. ugh. so the files get patched as the first step in
# the configure process below.

define APACHE_CONFIGURE_CMDS
    ( cd $(@D); ./buildconf )
        ( cd $(@D); patch -i $(APACHE_PACKAGE_DIR)/httpd-2.2.x-cross_compile-apache-root.diff )
        ( cd $(@D)/server; patch -i $(APACHE_PACKAGE_DIR)/httpd-2.2.x-cross_compile-apache-root-server.diff )
        ( cd $(@D)/srclib/pcre; patch -i $(APACHE_PACKAGE_DIR)/httpd-2.2.x-cross_compile-apache-root-srclib-pcre.diff )
        ( cd $(@D) && rm -rf config.cache; \
    $(APACHE_CONF_ENV) \
    ./configure \
    $(APACHE_CONF_OPT) \
    )
endef

APACHE_MAKE_ENV += \
    CC_FOR_BUILD=cc \
    CFLAGS_FOR_BUILD=

define APACHE_INSTALL_INIT_SCRIPT

    $(INSTALL) -m 0755 package/apache/S50apache $(TARGET_DIR)/etc/init.d/S50apache

endef

APACHE_POST_INSTALL_TARGET_HOOKS += APACHE_INSTALL_INIT_SCRIPT

$(eval $(call AUTOTARGETS,package,apache))

==========[ Config.in ]==========

config BR2_PACKAGE_APACHE
    bool "apache"
    help
      Apache web server software.

      http://httpd.apache.org/

==========[ S50apache ]==========

#!/bin/sh
#
# Start the network....
#

APACHE_DIR=/usr/local/apache2/bin

case "$1" in
  start)
    echo "Starting apache web server..."
    $APACHE_DIR/apachectl -k start
    ;;
  stop)
    echo -n "Stopping apache web server..."
    $APACHE_DIR/apachectl -k stop
    ;;
  restart|reload)
    $APACHE_DIR/apachectl -k stop
    $APACHE_DIR/apachectl -k start
    ;;
  *)
    echo $"Usage: $0 {start|stop|restart}"
    exit 1
esac

exit $?

==========[  httpd-2.2.x-cross_compile-apache-root.diff  ]==========

Index: configure.in
===================================================================
--- configure.in    (revision 1328718)
+++ configure.in    (working copy)
@@ -154,6 +154,14 @@
AC_PROG_CC
AC_PROG_CPP
+dnl In case of cross compilation we set CC_FOR_BUILD to cc unless
+dnl we got already CC_FOR_BUILD from environment.
+if test "x${build_alias}" != "x${host_alias}"; then
+  if test "x${CC_FOR_BUILD}" = "x"; then
+    CC_FOR_BUILD=cc
+  fi
+fi
+
if test "x${cache_file}" = "x/dev/null"; then
   # Likewise, ensure that CC and CPP are passed through to the pcre
   # configure script iff caching is disabled (the autoconf 2.5x default).
Index: acinclude.m4
===================================================================
--- acinclude.m4    (revision 1328718)
+++ acinclude.m4    (working copy)
@@ -53,6 +53,8 @@
   APACHE_SUBST(CPPFLAGS)
   APACHE_SUBST(CFLAGS)
   APACHE_SUBST(CXXFLAGS)
+  APACHE_SUBST(CC_FOR_BUILD)
+  APACHE_SUBST(CFLAGS_FOR_BUILD)
   APACHE_SUBST(LTFLAGS)
   APACHE_SUBST(LDFLAGS)
   APACHE_SUBST(LT_LDFLAGS)
@@ -568,7 +570,7 @@
{
     return sizeof(void *) < sizeof(long);
 }], [ap_cv_void_ptr_lt_long=no], [ap_cv_void_ptr_lt_long=yes],
-    [ap_cv_void_ptr_lt_long=yes])])
+    [ap_cv_void_ptr_lt_long="cross compile - not checked"])])
 if test "$ap_cv_void_ptr_lt_long" = "yes"; then
     AC_MSG_ERROR([Size of "void *" is less than size of "long"])

==========[  httpd-2.2.x-cross_compile-apache-root-server.diff  ]==========

Index: server/Makefile.in
===================================================================
--- server/Makefile.in  (revision 1328718)
+++ server/Makefile.in  (working copy)
@@ -21,9 +21,14 @@
include $(top_builddir)/build/rules.mk
include $(top_srcdir)/build/library.mk
+ifdef CC_FOR_BUILD
+gen_test_char: gen_test_char.c
+   $(CC_FOR_BUILD) $(CFLAGS_FOR_BUILD) -DCROSS_COMPILE -o $@ $<
+else
gen_test_char_OBJECTS = gen_test_char.lo
gen_test_char: $(gen_test_char_OBJECTS)
    $(LINK) $(EXTRA_LDFLAGS) $(gen_test_char_OBJECTS) $(EXTRA_LIBS)
+endif
 test_char.h: gen_test_char
    ./gen_test_char > test_char.h


==========[  httpd-2.2.x-cross_compile.diff  ]==========

Index: srclib/pcre/Makefile.in
===================================================================
--- srclib/pcre/Makefile.in (revision 1328718)
+++ srclib/pcre/Makefile.in (working copy)
@@ -11,8 +11,13 @@
 $(LTLIBRARY_OBJECTS) dftables.lo: config.h
+ifdef CC_FOR_BUILD
+dftables: dftables.c
+   $(CC_FOR_BUILD) $(CFLAGS_FOR_BUILD) -o $@ $<
+else
dftables: dftables.lo
    $(LINK) $(EXTRA_LDFLAGS) dftables.lo $(EXTRA_LIBS)
+endif
 $(srcdir)/chartables.c: dftables
    ./dftables $@


==========[  httpd-2.2.x-cross_compile-apache-root-srclib-pcre.diff  ]==========

Index: server/Makefile.in
===================================================================
--- server/Makefile.in  (revision 1328718)
+++ server/Makefile.in  (working copy)
@@ -21,9 +21,14 @@
include $(top_builddir)/build/rules.mk
include $(top_srcdir)/build/library.mk
+ifdef CC_FOR_BUILD
+gen_test_char: gen_test_char.c
+   $(CC_FOR_BUILD) $(CFLAGS_FOR_BUILD) -DCROSS_COMPILE -o $@ $<
+else
gen_test_char_OBJECTS = gen_test_char.lo
gen_test_char: $(gen_test_char_OBJECTS)
    $(LINK) $(EXTRA_LDFLAGS) $(gen_test_char_OBJECTS) $(EXTRA_LIBS)
+endif
 test_char.h: gen_test_char
    ./gen_test_char > test_char.h
Index: srclib/pcre/Makefile.in
===================================================================
--- srclib/pcre/Makefile.in (revision 1328718)
+++ srclib/pcre/Makefile.in (working copy)
@@ -11,8 +11,13 @@
 $(LTLIBRARY_OBJECTS) dftables.lo: config.h
+ifdef CC_FOR_BUILD
+dftables: dftables.c
+   $(CC_FOR_BUILD) $(CFLAGS_FOR_BUILD) -o $@ $<
+else
dftables: dftables.lo
    $(LINK) $(EXTRA_LDFLAGS) dftables.lo $(EXTRA_LIBS)
+endif
 $(srcdir)/chartables.c: dftables
    ./dftables $@
Index: configure.in
===================================================================
--- configure.in    (revision 1328718)
+++ configure.in    (working copy)
@@ -154,6 +154,14 @@
AC_PROG_CC
AC_PROG_CPP
+dnl In case of cross compilation we set CC_FOR_BUILD to cc unless
+dnl we got already CC_FOR_BUILD from environment.
+if test "x${build_alias}" != "x${host_alias}"; then
+  if test "x${CC_FOR_BUILD}" = "x"; then
+    CC_FOR_BUILD=cc
+  fi
+fi
+
if test "x${cache_file}" = "x/dev/null"; then
   # Likewise, ensure that CC and CPP are passed through to the pcre
   # configure script iff caching is disabled (the autoconf 2.5x default).
Index: acinclude.m4
===================================================================
--- acinclude.m4    (revision 1328718)
+++ acinclude.m4    (working copy)
@@ -53,6 +53,8 @@
   APACHE_SUBST(CPPFLAGS)
   APACHE_SUBST(CFLAGS)
   APACHE_SUBST(CXXFLAGS)
+  APACHE_SUBST(CC_FOR_BUILD)
+  APACHE_SUBST(CFLAGS_FOR_BUILD)
   APACHE_SUBST(LTFLAGS)
   APACHE_SUBST(LDFLAGS)
   APACHE_SUBST(LT_LDFLAGS)
@@ -568,7 +570,7 @@
{
     return sizeof(void *) < sizeof(long);
 }], [ap_cv_void_ptr_lt_long=no], [ap_cv_void_ptr_lt_long=yes],
-    [ap_cv_void_ptr_lt_long=yes])])
+    [ap_cv_void_ptr_lt_long="cross compile - not checked"])])
 if test "$ap_cv_void_ptr_lt_long" = "yes"; then
     AC_MSG_ERROR([Size of "void *" is less than size of "long"])

