From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@sympa.inria.fr Delivered-To: caml-list@sympa.inria.fr Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by sympa.inria.fr (Postfix) with ESMTPS id D06967FC6C for ; Fri, 9 Oct 2015 14:03:24 +0200 (CEST) IronPort-PHdr: 9a23:fqjepRw8XwxnsJHXCy+O+j09IxM/srCxBDY+r6Qd0ekRIJqq85mqBkHD//Il1AaPBtWHra8cw8Pt8IneGkU4qa6bt34DdJEeHzQksu4x2zIaPcieFEfgJ+TrZSFpVO5LVVti4m3peRMNQJW2WVTerzWI4CIIHV2nbEwudrizR9aapv/0/t7x0qWbWx9Piju5bOE6BzSNhiKViPMrh5B/IL060BrDrygAUe1XwWR1OQDbxE6ktY/jtKJkpi9ZvvZk889bTY37eb45RPpWFmcIKWcwsfb3uBfKS0Ov638YX38TmxxOS1ze8Bz0V5HZriv37O90wzWXJ9awQb1iCmfq1LtiVBK90HRPDDU+6myC0sE= Authentication-Results: mail2-smtp-roc.national.inria.fr; spf=None smtp.pra=stefan@the2masters.de; spf=Pass smtp.mailfrom=stefan@the2masters.de; spf=None smtp.helo=postmaster@mail-wi0-f173.google.com Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of stefan@the2masters.de) identity=pra; client-ip=209.85.212.173; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="stefan@the2masters.de"; x-sender="stefan@the2masters.de"; x-conformance=sidf_compatible Received-SPF: Pass (mail2-smtp-roc.national.inria.fr: domain of stefan@the2masters.de designates 209.85.212.173 as permitted sender) identity=mailfrom; client-ip=209.85.212.173; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="stefan@the2masters.de"; x-sender="stefan@the2masters.de"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of postmaster@mail-wi0-f173.google.com) identity=helo; client-ip=209.85.212.173; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="stefan@the2masters.de"; x-sender="postmaster@mail-wi0-f173.google.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A0BwAQDbqxdWm63UVdFehGiBTbdyhCIBDYFagxOCCn8CgUk4FAEBAQEBAQEBEAEBAQEBBgsLCSEugh+CCAEBBBIuAQE4Dx0iEjQBBQEODhkiiAwEAaEugTE+MYpYhVYBBY8qAQEBBwIBGQYKkHuELodBjlaNdIgpDJEkNYEXHwEBgkYNFgeBVm+HagEBAQ X-IPAS-Result: A0BwAQDbqxdWm63UVdFehGiBTbdyhCIBDYFagxOCCn8CgUk4FAEBAQEBAQEBEAEBAQEBBgsLCSEugh+CCAEBBBIuAQE4Dx0iEjQBBQEODhkiiAwEAaEugTE+MYpYhVYBBY8qAQEBBwIBGQYKkHuELodBjlaNdIgpDJEkNYEXHwEBgkYNFgeBVm+HagEBAQ X-IronPort-AV: E=Sophos;i="5.17,657,1437429600"; d="scan'208";a="181942592" Received: from mail-wi0-f173.google.com ([209.85.212.173]) by mail2-smtp-roc.national.inria.fr with ESMTP/TLS/AES128-GCM-SHA256; 09 Oct 2015 14:03:24 +0200 Received: by wiclk2 with SMTP id lk2so67451654wic.0 for ; Fri, 09 Oct 2015 05:03:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=the2masters.de; s=mail; h=from:to:subject:date:message-id:in-reply-to:references; bh=LsgFtSe70JYxaTAh/m9lSHarETYjNejv3T2WmuBXaYo=; b=f4pgvT/EoLylKTmKEUCq4GJEEAkuVvkTUZjt6tABsh5U20WvJwuEE/bkObo7BPOxcj M08+fp3w3nv8oadFaQ7sN2GgTyOkk/3vSvgzvmk+2rJMETDqPMDaZrffzFQZkL8kZ/gn xWmeIsn2gE9cd2Cv4aK50nNIhb+UD0f4h1Dik= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=LsgFtSe70JYxaTAh/m9lSHarETYjNejv3T2WmuBXaYo=; b=XBKV/Gvz+IFeEDctssabmIIXM+X8tcLVopcoudvJ8TxOiqRZNBQBjme1j9yM2ZO5jN B6uf22FtOT7ca3mSIp3Bqi3ks9l9yJodnjsIK3o4hvrxyRPlCWjqyiHCterS0bPs/7q/ ttvmazCZ7kGHZNiE2bN1xvbvZwhge5PGYSvIX84lFJARiCL/X9p8IM1UUcMMItmEAsgB h3jJJlgAtFrU2KPvWRtUYKt5kg92mMj5bhoVf3fyzXpg5OXHJsowSLE7vLWTyosdPbIt xSdhBo8x0qhLhFgfTUXep14z4HYuaTmL6+QzcY2qp7HiTTgrYRDtIdCFHRn4sr31pzrt AIrQ== X-Gm-Message-State: ALoCoQklzErw8SQTVmkqO65ASeENQQuRtUNnt+vsOqwxu2mOrY8XWJnmk6AkitHpG4uxDgOiO15n X-Received: by 10.180.9.112 with SMTP id y16mr10482146wia.28.1444392204256; Fri, 09 Oct 2015 05:03:24 -0700 (PDT) Received: from devel.eslohe.lan (p579F4BD2.dip0.t-ipconnect.de. [87.159.75.210]) by smtp.googlemail.com with ESMTPSA id h7sm1754456wjz.7.2015.10.09.05.03.23 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 09 Oct 2015 05:03:23 -0700 (PDT) From: Stefan Hellermann To: caml-list@inria.fr Date: Fri, 9 Oct 2015 14:03:14 +0200 Message-Id: <1444392194-18276-3-git-send-email-stefan@the2masters.de> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1444392194-18276-1-git-send-email-stefan@the2masters.de> References: <1444392194-18276-1-git-send-email-stefan@the2masters.de> Subject: [Caml-list] [PATCH 2/2] configure: Check endianess by using the preprocessor Signed-off-by: Stefan Hellermann --- config/auto-aux/endian.c | 60 +++++++++++++++++++----------------------------- configure | 26 ++++++++++++--------- 2 files changed, 38 insertions(+), 48 deletions(-) diff --git a/config/auto-aux/endian.c b/config/auto-aux/endian.c index 5dc623a..eee48c8 100644 --- a/config/auto-aux/endian.c +++ b/config/auto-aux/endian.c @@ -1,40 +1,26 @@ -/***********************************************************************/ -/* */ -/* OCaml */ -/* */ -/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ -/* */ -/* Copyright 1996 Institut National de Recherche en Informatique et */ -/* en Automatique. All rights reserved. This file is distributed */ -/* under the terms of the GNU Library General Public License, with */ -/* the special exception on linking described in file ../../LICENSE. */ -/* */ -/***********************************************************************/ - -#include -#include "m.h" +// Try to find the right includes +#if defined(__linux__) || defined(__CYGWIN__) +# define _BSD_SOURCE +# include +#elif defined(__APPLE__) +# include +#elif defined(BSD) +# include +#elif defined(_WIN16) || defined(_WIN32) || defined(_WIN64) +# include +# include +#endif -#ifndef ARCH_SIXTYFOUR -long intval = 0x41424344L; -char * bigendian = "ABCD"; -char * littleendian = "DCBA"; +#if defined(__BIG_ENDIAN__) || \ + defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ || \ + defined(__BYTE_ORDER) && __BYTE_ORDER == __BIG_ENDIAN || \ + defined(BYTE_ORDER) && BYTE_ORDER == BIG_ENDIAN +0 +#elif defined(__LITTLE_ENDIAN__) || \ + defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ || \ + defined(__BYTE_ORDER) && __BYTE_ORDER == __LITTLE_ENDIAN || \ + defined(BYTE_ORDER) && BYTE_ORDER == LITTLE_ENDIAN +1 #else -long intval = 0x4142434445464748L; -char * bigendian = "ABCDEFGH"; -char * littleendian = "HGFEDCBA"; +# error Cannot detect endianess of target #endif - -int main(void) -{ - long n[2]; - char * p; - - n[0] = intval; - n[1] = 0; - p = (char *) n; - if (strcmp(p, bigendian) == 0) - return 0; - if (strcmp(p, littleendian) == 0) - return 1; - return 2; -} diff --git a/configure b/configure index e3ea7eb..b7c3348 100755 --- a/configure +++ b/configure @@ -552,22 +552,26 @@ echo "#define SIZEOF_LONGLONG $5" >> m.h # Determine endianness -sh ./runtest endian.c -case $? in - 0) inf "This is a big-endian architecture." - echo "#define ARCH_BIG_ENDIAN" >> m.h;; - 1) inf "This is a little-endian architecture." - echo "#undef ARCH_BIG_ENDIAN" >> m.h;; - 2) err "This architecture seems to be neither big endian nor little" \ - "endian.\n OCaml won't run on this architecture.";; - *) case $target in +ret=`sh ./preprocesstest endian.c` +if test "$?" -eq 0; then + set $ret + case "$1" in + 0) inf "This is a big-endian architecture." + echo "#define ARCH_BIG_ENDIAN" >> m.h;; + 1) inf "This is a little-endian architecture." + echo "#undef ARCH_BIG_ENDIAN" >> m.h;; + *) err "This architecture seems to be neither big endian nor little" \ + "endian.\n OCaml won't run on this architecture.";; + esac +else + case $target in *-*-mingw*) inf "This is a little-endian architecture." echo "#undef ARCH_BIG_ENDIAN" >> m.h;; *) wrn "Something went wrong during endianness determination.\n" \ "You will have to figure out endianness yourself\n" \ "(option ARCH_BIG_ENDIAN in m.h).";; - esac;; -esac + esac +fi # Determine alignment constraints -- 2.1.4