Source: nginx Version: 1.14.0-1 Tags: patch User: [email protected] Usertags: rebootstrap
nginx fails to cross build from source for multiple reasons. Upstream does not support cross compilation and it is not clear whether doing so is feasible at all. Yet, I found a number of easy fixes I would like to share with you: * debian/rules checks DEB_BUILD_ARCH for sparc, but it should be checking DEB_HOST_ARCH. * debian/rules should be passing documented options such as --crossbuild or --with-cc to ./configure. * auto/cc/name requires running compiled binaries, but that's not strictly necessary. * auto/types/sizeof also requires running compiled binaries. The attached patch fixes all of the issues above. After applying it, nginx fails finding accept4, struct in6_pktinfo and NGX_SYS_NERR. Likely, some checks are still broken. Still I think that the patch is an incremental step in the right direction. Please consider applying it and close this bug when doing so. Helmut
diff --minimal -Nru nginx-1.14.0/debian/changelog nginx-1.14.0/debian/changelog --- nginx-1.14.0/debian/changelog 2018-08-31 14:28:04.000000000 +0200 +++ nginx-1.14.0/debian/changelog 2018-10-29 20:57:17.000000000 +0100 @@ -1,3 +1,10 @@ +nginx (1.14.0-1.1) UNRELEASED; urgency=medium + + * Non-maintainer upload. + * Improve cross compilation: (Closes: #-1) + + Fix build/host confusion in debian/rules. + + Pass --crossbuild and --with-cc to ./configure for cross compilation. + + cross.patch: Detect C compiler without running host binaries. + + cross.patch: Make auto/types/sizeof work without running host binaries. + + -- Helmut Grohne <[email protected]> Mon, 29 Oct 2018 20:57:17 +0100 + nginx (1.14.0-1) unstable; urgency=medium [ Kartik Mistry ] diff --minimal -Nru nginx-1.14.0/debian/patches/cross.patch nginx-1.14.0/debian/patches/cross.patch --- nginx-1.14.0/debian/patches/cross.patch 1970-01-01 01:00:00.000000000 +0100 +++ nginx-1.14.0/debian/patches/cross.patch 2018-10-29 20:57:17.000000000 +0100 @@ -0,0 +1,86 @@ +--- nginx-1.14.0.orig/auto/cc/name ++++ nginx-1.14.0/auto/cc/name +@@ -7,7 +7,7 @@ + + ngx_feature="C compiler" + ngx_feature_name= +- ngx_feature_run=yes ++ ngx_feature_run=compile + ngx_feature_incs= + ngx_feature_path= + ngx_feature_libs= +--- nginx-1.14.0.orig/auto/types/sizeof ++++ nginx-1.14.0/auto/types/sizeof +@@ -26,8 +26,8 @@ + $NGX_INCLUDE_AUTO_CONFIG_H + + int main(void) { +- printf("%d", (int) sizeof($ngx_type)); +- return 0; ++ int x[sizeof($ngx_type) == 8 ? 1 : -1] = {}; ++ return x; + } + + END +@@ -36,27 +36,35 @@ + ngx_test="$CC $CC_TEST_FLAGS $CC_AUX_FLAGS \ + -o $NGX_AUTOTEST $NGX_AUTOTEST.c $NGX_LD_OPT $ngx_feature_libs" + +-eval "$ngx_test >> $NGX_AUTOCONF_ERR 2>&1" +- +- +-if [ -x $NGX_AUTOTEST ]; then +- ngx_size=`$NGX_AUTOTEST` ++if eval "$ngx_test >> $NGX_AUTOCONF_ERR 2>&1"; then ++ ngx_size=8 + echo " $ngx_size bytes" +-fi ++ ngx_max_value=9223372036854775807LL ++ ngx_max_len='(sizeof("-9223372036854775808") - 1)' ++else ++ cat << END > $NGX_AUTOTEST.c + ++#include <sys/types.h> ++#include <sys/time.h> ++$NGX_INCLUDE_UNISTD_H ++#include <signal.h> ++#include <stdio.h> ++#include <sys/resource.h> ++$NGX_INCLUDE_INTTYPES_H ++$NGX_INCLUDE_AUTO_CONFIG_H + +-case $ngx_size in +- 4) ++int main(void) { ++ int x[sizeof($ngx_type) == 4 ? 1 : -1] = {}; ++ return x; ++} ++ ++END ++ if eval "$ngx_test >> $NGX_AUTOCONF_ERR 2>&1"; then ++ ngx_size=4 ++ echo " $ngx_size bytes" + ngx_max_value=2147483647 + ngx_max_len='(sizeof("-2147483648") - 1)' +- ;; +- +- 8) +- ngx_max_value=9223372036854775807LL +- ngx_max_len='(sizeof("-9223372036854775808") - 1)' +- ;; +- +- *) ++ else + echo + echo "$0: error: can not detect $ngx_type size" + +@@ -69,7 +77,8 @@ + rm -rf $NGX_AUTOTEST* + + exit 1 +-esac ++ fi ++fi + + + rm -rf $NGX_AUTOTEST* diff --minimal -Nru nginx-1.14.0/debian/patches/series nginx-1.14.0/debian/patches/series --- nginx-1.14.0/debian/patches/series 2018-08-31 14:28:04.000000000 +0200 +++ nginx-1.14.0/debian/patches/series 2018-10-29 20:57:17.000000000 +0100 @@ -1,2 +1,3 @@ 0002-Make-sure-signature-stays-the-same-in-all-nginx-buil.patch 0003-define_gnu_source-on-other-glibc-based-platforms.patch +cross.patch diff --minimal -Nru nginx-1.14.0/debian/rules nginx-1.14.0/debian/rules --- nginx-1.14.0/debian/rules 2018-08-31 14:28:04.000000000 +0200 +++ nginx-1.14.0/debian/rules 2018-10-29 20:57:17.000000000 +0100 @@ -1,6 +1,7 @@ #!/usr/bin/make -f export DH_VERBOSE=1 +include /usr/share/dpkg/architecture.mk export DEB_BUILD_MAINT_OPTIONS=hardening=+all debian_cflags:=$(shell dpkg-buildflags --get CFLAGS) -fPIC $(shell dpkg-buildflags --get CPPFLAGS) debian_ldflags:=$(shell dpkg-buildflags --get LDFLAGS) -fPIC @@ -31,8 +32,7 @@ BASEDIR = $(CURDIR) $(foreach flavour,$(FLAVOURS),$(eval BUILDDIR_$(flavour) = $(CURDIR)/debian/build-$(flavour))) -DEB_BUILD_ARCH ?=$(shell dpkg-architecture -qDEB_BUILD_ARCH) -ifeq ($(DEB_BUILD_ARCH),sparc) +ifeq ($(DEB_HOST_ARCH),sparc) debian_cflags += -m32 -mcpu=ultrasparc endif @@ -71,6 +71,12 @@ --with-http_slice_module \ --with-threads +ifneq ($(DEB_BUILD_ARCH),$(DEB_HOST_ARCH)) +os_map_linux=Linux +common_configure_flags += --crossbuild=$(or $(os_map_$(DEB_HOST_ARCH_OS)),$(DEB_HOST_ARCH_OS)) +common_configure_flags += --with-cc=$(DEB_HOST_GNU_TYPE)-gcc +endif + light_configure_flags := \ $(common_configure_flags) \ --with-http_gzip_static_module \

