From bc8bb428b31ff8d065a6bac763d6408cc3537792 Mon Sep 17 00:00:00 2001 From: rustina-devs Date: Mon, 9 Nov 2020 20:35:16 +0100 Subject: [PATCH 01/49] Add fast path when extraction leads to intnat --- caml_z.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/caml_z.c b/caml_z.c index f34c55c..0d98ffc 100644 --- a/caml_z.c +++ b/caml_z.c @@ -934,6 +934,30 @@ CAMLprim value ml_z_extract(value arg, value off, value len) if (x >= 0) return Val_long(x); /* If x < 0, fall through slow path */ } + } else if (l <= Z_BASE2_LENGTH_OP) { + Z_ARG(arg); + c1 = o / Z_LIMB_BITS; + c2 = o % Z_LIMB_BITS; + csz = size_arg - c1; + if (csz > 0) { + if (c2) { + x = ptr_arg[c1] >> c2; + if ((o + l > (intnat)Z_LIMB_BITS) && (csz > 1)) + x |= (ptr_arg[c1 + 1] << (Z_LIMB_BITS - c2)); + } else x = ptr_arg[c1]; + } else x = (intnat)0; + if (sign_arg) { + x = ~x; + if (csz > 0) { + /* carry (cr=0 if all shifted-out bits are 0) */ + cr = ptr_arg[c1] & (((intnat)1 << c2) - 1); + for (i = 0; !cr && i < c1; i++) + cr = ptr_arg[i]; + if (!cr) x += 1; + } + } + x &= (((intnat)1 << l) - 1); + return Val_long(x); } #endif Z_MARK_SLOW; From 39df015463f2797256dfb12440ed8f6c2dfd59cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antoine=20Min=C3=A9?= Date: Wed, 3 Mar 2021 10:00:00 +0100 Subject: [PATCH 02/49] Preparation for release 1.12 --- Changes | 8 ++++++++ META | 4 ++-- z.mli | 2 +- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/Changes b/Changes index e38601e..a7f17cd 100644 --- a/Changes +++ b/Changes @@ -1,3 +1,11 @@ +Release 1.12 (2021-03-03) +- PR #79: fast path in OCaml (instead of assembly language) [Xavier Leroy] +- PR #94: remove source preprocessing and simplify configuration [Xavier Leroy] +- PR #93: fix parallel build [Guillaume Melquiond] +- PR #92: fix benchmark for subtraction [Guillaume Melquiond] +- require OCaml 4.04 or later [Xavier Leroy] +- add CI testing on macOS [Xavier Leroy] + Release 1.11 (2020-11-09) - Fixes #72, #75, #78: multiple fixes for of_string, support for underscores [hhugo] - Fix #74: fix Q.to_float for denormal numbers [pascal-cuoq] diff --git a/META b/META index 65adb2a..1b2b5af 100644 --- a/META +++ b/META @@ -1,11 +1,11 @@ description = "Arbitrary precision integers" requires = "" -version = "1.11" +version = "1.12" archive(byte) = "zarith.cma" archive(native) = "zarith.cmxa" package "top" ( - version = "1.11" + version = "1.12" description = "ZArith toplevel support" requires = "zarith" archive(byte) = "zarith_top.cma" diff --git a/z.mli b/z.mli index 0e4a046..2d155c5 100644 --- a/z.mli +++ b/z.mli @@ -712,7 +712,7 @@ end (** {1 Miscellaneous} *) val version: string -(** Library version (this file refers to version [@VERSION]). *) +(** Library version. *) (**/**) From 91d28189c27ce68648ed22f6f07f2db40e8bc85f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Recoules?= Date: Fri, 21 May 2021 22:31:12 +0200 Subject: [PATCH 03/49] Give 'extract' both ocaml and noalloc fast paths (see #79) --- caml_z.c | 86 ++++++++++++++++++++++++-------------------------------- z.ml | 28 +++++++++++++++++- z.mli | 2 +- 3 files changed, 64 insertions(+), 52 deletions(-) diff --git a/caml_z.c b/caml_z.c index 6c62347..0fd2353 100644 --- a/caml_z.c +++ b/caml_z.c @@ -902,15 +902,45 @@ CAMLprim value ml_z_format(value f, value v) CAMLreturn(r); } -#ifdef ARCH_SIXTYFOUR -#define BITS_PER_WORD 64 -#else -#define BITS_PER_WORD 32 -#endif +/* Fast path since len < BITS_PER_WORD */ +CAMLprim value ml_z_extract_small(value arg, value off, value len) +{ + Z_DECL(arg); + uintnat o, l; /* caml code ensures off and len are non signed */ + intnat x; + mp_size_t c1, c2, csz, i; + mp_limb_t cr; + Z_ARG(arg); + o = Long_val(off); + l = Long_val(len); + c1 = o / Z_LIMB_BITS; + c2 = o % Z_LIMB_BITS; + csz = size_arg - c1; + if (csz > 0) { + if (c2) { + x = ptr_arg[c1] >> c2; + if ((o + l > (intnat)Z_LIMB_BITS) && (csz > 1)) + x |= (ptr_arg[c1 + 1] << (Z_LIMB_BITS - c2)); + } else x = ptr_arg[c1]; + } else x = (intnat)0; + if (sign_arg) { + x = ~x; + if (csz > 0) { + /* carry (cr=0 if all shifted-out bits are 0) */ + cr = ptr_arg[c1] & (((intnat)1 << c2) - 1); + for (i = 0; !cr && i < c1; i++) + cr = ptr_arg[i]; + if (!cr) x += 1; + } + } + x &= (((intnat)1 << l) - 1); + return Val_long(x); +} CAMLprim value ml_z_extract(value arg, value off, value len) { - intnat o, l, x; + uintnat o, l; /* caml code ensures off and len are non signed */ + intnat x; mp_size_t sz, c1, c2, csz, i; mp_limb_t cr; value r; @@ -919,50 +949,6 @@ CAMLprim value ml_z_extract(value arg, value off, value len) MAYBE_UNUSED x; o = Long_val(off); l = Long_val(len); - if (o < 0) caml_invalid_argument("Z.extract: negative bit offset"); - if (l <= 0) caml_invalid_argument("Z.extract: nonpositive bit length"); -#if Z_USE_NATINT - /* Fast path */ - if (Is_long(arg)) { - x = Long_val(arg); - /* Shift away low "o" bits. If "o" too big, just replicate sign bit. */ - if (o >= BITS_PER_WORD) o = BITS_PER_WORD - 1; - x = x >> o; - /* Extract "l" low bits, if "l" is small enough */ - if (l < BITS_PER_WORD - 1) { - x = x & (((intnat)1 << l) - 1); - return Val_long(x); - } else { - /* If x >= 0, the extraction of "l" low bits keeps x unchanged. */ - if (x >= 0) return Val_long(x); - /* If x < 0, fall through slow path */ - } - } else if (l <= Z_BASE2_LENGTH_OP) { - Z_ARG(arg); - c1 = o / Z_LIMB_BITS; - c2 = o % Z_LIMB_BITS; - csz = size_arg - c1; - if (csz > 0) { - if (c2) { - x = ptr_arg[c1] >> c2; - if ((o + l > (intnat)Z_LIMB_BITS) && (csz > 1)) - x |= (ptr_arg[c1 + 1] << (Z_LIMB_BITS - c2)); - } else x = ptr_arg[c1]; - } else x = (intnat)0; - if (sign_arg) { - x = ~x; - if (csz > 0) { - /* carry (cr=0 if all shifted-out bits are 0) */ - cr = ptr_arg[c1] & (((intnat)1 << c2) - 1); - for (i = 0; !cr && i < c1; i++) - cr = ptr_arg[i]; - if (!cr) x += 1; - } - } - x &= (((intnat)1 << l) - 1); - return Val_long(x); - } -#endif Z_MARK_SLOW; { CAMLparam1(arg); diff --git a/z.ml b/z.ml index 4de0d56..47fbecc 100644 --- a/z.ml +++ b/z.ml @@ -232,7 +232,6 @@ external fits_int: t -> bool = "ml_z_fits_int" [@@noalloc] external fits_int32: t -> bool = "ml_z_fits_int32" [@@noalloc] external fits_int64: t -> bool = "ml_z_fits_int64" [@@noalloc] external fits_nativeint: t -> bool = "ml_z_fits_nativeint" [@@noalloc] -external extract: t -> int -> int -> t = "ml_z_extract" external powm: t -> t -> t -> t = "ml_z_powm" external pow: t -> int -> t = "ml_z_pow" external powm_sec: t -> t -> t -> t = "ml_z_powm_sec" @@ -323,6 +322,33 @@ let testbit x n = let is_odd x = testbit_internal x 0 let is_even x = not (testbit_internal x 0) +external c_extract_small: t -> int -> int -> t + = "ml_z_extract_small" [@@noalloc] +external c_extract: t -> int -> int -> t = "ml_z_extract" + +let extract x o l = + if o < 0 then invalid_arg "Z.signed_extract: negative bit offset"; + if l < 1 then invalid_arg "Z.signed_extract: nonpositive bit length"; + if is_small_int x then + (* Fast path *) + let o = if o >= Sys.int_size then Sys.int_size - 1 else o in + (* Shift away low "o" bits. If "o" too big, just replicate sign bit. *) + let z = unsafe_to_int x asr o in + if l < Sys.int_size then + (* Extract "l" low bits, if "l" is small enough *) + of_int (z land ((1 lsl l) - 1)) + else if z >= 0 then + (* If x >= 0, the extraction of "l" low bits keeps x unchanged. *) + of_int z + else + (* If x < 0, fall through slow path *) + c_extract x o l + else if l < Sys.int_size then + (* Alternative fast path since no allocation is required *) + c_extract_small x o l + else + c_extract x o l + let signed_extract x o l = if o < 0 then invalid_arg "Z.signed_extract: negative bit offset"; if l < 1 then invalid_arg "Z.signed_extract: nonpositive bit length"; diff --git a/z.mli b/z.mli index 2d155c5..e27be65 100644 --- a/z.mli +++ b/z.mli @@ -588,7 +588,7 @@ val log2up: t -> int external size: t -> int = "ml_z_size" [@@noalloc] (** Returns the number of machine words used to represent the number. *) -external extract: t -> int -> int -> t = "ml_z_extract" +val extract: t -> int -> int -> t (** [extract a off len] returns a nonnegative number corresponding to bits [off] to [off]+[len]-1 of [b]. Negative [a] are considered in infinite-length 2's complement From 53603d5841a3e7ba278279906ae1ab11a1c11233 Mon Sep 17 00:00:00 2001 From: Xavier Leroy Date: Sat, 9 Oct 2021 17:40:17 +0200 Subject: [PATCH 04/49] Use labels on the calls to Z.of_substring It's good style to call functions with the labels they are defined with. Plus, it silences a warning. --- q.ml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/q.ml b/q.ml index 3c57831..8abfc08 100644 --- a/q.ml +++ b/q.ml @@ -534,8 +534,8 @@ let of_string = try let i = String.index s '/' in make - (Z.of_substring s 0 i) - (Z.of_substring s (i+1) (String.length s-i-1)) + (Z.of_substring s ~pos:0 ~len:i) + (Z.of_substring s ~pos:(i+1) ~len:(String.length s-i-1)) with Not_found -> of_scientific_notation s From cc81bcc7639e50246b1282876ce4276be907f7f7 Mon Sep 17 00:00:00 2001 From: Yishuai Li Date: Mon, 25 Oct 2021 00:14:57 -0400 Subject: [PATCH 05/49] Add big_int_of_float --- big_int_Z.ml | 2 ++ big_int_Z.mli | 1 + 2 files changed, 3 insertions(+) diff --git a/big_int_Z.ml b/big_int_Z.ml index 3939d02..31d54f3 100644 --- a/big_int_Z.ml +++ b/big_int_Z.ml @@ -124,6 +124,8 @@ let int64_of_big_int x = let float_of_big_int = Z.to_float +let big_int_of_float = Z.of_float + let and_big_int = Z.logand let or_big_int = Z.logor diff --git a/big_int_Z.mli b/big_int_Z.mli index 31275d3..a888820 100644 --- a/big_int_Z.mli +++ b/big_int_Z.mli @@ -68,6 +68,7 @@ val int32_of_big_int : Z.t -> int32 val nativeint_of_big_int : Z.t -> nativeint val int64_of_big_int : Z.t -> int64 val float_of_big_int : Z.t -> float +val big_int_of_float : float -> Z.t val and_big_int : Z.t -> Z.t -> Z.t val or_big_int : Z.t -> Z.t -> Z.t val xor_big_int : Z.t -> Z.t -> Z.t From 1a53cc7cc489f1a139c060622d99c8616bba9841 Mon Sep 17 00:00:00 2001 From: Hugo Heuzard Date: Tue, 9 Nov 2021 13:53:54 +0100 Subject: [PATCH 06/49] add debug info --- project.mak | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/project.mak b/project.mak index fd1c158..511f851 100644 --- a/project.mak +++ b/project.mak @@ -49,9 +49,9 @@ ifeq ($(HASOCAMLOPT),yes) TOBUILD += zarith.cmxa $(CMXOBJ) TOINSTALL += zarith.$(LIBSUFFIX) endif - -OCAMLFLAGS = -I +compiler-libs -OCAMLOPTFLAGS = -I +compiler-libs +DEBUG = -g +OCAMLFLAGS += $(DEBUG) -I +compiler-libs +OCAMLOPTFLAGS += $(DEBUG) -I +compiler-libs ifeq ($(HASDYNLINK),yes) TOBUILD += zarith.cmxs @@ -71,19 +71,19 @@ tests: make -C tests test zarith.cma: $(MLSRC:%.ml=%.cmo) - $(OCAMLMKLIB) -failsafe -o zarith $+ $(LIBS) + $(OCAMLMKLIB) $(DEBUG) -failsafe -o zarith $+ $(LIBS) zarith.cmxa: $(MLSRC:%.ml=%.cmx) - $(OCAMLMKLIB) -failsafe -o zarith $+ $(LIBS) + $(OCAMLMKLIB) $(DEBUG) -failsafe -o zarith $+ $(LIBS) zarith.cmxs: zarith.cmxa libzarith.$(LIBSUFFIX) $(OCAMLOPT) -shared -o $@ -I . zarith.cmxa -linkall libzarith.$(LIBSUFFIX): $(CSRC:%.c=%.$(OBJSUFFIX)) - $(OCAMLMKLIB) -failsafe -o zarith $+ $(LIBS) + $(OCAMLMKLIB) $(DEBUG) -failsafe -o zarith $+ $(LIBS) zarith_top.cma: zarith_top.cmo - $(OCAMLC) -o $@ -a $< + $(OCAMLC) $(DEBUG) -o $@ -a $< doc: $(MLISRC) mkdir -p html From 661849f6440aeb429d5e384b3074e6c3b8e5f939 Mon Sep 17 00:00:00 2001 From: Xavier Clerc Date: Sat, 20 Nov 2021 08:55:31 +0000 Subject: [PATCH 07/49] Fix ml_z_remove w.r.t. GC rules (#108) `Field(...) = allocating_expression` can misbehave if the address of the left hand side is computed before the allocating expression is evaluated and triggers a GC. This pull request simply goes through a temporary variable. --- caml_z.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/caml_z.c b/caml_z.c index f8c3179..4a7b4f4 100644 --- a/caml_z.c +++ b/caml_z.c @@ -3049,15 +3049,16 @@ CAMLprim value ml_z_kronecker(value a, value b) CAMLprim value ml_z_remove(value a, value b) { CAMLparam2(a,b); - CAMLlocal1(r); + CAMLlocal2(r,tmp); mpz_t ma, mb, mr; int i; ml_z_mpz_init_set_z(ma, a); ml_z_mpz_init_set_z(mb, b); mpz_init(mr); i = mpz_remove(mr, ma, mb); + tmp = ml_z_from_mpz(mr); r = caml_alloc_small(2, 0); - Field(r,0) = ml_z_from_mpz(mr); + Field(r,0) = tmp; Field(r,1) = Val_int(i); mpz_clear(ma); mpz_clear(mb); From a4aaceabdb58dce3037cb84a8432b77295101467 Mon Sep 17 00:00:00 2001 From: Bernhard Schommer Date: Mon, 22 Nov 2021 13:52:25 +0100 Subject: [PATCH 08/49] Fix typo in ml_z_mul. It should be `Val_long(Long_val(arg1) * Long_val(arg2))` instead of `Val_long(Long_val(a1) * Long_val(a2))`. --- caml_z.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/caml_z.c b/caml_z.c index 4a7b4f4..6fc3aa5 100644 --- a/caml_z.c +++ b/caml_z.c @@ -1497,7 +1497,7 @@ CAMLprim value ml_z_mul(value arg1, value arg2) #if Z_FAST_PATH && !Z_FAST_PATH_IN_OCAML if (Is_long(arg1) && Is_long(arg2) && ml_z_mul_overflows(arg1, arg2) == Val_false) { - return Val_long(Long_val(a1) * Long_val(a2)); + return Val_long(Long_val(arg1) * Long_val(arg2)); } #endif /* mpn_ version */ From 09b03f66412b07f2d6928d65802cccaebd6ea8bb Mon Sep 17 00:00:00 2001 From: Simon Cruanes Date: Tue, 16 Feb 2021 19:00:19 -0500 Subject: [PATCH 09/49] add @since annotations on infix operators --- q.mli | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/q.mli b/q.mli index 957b723..6ee4127 100644 --- a/q.mli +++ b/q.mli @@ -274,19 +274,25 @@ val (///): Z.t -> Z.t -> t (** Creates a rational from two [Z.t]. *) val (=): t -> t -> bool -(** Same as [equal]. *) +(** Same as [equal]. + @since 1.8 *) val (<): t -> t -> bool -(** Same as [lt]. *) +(** Same as [lt]. + @since 1.8 *) val (>): t -> t -> bool -(** Same as [gt]. *) +(** Same as [gt]. + @since 1.8 *) val (<=): t -> t -> bool -(** Same as [leq]. *) +(** Same as [leq]. + @since 1.8 *) val (>=): t -> t -> bool -(** Same as [geq]. *) +(** Same as [geq]. + @since 1.8 *) val (<>): t -> t -> bool -(** [a <> b] is equivalent to [not (equal a b)]. *) +(** [a <> b] is equivalent to [not (equal a b)]. + @since 1.8 *) From 6a11543f749d7a7655c575ccd7e055d355e15030 Mon Sep 17 00:00:00 2001 From: Simon Cruanes Date: Wed, 5 Jan 2022 09:17:49 -0500 Subject: [PATCH 10/49] add more @since annotations --- z.mli | 69 ++++++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 47 insertions(+), 22 deletions(-) diff --git a/z.mli b/z.mli index 2d155c5..56476a2 100644 --- a/z.mli +++ b/z.mli @@ -99,7 +99,8 @@ val of_string: string -> t val of_substring : string -> pos:int -> len:int -> t (** [of_substring s ~pos ~len] is the same as [of_string (String.sub s pos len)] - *) + @since 1.4 +*) val of_string_base: int -> string -> t (** Parses a number represented as a string in the specified base, @@ -112,6 +113,7 @@ external of_substring_base = "ml_z_of_substring_base" (** [of_substring_base base s ~pos ~len] is the same as [of_string_base base (String.sub s pos len)] + @since 1.4 *) @@ -196,12 +198,14 @@ external divisible: t -> t -> bool = "ml_z_divisible" (** [divisible a b] returns [true] if [a] is exactly divisible by [b]. Unlike the other division functions, [b = 0] is accepted (only 0 is considered divisible by 0). + @since 1.10 *) external congruent: t -> t -> t -> bool = "ml_z_congruent" (** [congruent a b c] returns [true] if [a] is congruent to [b] modulo [c]. Unlike the other division functions, [c = 0] is accepted (only equal numbers are considered equal congruent 0). + @since 1.10 *) @@ -252,7 +256,9 @@ external numbits: t -> int = "ml_z_numbits" [@@noalloc] If [x] is zero, [numbits x] returns 0. Otherwise, [numbits x] returns a positive integer [n] such that [2^{n-1} <= |x| < 2^n]. Note that [numbits] is defined - for negative arguments, and that [numbits (-x) = numbits x]. *) + for negative arguments, and that [numbits (-x) = numbits x]. + @since 1.4 +*) external trailing_zeros: t -> int = "ml_z_trailing_zeros" [@@noalloc] (** Returns the number of trailing 0 bits in the given number. @@ -260,13 +266,17 @@ external trailing_zeros: t -> int = "ml_z_trailing_zeros" [@@noalloc] Otherwise, [trailing_zeros x] returns a nonnegative integer [n] which is the largest [n] such that [2^n] divides [x] evenly. Note that [trailing_zeros] is defined for negative arguments, - and that [trailing_zeros (-x) = trailing_zeros x]. *) + and that [trailing_zeros (-x) = trailing_zeros x]. + @since 1.4 +*) val testbit: t -> int -> bool (** [testbit x n] return the value of bit number [n] in [x]: [true] if the bit is 1, [false] if the bit is 0. Bits are numbered from 0. Raise [Invalid_argument] if [n] - is negative. *) + is negative. + @since 1.4 +*) external popcount: t -> int = "ml_z_popcount" (** Counts the number of bits set. @@ -409,10 +419,14 @@ val max: t -> t -> t (** Returns the maximum of its arguments. *) val is_even: t -> bool -(** Returns true if the argument is even (divisible by 2), false if odd. *) +(** Returns true if the argument is even (divisible by 2), false if odd. + @since 1.4 +*) val is_odd: t -> bool -(** Returns true if the argument is odd, false if even. *) +(** Returns true if the argument is odd, false if even. + @since 1.4 +*) external hash: t -> int = "ml_z_hash" [@@noalloc] (** Hashes a number, producing a small integer. @@ -460,7 +474,9 @@ external powm_sec: t -> t -> t -> t = "ml_z_powm_sec" arguments. Used in cryptographic applications, it provides better resistance to side-channel attacks than [Z.powm]. The exponent [exp] must be positive, and the modulus [mod] - must be odd. Otherwise, [Invalid_arg] is raised. *) + must be odd. Otherwise, [Invalid_arg] is raised. + @since 1.4 +*) external invert: t -> t -> t = "ml_z_invert" (** [invert base mod] returns the inverse of [base] modulo [mod]. @@ -480,55 +496,58 @@ external nextprime: t -> t = "ml_z_nextprime" *) external jacobi: t -> t -> int = "ml_z_jacobi" -(** [jacobi a b] returns the Jacobi symbol [(a/b)]. *) +(** [jacobi a b] returns the Jacobi symbol [(a/b)]. + @since 1.10 *) external legendre: t -> t -> int = "ml_z_legendre" -(** [legendre a b] returns the Legendre symbol [(a/b)]. *) +(** [legendre a b] returns the Legendre symbol [(a/b)]. + @since 1.10 *) external kronecker: t -> t -> int = "ml_z_kronecker" -(** [kronecker a b] returns the Kronecker symbol [(a/b)]. *) +(** [kronecker a b] returns the Kronecker symbol [(a/b)]. + @since 1.10 *) external remove: t -> t -> t * int = "ml_z_remove" (** [remove a b] returns [a] after removing all the occurences of the factor [b]. Also returns how many occurrences were removed. - *) + @since 1.10 *) external fac: int -> t = "ml_z_fac" (** [fac n] returns the factorial of [n] ([n!]). Raises an [Invaid_argument] if [n] is non-positive. -*) + @since 1.10 *) external fac2: int -> t = "ml_z_fac2" (** [fac2 n] returns the double factorial of [n] ([n!!]). Raises an [Invaid_argument] if [n] is non-positive. -*) + @since 1.10 *) external facM: int -> int -> t = "ml_z_facM" (** [facM n m] returns the [m]-th factorial of [n]. Raises an [Invaid_argument] if [n] or [m] is non-positive. -*) + @since 1.10 *) external primorial: int -> t = "ml_z_primorial" (** [primorial n] returns the product of all positive prime numbers less than or equal to [n]. Raises an [Invaid_argument] if [n] is non-positive. -*) + @since 1.10 *) external bin: t -> int -> t = "ml_z_bin" (** [bin n k] returns the binomial coefficient [n] over [k]. Raises an [Invaid_argument] if [k] is non-positive. -*) + @since 1.10 *) external fib: int -> t = "ml_z_fib" (** [fib n] returns the [n]-th Fibonacci number. Raises an [Invaid_argument] if [n] is non-positive. -*) + @since 1.10 *) external lucnum: int -> t = "ml_z_lucnum" (** [lucnum n] returns the [n]-th Lucas number. Raises an [Invaid_argument] if [n] is non-positive. -*) + @since 1.10 *) (** {1 Powers} *) @@ -563,7 +582,7 @@ external rootrem: t -> int -> t * t = "ml_z_rootrem" [x-root**n]. [n] must be positive and, if [n] is even, then [x] must be nonnegative. Otherwise, an [Invalid_argument] is raised. - *) + @since 1.10 *) external perfect_power: t -> bool = "ml_z_perfect_power" (** True if the argument has the form [a^b], with [b>1] *) @@ -575,13 +594,17 @@ val log2: t -> int (** Returns the base-2 logarithm of its argument, rounded down to an integer. If [x] is positive, [log2 x] returns the largest [n] such that [2^n <= x]. If [x] is negative or zero, [log2 x] raise - the [Invalid_argument] exception. *) + the [Invalid_argument] exception. + @since 1.4 +*) val log2up: t -> int (** Returns the base-2 logarithm of its argument, rounded up to an integer. If [x] is positive, [log2up x] returns the smallest [n] such that [x <= 2^n]. If [x] is negative or zero, [log2up x] raise - the [Invalid_argument] exception. *) + the [Invalid_argument] exception. + @since 1.4 +*) (** {1 Representation} *) @@ -712,7 +735,9 @@ end (** {1 Miscellaneous} *) val version: string -(** Library version. *) +(** Library version. + @since 1.1 +*) (**/**) From 050b2c4ad4f264d5024cb9d26379129d149f9999 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antoine=20Min=C3=A9?= Date: Wed, 5 Jan 2022 15:44:34 +0100 Subject: [PATCH 11/49] add plugin directives in META (issue #102) --- META | 2 ++ 1 file changed, 2 insertions(+) diff --git a/META b/META index 1b2b5af..1828d24 100644 --- a/META +++ b/META @@ -3,6 +3,8 @@ requires = "" version = "1.12" archive(byte) = "zarith.cma" archive(native) = "zarith.cmxa" +plugin(byte) = "zarith.cma" +plugin(native) = "zarith.cmxs" package "top" ( version = "1.12" From 6248230f1cb95391ddd3e95f386c135a7d202714 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antoine=20Min=C3=A9?= Date: Tue, 11 Jan 2022 16:58:59 +0100 Subject: [PATCH 12/49] clarify in doc that to_int & co. consider ints as signed(issue #104) --- z.mli | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/z.mli b/z.mli index 2d155c5..9da5b17 100644 --- a/z.mli +++ b/z.mli @@ -287,16 +287,20 @@ external hamdist: t -> t -> int = "ml_z_hamdist" *) val to_int: t -> int -(** Converts to a base integer. May raise an [Overflow]. *) +(** Converts to a signed OCaml [int]. + Raises an [Overflow] if the value does not fit in a signed OCaml [int]. *) external to_int32: t -> int32 = "ml_z_to_int32" -(** Converts to a 32-bit integer. May raise [Overflow]. *) +(** Converts to a signed 32-bit integer [int32]. + Raises an [Overflow] if the value does not fit in a signed [int32]. *) external to_int64: t -> int64 = "ml_z_to_int64" -(** Converts to a 64-bit integer. May raise [Overflow]. *) +(** Converts to a signed 64-bit integer [int64]. + Raises an [Overflow] if the value does not fit in a signed [int64]. *) external to_nativeint: t -> nativeint = "ml_z_to_nativeint" -(** Converts to a native integer. May raise [Overflow]. *) +(** Converts to a native signed integer [nativeint]. + Raises an [Overflow] if the value does not fit in a signed [nativeint]. *) val to_float: t -> float (** Converts to a floating-point value. @@ -337,16 +341,16 @@ external format: string -> t -> string = "ml_z_format" *) external fits_int: t -> bool = "ml_z_fits_int" [@@noalloc] -(** Whether the argument fits in a regular [int]. *) +(** Whether the argument fits in an OCaml signed [int]. *) external fits_int32: t -> bool = "ml_z_fits_int32" [@@noalloc] -(** Whether the argument fits in an [int32]. *) +(** Whether the argument fits in a signed [int32]. *) external fits_int64: t -> bool = "ml_z_fits_int64" [@@noalloc] -(** Whether the argument fits in an [int64]. *) +(** Whether the argument fits in a signed [int64]. *) external fits_nativeint: t -> bool = "ml_z_fits_nativeint" [@@noalloc] -(** Whether the argument fits in a [nativeint]. *) +(** Whether the argument fits in a signed [nativeint]. *) (** {1 Printing} *) From 8fb3e11a8264b070d1c4220de6ca0f5340bf18c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antoine=20Min=C3=A9?= Date: Fri, 14 Jan 2022 20:41:08 +0100 Subject: [PATCH 13/49] minor typos & doc fixes --- Changes | 4 ++-- z.mli | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Changes b/Changes index a7f17cd..68bcf8c 100644 --- a/Changes +++ b/Changes @@ -3,8 +3,8 @@ Release 1.12 (2021-03-03) - PR #94: remove source preprocessing and simplify configuration [Xavier Leroy] - PR #93: fix parallel build [Guillaume Melquiond] - PR #92: fix benchmark for subtraction [Guillaume Melquiond] -- require OCaml 4.04 or later [Xavier Leroy] -- add CI testing on macOS [Xavier Leroy] +- Require OCaml 4.04 or later [Xavier Leroy] +- Add CI testing on macOS [Xavier Leroy] Release 1.11 (2020-11-09) - Fixes #72, #75, #78: multiple fixes for of_string, support for underscores [hhugo] diff --git a/z.mli b/z.mli index fa8f95a..b558284 100644 --- a/z.mli +++ b/z.mli @@ -617,9 +617,10 @@ external size: t -> int = "ml_z_size" [@@noalloc] external extract: t -> int -> int -> t = "ml_z_extract" (** [extract a off len] returns a nonnegative number corresponding to bits - [off] to [off]+[len]-1 of [b]. + [off] to [off]+[len]-1 of [a]. Negative [a] are considered in infinite-length 2's complement representation. + Raises an [Invalid_argument] if [off] is strictly negative, or if [len] is negative or null. *) val signed_extract: t -> int -> int -> t @@ -628,6 +629,7 @@ val signed_extract: t -> int -> int -> t (that is, bit [off + len - 1] of [a]). The result is between [- 2{^[len]-1}] (included) and [2{^[len]-1}] (excluded), and equal to [extract a off len] modulo [2{^len}]. + Raises an [Invalid_argument] if [off] is strictly negative, or if [len] is negative or null. *) external to_bits: t -> string = "ml_z_to_bits" From 7965fa90c41a2b3b1e5507fb129330932a2d8002 Mon Sep 17 00:00:00 2001 From: ayb Date: Sat, 15 Jan 2022 09:55:19 +0100 Subject: [PATCH 14/49] Fixed a typo in the README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 7c2a5c9..62029fd 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ arbitrary-precision integers. The module is simply named `Z`. Its interface is similar to that of the `Int32`, `Int64` and `Nativeint` modules from the OCaml standard -library, with some additional functions. See the file `z.mlip` for +library, with some additional functions. See the file `z.mli` for documentation. The implementation uses GMP (the GNU Multiple Precision arithmetic From 5c934fdef07223d5d266e70f3687925baa8c5611 Mon Sep 17 00:00:00 2001 From: David Allsopp Date: Fri, 21 Jan 2022 15:02:59 +0000 Subject: [PATCH 15/49] ocamldoc is not a required tool --- configure | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure b/configure index 585a002..569f30c 100755 --- a/configure +++ b/configure @@ -198,7 +198,7 @@ searchbinreq $ocaml searchbinreq $ocamlc searchbinreq $ocamldep searchbinreq $ocamlmklib -searchbinreq $ocamldoc +searchbin $ocamldoc if test -n "$CC"; then searchbinreq "$CC" From 8dcc91240f42d2bebcd025381ed10ea11d45ce98 Mon Sep 17 00:00:00 2001 From: David Allsopp Date: Fri, 21 Jan 2022 15:06:43 +0000 Subject: [PATCH 16/49] Report error if make doc run without ocamldoc --- configure | 4 +++- project.mak | 4 ++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/configure b/configure index 569f30c..4f93e2a 100755 --- a/configure +++ b/configure @@ -198,7 +198,9 @@ searchbinreq $ocaml searchbinreq $ocamlc searchbinreq $ocamldep searchbinreq $ocamlmklib -searchbin $ocamldoc +if searchbin $ocamldoc; then + ocamldoc='' +fi if test -n "$CC"; then searchbinreq "$CC" diff --git a/project.mak b/project.mak index 511f851..82a5aba 100644 --- a/project.mak +++ b/project.mak @@ -86,8 +86,12 @@ zarith_top.cma: zarith_top.cmo $(OCAMLC) $(DEBUG) -o $@ -a $< doc: $(MLISRC) +ifneq ($(OCAMLDOC),) mkdir -p html $(OCAMLDOC) -html -d html -charset utf8 $+ +else + $(error ocamldoc is required to build the documentation) +endif zarith_version.ml: META (echo "let"; grep "version" META | head -1) > zarith_version.ml From 26d4a0fb54f0c3c8c8079d1e882d43cbe2f7ba3b Mon Sep 17 00:00:00 2001 From: Simmo Saan Date: Fri, 21 Jan 2022 18:58:02 +0200 Subject: [PATCH 17/49] Fix Z_mlgmpidl for mlgmpidl >= 1.2 This includes all mlgmpidl versions on opam. --- z_mlgmpidl.ml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/z_mlgmpidl.ml b/z_mlgmpidl.ml index 023d731..429426c 100644 --- a/z_mlgmpidl.ml +++ b/z_mlgmpidl.ml @@ -28,10 +28,10 @@ let mpz_of_z x = r let z_of_mpzf x = - z_of_mpz (Mpzf.mpz x) + z_of_mpz (Mpzf._mpz x) let mpzf_of_z x = - Mpzf.mpzf (mpz_of_z x) + Mpzf._mpzf (mpz_of_z x) let q_of_mpq x = let n,d = Mpz.init (), Mpz.init () in @@ -43,7 +43,7 @@ let mpq_of_q x = Mpq.of_mpz2 (mpz_of_z x.Q.num) (mpz_of_z x.Q.den) let q_of_mpqf x = - q_of_mpq (Mpqf.mpq x) + q_of_mpq (Mpqf._mpq x) let mpqf_of_q x = - Mpqf.mpqf (mpq_of_q x) + Mpqf._mpqf (mpq_of_q x) From b7ffd9d1324e5c719dd47d244acab36140460b62 Mon Sep 17 00:00:00 2001 From: Issam Maghni Date: Sun, 13 Feb 2022 01:13:28 -0500 Subject: [PATCH 18/49] shell: test -a|o is not POSIX Recent versions of POSIX mark the syntax -a and -o as obsolescent. See https://pubs.opengroup.org/onlinepubs/9699919799/utilities/test.html Same as ocaml/ocaml#11005 --- configure | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/configure b/configure index 585a002..96e8f55 100755 --- a/configure +++ b/configure @@ -116,7 +116,7 @@ searchbin() echo_n "binary $1: " case "$1" in /*|./*|../*) - if test -f "$1" -a -x "$1" + if test -f "$1" && test -x "$1" then echo "found"; return 1 else echo "not found"; return 0 fi;; @@ -125,7 +125,7 @@ searchbin() for i in $PATH do if test -z "$i"; then i='.'; fi - if test -f $i/$1 -a -x $i/$1; then echo "found in $i"; unset IFS; return 1; fi + if test -f $i/$1 && test -x $i/$1; then echo "found in $i"; unset IFS; return 1; fi done echo "not found" unset IFS @@ -265,7 +265,7 @@ fi # installation method searchbin ocamlfind -if test $? -eq 1 -a $ocamlfind != "no"; then +if test $? -eq 1 && test $ocamlfind != "no"; then instmeth='findlib' if test "$installdir" = "auto" then installdir=`ocamlfind printconf destdir`; fi @@ -296,7 +296,7 @@ fi # check GMP, MPIR -if test "$gmp" = 'gmp' -o "$gmp" = 'auto'; then +if test "$gmp" = 'gmp' || test "$gmp" = 'auto'; then checkinc gmp.h if test $? -eq 1; then checklib gmp @@ -307,7 +307,7 @@ if test "$gmp" = 'gmp' -o "$gmp" = 'auto'; then fi fi fi -if test "$gmp" = 'mpir' -o "$gmp" = 'auto'; then +if test "$gmp" = 'mpir' || test "$gmp" = 'auto'; then checkinc mpir.h if test $? -eq 1; then checklib mpir From a5989b09a64a22e5507f60a02dddc46979012674 Mon Sep 17 00:00:00 2001 From: Pau Ruiz Safont Date: Wed, 16 Feb 2022 14:28:44 +0000 Subject: [PATCH 19/49] Add license to opam metadata Saw this was missing when looking at upstream packages used in the xapi project. The metadata for the versions published in opam-repository could be changed as well, as I don't see the license having changed. --- zarith.opam | 1 + 1 file changed, 1 insertion(+) diff --git a/zarith.opam b/zarith.opam index b299715..2c406c9 100644 --- a/zarith.opam +++ b/zarith.opam @@ -9,6 +9,7 @@ authors: [ homepage: "https://github.com/ocaml/Zarith" bug-reports: "https://github.com/ocaml/Zarith/issues" dev-repo: "git+https://github.com/ocaml/Zarith.git" +license: "LGPL-2.0-only WITH OCaml-LGPL-linking-exception" build: [ ["./configure"] {os != "openbsd" & os != "freebsd" & os != "macos"} [ From c65e82e32e0abf4dd38f3373804cc6e9523ea40b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antoine=20Min=C3=A9?= Date: Thu, 3 Mar 2022 16:20:38 +0100 Subject: [PATCH 20/49] extract: cosmetic fixes + tests --- caml_z.c | 22 ++++++++++++---------- tests/Makefile | 4 ++++ tests/tst_extract.ml | 35 +++++++++++++++++++++++++++++++++++ z.ml | 9 ++++++--- 4 files changed, 57 insertions(+), 13 deletions(-) create mode 100644 tests/tst_extract.ml diff --git a/caml_z.c b/caml_z.c index 0fd2353..f088960 100644 --- a/caml_z.c +++ b/caml_z.c @@ -911,29 +911,31 @@ CAMLprim value ml_z_extract_small(value arg, value off, value len) mp_size_t c1, c2, csz, i; mp_limb_t cr; Z_ARG(arg); - o = Long_val(off); - l = Long_val(len); + o = (uintnat)Long_val(off); + l = (uintnat)Long_val(len); c1 = o / Z_LIMB_BITS; c2 = o % Z_LIMB_BITS; csz = size_arg - c1; if (csz > 0) { if (c2) { x = ptr_arg[c1] >> c2; - if ((o + l > (intnat)Z_LIMB_BITS) && (csz > 1)) + if ((c2 + l > (intnat)Z_LIMB_BITS) && (csz > 1)) x |= (ptr_arg[c1 + 1] << (Z_LIMB_BITS - c2)); - } else x = ptr_arg[c1]; - } else x = (intnat)0; + } + else x = ptr_arg[c1]; + } + else x = 0; if (sign_arg) { x = ~x; if (csz > 0) { /* carry (cr=0 if all shifted-out bits are 0) */ cr = ptr_arg[c1] & (((intnat)1 << c2) - 1); for (i = 0; !cr && i < c1; i++) - cr = ptr_arg[i]; - if (!cr) x += 1; + cr = ptr_arg[i]; + if (!cr) x ++; } } - x &= (((intnat)1 << l) - 1); + x &= ((intnat)1 << l) - 1; return Val_long(x); } @@ -947,8 +949,8 @@ CAMLprim value ml_z_extract(value arg, value off, value len) Z_DECL(arg); Z_MARK_OP; MAYBE_UNUSED x; - o = Long_val(off); - l = Long_val(len); + o = (uintnat)Long_val(off); + l = (uintnat)Long_val(len); Z_MARK_SLOW; { CAMLparam1(arg); diff --git a/tests/Makefile b/tests/Makefile index 3e02207..5232366 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -42,6 +42,10 @@ bench:: timings.exe bench:: pi.exe @echo "Benchmarking pi"; time ./pi.exe 10000 > /dev/null +test:: tst_extract.exe + @echo "Testing extract..." + @if ./tst_extract.exe; then echo "tst_extract: passed"; else echo "tst_extract: FAILED"; exit 2; fi + tofloat.exe: tofloat.ml setround.o ../zarith.cmxa ocamlopt -I .. -ccopt "-L.." zarith.cmxa -o tofloat.exe \ setround.o tofloat.ml diff --git a/tests/tst_extract.ml b/tests/tst_extract.ml new file mode 100644 index 0000000..a687f6c --- /dev/null +++ b/tests/tst_extract.ml @@ -0,0 +1,35 @@ +module I = Z + +let pr ch x = + output_string ch (I.to_string x); + flush ch + +let chk_extract x o l = + let expected = + I.logand (I.shift_right x o) (I.pred (I.shift_left (I.of_int 1) l)) + and actual = + I.extract x o l in + if actual <> expected then (Printf.printf "extract %a %d %d = %a found %a\n" pr x o l pr expected pr actual; failwith "test failed") + +let doit () = + let max = 128 in + for l = 1 to max do + if l mod 16 == 0 then Printf.printf "%i/%i\n%!" l max; + for o = 0 to 256 do + for n = 0 to 256 do + let x = I.shift_left I.one n in + chk_extract x o l; + chk_extract (I.mul x x) o l; + chk_extract (I.mul x (I.mul x x)) o l; + chk_extract (I.succ x) o l; + chk_extract (I.pred x) o l; + chk_extract (I.neg (I.mul x x)) o l; + chk_extract (I.neg (I.mul x (I.mul x x))) o l; + chk_extract (I.neg x) o l; + chk_extract (I.neg (I.succ x)) o l; + chk_extract (I.neg (I.pred x)) o l; + done + done + done + +let _ = doit () diff --git a/z.ml b/z.ml index 47fbecc..ac8fc80 100644 --- a/z.ml +++ b/z.ml @@ -326,9 +326,7 @@ external c_extract_small: t -> int -> int -> t = "ml_z_extract_small" [@@noalloc] external c_extract: t -> int -> int -> t = "ml_z_extract" -let extract x o l = - if o < 0 then invalid_arg "Z.signed_extract: negative bit offset"; - if l < 1 then invalid_arg "Z.signed_extract: nonpositive bit length"; +let extract_internal x o l = if is_small_int x then (* Fast path *) let o = if o >= Sys.int_size then Sys.int_size - 1 else o in @@ -349,6 +347,11 @@ let extract x o l = else c_extract x o l +let extract x o l = + if o < 0 then invalid_arg "Z.extract: negative bit offset"; + if l < 1 then invalid_arg "Z.extract: nonpositive bit length"; + extract_internal x o l + let signed_extract x o l = if o < 0 then invalid_arg "Z.signed_extract: negative bit offset"; if l < 1 then invalid_arg "Z.signed_extract: nonpositive bit length"; From 658440a2392f27215fca6615b20a6065b0812bc0 Mon Sep 17 00:00:00 2001 From: Marshall Roch Date: Tue, 26 Apr 2022 13:05:29 -0400 Subject: [PATCH 21/49] pass LDFLAGS to ocamlmklib via -ldopt `ocamlmklib` supports some but not all linker flags. we have some `LDFLAGS` that are not supported by `ocamlmklib`, so they need to be passed via `-ldopt`. this PR prepends `-ldopt` to each word in `LIBS` (which is set to `LDFLAGS` in ./configure). --- project.mak | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/project.mak b/project.mak index 82a5aba..fe6dc67 100644 --- a/project.mak +++ b/project.mak @@ -52,6 +52,7 @@ endif DEBUG = -g OCAMLFLAGS += $(DEBUG) -I +compiler-libs OCAMLOPTFLAGS += $(DEBUG) -I +compiler-libs +LDFLAGS = $(foreach flag, $(LIBS), -ldopt $(flag)) ifeq ($(HASDYNLINK),yes) TOBUILD += zarith.cmxs @@ -71,16 +72,16 @@ tests: make -C tests test zarith.cma: $(MLSRC:%.ml=%.cmo) - $(OCAMLMKLIB) $(DEBUG) -failsafe -o zarith $+ $(LIBS) + $(OCAMLMKLIB) $(DEBUG) -failsafe -o zarith $+ $(LDFLAGS) zarith.cmxa: $(MLSRC:%.ml=%.cmx) - $(OCAMLMKLIB) $(DEBUG) -failsafe -o zarith $+ $(LIBS) + $(OCAMLMKLIB) $(DEBUG) -failsafe -o zarith $+ $(LDFLAGS) zarith.cmxs: zarith.cmxa libzarith.$(LIBSUFFIX) $(OCAMLOPT) -shared -o $@ -I . zarith.cmxa -linkall libzarith.$(LIBSUFFIX): $(CSRC:%.c=%.$(OBJSUFFIX)) - $(OCAMLMKLIB) $(DEBUG) -failsafe -o zarith $+ $(LIBS) + $(OCAMLMKLIB) $(DEBUG) -failsafe -o zarith $+ $(LDFLAGS) zarith_top.cma: zarith_top.cmo $(OCAMLC) $(DEBUG) -o $@ -a $< From 7b1dda4d92e26e91f0dbc901fa54603cf872376b Mon Sep 17 00:00:00 2001 From: Marshall Roch Date: Tue, 3 May 2022 16:32:19 -0400 Subject: [PATCH 22/49] use single quoted -ldopt --- project.mak | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/project.mak b/project.mak index fe6dc67..e857946 100644 --- a/project.mak +++ b/project.mak @@ -52,7 +52,6 @@ endif DEBUG = -g OCAMLFLAGS += $(DEBUG) -I +compiler-libs OCAMLOPTFLAGS += $(DEBUG) -I +compiler-libs -LDFLAGS = $(foreach flag, $(LIBS), -ldopt $(flag)) ifeq ($(HASDYNLINK),yes) TOBUILD += zarith.cmxs @@ -72,16 +71,16 @@ tests: make -C tests test zarith.cma: $(MLSRC:%.ml=%.cmo) - $(OCAMLMKLIB) $(DEBUG) -failsafe -o zarith $+ $(LDFLAGS) + $(OCAMLMKLIB) $(DEBUG) -failsafe -o zarith $+ -ldopt "$(LIBS)" zarith.cmxa: $(MLSRC:%.ml=%.cmx) - $(OCAMLMKLIB) $(DEBUG) -failsafe -o zarith $+ $(LDFLAGS) + $(OCAMLMKLIB) $(DEBUG) -failsafe -o zarith $+ -ldopt "$(LIBS)" zarith.cmxs: zarith.cmxa libzarith.$(LIBSUFFIX) $(OCAMLOPT) -shared -o $@ -I . zarith.cmxa -linkall libzarith.$(LIBSUFFIX): $(CSRC:%.c=%.$(OBJSUFFIX)) - $(OCAMLMKLIB) $(DEBUG) -failsafe -o zarith $+ $(LDFLAGS) + $(OCAMLMKLIB) $(DEBUG) -failsafe -o zarith $+ -ldopt "$(LIBS)" zarith_top.cma: zarith_top.cmo $(OCAMLC) $(DEBUG) -o $@ -a $< From 940509ca1b02a9180a7cdbe752c0cd2d863712b6 Mon Sep 17 00:00:00 2001 From: Xavier Leroy Date: Tue, 1 Mar 2022 15:08:32 +0100 Subject: [PATCH 23/49] Add functions to generate integers pseudo-randomly --- tests/Makefile | 4 +++ tests/chi2.ml | 43 ++++++++++++++++++++++++++ tests/zq.ml | 23 ++++++++++++++ tests/zq.output32 | 5 +++ tests/zq.output64 | 5 +++ z.ml | 79 +++++++++++++++++++++++++++++++++++++++++++++++ z.mli | 57 ++++++++++++++++++++++++++++++++++ 7 files changed, 216 insertions(+) create mode 100644 tests/chi2.ml diff --git a/tests/Makefile b/tests/Makefile index 3e02207..db46680 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -36,6 +36,10 @@ test:: ofstring.exe @echo "Testing ofstring..." @./ofstring.exe +test:: chi2.exe + @echo "Testing random number generation..." + @./chi2.exe + bench:: timings.exe ./timings.exe diff --git a/tests/chi2.ml b/tests/chi2.ml new file mode 100644 index 0000000..1241828 --- /dev/null +++ b/tests/chi2.ml @@ -0,0 +1,43 @@ +(* Accumulate [n] samples from function [f] and check the chi-square. + Only the low 8 bits of the result of [f] are sampled. *) + +let chisquare n f = + let r = 256 in + let freq = Array.make r 0 in + for i = 0 to n - 1 do + let t = Z.to_int (Z.logand (f ()) (Z.of_int 0xFF)) in + freq.(t) <- freq.(t) + 1 + done; + let expected = float n /. float r in + let t = + Array.fold_left + (fun s x -> let d = float x -. expected in d *. d +. s) + 0.0 freq in + let chi2 = t /. expected in + let degfree = float r -. 1.0 in + (* The degree of freedom is high, so we approximate as a normal + distribution with mean equal to degfree and variance 2 * degfree. + Four sigmas correspond to a 99.9968% confidence interval. + (Without the approximation, the confidence interval seems to be 99.986%.) + *) + chi2 <= degfree +. 4.0 *. sqrt (2.0 *. degfree) + +let test name f = + if not (chisquare 100_000 f) + then Printf.printf "%s: suspicious result\n%!" name + +let _ = + test "random_bits 15 (bits 0-7)" + (fun () -> Z.random_bits 15); + test "random_bits 32 (bits 12-19)" + (fun () -> Z.(shift_right (random_bits 32) 12)); + test "random_bits 31 (bits 23-30)" + (fun () -> Z.(shift_right (random_bits 31) 23)); + test "random_int 2^30 (bits 0-7)" + (fun () -> Z.(random_int (shift_left one 30))); + test "random_int 2^30 (bits 21-28)" + (fun () -> Z.(shift_right (random_int (shift_left one 30)) 21)); + test "random_int (256 * p) / p" + (let p = Z.of_string "35742549198872617291353508656626642567" in + let bound = Z.shift_left p 8 in + fun () -> Z.(div (random_int bound) p)) diff --git a/tests/zq.ml b/tests/zq.ml index d600605..2a0bc16 100644 --- a/tests/zq.ml +++ b/tests/zq.ml @@ -150,6 +150,17 @@ let chk_testbit x = then Printf.printf "(passed)\n" else Printf.printf "(FAILED)\n" +let pr_byte = + let state = ref 0 in + fun () -> + state := (!state * 65793 + 4282663) land 0xFF_FF_FF; + !state lsr 16 + +let pr_bytes buf pos len = + for i = pos to pos + len - 1 do + Bytes.set_uint8 buf i (pr_byte ()) + done + let test_Z() = Printf.printf "0\n = %a\n" pr I.zero; Printf.printf "1\n = %a\n" pr I.one; @@ -746,6 +757,18 @@ let test_Z() = I.shift_left (I.of_int 9999) 77; I.neg (I.shift_left (I.of_int 123456) 64); ]; + + Printf.printf "random_bits 45 = %a\n" + pr (I.random_bits_gen ~fill:pr_bytes 45); + Printf.printf "random_bits 45 = %a\n" + pr (I.random_bits_gen ~fill:pr_bytes 45); + Printf.printf "random_bits 12 = %a\n" + pr (I.random_bits_gen ~fill:pr_bytes 12); + Printf.printf "random_int 123456 = %a\n" + pr (I.random_int_gen ~fill:pr_bytes (I.of_int 123456)); + Printf.printf "random_int 9999999 = %a\n" + pr (I.random_int_gen ~fill:pr_bytes (I.of_int 9999999)); + () diff --git a/tests/zq.output32 b/tests/zq.output32 index 376984a..16c42d5 100644 --- a/tests/zq.output32 +++ b/tests/zq.output32 @@ -1113,6 +1113,11 @@ numbits / trailing_zeros 1 (passed) numbits / trailing_zeros -42 (passed) numbits / trailing_zeros 1511006158790834639735881728 (passed) numbits / trailing_zeros -2277361236363886404304896 (passed) +random_bits 45 = 25076743995969 +random_bits 45 = 33510880286625 +random_bits 12 = 1263 +random_int 123456 = 103797 +random_int 9999999 = 1089068 - 0 = 0 - 1 = -1 - -1 = 1 diff --git a/tests/zq.output64 b/tests/zq.output64 index 5c09e7e..2404fab 100644 --- a/tests/zq.output64 +++ b/tests/zq.output64 @@ -1113,6 +1113,11 @@ numbits / trailing_zeros 1 (passed) numbits / trailing_zeros -42 (passed) numbits / trailing_zeros 1511006158790834639735881728 (passed) numbits / trailing_zeros -2277361236363886404304896 (passed) +random_bits 45 = 25076743995969 +random_bits 45 = 33510880286625 +random_bits 12 = 1263 +random_int 123456 = 103797 +random_int 9999999 = 1089068 - 0 = 0 - 1 = -1 - -1 = 1 diff --git a/z.ml b/z.ml index 4de0d56..da5cd11 100644 --- a/z.ml +++ b/z.ml @@ -373,12 +373,91 @@ let to_float x = end end +(* Formatting *) + let print x = print_string (to_string x) let output chan x = output_string chan (to_string x) let sprint () x = to_string x let bprint b x = Buffer.add_string b (to_string x) let pp_print f x = Format.pp_print_string f (to_string x) +(* Pseudo-random generation *) + +let rec raw_bits_random ?(rng: Random.State.t option) nbits = + let rec raw_bits accu n = + if n >= nbits then (accu, n) else begin + let i = + match rng with + | None -> Random.bits () + | Some r -> Random.State.bits r in + raw_bits (logxor (shift_left accu 30) (of_int i)) (n + 30) + end in + raw_bits zero 0 + +let raw_bits_from_bytes ~(fill: bytes -> int -> int -> unit) nbits = + let nbytes = (nbits + 7) / 8 in + let buf = Bytes.create nbytes in + fill buf 0 nbytes; + (of_bits (Bytes.to_string buf), nbytes * 8) + +let random_bits_aux (f: int -> t * int) nbits = + if nbits < 0 then invalid_arg "random_bits: number of bits must be >= 0"; + let (x, _) = f nbits in + extract x 0 nbits + +let random_int_aux (f: int -> t * int) bound = + if sign bound <= 0 then invalid_arg "random_int: bound must be > 0"; + let nbits1 = log2up bound in + let rec draw () = + (* The minimal number of random bits we need to draw is nbits1. + However, in the worst case, rejection (as described below) + will occur with probability almost 1/2. So, we draw more bits + than strictly necessary to make rejection much less likely. + With 4 extra bits, the probability of rejection is less than + 1/32. *) + let (x, nbits) = f (nbits1 + 4) in + let y = rem x bound in + (* We divide the range of x, namely [0 .. 2^nbits), into + - k intervals of width bound : + [0 .. bound) [bound.. 2*bound) .. [(k-1) * bound.. k * bound) + - the remaining numbers: [k * bound .. 2^nbits) + + k is chosen as large as possible: k = floor (2^nbits / bound). + + If x falls within the k intervals of width bound, + y = x mod bound is evenly distributed in [0 .. bound) + and we can use it as the pseudo-random number. + If x falls within the [k * bound .. 2^nbits) interval, + y = x mod bound may not be evenly distributed; + we reject and draw again. + + We can decide efficiently whether to reject, as follows. + Write 2^nbits = k * bound + r and x = q * bound + y, + with r and y in [0 .. bound). + If x - y <= 2^nbits - bound, then + q * bound = x - y <= 2^nbits - bound < 2^nbits - r = k * bound, + hence q < k and we can accept x. + Otherwise, + q * bound = x - y > 2^nbits - bound = (k - 1) * bound + r + hence q >= k and we must reject x. + *) + if leq (sub x y) (sub (shift_left one nbits) bound) + then y + else draw () in + draw () + +let random_int ?rng bound = + random_int_aux (raw_bits_random ?rng) bound +let random_bits ?rng nbits = + random_bits_aux (raw_bits_random ?rng) nbits + +let random_int_gen ~fill bound = + random_int_aux (raw_bits_from_bytes ~fill) bound +let random_bits_gen ~fill nbits = + random_bits_aux (raw_bits_from_bytes ~fill) nbits + +(* Infix notations *) + let (~-) = neg let (~+) x = x let (+) = add diff --git a/z.mli b/z.mli index b558284..5fc5282 100644 --- a/z.mli +++ b/z.mli @@ -649,6 +649,63 @@ external of_bits: string -> t = "ml_z_of_bits" trailing zeros in s. *) +(** {1 Pseudo-random number generation} *) + +val random_int: ?rng: Random.State.t -> t -> t +(** [random_int bound] returns a random integer between 0 (inclusive) + and [bound] (exclusive). [bound] must be greater than 0. + + The source of randomness is the {!Random} module from the OCaml + standard library. The optional [rng] argument specifies which + random state to use. If omitted, the default random state for the + {!Random} module is used. + + Random numbers produced by this function are not cryptographically + strong and must not be used in cryptographic or high-security + contexts. See {!Z.random_int_gen} for an alternative. +*) + +val random_bits: ?rng: Random.State.t -> int -> t +(** [random_bits nbits] returns a random integer between 0 (inclusive) + and [2{^nbits}] (exclusive). [nbits] must be nonnegative. + This is a more efficient special case of {!Z.random_int} when the + bound is a power of two. + + The source of randomness and the [rng] optional argument are as + described in {!Z.random_int}. + + Random numbers produced by this function are not cryptographically + strong and must not be used in cryptographic or high-security + contexts. See {!Z.random_bits_gen} for an alternative. +*) + +val random_int_gen: fill: (bytes -> int -> int -> unit) -> t -> t +(** [random_int_gen ~fill bound] returns a random integer between 0 (inclusive) + and [bound] (exclusive). [bound] must be greater than 0. + + The [fill] parameter is the source of randomness. It is called + as [fill buf pos len], and is responsible for drawing [len] random + bytes and writing them to offsets [pos] to [pos + len - 1] of + the byte array [buf]. + + Example of use where [/dev/random] provides the random bytes: +<< + In_channel.with_open_bin "/dev/random" + (fun ic -> Z.random_int_gen ~fill:(really_input ic) bound) +>> + Example of use where the Cryptokit library provides the random bytes: +<< + Z.random_int_gen ~fill:Cryptokit.Random.secure_rng#bytes bound +>> +*) + +val random_bits_gen: fill: (bytes -> int -> int -> unit) -> int -> t +(** [random_bits_gen ~fill nbits] returns a random integer between 0 (inclusive) + and [2{^nbits}] (exclusive). [nbits] must be nonnegative. + This is a more efficient special case of {!Z.random_int_gen} when the + bound is a power of two. The [fill] parameter is as described in + {!Z.random_int_gen}. +*) (** {1 Prefix and infix operators} *) From 53934607cb822a3a4a55be1456edab0016dab738 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antoine=20Min=C3=A9?= Date: Mon, 2 Jan 2023 12:24:23 +0100 Subject: [PATCH 24/49] tentative fix after merging #124 broke some builds --- project.mak | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/project.mak b/project.mak index e857946..a35cb39 100644 --- a/project.mak +++ b/project.mak @@ -62,6 +62,8 @@ TOINSTALL += $(CMIDOC) OCAMLFLAGS += -bin-annot endif +MKLIBLDFLAGS = $(foreach flag, $(LDFLAGS), -ldopt $(flag)) + # build targets ############### @@ -71,16 +73,16 @@ tests: make -C tests test zarith.cma: $(MLSRC:%.ml=%.cmo) - $(OCAMLMKLIB) $(DEBUG) -failsafe -o zarith $+ -ldopt "$(LIBS)" + $(OCAMLMKLIB) $(DEBUG) -failsafe -o zarith $+ $(LIBS) $(MKLIBLDFLAGS) zarith.cmxa: $(MLSRC:%.ml=%.cmx) - $(OCAMLMKLIB) $(DEBUG) -failsafe -o zarith $+ -ldopt "$(LIBS)" + $(OCAMLMKLIB) $(DEBUG) -failsafe -o zarith $+ $(LIBS) $(MKLIBLDFLAGS) zarith.cmxs: zarith.cmxa libzarith.$(LIBSUFFIX) $(OCAMLOPT) -shared -o $@ -I . zarith.cmxa -linkall libzarith.$(LIBSUFFIX): $(CSRC:%.c=%.$(OBJSUFFIX)) - $(OCAMLMKLIB) $(DEBUG) -failsafe -o zarith $+ -ldopt "$(LIBS)" + $(OCAMLMKLIB) $(DEBUG) -failsafe -o zarith $+ $(LIBS) $(MKLIBLDFLAGS) zarith_top.cma: zarith_top.cmo $(OCAMLC) $(DEBUG) -o $@ -a $< From 891c0b0c24b66030d1ef1dfa504d5aa0b42eaba3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antoine=20Min=C3=A9?= Date: Mon, 2 Jan 2023 12:36:06 +0100 Subject: [PATCH 25/49] fix typos (issue #127) --- q.mli | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/q.mli b/q.mli index 6ee4127..c3ee8f0 100644 --- a/q.mli +++ b/q.mli @@ -136,10 +136,10 @@ val max: t -> t -> t (** Returns the largest of its arguments. *) val leq: t -> t -> bool -(** Less than or equal. [leq undef undef] resturns false. *) +(** Less than or equal. [leq undef undef] returns false. *) val geq: t -> t -> bool -(** Greater than or equal. [leq undef undef] resturns false. *) +(** Greater than or equal. [leq undef undef] returns false. *) val lt: t -> t -> bool (** Less than (not equal). *) From 14f140d16149350cd96ca1c4b6946ae4a85a5e40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antoine=20Min=C3=A9?= Date: Tue, 3 Jan 2023 11:51:41 +0100 Subject: [PATCH 26/49] better separation of user-supplied linker flags (LDFLAGS) and libraries added by configure --- configure | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/configure b/configure index adb302a..0865c22 100755 --- a/configure +++ b/configure @@ -29,7 +29,8 @@ ocamlmklib='ocamlmklib' ocamldep='ocamldep' ocamldoc='ocamldoc' ccinc="$CPPFLAGS" -cclib="$LDFLAGS" +ldflags="$LDFLAGS" +cclib='' ccdef='' mlflags="$OCAMLFLAGS" mloptflags="$OCAMLOPTFLAGS" @@ -161,7 +162,7 @@ checklib() rm -f tmp.c tmp.out echo "int main() { return 1; }" >> tmp.c r=1 - $cc $ccopt $cclib tmp.c -l$1 -o tmp.out >/dev/null 2>/dev/null || r=0 + $cc $ccopt $ldflags $cclib tmp.c -l$1 -o tmp.out >/dev/null 2>/dev/null || r=0 if test ! -x tmp.out; then r=0; fi rm -f tmp.c tmp.o tmp.out if test $r -eq 0; then echo "not found"; else echo "found"; fi @@ -367,6 +368,7 @@ OCAMLOPTFLAGS=$mloptflags OCAMLINC=$mlinc CFLAGS=$ccinc $ccdef $ccopt LIBS=$cclib +LDFLAGS=$ldflags INSTALLDIR=$installdir INSTALL=install OCAMLFIND=ocamlfind @@ -390,6 +392,7 @@ detected configuration: dynamic linking: $hasdynlink defines: $ccdef libraries: $cclib + linker options: $ldflags C options: $ccopt installation path: $installdir installation method $instmeth From e67bccbe69362866d2ce182bb4ba8a1a458cd387 Mon Sep 17 00:00:00 2001 From: Alfredo Tupone Date: Sun, 29 Jan 2023 19:01:42 +0100 Subject: [PATCH 27/49] Call `ocamldep` without the `-native` option (#129) It looks like `-native` causes `ocamldep` to produce insufficient dependencies for a bytecode + native build like we need to do. See log at https://881129.bugs.gentoo.org/attachment.cgi?id=832035 --- project.mak | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/project.mak b/project.mak index a35cb39..8dc72c9 100644 --- a/project.mak +++ b/project.mak @@ -151,7 +151,7 @@ clean: make -C tests clean depend: $(AUTOGEN) - $(OCAMLDEP) -native $(OCAMLINC) $(MLSRC) $(MLISRC) > depend + $(OCAMLDEP) $(OCAMLINC) $(MLSRC) $(MLISRC) > depend include depend From 0083fbd986570a2906461a83ab68b6823466fcc7 Mon Sep 17 00:00:00 2001 From: Anil Madhavapeddy Date: Sun, 26 Feb 2023 16:59:03 +0000 Subject: [PATCH 28/49] update config.guess to latest upstream version from autotools (#131) This allows linux-riscv targets to be detected successfully. --- config.guess | 1837 ++++++++++++++++++++++++++++---------------------- 1 file changed, 1044 insertions(+), 793 deletions(-) diff --git a/config.guess b/config.guess index e1f34b5..69188da 100644 --- a/config.guess +++ b/config.guess @@ -1,14 +1,14 @@ #! /bin/sh # Attempt to guess a canonical system name. -# Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, -# 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 -# Free Software Foundation, Inc. +# Copyright 1992-2023 Free Software Foundation, Inc. -timestamp='2010-09-24' +# shellcheck disable=SC2006,SC2268 # see below for rationale + +timestamp='2023-01-01' # This file is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or +# the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, but @@ -17,26 +17,30 @@ timestamp='2010-09-24' # General Public License for more details. # # You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA -# 02110-1301, USA. +# along with this program; if not, see . # # As a special exception to the GNU General Public License, if you # distribute this file as part of a program that contains a # configuration script generated by Autoconf, you may include it under -# the same distribution terms that you use for the rest of that program. - - -# Originally written by Per Bothner. Please send patches (context -# diff format) to and include a ChangeLog -# entry. +# the same distribution terms that you use for the rest of that +# program. This Exception is an additional permission under section 7 +# of the GNU General Public License, version 3 ("GPLv3"). # -# This script attempts to guess a canonical system name similar to -# config.sub. If it succeeds, it prints the system name on stdout, and -# exits with 0. Otherwise, it exits with 1. +# Originally written by Per Bothner; maintained since 2000 by Ben Elliston. # # You can get the latest version of this script from: -# http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.guess;hb=HEAD +# https://git.savannah.gnu.org/cgit/config.git/plain/config.guess +# +# Please send patches to . + + +# The "shellcheck disable" line above the timestamp inhibits complaints +# about features and limitations of the classic Bourne shell that were +# superseded or lifted in POSIX. However, this script identifies a wide +# variety of pre-POSIX systems that do not have POSIX shells at all, and +# even some reasonably current systems (Solaris 10 as case-in-point) still +# have a pre-POSIX /bin/sh. + me=`echo "$0" | sed -e 's,.*/,,'` @@ -45,7 +49,7 @@ Usage: $0 [OPTION] Output the configuration name of the system \`$me' is run on. -Operation modes: +Options: -h, --help print this help, then exit -t, --time-stamp print date of last modification, then exit -v, --version print version number, then exit @@ -56,9 +60,7 @@ version="\ GNU config.guess ($timestamp) Originally written by Per Bothner. -Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, -2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 Free -Software Foundation, Inc. +Copyright 1992-2023 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE." @@ -92,7 +94,8 @@ if test $# != 0; then exit 1 fi -trap 'exit 1' HUP INT TERM +# Just in case it came from the environment. +GUESS= # CC_FOR_BUILD -- compiler used by this script. Note that the use of a # compiler to aid in system detection is discouraged as it requires @@ -104,71 +107,93 @@ trap 'exit 1' HUP INT TERM # Portable tmp directory creation inspired by the Autoconf team. -set_cc_for_build=' -trap "exitcode=\$?; (rm -f \$tmpfiles 2>/dev/null; rmdir \$tmp 2>/dev/null) && exit \$exitcode" 0 ; -trap "rm -f \$tmpfiles 2>/dev/null; rmdir \$tmp 2>/dev/null; exit 1" HUP INT PIPE TERM ; -: ${TMPDIR=/tmp} ; - { tmp=`(umask 077 && mktemp -d "$TMPDIR/cgXXXXXX") 2>/dev/null` && test -n "$tmp" && test -d "$tmp" ; } || - { test -n "$RANDOM" && tmp=$TMPDIR/cg$$-$RANDOM && (umask 077 && mkdir $tmp) ; } || - { tmp=$TMPDIR/cg-$$ && (umask 077 && mkdir $tmp) && echo "Warning: creating insecure temp directory" >&2 ; } || - { echo "$me: cannot create a temporary directory in $TMPDIR" >&2 ; exit 1 ; } ; -dummy=$tmp/dummy ; -tmpfiles="$dummy.c $dummy.o $dummy.rel $dummy" ; -case $CC_FOR_BUILD,$HOST_CC,$CC in - ,,) echo "int x;" > $dummy.c ; - for c in cc gcc c89 c99 ; do - if ($c -c -o $dummy.o $dummy.c) >/dev/null 2>&1 ; then - CC_FOR_BUILD="$c"; break ; - fi ; - done ; - if test x"$CC_FOR_BUILD" = x ; then - CC_FOR_BUILD=no_compiler_found ; - fi - ;; - ,,*) CC_FOR_BUILD=$CC ;; - ,*,*) CC_FOR_BUILD=$HOST_CC ;; -esac ; set_cc_for_build= ;' +tmp= +# shellcheck disable=SC2172 +trap 'test -z "$tmp" || rm -fr "$tmp"' 0 1 2 13 15 + +set_cc_for_build() { + # prevent multiple calls if $tmp is already set + test "$tmp" && return 0 + : "${TMPDIR=/tmp}" + # shellcheck disable=SC2039,SC3028 + { tmp=`(umask 077 && mktemp -d "$TMPDIR/cgXXXXXX") 2>/dev/null` && test -n "$tmp" && test -d "$tmp" ; } || + { test -n "$RANDOM" && tmp=$TMPDIR/cg$$-$RANDOM && (umask 077 && mkdir "$tmp" 2>/dev/null) ; } || + { tmp=$TMPDIR/cg-$$ && (umask 077 && mkdir "$tmp" 2>/dev/null) && echo "Warning: creating insecure temp directory" >&2 ; } || + { echo "$me: cannot create a temporary directory in $TMPDIR" >&2 ; exit 1 ; } + dummy=$tmp/dummy + case ${CC_FOR_BUILD-},${HOST_CC-},${CC-} in + ,,) echo "int x;" > "$dummy.c" + for driver in cc gcc c89 c99 ; do + if ($driver -c -o "$dummy.o" "$dummy.c") >/dev/null 2>&1 ; then + CC_FOR_BUILD=$driver + break + fi + done + if test x"$CC_FOR_BUILD" = x ; then + CC_FOR_BUILD=no_compiler_found + fi + ;; + ,,*) CC_FOR_BUILD=$CC ;; + ,*,*) CC_FOR_BUILD=$HOST_CC ;; + esac +} # This is needed to find uname on a Pyramid OSx when run in the BSD universe. # (ghazi@noc.rutgers.edu 1994-08-24) -if (test -f /.attbin/uname) >/dev/null 2>&1 ; then +if test -f /.attbin/uname ; then PATH=$PATH:/.attbin ; export PATH fi UNAME_MACHINE=`(uname -m) 2>/dev/null` || UNAME_MACHINE=unknown UNAME_RELEASE=`(uname -r) 2>/dev/null` || UNAME_RELEASE=unknown -UNAME_SYSTEM=`(uname -s) 2>/dev/null` || UNAME_SYSTEM=unknown +UNAME_SYSTEM=`(uname -s) 2>/dev/null` || UNAME_SYSTEM=unknown UNAME_VERSION=`(uname -v) 2>/dev/null` || UNAME_VERSION=unknown -case "${UNAME_SYSTEM}" in -Linux|GNU/*) - eval $set_cc_for_build - cat <<-EOF > $dummy.c +case $UNAME_SYSTEM in +Linux|GNU|GNU/*) + LIBC=unknown + + set_cc_for_build + cat <<-EOF > "$dummy.c" #include - #ifdef __UCLIBC__ - # ifdef __UCLIBC_CONFIG_VERSION__ - LIBC=uclibc __UCLIBC_CONFIG_VERSION__ - # else + #if defined(__UCLIBC__) LIBC=uclibc - # endif - #else - # ifdef __dietlibc__ + #elif defined(__dietlibc__) LIBC=dietlibc - # else + #elif defined(__GLIBC__) LIBC=gnu - # endif + #else + #include + /* First heuristic to detect musl libc. */ + #ifdef __DEFINED_va_list + LIBC=musl + #endif #endif EOF - eval `$CC_FOR_BUILD -E $dummy.c 2>/dev/null | grep '^LIBC'` + cc_set_libc=`$CC_FOR_BUILD -E "$dummy.c" 2>/dev/null | grep '^LIBC' | sed 's, ,,g'` + eval "$cc_set_libc" + + # Second heuristic to detect musl libc. + if [ "$LIBC" = unknown ] && + command -v ldd >/dev/null && + ldd --version 2>&1 | grep -q ^musl; then + LIBC=musl + fi + + # If the system lacks a compiler, then just pick glibc. + # We could probably try harder. + if [ "$LIBC" = unknown ]; then + LIBC=gnu + fi ;; esac # Note: order is significant - the case branches are not exclusive. -case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in +case $UNAME_MACHINE:$UNAME_SYSTEM:$UNAME_RELEASE:$UNAME_VERSION in *:NetBSD:*:*) # NetBSD (nbsd) targets should (where applicable) match one or - # more of the tupples: *-*-netbsdelf*, *-*-netbsdaout*, + # more of the tuples: *-*-netbsdelf*, *-*-netbsdaout*, # *-*-netbsdecoff* and *-*-netbsd*. For targets that recently # switched to ELF, *-*-netbsd* would select the old # object file format. This provides both forward @@ -177,22 +202,32 @@ case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in # # Note: NetBSD doesn't particularly care about the vendor # portion of the name. We always set it to "unknown". - sysctl="sysctl -n hw.machine_arch" - UNAME_MACHINE_ARCH=`(/sbin/$sysctl 2>/dev/null || \ - /usr/sbin/$sysctl 2>/dev/null || echo unknown)` - case "${UNAME_MACHINE_ARCH}" in + UNAME_MACHINE_ARCH=`(uname -p 2>/dev/null || \ + /sbin/sysctl -n hw.machine_arch 2>/dev/null || \ + /usr/sbin/sysctl -n hw.machine_arch 2>/dev/null || \ + echo unknown)` + case $UNAME_MACHINE_ARCH in + aarch64eb) machine=aarch64_be-unknown ;; armeb) machine=armeb-unknown ;; arm*) machine=arm-unknown ;; sh3el) machine=shl-unknown ;; sh3eb) machine=sh-unknown ;; sh5el) machine=sh5le-unknown ;; - *) machine=${UNAME_MACHINE_ARCH}-unknown ;; + earmv*) + arch=`echo "$UNAME_MACHINE_ARCH" | sed -e 's,^e\(armv[0-9]\).*$,\1,'` + endian=`echo "$UNAME_MACHINE_ARCH" | sed -ne 's,^.*\(eb\)$,\1,p'` + machine=${arch}${endian}-unknown + ;; + *) machine=$UNAME_MACHINE_ARCH-unknown ;; esac # The Operating System including object format, if it has switched - # to ELF recently, or will in the future. - case "${UNAME_MACHINE_ARCH}" in + # to ELF recently (or will in the future) and ABI. + case $UNAME_MACHINE_ARCH in + earm*) + os=netbsdelf + ;; arm*|i386|m68k|ns32k|sh3*|sparc|vax) - eval $set_cc_for_build + set_cc_for_build if echo __ELF__ | $CC_FOR_BUILD -E - 2>/dev/null \ | grep -q __ELF__ then @@ -204,7 +239,14 @@ case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in fi ;; *) - os=netbsd + os=netbsd + ;; + esac + # Determine ABI tags. + case $UNAME_MACHINE_ARCH in + earm*) + expr='s/^earmv[0-9]/-eabi/;s/eb$//' + abi=`echo "$UNAME_MACHINE_ARCH" | sed -e "$expr"` ;; esac # The OS release @@ -212,42 +254,74 @@ case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in # thus, need a distinct triplet. However, they do not need # kernel version information, so it can be replaced with a # suitable tag, in the style of linux-gnu. - case "${UNAME_VERSION}" in + case $UNAME_VERSION in Debian*) release='-gnu' ;; *) - release=`echo ${UNAME_RELEASE}|sed -e 's/[-_].*/\./'` + release=`echo "$UNAME_RELEASE" | sed -e 's/[-_].*//' | cut -d. -f1,2` ;; esac # Since CPU_TYPE-MANUFACTURER-KERNEL-OPERATING_SYSTEM: # contains redundant information, the shorter form: # CPU_TYPE-MANUFACTURER-OPERATING_SYSTEM is used. - echo "${machine}-${os}${release}" - exit ;; + GUESS=$machine-${os}${release}${abi-} + ;; + *:Bitrig:*:*) + UNAME_MACHINE_ARCH=`arch | sed 's/Bitrig.//'` + GUESS=$UNAME_MACHINE_ARCH-unknown-bitrig$UNAME_RELEASE + ;; *:OpenBSD:*:*) UNAME_MACHINE_ARCH=`arch | sed 's/OpenBSD.//'` - echo ${UNAME_MACHINE_ARCH}-unknown-openbsd${UNAME_RELEASE} - exit ;; + GUESS=$UNAME_MACHINE_ARCH-unknown-openbsd$UNAME_RELEASE + ;; + *:SecBSD:*:*) + UNAME_MACHINE_ARCH=`arch | sed 's/SecBSD.//'` + GUESS=$UNAME_MACHINE_ARCH-unknown-secbsd$UNAME_RELEASE + ;; + *:LibertyBSD:*:*) + UNAME_MACHINE_ARCH=`arch | sed 's/^.*BSD\.//'` + GUESS=$UNAME_MACHINE_ARCH-unknown-libertybsd$UNAME_RELEASE + ;; + *:MidnightBSD:*:*) + GUESS=$UNAME_MACHINE-unknown-midnightbsd$UNAME_RELEASE + ;; *:ekkoBSD:*:*) - echo ${UNAME_MACHINE}-unknown-ekkobsd${UNAME_RELEASE} - exit ;; + GUESS=$UNAME_MACHINE-unknown-ekkobsd$UNAME_RELEASE + ;; *:SolidBSD:*:*) - echo ${UNAME_MACHINE}-unknown-solidbsd${UNAME_RELEASE} - exit ;; + GUESS=$UNAME_MACHINE-unknown-solidbsd$UNAME_RELEASE + ;; + *:OS108:*:*) + GUESS=$UNAME_MACHINE-unknown-os108_$UNAME_RELEASE + ;; macppc:MirBSD:*:*) - echo powerpc-unknown-mirbsd${UNAME_RELEASE} - exit ;; + GUESS=powerpc-unknown-mirbsd$UNAME_RELEASE + ;; *:MirBSD:*:*) - echo ${UNAME_MACHINE}-unknown-mirbsd${UNAME_RELEASE} - exit ;; + GUESS=$UNAME_MACHINE-unknown-mirbsd$UNAME_RELEASE + ;; + *:Sortix:*:*) + GUESS=$UNAME_MACHINE-unknown-sortix + ;; + *:Twizzler:*:*) + GUESS=$UNAME_MACHINE-unknown-twizzler + ;; + *:Redox:*:*) + GUESS=$UNAME_MACHINE-unknown-redox + ;; + mips:OSF1:*.*) + GUESS=mips-dec-osf1 + ;; alpha:OSF1:*:*) + # Reset EXIT trap before exiting to avoid spurious non-zero exit code. + trap '' 0 case $UNAME_RELEASE in *4.0) UNAME_RELEASE=`/usr/sbin/sizer -v | awk '{print $3}'` ;; *5.*) - UNAME_RELEASE=`/usr/sbin/sizer -v | awk '{print $4}'` + UNAME_RELEASE=`/usr/sbin/sizer -v | awk '{print $4}'` ;; esac # According to Compaq, /usr/sbin/psrinfo has been available on @@ -255,160 +329,158 @@ case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in # covers most systems running today. This code pipes the CPU # types through head -n 1, so we only detect the type of CPU 0. ALPHA_CPU_TYPE=`/usr/sbin/psrinfo -v | sed -n -e 's/^ The alpha \(.*\) processor.*$/\1/p' | head -n 1` - case "$ALPHA_CPU_TYPE" in + case $ALPHA_CPU_TYPE in "EV4 (21064)") - UNAME_MACHINE="alpha" ;; + UNAME_MACHINE=alpha ;; "EV4.5 (21064)") - UNAME_MACHINE="alpha" ;; + UNAME_MACHINE=alpha ;; "LCA4 (21066/21068)") - UNAME_MACHINE="alpha" ;; + UNAME_MACHINE=alpha ;; "EV5 (21164)") - UNAME_MACHINE="alphaev5" ;; + UNAME_MACHINE=alphaev5 ;; "EV5.6 (21164A)") - UNAME_MACHINE="alphaev56" ;; + UNAME_MACHINE=alphaev56 ;; "EV5.6 (21164PC)") - UNAME_MACHINE="alphapca56" ;; + UNAME_MACHINE=alphapca56 ;; "EV5.7 (21164PC)") - UNAME_MACHINE="alphapca57" ;; + UNAME_MACHINE=alphapca57 ;; "EV6 (21264)") - UNAME_MACHINE="alphaev6" ;; + UNAME_MACHINE=alphaev6 ;; "EV6.7 (21264A)") - UNAME_MACHINE="alphaev67" ;; + UNAME_MACHINE=alphaev67 ;; "EV6.8CB (21264C)") - UNAME_MACHINE="alphaev68" ;; + UNAME_MACHINE=alphaev68 ;; "EV6.8AL (21264B)") - UNAME_MACHINE="alphaev68" ;; + UNAME_MACHINE=alphaev68 ;; "EV6.8CX (21264D)") - UNAME_MACHINE="alphaev68" ;; + UNAME_MACHINE=alphaev68 ;; "EV6.9A (21264/EV69A)") - UNAME_MACHINE="alphaev69" ;; + UNAME_MACHINE=alphaev69 ;; "EV7 (21364)") - UNAME_MACHINE="alphaev7" ;; + UNAME_MACHINE=alphaev7 ;; "EV7.9 (21364A)") - UNAME_MACHINE="alphaev79" ;; + UNAME_MACHINE=alphaev79 ;; esac # A Pn.n version is a patched version. # A Vn.n version is a released version. # A Tn.n version is a released field test version. # A Xn.n version is an unreleased experimental baselevel. # 1.2 uses "1.2" for uname -r. - echo ${UNAME_MACHINE}-dec-osf`echo ${UNAME_RELEASE} | sed -e 's/^[PVTX]//' | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'` - exit ;; - Alpha\ *:Windows_NT*:*) - # How do we know it's Interix rather than the generic POSIX subsystem? - # Should we change UNAME_MACHINE based on the output of uname instead - # of the specific Alpha model? - echo alpha-pc-interix - exit ;; - 21064:Windows_NT:50:3) - echo alpha-dec-winnt3.5 - exit ;; + OSF_REL=`echo "$UNAME_RELEASE" | sed -e 's/^[PVTX]//' | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz` + GUESS=$UNAME_MACHINE-dec-osf$OSF_REL + ;; Amiga*:UNIX_System_V:4.0:*) - echo m68k-unknown-sysv4 - exit ;; + GUESS=m68k-unknown-sysv4 + ;; *:[Aa]miga[Oo][Ss]:*:*) - echo ${UNAME_MACHINE}-unknown-amigaos - exit ;; + GUESS=$UNAME_MACHINE-unknown-amigaos + ;; *:[Mm]orph[Oo][Ss]:*:*) - echo ${UNAME_MACHINE}-unknown-morphos - exit ;; + GUESS=$UNAME_MACHINE-unknown-morphos + ;; *:OS/390:*:*) - echo i370-ibm-openedition - exit ;; + GUESS=i370-ibm-openedition + ;; *:z/VM:*:*) - echo s390-ibm-zvmoe - exit ;; + GUESS=s390-ibm-zvmoe + ;; *:OS400:*:*) - echo powerpc-ibm-os400 - exit ;; + GUESS=powerpc-ibm-os400 + ;; arm:RISC*:1.[012]*:*|arm:riscix:1.[012]*:*) - echo arm-acorn-riscix${UNAME_RELEASE} - exit ;; - arm:riscos:*:*|arm:RISCOS:*:*) - echo arm-unknown-riscos - exit ;; + GUESS=arm-acorn-riscix$UNAME_RELEASE + ;; + arm*:riscos:*:*|arm*:RISCOS:*:*) + GUESS=arm-unknown-riscos + ;; SR2?01:HI-UX/MPP:*:* | SR8000:HI-UX/MPP:*:*) - echo hppa1.1-hitachi-hiuxmpp - exit ;; + GUESS=hppa1.1-hitachi-hiuxmpp + ;; Pyramid*:OSx*:*:* | MIS*:OSx*:*:* | MIS*:SMP_DC-OSx*:*:*) # akee@wpdis03.wpafb.af.mil (Earle F. Ake) contributed MIS and NILE. - if test "`(/bin/universe) 2>/dev/null`" = att ; then - echo pyramid-pyramid-sysv3 - else - echo pyramid-pyramid-bsd - fi - exit ;; + case `(/bin/universe) 2>/dev/null` in + att) GUESS=pyramid-pyramid-sysv3 ;; + *) GUESS=pyramid-pyramid-bsd ;; + esac + ;; NILE*:*:*:dcosx) - echo pyramid-pyramid-svr4 - exit ;; + GUESS=pyramid-pyramid-svr4 + ;; DRS?6000:unix:4.0:6*) - echo sparc-icl-nx6 - exit ;; + GUESS=sparc-icl-nx6 + ;; DRS?6000:UNIX_SV:4.2*:7* | DRS?6000:isis:4.2*:7*) case `/usr/bin/uname -p` in - sparc) echo sparc-icl-nx7; exit ;; - esac ;; + sparc) GUESS=sparc-icl-nx7 ;; + esac + ;; s390x:SunOS:*:*) - echo ${UNAME_MACHINE}-ibm-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` - exit ;; + SUN_REL=`echo "$UNAME_RELEASE" | sed -e 's/[^.]*//'` + GUESS=$UNAME_MACHINE-ibm-solaris2$SUN_REL + ;; sun4H:SunOS:5.*:*) - echo sparc-hal-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` - exit ;; + SUN_REL=`echo "$UNAME_RELEASE" | sed -e 's/[^.]*//'` + GUESS=sparc-hal-solaris2$SUN_REL + ;; sun4*:SunOS:5.*:* | tadpole*:SunOS:5.*:*) - echo sparc-sun-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` - exit ;; + SUN_REL=`echo "$UNAME_RELEASE" | sed -e 's/[^.]*//'` + GUESS=sparc-sun-solaris2$SUN_REL + ;; i86pc:AuroraUX:5.*:* | i86xen:AuroraUX:5.*:*) - echo i386-pc-auroraux${UNAME_RELEASE} - exit ;; + GUESS=i386-pc-auroraux$UNAME_RELEASE + ;; i86pc:SunOS:5.*:* | i86xen:SunOS:5.*:*) - eval $set_cc_for_build - SUN_ARCH="i386" + set_cc_for_build + SUN_ARCH=i386 # If there is a compiler, see if it is configured for 64-bit objects. # Note that the Sun cc does not turn __LP64__ into 1 like gcc does. # This test works for both compilers. - if [ "$CC_FOR_BUILD" != 'no_compiler_found' ]; then + if test "$CC_FOR_BUILD" != no_compiler_found; then if (echo '#ifdef __amd64'; echo IS_64BIT_ARCH; echo '#endif') | \ - (CCOPTS= $CC_FOR_BUILD -E - 2>/dev/null) | \ + (CCOPTS="" $CC_FOR_BUILD -m64 -E - 2>/dev/null) | \ grep IS_64BIT_ARCH >/dev/null then - SUN_ARCH="x86_64" + SUN_ARCH=x86_64 fi fi - echo ${SUN_ARCH}-pc-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` - exit ;; + SUN_REL=`echo "$UNAME_RELEASE" | sed -e 's/[^.]*//'` + GUESS=$SUN_ARCH-pc-solaris2$SUN_REL + ;; sun4*:SunOS:6*:*) # According to config.sub, this is the proper way to canonicalize # SunOS6. Hard to guess exactly what SunOS6 will be like, but # it's likely to be more like Solaris than SunOS4. - echo sparc-sun-solaris3`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` - exit ;; + SUN_REL=`echo "$UNAME_RELEASE" | sed -e 's/[^.]*//'` + GUESS=sparc-sun-solaris3$SUN_REL + ;; sun4*:SunOS:*:*) - case "`/usr/bin/arch -k`" in + case `/usr/bin/arch -k` in Series*|S4*) UNAME_RELEASE=`uname -v` ;; esac # Japanese Language versions have a version number like `4.1.3-JL'. - echo sparc-sun-sunos`echo ${UNAME_RELEASE}|sed -e 's/-/_/'` - exit ;; + SUN_REL=`echo "$UNAME_RELEASE" | sed -e 's/-/_/'` + GUESS=sparc-sun-sunos$SUN_REL + ;; sun3*:SunOS:*:*) - echo m68k-sun-sunos${UNAME_RELEASE} - exit ;; + GUESS=m68k-sun-sunos$UNAME_RELEASE + ;; sun*:*:4.2BSD:*) UNAME_RELEASE=`(sed 1q /etc/motd | awk '{print substr($5,1,3)}') 2>/dev/null` - test "x${UNAME_RELEASE}" = "x" && UNAME_RELEASE=3 - case "`/bin/arch`" in + test "x$UNAME_RELEASE" = x && UNAME_RELEASE=3 + case `/bin/arch` in sun3) - echo m68k-sun-sunos${UNAME_RELEASE} + GUESS=m68k-sun-sunos$UNAME_RELEASE ;; sun4) - echo sparc-sun-sunos${UNAME_RELEASE} + GUESS=sparc-sun-sunos$UNAME_RELEASE ;; esac - exit ;; + ;; aushp:SunOS:*:*) - echo sparc-auspex-sunos${UNAME_RELEASE} - exit ;; + GUESS=sparc-auspex-sunos$UNAME_RELEASE + ;; # The situation for MiNT is a little confusing. The machine name # can be virtually everything (everything which is not # "atarist" or "atariste" at least should have a processor @@ -418,44 +490,44 @@ case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in # MiNT. But MiNT is downward compatible to TOS, so this should # be no problem. atarist[e]:*MiNT:*:* | atarist[e]:*mint:*:* | atarist[e]:*TOS:*:*) - echo m68k-atari-mint${UNAME_RELEASE} - exit ;; + GUESS=m68k-atari-mint$UNAME_RELEASE + ;; atari*:*MiNT:*:* | atari*:*mint:*:* | atarist[e]:*TOS:*:*) - echo m68k-atari-mint${UNAME_RELEASE} - exit ;; + GUESS=m68k-atari-mint$UNAME_RELEASE + ;; *falcon*:*MiNT:*:* | *falcon*:*mint:*:* | *falcon*:*TOS:*:*) - echo m68k-atari-mint${UNAME_RELEASE} - exit ;; + GUESS=m68k-atari-mint$UNAME_RELEASE + ;; milan*:*MiNT:*:* | milan*:*mint:*:* | *milan*:*TOS:*:*) - echo m68k-milan-mint${UNAME_RELEASE} - exit ;; + GUESS=m68k-milan-mint$UNAME_RELEASE + ;; hades*:*MiNT:*:* | hades*:*mint:*:* | *hades*:*TOS:*:*) - echo m68k-hades-mint${UNAME_RELEASE} - exit ;; + GUESS=m68k-hades-mint$UNAME_RELEASE + ;; *:*MiNT:*:* | *:*mint:*:* | *:*TOS:*:*) - echo m68k-unknown-mint${UNAME_RELEASE} - exit ;; + GUESS=m68k-unknown-mint$UNAME_RELEASE + ;; m68k:machten:*:*) - echo m68k-apple-machten${UNAME_RELEASE} - exit ;; + GUESS=m68k-apple-machten$UNAME_RELEASE + ;; powerpc:machten:*:*) - echo powerpc-apple-machten${UNAME_RELEASE} - exit ;; + GUESS=powerpc-apple-machten$UNAME_RELEASE + ;; RISC*:Mach:*:*) - echo mips-dec-mach_bsd4.3 - exit ;; + GUESS=mips-dec-mach_bsd4.3 + ;; RISC*:ULTRIX:*:*) - echo mips-dec-ultrix${UNAME_RELEASE} - exit ;; + GUESS=mips-dec-ultrix$UNAME_RELEASE + ;; VAX*:ULTRIX*:*:*) - echo vax-dec-ultrix${UNAME_RELEASE} - exit ;; + GUESS=vax-dec-ultrix$UNAME_RELEASE + ;; 2020:CLIX:*:* | 2430:CLIX:*:*) - echo clipper-intergraph-clix${UNAME_RELEASE} - exit ;; + GUESS=clipper-intergraph-clix$UNAME_RELEASE + ;; mips:*:*:UMIPS | mips:*:*:RISCos) - eval $set_cc_for_build - sed 's/^ //' << EOF >$dummy.c + set_cc_for_build + sed 's/^ //' << EOF > "$dummy.c" #ifdef __cplusplus #include /* for printf() prototype */ int main (int argc, char *argv[]) { @@ -464,95 +536,96 @@ case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in #endif #if defined (host_mips) && defined (MIPSEB) #if defined (SYSTYPE_SYSV) - printf ("mips-mips-riscos%ssysv\n", argv[1]); exit (0); + printf ("mips-mips-riscos%ssysv\\n", argv[1]); exit (0); #endif #if defined (SYSTYPE_SVR4) - printf ("mips-mips-riscos%ssvr4\n", argv[1]); exit (0); + printf ("mips-mips-riscos%ssvr4\\n", argv[1]); exit (0); #endif #if defined (SYSTYPE_BSD43) || defined(SYSTYPE_BSD) - printf ("mips-mips-riscos%sbsd\n", argv[1]); exit (0); + printf ("mips-mips-riscos%sbsd\\n", argv[1]); exit (0); #endif #endif exit (-1); } EOF - $CC_FOR_BUILD -o $dummy $dummy.c && - dummyarg=`echo "${UNAME_RELEASE}" | sed -n 's/\([0-9]*\).*/\1/p'` && - SYSTEM_NAME=`$dummy $dummyarg` && + $CC_FOR_BUILD -o "$dummy" "$dummy.c" && + dummyarg=`echo "$UNAME_RELEASE" | sed -n 's/\([0-9]*\).*/\1/p'` && + SYSTEM_NAME=`"$dummy" "$dummyarg"` && { echo "$SYSTEM_NAME"; exit; } - echo mips-mips-riscos${UNAME_RELEASE} - exit ;; + GUESS=mips-mips-riscos$UNAME_RELEASE + ;; Motorola:PowerMAX_OS:*:*) - echo powerpc-motorola-powermax - exit ;; + GUESS=powerpc-motorola-powermax + ;; Motorola:*:4.3:PL8-*) - echo powerpc-harris-powermax - exit ;; + GUESS=powerpc-harris-powermax + ;; Night_Hawk:*:*:PowerMAX_OS | Synergy:PowerMAX_OS:*:*) - echo powerpc-harris-powermax - exit ;; + GUESS=powerpc-harris-powermax + ;; Night_Hawk:Power_UNIX:*:*) - echo powerpc-harris-powerunix - exit ;; + GUESS=powerpc-harris-powerunix + ;; m88k:CX/UX:7*:*) - echo m88k-harris-cxux7 - exit ;; + GUESS=m88k-harris-cxux7 + ;; m88k:*:4*:R4*) - echo m88k-motorola-sysv4 - exit ;; + GUESS=m88k-motorola-sysv4 + ;; m88k:*:3*:R3*) - echo m88k-motorola-sysv3 - exit ;; + GUESS=m88k-motorola-sysv3 + ;; AViiON:dgux:*:*) - # DG/UX returns AViiON for all architectures - UNAME_PROCESSOR=`/usr/bin/uname -p` - if [ $UNAME_PROCESSOR = mc88100 ] || [ $UNAME_PROCESSOR = mc88110 ] + # DG/UX returns AViiON for all architectures + UNAME_PROCESSOR=`/usr/bin/uname -p` + if test "$UNAME_PROCESSOR" = mc88100 || test "$UNAME_PROCESSOR" = mc88110 then - if [ ${TARGET_BINARY_INTERFACE}x = m88kdguxelfx ] || \ - [ ${TARGET_BINARY_INTERFACE}x = x ] + if test "$TARGET_BINARY_INTERFACE"x = m88kdguxelfx || \ + test "$TARGET_BINARY_INTERFACE"x = x then - echo m88k-dg-dgux${UNAME_RELEASE} + GUESS=m88k-dg-dgux$UNAME_RELEASE else - echo m88k-dg-dguxbcs${UNAME_RELEASE} + GUESS=m88k-dg-dguxbcs$UNAME_RELEASE fi else - echo i586-dg-dgux${UNAME_RELEASE} + GUESS=i586-dg-dgux$UNAME_RELEASE fi - exit ;; + ;; M88*:DolphinOS:*:*) # DolphinOS (SVR3) - echo m88k-dolphin-sysv3 - exit ;; + GUESS=m88k-dolphin-sysv3 + ;; M88*:*:R3*:*) # Delta 88k system running SVR3 - echo m88k-motorola-sysv3 - exit ;; + GUESS=m88k-motorola-sysv3 + ;; XD88*:*:*:*) # Tektronix XD88 system running UTekV (SVR3) - echo m88k-tektronix-sysv3 - exit ;; + GUESS=m88k-tektronix-sysv3 + ;; Tek43[0-9][0-9]:UTek:*:*) # Tektronix 4300 system running UTek (BSD) - echo m68k-tektronix-bsd - exit ;; + GUESS=m68k-tektronix-bsd + ;; *:IRIX*:*:*) - echo mips-sgi-irix`echo ${UNAME_RELEASE}|sed -e 's/-/_/g'` - exit ;; + IRIX_REL=`echo "$UNAME_RELEASE" | sed -e 's/-/_/g'` + GUESS=mips-sgi-irix$IRIX_REL + ;; ????????:AIX?:[12].1:2) # AIX 2.2.1 or AIX 2.1.1 is RT/PC AIX. - echo romp-ibm-aix # uname -m gives an 8 hex-code CPU id - exit ;; # Note that: echo "'`uname -s`'" gives 'AIX ' + GUESS=romp-ibm-aix # uname -m gives an 8 hex-code CPU id + ;; # Note that: echo "'`uname -s`'" gives 'AIX ' i*86:AIX:*:*) - echo i386-ibm-aix - exit ;; + GUESS=i386-ibm-aix + ;; ia64:AIX:*:*) - if [ -x /usr/bin/oslevel ] ; then + if test -x /usr/bin/oslevel ; then IBM_REV=`/usr/bin/oslevel` else - IBM_REV=${UNAME_VERSION}.${UNAME_RELEASE} + IBM_REV=$UNAME_VERSION.$UNAME_RELEASE fi - echo ${UNAME_MACHINE}-ibm-aix${IBM_REV} - exit ;; + GUESS=$UNAME_MACHINE-ibm-aix$IBM_REV + ;; *:AIX:2:3) if grep bos325 /usr/include/stdio.h >/dev/null 2>&1; then - eval $set_cc_for_build - sed 's/^ //' << EOF >$dummy.c + set_cc_for_build + sed 's/^ //' << EOF > "$dummy.c" #include main() @@ -563,115 +636,116 @@ EOF exit(0); } EOF - if $CC_FOR_BUILD -o $dummy $dummy.c && SYSTEM_NAME=`$dummy` + if $CC_FOR_BUILD -o "$dummy" "$dummy.c" && SYSTEM_NAME=`"$dummy"` then - echo "$SYSTEM_NAME" + GUESS=$SYSTEM_NAME else - echo rs6000-ibm-aix3.2.5 + GUESS=rs6000-ibm-aix3.2.5 fi elif grep bos324 /usr/include/stdio.h >/dev/null 2>&1; then - echo rs6000-ibm-aix3.2.4 + GUESS=rs6000-ibm-aix3.2.4 else - echo rs6000-ibm-aix3.2 + GUESS=rs6000-ibm-aix3.2 fi - exit ;; + ;; *:AIX:*:[4567]) IBM_CPU_ID=`/usr/sbin/lsdev -C -c processor -S available | sed 1q | awk '{ print $1 }'` - if /usr/sbin/lsattr -El ${IBM_CPU_ID} | grep ' POWER' >/dev/null 2>&1; then + if /usr/sbin/lsattr -El "$IBM_CPU_ID" | grep ' POWER' >/dev/null 2>&1; then IBM_ARCH=rs6000 else IBM_ARCH=powerpc fi - if [ -x /usr/bin/oslevel ] ; then - IBM_REV=`/usr/bin/oslevel` + if test -x /usr/bin/lslpp ; then + IBM_REV=`/usr/bin/lslpp -Lqc bos.rte.libc | \ + awk -F: '{ print $3 }' | sed s/[0-9]*$/0/` else - IBM_REV=${UNAME_VERSION}.${UNAME_RELEASE} + IBM_REV=$UNAME_VERSION.$UNAME_RELEASE fi - echo ${IBM_ARCH}-ibm-aix${IBM_REV} - exit ;; + GUESS=$IBM_ARCH-ibm-aix$IBM_REV + ;; *:AIX:*:*) - echo rs6000-ibm-aix - exit ;; - ibmrt:4.4BSD:*|romp-ibm:BSD:*) - echo romp-ibm-bsd4.4 - exit ;; + GUESS=rs6000-ibm-aix + ;; + ibmrt:4.4BSD:*|romp-ibm:4.4BSD:*) + GUESS=romp-ibm-bsd4.4 + ;; ibmrt:*BSD:*|romp-ibm:BSD:*) # covers RT/PC BSD and - echo romp-ibm-bsd${UNAME_RELEASE} # 4.3 with uname added to - exit ;; # report: romp-ibm BSD 4.3 + GUESS=romp-ibm-bsd$UNAME_RELEASE # 4.3 with uname added to + ;; # report: romp-ibm BSD 4.3 *:BOSX:*:*) - echo rs6000-bull-bosx - exit ;; + GUESS=rs6000-bull-bosx + ;; DPX/2?00:B.O.S.:*:*) - echo m68k-bull-sysv3 - exit ;; + GUESS=m68k-bull-sysv3 + ;; 9000/[34]??:4.3bsd:1.*:*) - echo m68k-hp-bsd - exit ;; + GUESS=m68k-hp-bsd + ;; hp300:4.4BSD:*:* | 9000/[34]??:4.3bsd:2.*:*) - echo m68k-hp-bsd4.4 - exit ;; + GUESS=m68k-hp-bsd4.4 + ;; 9000/[34678]??:HP-UX:*:*) - HPUX_REV=`echo ${UNAME_RELEASE}|sed -e 's/[^.]*.[0B]*//'` - case "${UNAME_MACHINE}" in - 9000/31? ) HP_ARCH=m68000 ;; - 9000/[34]?? ) HP_ARCH=m68k ;; + HPUX_REV=`echo "$UNAME_RELEASE" | sed -e 's/[^.]*.[0B]*//'` + case $UNAME_MACHINE in + 9000/31?) HP_ARCH=m68000 ;; + 9000/[34]??) HP_ARCH=m68k ;; 9000/[678][0-9][0-9]) - if [ -x /usr/bin/getconf ]; then + if test -x /usr/bin/getconf; then sc_cpu_version=`/usr/bin/getconf SC_CPU_VERSION 2>/dev/null` - sc_kernel_bits=`/usr/bin/getconf SC_KERNEL_BITS 2>/dev/null` - case "${sc_cpu_version}" in - 523) HP_ARCH="hppa1.0" ;; # CPU_PA_RISC1_0 - 528) HP_ARCH="hppa1.1" ;; # CPU_PA_RISC1_1 - 532) # CPU_PA_RISC2_0 - case "${sc_kernel_bits}" in - 32) HP_ARCH="hppa2.0n" ;; - 64) HP_ARCH="hppa2.0w" ;; - '') HP_ARCH="hppa2.0" ;; # HP-UX 10.20 - esac ;; - esac + sc_kernel_bits=`/usr/bin/getconf SC_KERNEL_BITS 2>/dev/null` + case $sc_cpu_version in + 523) HP_ARCH=hppa1.0 ;; # CPU_PA_RISC1_0 + 528) HP_ARCH=hppa1.1 ;; # CPU_PA_RISC1_1 + 532) # CPU_PA_RISC2_0 + case $sc_kernel_bits in + 32) HP_ARCH=hppa2.0n ;; + 64) HP_ARCH=hppa2.0w ;; + '') HP_ARCH=hppa2.0 ;; # HP-UX 10.20 + esac ;; + esac fi - if [ "${HP_ARCH}" = "" ]; then - eval $set_cc_for_build - sed 's/^ //' << EOF >$dummy.c - - #define _HPUX_SOURCE - #include - #include - - int main () - { - #if defined(_SC_KERNEL_BITS) - long bits = sysconf(_SC_KERNEL_BITS); - #endif - long cpu = sysconf (_SC_CPU_VERSION); - - switch (cpu) - { - case CPU_PA_RISC1_0: puts ("hppa1.0"); break; - case CPU_PA_RISC1_1: puts ("hppa1.1"); break; - case CPU_PA_RISC2_0: - #if defined(_SC_KERNEL_BITS) - switch (bits) - { - case 64: puts ("hppa2.0w"); break; - case 32: puts ("hppa2.0n"); break; - default: puts ("hppa2.0"); break; - } break; - #else /* !defined(_SC_KERNEL_BITS) */ - puts ("hppa2.0"); break; - #endif - default: puts ("hppa1.0"); break; - } - exit (0); - } + if test "$HP_ARCH" = ""; then + set_cc_for_build + sed 's/^ //' << EOF > "$dummy.c" + + #define _HPUX_SOURCE + #include + #include + + int main () + { + #if defined(_SC_KERNEL_BITS) + long bits = sysconf(_SC_KERNEL_BITS); + #endif + long cpu = sysconf (_SC_CPU_VERSION); + + switch (cpu) + { + case CPU_PA_RISC1_0: puts ("hppa1.0"); break; + case CPU_PA_RISC1_1: puts ("hppa1.1"); break; + case CPU_PA_RISC2_0: + #if defined(_SC_KERNEL_BITS) + switch (bits) + { + case 64: puts ("hppa2.0w"); break; + case 32: puts ("hppa2.0n"); break; + default: puts ("hppa2.0"); break; + } break; + #else /* !defined(_SC_KERNEL_BITS) */ + puts ("hppa2.0"); break; + #endif + default: puts ("hppa1.0"); break; + } + exit (0); + } EOF - (CCOPTS= $CC_FOR_BUILD -o $dummy $dummy.c 2>/dev/null) && HP_ARCH=`$dummy` + (CCOPTS="" $CC_FOR_BUILD -o "$dummy" "$dummy.c" 2>/dev/null) && HP_ARCH=`"$dummy"` test -z "$HP_ARCH" && HP_ARCH=hppa fi ;; esac - if [ ${HP_ARCH} = "hppa2.0w" ] + if test "$HP_ARCH" = hppa2.0w then - eval $set_cc_for_build + set_cc_for_build # hppa2.0w-hp-hpux* has a 64-bit kernel and a compiler generating # 32-bit code. hppa64-hp-hpux* has the same kernel and a compiler @@ -682,23 +756,23 @@ EOF # $ CC_FOR_BUILD="cc +DA2.0w" ./config.guess # => hppa64-hp-hpux11.23 - if echo __LP64__ | (CCOPTS= $CC_FOR_BUILD -E - 2>/dev/null) | + if echo __LP64__ | (CCOPTS="" $CC_FOR_BUILD -E - 2>/dev/null) | grep -q __LP64__ then - HP_ARCH="hppa2.0w" + HP_ARCH=hppa2.0w else - HP_ARCH="hppa64" + HP_ARCH=hppa64 fi fi - echo ${HP_ARCH}-hp-hpux${HPUX_REV} - exit ;; + GUESS=$HP_ARCH-hp-hpux$HPUX_REV + ;; ia64:HP-UX:*:*) - HPUX_REV=`echo ${UNAME_RELEASE}|sed -e 's/[^.]*.[0B]*//'` - echo ia64-hp-hpux${HPUX_REV} - exit ;; + HPUX_REV=`echo "$UNAME_RELEASE" | sed -e 's/[^.]*.[0B]*//'` + GUESS=ia64-hp-hpux$HPUX_REV + ;; 3050*:HI-UX:*:*) - eval $set_cc_for_build - sed 's/^ //' << EOF >$dummy.c + set_cc_for_build + sed 's/^ //' << EOF > "$dummy.c" #include int main () @@ -723,333 +797,446 @@ EOF exit (0); } EOF - $CC_FOR_BUILD -o $dummy $dummy.c && SYSTEM_NAME=`$dummy` && + $CC_FOR_BUILD -o "$dummy" "$dummy.c" && SYSTEM_NAME=`"$dummy"` && { echo "$SYSTEM_NAME"; exit; } - echo unknown-hitachi-hiuxwe2 - exit ;; - 9000/7??:4.3bsd:*:* | 9000/8?[79]:4.3bsd:*:* ) - echo hppa1.1-hp-bsd - exit ;; + GUESS=unknown-hitachi-hiuxwe2 + ;; + 9000/7??:4.3bsd:*:* | 9000/8?[79]:4.3bsd:*:*) + GUESS=hppa1.1-hp-bsd + ;; 9000/8??:4.3bsd:*:*) - echo hppa1.0-hp-bsd - exit ;; + GUESS=hppa1.0-hp-bsd + ;; *9??*:MPE/iX:*:* | *3000*:MPE/iX:*:*) - echo hppa1.0-hp-mpeix - exit ;; - hp7??:OSF1:*:* | hp8?[79]:OSF1:*:* ) - echo hppa1.1-hp-osf - exit ;; + GUESS=hppa1.0-hp-mpeix + ;; + hp7??:OSF1:*:* | hp8?[79]:OSF1:*:*) + GUESS=hppa1.1-hp-osf + ;; hp8??:OSF1:*:*) - echo hppa1.0-hp-osf - exit ;; + GUESS=hppa1.0-hp-osf + ;; i*86:OSF1:*:*) - if [ -x /usr/sbin/sysversion ] ; then - echo ${UNAME_MACHINE}-unknown-osf1mk + if test -x /usr/sbin/sysversion ; then + GUESS=$UNAME_MACHINE-unknown-osf1mk else - echo ${UNAME_MACHINE}-unknown-osf1 + GUESS=$UNAME_MACHINE-unknown-osf1 fi - exit ;; + ;; parisc*:Lites*:*:*) - echo hppa1.1-hp-lites - exit ;; + GUESS=hppa1.1-hp-lites + ;; C1*:ConvexOS:*:* | convex:ConvexOS:C1*:*) - echo c1-convex-bsd - exit ;; + GUESS=c1-convex-bsd + ;; C2*:ConvexOS:*:* | convex:ConvexOS:C2*:*) if getsysinfo -f scalar_acc then echo c32-convex-bsd else echo c2-convex-bsd fi - exit ;; + exit ;; C34*:ConvexOS:*:* | convex:ConvexOS:C34*:*) - echo c34-convex-bsd - exit ;; + GUESS=c34-convex-bsd + ;; C38*:ConvexOS:*:* | convex:ConvexOS:C38*:*) - echo c38-convex-bsd - exit ;; + GUESS=c38-convex-bsd + ;; C4*:ConvexOS:*:* | convex:ConvexOS:C4*:*) - echo c4-convex-bsd - exit ;; + GUESS=c4-convex-bsd + ;; CRAY*Y-MP:*:*:*) - echo ymp-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' - exit ;; + CRAY_REL=`echo "$UNAME_RELEASE" | sed -e 's/\.[^.]*$/.X/'` + GUESS=ymp-cray-unicos$CRAY_REL + ;; CRAY*[A-Z]90:*:*:*) - echo ${UNAME_MACHINE}-cray-unicos${UNAME_RELEASE} \ + echo "$UNAME_MACHINE"-cray-unicos"$UNAME_RELEASE" \ | sed -e 's/CRAY.*\([A-Z]90\)/\1/' \ -e y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/ \ -e 's/\.[^.]*$/.X/' exit ;; CRAY*TS:*:*:*) - echo t90-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' - exit ;; + CRAY_REL=`echo "$UNAME_RELEASE" | sed -e 's/\.[^.]*$/.X/'` + GUESS=t90-cray-unicos$CRAY_REL + ;; CRAY*T3E:*:*:*) - echo alphaev5-cray-unicosmk${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' - exit ;; + CRAY_REL=`echo "$UNAME_RELEASE" | sed -e 's/\.[^.]*$/.X/'` + GUESS=alphaev5-cray-unicosmk$CRAY_REL + ;; CRAY*SV1:*:*:*) - echo sv1-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' - exit ;; + CRAY_REL=`echo "$UNAME_RELEASE" | sed -e 's/\.[^.]*$/.X/'` + GUESS=sv1-cray-unicos$CRAY_REL + ;; *:UNICOS/mp:*:*) - echo craynv-cray-unicosmp${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' - exit ;; + CRAY_REL=`echo "$UNAME_RELEASE" | sed -e 's/\.[^.]*$/.X/'` + GUESS=craynv-cray-unicosmp$CRAY_REL + ;; F30[01]:UNIX_System_V:*:* | F700:UNIX_System_V:*:*) - FUJITSU_PROC=`uname -m | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'` - FUJITSU_SYS=`uname -p | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/\///'` - FUJITSU_REL=`echo ${UNAME_RELEASE} | sed -e 's/ /_/'` - echo "${FUJITSU_PROC}-fujitsu-${FUJITSU_SYS}${FUJITSU_REL}" - exit ;; + FUJITSU_PROC=`uname -m | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz` + FUJITSU_SYS=`uname -p | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz | sed -e 's/\///'` + FUJITSU_REL=`echo "$UNAME_RELEASE" | sed -e 's/ /_/'` + GUESS=${FUJITSU_PROC}-fujitsu-${FUJITSU_SYS}${FUJITSU_REL} + ;; 5000:UNIX_System_V:4.*:*) - FUJITSU_SYS=`uname -p | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/\///'` - FUJITSU_REL=`echo ${UNAME_RELEASE} | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/ /_/'` - echo "sparc-fujitsu-${FUJITSU_SYS}${FUJITSU_REL}" - exit ;; + FUJITSU_SYS=`uname -p | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz | sed -e 's/\///'` + FUJITSU_REL=`echo "$UNAME_RELEASE" | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz | sed -e 's/ /_/'` + GUESS=sparc-fujitsu-${FUJITSU_SYS}${FUJITSU_REL} + ;; i*86:BSD/386:*:* | i*86:BSD/OS:*:* | *:Ascend\ Embedded/OS:*:*) - echo ${UNAME_MACHINE}-pc-bsdi${UNAME_RELEASE} - exit ;; + GUESS=$UNAME_MACHINE-pc-bsdi$UNAME_RELEASE + ;; sparc*:BSD/OS:*:*) - echo sparc-unknown-bsdi${UNAME_RELEASE} - exit ;; + GUESS=sparc-unknown-bsdi$UNAME_RELEASE + ;; *:BSD/OS:*:*) - echo ${UNAME_MACHINE}-unknown-bsdi${UNAME_RELEASE} - exit ;; + GUESS=$UNAME_MACHINE-unknown-bsdi$UNAME_RELEASE + ;; + arm:FreeBSD:*:*) + UNAME_PROCESSOR=`uname -p` + set_cc_for_build + if echo __ARM_PCS_VFP | $CC_FOR_BUILD -E - 2>/dev/null \ + | grep -q __ARM_PCS_VFP + then + FREEBSD_REL=`echo "$UNAME_RELEASE" | sed -e 's/[-(].*//'` + GUESS=$UNAME_PROCESSOR-unknown-freebsd$FREEBSD_REL-gnueabi + else + FREEBSD_REL=`echo "$UNAME_RELEASE" | sed -e 's/[-(].*//'` + GUESS=$UNAME_PROCESSOR-unknown-freebsd$FREEBSD_REL-gnueabihf + fi + ;; *:FreeBSD:*:*) - case ${UNAME_MACHINE} in - pc98) - echo i386-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` ;; + UNAME_PROCESSOR=`/usr/bin/uname -p` + case $UNAME_PROCESSOR in amd64) - echo x86_64-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` ;; - *) - echo ${UNAME_MACHINE}-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` ;; + UNAME_PROCESSOR=x86_64 ;; + i386) + UNAME_PROCESSOR=i586 ;; esac - exit ;; + FREEBSD_REL=`echo "$UNAME_RELEASE" | sed -e 's/[-(].*//'` + GUESS=$UNAME_PROCESSOR-unknown-freebsd$FREEBSD_REL + ;; i*:CYGWIN*:*) - echo ${UNAME_MACHINE}-pc-cygwin - exit ;; + GUESS=$UNAME_MACHINE-pc-cygwin + ;; + *:MINGW64*:*) + GUESS=$UNAME_MACHINE-pc-mingw64 + ;; *:MINGW*:*) - echo ${UNAME_MACHINE}-pc-mingw32 - exit ;; - i*:windows32*:*) - # uname -m includes "-pc" on this system. - echo ${UNAME_MACHINE}-mingw32 - exit ;; + GUESS=$UNAME_MACHINE-pc-mingw32 + ;; + *:MSYS*:*) + GUESS=$UNAME_MACHINE-pc-msys + ;; i*:PW*:*) - echo ${UNAME_MACHINE}-pc-pw32 - exit ;; + GUESS=$UNAME_MACHINE-pc-pw32 + ;; + *:SerenityOS:*:*) + GUESS=$UNAME_MACHINE-pc-serenity + ;; *:Interix*:*) - case ${UNAME_MACHINE} in + case $UNAME_MACHINE in x86) - echo i586-pc-interix${UNAME_RELEASE} - exit ;; + GUESS=i586-pc-interix$UNAME_RELEASE + ;; authenticamd | genuineintel | EM64T) - echo x86_64-unknown-interix${UNAME_RELEASE} - exit ;; + GUESS=x86_64-unknown-interix$UNAME_RELEASE + ;; IA64) - echo ia64-unknown-interix${UNAME_RELEASE} - exit ;; + GUESS=ia64-unknown-interix$UNAME_RELEASE + ;; esac ;; - [345]86:Windows_95:* | [345]86:Windows_98:* | [345]86:Windows_NT:*) - echo i${UNAME_MACHINE}-pc-mks - exit ;; - 8664:Windows_NT:*) - echo x86_64-pc-mks - exit ;; - i*:Windows_NT*:* | Pentium*:Windows_NT*:*) - # How do we know it's Interix rather than the generic POSIX subsystem? - # It also conflicts with pre-2.0 versions of AT&T UWIN. Should we - # UNAME_MACHINE based on the output of uname instead of i386? - echo i586-pc-interix - exit ;; i*:UWIN*:*) - echo ${UNAME_MACHINE}-pc-uwin - exit ;; + GUESS=$UNAME_MACHINE-pc-uwin + ;; amd64:CYGWIN*:*:* | x86_64:CYGWIN*:*:*) - echo x86_64-unknown-cygwin - exit ;; - p*:CYGWIN*:*) - echo powerpcle-unknown-cygwin - exit ;; + GUESS=x86_64-pc-cygwin + ;; prep*:SunOS:5.*:*) - echo powerpcle-unknown-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` - exit ;; + SUN_REL=`echo "$UNAME_RELEASE" | sed -e 's/[^.]*//'` + GUESS=powerpcle-unknown-solaris2$SUN_REL + ;; *:GNU:*:*) # the GNU system - echo `echo ${UNAME_MACHINE}|sed -e 's,[-/].*$,,'`-unknown-${LIBC}`echo ${UNAME_RELEASE}|sed -e 's,/.*$,,'` - exit ;; + GNU_ARCH=`echo "$UNAME_MACHINE" | sed -e 's,[-/].*$,,'` + GNU_REL=`echo "$UNAME_RELEASE" | sed -e 's,/.*$,,'` + GUESS=$GNU_ARCH-unknown-$LIBC$GNU_REL + ;; *:GNU/*:*:*) # other systems with GNU libc and userland - echo ${UNAME_MACHINE}-unknown-`echo ${UNAME_SYSTEM} | sed 's,^[^/]*/,,' | tr '[A-Z]' '[a-z]'``echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'`-${LIBC} - exit ;; - i*86:Minix:*:*) - echo ${UNAME_MACHINE}-pc-minix - exit ;; - alpha:Linux:*:*) - case `sed -n '/^cpu model/s/^.*: \(.*\)/\1/p' < /proc/cpuinfo` in - EV5) UNAME_MACHINE=alphaev5 ;; + GNU_SYS=`echo "$UNAME_SYSTEM" | sed 's,^[^/]*/,,' | tr "[:upper:]" "[:lower:]"` + GNU_REL=`echo "$UNAME_RELEASE" | sed -e 's/[-(].*//'` + GUESS=$UNAME_MACHINE-unknown-$GNU_SYS$GNU_REL-$LIBC + ;; + x86_64:[Mm]anagarm:*:*|i?86:[Mm]anagarm:*:*) + GUESS="$UNAME_MACHINE-pc-managarm-mlibc" + ;; + *:[Mm]anagarm:*:*) + GUESS="$UNAME_MACHINE-unknown-managarm-mlibc" + ;; + *:Minix:*:*) + GUESS=$UNAME_MACHINE-unknown-minix + ;; + aarch64:Linux:*:*) + GUESS=$UNAME_MACHINE-unknown-linux-$LIBC + ;; + aarch64_be:Linux:*:*) + UNAME_MACHINE=aarch64_be + GUESS=$UNAME_MACHINE-unknown-linux-$LIBC + ;; + alpha:Linux:*:*) + case `sed -n '/^cpu model/s/^.*: \(.*\)/\1/p' /proc/cpuinfo 2>/dev/null` in + EV5) UNAME_MACHINE=alphaev5 ;; EV56) UNAME_MACHINE=alphaev56 ;; PCA56) UNAME_MACHINE=alphapca56 ;; PCA57) UNAME_MACHINE=alphapca56 ;; EV6) UNAME_MACHINE=alphaev6 ;; EV67) UNAME_MACHINE=alphaev67 ;; EV68*) UNAME_MACHINE=alphaev68 ;; - esac + esac objdump --private-headers /bin/sh | grep -q ld.so.1 - if test "$?" = 0 ; then LIBC="gnulibc1" ; fi - echo ${UNAME_MACHINE}-unknown-linux-${LIBC} - exit ;; + if test "$?" = 0 ; then LIBC=gnulibc1 ; fi + GUESS=$UNAME_MACHINE-unknown-linux-$LIBC + ;; + arc:Linux:*:* | arceb:Linux:*:* | arc32:Linux:*:* | arc64:Linux:*:*) + GUESS=$UNAME_MACHINE-unknown-linux-$LIBC + ;; arm*:Linux:*:*) - eval $set_cc_for_build + set_cc_for_build if echo __ARM_EABI__ | $CC_FOR_BUILD -E - 2>/dev/null \ | grep -q __ARM_EABI__ then - echo ${UNAME_MACHINE}-unknown-linux-${LIBC} + GUESS=$UNAME_MACHINE-unknown-linux-$LIBC else - echo ${UNAME_MACHINE}-unknown-linux-${LIBC}eabi + if echo __ARM_PCS_VFP | $CC_FOR_BUILD -E - 2>/dev/null \ + | grep -q __ARM_PCS_VFP + then + GUESS=$UNAME_MACHINE-unknown-linux-${LIBC}eabi + else + GUESS=$UNAME_MACHINE-unknown-linux-${LIBC}eabihf + fi fi - exit ;; + ;; avr32*:Linux:*:*) - echo ${UNAME_MACHINE}-unknown-linux-${LIBC} - exit ;; + GUESS=$UNAME_MACHINE-unknown-linux-$LIBC + ;; cris:Linux:*:*) - echo cris-axis-linux-${LIBC} - exit ;; + GUESS=$UNAME_MACHINE-axis-linux-$LIBC + ;; crisv32:Linux:*:*) - echo crisv32-axis-linux-${LIBC} - exit ;; + GUESS=$UNAME_MACHINE-axis-linux-$LIBC + ;; + e2k:Linux:*:*) + GUESS=$UNAME_MACHINE-unknown-linux-$LIBC + ;; frv:Linux:*:*) - echo frv-unknown-linux-${LIBC} - exit ;; + GUESS=$UNAME_MACHINE-unknown-linux-$LIBC + ;; + hexagon:Linux:*:*) + GUESS=$UNAME_MACHINE-unknown-linux-$LIBC + ;; i*86:Linux:*:*) - echo ${UNAME_MACHINE}-pc-linux-${LIBC} - exit ;; + GUESS=$UNAME_MACHINE-pc-linux-$LIBC + ;; ia64:Linux:*:*) - echo ${UNAME_MACHINE}-unknown-linux-${LIBC} - exit ;; + GUESS=$UNAME_MACHINE-unknown-linux-$LIBC + ;; + k1om:Linux:*:*) + GUESS=$UNAME_MACHINE-unknown-linux-$LIBC + ;; + loongarch32:Linux:*:* | loongarch64:Linux:*:*) + GUESS=$UNAME_MACHINE-unknown-linux-$LIBC + ;; m32r*:Linux:*:*) - echo ${UNAME_MACHINE}-unknown-linux-${LIBC} - exit ;; + GUESS=$UNAME_MACHINE-unknown-linux-$LIBC + ;; m68*:Linux:*:*) - echo ${UNAME_MACHINE}-unknown-linux-${LIBC} - exit ;; + GUESS=$UNAME_MACHINE-unknown-linux-$LIBC + ;; mips:Linux:*:* | mips64:Linux:*:*) - eval $set_cc_for_build - sed 's/^ //' << EOF >$dummy.c + set_cc_for_build + IS_GLIBC=0 + test x"${LIBC}" = xgnu && IS_GLIBC=1 + sed 's/^ //' << EOF > "$dummy.c" #undef CPU - #undef ${UNAME_MACHINE} - #undef ${UNAME_MACHINE}el + #undef mips + #undef mipsel + #undef mips64 + #undef mips64el + #if ${IS_GLIBC} && defined(_ABI64) + LIBCABI=gnuabi64 + #else + #if ${IS_GLIBC} && defined(_ABIN32) + LIBCABI=gnuabin32 + #else + LIBCABI=${LIBC} + #endif + #endif + + #if ${IS_GLIBC} && defined(__mips64) && defined(__mips_isa_rev) && __mips_isa_rev>=6 + CPU=mipsisa64r6 + #else + #if ${IS_GLIBC} && !defined(__mips64) && defined(__mips_isa_rev) && __mips_isa_rev>=6 + CPU=mipsisa32r6 + #else + #if defined(__mips64) + CPU=mips64 + #else + CPU=mips + #endif + #endif + #endif + #if defined(__MIPSEL__) || defined(__MIPSEL) || defined(_MIPSEL) || defined(MIPSEL) - CPU=${UNAME_MACHINE}el + MIPS_ENDIAN=el #else #if defined(__MIPSEB__) || defined(__MIPSEB) || defined(_MIPSEB) || defined(MIPSEB) - CPU=${UNAME_MACHINE} + MIPS_ENDIAN= #else - CPU= + MIPS_ENDIAN= #endif #endif EOF - eval `$CC_FOR_BUILD -E $dummy.c 2>/dev/null | grep '^CPU'` - test x"${CPU}" != x && { echo "${CPU}-unknown-linux-${LIBC}"; exit; } + cc_set_vars=`$CC_FOR_BUILD -E "$dummy.c" 2>/dev/null | grep '^CPU\|^MIPS_ENDIAN\|^LIBCABI'` + eval "$cc_set_vars" + test "x$CPU" != x && { echo "$CPU${MIPS_ENDIAN}-unknown-linux-$LIBCABI"; exit; } + ;; + mips64el:Linux:*:*) + GUESS=$UNAME_MACHINE-unknown-linux-$LIBC + ;; + openrisc*:Linux:*:*) + GUESS=or1k-unknown-linux-$LIBC + ;; + or32:Linux:*:* | or1k*:Linux:*:*) + GUESS=$UNAME_MACHINE-unknown-linux-$LIBC ;; - or32:Linux:*:*) - echo or32-unknown-linux-${LIBC} - exit ;; padre:Linux:*:*) - echo sparc-unknown-linux-${LIBC} - exit ;; + GUESS=sparc-unknown-linux-$LIBC + ;; parisc64:Linux:*:* | hppa64:Linux:*:*) - echo hppa64-unknown-linux-${LIBC} - exit ;; + GUESS=hppa64-unknown-linux-$LIBC + ;; parisc:Linux:*:* | hppa:Linux:*:*) # Look for CPU level case `grep '^cpu[^a-z]*:' /proc/cpuinfo 2>/dev/null | cut -d' ' -f2` in - PA7*) echo hppa1.1-unknown-linux-${LIBC} ;; - PA8*) echo hppa2.0-unknown-linux-${LIBC} ;; - *) echo hppa-unknown-linux-${LIBC} ;; + PA7*) GUESS=hppa1.1-unknown-linux-$LIBC ;; + PA8*) GUESS=hppa2.0-unknown-linux-$LIBC ;; + *) GUESS=hppa-unknown-linux-$LIBC ;; esac - exit ;; + ;; ppc64:Linux:*:*) - echo powerpc64-unknown-linux-${LIBC} - exit ;; + GUESS=powerpc64-unknown-linux-$LIBC + ;; ppc:Linux:*:*) - echo powerpc-unknown-linux-${LIBC} - exit ;; + GUESS=powerpc-unknown-linux-$LIBC + ;; + ppc64le:Linux:*:*) + GUESS=powerpc64le-unknown-linux-$LIBC + ;; + ppcle:Linux:*:*) + GUESS=powerpcle-unknown-linux-$LIBC + ;; + riscv32:Linux:*:* | riscv32be:Linux:*:* | riscv64:Linux:*:* | riscv64be:Linux:*:*) + GUESS=$UNAME_MACHINE-unknown-linux-$LIBC + ;; s390:Linux:*:* | s390x:Linux:*:*) - echo ${UNAME_MACHINE}-ibm-linux - exit ;; + GUESS=$UNAME_MACHINE-ibm-linux-$LIBC + ;; sh64*:Linux:*:*) - echo ${UNAME_MACHINE}-unknown-linux-${LIBC} - exit ;; + GUESS=$UNAME_MACHINE-unknown-linux-$LIBC + ;; sh*:Linux:*:*) - echo ${UNAME_MACHINE}-unknown-linux-${LIBC} - exit ;; + GUESS=$UNAME_MACHINE-unknown-linux-$LIBC + ;; sparc:Linux:*:* | sparc64:Linux:*:*) - echo ${UNAME_MACHINE}-unknown-linux-${LIBC} - exit ;; + GUESS=$UNAME_MACHINE-unknown-linux-$LIBC + ;; tile*:Linux:*:*) - echo ${UNAME_MACHINE}-tilera-linux-gnu - exit ;; + GUESS=$UNAME_MACHINE-unknown-linux-$LIBC + ;; vax:Linux:*:*) - echo ${UNAME_MACHINE}-dec-linux-${LIBC} - exit ;; + GUESS=$UNAME_MACHINE-dec-linux-$LIBC + ;; x86_64:Linux:*:*) - echo x86_64-unknown-linux-${LIBC} - exit ;; + set_cc_for_build + CPU=$UNAME_MACHINE + LIBCABI=$LIBC + if test "$CC_FOR_BUILD" != no_compiler_found; then + ABI=64 + sed 's/^ //' << EOF > "$dummy.c" + #ifdef __i386__ + ABI=x86 + #else + #ifdef __ILP32__ + ABI=x32 + #endif + #endif +EOF + cc_set_abi=`$CC_FOR_BUILD -E "$dummy.c" 2>/dev/null | grep '^ABI' | sed 's, ,,g'` + eval "$cc_set_abi" + case $ABI in + x86) CPU=i686 ;; + x32) LIBCABI=${LIBC}x32 ;; + esac + fi + GUESS=$CPU-pc-linux-$LIBCABI + ;; xtensa*:Linux:*:*) - echo ${UNAME_MACHINE}-unknown-linux-${LIBC} - exit ;; + GUESS=$UNAME_MACHINE-unknown-linux-$LIBC + ;; i*86:DYNIX/ptx:4*:*) # ptx 4.0 does uname -s correctly, with DYNIX/ptx in there. # earlier versions are messed up and put the nodename in both # sysname and nodename. - echo i386-sequent-sysv4 - exit ;; + GUESS=i386-sequent-sysv4 + ;; i*86:UNIX_SV:4.2MP:2.*) - # Unixware is an offshoot of SVR4, but it has its own version - # number series starting with 2... - # I am not positive that other SVR4 systems won't match this, + # Unixware is an offshoot of SVR4, but it has its own version + # number series starting with 2... + # I am not positive that other SVR4 systems won't match this, # I just have to hope. -- rms. - # Use sysv4.2uw... so that sysv4* matches it. - echo ${UNAME_MACHINE}-pc-sysv4.2uw${UNAME_VERSION} - exit ;; + # Use sysv4.2uw... so that sysv4* matches it. + GUESS=$UNAME_MACHINE-pc-sysv4.2uw$UNAME_VERSION + ;; i*86:OS/2:*:*) # If we were able to find `uname', then EMX Unix compatibility # is probably installed. - echo ${UNAME_MACHINE}-pc-os2-emx - exit ;; + GUESS=$UNAME_MACHINE-pc-os2-emx + ;; i*86:XTS-300:*:STOP) - echo ${UNAME_MACHINE}-unknown-stop - exit ;; + GUESS=$UNAME_MACHINE-unknown-stop + ;; i*86:atheos:*:*) - echo ${UNAME_MACHINE}-unknown-atheos - exit ;; + GUESS=$UNAME_MACHINE-unknown-atheos + ;; i*86:syllable:*:*) - echo ${UNAME_MACHINE}-pc-syllable - exit ;; + GUESS=$UNAME_MACHINE-pc-syllable + ;; i*86:LynxOS:2.*:* | i*86:LynxOS:3.[01]*:* | i*86:LynxOS:4.[02]*:*) - echo i386-unknown-lynxos${UNAME_RELEASE} - exit ;; + GUESS=i386-unknown-lynxos$UNAME_RELEASE + ;; i*86:*DOS:*:*) - echo ${UNAME_MACHINE}-pc-msdosdjgpp - exit ;; - i*86:*:4.*:* | i*86:SYSTEM_V:4.*:*) - UNAME_REL=`echo ${UNAME_RELEASE} | sed 's/\/MP$//'` + GUESS=$UNAME_MACHINE-pc-msdosdjgpp + ;; + i*86:*:4.*:*) + UNAME_REL=`echo "$UNAME_RELEASE" | sed 's/\/MP$//'` if grep Novell /usr/include/link.h >/dev/null 2>/dev/null; then - echo ${UNAME_MACHINE}-univel-sysv${UNAME_REL} + GUESS=$UNAME_MACHINE-univel-sysv$UNAME_REL else - echo ${UNAME_MACHINE}-pc-sysv${UNAME_REL} + GUESS=$UNAME_MACHINE-pc-sysv$UNAME_REL fi - exit ;; + ;; i*86:*:5:[678]*) - # UnixWare 7.x, OpenUNIX and OpenServer 6. + # UnixWare 7.x, OpenUNIX and OpenServer 6. case `/bin/uname -X | grep "^Machine"` in *486*) UNAME_MACHINE=i486 ;; *Pentium) UNAME_MACHINE=i586 ;; *Pent*|*Celeron) UNAME_MACHINE=i686 ;; esac - echo ${UNAME_MACHINE}-unknown-sysv${UNAME_RELEASE}${UNAME_SYSTEM}${UNAME_VERSION} - exit ;; + GUESS=$UNAME_MACHINE-unknown-sysv${UNAME_RELEASE}${UNAME_SYSTEM}${UNAME_VERSION} + ;; i*86:*:3.2:*) if test -f /usr/options/cb.name; then UNAME_REL=`sed -n 's/.*Version //p' /dev/null >/dev/null ; then UNAME_REL=`(/bin/uname -X|grep Release|sed -e 's/.*= //')` (/bin/uname -X|grep i80486 >/dev/null) && UNAME_MACHINE=i486 @@ -1059,43 +1246,43 @@ EOF && UNAME_MACHINE=i686 (/bin/uname -X|grep '^Machine.*Pentium Pro' >/dev/null) \ && UNAME_MACHINE=i686 - echo ${UNAME_MACHINE}-pc-sco$UNAME_REL + GUESS=$UNAME_MACHINE-pc-sco$UNAME_REL else - echo ${UNAME_MACHINE}-pc-sysv32 + GUESS=$UNAME_MACHINE-pc-sysv32 fi - exit ;; + ;; pc:*:*:*) # Left here for compatibility: - # uname -m prints for DJGPP always 'pc', but it prints nothing about - # the processor, so we play safe by assuming i586. + # uname -m prints for DJGPP always 'pc', but it prints nothing about + # the processor, so we play safe by assuming i586. # Note: whatever this is, it MUST be the same as what config.sub - # prints for the "djgpp" host, or else GDB configury will decide that + # prints for the "djgpp" host, or else GDB configure will decide that # this is a cross-build. - echo i586-pc-msdosdjgpp - exit ;; + GUESS=i586-pc-msdosdjgpp + ;; Intel:Mach:3*:*) - echo i386-pc-mach3 - exit ;; + GUESS=i386-pc-mach3 + ;; paragon:*:*:*) - echo i860-intel-osf1 - exit ;; + GUESS=i860-intel-osf1 + ;; i860:*:4.*:*) # i860-SVR4 if grep Stardent /usr/include/sys/uadmin.h >/dev/null 2>&1 ; then - echo i860-stardent-sysv${UNAME_RELEASE} # Stardent Vistra i860-SVR4 + GUESS=i860-stardent-sysv$UNAME_RELEASE # Stardent Vistra i860-SVR4 else # Add other i860-SVR4 vendors below as they are discovered. - echo i860-unknown-sysv${UNAME_RELEASE} # Unknown i860-SVR4 + GUESS=i860-unknown-sysv$UNAME_RELEASE # Unknown i860-SVR4 fi - exit ;; + ;; mini*:CTIX:SYS*5:*) # "miniframe" - echo m68010-convergent-sysv - exit ;; + GUESS=m68010-convergent-sysv + ;; mc68k:UNIX:SYSTEM5:3.51m) - echo m68k-convergent-sysv - exit ;; + GUESS=m68k-convergent-sysv + ;; M680?0:D-NIX:5.3:*) - echo m68k-diab-dnix - exit ;; + GUESS=m68k-diab-dnix + ;; M68*:*:R3V[5678]*:*) test -r /sysV68 && { echo 'm68k-motorola-sysv'; exit; } ;; 3[345]??:*:4.0:3.0 | 3[34]??A:*:4.0:3.0 | 3[34]??,*:*:4.0:3.0 | 3[34]??/*:*:4.0:3.0 | 4400:*:4.0:3.0 | 4850:*:4.0:3.0 | SKA40:*:4.0:3.0 | SDS2:*:4.0:3.0 | SHG2:*:4.0:3.0 | S7501*:*:4.0:3.0) @@ -1103,234 +1290,298 @@ EOF test -r /etc/.relid \ && OS_REL=.`sed -n 's/[^ ]* [^ ]* \([0-9][0-9]\).*/\1/p' < /etc/.relid` /bin/uname -p 2>/dev/null | grep 86 >/dev/null \ - && { echo i486-ncr-sysv4.3${OS_REL}; exit; } + && { echo i486-ncr-sysv4.3"$OS_REL"; exit; } /bin/uname -p 2>/dev/null | /bin/grep entium >/dev/null \ - && { echo i586-ncr-sysv4.3${OS_REL}; exit; } ;; + && { echo i586-ncr-sysv4.3"$OS_REL"; exit; } ;; 3[34]??:*:4.0:* | 3[34]??,*:*:4.0:*) - /bin/uname -p 2>/dev/null | grep 86 >/dev/null \ - && { echo i486-ncr-sysv4; exit; } ;; + /bin/uname -p 2>/dev/null | grep 86 >/dev/null \ + && { echo i486-ncr-sysv4; exit; } ;; NCR*:*:4.2:* | MPRAS*:*:4.2:*) OS_REL='.3' test -r /etc/.relid \ && OS_REL=.`sed -n 's/[^ ]* [^ ]* \([0-9][0-9]\).*/\1/p' < /etc/.relid` /bin/uname -p 2>/dev/null | grep 86 >/dev/null \ - && { echo i486-ncr-sysv4.3${OS_REL}; exit; } + && { echo i486-ncr-sysv4.3"$OS_REL"; exit; } /bin/uname -p 2>/dev/null | /bin/grep entium >/dev/null \ - && { echo i586-ncr-sysv4.3${OS_REL}; exit; } + && { echo i586-ncr-sysv4.3"$OS_REL"; exit; } /bin/uname -p 2>/dev/null | /bin/grep pteron >/dev/null \ - && { echo i586-ncr-sysv4.3${OS_REL}; exit; } ;; + && { echo i586-ncr-sysv4.3"$OS_REL"; exit; } ;; m68*:LynxOS:2.*:* | m68*:LynxOS:3.0*:*) - echo m68k-unknown-lynxos${UNAME_RELEASE} - exit ;; + GUESS=m68k-unknown-lynxos$UNAME_RELEASE + ;; mc68030:UNIX_System_V:4.*:*) - echo m68k-atari-sysv4 - exit ;; + GUESS=m68k-atari-sysv4 + ;; TSUNAMI:LynxOS:2.*:*) - echo sparc-unknown-lynxos${UNAME_RELEASE} - exit ;; + GUESS=sparc-unknown-lynxos$UNAME_RELEASE + ;; rs6000:LynxOS:2.*:*) - echo rs6000-unknown-lynxos${UNAME_RELEASE} - exit ;; + GUESS=rs6000-unknown-lynxos$UNAME_RELEASE + ;; PowerPC:LynxOS:2.*:* | PowerPC:LynxOS:3.[01]*:* | PowerPC:LynxOS:4.[02]*:*) - echo powerpc-unknown-lynxos${UNAME_RELEASE} - exit ;; + GUESS=powerpc-unknown-lynxos$UNAME_RELEASE + ;; SM[BE]S:UNIX_SV:*:*) - echo mips-dde-sysv${UNAME_RELEASE} - exit ;; + GUESS=mips-dde-sysv$UNAME_RELEASE + ;; RM*:ReliantUNIX-*:*:*) - echo mips-sni-sysv4 - exit ;; + GUESS=mips-sni-sysv4 + ;; RM*:SINIX-*:*:*) - echo mips-sni-sysv4 - exit ;; + GUESS=mips-sni-sysv4 + ;; *:SINIX-*:*:*) if uname -p 2>/dev/null >/dev/null ; then UNAME_MACHINE=`(uname -p) 2>/dev/null` - echo ${UNAME_MACHINE}-sni-sysv4 + GUESS=$UNAME_MACHINE-sni-sysv4 else - echo ns32k-sni-sysv + GUESS=ns32k-sni-sysv fi - exit ;; - PENTIUM:*:4.0*:*) # Unisys `ClearPath HMP IX 4000' SVR4/MP effort - # says - echo i586-unisys-sysv4 - exit ;; + ;; + PENTIUM:*:4.0*:*) # Unisys `ClearPath HMP IX 4000' SVR4/MP effort + # says + GUESS=i586-unisys-sysv4 + ;; *:UNIX_System_V:4*:FTX*) # From Gerald Hewes . # How about differentiating between stratus architectures? -djm - echo hppa1.1-stratus-sysv4 - exit ;; + GUESS=hppa1.1-stratus-sysv4 + ;; *:*:*:FTX*) # From seanf@swdc.stratus.com. - echo i860-stratus-sysv4 - exit ;; + GUESS=i860-stratus-sysv4 + ;; i*86:VOS:*:*) # From Paul.Green@stratus.com. - echo ${UNAME_MACHINE}-stratus-vos - exit ;; + GUESS=$UNAME_MACHINE-stratus-vos + ;; *:VOS:*:*) # From Paul.Green@stratus.com. - echo hppa1.1-stratus-vos - exit ;; + GUESS=hppa1.1-stratus-vos + ;; mc68*:A/UX:*:*) - echo m68k-apple-aux${UNAME_RELEASE} - exit ;; + GUESS=m68k-apple-aux$UNAME_RELEASE + ;; news*:NEWS-OS:6*:*) - echo mips-sony-newsos6 - exit ;; + GUESS=mips-sony-newsos6 + ;; R[34]000:*System_V*:*:* | R4000:UNIX_SYSV:*:* | R*000:UNIX_SV:*:*) - if [ -d /usr/nec ]; then - echo mips-nec-sysv${UNAME_RELEASE} + if test -d /usr/nec; then + GUESS=mips-nec-sysv$UNAME_RELEASE else - echo mips-unknown-sysv${UNAME_RELEASE} + GUESS=mips-unknown-sysv$UNAME_RELEASE fi - exit ;; + ;; BeBox:BeOS:*:*) # BeOS running on hardware made by Be, PPC only. - echo powerpc-be-beos - exit ;; + GUESS=powerpc-be-beos + ;; BeMac:BeOS:*:*) # BeOS running on Mac or Mac clone, PPC only. - echo powerpc-apple-beos - exit ;; + GUESS=powerpc-apple-beos + ;; BePC:BeOS:*:*) # BeOS running on Intel PC compatible. - echo i586-pc-beos - exit ;; + GUESS=i586-pc-beos + ;; BePC:Haiku:*:*) # Haiku running on Intel PC compatible. - echo i586-pc-haiku - exit ;; + GUESS=i586-pc-haiku + ;; + ppc:Haiku:*:*) # Haiku running on Apple PowerPC + GUESS=powerpc-apple-haiku + ;; + *:Haiku:*:*) # Haiku modern gcc (not bound by BeOS compat) + GUESS=$UNAME_MACHINE-unknown-haiku + ;; SX-4:SUPER-UX:*:*) - echo sx4-nec-superux${UNAME_RELEASE} - exit ;; + GUESS=sx4-nec-superux$UNAME_RELEASE + ;; SX-5:SUPER-UX:*:*) - echo sx5-nec-superux${UNAME_RELEASE} - exit ;; + GUESS=sx5-nec-superux$UNAME_RELEASE + ;; SX-6:SUPER-UX:*:*) - echo sx6-nec-superux${UNAME_RELEASE} - exit ;; + GUESS=sx6-nec-superux$UNAME_RELEASE + ;; SX-7:SUPER-UX:*:*) - echo sx7-nec-superux${UNAME_RELEASE} - exit ;; + GUESS=sx7-nec-superux$UNAME_RELEASE + ;; SX-8:SUPER-UX:*:*) - echo sx8-nec-superux${UNAME_RELEASE} - exit ;; + GUESS=sx8-nec-superux$UNAME_RELEASE + ;; SX-8R:SUPER-UX:*:*) - echo sx8r-nec-superux${UNAME_RELEASE} - exit ;; + GUESS=sx8r-nec-superux$UNAME_RELEASE + ;; + SX-ACE:SUPER-UX:*:*) + GUESS=sxace-nec-superux$UNAME_RELEASE + ;; Power*:Rhapsody:*:*) - echo powerpc-apple-rhapsody${UNAME_RELEASE} - exit ;; + GUESS=powerpc-apple-rhapsody$UNAME_RELEASE + ;; *:Rhapsody:*:*) - echo ${UNAME_MACHINE}-apple-rhapsody${UNAME_RELEASE} - exit ;; + GUESS=$UNAME_MACHINE-apple-rhapsody$UNAME_RELEASE + ;; + arm64:Darwin:*:*) + GUESS=aarch64-apple-darwin$UNAME_RELEASE + ;; *:Darwin:*:*) - UNAME_PROCESSOR=`uname -p` || UNAME_PROCESSOR=unknown + UNAME_PROCESSOR=`uname -p` case $UNAME_PROCESSOR in - i386) - eval $set_cc_for_build - if [ "$CC_FOR_BUILD" != 'no_compiler_found' ]; then - if (echo '#ifdef __LP64__'; echo IS_64BIT_ARCH; echo '#endif') | \ - (CCOPTS= $CC_FOR_BUILD -E - 2>/dev/null) | \ - grep IS_64BIT_ARCH >/dev/null - then - UNAME_PROCESSOR="x86_64" - fi - fi ;; unknown) UNAME_PROCESSOR=powerpc ;; esac - echo ${UNAME_PROCESSOR}-apple-darwin${UNAME_RELEASE} - exit ;; + if command -v xcode-select > /dev/null 2> /dev/null && \ + ! xcode-select --print-path > /dev/null 2> /dev/null ; then + # Avoid executing cc if there is no toolchain installed as + # cc will be a stub that puts up a graphical alert + # prompting the user to install developer tools. + CC_FOR_BUILD=no_compiler_found + else + set_cc_for_build + fi + if test "$CC_FOR_BUILD" != no_compiler_found; then + if (echo '#ifdef __LP64__'; echo IS_64BIT_ARCH; echo '#endif') | \ + (CCOPTS="" $CC_FOR_BUILD -E - 2>/dev/null) | \ + grep IS_64BIT_ARCH >/dev/null + then + case $UNAME_PROCESSOR in + i386) UNAME_PROCESSOR=x86_64 ;; + powerpc) UNAME_PROCESSOR=powerpc64 ;; + esac + fi + # On 10.4-10.6 one might compile for PowerPC via gcc -arch ppc + if (echo '#ifdef __POWERPC__'; echo IS_PPC; echo '#endif') | \ + (CCOPTS="" $CC_FOR_BUILD -E - 2>/dev/null) | \ + grep IS_PPC >/dev/null + then + UNAME_PROCESSOR=powerpc + fi + elif test "$UNAME_PROCESSOR" = i386 ; then + # uname -m returns i386 or x86_64 + UNAME_PROCESSOR=$UNAME_MACHINE + fi + GUESS=$UNAME_PROCESSOR-apple-darwin$UNAME_RELEASE + ;; *:procnto*:*:* | *:QNX:[0123456789]*:*) UNAME_PROCESSOR=`uname -p` - if test "$UNAME_PROCESSOR" = "x86"; then + if test "$UNAME_PROCESSOR" = x86; then UNAME_PROCESSOR=i386 UNAME_MACHINE=pc fi - echo ${UNAME_PROCESSOR}-${UNAME_MACHINE}-nto-qnx${UNAME_RELEASE} - exit ;; + GUESS=$UNAME_PROCESSOR-$UNAME_MACHINE-nto-qnx$UNAME_RELEASE + ;; *:QNX:*:4*) - echo i386-pc-qnx - exit ;; - NEO-?:NONSTOP_KERNEL:*:*) - echo neo-tandem-nsk${UNAME_RELEASE} - exit ;; - NSE-?:NONSTOP_KERNEL:*:*) - echo nse-tandem-nsk${UNAME_RELEASE} - exit ;; - NSR-?:NONSTOP_KERNEL:*:*) - echo nsr-tandem-nsk${UNAME_RELEASE} - exit ;; + GUESS=i386-pc-qnx + ;; + NEO-*:NONSTOP_KERNEL:*:*) + GUESS=neo-tandem-nsk$UNAME_RELEASE + ;; + NSE-*:NONSTOP_KERNEL:*:*) + GUESS=nse-tandem-nsk$UNAME_RELEASE + ;; + NSR-*:NONSTOP_KERNEL:*:*) + GUESS=nsr-tandem-nsk$UNAME_RELEASE + ;; + NSV-*:NONSTOP_KERNEL:*:*) + GUESS=nsv-tandem-nsk$UNAME_RELEASE + ;; + NSX-*:NONSTOP_KERNEL:*:*) + GUESS=nsx-tandem-nsk$UNAME_RELEASE + ;; *:NonStop-UX:*:*) - echo mips-compaq-nonstopux - exit ;; + GUESS=mips-compaq-nonstopux + ;; BS2000:POSIX*:*:*) - echo bs2000-siemens-sysv - exit ;; + GUESS=bs2000-siemens-sysv + ;; DS/*:UNIX_System_V:*:*) - echo ${UNAME_MACHINE}-${UNAME_SYSTEM}-${UNAME_RELEASE} - exit ;; + GUESS=$UNAME_MACHINE-$UNAME_SYSTEM-$UNAME_RELEASE + ;; *:Plan9:*:*) # "uname -m" is not consistent, so use $cputype instead. 386 # is converted to i386 for consistency with other x86 # operating systems. - if test "$cputype" = "386"; then + if test "${cputype-}" = 386; then UNAME_MACHINE=i386 - else - UNAME_MACHINE="$cputype" + elif test "x${cputype-}" != x; then + UNAME_MACHINE=$cputype fi - echo ${UNAME_MACHINE}-unknown-plan9 - exit ;; + GUESS=$UNAME_MACHINE-unknown-plan9 + ;; *:TOPS-10:*:*) - echo pdp10-unknown-tops10 - exit ;; + GUESS=pdp10-unknown-tops10 + ;; *:TENEX:*:*) - echo pdp10-unknown-tenex - exit ;; + GUESS=pdp10-unknown-tenex + ;; KS10:TOPS-20:*:* | KL10:TOPS-20:*:* | TYPE4:TOPS-20:*:*) - echo pdp10-dec-tops20 - exit ;; + GUESS=pdp10-dec-tops20 + ;; XKL-1:TOPS-20:*:* | TYPE5:TOPS-20:*:*) - echo pdp10-xkl-tops20 - exit ;; + GUESS=pdp10-xkl-tops20 + ;; *:TOPS-20:*:*) - echo pdp10-unknown-tops20 - exit ;; + GUESS=pdp10-unknown-tops20 + ;; *:ITS:*:*) - echo pdp10-unknown-its - exit ;; + GUESS=pdp10-unknown-its + ;; SEI:*:*:SEIUX) - echo mips-sei-seiux${UNAME_RELEASE} - exit ;; + GUESS=mips-sei-seiux$UNAME_RELEASE + ;; *:DragonFly:*:*) - echo ${UNAME_MACHINE}-unknown-dragonfly`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` - exit ;; + DRAGONFLY_REL=`echo "$UNAME_RELEASE" | sed -e 's/[-(].*//'` + GUESS=$UNAME_MACHINE-unknown-dragonfly$DRAGONFLY_REL + ;; *:*VMS:*:*) - UNAME_MACHINE=`(uname -p) 2>/dev/null` - case "${UNAME_MACHINE}" in - A*) echo alpha-dec-vms ; exit ;; - I*) echo ia64-dec-vms ; exit ;; - V*) echo vax-dec-vms ; exit ;; + UNAME_MACHINE=`(uname -p) 2>/dev/null` + case $UNAME_MACHINE in + A*) GUESS=alpha-dec-vms ;; + I*) GUESS=ia64-dec-vms ;; + V*) GUESS=vax-dec-vms ;; esac ;; *:XENIX:*:SysV) - echo i386-pc-xenix - exit ;; + GUESS=i386-pc-xenix + ;; i*86:skyos:*:*) - echo ${UNAME_MACHINE}-pc-skyos`echo ${UNAME_RELEASE}` | sed -e 's/ .*$//' - exit ;; + SKYOS_REL=`echo "$UNAME_RELEASE" | sed -e 's/ .*$//'` + GUESS=$UNAME_MACHINE-pc-skyos$SKYOS_REL + ;; i*86:rdos:*:*) - echo ${UNAME_MACHINE}-pc-rdos - exit ;; - i*86:AROS:*:*) - echo ${UNAME_MACHINE}-pc-aros - exit ;; + GUESS=$UNAME_MACHINE-pc-rdos + ;; + i*86:Fiwix:*:*) + GUESS=$UNAME_MACHINE-pc-fiwix + ;; + *:AROS:*:*) + GUESS=$UNAME_MACHINE-unknown-aros + ;; + x86_64:VMkernel:*:*) + GUESS=$UNAME_MACHINE-unknown-esx + ;; + amd64:Isilon\ OneFS:*:*) + GUESS=x86_64-unknown-onefs + ;; + *:Unleashed:*:*) + GUESS=$UNAME_MACHINE-unknown-unleashed$UNAME_RELEASE + ;; esac -#echo '(No uname command or uname output not recognized.)' 1>&2 -#echo "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" 1>&2 +# Do we have a guess based on uname results? +if test "x$GUESS" != x; then + echo "$GUESS" + exit +fi -eval $set_cc_for_build -cat >$dummy.c < "$dummy.c" < -# include +#include +#include +#endif +#if defined(ultrix) || defined(_ultrix) || defined(__ultrix) || defined(__ultrix__) +#if defined (vax) || defined (__vax) || defined (__vax__) || defined(mips) || defined(__mips) || defined(__mips__) || defined(MIPS) || defined(__MIPS__) +#include +#if defined(_SIZE_T_) || defined(SIGLOST) +#include +#endif +#endif #endif main () { @@ -1343,20 +1594,12 @@ main () #include printf ("m68k-sony-newsos%s\n", #ifdef NEWSOS4 - "4" + "4" #else - "" -#endif - ); exit (0); + "" #endif + ); exit (0); #endif - -#if defined (__arm) && defined (__acorn) && defined (__unix) - printf ("arm-acorn-riscix\n"); exit (0); -#endif - -#if defined (hp300) && !defined (hpux) - printf ("m68k-hp-bsd\n"); exit (0); #endif #if defined (NeXT) @@ -1398,39 +1641,54 @@ main () #endif #if defined (_SEQUENT_) - struct utsname un; - - uname(&un); - - if (strncmp(un.version, "V2", 2) == 0) { - printf ("i386-sequent-ptx2\n"); exit (0); - } - if (strncmp(un.version, "V1", 2) == 0) { /* XXX is V1 correct? */ - printf ("i386-sequent-ptx1\n"); exit (0); - } - printf ("i386-sequent-ptx\n"); exit (0); + struct utsname un; + uname(&un); + if (strncmp(un.version, "V2", 2) == 0) { + printf ("i386-sequent-ptx2\n"); exit (0); + } + if (strncmp(un.version, "V1", 2) == 0) { /* XXX is V1 correct? */ + printf ("i386-sequent-ptx1\n"); exit (0); + } + printf ("i386-sequent-ptx\n"); exit (0); #endif #if defined (vax) -# if !defined (ultrix) -# include -# if defined (BSD) -# if BSD == 43 - printf ("vax-dec-bsd4.3\n"); exit (0); -# else -# if BSD == 199006 - printf ("vax-dec-bsd4.3reno\n"); exit (0); -# else - printf ("vax-dec-bsd\n"); exit (0); -# endif -# endif -# else - printf ("vax-dec-bsd\n"); exit (0); -# endif -# else - printf ("vax-dec-ultrix\n"); exit (0); -# endif +#if !defined (ultrix) +#include +#if defined (BSD) +#if BSD == 43 + printf ("vax-dec-bsd4.3\n"); exit (0); +#else +#if BSD == 199006 + printf ("vax-dec-bsd4.3reno\n"); exit (0); +#else + printf ("vax-dec-bsd\n"); exit (0); +#endif +#endif +#else + printf ("vax-dec-bsd\n"); exit (0); +#endif +#else +#if defined(_SIZE_T_) || defined(SIGLOST) + struct utsname un; + uname (&un); + printf ("vax-dec-ultrix%s\n", un.release); exit (0); +#else + printf ("vax-dec-ultrix\n"); exit (0); +#endif +#endif +#endif +#if defined(ultrix) || defined(_ultrix) || defined(__ultrix) || defined(__ultrix__) +#if defined(mips) || defined(__mips) || defined(__mips__) || defined(MIPS) || defined(__MIPS__) +#if defined(_SIZE_T_) || defined(SIGLOST) + struct utsname *un; + uname (&un); + printf ("mips-dec-ultrix%s\n", un.release); exit (0); +#else + printf ("mips-dec-ultrix\n"); exit (0); +#endif +#endif #endif #if defined (alliant) && defined (i860) @@ -1441,54 +1699,46 @@ main () } EOF -$CC_FOR_BUILD -o $dummy $dummy.c 2>/dev/null && SYSTEM_NAME=`$dummy` && +$CC_FOR_BUILD -o "$dummy" "$dummy.c" 2>/dev/null && SYSTEM_NAME=`"$dummy"` && { echo "$SYSTEM_NAME"; exit; } # Apollos put the system type in the environment. +test -d /usr/apollo && { echo "$ISP-apollo-$SYSTYPE"; exit; } -test -d /usr/apollo && { echo ${ISP}-apollo-${SYSTYPE}; exit; } +echo "$0: unable to guess system type" >&2 -# Convex versions that predate uname can use getsysinfo(1) +case $UNAME_MACHINE:$UNAME_SYSTEM in + mips:Linux | mips64:Linux) + # If we got here on MIPS GNU/Linux, output extra information. + cat >&2 <&2 < in order to provide the needed -information to handle your system. +our_year=`echo $timestamp | sed 's,-.*,,'` +thisyear=`date +%Y` +# shellcheck disable=SC2003 +script_age=`expr "$thisyear" - "$our_year"` +if test "$script_age" -lt 3 ; then + cat >&2 </dev/null` /usr/bin/oslevel = `(/usr/bin/oslevel) 2>/dev/null` /usr/convex/getsysinfo = `(/usr/convex/getsysinfo) 2>/dev/null` -UNAME_MACHINE = ${UNAME_MACHINE} -UNAME_RELEASE = ${UNAME_RELEASE} -UNAME_SYSTEM = ${UNAME_SYSTEM} -UNAME_VERSION = ${UNAME_VERSION} +UNAME_MACHINE = "$UNAME_MACHINE" +UNAME_RELEASE = "$UNAME_RELEASE" +UNAME_SYSTEM = "$UNAME_SYSTEM" +UNAME_VERSION = "$UNAME_VERSION" EOF +fi exit 1 # Local variables: -# eval: (add-hook 'write-file-hooks 'time-stamp) +# eval: (add-hook 'before-save-hook 'time-stamp) # time-stamp-start: "timestamp='" # time-stamp-format: "%:y-%02m-%02d" # time-stamp-end: "'" From a6ad837b1275c9194f998681ed068840756a2086 Mon Sep 17 00:00:00 2001 From: David Allsopp Date: Mon, 13 Mar 2023 18:40:05 +0000 Subject: [PATCH 29/49] Use ocamlc to test the C compiler in configure (#135) The build uses ocamlc to compile C files, so it's more reliable to test C compilation and linking using $ocamlc than using $cc. Also: add .gitattributes for Windows Co-authored-by: Xavier Leroy --- .gitattributes | 4 ++++ configure | 31 +++++++++---------------------- 2 files changed, 13 insertions(+), 22 deletions(-) create mode 100644 .gitattributes diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..3aa538a --- /dev/null +++ b/.gitattributes @@ -0,0 +1,4 @@ +# Default behaviour, for if core.autocrlf isn't set +* text=auto + +configure text eol=lf diff --git a/configure b/configure index 0865c22..6e87fe9 100755 --- a/configure +++ b/configure @@ -59,7 +59,6 @@ where options include: -prefixnonocaml add for non ocaml tool, e.g. -prefixnonocaml x86_64-w64-mingw32- Environment variables that affect configuration: - CC C compiler to use (default: try gcc, then cc) CFLAGS extra flags to pass to the C compiler CPPFLAGS extra includes, e.g. -I/path/to/gmp/include LDFLAGS extra link flags, e.g. -L/path/to/gmp/lib @@ -149,7 +148,7 @@ checkinc() echo "#include <$1>" > tmp.c echo "int main() { return 1; }" >> tmp.c r=1 - $cc $ccopt $ccinc -c tmp.c -o tmp.o >/dev/null 2>/dev/null || r=0 + $ocamlc -ccopt "$ccopt $ccinc" -c tmp.c -o tmp.o >/dev/null 2>/dev/null || r=0 if test ! -f tmp.o; then r=0; fi rm -f tmp.c tmp.o if test $r -eq 0; then echo "not found"; else echo "found"; fi @@ -159,25 +158,26 @@ checkinc() checklib() { echo_n "library $1: " - rm -f tmp.c tmp.out - echo "int main() { return 1; }" >> tmp.c + rm -f tmp.ml tmp.out + echo "" > tmp.ml r=1 - $cc $ccopt $ldflags $cclib tmp.c -l$1 -o tmp.out >/dev/null 2>/dev/null || r=0 + $ocamlc -custom -ccopt "$ccopt $ldflags $cclib" tmp.ml -cclib -l$1 -o tmp.out >/dev/null 2>/dev/null || r=0 if test ! -x tmp.out; then r=0; fi - rm -f tmp.c tmp.o tmp.out + rm -f tmp.out tmp.ml tmp.cmi tmp.cmo if test $r -eq 0; then echo "not found"; else echo "found"; fi return $r } checkcc() { - echo_n "checking compilation with $cc $ccopt: " + echo_n "checking compilation with $ocamlc $ccopt: " rm -f tmp.c tmp.out echo "int main() { return 1; }" >> tmp.c + echo "" > tmpml.ml r=1 - $cc $ccopt tmp.c -o tmp.out >/dev/null 2>/dev/null || r=0 + $ocamlc -ccopt "$ccopt" tmp.c tmpml.ml -o tmp.out >/dev/null 2>/dev/null || r=0 if test ! -x tmp.out; then r=0; fi - rm -f tmp.c tmp.o tmp.out + rm -f tmp.c tmp.o tmp.out tmpml.ml tmpml.cm* if test $r -eq 0; then echo "not working"; else echo "working"; fi return $r } @@ -205,20 +205,8 @@ fi if test -n "$CC"; then searchbinreq "$CC" - cc="$CC" ccopt="$CFLAGS" -elif ! searchbin 'gcc'; then - cc='gcc' - ccopt="-O3 -Wall -Wextra $CFLAGS" -elif ! searchbin $prefixnonocaml'gcc'; then - cc=$prefixnonocaml'gcc' - ccopt="-O3 -Wall -Wextra $CFLAGS" -elif ! searchbin 'cc'; then - cc='cc' - ccopt="-O3 -Wall -Wextra $CFLAGS" else - searchbinreq $prefixnonocaml'cc' - cc=$prefixnonocaml'cc' ccopt="-O3 -Wall -Wextra $CFLAGS" fi @@ -357,7 +345,6 @@ esac cat > Makefile < Date: Tue, 13 Jun 2023 16:14:49 +0200 Subject: [PATCH 30/49] Install Zarith_version.cmx (#139) With the flambda variants of the ocaml compiler, compilation failed with `Error (warning 58 [no-cmx-file]): no cmx file was found in path for module Zarith_version, and its interface was not compiled with -opaque` --- project.mak | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/project.mak b/project.mak index 8dc72c9..018801d 100644 --- a/project.mak +++ b/project.mak @@ -38,7 +38,7 @@ MLISRC = z.mli q.mli big_int_Z.mli AUTOGEN = zarith_version.ml CMIOBJ = $(MLISRC:%.mli=%.cmi) -CMXOBJ = $(MLISRC:%.mli=%.cmx) +CMXOBJ = $(MLSRC:%.ml=%.cmx) CMIDOC = $(MLISRC:%.mli=%.cmti) TOBUILD = zarith.cma libzarith.$(LIBSUFFIX) $(CMIOBJ) zarith_top.cma z.mli From 6f840fb026ab6920104ea7b43140fdcc3e936914 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antoine=20Min=C3=A9?= Date: Tue, 13 Jun 2023 16:18:52 +0200 Subject: [PATCH 31/49] Add unsigned conversions (to|fits)_(int32|int64|nativeint)_unsigned (#113) --- caml_z.c | 358 ++++++++++++++++++++++++++++------------------ tests/zq.ml | 100 ++++++++++--- tests/zq.output32 | 160 ++++++++++++++------- tests/zq.output64 | 160 ++++++++++++++------- z.ml | 16 +++ z.mli | 60 +++++++- 6 files changed, 591 insertions(+), 263 deletions(-) diff --git a/caml_z.c b/caml_z.c index 851875a..c79626a 100644 --- a/caml_z.c +++ b/caml_z.c @@ -182,6 +182,7 @@ extern "C" { /* hi bit of OCaml int32, int64 & nativeint */ #define Z_HI_INT32 0x80000000 +#define Z_HI_UINT32 0x100000000LL #define Z_HI_INT64 0x8000000000000000LL #ifdef ARCH_SIXTYFOUR #define Z_HI_INTNAT Z_HI_INT64 @@ -695,92 +696,222 @@ CAMLprim value ml_z_of_substring_base(value b, value v, value offset, value leng CAMLreturn(r); } -CAMLprim value ml_z_to_int(value v) +/* either stores the result in r and returns 0 (no overflow), + or returns 1 and leave r undefined (overflow) +*/ +static int ml_to_int(value v, intnat* r) { - intnat x; Z_DECL(v); Z_MARK_OP; Z_CHECK(v); - if (Is_long(v)) return v; + if (Is_long(v)) { *r = v; return 0; } Z_MARK_SLOW; Z_ARG(v); - if (size_v > 1) ml_z_raise_overflow(); - if (!size_v) return Val_long(0); - x = *ptr_v; - if (sign_v) { - if ((uintnat)x > Z_HI_INT) ml_z_raise_overflow(); - x = -x; - } + if (size_v > 1) return 1; + else if (!size_v) { *r = Val_long(0); return 0; } else { - if ((uintnat)x >= Z_HI_INT) ml_z_raise_overflow(); + intnat x = *ptr_v; + if (sign_v) { + if ((uintnat)x > Z_HI_INT) return 1; + *r = Val_long(-x); + } + else { + if ((uintnat)x >= Z_HI_INT) return 1; + *r = Val_long(x); + } + return 0; } - return Val_long(x); } -CAMLprim value ml_z_to_nativeint(value v) +CAMLprim value ml_z_to_int(value v) +{ + value x; + if (ml_to_int(v, &x)) ml_z_raise_overflow(); + return x; +} + +CAMLprim value ml_z_fits_int(value v) +{ + value x; + if (ml_to_int(v, &x)) return Val_false; + return Val_true; +} + +static int ml_to_nativeint(value v, intnat* r) { - intnat x; Z_DECL(v); Z_MARK_OP; Z_CHECK(v); - if (Is_long(v)) return caml_copy_nativeint(Long_val(v)); + if (Is_long(v)) { *r = Long_val(v); return 0; } Z_MARK_SLOW; Z_ARG(v); - if (size_v > 1) ml_z_raise_overflow(); - if (!size_v) x = 0; + if (size_v > 1) return 1; + if (!size_v) { *r = 0; return 0; } else { + intnat x; x = *ptr_v; if (sign_v) { - if ((uintnat)x > Z_HI_INTNAT) ml_z_raise_overflow(); - x = -x; + if ((uintnat)x > Z_HI_INTNAT) return 1; + *r = -x; } else { - if ((uintnat)x >= Z_HI_INTNAT) ml_z_raise_overflow(); + if ((uintnat)x >= Z_HI_INTNAT) return 1; + *r = x; } + return 0; } +} + +CAMLprim value ml_z_to_nativeint(value v) +{ + intnat x; + if (ml_to_nativeint(v, &x)) ml_z_raise_overflow(); return caml_copy_nativeint(x); } -CAMLprim value ml_z_to_int32(value v) +CAMLprim value ml_z_fits_nativeint(value v) { intnat x; + if (ml_to_nativeint(v, &x)) return Val_false; + return Val_true; +} + +static int ml_to_nativeint_unsigned(value v, uintnat* r) +{ Z_DECL(v); Z_MARK_OP; Z_CHECK(v); if (Is_long(v)) { - x = Long_val(v); + intnat x = Long_val(v); + if (x < 0) return 1; + *r = (uintnat)x; + return 0; + } + Z_MARK_SLOW; + Z_ARG(v); + if (!size_v) { *r = 0; return 0; } + else if (sign_v || size_v > 1) return 1; + else { + *r = *ptr_v; + return 0; + } +} + +CAMLprim value ml_z_to_nativeint_unsigned(value v) +{ + uintnat x; + if (ml_to_nativeint_unsigned(v, &x)) ml_z_raise_overflow(); + return caml_copy_nativeint(x); +} + +CAMLprim value ml_z_fits_nativeint_unsigned(value v) +{ + uintnat x; + if (ml_to_nativeint_unsigned(v, &x)) return Val_false; + return Val_true; +} + +static int ml_to_int32(value v, int32_t* r) +{ + Z_DECL(v); + Z_MARK_OP; + Z_CHECK(v); + if (Is_long(v)) { + intnat x = Long_val(v); #ifdef ARCH_SIXTYFOUR if (x >= (intnat)Z_HI_INT32 || x < -(intnat)Z_HI_INT32) - ml_z_raise_overflow(); + return 1; #endif - return caml_copy_int32(x); + *r = x; + return 0; } else { Z_ARG(v); Z_MARK_SLOW; - if (size_v > 1) ml_z_raise_overflow(); - if (!size_v) x = 0; + if (size_v > 1) return 1; + if (!size_v) { *r = 0; return 0; } else { - x = *ptr_v; + uintnat x = *ptr_v; if (sign_v) { - if ((uintnat)x > Z_HI_INT32) ml_z_raise_overflow(); - x = -x; + if (x > Z_HI_INT32) return 1; + *r = -x; } else { - if ((uintnat)x >= Z_HI_INT32) ml_z_raise_overflow(); + if (x >= Z_HI_INT32) return 1; + *r = x; } + return 0; } - return caml_copy_int32(x); } } -CAMLprim value ml_z_to_int64(value v) +CAMLprim value ml_z_to_int32(value v) +{ + int32_t x; + if (ml_to_int32(v, &x)) ml_z_raise_overflow(); + return caml_copy_int32(x); +} + +CAMLprim value ml_z_fits_int32(value v) +{ + int32_t x; + if (ml_to_int32(v, &x)) return Val_false; + return Val_true; +} + +static int ml_to_int32_unsigned(value v, uint32_t* r) { - int64_t x = 0; Z_DECL(v); Z_MARK_OP; Z_CHECK(v); - if (Is_long(v)) return caml_copy_int64(Long_val(v)); + if (Is_long(v)) { + intnat x = Long_val(v); +#ifdef ARCH_SIXTYFOUR + if (x < 0 || x >= Z_HI_UINT32) +#else + if (x < 0) +#endif + return 1; + *r = x; + return 0; + } + else { + Z_ARG(v); + Z_MARK_SLOW; + if (!size_v) { *r = 0; return 0; } + else if (sign_v || size_v > 1) return 1; + else { + uintnat x = *ptr_v; +#ifdef ARCH_SIXTYFOUR + if (x >= Z_HI_UINT32) return 1; +#endif + *r = x; + return 0; + } + } +} + +CAMLprim value ml_z_to_int32_unsigned(value v) +{ + uint32_t x; + if (ml_to_int32_unsigned(v, &x)) ml_z_raise_overflow(); + return caml_copy_int32(x); +} + +CAMLprim value ml_z_fits_int32_unsigned(value v) +{ + uint32_t x; + if (ml_to_int32_unsigned(v, &x)) return Val_false; + return Val_true; +} + +static int ml_to_int64(value v, int64_t* r) +{ + int64_t x; + Z_DECL(v); + Z_MARK_OP; + Z_CHECK(v); + if (Is_long(v)) { *r = Long_val(v); return 0; } Z_MARK_SLOW; Z_ARG(v); switch (size_v) { @@ -789,18 +920,71 @@ CAMLprim value ml_z_to_int64(value v) #ifndef ARCH_SIXTYFOUR case 2: x = ptr_v[0] | ((uint64_t)ptr_v[1] << 32); break; #endif - default: ml_z_raise_overflow(); break; + default: return 1; } if (sign_v) { - if ((uint64_t)x > Z_HI_INT64) ml_z_raise_overflow(); - x = -x; + if ((uint64_t)x > Z_HI_INT64) return 1; + *r = -x; } else { - if ((uint64_t)x >= Z_HI_INT64) ml_z_raise_overflow(); + if ((uint64_t)x >= Z_HI_INT64) return 1; + *r = x; } + return 0; +} + +CAMLprim value ml_z_to_int64(value v) +{ + int64_t x; + if (ml_to_int64(v, &x)) ml_z_raise_overflow(); return caml_copy_int64(x); } +CAMLprim value ml_z_fits_int64(value v) +{ + int64_t x; + if (ml_to_int64(v, &x)) return Val_false; + return Val_true; +} + +static int ml_to_int64_unsigned(value v, uint64_t* r) +{ + Z_DECL(v); + Z_MARK_OP; + Z_CHECK(v); + if (Is_long(v)) { + intnat x = Long_val(v); + if (x < 0) return 1; + *r = x; + return 0; + } + Z_MARK_SLOW; + Z_ARG(v); + if (sign_v) return 1; + switch (size_v) { + case 0: *r = 0; return 0; + case 1: *r = ptr_v[0]; return 0; +#ifndef ARCH_SIXTYFOUR + case 2: *r = ptr_v[0] | ((uint64_t) ptr_v[1] << 32); return 0; +#endif + default: return 1; + } +} + +CAMLprim value ml_z_to_int64_unsigned(value v) +{ + uint64_t x; + if (ml_to_int64_unsigned(v, &x)) ml_z_raise_overflow(); + return caml_copy_int64(x); +} + +CAMLprim value ml_z_fits_int64_unsigned(value v) +{ + uint64_t x; + if (ml_to_int64_unsigned(v, &x)) return Val_false; + return Val_true; +} + /* XXX: characters that do not belong to the format are ignored, this departs from the classic printf behavior (it copies them in the output) */ @@ -1168,104 +1352,6 @@ CAMLprim value ml_z_sign(value arg) return Val_long(ml_z_sgn(arg)); } -CAMLprim value ml_z_fits_int(value v) -{ - intnat x; - Z_DECL(v); - Z_MARK_OP; - Z_CHECK(v); - if (Is_long(v)) return Val_true; - Z_MARK_SLOW; - Z_ARG(v); - if (size_v > 1) return Val_false; - if (!size_v) return Val_true; - x = *ptr_v; - if (sign_v) { - if ((uintnat)x > Z_HI_INT) return Val_false; - } - else { - if ((uintnat)x >= Z_HI_INT) return Val_false; - } - return Val_true; -} - -CAMLprim value ml_z_fits_nativeint(value v) -{ - intnat x; - Z_DECL(v); - Z_MARK_OP; - Z_CHECK(v); - if (Is_long(v)) return Val_true; - Z_MARK_SLOW; - Z_ARG(v); - if (size_v > 1) return Val_false; - if (!size_v) return Val_true; - x = *ptr_v; - if (sign_v) { - if ((uintnat)x > Z_HI_INTNAT) return Val_false; - } - else { - if ((uintnat)x >= Z_HI_INTNAT) return Val_false; - } - return Val_true; -} - -CAMLprim value ml_z_fits_int32(value v) -{ - intnat x; - Z_MARK_OP; - Z_CHECK(v); - if (Is_long(v)) { -#ifdef ARCH_SIXTYFOUR - x = Long_val(v); - if (x >= (intnat)Z_HI_INT32 || x < -(intnat)Z_HI_INT32) - return Val_false; -#endif - return Val_true; - } - else { - Z_DECL(v); - Z_MARK_SLOW; - Z_ARG(v); - if (size_v > 1) return Val_false; - if (!size_v) return Val_true; - x = *ptr_v; - if (sign_v) { - if ((uintnat)x > Z_HI_INT32) return Val_false; - } - else { - if ((uintnat)x >= Z_HI_INT32) return Val_false; - } - return Val_true; - } -} - -CAMLprim value ml_z_fits_int64(value v) -{ - int64_t x; - Z_DECL(v); - Z_MARK_OP; - Z_CHECK(v); - if (Is_long(v)) return Val_true; - Z_MARK_SLOW; - Z_ARG(v); - switch (size_v) { - case 0: return Val_true; - case 1: x = ptr_v[0]; break; -#ifndef ARCH_SIXTYFOUR - case 2: x = ptr_v[0] | ((uint64_t)ptr_v[1] << 32); break; -#endif - default: return Val_false; - } - if (sign_v) { - if ((uint64_t)x > Z_HI_INT64) return Val_false; - } - else { - if ((uint64_t)x >= Z_HI_INT64) return Val_false; - } - return Val_true; -} - CAMLprim value ml_z_size(value v) { Z_MARK_OP; diff --git a/tests/zq.ml b/tests/zq.ml index 2a0bc16..1cb1115 100644 --- a/tests/zq.ml +++ b/tests/zq.ml @@ -68,12 +68,43 @@ let pow a b = in doit b -let cvt_int x = try string_of_int (I.to_int x) with I.Overflow -> "ovf" -let cvt_int32 x = try Int32.to_string (I.to_int32 x) with I.Overflow -> "ovf" -let cvt_int64 x = try Int64.to_string (I.to_int64 x) with I.Overflow -> "ovf" -let cvt_nativeint x = try Nativeint.to_string (I.to_nativeint x) with I.Overflow -> "ovf" +let cvt_int x = + (string_of_bool (I.fits_int x)) + ^","^ + (try string_of_int (I.to_int x) with I.Overflow -> "ovf") + +let cvt_int32 x = + (string_of_bool (I.fits_int32 x)) + ^","^ + (try Int32.to_string (I.to_int32 x) with I.Overflow -> "ovf") + +let cvt_int64 x = + (string_of_bool (I.fits_int64 x)) + ^","^ + (try Int64.to_string (I.to_int64 x) with I.Overflow -> "ovf") + +let cvt_nativeint x = + (string_of_bool (I.fits_nativeint x)) + ^","^ + (try Nativeint.to_string (I.to_nativeint x) with I.Overflow -> "ovf") + +let cvt_int32_unsigned x = + (string_of_bool (I.fits_int32_unsigned x)) + ^","^ + (try Int32.to_string (I.to_int32_unsigned x) with I.Overflow -> "ovf") + +let cvt_int64_unsigned x = + (string_of_bool (I.fits_int64_unsigned x)) + ^","^ + (try Int64.to_string (I.to_int64_unsigned x) with I.Overflow -> "ovf") + +let cvt_nativeint_unsigned x = + (string_of_bool (I.fits_nativeint_unsigned x)) + ^","^ + (try Nativeint.to_string (I.to_nativeint_unsigned x) with I.Overflow -> "ovf") let p2 = I.of_int 2 +let p3 = I.of_int 3 let p30 = pow2 30 let p62 = pow2 62 let p300 = pow2 300 @@ -267,45 +298,74 @@ let test_Z() = Printf.printf "abs(min_int)\n = %a\n" pr (I.abs mini); Printf.printf "abs(2^300)\n = %a\n" pr (I.abs p300); Printf.printf "abs(-(2^300))\n = %a\n" pr (I.abs (I.neg p300)); - Printf.printf "max_natint\n = %a\n" pr maxni; + Printf.printf "max_nativeint\n = %a\n" pr maxni; Printf.printf "max_int32\n = %a\n" pr maxi32; Printf.printf "max_int64\n = %a\n" pr maxi64; Printf.printf "to_int 1\n = %s\n" (cvt_int I.one); Printf.printf "to_int max_int\n = %s\n" (cvt_int maxi); - Printf.printf "to_int max_natint\n = %s\n" (cvt_int maxni); + Printf.printf "to_int max_nativeint\n = %s\n" (cvt_int maxni); Printf.printf "to_int max_int32\n = %s\n" (cvt_int maxi32); Printf.printf "to_int max_int64\n = %s\n" (cvt_int maxi64); Printf.printf "to_int32 1\n = %s\n" (cvt_int32 I.one); Printf.printf "to_int32 max_int\n = %s\n" (cvt_int32 maxi); - Printf.printf "to_int32 max_natint\n = %s\n" (cvt_int32 maxni); + Printf.printf "to_int32 max_nativeint\n = %s\n" (cvt_int32 maxni); Printf.printf "to_int32 max_int32\n = %s\n" (cvt_int32 maxi32); Printf.printf "to_int32 max_int64\n = %s\n" (cvt_int32 maxi64); Printf.printf "to_int64 1\n = %s\n" (cvt_int64 I.one); Printf.printf "to_int64 max_int\n = %s\n" (cvt_int64 maxi); - Printf.printf "to_int64 max_natint\n = %s\n" (cvt_int64 maxni); + Printf.printf "to_int64 max_nativeint\n = %s\n" (cvt_int64 maxni); Printf.printf "to_int64 max_int32\n = %s\n" (cvt_int64 maxi32); Printf.printf "to_int64 max_int64\n = %s\n" (cvt_int64 maxi64); - Printf.printf "to_natint 1\n = %s\n" (cvt_nativeint I.one); - Printf.printf "to_natint max_int\n = %s\n" (cvt_nativeint maxi); - Printf.printf "to_natint max_natint\n = %s\n" (cvt_nativeint maxni); - Printf.printf "to_natint max_int32\n = %s\n" (cvt_nativeint maxi32); - Printf.printf "to_natint max_int64\n = %s\n" (cvt_nativeint maxi64); + Printf.printf "to_nativeint 1\n = %s\n" (cvt_nativeint I.one); + Printf.printf "to_nativeint max_int\n = %s\n" (cvt_nativeint maxi); + Printf.printf "to_nativeint max_nativeint\n = %s\n" (cvt_nativeint maxni); + Printf.printf "to_nativeint max_int32\n = %s\n" (cvt_nativeint maxi32); + Printf.printf "to_nativeint max_int64\n = %s\n" (cvt_nativeint maxi64); Printf.printf "to_int -min_int\n = %s\n" (cvt_int (I.neg mini)); - Printf.printf "to_int -min_natint\n = %s\n" (cvt_int (I.neg minni)); + Printf.printf "to_int -min_nativeint\n = %s\n" (cvt_int (I.neg minni)); Printf.printf "to_int -min_int32\n = %s\n" (cvt_int (I.neg mini32)); Printf.printf "to_int -min_int64\n = %s\n" (cvt_int (I.neg mini64)); Printf.printf "to_int32 -min_int\n = %s\n" (cvt_int32 (I.neg mini)); - Printf.printf "to_int32 -min_natint\n = %s\n" (cvt_int32 (I.neg minni)); + Printf.printf "to_int32 -min_nativeint\n = %s\n" (cvt_int32 (I.neg minni)); Printf.printf "to_int32 -min_int32\n = %s\n" (cvt_int32 (I.neg mini32)); Printf.printf "to_int32 -min_int64\n = %s\n" (cvt_int32(I.neg mini64)); Printf.printf "to_int64 -min_int\n = %s\n" (cvt_int64 (I.neg mini)); - Printf.printf "to_int64 -min_natint\n = %s\n" (cvt_int64 (I.neg minni)); + Printf.printf "to_int64 -min_nativeint\n = %s\n" (cvt_int64 (I.neg minni)); Printf.printf "to_int64 -min_int32\n = %s\n" (cvt_int64 (I.neg mini32)); Printf.printf "to_int64 -min_int64\n = %s\n" (cvt_int64 (I.neg mini64)); - Printf.printf "to_natint -min_int\n = %s\n" (cvt_nativeint (I.neg mini)); - Printf.printf "to_natint -min_natint\n = %s\n" (cvt_nativeint (I.neg minni)); - Printf.printf "to_natint -min_int32\n = %s\n" (cvt_nativeint (I.neg mini32)); - Printf.printf "to_natint -min_int64\n = %s\n" (cvt_nativeint (I.neg mini64)); + Printf.printf "to_nativeint -min_int\n = %s\n" (cvt_nativeint (I.neg mini)); + Printf.printf "to_nativeint -min_nativeint\n = %s\n" (cvt_nativeint (I.neg minni)); + Printf.printf "to_nativeint -min_int32\n = %s\n" (cvt_nativeint (I.neg mini32)); + Printf.printf "to_nativeint -min_int64\n = %s\n" (cvt_nativeint (I.neg mini64)); + Printf.printf "to_int32_unsigned 1\n = %s\n" (cvt_int32_unsigned I.one); + Printf.printf "to_int32_unsigned -1\n = %s\n" (cvt_int32_unsigned I.minus_one); + Printf.printf "to_int32_unsigned max_int\n = %s\n" (cvt_int32_unsigned maxi); + Printf.printf "to_int32_unsigned max_nativeint\n = %s\n" (cvt_int32_unsigned maxni); + Printf.printf "to_int32_unsigned max_int32\n = %s\n" (cvt_int32_unsigned maxi32); + Printf.printf "to_int32_unsigned 2max_int32\n = %s\n" (cvt_int32_unsigned (I.mul p2 maxi32)); + Printf.printf "to_int32_unsigned 3max_int32\n = %s\n" (cvt_int32_unsigned (I.mul p3 maxi32)); + Printf.printf "to_int32_unsigned max_int64\n = %s\n" (cvt_int32_unsigned maxi64); + Printf.printf "to_int64_unsigned 1\n = %s\n" (cvt_int64_unsigned I.one); + Printf.printf "to_int64_unsigned -1\n = %s\n" (cvt_int64_unsigned I.minus_one); + Printf.printf "to_int64_unsigned max_int\n = %s\n" (cvt_int64_unsigned maxi); + Printf.printf "to_int64_unsigned max_nativeint\n = %s\n" (cvt_int64_unsigned maxni); + Printf.printf "to_int64_unsigned max_int32\n = %s\n" (cvt_int64_unsigned maxi32); + Printf.printf "to_int64_unsigned max_int64\n = %s\n" (cvt_int64_unsigned maxi64); + Printf.printf "to_int64_unsigned 2max_int64\n = %s\n" (cvt_int64_unsigned (I.mul p2 maxi64)); + Printf.printf "to_int64_unsigned 3max_int64\n = %s\n" (cvt_int64_unsigned (I.mul p3 maxi64)); + Printf.printf "to_nativeint_unsigned 1\n = %s\n" (cvt_nativeint_unsigned I.one); + Printf.printf "to_nativeint_unsigned -1\n = %s\n" (cvt_nativeint_unsigned I.minus_one); + Printf.printf "to_nativeint_unsigned max_int\n = %s\n" (cvt_nativeint_unsigned maxi); + Printf.printf "to_nativeint_unsigned max_nativeint\n = %s\n" (cvt_nativeint_unsigned maxni); + Printf.printf "to_nativeint_unsigned 2max_nativeint\n = %s\n" (cvt_nativeint_unsigned (I.mul p2 maxni)); + Printf.printf "to_nativeint_unsigned max_int32\n = %s\n" (cvt_nativeint_unsigned maxi32); + Printf.printf "to_nativeint_unsigned max_int64\n = %s\n" (cvt_nativeint_unsigned maxi64); + Printf.printf "to_nativeint_unsigned 2max_int64\n = %s\n" (cvt_nativeint_unsigned (I.mul p2 maxi64)); + Printf.printf "to_nativeint_unsigned 3max_int64\n = %s\n" (cvt_nativeint_unsigned (I.mul p3 maxi64)); + Printf.printf "of_int32_unsigned -1\n = %a\n" pr (I.of_int32_unsigned (-1l)); + Printf.printf "of_int64_unsigned -1\n = %a\n" pr (I.of_int64_unsigned (-1L)); + Printf.printf "of_nativeint_unsigned -1\n = %a\n" pr (I.of_nativeint_unsigned (-1n)); + Printf.printf "of_float 1.\n = %a\n" pr (I.of_float 1.); Printf.printf "of_float -1.\n = %a\n" pr (I.of_float (-. 1.)); Printf.printf "of_float pi\n = %a\n" pr (I.of_float (2. *. acos 0.)); diff --git a/tests/zq.output32 b/tests/zq.output32 index 16c42d5..b22a85c 100644 --- a/tests/zq.output32 +++ b/tests/zq.output32 @@ -202,84 +202,140 @@ abs(2^300) = 2037035976334486086268445688409378161051468393665936250636140449354381299763336706183397376 abs(-(2^300)) = 2037035976334486086268445688409378161051468393665936250636140449354381299763336706183397376 -max_natint +max_nativeint = 2147483647 max_int32 = 2147483647 max_int64 = 9223372036854775807 to_int 1 - = 1 + = true,1 to_int max_int - = 1073741823 -to_int max_natint - = ovf + = true,1073741823 +to_int max_nativeint + = false,ovf to_int max_int32 - = ovf + = false,ovf to_int max_int64 - = ovf + = false,ovf to_int32 1 - = 1 + = true,1 to_int32 max_int - = 1073741823 -to_int32 max_natint - = 2147483647 + = true,1073741823 +to_int32 max_nativeint + = true,2147483647 to_int32 max_int32 - = 2147483647 + = true,2147483647 to_int32 max_int64 - = ovf + = false,ovf to_int64 1 - = 1 + = true,1 to_int64 max_int - = 1073741823 -to_int64 max_natint - = 2147483647 + = true,1073741823 +to_int64 max_nativeint + = true,2147483647 to_int64 max_int32 - = 2147483647 + = true,2147483647 to_int64 max_int64 - = 9223372036854775807 -to_natint 1 - = 1 -to_natint max_int - = 1073741823 -to_natint max_natint - = 2147483647 -to_natint max_int32 - = 2147483647 -to_natint max_int64 - = ovf + = true,9223372036854775807 +to_nativeint 1 + = true,1 +to_nativeint max_int + = true,1073741823 +to_nativeint max_nativeint + = true,2147483647 +to_nativeint max_int32 + = true,2147483647 +to_nativeint max_int64 + = false,ovf to_int -min_int - = ovf -to_int -min_natint - = ovf + = false,ovf +to_int -min_nativeint + = false,ovf to_int -min_int32 - = ovf + = false,ovf to_int -min_int64 - = ovf + = false,ovf to_int32 -min_int - = 1073741824 -to_int32 -min_natint - = ovf + = true,1073741824 +to_int32 -min_nativeint + = false,ovf to_int32 -min_int32 - = ovf + = false,ovf to_int32 -min_int64 - = ovf + = false,ovf to_int64 -min_int - = 1073741824 -to_int64 -min_natint - = 2147483648 + = true,1073741824 +to_int64 -min_nativeint + = true,2147483648 to_int64 -min_int32 - = 2147483648 + = true,2147483648 to_int64 -min_int64 - = ovf -to_natint -min_int - = 1073741824 -to_natint -min_natint - = ovf -to_natint -min_int32 - = ovf -to_natint -min_int64 - = ovf + = false,ovf +to_nativeint -min_int + = true,1073741824 +to_nativeint -min_nativeint + = false,ovf +to_nativeint -min_int32 + = false,ovf +to_nativeint -min_int64 + = false,ovf +to_int32_unsigned 1 + = true,1 +to_int32_unsigned -1 + = false,ovf +to_int32_unsigned max_int + = true,1073741823 +to_int32_unsigned max_nativeint + = true,2147483647 +to_int32_unsigned max_int32 + = true,2147483647 +to_int32_unsigned 2max_int32 + = true,-2 +to_int32_unsigned 3max_int32 + = false,ovf +to_int32_unsigned max_int64 + = false,ovf +to_int64_unsigned 1 + = true,1 +to_int64_unsigned -1 + = false,ovf +to_int64_unsigned max_int + = true,1073741823 +to_int64_unsigned max_nativeint + = true,2147483647 +to_int64_unsigned max_int32 + = true,2147483647 +to_int64_unsigned max_int64 + = true,9223372036854775807 +to_int64_unsigned 2max_int64 + = true,-2 +to_int64_unsigned 3max_int64 + = false,ovf +to_nativeint_unsigned 1 + = true,1 +to_nativeint_unsigned -1 + = false,ovf +to_nativeint_unsigned max_int + = true,1073741823 +to_nativeint_unsigned max_nativeint + = true,2147483647 +to_nativeint_unsigned 2max_nativeint + = true,-2 +to_nativeint_unsigned max_int32 + = true,2147483647 +to_nativeint_unsigned max_int64 + = false,ovf +to_nativeint_unsigned 2max_int64 + = false,ovf +to_nativeint_unsigned 3max_int64 + = false,ovf +of_int32_unsigned -1 + = 4294967295 +of_int64_unsigned -1 + = 18446744073709551615 +of_nativeint_unsigned -1 + = 4294967295 of_float 1. = 1 of_float -1. diff --git a/tests/zq.output64 b/tests/zq.output64 index 2404fab..61bd14e 100644 --- a/tests/zq.output64 +++ b/tests/zq.output64 @@ -202,84 +202,140 @@ abs(2^300) = 2037035976334486086268445688409378161051468393665936250636140449354381299763336706183397376 abs(-(2^300)) = 2037035976334486086268445688409378161051468393665936250636140449354381299763336706183397376 -max_natint +max_nativeint = 9223372036854775807 max_int32 = 2147483647 max_int64 = 9223372036854775807 to_int 1 - = 1 + = true,1 to_int max_int - = 4611686018427387903 -to_int max_natint - = ovf + = true,4611686018427387903 +to_int max_nativeint + = false,ovf to_int max_int32 - = 2147483647 + = true,2147483647 to_int max_int64 - = ovf + = false,ovf to_int32 1 - = 1 + = true,1 to_int32 max_int - = ovf -to_int32 max_natint - = ovf + = false,ovf +to_int32 max_nativeint + = false,ovf to_int32 max_int32 - = 2147483647 + = true,2147483647 to_int32 max_int64 - = ovf + = false,ovf to_int64 1 - = 1 + = true,1 to_int64 max_int - = 4611686018427387903 -to_int64 max_natint - = 9223372036854775807 + = true,4611686018427387903 +to_int64 max_nativeint + = true,9223372036854775807 to_int64 max_int32 - = 2147483647 + = true,2147483647 to_int64 max_int64 - = 9223372036854775807 -to_natint 1 - = 1 -to_natint max_int - = 4611686018427387903 -to_natint max_natint - = 9223372036854775807 -to_natint max_int32 - = 2147483647 -to_natint max_int64 - = 9223372036854775807 + = true,9223372036854775807 +to_nativeint 1 + = true,1 +to_nativeint max_int + = true,4611686018427387903 +to_nativeint max_nativeint + = true,9223372036854775807 +to_nativeint max_int32 + = true,2147483647 +to_nativeint max_int64 + = true,9223372036854775807 to_int -min_int - = ovf -to_int -min_natint - = ovf + = false,ovf +to_int -min_nativeint + = false,ovf to_int -min_int32 - = 2147483648 + = true,2147483648 to_int -min_int64 - = ovf + = false,ovf to_int32 -min_int - = ovf -to_int32 -min_natint - = ovf + = false,ovf +to_int32 -min_nativeint + = false,ovf to_int32 -min_int32 - = ovf + = false,ovf to_int32 -min_int64 - = ovf + = false,ovf to_int64 -min_int - = 4611686018427387904 -to_int64 -min_natint - = ovf + = true,4611686018427387904 +to_int64 -min_nativeint + = false,ovf to_int64 -min_int32 - = 2147483648 + = true,2147483648 to_int64 -min_int64 - = ovf -to_natint -min_int - = 4611686018427387904 -to_natint -min_natint - = ovf -to_natint -min_int32 - = 2147483648 -to_natint -min_int64 - = ovf + = false,ovf +to_nativeint -min_int + = true,4611686018427387904 +to_nativeint -min_nativeint + = false,ovf +to_nativeint -min_int32 + = true,2147483648 +to_nativeint -min_int64 + = false,ovf +to_int32_unsigned 1 + = true,1 +to_int32_unsigned -1 + = false,ovf +to_int32_unsigned max_int + = false,ovf +to_int32_unsigned max_nativeint + = false,ovf +to_int32_unsigned max_int32 + = true,2147483647 +to_int32_unsigned 2max_int32 + = true,-2 +to_int32_unsigned 3max_int32 + = false,ovf +to_int32_unsigned max_int64 + = false,ovf +to_int64_unsigned 1 + = true,1 +to_int64_unsigned -1 + = false,ovf +to_int64_unsigned max_int + = true,4611686018427387903 +to_int64_unsigned max_nativeint + = true,9223372036854775807 +to_int64_unsigned max_int32 + = true,2147483647 +to_int64_unsigned max_int64 + = true,9223372036854775807 +to_int64_unsigned 2max_int64 + = true,-2 +to_int64_unsigned 3max_int64 + = false,ovf +to_nativeint_unsigned 1 + = true,1 +to_nativeint_unsigned -1 + = false,ovf +to_nativeint_unsigned max_int + = true,4611686018427387903 +to_nativeint_unsigned max_nativeint + = true,9223372036854775807 +to_nativeint_unsigned 2max_nativeint + = true,-2 +to_nativeint_unsigned max_int32 + = true,2147483647 +to_nativeint_unsigned max_int64 + = true,9223372036854775807 +to_nativeint_unsigned 2max_int64 + = true,-2 +to_nativeint_unsigned 3max_int64 + = false,ovf +of_int32_unsigned -1 + = 4294967295 +of_int64_unsigned -1 + = 18446744073709551615 +of_nativeint_unsigned -1 + = 18446744073709551615 of_float 1. = 1 of_float -1. diff --git a/z.ml b/z.ml index fb62db5..772621d 100644 --- a/z.ml +++ b/z.ml @@ -206,6 +206,15 @@ external of_int64: int64 -> t = "ml_z_of_int64" external of_nativeint: nativeint -> t = "ml_z_of_nativeint" external of_float: float -> t = "ml_z_of_float" +let uint32_mask = pred (shift_left (of_int 1) 32) +let of_int32_unsigned x = logand (of_int32 x) uint32_mask + +let uint64_mask = pred (shift_left (of_int 1) 64) +let of_int64_unsigned x = logand (of_int64 x) uint64_mask + +let uintnat_mask = pred (shift_left (of_int 1) Nativeint.size) +let of_nativeint_unsigned x = logand (of_nativeint x) uintnat_mask + external c_to_int: t -> int = "ml_z_to_int" let to_int x = @@ -214,6 +223,9 @@ let to_int x = external to_int32: t -> int32 = "ml_z_to_int32" external to_int64: t -> int64 = "ml_z_to_int64" external to_nativeint: t -> nativeint = "ml_z_to_nativeint" +external to_int32_unsigned: t -> int32 = "ml_z_to_int32_unsigned" +external to_int64_unsigned: t -> int64 = "ml_z_to_int64_unsigned" +external to_nativeint_unsigned: t -> nativeint = "ml_z_to_nativeint_unsigned" external format: string -> t -> string = "ml_z_format" external of_substring_base: int -> string -> pos:int -> len:int -> t = "ml_z_of_substring_base" external compare: t -> t -> int = "ml_z_compare" [@@noalloc] @@ -232,6 +244,10 @@ external fits_int: t -> bool = "ml_z_fits_int" [@@noalloc] external fits_int32: t -> bool = "ml_z_fits_int32" [@@noalloc] external fits_int64: t -> bool = "ml_z_fits_int64" [@@noalloc] external fits_nativeint: t -> bool = "ml_z_fits_nativeint" [@@noalloc] +external fits_int32_unsigned: t -> bool = "ml_z_fits_int32_unsigned" [@@noalloc] +external fits_int64_unsigned: t -> bool = "ml_z_fits_int64_unsigned" [@@noalloc] +external fits_nativeint_unsigned: t -> bool = "ml_z_fits_nativeint_unsigned" [@@noalloc] +external extract: t -> int -> int -> t = "ml_z_extract" external powm: t -> t -> t -> t = "ml_z_powm" external pow: t -> int -> t = "ml_z_pow" external powm_sec: t -> t -> t -> t = "ml_z_powm_sec" diff --git a/z.mli b/z.mli index 1e8d580..cbbf7c5 100644 --- a/z.mli +++ b/z.mli @@ -69,13 +69,28 @@ external of_int: int -> t = "%identity" (** Converts from a base integer. *) external of_int32: int32 -> t = "ml_z_of_int32" -(** Converts from a 32-bit integer. *) +(** Converts from a 32-bit (signed) integer. *) external of_int64: int64 -> t = "ml_z_of_int64" -(** Converts from a 64-bit integer. *) +(** Converts from a 64-bit (signed) integer. *) external of_nativeint: nativeint -> t = "ml_z_of_nativeint" -(** Converts from a native integer. *) +(** Converts from a native (signed) integer. *) + +val of_int32_unsigned: int32 -> t +(** Converts from a 32-bit integer, interpreted as an unsigned integer. + @since 1.13 + *) + +val of_int64_unsigned: int64 -> t +(** Converts from a 64-bit integer, interpreted as an unsigned integer. + @since 1.13 + *) + +val of_nativeint_unsigned: nativeint -> t +(** Converts from a native integer, interpreted as an unsigned integer.. + @since 1.13 + *) external of_float: float -> t = "ml_z_of_float" (** Converts from a floating-point value. @@ -312,6 +327,30 @@ external to_nativeint: t -> nativeint = "ml_z_to_nativeint" (** Converts to a native signed integer [nativeint]. Raises an [Overflow] if the value does not fit in a signed [nativeint]. *) +external to_int32_unsigned: t -> int32 = "ml_z_to_int32_unsigned" +(** Converts to an unsigned 32-bit integer. + The result is stored into an OCaml [int32]. + Beware that most [Int32] operations consider [int32] to a signed type, not unsigned. + Raises an [Overflow] if the value is negative or does not fit in an unsigned 32-bit integer. + @since 1.13 +*) + +external to_int64_unsigned: t -> int64 = "ml_z_to_int64_unsigned" +(** Converts to an unsigned 64-bit integer. + The result is stored into an OCaml [int64]. + Beware that most [Int64] operations consider [int64] to a signed type, not unsigned. + Raises an [Overflow] if the value is negative or does not fit in an unsigned 64-bit integer. + @since 1.13 + *) + +external to_nativeint_unsigned: t -> nativeint = "ml_z_to_nativeint_unsigned" +(** Converts to a native unsigned integer. + The result is stored into an OCaml [nativeint]. + Beware that most [Nativeint] operations consider [nativeint] to a signed type, not unsigned. + Raises an [Overflow] if the value is negative or does not fit in an unsigned native integer. + @since 1.13 + *) + val to_float: t -> float (** Converts to a floating-point value. This function rounds the given integer according to the current @@ -362,6 +401,21 @@ external fits_int64: t -> bool = "ml_z_fits_int64" [@@noalloc] external fits_nativeint: t -> bool = "ml_z_fits_nativeint" [@@noalloc] (** Whether the argument fits in a signed [nativeint]. *) +external fits_int32_unsigned: t -> bool = "ml_z_fits_int32_unsigned" [@@noalloc] +(** Whether the argument is non-negative and fits in an unsigned [int32]. + @since 1.13 + *) + +external fits_int64_unsigned: t -> bool = "ml_z_fits_int64_unsigned" [@@noalloc] +(** Whether the argument is non-negative and fits in an unsigned [int64]. + @since 1.13 +*) + +external fits_nativeint_unsigned: t -> bool = "ml_z_fits_nativeint_unsigned" [@@noalloc] +(** Whether the argument is non-negative fits in an unsigned [nativeint]. + @since 1.13 + *) + (** {1 Printing} *) From 5a0e433d011c21c58025bc467f1271d0cc060564 Mon Sep 17 00:00:00 2001 From: hhugo Date: Tue, 18 Jul 2023 10:52:45 +0200 Subject: [PATCH 32/49] Configuration fix for Windows (#141) When testing for the availability of a library, don't pass compilation flags to the linker: they are not relevant and flexdll may not recognize them. Co-authored-by: Hugo Heuzard --- .gitattributes | 1 + configure | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitattributes b/.gitattributes index 3aa538a..8f48a14 100644 --- a/.gitattributes +++ b/.gitattributes @@ -2,3 +2,4 @@ * text=auto configure text eol=lf +config.guess text eol=lf diff --git a/configure b/configure index 6e87fe9..1d5833d 100755 --- a/configure +++ b/configure @@ -161,7 +161,7 @@ checklib() rm -f tmp.ml tmp.out echo "" > tmp.ml r=1 - $ocamlc -custom -ccopt "$ccopt $ldflags $cclib" tmp.ml -cclib -l$1 -o tmp.out >/dev/null 2>/dev/null || r=0 + $ocamlc -custom -ccopt "$ldflags $cclib" tmp.ml -cclib -l$1 -o tmp.out >/dev/null 2>/dev/null || r=0 if test ! -x tmp.out; then r=0; fi rm -f tmp.out tmp.ml tmp.cmi tmp.cmo if test $r -eq 0; then echo "not found"; else echo "found"; fi From ba6ebd7b6adeaa23eac0ab12f5de9e69e5d124ce Mon Sep 17 00:00:00 2001 From: Xavier Leroy Date: Sun, 26 Feb 2023 18:25:45 +0100 Subject: [PATCH 33/49] Remove host detection and config.guess script We no longer need it to select between assembly files. --- config.guess | 1774 -------------------------------------------------- configure | 10 - 2 files changed, 1784 deletions(-) delete mode 100644 config.guess diff --git a/config.guess b/config.guess deleted file mode 100644 index 69188da..0000000 --- a/config.guess +++ /dev/null @@ -1,1774 +0,0 @@ -#! /bin/sh -# Attempt to guess a canonical system name. -# Copyright 1992-2023 Free Software Foundation, Inc. - -# shellcheck disable=SC2006,SC2268 # see below for rationale - -timestamp='2023-01-01' - -# This file is free software; you can redistribute it and/or modify it -# under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, but -# WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, see . -# -# As a special exception to the GNU General Public License, if you -# distribute this file as part of a program that contains a -# configuration script generated by Autoconf, you may include it under -# the same distribution terms that you use for the rest of that -# program. This Exception is an additional permission under section 7 -# of the GNU General Public License, version 3 ("GPLv3"). -# -# Originally written by Per Bothner; maintained since 2000 by Ben Elliston. -# -# You can get the latest version of this script from: -# https://git.savannah.gnu.org/cgit/config.git/plain/config.guess -# -# Please send patches to . - - -# The "shellcheck disable" line above the timestamp inhibits complaints -# about features and limitations of the classic Bourne shell that were -# superseded or lifted in POSIX. However, this script identifies a wide -# variety of pre-POSIX systems that do not have POSIX shells at all, and -# even some reasonably current systems (Solaris 10 as case-in-point) still -# have a pre-POSIX /bin/sh. - - -me=`echo "$0" | sed -e 's,.*/,,'` - -usage="\ -Usage: $0 [OPTION] - -Output the configuration name of the system \`$me' is run on. - -Options: - -h, --help print this help, then exit - -t, --time-stamp print date of last modification, then exit - -v, --version print version number, then exit - -Report bugs and patches to ." - -version="\ -GNU config.guess ($timestamp) - -Originally written by Per Bothner. -Copyright 1992-2023 Free Software Foundation, Inc. - -This is free software; see the source for copying conditions. There is NO -warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE." - -help=" -Try \`$me --help' for more information." - -# Parse command line -while test $# -gt 0 ; do - case $1 in - --time-stamp | --time* | -t ) - echo "$timestamp" ; exit ;; - --version | -v ) - echo "$version" ; exit ;; - --help | --h* | -h ) - echo "$usage"; exit ;; - -- ) # Stop option processing - shift; break ;; - - ) # Use stdin as input. - break ;; - -* ) - echo "$me: invalid option $1$help" >&2 - exit 1 ;; - * ) - break ;; - esac -done - -if test $# != 0; then - echo "$me: too many arguments$help" >&2 - exit 1 -fi - -# Just in case it came from the environment. -GUESS= - -# CC_FOR_BUILD -- compiler used by this script. Note that the use of a -# compiler to aid in system detection is discouraged as it requires -# temporary files to be created and, as you can see below, it is a -# headache to deal with in a portable fashion. - -# Historically, `CC_FOR_BUILD' used to be named `HOST_CC'. We still -# use `HOST_CC' if defined, but it is deprecated. - -# Portable tmp directory creation inspired by the Autoconf team. - -tmp= -# shellcheck disable=SC2172 -trap 'test -z "$tmp" || rm -fr "$tmp"' 0 1 2 13 15 - -set_cc_for_build() { - # prevent multiple calls if $tmp is already set - test "$tmp" && return 0 - : "${TMPDIR=/tmp}" - # shellcheck disable=SC2039,SC3028 - { tmp=`(umask 077 && mktemp -d "$TMPDIR/cgXXXXXX") 2>/dev/null` && test -n "$tmp" && test -d "$tmp" ; } || - { test -n "$RANDOM" && tmp=$TMPDIR/cg$$-$RANDOM && (umask 077 && mkdir "$tmp" 2>/dev/null) ; } || - { tmp=$TMPDIR/cg-$$ && (umask 077 && mkdir "$tmp" 2>/dev/null) && echo "Warning: creating insecure temp directory" >&2 ; } || - { echo "$me: cannot create a temporary directory in $TMPDIR" >&2 ; exit 1 ; } - dummy=$tmp/dummy - case ${CC_FOR_BUILD-},${HOST_CC-},${CC-} in - ,,) echo "int x;" > "$dummy.c" - for driver in cc gcc c89 c99 ; do - if ($driver -c -o "$dummy.o" "$dummy.c") >/dev/null 2>&1 ; then - CC_FOR_BUILD=$driver - break - fi - done - if test x"$CC_FOR_BUILD" = x ; then - CC_FOR_BUILD=no_compiler_found - fi - ;; - ,,*) CC_FOR_BUILD=$CC ;; - ,*,*) CC_FOR_BUILD=$HOST_CC ;; - esac -} - -# This is needed to find uname on a Pyramid OSx when run in the BSD universe. -# (ghazi@noc.rutgers.edu 1994-08-24) -if test -f /.attbin/uname ; then - PATH=$PATH:/.attbin ; export PATH -fi - -UNAME_MACHINE=`(uname -m) 2>/dev/null` || UNAME_MACHINE=unknown -UNAME_RELEASE=`(uname -r) 2>/dev/null` || UNAME_RELEASE=unknown -UNAME_SYSTEM=`(uname -s) 2>/dev/null` || UNAME_SYSTEM=unknown -UNAME_VERSION=`(uname -v) 2>/dev/null` || UNAME_VERSION=unknown - -case $UNAME_SYSTEM in -Linux|GNU|GNU/*) - LIBC=unknown - - set_cc_for_build - cat <<-EOF > "$dummy.c" - #include - #if defined(__UCLIBC__) - LIBC=uclibc - #elif defined(__dietlibc__) - LIBC=dietlibc - #elif defined(__GLIBC__) - LIBC=gnu - #else - #include - /* First heuristic to detect musl libc. */ - #ifdef __DEFINED_va_list - LIBC=musl - #endif - #endif - EOF - cc_set_libc=`$CC_FOR_BUILD -E "$dummy.c" 2>/dev/null | grep '^LIBC' | sed 's, ,,g'` - eval "$cc_set_libc" - - # Second heuristic to detect musl libc. - if [ "$LIBC" = unknown ] && - command -v ldd >/dev/null && - ldd --version 2>&1 | grep -q ^musl; then - LIBC=musl - fi - - # If the system lacks a compiler, then just pick glibc. - # We could probably try harder. - if [ "$LIBC" = unknown ]; then - LIBC=gnu - fi - ;; -esac - -# Note: order is significant - the case branches are not exclusive. - -case $UNAME_MACHINE:$UNAME_SYSTEM:$UNAME_RELEASE:$UNAME_VERSION in - *:NetBSD:*:*) - # NetBSD (nbsd) targets should (where applicable) match one or - # more of the tuples: *-*-netbsdelf*, *-*-netbsdaout*, - # *-*-netbsdecoff* and *-*-netbsd*. For targets that recently - # switched to ELF, *-*-netbsd* would select the old - # object file format. This provides both forward - # compatibility and a consistent mechanism for selecting the - # object file format. - # - # Note: NetBSD doesn't particularly care about the vendor - # portion of the name. We always set it to "unknown". - UNAME_MACHINE_ARCH=`(uname -p 2>/dev/null || \ - /sbin/sysctl -n hw.machine_arch 2>/dev/null || \ - /usr/sbin/sysctl -n hw.machine_arch 2>/dev/null || \ - echo unknown)` - case $UNAME_MACHINE_ARCH in - aarch64eb) machine=aarch64_be-unknown ;; - armeb) machine=armeb-unknown ;; - arm*) machine=arm-unknown ;; - sh3el) machine=shl-unknown ;; - sh3eb) machine=sh-unknown ;; - sh5el) machine=sh5le-unknown ;; - earmv*) - arch=`echo "$UNAME_MACHINE_ARCH" | sed -e 's,^e\(armv[0-9]\).*$,\1,'` - endian=`echo "$UNAME_MACHINE_ARCH" | sed -ne 's,^.*\(eb\)$,\1,p'` - machine=${arch}${endian}-unknown - ;; - *) machine=$UNAME_MACHINE_ARCH-unknown ;; - esac - # The Operating System including object format, if it has switched - # to ELF recently (or will in the future) and ABI. - case $UNAME_MACHINE_ARCH in - earm*) - os=netbsdelf - ;; - arm*|i386|m68k|ns32k|sh3*|sparc|vax) - set_cc_for_build - if echo __ELF__ | $CC_FOR_BUILD -E - 2>/dev/null \ - | grep -q __ELF__ - then - # Once all utilities can be ECOFF (netbsdecoff) or a.out (netbsdaout). - # Return netbsd for either. FIX? - os=netbsd - else - os=netbsdelf - fi - ;; - *) - os=netbsd - ;; - esac - # Determine ABI tags. - case $UNAME_MACHINE_ARCH in - earm*) - expr='s/^earmv[0-9]/-eabi/;s/eb$//' - abi=`echo "$UNAME_MACHINE_ARCH" | sed -e "$expr"` - ;; - esac - # The OS release - # Debian GNU/NetBSD machines have a different userland, and - # thus, need a distinct triplet. However, they do not need - # kernel version information, so it can be replaced with a - # suitable tag, in the style of linux-gnu. - case $UNAME_VERSION in - Debian*) - release='-gnu' - ;; - *) - release=`echo "$UNAME_RELEASE" | sed -e 's/[-_].*//' | cut -d. -f1,2` - ;; - esac - # Since CPU_TYPE-MANUFACTURER-KERNEL-OPERATING_SYSTEM: - # contains redundant information, the shorter form: - # CPU_TYPE-MANUFACTURER-OPERATING_SYSTEM is used. - GUESS=$machine-${os}${release}${abi-} - ;; - *:Bitrig:*:*) - UNAME_MACHINE_ARCH=`arch | sed 's/Bitrig.//'` - GUESS=$UNAME_MACHINE_ARCH-unknown-bitrig$UNAME_RELEASE - ;; - *:OpenBSD:*:*) - UNAME_MACHINE_ARCH=`arch | sed 's/OpenBSD.//'` - GUESS=$UNAME_MACHINE_ARCH-unknown-openbsd$UNAME_RELEASE - ;; - *:SecBSD:*:*) - UNAME_MACHINE_ARCH=`arch | sed 's/SecBSD.//'` - GUESS=$UNAME_MACHINE_ARCH-unknown-secbsd$UNAME_RELEASE - ;; - *:LibertyBSD:*:*) - UNAME_MACHINE_ARCH=`arch | sed 's/^.*BSD\.//'` - GUESS=$UNAME_MACHINE_ARCH-unknown-libertybsd$UNAME_RELEASE - ;; - *:MidnightBSD:*:*) - GUESS=$UNAME_MACHINE-unknown-midnightbsd$UNAME_RELEASE - ;; - *:ekkoBSD:*:*) - GUESS=$UNAME_MACHINE-unknown-ekkobsd$UNAME_RELEASE - ;; - *:SolidBSD:*:*) - GUESS=$UNAME_MACHINE-unknown-solidbsd$UNAME_RELEASE - ;; - *:OS108:*:*) - GUESS=$UNAME_MACHINE-unknown-os108_$UNAME_RELEASE - ;; - macppc:MirBSD:*:*) - GUESS=powerpc-unknown-mirbsd$UNAME_RELEASE - ;; - *:MirBSD:*:*) - GUESS=$UNAME_MACHINE-unknown-mirbsd$UNAME_RELEASE - ;; - *:Sortix:*:*) - GUESS=$UNAME_MACHINE-unknown-sortix - ;; - *:Twizzler:*:*) - GUESS=$UNAME_MACHINE-unknown-twizzler - ;; - *:Redox:*:*) - GUESS=$UNAME_MACHINE-unknown-redox - ;; - mips:OSF1:*.*) - GUESS=mips-dec-osf1 - ;; - alpha:OSF1:*:*) - # Reset EXIT trap before exiting to avoid spurious non-zero exit code. - trap '' 0 - case $UNAME_RELEASE in - *4.0) - UNAME_RELEASE=`/usr/sbin/sizer -v | awk '{print $3}'` - ;; - *5.*) - UNAME_RELEASE=`/usr/sbin/sizer -v | awk '{print $4}'` - ;; - esac - # According to Compaq, /usr/sbin/psrinfo has been available on - # OSF/1 and Tru64 systems produced since 1995. I hope that - # covers most systems running today. This code pipes the CPU - # types through head -n 1, so we only detect the type of CPU 0. - ALPHA_CPU_TYPE=`/usr/sbin/psrinfo -v | sed -n -e 's/^ The alpha \(.*\) processor.*$/\1/p' | head -n 1` - case $ALPHA_CPU_TYPE in - "EV4 (21064)") - UNAME_MACHINE=alpha ;; - "EV4.5 (21064)") - UNAME_MACHINE=alpha ;; - "LCA4 (21066/21068)") - UNAME_MACHINE=alpha ;; - "EV5 (21164)") - UNAME_MACHINE=alphaev5 ;; - "EV5.6 (21164A)") - UNAME_MACHINE=alphaev56 ;; - "EV5.6 (21164PC)") - UNAME_MACHINE=alphapca56 ;; - "EV5.7 (21164PC)") - UNAME_MACHINE=alphapca57 ;; - "EV6 (21264)") - UNAME_MACHINE=alphaev6 ;; - "EV6.7 (21264A)") - UNAME_MACHINE=alphaev67 ;; - "EV6.8CB (21264C)") - UNAME_MACHINE=alphaev68 ;; - "EV6.8AL (21264B)") - UNAME_MACHINE=alphaev68 ;; - "EV6.8CX (21264D)") - UNAME_MACHINE=alphaev68 ;; - "EV6.9A (21264/EV69A)") - UNAME_MACHINE=alphaev69 ;; - "EV7 (21364)") - UNAME_MACHINE=alphaev7 ;; - "EV7.9 (21364A)") - UNAME_MACHINE=alphaev79 ;; - esac - # A Pn.n version is a patched version. - # A Vn.n version is a released version. - # A Tn.n version is a released field test version. - # A Xn.n version is an unreleased experimental baselevel. - # 1.2 uses "1.2" for uname -r. - OSF_REL=`echo "$UNAME_RELEASE" | sed -e 's/^[PVTX]//' | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz` - GUESS=$UNAME_MACHINE-dec-osf$OSF_REL - ;; - Amiga*:UNIX_System_V:4.0:*) - GUESS=m68k-unknown-sysv4 - ;; - *:[Aa]miga[Oo][Ss]:*:*) - GUESS=$UNAME_MACHINE-unknown-amigaos - ;; - *:[Mm]orph[Oo][Ss]:*:*) - GUESS=$UNAME_MACHINE-unknown-morphos - ;; - *:OS/390:*:*) - GUESS=i370-ibm-openedition - ;; - *:z/VM:*:*) - GUESS=s390-ibm-zvmoe - ;; - *:OS400:*:*) - GUESS=powerpc-ibm-os400 - ;; - arm:RISC*:1.[012]*:*|arm:riscix:1.[012]*:*) - GUESS=arm-acorn-riscix$UNAME_RELEASE - ;; - arm*:riscos:*:*|arm*:RISCOS:*:*) - GUESS=arm-unknown-riscos - ;; - SR2?01:HI-UX/MPP:*:* | SR8000:HI-UX/MPP:*:*) - GUESS=hppa1.1-hitachi-hiuxmpp - ;; - Pyramid*:OSx*:*:* | MIS*:OSx*:*:* | MIS*:SMP_DC-OSx*:*:*) - # akee@wpdis03.wpafb.af.mil (Earle F. Ake) contributed MIS and NILE. - case `(/bin/universe) 2>/dev/null` in - att) GUESS=pyramid-pyramid-sysv3 ;; - *) GUESS=pyramid-pyramid-bsd ;; - esac - ;; - NILE*:*:*:dcosx) - GUESS=pyramid-pyramid-svr4 - ;; - DRS?6000:unix:4.0:6*) - GUESS=sparc-icl-nx6 - ;; - DRS?6000:UNIX_SV:4.2*:7* | DRS?6000:isis:4.2*:7*) - case `/usr/bin/uname -p` in - sparc) GUESS=sparc-icl-nx7 ;; - esac - ;; - s390x:SunOS:*:*) - SUN_REL=`echo "$UNAME_RELEASE" | sed -e 's/[^.]*//'` - GUESS=$UNAME_MACHINE-ibm-solaris2$SUN_REL - ;; - sun4H:SunOS:5.*:*) - SUN_REL=`echo "$UNAME_RELEASE" | sed -e 's/[^.]*//'` - GUESS=sparc-hal-solaris2$SUN_REL - ;; - sun4*:SunOS:5.*:* | tadpole*:SunOS:5.*:*) - SUN_REL=`echo "$UNAME_RELEASE" | sed -e 's/[^.]*//'` - GUESS=sparc-sun-solaris2$SUN_REL - ;; - i86pc:AuroraUX:5.*:* | i86xen:AuroraUX:5.*:*) - GUESS=i386-pc-auroraux$UNAME_RELEASE - ;; - i86pc:SunOS:5.*:* | i86xen:SunOS:5.*:*) - set_cc_for_build - SUN_ARCH=i386 - # If there is a compiler, see if it is configured for 64-bit objects. - # Note that the Sun cc does not turn __LP64__ into 1 like gcc does. - # This test works for both compilers. - if test "$CC_FOR_BUILD" != no_compiler_found; then - if (echo '#ifdef __amd64'; echo IS_64BIT_ARCH; echo '#endif') | \ - (CCOPTS="" $CC_FOR_BUILD -m64 -E - 2>/dev/null) | \ - grep IS_64BIT_ARCH >/dev/null - then - SUN_ARCH=x86_64 - fi - fi - SUN_REL=`echo "$UNAME_RELEASE" | sed -e 's/[^.]*//'` - GUESS=$SUN_ARCH-pc-solaris2$SUN_REL - ;; - sun4*:SunOS:6*:*) - # According to config.sub, this is the proper way to canonicalize - # SunOS6. Hard to guess exactly what SunOS6 will be like, but - # it's likely to be more like Solaris than SunOS4. - SUN_REL=`echo "$UNAME_RELEASE" | sed -e 's/[^.]*//'` - GUESS=sparc-sun-solaris3$SUN_REL - ;; - sun4*:SunOS:*:*) - case `/usr/bin/arch -k` in - Series*|S4*) - UNAME_RELEASE=`uname -v` - ;; - esac - # Japanese Language versions have a version number like `4.1.3-JL'. - SUN_REL=`echo "$UNAME_RELEASE" | sed -e 's/-/_/'` - GUESS=sparc-sun-sunos$SUN_REL - ;; - sun3*:SunOS:*:*) - GUESS=m68k-sun-sunos$UNAME_RELEASE - ;; - sun*:*:4.2BSD:*) - UNAME_RELEASE=`(sed 1q /etc/motd | awk '{print substr($5,1,3)}') 2>/dev/null` - test "x$UNAME_RELEASE" = x && UNAME_RELEASE=3 - case `/bin/arch` in - sun3) - GUESS=m68k-sun-sunos$UNAME_RELEASE - ;; - sun4) - GUESS=sparc-sun-sunos$UNAME_RELEASE - ;; - esac - ;; - aushp:SunOS:*:*) - GUESS=sparc-auspex-sunos$UNAME_RELEASE - ;; - # The situation for MiNT is a little confusing. The machine name - # can be virtually everything (everything which is not - # "atarist" or "atariste" at least should have a processor - # > m68000). The system name ranges from "MiNT" over "FreeMiNT" - # to the lowercase version "mint" (or "freemint"). Finally - # the system name "TOS" denotes a system which is actually not - # MiNT. But MiNT is downward compatible to TOS, so this should - # be no problem. - atarist[e]:*MiNT:*:* | atarist[e]:*mint:*:* | atarist[e]:*TOS:*:*) - GUESS=m68k-atari-mint$UNAME_RELEASE - ;; - atari*:*MiNT:*:* | atari*:*mint:*:* | atarist[e]:*TOS:*:*) - GUESS=m68k-atari-mint$UNAME_RELEASE - ;; - *falcon*:*MiNT:*:* | *falcon*:*mint:*:* | *falcon*:*TOS:*:*) - GUESS=m68k-atari-mint$UNAME_RELEASE - ;; - milan*:*MiNT:*:* | milan*:*mint:*:* | *milan*:*TOS:*:*) - GUESS=m68k-milan-mint$UNAME_RELEASE - ;; - hades*:*MiNT:*:* | hades*:*mint:*:* | *hades*:*TOS:*:*) - GUESS=m68k-hades-mint$UNAME_RELEASE - ;; - *:*MiNT:*:* | *:*mint:*:* | *:*TOS:*:*) - GUESS=m68k-unknown-mint$UNAME_RELEASE - ;; - m68k:machten:*:*) - GUESS=m68k-apple-machten$UNAME_RELEASE - ;; - powerpc:machten:*:*) - GUESS=powerpc-apple-machten$UNAME_RELEASE - ;; - RISC*:Mach:*:*) - GUESS=mips-dec-mach_bsd4.3 - ;; - RISC*:ULTRIX:*:*) - GUESS=mips-dec-ultrix$UNAME_RELEASE - ;; - VAX*:ULTRIX*:*:*) - GUESS=vax-dec-ultrix$UNAME_RELEASE - ;; - 2020:CLIX:*:* | 2430:CLIX:*:*) - GUESS=clipper-intergraph-clix$UNAME_RELEASE - ;; - mips:*:*:UMIPS | mips:*:*:RISCos) - set_cc_for_build - sed 's/^ //' << EOF > "$dummy.c" -#ifdef __cplusplus -#include /* for printf() prototype */ - int main (int argc, char *argv[]) { -#else - int main (argc, argv) int argc; char *argv[]; { -#endif - #if defined (host_mips) && defined (MIPSEB) - #if defined (SYSTYPE_SYSV) - printf ("mips-mips-riscos%ssysv\\n", argv[1]); exit (0); - #endif - #if defined (SYSTYPE_SVR4) - printf ("mips-mips-riscos%ssvr4\\n", argv[1]); exit (0); - #endif - #if defined (SYSTYPE_BSD43) || defined(SYSTYPE_BSD) - printf ("mips-mips-riscos%sbsd\\n", argv[1]); exit (0); - #endif - #endif - exit (-1); - } -EOF - $CC_FOR_BUILD -o "$dummy" "$dummy.c" && - dummyarg=`echo "$UNAME_RELEASE" | sed -n 's/\([0-9]*\).*/\1/p'` && - SYSTEM_NAME=`"$dummy" "$dummyarg"` && - { echo "$SYSTEM_NAME"; exit; } - GUESS=mips-mips-riscos$UNAME_RELEASE - ;; - Motorola:PowerMAX_OS:*:*) - GUESS=powerpc-motorola-powermax - ;; - Motorola:*:4.3:PL8-*) - GUESS=powerpc-harris-powermax - ;; - Night_Hawk:*:*:PowerMAX_OS | Synergy:PowerMAX_OS:*:*) - GUESS=powerpc-harris-powermax - ;; - Night_Hawk:Power_UNIX:*:*) - GUESS=powerpc-harris-powerunix - ;; - m88k:CX/UX:7*:*) - GUESS=m88k-harris-cxux7 - ;; - m88k:*:4*:R4*) - GUESS=m88k-motorola-sysv4 - ;; - m88k:*:3*:R3*) - GUESS=m88k-motorola-sysv3 - ;; - AViiON:dgux:*:*) - # DG/UX returns AViiON for all architectures - UNAME_PROCESSOR=`/usr/bin/uname -p` - if test "$UNAME_PROCESSOR" = mc88100 || test "$UNAME_PROCESSOR" = mc88110 - then - if test "$TARGET_BINARY_INTERFACE"x = m88kdguxelfx || \ - test "$TARGET_BINARY_INTERFACE"x = x - then - GUESS=m88k-dg-dgux$UNAME_RELEASE - else - GUESS=m88k-dg-dguxbcs$UNAME_RELEASE - fi - else - GUESS=i586-dg-dgux$UNAME_RELEASE - fi - ;; - M88*:DolphinOS:*:*) # DolphinOS (SVR3) - GUESS=m88k-dolphin-sysv3 - ;; - M88*:*:R3*:*) - # Delta 88k system running SVR3 - GUESS=m88k-motorola-sysv3 - ;; - XD88*:*:*:*) # Tektronix XD88 system running UTekV (SVR3) - GUESS=m88k-tektronix-sysv3 - ;; - Tek43[0-9][0-9]:UTek:*:*) # Tektronix 4300 system running UTek (BSD) - GUESS=m68k-tektronix-bsd - ;; - *:IRIX*:*:*) - IRIX_REL=`echo "$UNAME_RELEASE" | sed -e 's/-/_/g'` - GUESS=mips-sgi-irix$IRIX_REL - ;; - ????????:AIX?:[12].1:2) # AIX 2.2.1 or AIX 2.1.1 is RT/PC AIX. - GUESS=romp-ibm-aix # uname -m gives an 8 hex-code CPU id - ;; # Note that: echo "'`uname -s`'" gives 'AIX ' - i*86:AIX:*:*) - GUESS=i386-ibm-aix - ;; - ia64:AIX:*:*) - if test -x /usr/bin/oslevel ; then - IBM_REV=`/usr/bin/oslevel` - else - IBM_REV=$UNAME_VERSION.$UNAME_RELEASE - fi - GUESS=$UNAME_MACHINE-ibm-aix$IBM_REV - ;; - *:AIX:2:3) - if grep bos325 /usr/include/stdio.h >/dev/null 2>&1; then - set_cc_for_build - sed 's/^ //' << EOF > "$dummy.c" - #include - - main() - { - if (!__power_pc()) - exit(1); - puts("powerpc-ibm-aix3.2.5"); - exit(0); - } -EOF - if $CC_FOR_BUILD -o "$dummy" "$dummy.c" && SYSTEM_NAME=`"$dummy"` - then - GUESS=$SYSTEM_NAME - else - GUESS=rs6000-ibm-aix3.2.5 - fi - elif grep bos324 /usr/include/stdio.h >/dev/null 2>&1; then - GUESS=rs6000-ibm-aix3.2.4 - else - GUESS=rs6000-ibm-aix3.2 - fi - ;; - *:AIX:*:[4567]) - IBM_CPU_ID=`/usr/sbin/lsdev -C -c processor -S available | sed 1q | awk '{ print $1 }'` - if /usr/sbin/lsattr -El "$IBM_CPU_ID" | grep ' POWER' >/dev/null 2>&1; then - IBM_ARCH=rs6000 - else - IBM_ARCH=powerpc - fi - if test -x /usr/bin/lslpp ; then - IBM_REV=`/usr/bin/lslpp -Lqc bos.rte.libc | \ - awk -F: '{ print $3 }' | sed s/[0-9]*$/0/` - else - IBM_REV=$UNAME_VERSION.$UNAME_RELEASE - fi - GUESS=$IBM_ARCH-ibm-aix$IBM_REV - ;; - *:AIX:*:*) - GUESS=rs6000-ibm-aix - ;; - ibmrt:4.4BSD:*|romp-ibm:4.4BSD:*) - GUESS=romp-ibm-bsd4.4 - ;; - ibmrt:*BSD:*|romp-ibm:BSD:*) # covers RT/PC BSD and - GUESS=romp-ibm-bsd$UNAME_RELEASE # 4.3 with uname added to - ;; # report: romp-ibm BSD 4.3 - *:BOSX:*:*) - GUESS=rs6000-bull-bosx - ;; - DPX/2?00:B.O.S.:*:*) - GUESS=m68k-bull-sysv3 - ;; - 9000/[34]??:4.3bsd:1.*:*) - GUESS=m68k-hp-bsd - ;; - hp300:4.4BSD:*:* | 9000/[34]??:4.3bsd:2.*:*) - GUESS=m68k-hp-bsd4.4 - ;; - 9000/[34678]??:HP-UX:*:*) - HPUX_REV=`echo "$UNAME_RELEASE" | sed -e 's/[^.]*.[0B]*//'` - case $UNAME_MACHINE in - 9000/31?) HP_ARCH=m68000 ;; - 9000/[34]??) HP_ARCH=m68k ;; - 9000/[678][0-9][0-9]) - if test -x /usr/bin/getconf; then - sc_cpu_version=`/usr/bin/getconf SC_CPU_VERSION 2>/dev/null` - sc_kernel_bits=`/usr/bin/getconf SC_KERNEL_BITS 2>/dev/null` - case $sc_cpu_version in - 523) HP_ARCH=hppa1.0 ;; # CPU_PA_RISC1_0 - 528) HP_ARCH=hppa1.1 ;; # CPU_PA_RISC1_1 - 532) # CPU_PA_RISC2_0 - case $sc_kernel_bits in - 32) HP_ARCH=hppa2.0n ;; - 64) HP_ARCH=hppa2.0w ;; - '') HP_ARCH=hppa2.0 ;; # HP-UX 10.20 - esac ;; - esac - fi - if test "$HP_ARCH" = ""; then - set_cc_for_build - sed 's/^ //' << EOF > "$dummy.c" - - #define _HPUX_SOURCE - #include - #include - - int main () - { - #if defined(_SC_KERNEL_BITS) - long bits = sysconf(_SC_KERNEL_BITS); - #endif - long cpu = sysconf (_SC_CPU_VERSION); - - switch (cpu) - { - case CPU_PA_RISC1_0: puts ("hppa1.0"); break; - case CPU_PA_RISC1_1: puts ("hppa1.1"); break; - case CPU_PA_RISC2_0: - #if defined(_SC_KERNEL_BITS) - switch (bits) - { - case 64: puts ("hppa2.0w"); break; - case 32: puts ("hppa2.0n"); break; - default: puts ("hppa2.0"); break; - } break; - #else /* !defined(_SC_KERNEL_BITS) */ - puts ("hppa2.0"); break; - #endif - default: puts ("hppa1.0"); break; - } - exit (0); - } -EOF - (CCOPTS="" $CC_FOR_BUILD -o "$dummy" "$dummy.c" 2>/dev/null) && HP_ARCH=`"$dummy"` - test -z "$HP_ARCH" && HP_ARCH=hppa - fi ;; - esac - if test "$HP_ARCH" = hppa2.0w - then - set_cc_for_build - - # hppa2.0w-hp-hpux* has a 64-bit kernel and a compiler generating - # 32-bit code. hppa64-hp-hpux* has the same kernel and a compiler - # generating 64-bit code. GNU and HP use different nomenclature: - # - # $ CC_FOR_BUILD=cc ./config.guess - # => hppa2.0w-hp-hpux11.23 - # $ CC_FOR_BUILD="cc +DA2.0w" ./config.guess - # => hppa64-hp-hpux11.23 - - if echo __LP64__ | (CCOPTS="" $CC_FOR_BUILD -E - 2>/dev/null) | - grep -q __LP64__ - then - HP_ARCH=hppa2.0w - else - HP_ARCH=hppa64 - fi - fi - GUESS=$HP_ARCH-hp-hpux$HPUX_REV - ;; - ia64:HP-UX:*:*) - HPUX_REV=`echo "$UNAME_RELEASE" | sed -e 's/[^.]*.[0B]*//'` - GUESS=ia64-hp-hpux$HPUX_REV - ;; - 3050*:HI-UX:*:*) - set_cc_for_build - sed 's/^ //' << EOF > "$dummy.c" - #include - int - main () - { - long cpu = sysconf (_SC_CPU_VERSION); - /* The order matters, because CPU_IS_HP_MC68K erroneously returns - true for CPU_PA_RISC1_0. CPU_IS_PA_RISC returns correct - results, however. */ - if (CPU_IS_PA_RISC (cpu)) - { - switch (cpu) - { - case CPU_PA_RISC1_0: puts ("hppa1.0-hitachi-hiuxwe2"); break; - case CPU_PA_RISC1_1: puts ("hppa1.1-hitachi-hiuxwe2"); break; - case CPU_PA_RISC2_0: puts ("hppa2.0-hitachi-hiuxwe2"); break; - default: puts ("hppa-hitachi-hiuxwe2"); break; - } - } - else if (CPU_IS_HP_MC68K (cpu)) - puts ("m68k-hitachi-hiuxwe2"); - else puts ("unknown-hitachi-hiuxwe2"); - exit (0); - } -EOF - $CC_FOR_BUILD -o "$dummy" "$dummy.c" && SYSTEM_NAME=`"$dummy"` && - { echo "$SYSTEM_NAME"; exit; } - GUESS=unknown-hitachi-hiuxwe2 - ;; - 9000/7??:4.3bsd:*:* | 9000/8?[79]:4.3bsd:*:*) - GUESS=hppa1.1-hp-bsd - ;; - 9000/8??:4.3bsd:*:*) - GUESS=hppa1.0-hp-bsd - ;; - *9??*:MPE/iX:*:* | *3000*:MPE/iX:*:*) - GUESS=hppa1.0-hp-mpeix - ;; - hp7??:OSF1:*:* | hp8?[79]:OSF1:*:*) - GUESS=hppa1.1-hp-osf - ;; - hp8??:OSF1:*:*) - GUESS=hppa1.0-hp-osf - ;; - i*86:OSF1:*:*) - if test -x /usr/sbin/sysversion ; then - GUESS=$UNAME_MACHINE-unknown-osf1mk - else - GUESS=$UNAME_MACHINE-unknown-osf1 - fi - ;; - parisc*:Lites*:*:*) - GUESS=hppa1.1-hp-lites - ;; - C1*:ConvexOS:*:* | convex:ConvexOS:C1*:*) - GUESS=c1-convex-bsd - ;; - C2*:ConvexOS:*:* | convex:ConvexOS:C2*:*) - if getsysinfo -f scalar_acc - then echo c32-convex-bsd - else echo c2-convex-bsd - fi - exit ;; - C34*:ConvexOS:*:* | convex:ConvexOS:C34*:*) - GUESS=c34-convex-bsd - ;; - C38*:ConvexOS:*:* | convex:ConvexOS:C38*:*) - GUESS=c38-convex-bsd - ;; - C4*:ConvexOS:*:* | convex:ConvexOS:C4*:*) - GUESS=c4-convex-bsd - ;; - CRAY*Y-MP:*:*:*) - CRAY_REL=`echo "$UNAME_RELEASE" | sed -e 's/\.[^.]*$/.X/'` - GUESS=ymp-cray-unicos$CRAY_REL - ;; - CRAY*[A-Z]90:*:*:*) - echo "$UNAME_MACHINE"-cray-unicos"$UNAME_RELEASE" \ - | sed -e 's/CRAY.*\([A-Z]90\)/\1/' \ - -e y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/ \ - -e 's/\.[^.]*$/.X/' - exit ;; - CRAY*TS:*:*:*) - CRAY_REL=`echo "$UNAME_RELEASE" | sed -e 's/\.[^.]*$/.X/'` - GUESS=t90-cray-unicos$CRAY_REL - ;; - CRAY*T3E:*:*:*) - CRAY_REL=`echo "$UNAME_RELEASE" | sed -e 's/\.[^.]*$/.X/'` - GUESS=alphaev5-cray-unicosmk$CRAY_REL - ;; - CRAY*SV1:*:*:*) - CRAY_REL=`echo "$UNAME_RELEASE" | sed -e 's/\.[^.]*$/.X/'` - GUESS=sv1-cray-unicos$CRAY_REL - ;; - *:UNICOS/mp:*:*) - CRAY_REL=`echo "$UNAME_RELEASE" | sed -e 's/\.[^.]*$/.X/'` - GUESS=craynv-cray-unicosmp$CRAY_REL - ;; - F30[01]:UNIX_System_V:*:* | F700:UNIX_System_V:*:*) - FUJITSU_PROC=`uname -m | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz` - FUJITSU_SYS=`uname -p | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz | sed -e 's/\///'` - FUJITSU_REL=`echo "$UNAME_RELEASE" | sed -e 's/ /_/'` - GUESS=${FUJITSU_PROC}-fujitsu-${FUJITSU_SYS}${FUJITSU_REL} - ;; - 5000:UNIX_System_V:4.*:*) - FUJITSU_SYS=`uname -p | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz | sed -e 's/\///'` - FUJITSU_REL=`echo "$UNAME_RELEASE" | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz | sed -e 's/ /_/'` - GUESS=sparc-fujitsu-${FUJITSU_SYS}${FUJITSU_REL} - ;; - i*86:BSD/386:*:* | i*86:BSD/OS:*:* | *:Ascend\ Embedded/OS:*:*) - GUESS=$UNAME_MACHINE-pc-bsdi$UNAME_RELEASE - ;; - sparc*:BSD/OS:*:*) - GUESS=sparc-unknown-bsdi$UNAME_RELEASE - ;; - *:BSD/OS:*:*) - GUESS=$UNAME_MACHINE-unknown-bsdi$UNAME_RELEASE - ;; - arm:FreeBSD:*:*) - UNAME_PROCESSOR=`uname -p` - set_cc_for_build - if echo __ARM_PCS_VFP | $CC_FOR_BUILD -E - 2>/dev/null \ - | grep -q __ARM_PCS_VFP - then - FREEBSD_REL=`echo "$UNAME_RELEASE" | sed -e 's/[-(].*//'` - GUESS=$UNAME_PROCESSOR-unknown-freebsd$FREEBSD_REL-gnueabi - else - FREEBSD_REL=`echo "$UNAME_RELEASE" | sed -e 's/[-(].*//'` - GUESS=$UNAME_PROCESSOR-unknown-freebsd$FREEBSD_REL-gnueabihf - fi - ;; - *:FreeBSD:*:*) - UNAME_PROCESSOR=`/usr/bin/uname -p` - case $UNAME_PROCESSOR in - amd64) - UNAME_PROCESSOR=x86_64 ;; - i386) - UNAME_PROCESSOR=i586 ;; - esac - FREEBSD_REL=`echo "$UNAME_RELEASE" | sed -e 's/[-(].*//'` - GUESS=$UNAME_PROCESSOR-unknown-freebsd$FREEBSD_REL - ;; - i*:CYGWIN*:*) - GUESS=$UNAME_MACHINE-pc-cygwin - ;; - *:MINGW64*:*) - GUESS=$UNAME_MACHINE-pc-mingw64 - ;; - *:MINGW*:*) - GUESS=$UNAME_MACHINE-pc-mingw32 - ;; - *:MSYS*:*) - GUESS=$UNAME_MACHINE-pc-msys - ;; - i*:PW*:*) - GUESS=$UNAME_MACHINE-pc-pw32 - ;; - *:SerenityOS:*:*) - GUESS=$UNAME_MACHINE-pc-serenity - ;; - *:Interix*:*) - case $UNAME_MACHINE in - x86) - GUESS=i586-pc-interix$UNAME_RELEASE - ;; - authenticamd | genuineintel | EM64T) - GUESS=x86_64-unknown-interix$UNAME_RELEASE - ;; - IA64) - GUESS=ia64-unknown-interix$UNAME_RELEASE - ;; - esac ;; - i*:UWIN*:*) - GUESS=$UNAME_MACHINE-pc-uwin - ;; - amd64:CYGWIN*:*:* | x86_64:CYGWIN*:*:*) - GUESS=x86_64-pc-cygwin - ;; - prep*:SunOS:5.*:*) - SUN_REL=`echo "$UNAME_RELEASE" | sed -e 's/[^.]*//'` - GUESS=powerpcle-unknown-solaris2$SUN_REL - ;; - *:GNU:*:*) - # the GNU system - GNU_ARCH=`echo "$UNAME_MACHINE" | sed -e 's,[-/].*$,,'` - GNU_REL=`echo "$UNAME_RELEASE" | sed -e 's,/.*$,,'` - GUESS=$GNU_ARCH-unknown-$LIBC$GNU_REL - ;; - *:GNU/*:*:*) - # other systems with GNU libc and userland - GNU_SYS=`echo "$UNAME_SYSTEM" | sed 's,^[^/]*/,,' | tr "[:upper:]" "[:lower:]"` - GNU_REL=`echo "$UNAME_RELEASE" | sed -e 's/[-(].*//'` - GUESS=$UNAME_MACHINE-unknown-$GNU_SYS$GNU_REL-$LIBC - ;; - x86_64:[Mm]anagarm:*:*|i?86:[Mm]anagarm:*:*) - GUESS="$UNAME_MACHINE-pc-managarm-mlibc" - ;; - *:[Mm]anagarm:*:*) - GUESS="$UNAME_MACHINE-unknown-managarm-mlibc" - ;; - *:Minix:*:*) - GUESS=$UNAME_MACHINE-unknown-minix - ;; - aarch64:Linux:*:*) - GUESS=$UNAME_MACHINE-unknown-linux-$LIBC - ;; - aarch64_be:Linux:*:*) - UNAME_MACHINE=aarch64_be - GUESS=$UNAME_MACHINE-unknown-linux-$LIBC - ;; - alpha:Linux:*:*) - case `sed -n '/^cpu model/s/^.*: \(.*\)/\1/p' /proc/cpuinfo 2>/dev/null` in - EV5) UNAME_MACHINE=alphaev5 ;; - EV56) UNAME_MACHINE=alphaev56 ;; - PCA56) UNAME_MACHINE=alphapca56 ;; - PCA57) UNAME_MACHINE=alphapca56 ;; - EV6) UNAME_MACHINE=alphaev6 ;; - EV67) UNAME_MACHINE=alphaev67 ;; - EV68*) UNAME_MACHINE=alphaev68 ;; - esac - objdump --private-headers /bin/sh | grep -q ld.so.1 - if test "$?" = 0 ; then LIBC=gnulibc1 ; fi - GUESS=$UNAME_MACHINE-unknown-linux-$LIBC - ;; - arc:Linux:*:* | arceb:Linux:*:* | arc32:Linux:*:* | arc64:Linux:*:*) - GUESS=$UNAME_MACHINE-unknown-linux-$LIBC - ;; - arm*:Linux:*:*) - set_cc_for_build - if echo __ARM_EABI__ | $CC_FOR_BUILD -E - 2>/dev/null \ - | grep -q __ARM_EABI__ - then - GUESS=$UNAME_MACHINE-unknown-linux-$LIBC - else - if echo __ARM_PCS_VFP | $CC_FOR_BUILD -E - 2>/dev/null \ - | grep -q __ARM_PCS_VFP - then - GUESS=$UNAME_MACHINE-unknown-linux-${LIBC}eabi - else - GUESS=$UNAME_MACHINE-unknown-linux-${LIBC}eabihf - fi - fi - ;; - avr32*:Linux:*:*) - GUESS=$UNAME_MACHINE-unknown-linux-$LIBC - ;; - cris:Linux:*:*) - GUESS=$UNAME_MACHINE-axis-linux-$LIBC - ;; - crisv32:Linux:*:*) - GUESS=$UNAME_MACHINE-axis-linux-$LIBC - ;; - e2k:Linux:*:*) - GUESS=$UNAME_MACHINE-unknown-linux-$LIBC - ;; - frv:Linux:*:*) - GUESS=$UNAME_MACHINE-unknown-linux-$LIBC - ;; - hexagon:Linux:*:*) - GUESS=$UNAME_MACHINE-unknown-linux-$LIBC - ;; - i*86:Linux:*:*) - GUESS=$UNAME_MACHINE-pc-linux-$LIBC - ;; - ia64:Linux:*:*) - GUESS=$UNAME_MACHINE-unknown-linux-$LIBC - ;; - k1om:Linux:*:*) - GUESS=$UNAME_MACHINE-unknown-linux-$LIBC - ;; - loongarch32:Linux:*:* | loongarch64:Linux:*:*) - GUESS=$UNAME_MACHINE-unknown-linux-$LIBC - ;; - m32r*:Linux:*:*) - GUESS=$UNAME_MACHINE-unknown-linux-$LIBC - ;; - m68*:Linux:*:*) - GUESS=$UNAME_MACHINE-unknown-linux-$LIBC - ;; - mips:Linux:*:* | mips64:Linux:*:*) - set_cc_for_build - IS_GLIBC=0 - test x"${LIBC}" = xgnu && IS_GLIBC=1 - sed 's/^ //' << EOF > "$dummy.c" - #undef CPU - #undef mips - #undef mipsel - #undef mips64 - #undef mips64el - #if ${IS_GLIBC} && defined(_ABI64) - LIBCABI=gnuabi64 - #else - #if ${IS_GLIBC} && defined(_ABIN32) - LIBCABI=gnuabin32 - #else - LIBCABI=${LIBC} - #endif - #endif - - #if ${IS_GLIBC} && defined(__mips64) && defined(__mips_isa_rev) && __mips_isa_rev>=6 - CPU=mipsisa64r6 - #else - #if ${IS_GLIBC} && !defined(__mips64) && defined(__mips_isa_rev) && __mips_isa_rev>=6 - CPU=mipsisa32r6 - #else - #if defined(__mips64) - CPU=mips64 - #else - CPU=mips - #endif - #endif - #endif - - #if defined(__MIPSEL__) || defined(__MIPSEL) || defined(_MIPSEL) || defined(MIPSEL) - MIPS_ENDIAN=el - #else - #if defined(__MIPSEB__) || defined(__MIPSEB) || defined(_MIPSEB) || defined(MIPSEB) - MIPS_ENDIAN= - #else - MIPS_ENDIAN= - #endif - #endif -EOF - cc_set_vars=`$CC_FOR_BUILD -E "$dummy.c" 2>/dev/null | grep '^CPU\|^MIPS_ENDIAN\|^LIBCABI'` - eval "$cc_set_vars" - test "x$CPU" != x && { echo "$CPU${MIPS_ENDIAN}-unknown-linux-$LIBCABI"; exit; } - ;; - mips64el:Linux:*:*) - GUESS=$UNAME_MACHINE-unknown-linux-$LIBC - ;; - openrisc*:Linux:*:*) - GUESS=or1k-unknown-linux-$LIBC - ;; - or32:Linux:*:* | or1k*:Linux:*:*) - GUESS=$UNAME_MACHINE-unknown-linux-$LIBC - ;; - padre:Linux:*:*) - GUESS=sparc-unknown-linux-$LIBC - ;; - parisc64:Linux:*:* | hppa64:Linux:*:*) - GUESS=hppa64-unknown-linux-$LIBC - ;; - parisc:Linux:*:* | hppa:Linux:*:*) - # Look for CPU level - case `grep '^cpu[^a-z]*:' /proc/cpuinfo 2>/dev/null | cut -d' ' -f2` in - PA7*) GUESS=hppa1.1-unknown-linux-$LIBC ;; - PA8*) GUESS=hppa2.0-unknown-linux-$LIBC ;; - *) GUESS=hppa-unknown-linux-$LIBC ;; - esac - ;; - ppc64:Linux:*:*) - GUESS=powerpc64-unknown-linux-$LIBC - ;; - ppc:Linux:*:*) - GUESS=powerpc-unknown-linux-$LIBC - ;; - ppc64le:Linux:*:*) - GUESS=powerpc64le-unknown-linux-$LIBC - ;; - ppcle:Linux:*:*) - GUESS=powerpcle-unknown-linux-$LIBC - ;; - riscv32:Linux:*:* | riscv32be:Linux:*:* | riscv64:Linux:*:* | riscv64be:Linux:*:*) - GUESS=$UNAME_MACHINE-unknown-linux-$LIBC - ;; - s390:Linux:*:* | s390x:Linux:*:*) - GUESS=$UNAME_MACHINE-ibm-linux-$LIBC - ;; - sh64*:Linux:*:*) - GUESS=$UNAME_MACHINE-unknown-linux-$LIBC - ;; - sh*:Linux:*:*) - GUESS=$UNAME_MACHINE-unknown-linux-$LIBC - ;; - sparc:Linux:*:* | sparc64:Linux:*:*) - GUESS=$UNAME_MACHINE-unknown-linux-$LIBC - ;; - tile*:Linux:*:*) - GUESS=$UNAME_MACHINE-unknown-linux-$LIBC - ;; - vax:Linux:*:*) - GUESS=$UNAME_MACHINE-dec-linux-$LIBC - ;; - x86_64:Linux:*:*) - set_cc_for_build - CPU=$UNAME_MACHINE - LIBCABI=$LIBC - if test "$CC_FOR_BUILD" != no_compiler_found; then - ABI=64 - sed 's/^ //' << EOF > "$dummy.c" - #ifdef __i386__ - ABI=x86 - #else - #ifdef __ILP32__ - ABI=x32 - #endif - #endif -EOF - cc_set_abi=`$CC_FOR_BUILD -E "$dummy.c" 2>/dev/null | grep '^ABI' | sed 's, ,,g'` - eval "$cc_set_abi" - case $ABI in - x86) CPU=i686 ;; - x32) LIBCABI=${LIBC}x32 ;; - esac - fi - GUESS=$CPU-pc-linux-$LIBCABI - ;; - xtensa*:Linux:*:*) - GUESS=$UNAME_MACHINE-unknown-linux-$LIBC - ;; - i*86:DYNIX/ptx:4*:*) - # ptx 4.0 does uname -s correctly, with DYNIX/ptx in there. - # earlier versions are messed up and put the nodename in both - # sysname and nodename. - GUESS=i386-sequent-sysv4 - ;; - i*86:UNIX_SV:4.2MP:2.*) - # Unixware is an offshoot of SVR4, but it has its own version - # number series starting with 2... - # I am not positive that other SVR4 systems won't match this, - # I just have to hope. -- rms. - # Use sysv4.2uw... so that sysv4* matches it. - GUESS=$UNAME_MACHINE-pc-sysv4.2uw$UNAME_VERSION - ;; - i*86:OS/2:*:*) - # If we were able to find `uname', then EMX Unix compatibility - # is probably installed. - GUESS=$UNAME_MACHINE-pc-os2-emx - ;; - i*86:XTS-300:*:STOP) - GUESS=$UNAME_MACHINE-unknown-stop - ;; - i*86:atheos:*:*) - GUESS=$UNAME_MACHINE-unknown-atheos - ;; - i*86:syllable:*:*) - GUESS=$UNAME_MACHINE-pc-syllable - ;; - i*86:LynxOS:2.*:* | i*86:LynxOS:3.[01]*:* | i*86:LynxOS:4.[02]*:*) - GUESS=i386-unknown-lynxos$UNAME_RELEASE - ;; - i*86:*DOS:*:*) - GUESS=$UNAME_MACHINE-pc-msdosdjgpp - ;; - i*86:*:4.*:*) - UNAME_REL=`echo "$UNAME_RELEASE" | sed 's/\/MP$//'` - if grep Novell /usr/include/link.h >/dev/null 2>/dev/null; then - GUESS=$UNAME_MACHINE-univel-sysv$UNAME_REL - else - GUESS=$UNAME_MACHINE-pc-sysv$UNAME_REL - fi - ;; - i*86:*:5:[678]*) - # UnixWare 7.x, OpenUNIX and OpenServer 6. - case `/bin/uname -X | grep "^Machine"` in - *486*) UNAME_MACHINE=i486 ;; - *Pentium) UNAME_MACHINE=i586 ;; - *Pent*|*Celeron) UNAME_MACHINE=i686 ;; - esac - GUESS=$UNAME_MACHINE-unknown-sysv${UNAME_RELEASE}${UNAME_SYSTEM}${UNAME_VERSION} - ;; - i*86:*:3.2:*) - if test -f /usr/options/cb.name; then - UNAME_REL=`sed -n 's/.*Version //p' /dev/null >/dev/null ; then - UNAME_REL=`(/bin/uname -X|grep Release|sed -e 's/.*= //')` - (/bin/uname -X|grep i80486 >/dev/null) && UNAME_MACHINE=i486 - (/bin/uname -X|grep '^Machine.*Pentium' >/dev/null) \ - && UNAME_MACHINE=i586 - (/bin/uname -X|grep '^Machine.*Pent *II' >/dev/null) \ - && UNAME_MACHINE=i686 - (/bin/uname -X|grep '^Machine.*Pentium Pro' >/dev/null) \ - && UNAME_MACHINE=i686 - GUESS=$UNAME_MACHINE-pc-sco$UNAME_REL - else - GUESS=$UNAME_MACHINE-pc-sysv32 - fi - ;; - pc:*:*:*) - # Left here for compatibility: - # uname -m prints for DJGPP always 'pc', but it prints nothing about - # the processor, so we play safe by assuming i586. - # Note: whatever this is, it MUST be the same as what config.sub - # prints for the "djgpp" host, or else GDB configure will decide that - # this is a cross-build. - GUESS=i586-pc-msdosdjgpp - ;; - Intel:Mach:3*:*) - GUESS=i386-pc-mach3 - ;; - paragon:*:*:*) - GUESS=i860-intel-osf1 - ;; - i860:*:4.*:*) # i860-SVR4 - if grep Stardent /usr/include/sys/uadmin.h >/dev/null 2>&1 ; then - GUESS=i860-stardent-sysv$UNAME_RELEASE # Stardent Vistra i860-SVR4 - else # Add other i860-SVR4 vendors below as they are discovered. - GUESS=i860-unknown-sysv$UNAME_RELEASE # Unknown i860-SVR4 - fi - ;; - mini*:CTIX:SYS*5:*) - # "miniframe" - GUESS=m68010-convergent-sysv - ;; - mc68k:UNIX:SYSTEM5:3.51m) - GUESS=m68k-convergent-sysv - ;; - M680?0:D-NIX:5.3:*) - GUESS=m68k-diab-dnix - ;; - M68*:*:R3V[5678]*:*) - test -r /sysV68 && { echo 'm68k-motorola-sysv'; exit; } ;; - 3[345]??:*:4.0:3.0 | 3[34]??A:*:4.0:3.0 | 3[34]??,*:*:4.0:3.0 | 3[34]??/*:*:4.0:3.0 | 4400:*:4.0:3.0 | 4850:*:4.0:3.0 | SKA40:*:4.0:3.0 | SDS2:*:4.0:3.0 | SHG2:*:4.0:3.0 | S7501*:*:4.0:3.0) - OS_REL='' - test -r /etc/.relid \ - && OS_REL=.`sed -n 's/[^ ]* [^ ]* \([0-9][0-9]\).*/\1/p' < /etc/.relid` - /bin/uname -p 2>/dev/null | grep 86 >/dev/null \ - && { echo i486-ncr-sysv4.3"$OS_REL"; exit; } - /bin/uname -p 2>/dev/null | /bin/grep entium >/dev/null \ - && { echo i586-ncr-sysv4.3"$OS_REL"; exit; } ;; - 3[34]??:*:4.0:* | 3[34]??,*:*:4.0:*) - /bin/uname -p 2>/dev/null | grep 86 >/dev/null \ - && { echo i486-ncr-sysv4; exit; } ;; - NCR*:*:4.2:* | MPRAS*:*:4.2:*) - OS_REL='.3' - test -r /etc/.relid \ - && OS_REL=.`sed -n 's/[^ ]* [^ ]* \([0-9][0-9]\).*/\1/p' < /etc/.relid` - /bin/uname -p 2>/dev/null | grep 86 >/dev/null \ - && { echo i486-ncr-sysv4.3"$OS_REL"; exit; } - /bin/uname -p 2>/dev/null | /bin/grep entium >/dev/null \ - && { echo i586-ncr-sysv4.3"$OS_REL"; exit; } - /bin/uname -p 2>/dev/null | /bin/grep pteron >/dev/null \ - && { echo i586-ncr-sysv4.3"$OS_REL"; exit; } ;; - m68*:LynxOS:2.*:* | m68*:LynxOS:3.0*:*) - GUESS=m68k-unknown-lynxos$UNAME_RELEASE - ;; - mc68030:UNIX_System_V:4.*:*) - GUESS=m68k-atari-sysv4 - ;; - TSUNAMI:LynxOS:2.*:*) - GUESS=sparc-unknown-lynxos$UNAME_RELEASE - ;; - rs6000:LynxOS:2.*:*) - GUESS=rs6000-unknown-lynxos$UNAME_RELEASE - ;; - PowerPC:LynxOS:2.*:* | PowerPC:LynxOS:3.[01]*:* | PowerPC:LynxOS:4.[02]*:*) - GUESS=powerpc-unknown-lynxos$UNAME_RELEASE - ;; - SM[BE]S:UNIX_SV:*:*) - GUESS=mips-dde-sysv$UNAME_RELEASE - ;; - RM*:ReliantUNIX-*:*:*) - GUESS=mips-sni-sysv4 - ;; - RM*:SINIX-*:*:*) - GUESS=mips-sni-sysv4 - ;; - *:SINIX-*:*:*) - if uname -p 2>/dev/null >/dev/null ; then - UNAME_MACHINE=`(uname -p) 2>/dev/null` - GUESS=$UNAME_MACHINE-sni-sysv4 - else - GUESS=ns32k-sni-sysv - fi - ;; - PENTIUM:*:4.0*:*) # Unisys `ClearPath HMP IX 4000' SVR4/MP effort - # says - GUESS=i586-unisys-sysv4 - ;; - *:UNIX_System_V:4*:FTX*) - # From Gerald Hewes . - # How about differentiating between stratus architectures? -djm - GUESS=hppa1.1-stratus-sysv4 - ;; - *:*:*:FTX*) - # From seanf@swdc.stratus.com. - GUESS=i860-stratus-sysv4 - ;; - i*86:VOS:*:*) - # From Paul.Green@stratus.com. - GUESS=$UNAME_MACHINE-stratus-vos - ;; - *:VOS:*:*) - # From Paul.Green@stratus.com. - GUESS=hppa1.1-stratus-vos - ;; - mc68*:A/UX:*:*) - GUESS=m68k-apple-aux$UNAME_RELEASE - ;; - news*:NEWS-OS:6*:*) - GUESS=mips-sony-newsos6 - ;; - R[34]000:*System_V*:*:* | R4000:UNIX_SYSV:*:* | R*000:UNIX_SV:*:*) - if test -d /usr/nec; then - GUESS=mips-nec-sysv$UNAME_RELEASE - else - GUESS=mips-unknown-sysv$UNAME_RELEASE - fi - ;; - BeBox:BeOS:*:*) # BeOS running on hardware made by Be, PPC only. - GUESS=powerpc-be-beos - ;; - BeMac:BeOS:*:*) # BeOS running on Mac or Mac clone, PPC only. - GUESS=powerpc-apple-beos - ;; - BePC:BeOS:*:*) # BeOS running on Intel PC compatible. - GUESS=i586-pc-beos - ;; - BePC:Haiku:*:*) # Haiku running on Intel PC compatible. - GUESS=i586-pc-haiku - ;; - ppc:Haiku:*:*) # Haiku running on Apple PowerPC - GUESS=powerpc-apple-haiku - ;; - *:Haiku:*:*) # Haiku modern gcc (not bound by BeOS compat) - GUESS=$UNAME_MACHINE-unknown-haiku - ;; - SX-4:SUPER-UX:*:*) - GUESS=sx4-nec-superux$UNAME_RELEASE - ;; - SX-5:SUPER-UX:*:*) - GUESS=sx5-nec-superux$UNAME_RELEASE - ;; - SX-6:SUPER-UX:*:*) - GUESS=sx6-nec-superux$UNAME_RELEASE - ;; - SX-7:SUPER-UX:*:*) - GUESS=sx7-nec-superux$UNAME_RELEASE - ;; - SX-8:SUPER-UX:*:*) - GUESS=sx8-nec-superux$UNAME_RELEASE - ;; - SX-8R:SUPER-UX:*:*) - GUESS=sx8r-nec-superux$UNAME_RELEASE - ;; - SX-ACE:SUPER-UX:*:*) - GUESS=sxace-nec-superux$UNAME_RELEASE - ;; - Power*:Rhapsody:*:*) - GUESS=powerpc-apple-rhapsody$UNAME_RELEASE - ;; - *:Rhapsody:*:*) - GUESS=$UNAME_MACHINE-apple-rhapsody$UNAME_RELEASE - ;; - arm64:Darwin:*:*) - GUESS=aarch64-apple-darwin$UNAME_RELEASE - ;; - *:Darwin:*:*) - UNAME_PROCESSOR=`uname -p` - case $UNAME_PROCESSOR in - unknown) UNAME_PROCESSOR=powerpc ;; - esac - if command -v xcode-select > /dev/null 2> /dev/null && \ - ! xcode-select --print-path > /dev/null 2> /dev/null ; then - # Avoid executing cc if there is no toolchain installed as - # cc will be a stub that puts up a graphical alert - # prompting the user to install developer tools. - CC_FOR_BUILD=no_compiler_found - else - set_cc_for_build - fi - if test "$CC_FOR_BUILD" != no_compiler_found; then - if (echo '#ifdef __LP64__'; echo IS_64BIT_ARCH; echo '#endif') | \ - (CCOPTS="" $CC_FOR_BUILD -E - 2>/dev/null) | \ - grep IS_64BIT_ARCH >/dev/null - then - case $UNAME_PROCESSOR in - i386) UNAME_PROCESSOR=x86_64 ;; - powerpc) UNAME_PROCESSOR=powerpc64 ;; - esac - fi - # On 10.4-10.6 one might compile for PowerPC via gcc -arch ppc - if (echo '#ifdef __POWERPC__'; echo IS_PPC; echo '#endif') | \ - (CCOPTS="" $CC_FOR_BUILD -E - 2>/dev/null) | \ - grep IS_PPC >/dev/null - then - UNAME_PROCESSOR=powerpc - fi - elif test "$UNAME_PROCESSOR" = i386 ; then - # uname -m returns i386 or x86_64 - UNAME_PROCESSOR=$UNAME_MACHINE - fi - GUESS=$UNAME_PROCESSOR-apple-darwin$UNAME_RELEASE - ;; - *:procnto*:*:* | *:QNX:[0123456789]*:*) - UNAME_PROCESSOR=`uname -p` - if test "$UNAME_PROCESSOR" = x86; then - UNAME_PROCESSOR=i386 - UNAME_MACHINE=pc - fi - GUESS=$UNAME_PROCESSOR-$UNAME_MACHINE-nto-qnx$UNAME_RELEASE - ;; - *:QNX:*:4*) - GUESS=i386-pc-qnx - ;; - NEO-*:NONSTOP_KERNEL:*:*) - GUESS=neo-tandem-nsk$UNAME_RELEASE - ;; - NSE-*:NONSTOP_KERNEL:*:*) - GUESS=nse-tandem-nsk$UNAME_RELEASE - ;; - NSR-*:NONSTOP_KERNEL:*:*) - GUESS=nsr-tandem-nsk$UNAME_RELEASE - ;; - NSV-*:NONSTOP_KERNEL:*:*) - GUESS=nsv-tandem-nsk$UNAME_RELEASE - ;; - NSX-*:NONSTOP_KERNEL:*:*) - GUESS=nsx-tandem-nsk$UNAME_RELEASE - ;; - *:NonStop-UX:*:*) - GUESS=mips-compaq-nonstopux - ;; - BS2000:POSIX*:*:*) - GUESS=bs2000-siemens-sysv - ;; - DS/*:UNIX_System_V:*:*) - GUESS=$UNAME_MACHINE-$UNAME_SYSTEM-$UNAME_RELEASE - ;; - *:Plan9:*:*) - # "uname -m" is not consistent, so use $cputype instead. 386 - # is converted to i386 for consistency with other x86 - # operating systems. - if test "${cputype-}" = 386; then - UNAME_MACHINE=i386 - elif test "x${cputype-}" != x; then - UNAME_MACHINE=$cputype - fi - GUESS=$UNAME_MACHINE-unknown-plan9 - ;; - *:TOPS-10:*:*) - GUESS=pdp10-unknown-tops10 - ;; - *:TENEX:*:*) - GUESS=pdp10-unknown-tenex - ;; - KS10:TOPS-20:*:* | KL10:TOPS-20:*:* | TYPE4:TOPS-20:*:*) - GUESS=pdp10-dec-tops20 - ;; - XKL-1:TOPS-20:*:* | TYPE5:TOPS-20:*:*) - GUESS=pdp10-xkl-tops20 - ;; - *:TOPS-20:*:*) - GUESS=pdp10-unknown-tops20 - ;; - *:ITS:*:*) - GUESS=pdp10-unknown-its - ;; - SEI:*:*:SEIUX) - GUESS=mips-sei-seiux$UNAME_RELEASE - ;; - *:DragonFly:*:*) - DRAGONFLY_REL=`echo "$UNAME_RELEASE" | sed -e 's/[-(].*//'` - GUESS=$UNAME_MACHINE-unknown-dragonfly$DRAGONFLY_REL - ;; - *:*VMS:*:*) - UNAME_MACHINE=`(uname -p) 2>/dev/null` - case $UNAME_MACHINE in - A*) GUESS=alpha-dec-vms ;; - I*) GUESS=ia64-dec-vms ;; - V*) GUESS=vax-dec-vms ;; - esac ;; - *:XENIX:*:SysV) - GUESS=i386-pc-xenix - ;; - i*86:skyos:*:*) - SKYOS_REL=`echo "$UNAME_RELEASE" | sed -e 's/ .*$//'` - GUESS=$UNAME_MACHINE-pc-skyos$SKYOS_REL - ;; - i*86:rdos:*:*) - GUESS=$UNAME_MACHINE-pc-rdos - ;; - i*86:Fiwix:*:*) - GUESS=$UNAME_MACHINE-pc-fiwix - ;; - *:AROS:*:*) - GUESS=$UNAME_MACHINE-unknown-aros - ;; - x86_64:VMkernel:*:*) - GUESS=$UNAME_MACHINE-unknown-esx - ;; - amd64:Isilon\ OneFS:*:*) - GUESS=x86_64-unknown-onefs - ;; - *:Unleashed:*:*) - GUESS=$UNAME_MACHINE-unknown-unleashed$UNAME_RELEASE - ;; -esac - -# Do we have a guess based on uname results? -if test "x$GUESS" != x; then - echo "$GUESS" - exit -fi - -# No uname command or uname output not recognized. -set_cc_for_build -cat > "$dummy.c" < -#include -#endif -#if defined(ultrix) || defined(_ultrix) || defined(__ultrix) || defined(__ultrix__) -#if defined (vax) || defined (__vax) || defined (__vax__) || defined(mips) || defined(__mips) || defined(__mips__) || defined(MIPS) || defined(__MIPS__) -#include -#if defined(_SIZE_T_) || defined(SIGLOST) -#include -#endif -#endif -#endif -main () -{ -#if defined (sony) -#if defined (MIPSEB) - /* BFD wants "bsd" instead of "newsos". Perhaps BFD should be changed, - I don't know.... */ - printf ("mips-sony-bsd\n"); exit (0); -#else -#include - printf ("m68k-sony-newsos%s\n", -#ifdef NEWSOS4 - "4" -#else - "" -#endif - ); exit (0); -#endif -#endif - -#if defined (NeXT) -#if !defined (__ARCHITECTURE__) -#define __ARCHITECTURE__ "m68k" -#endif - int version; - version=`(hostinfo | sed -n 's/.*NeXT Mach \([0-9]*\).*/\1/p') 2>/dev/null`; - if (version < 4) - printf ("%s-next-nextstep%d\n", __ARCHITECTURE__, version); - else - printf ("%s-next-openstep%d\n", __ARCHITECTURE__, version); - exit (0); -#endif - -#if defined (MULTIMAX) || defined (n16) -#if defined (UMAXV) - printf ("ns32k-encore-sysv\n"); exit (0); -#else -#if defined (CMU) - printf ("ns32k-encore-mach\n"); exit (0); -#else - printf ("ns32k-encore-bsd\n"); exit (0); -#endif -#endif -#endif - -#if defined (__386BSD__) - printf ("i386-pc-bsd\n"); exit (0); -#endif - -#if defined (sequent) -#if defined (i386) - printf ("i386-sequent-dynix\n"); exit (0); -#endif -#if defined (ns32000) - printf ("ns32k-sequent-dynix\n"); exit (0); -#endif -#endif - -#if defined (_SEQUENT_) - struct utsname un; - - uname(&un); - if (strncmp(un.version, "V2", 2) == 0) { - printf ("i386-sequent-ptx2\n"); exit (0); - } - if (strncmp(un.version, "V1", 2) == 0) { /* XXX is V1 correct? */ - printf ("i386-sequent-ptx1\n"); exit (0); - } - printf ("i386-sequent-ptx\n"); exit (0); -#endif - -#if defined (vax) -#if !defined (ultrix) -#include -#if defined (BSD) -#if BSD == 43 - printf ("vax-dec-bsd4.3\n"); exit (0); -#else -#if BSD == 199006 - printf ("vax-dec-bsd4.3reno\n"); exit (0); -#else - printf ("vax-dec-bsd\n"); exit (0); -#endif -#endif -#else - printf ("vax-dec-bsd\n"); exit (0); -#endif -#else -#if defined(_SIZE_T_) || defined(SIGLOST) - struct utsname un; - uname (&un); - printf ("vax-dec-ultrix%s\n", un.release); exit (0); -#else - printf ("vax-dec-ultrix\n"); exit (0); -#endif -#endif -#endif -#if defined(ultrix) || defined(_ultrix) || defined(__ultrix) || defined(__ultrix__) -#if defined(mips) || defined(__mips) || defined(__mips__) || defined(MIPS) || defined(__MIPS__) -#if defined(_SIZE_T_) || defined(SIGLOST) - struct utsname *un; - uname (&un); - printf ("mips-dec-ultrix%s\n", un.release); exit (0); -#else - printf ("mips-dec-ultrix\n"); exit (0); -#endif -#endif -#endif - -#if defined (alliant) && defined (i860) - printf ("i860-alliant-bsd\n"); exit (0); -#endif - - exit (1); -} -EOF - -$CC_FOR_BUILD -o "$dummy" "$dummy.c" 2>/dev/null && SYSTEM_NAME=`"$dummy"` && - { echo "$SYSTEM_NAME"; exit; } - -# Apollos put the system type in the environment. -test -d /usr/apollo && { echo "$ISP-apollo-$SYSTYPE"; exit; } - -echo "$0: unable to guess system type" >&2 - -case $UNAME_MACHINE:$UNAME_SYSTEM in - mips:Linux | mips64:Linux) - # If we got here on MIPS GNU/Linux, output extra information. - cat >&2 <&2 <&2 </dev/null || echo unknown` -uname -r = `(uname -r) 2>/dev/null || echo unknown` -uname -s = `(uname -s) 2>/dev/null || echo unknown` -uname -v = `(uname -v) 2>/dev/null || echo unknown` - -/usr/bin/uname -p = `(/usr/bin/uname -p) 2>/dev/null` -/bin/uname -X = `(/bin/uname -X) 2>/dev/null` - -hostinfo = `(hostinfo) 2>/dev/null` -/bin/universe = `(/bin/universe) 2>/dev/null` -/usr/bin/arch -k = `(/usr/bin/arch -k) 2>/dev/null` -/bin/arch = `(/bin/arch) 2>/dev/null` -/usr/bin/oslevel = `(/usr/bin/oslevel) 2>/dev/null` -/usr/convex/getsysinfo = `(/usr/convex/getsysinfo) 2>/dev/null` - -UNAME_MACHINE = "$UNAME_MACHINE" -UNAME_RELEASE = "$UNAME_RELEASE" -UNAME_SYSTEM = "$UNAME_SYSTEM" -UNAME_VERSION = "$UNAME_VERSION" -EOF -fi - -exit 1 - -# Local variables: -# eval: (add-hook 'before-save-hook 'time-stamp) -# time-stamp-start: "timestamp='" -# time-stamp-format: "%:y-%02m-%02d" -# time-stamp-end: "'" -# End: diff --git a/configure b/configure index 6e87fe9..494e21e 100755 --- a/configure +++ b/configure @@ -18,7 +18,6 @@ # options installdir='auto' ocamllibdir='auto' -host='auto' gmp='auto' perf='no' @@ -276,15 +275,6 @@ echo "OCaml's word size is $wordsize" rm -f tmp.ml -# auto-detect host - -if test "x$host" = 'xauto'; then - searchbin uname - if test $? -eq 0; then host='none' - else host=`. ./config.guess` - fi -fi - # check GMP, MPIR if test "$gmp" = 'gmp' || test "$gmp" = 'auto'; then From ff08cba866cf98b08c9e62271b572db30bbab3be Mon Sep 17 00:00:00 2001 From: Xavier Leroy Date: Sun, 26 Feb 2023 18:38:58 +0100 Subject: [PATCH 34/49] Use pkg-config to find GMP This works better on Mac with Homebrew, for example. Fall back to the old method if pkg-config is not available or doesn't work. --- configure | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/configure b/configure index 494e21e..a986cce 100755 --- a/configure +++ b/configure @@ -278,13 +278,20 @@ rm -f tmp.ml # check GMP, MPIR if test "$gmp" = 'gmp' || test "$gmp" = 'auto'; then - checkinc gmp.h - if test $? -eq 1; then - checklib gmp - if test $? -eq 1; then - gmp='OK' - cclib="$cclib -lgmp" - ccdef="-DHAS_GMP $ccdef" + if pkg-config gmp 2>/dev/null; then + gmp='OK' + cclib="$cclib $(pkg-config --libs gmp)" + ccinc="$ccinc $(pkg-config --cflags gmp)" + ccdef="-DHAS_GMP $ccdef" + else + checkinc gmp.h + if test $? -eq 1; then + checklib gmp + if test $? -eq 1; then + gmp='OK' + cclib="$cclib -lgmp" + ccdef="-DHAS_GMP $ccdef" + fi fi fi fi From fdb46434a80ec0eb7720e0032e70c5d96dce1cc8 Mon Sep 17 00:00:00 2001 From: Xavier Leroy Date: Sun, 26 Feb 2023 18:43:10 +0100 Subject: [PATCH 35/49] configure script: print additional, possibly interesting information Namely: - Whether GMP was found from pkg-config - Which C includes were selected (in summary of configuration) --- configure | 2 ++ 1 file changed, 2 insertions(+) diff --git a/configure b/configure index a986cce..81f858f 100755 --- a/configure +++ b/configure @@ -279,6 +279,7 @@ rm -f tmp.ml if test "$gmp" = 'gmp' || test "$gmp" = 'auto'; then if pkg-config gmp 2>/dev/null; then + echo 'package gmp: found' gmp='OK' cclib="$cclib $(pkg-config --libs gmp)" ccinc="$ccinc $(pkg-config --cflags gmp)" @@ -375,6 +376,7 @@ detected configuration: native-code: $hasocamlopt dynamic linking: $hasdynlink defines: $ccdef + includes: $ccinc libraries: $cclib linker options: $ldflags C options: $ccopt From b139389b451e44ac128c500dec285bef24ce4a16 Mon Sep 17 00:00:00 2001 From: hhugo Date: Tue, 18 Jul 2023 11:48:35 +0200 Subject: [PATCH 36/49] More CI jobs, including a Windows job (#134) Co-authored-by: Hugo Heuzard Co-authored-by: Xavier Leroy --- .github/workflows/build.yml | 71 +++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 .github/workflows/build.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..ce6e2e6 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,71 @@ +name: build + +on: + pull_request: + push: + branches: + - master + schedule: + # Prime the caches every Monday + - cron: 0 1 * * MON + +jobs: + build: + strategy: + fail-fast: false + matrix: + os: + - ubuntu-latest + - windows-latest + - macos-latest + ocaml-compiler: + - 4.14.x + include: + - os: ubuntu-latest + ocaml-compiler: 5.0.x + - os: macos-latest + ocaml-compiler: 5.0.x + - os: windows-latest + ocaml-compiler: ocaml.5.0.0,ocaml-option-mingw + + runs-on: ${{ matrix.os }} + + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Use OCaml ${{ matrix.ocaml-compiler }} + uses: ocaml/setup-ocaml@v2 + if: runner.os != 'Windows' + with: + ocaml-compiler: ${{ matrix.ocaml-compiler }} + dune-cache: true + opam-depext: true + opam-depext-flags: --with-test + + - name: Use OCaml ${{ matrix.ocaml-compiler }} + uses: ocaml/setup-ocaml@v2 + if: runner.os == 'Windows' + with: + ocaml-compiler: ${{ matrix.ocaml-compiler }} + opam-repositories: | + dra27: https://github.com/dra27/opam-repository.git#windows-5.0 + default: https://github.com/ocaml-opam/opam-repository-mingw.git#sunset + opam: https://github.com/ocaml/opam-repository.git + dune-cache: true + opam-depext: true + opam-depext-flags: --with-test + + - name: configure tree + run: opam exec -- ./configure + + - name: Build + run: opam exec -- make + + - name: Run the testsuite + run: opam exec -- make -C tests test + + - run: opam install . --with-test + + - run: opam exec -- git diff --exit-code + if: ${{ !matrix.skip-test }} From 6cc5793e66a459e54808b02ec2089bcddd56cd0c Mon Sep 17 00:00:00 2001 From: Xavier Leroy Date: Tue, 18 Jul 2023 11:47:33 +0200 Subject: [PATCH 37/49] config.guess is no more --- .gitattributes | 1 - 1 file changed, 1 deletion(-) diff --git a/.gitattributes b/.gitattributes index 8f48a14..3aa538a 100644 --- a/.gitattributes +++ b/.gitattributes @@ -2,4 +2,3 @@ * text=auto configure text eol=lf -config.guess text eol=lf From 1958fd62240bc3e7322c596c03ef88f528079439 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antoine=20Min=C3=A9?= Date: Tue, 18 Jul 2023 15:01:26 +0200 Subject: [PATCH 38/49] More precise bounds for of_float conversion to small ints (#137) This patch improves the bounds used in of_float to decide whether the double can fit into an OCaml 63-bit tagged int. The upper bound is 0x3ffffffffffffe00, which is exactly representable as a double (2^53-1)*2^9 = (2-2^-52) * 2^61 as it is 1.1...1 * 2^61 with 52 ones after the 1, and is less than 2^62, so it is representable as an OCaml int. The double just after 0x3ffffffffffffe00 is 0x4000000000000000, or 2^62, which does not fit an OCaml int. For the lower bound, -0x4000000000000000 is exactly representable as a double, but also the smallest number that fits an OCaml int. --- caml_z.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/caml_z.c b/caml_z.c index c79626a..02e758d 100644 --- a/caml_z.c +++ b/caml_z.c @@ -160,12 +160,10 @@ extern "C" { #endif #define Z_FITS_INT(v) ((v) >= Z_MIN_INT && (v) <= Z_MAX_INT) -/* Z_MAX_INT may not be representable exactly as a double => we use a - lower approximation to be safe - */ +/* greatest/smallest double that can fit in an int */ #ifdef ARCH_SIXTYFOUR -#define Z_MAX_INT_FL 0x3ffffffffffff000 -#define Z_MIN_INT_FL (-Z_MAX_INT_FL) +#define Z_MAX_INT_FL 0x3ffffffffffffe00 +#define Z_MIN_INT_FL (-0x4000000000000000) #else #define Z_MAX_INT_FL Z_MAX_INT #define Z_MIN_INT_FL Z_MIN_INT From 94f674e70be15a16a04161b4991f8e928d37ceaa Mon Sep 17 00:00:00 2001 From: Xavier Leroy Date: Wed, 19 Jul 2023 10:59:36 +0200 Subject: [PATCH 39/49] Updates for release 1.13 --- Changes | 12 ++++++++++++ META | 4 ++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/Changes b/Changes index 68bcf8c..b74e0c5 100644 --- a/Changes +++ b/Changes @@ -1,3 +1,15 @@ +Release 1.13 (2023-07-19) +- #113: add conversions to/from small unsigned integers `(to|fits)_(int32|int64|nativeint)_unsigned` [Antoine Miné] +- #128: add functions to pseudo-randomly generate integers [Xavier Leroy] +- #105: add `Big_int.big_int_of_float` [Yishuai Li] +- #90: add fast path to `Z.extract` when extraction leads to a small integer [Frédéric Recoules] +- #137: more precise bounds for of_float conversion to small ints [Antoine Miné] +- #118: fix Z_mlgmpidl interface for mlgmpidl >= 1.2 [Simmo Saan] +- #109: fix typo in `ml_z_mul` function [Bernhard Schommer] +- #108: fix dependency on C evaluation order in `ml_z_remove` [Xavier Clerc] +- #117 #120 #124 #129 #132 #135 #139 #141: configure & build simplifications and fixes [various authors] +- #134: CI testing: add Windows, test both 4.14 and 5.0 [Hugo Heuzard] + Release 1.12 (2021-03-03) - PR #79: fast path in OCaml (instead of assembly language) [Xavier Leroy] - PR #94: remove source preprocessing and simplify configuration [Xavier Leroy] diff --git a/META b/META index 1828d24..a409856 100644 --- a/META +++ b/META @@ -1,13 +1,13 @@ description = "Arbitrary precision integers" requires = "" -version = "1.12" +version = "1.13" archive(byte) = "zarith.cma" archive(native) = "zarith.cmxa" plugin(byte) = "zarith.cma" plugin(native) = "zarith.cmxs" package "top" ( - version = "1.12" + version = "1.13" description = "ZArith toplevel support" requires = "zarith" archive(byte) = "zarith_top.cma" From b9759081cffbcd692502b06af6cfbce97ccabc18 Mon Sep 17 00:00:00 2001 From: Xavier Leroy Date: Wed, 19 Jul 2023 19:54:49 +0200 Subject: [PATCH 40/49] Revert #124 `-L/path/to/gmp/lib` must be passed as is to `ocamlmklib`, not behind a `-ldopt` flag, otherwise it is ignored in static linking situations. --- Changes | 2 +- project.mak | 8 +++----- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/Changes b/Changes index b74e0c5..f4d2082 100644 --- a/Changes +++ b/Changes @@ -7,7 +7,7 @@ Release 1.13 (2023-07-19) - #118: fix Z_mlgmpidl interface for mlgmpidl >= 1.2 [Simmo Saan] - #109: fix typo in `ml_z_mul` function [Bernhard Schommer] - #108: fix dependency on C evaluation order in `ml_z_remove` [Xavier Clerc] -- #117 #120 #124 #129 #132 #135 #139 #141: configure & build simplifications and fixes [various authors] +- #117 #120 #129 #132 #135 #139 #141: configure & build simplifications and fixes [various authors] - #134: CI testing: add Windows, test both 4.14 and 5.0 [Hugo Heuzard] Release 1.12 (2021-03-03) diff --git a/project.mak b/project.mak index 018801d..3d5a837 100644 --- a/project.mak +++ b/project.mak @@ -62,8 +62,6 @@ TOINSTALL += $(CMIDOC) OCAMLFLAGS += -bin-annot endif -MKLIBLDFLAGS = $(foreach flag, $(LDFLAGS), -ldopt $(flag)) - # build targets ############### @@ -73,16 +71,16 @@ tests: make -C tests test zarith.cma: $(MLSRC:%.ml=%.cmo) - $(OCAMLMKLIB) $(DEBUG) -failsafe -o zarith $+ $(LIBS) $(MKLIBLDFLAGS) + $(OCAMLMKLIB) $(DEBUG) -failsafe -o zarith $+ $(LIBS) $(LDFLAGS) zarith.cmxa: $(MLSRC:%.ml=%.cmx) - $(OCAMLMKLIB) $(DEBUG) -failsafe -o zarith $+ $(LIBS) $(MKLIBLDFLAGS) + $(OCAMLMKLIB) $(DEBUG) -failsafe -o zarith $+ $(LIBS) $(LDFLAGS) zarith.cmxs: zarith.cmxa libzarith.$(LIBSUFFIX) $(OCAMLOPT) -shared -o $@ -I . zarith.cmxa -linkall libzarith.$(LIBSUFFIX): $(CSRC:%.c=%.$(OBJSUFFIX)) - $(OCAMLMKLIB) $(DEBUG) -failsafe -o zarith $+ $(LIBS) $(MKLIBLDFLAGS) + $(OCAMLMKLIB) $(DEBUG) -failsafe -o zarith $+ $(LIBS) $(LDFLAGS) zarith_top.cma: zarith_top.cmo $(OCAMLC) $(DEBUG) -o $@ -a $< From cf4154d33fef2958aba29f7790cee181a2c911d6 Mon Sep 17 00:00:00 2001 From: Hugo Heuzard Date: Thu, 20 Jul 2023 14:33:53 +0200 Subject: [PATCH 41/49] document jsoo support --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 62029fd..d552663 100644 --- a/README.md +++ b/README.md @@ -27,6 +27,9 @@ Additional features include: * a module `Q` for rationals, built on top of `Z` (see `q.mli`) * a compatibility layer `Big_int_Z` that implements the same API as Big_int from the legacy `Num` library, but uses `Z` internally +Support for [js_of_ocaml](https://github.com/ocsigen/js_of_ocaml/) is +provided by [Zarith_stubs_js](https://github.com/janestreet/zarith_stubs_js). + ## REQUIREMENTS * OCaml, version 4.04.0 or later. From 524a489cb10e17c9e3e55a3b74d1a9820d0a6a66 Mon Sep 17 00:00:00 2001 From: Xavier Leroy Date: Mon, 20 Nov 2023 14:29:08 +0100 Subject: [PATCH 42/49] Fast path for Z.divisible on small arguments (#147) Closes: #140 --- tests/zq.ml | 10 ++++++++++ tests/zq.output32 | 18 ++++++++++++++++++ tests/zq.output64 | 18 ++++++++++++++++++ z.ml | 22 +++++++++++++++++++++- z.mli | 2 +- 5 files changed, 68 insertions(+), 2 deletions(-) diff --git a/tests/zq.ml b/tests/zq.ml index 1cb1115..fb007ca 100644 --- a/tests/zq.ml +++ b/tests/zq.ml @@ -657,6 +657,16 @@ let test_Z() = Printf.printf "hamdist 2^120 (2^120-1)\n = %i\n" (I.hamdist p120 (I.pred p120)); Printf.printf "hamdist 2^120 2^300\n = %i\n" (I.hamdist p120 p300); Printf.printf "hamdist (2^120-1) (2^300-1)\n = %i\n" (I.hamdist (I.pred p120) (I.pred p300)); + Printf.printf "divisible 42 7\n = %B\n" (I.divisible (I.of_int 42) (I.of_int 7)); + Printf.printf "divisible 43 7\n = %B\n" (I.divisible (I.of_int 43) (I.of_int 7)); + Printf.printf "divisible 0 0\n = %B\n" (I.divisible I.zero I.zero); + Printf.printf "divisible 0 2^120\n = %B\n" (I.divisible I.zero p120); + Printf.printf "divisible 2 2^120\n = %B\n" (I.divisible (I.of_int 2) p120); + Printf.printf "divisible 2^300 2^120\n = %B\n" (I.divisible p300 p120); + Printf.printf "divisible (2^300-1) 32\n = %B\n" (I.divisible (I.pred p300) (I.of_int 32)); + Printf.printf "divisible min_int (max_int+1)\n = %B\n" (I.divisible (I.of_int min_int) (I.succ (I.of_int max_int))); + Printf.printf "divisible (max_int+1) min_int\n = %B\n" (I.divisible (I.succ (I.of_int max_int)) (I.of_int min_int)); + (* always 0 when not using custom blocks *) Printf.printf "hash(2^120)\n = %i\n" (Hashtbl.hash p120); Printf.printf "hash(2^121)\n = %i\n" (Hashtbl.hash p121); diff --git a/tests/zq.output32 b/tests/zq.output32 index b22a85c..d0912dd 100644 --- a/tests/zq.output32 +++ b/tests/zq.output32 @@ -903,6 +903,24 @@ hamdist 2^120 2^300 = 2 hamdist (2^120-1) (2^300-1) = 180 +divisible 42 7 + = true +divisible 43 7 + = false +divisible 0 0 + = true +divisible 0 2^120 + = true +divisible 2 2^120 + = false +divisible 2^300 2^120 + = true +divisible (2^300-1) 32 + = false +divisible min_int (max_int+1) + = true +divisible (max_int+1) min_int + = true hash(2^120) = 691199303 hash(2^121) diff --git a/tests/zq.output64 b/tests/zq.output64 index 61bd14e..a49ec06 100644 --- a/tests/zq.output64 +++ b/tests/zq.output64 @@ -903,6 +903,24 @@ hamdist 2^120 2^300 = 2 hamdist (2^120-1) (2^300-1) = 180 +divisible 42 7 + = true +divisible 43 7 + = false +divisible 0 0 + = true +divisible 0 2^120 + = true +divisible 2 2^120 + = false +divisible 2^300 2^120 + = true +divisible (2^300-1) 32 + = false +divisible min_int (max_int+1) + = true +divisible (max_int+1) min_int + = true hash(2^120) = 691199303 hash(2^121) diff --git a/z.ml b/z.ml index 772621d..975823f 100644 --- a/z.ml +++ b/z.ml @@ -261,7 +261,27 @@ external nextprime: t -> t = "ml_z_nextprime" external hash: t -> int = "ml_z_hash" [@@noalloc] external to_bits: t -> string = "ml_z_to_bits" external of_bits: string -> t = "ml_z_of_bits" -external divisible: t -> t -> bool = "ml_z_divisible" + +external c_divisible: t -> t -> bool = "ml_z_divisible" + +let divisible x y = + if is_small_int x then + if is_small_int y then + if unsafe_to_int y = 0 + then unsafe_to_int x = 0 + else (unsafe_to_int x) mod (unsafe_to_int y) = 0 + else + (* If y divides x, we have |y| <= |x| or x = 0. + Here, x is small: min_int <= x <= max_int + and y is not small: y < min_int \/ y > max_int. + |y| <= |x| is possible only if + x = min_int and y = -min_int = max_int+1 . + So, the only two cases where y divides x are + x = 0 or x = min_int /\ y = -min_int. *) + unsafe_to_int x = 0 || (unsafe_to_int x = min_int && y = c_neg x) + else + c_divisible x y + external congruent: t -> t -> t -> bool = "ml_z_congruent" external jacobi: t -> t -> int = "ml_z_jacobi" external legendre: t -> t -> int = "ml_z_legendre" diff --git a/z.mli b/z.mli index cbbf7c5..70098ff 100644 --- a/z.mli +++ b/z.mli @@ -209,7 +209,7 @@ val divexact: t -> t -> t Can raise a [Division_by_zero]. *) -external divisible: t -> t -> bool = "ml_z_divisible" +val divisible: t -> t -> bool (** [divisible a b] returns [true] if [a] is exactly divisible by [b]. Unlike the other division functions, [b = 0] is accepted (only 0 is considered divisible by 0). From cf2f94439a67cd65d5f94fb30a07f460c39e2bc0 Mon Sep 17 00:00:00 2001 From: Xavier Leroy Date: Thu, 28 Dec 2023 18:11:38 +0100 Subject: [PATCH 43/49] Use standard hash function for `Z.hash` and add `Z.seeded_hash` For consistency with other integer types in the standard library (modules Int, Int32, Int64, Nativeint), let's use the standard hash function (`Hashtbl.hash`) for `Z.hash` instead of our variant. This is a bit slower but has several benefits (see #145): - 32/64 bit compatibility - better mixing of the bits of the result. While we're at it, add a `Z.seeded_hash` function, defined as `Hashtbl.seeded_hash`, so that the `Z` module can be used as the argument to the `Hashtbl.MakeSeeded` functor. --- caml_z.c | 5 ----- z.ml | 3 ++- z.mli | 28 +++++++++++++++++++++++----- 3 files changed, 25 insertions(+), 11 deletions(-) diff --git a/caml_z.c b/caml_z.c index 02e758d..040bb90 100644 --- a/caml_z.c +++ b/caml_z.c @@ -3350,11 +3350,6 @@ static intnat ml_z_custom_hash(value v) return acc; } -CAMLprim value ml_z_hash(value v) -{ - return Val_long(ml_z_custom_hash(v)); -} - /* serialized format: - 1-byte sign (1 for negative, 0 for positive) - 4-byte size in bytes diff --git a/z.ml b/z.ml index 975823f..58faadb 100644 --- a/z.ml +++ b/z.ml @@ -258,7 +258,8 @@ external perfect_power: t -> bool = "ml_z_perfect_power" external perfect_square: t -> bool = "ml_z_perfect_square" external probab_prime: t -> int -> int = "ml_z_probab_prime" external nextprime: t -> t = "ml_z_nextprime" -external hash: t -> int = "ml_z_hash" [@@noalloc] +let hash: t -> int = Stdlib.Hashtbl.hash +let seeded_hash: int -> t -> int = Stdlib.Hashtbl.seeded_hash external to_bits: t -> string = "ml_z_to_bits" external of_bits: string -> t = "ml_z_of_bits" diff --git a/z.mli b/z.mli index 70098ff..1794942 100644 --- a/z.mli +++ b/z.mli @@ -486,12 +486,24 @@ val is_odd: t -> bool @since 1.4 *) -external hash: t -> int = "ml_z_hash" [@@noalloc] +val hash: t -> int (** Hashes a number, producing a small integer. - The result is consistent with equality: if [a] = [b], then [hash a] = - [hash b]. - OCaml's generic hash function, [Hashtbl.hash], works correctly with - numbers, but {!Z.hash} is slightly faster. + The result is consistent with equality: + if [a] = [b], then [hash a] = [hash b]. + The result is the same as produced by OCaml's generic hash function, + {!Hashtbl.hash}. + Together with type {!Z.t}, the function {!Z.hash} makes it possible + to pass module {!Z} as argument to the functor {!Hashtbl.Make}. + @before 1.14 a different hash algorithm was used. +*) + +val seeded_hash: int -> t -> int +(** Like {!Z.hash}, but takes a seed as extra argument for diversification. + The result is the same as produced by OCaml's generic seeded hash function, + {!Hashtbl.seeded_hash}. + Together with type {!Z.t}, the function {!Z.hash} makes it possible + to pass module {!Z} as argument to the functor {!Hashtbl.MakeSeeded}. + @since 1.14 *) (** {1 Elementary number theory} *) @@ -717,6 +729,8 @@ val random_int: ?rng: Random.State.t -> t -> t Random numbers produced by this function are not cryptographically strong and must not be used in cryptographic or high-security contexts. See {!Z.random_int_gen} for an alternative. + + @since 1.13 *) val random_bits: ?rng: Random.State.t -> int -> t @@ -731,6 +745,8 @@ val random_bits: ?rng: Random.State.t -> int -> t Random numbers produced by this function are not cryptographically strong and must not be used in cryptographic or high-security contexts. See {!Z.random_bits_gen} for an alternative. + + @since 1.13 *) val random_int_gen: fill: (bytes -> int -> int -> unit) -> t -> t @@ -751,6 +767,7 @@ val random_int_gen: fill: (bytes -> int -> int -> unit) -> t -> t << Z.random_int_gen ~fill:Cryptokit.Random.secure_rng#bytes bound >> + @since 1.13 *) val random_bits_gen: fill: (bytes -> int -> int -> unit) -> int -> t @@ -759,6 +776,7 @@ val random_bits_gen: fill: (bytes -> int -> int -> unit) -> int -> t This is a more efficient special case of {!Z.random_int_gen} when the bound is a power of two. The [fill] parameter is as described in {!Z.random_int_gen}. + @since 1.13 *) (** {1 Prefix and infix operators} *) From b9c96768b0764ab54ea04dfab1259b05731a8bad Mon Sep 17 00:00:00 2001 From: Xavier Leroy Date: Thu, 28 Dec 2023 18:15:48 +0100 Subject: [PATCH 44/49] Test the hash function with random integers and the chi2 test --- tests/Makefile | 2 +- tests/chi2.ml | 33 +++++++++++++++++++++++++-------- 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/tests/Makefile b/tests/Makefile index 760294b..f06bcb1 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -38,7 +38,7 @@ test:: ofstring.exe test:: chi2.exe @echo "Testing random number generation..." - @./chi2.exe + @if ./chi2.exe; then echo "chi2: passed"; else echo "chi2: FAILED"; exit 2; fi bench:: timings.exe ./timings.exe diff --git a/tests/chi2.ml b/tests/chi2.ml index 1241828..86a5738 100644 --- a/tests/chi2.ml +++ b/tests/chi2.ml @@ -1,12 +1,11 @@ (* Accumulate [n] samples from function [f] and check the chi-square. - Only the low 8 bits of the result of [f] are sampled. *) + Assumes [f] returns integers in the [0..255] range. *) let chisquare n f = let r = 256 in let freq = Array.make r 0 in for i = 0 to n - 1 do - let t = Z.to_int (Z.logand (f ()) (Z.of_int 0xFF)) in - freq.(t) <- freq.(t) + 1 + let t = f () in freq.(t) <- freq.(t) + 1 done; let expected = float n /. float r in let t = @@ -22,9 +21,19 @@ let chisquare n f = *) chi2 <= degfree +. 4.0 *. sqrt (2.0 *. degfree) +let failed = ref false + +let test_base name f = + if not (chisquare 100_000 f) then begin + Printf.printf "%s: suspicious result\n%!" name; + failed := true + end + let test name f = - if not (chisquare 100_000 f) - then Printf.printf "%s: suspicious result\n%!" name + (* Test the low 8 bits of the result of f *) + test_base name (fun () -> Z.to_int (Z.logand (f ()) (Z.of_int 0xFF))) + +let p = Z.of_string "35742549198872617291353508656626642567" let _ = test "random_bits 15 (bits 0-7)" @@ -38,6 +47,14 @@ let _ = test "random_int 2^30 (bits 21-28)" (fun () -> Z.(shift_right (random_int (shift_left one 30)) 21)); test "random_int (256 * p) / p" - (let p = Z.of_string "35742549198872617291353508656626642567" in - let bound = Z.shift_left p 8 in - fun () -> Z.(div (random_int bound) p)) + (let bound = Z.shift_left p 8 in + fun () -> Z.(div (random_int bound) p)); + (* Also test our hash function, why not? *) + test_base "hash (random_int p) (bits 0-7)" + (fun () -> Z.(hash (random_int p)) land 0xFF); + test_base "hash (random_int p) (bits 16-23)" + (fun () -> (Z.(hash (random_int p)) lsr 16) land 0xFF); + exit (if !failed then 2 else 0) + + + From d0a89ee751dcd00977272ae278083900956fb505 Mon Sep 17 00:00:00 2001 From: Xavier Leroy Date: Wed, 3 Jan 2024 14:17:14 +0100 Subject: [PATCH 45/49] Fail when unmarshaling would produce non-canonical big integers (#149) This can happen with numbers marshaled on a 32-bit platform (including from JS-of-OCaml) and unmarshaled on a 64-bit platform. Fixes: #148 --- caml_z.c | 23 ++++++-- tests/Makefile | 8 +++ tests/extern.data32 | Bin 0 -> 22300 bytes tests/extern.data64 | Bin 0 -> 20292 bytes tests/extern.ml | 14 +++++ tests/intern.ml | 24 +++++++++ tests/intern.output3232 | 113 ++++++++++++++++++++++++++++++++++++++++ tests/intern.output3264 | 113 ++++++++++++++++++++++++++++++++++++++++ tests/intern.output6432 | 113 ++++++++++++++++++++++++++++++++++++++++ tests/intern.output6464 | 113 ++++++++++++++++++++++++++++++++++++++++ 10 files changed, 517 insertions(+), 4 deletions(-) create mode 100644 tests/extern.data32 create mode 100644 tests/extern.data64 create mode 100644 tests/extern.ml create mode 100644 tests/intern.ml create mode 100644 tests/intern.output3232 create mode 100644 tests/intern.output3264 create mode 100644 tests/intern.output6432 create mode 100644 tests/intern.output6464 diff --git a/caml_z.c b/caml_z.c index 040bb90..a60637c 100644 --- a/caml_z.c +++ b/caml_z.c @@ -3390,10 +3390,17 @@ static void ml_z_custom_serialize(value v, #endif } -/* XXX: serializing a large (i.e., > 2^31) int on a 64-bit machine and - deserializing on a 32-bit machine will fail (instead of returning a - block). - */ +/* There are two issues with integers that are tagged ints on a 64-bit + machine but boxed bigints on a 32-bit machine, namely integers in the + [2^30, 2^62) and [-2^62, -2^30) ranges: + - Serializing such an integer on a 64-bit machine and + deserializing on a 32-bit machine will fail in the generic unmarshaler. + The correct behavior would be to return a boxed integer. + - Serializing such an integer on a 32-bit machine and + deserializing on a 64-bit machine must fail. + The wrong behavior would be to return a block containing a + non-normalized, boxed integer (issue #148). +*/ static uintnat ml_z_custom_deserialize(void * dst) { mp_limb_t* d = ((mp_limb_t*)dst) + 1; @@ -3439,6 +3446,14 @@ static uintnat ml_z_custom_deserialize(void * dst) #if Z_PERFORM_CHECK d[szw] = 0xDEADBEEF ^ szw; szw++; +#endif +#if Z_USE_NATINT + if (i == 0 || + (i == 1 && (d[0] <= Z_MAX_INT || (d[0] == -Z_MIN_INT && sign)))) { + /* Issue #148: this is not a canonical representation, + so we raise a Failure */ + caml_deserialize_error("Z.t value produced on a 32-bit platform cannot be read on a 64-bit platform"); + } #endif return (szw+1) * sizeof(mp_limb_t); } diff --git a/tests/Makefile b/tests/Makefile index f06bcb1..73ee2cb 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -50,6 +50,14 @@ test:: tst_extract.exe @echo "Testing extract..." @if ./tst_extract.exe; then echo "tst_extract: passed"; else echo "tst_extract: FAILED"; exit 2; fi +test:: intern.exe + @echo "Testing unmarshaling..." + @if ./intern.exe extern.data32 | cmp -s intern.output32$(WORDSIZE) -; then echo "intern 32: passed"; else echo "intern 32: failed"; exit 2; fi + @if ./intern.exe extern.data64 | cmp -s intern.output64$(WORDSIZE) -; then echo "intern 64: passed"; else echo "intern 64: failed"; exit 2; fi + +extern.data$(WORDSIZE): extern.exe + ./extern.exe extern.data$(WORDSIZE) + tofloat.exe: tofloat.ml setround.o ../zarith.cmxa ocamlopt -I .. -ccopt "-L.." zarith.cmxa -o tofloat.exe \ setround.o tofloat.ml diff --git a/tests/extern.data32 b/tests/extern.data32 new file mode 100644 index 0000000000000000000000000000000000000000..003164380b9f39c6d2c612ee7d827f049868dfd1 GIT binary patch literal 22300 zcmbW9Pm7_wzKR1Z&mj*GtHi&6%5ZgZ+#P(BznBE%1v^0qATZ7ov1~IjWsYTf3(YQXQRz{1k z%cFip+2v8su*;)P*yT|t?DD7+c6rnZyFBWIT^@D9E{{54mq(qj%cD-%@~9Jb zdDIEJJnDp99(BSlk2>*li}M7e4A-N9)t>pk-EVB0eq?9;F*esR{zKH0XKe}B*V zRImHq9|J-I&=u9#C!2dZm%4k`U_Z8D?_EISeE#7Aehesv0vh|Q`O_&mppGVFhj4>n z4ixYy$>D=-k)!N@I+~Cj!VQQyP{5}ohmW>3er!9S53_9Tu379VlS?y*a$W1P9bD_9D{RVI2W%>_h>L_2cl(HprA5P`BEP z0NFwJdJHIm0vhTL_IDf=tPQk%Zvzgc8DWU_fyAfD(cOO9&3nC?Pm7AUJ$P z3BiFS1cw)t5F8i~96qCj;J^}s!;BJw0|SD?D@q6sEFm~7C?Pm7AUM3Cgy6sug2Rdu zf&&AB!#9)=99TkdnBI{)UvOYRaM(s2SVDAoKk9&h=zzYZa2zI-5FMUI9S{&5K9Gdy zfD)p^Gf9Z&5(1*bN0Ja7P(pNgAqmj|0ny*KYJEQ|*gB_@quv?{|-{ z_aEDk0JQ);o|-=!u#Ti?=cz^#Qyx!EQ&O{MJL5hSQoyI=6TXD*^c+&BMw7Jje2naA z(zp|aG^^|s>J;3GCheR;aiE*zkmjgHA&t#Wp>EMla!8#TP1-r>3L|Iv&WS>rRdxz> z4DLjec24sZCkolVi<3RJLf@W4>eOa?;jdg`YKy%vBtUJk7lAZ3A18Z^#UYVui@iwF z?l`R@kd5`WT2GQRI6K*6Ee?rPTkS=Xc1~IWFr*Z35YpJ}WRJN}l0)je!KA&DtpMXr z5YnuQ6P%ty?xPMS?VW4|7v`PPRaeJHe#Alie0b(%uO|dna3E-)gsmpYeG^=vogGriq{`-^ub1E`DhZJ{f4AR(g z?%4uGk{r6FsAowBr(7KAetQQe2Kn^Lamsa@ZjwXlZjB`!oN}?Gn{;qukY*K*Q?BE5 zlN`GFsAowBrx~3Q2PX#k^vZF{b)69>mUM7ht~fF1;FRk;BTg*o;Iv+GV$i`U*L_Bu zSkl2M7hAeX4rz|}mdYVrNMpnGlLl!`G!P6*PhqEo69b(0*r`{)fN9i38frkmtYNJ5atN2gRb>LxifnsjtZ#hPx? z(Fs9Er&LGkCLNtn($Q%qzp)&h5Oj1(b)_LElyr1jt~ep+=#=VALry5^=(JvOLeSAE z)t!c%QqrGnZ<@NEyQkXI4@$7+wI~0_FSnm>Bkx|1!361D5#$Te*m$o!6EYV6K2)UCRS4ysFyCY~I1#$UP?DX1Cl977#z%#kLZ9OtW!6tw;C z9qq9p`c@rOm)dL__;5%xwZ%3tm>|6`_9CFh?vA59M&zLA)E3(yiKpYZj(|2cx7D^t zqJW*FJyztP=+su*Ac-eOt#KGkY5opDjomrgV@8zdpt{^(;@QzwookK|)C~8IaHy0|H#ERo`)scY} z$6V(db!3SZ$Mvcs11pZX?lXzz;-9!h~g@zJqj;TP`O{_U0P%}Ip$5cn`COR1W{O617<1}ONkcdE^+Tl2+y5g`S zN~|5n<*FkBYmTYTIP8cLYmVzxM+DX!Q{8dcF(v-l_9_*XK)%2KySFb&vNr33AJoOB fpYNWJ;RtFwz>lYVIA>EGvYV=qR6EtSH>Lg`$wjaX literal 0 HcmV?d00001 diff --git a/tests/extern.data64 b/tests/extern.data64 new file mode 100644 index 0000000000000000000000000000000000000000..6d0c104c5f689800432dc3c101c5d765f9111664 GIT binary patch literal 20292 zcmbW9O>*Q!5QR0i2b%~Y>;;QiK(sb2IYa9v+=Gp^;0j!UV=%sneFNA*1TZ3BX6mP^ zGTX1ZBBmsF)u&farR*mYVSf4bx8H|h_$dFjcC&n0mS4hwWf;PNVMvJKLqaV7CB*V2 zA%+hLG2A4?@=ro6|0cw6n-IfYLM(qJ#PWAS4EG5!JS4>OM?x%rCdBZV5W`bKEUyW% zyd}hNN{C@hh~;xaEH4Q$oD*W05@LByh-FTQAtQ#2kn%|CW5_fzLdqkqC@GIvL&_s2 zq m$|EMEJYqu1BPOIgVnWIzCZs%KLdqj1q m$|EMEJYqu1BPOIgVnWIzCSEh* zEhA1DG490Ia=JC#T$D(>vKN^be)pbtqP!d~Jnd9DC=g0z)oKUljFit&GBJt4S^oJ- zo6DkfViE(OLlOfiDPt(3m=p@7lxm`!Vp2XwNyVfLqO4+4Ae2^2%I7Grn3T`;DadXD z$}A@3vM9Aw6Xh0@@;OQ_CS?$17n1^^^kPyzNBPC1e2x-~Nf|^L#-u>6DJcVQDJcV| zl$60SC58H&k}~j;k}_~kNg13{QmE&Ylz}-VWgsVIFeewh_(=<&KKUGy@vg|{IqBsY zlU|;grj}<+dU?jAmuF0RdB&udXH0r|#^ivP#Ow}vdB)^|m&J_q@{CC@&v><7o-yg= z8IxX~G3n(QlU|-N>E#)dUY;@OE#)dUY;@OGg+;rXF^(fCZwfjLRxwzq@`ydS3L>dS4mT79|ANPW4@NPW4@NPW4@$XB7z!gsJYq0qv? zlX3|;Dz}l}%a3@h@ZbIJKK=AFM!!KP?Fj=9{?JXK)C=ZG3kT2TIxb4#BI_2cQWt^a z+Gdx3AApQB3c$n%xA4p;D1c7ds_=uHW2yJ@@1x(}Z{-~A69)7q<0rq*gDbrc0z#|6 zi#GxDS5NDcbx{ex`k2;A7s0|?^(FE?2wAiq5c8jWzn1EzTvSvL9a@iK;j#MCx~Qn2 z>8-yjY&CQd1haX(^(!z>jDkLYef{Adwe@bU70M_U9(zDt>bj4p8#G1{^R{QTN3qz) z^$Lt);jstQrLG{p;~j?W*a4zTbz_kuoueR-uG05F@!=MF^$eSVi>;c-nJ=B^g|*aPZP z*Ltj8(BJ<;UOo0GmL5HI`aO1lrAO#XV-zuO`_5Sdk^xJP9*{H$S#2F4=5NpH;sMDh zDyVAcIuuKfo;r-8f}3Io2xj-_0m&#Tc#UG|(H{jyvGmvhmL5GI8O73Lhhph*wA;ie zmL5AmUF!Co;{nMiDrgIoezY?NEIm%0piP&)0|c`_s~(WdQWZp}ZL$LcmLBI$(56e@ z0fN~*dO$KuRS=!F*$xa?di2zxLDNBx>vTlG_N;n9GKvt`v!g??@@P57C@Kh9Ydnbg z`#$<_kc^^&riPwZtUOxkFp8B&9@M4o`)C2lC@P4~8n0M+w47rUD~~*g6(07{0+LZw z(EOq26)TVSyfccGM;_Fr?)zu~$tWs_&Kj>+c^s8z6f2KB2!+EwT0k<23Zk<%>VW|( zk5eD0v$f+vOh0(EfMk}cAUbQ49vHClIQM}%TRR@a^n*tWNM@-DqO&&ZfdMOzmO3=( zayZ~Z{I5uRJz79AiV!&DBd=I{)YM@V6@;ue8pQm=K3YIBiVC_K4zyzJQB#LetUc18 zF7>dF8jy^lg6O=_inT{g9Y(SCNP}46aUV4x8AS!%9}cu)?NJ|iMzQutgSyniK59TR ziVC9hMl04HM_hnWtUb~o1djWt0m&#Th|b%HBLmhRr!Ekay-heWikNrwr~yfXpuJ5v zGGOg-?gBB{+l(Wlho z$SO7-kvfcGme51CPT8=9@h5$bq`l zavzs#J#vbX$D3h{h0wHk0T9MiWI0ztM>84C@Of3 zV&rjR6r+8lz{um7QH(rNijl{eQH(rNVB~TAd&iEyeXtE(6@Qc;u_F9`f4=g+d;HF( s3?l~gk01R5J>Ww$_xk*4Y$bH&1?QB*4A0IJcnE(I) literal 0 HcmV?d00001 diff --git a/tests/extern.ml b/tests/extern.ml new file mode 100644 index 0000000..247677b --- /dev/null +++ b/tests/extern.ml @@ -0,0 +1,14 @@ +(* Marshal some interesting big integers to the given file *) + +let _ = + let file = Sys.argv.(1) in + let oc = open_out_bin file in + for nbits = 16 to 128 do + let x = Z.shift_left Z.one nbits in + output_value oc (Z.pred (Z.neg x)); + output_value oc (Z.neg x); + output_value oc (Z.pred x); + output_value oc x + done; + close_out oc + diff --git a/tests/intern.ml b/tests/intern.ml new file mode 100644 index 0000000..c7940ae --- /dev/null +++ b/tests/intern.ml @@ -0,0 +1,24 @@ +(* Unmarshal big integers from the given file, and report errors *) + +open Printf + +let expect ic n = + try + let m = (input_value ic : Z.t) in + if Z.equal m n then printf " OK" else printf " Wrong" + with Failure _ -> + printf " Fail" + +let _ = + let file = Sys.argv.(1) in + let ic = open_in_bin file in + for nbits = 16 to 128 do + printf "%d:" nbits; + let x = Z.shift_left Z.one nbits in + expect ic (Z.pred (Z.neg x)); + expect ic (Z.neg x); + expect ic (Z.pred x); + expect ic x; + print_newline() + done; + close_in ic diff --git a/tests/intern.output3232 b/tests/intern.output3232 new file mode 100644 index 0000000..9029dd2 --- /dev/null +++ b/tests/intern.output3232 @@ -0,0 +1,113 @@ +16: OK OK OK OK +17: OK OK OK OK +18: OK OK OK OK +19: OK OK OK OK +20: OK OK OK OK +21: OK OK OK OK +22: OK OK OK OK +23: OK OK OK OK +24: OK OK OK OK +25: OK OK OK OK +26: OK OK OK OK +27: OK OK OK OK +28: OK OK OK OK +29: OK OK OK OK +30: OK OK OK OK +31: OK OK OK OK +32: OK OK OK OK +33: OK OK OK OK +34: OK OK OK OK +35: OK OK OK OK +36: OK OK OK OK +37: OK OK OK OK +38: OK OK OK OK +39: OK OK OK OK +40: OK OK OK OK +41: OK OK OK OK +42: OK OK OK OK +43: OK OK OK OK +44: OK OK OK OK +45: OK OK OK OK +46: OK OK OK OK +47: OK OK OK OK +48: OK OK OK OK +49: OK OK OK OK +50: OK OK OK OK +51: OK OK OK OK +52: OK OK OK OK +53: OK OK OK OK +54: OK OK OK OK +55: OK OK OK OK +56: OK OK OK OK +57: OK OK OK OK +58: OK OK OK OK +59: OK OK OK OK +60: OK OK OK OK +61: OK OK OK OK +62: OK OK OK OK +63: OK OK OK OK +64: OK OK OK OK +65: OK OK OK OK +66: OK OK OK OK +67: OK OK OK OK +68: OK OK OK OK +69: OK OK OK OK +70: OK OK OK OK +71: OK OK OK OK +72: OK OK OK OK +73: OK OK OK OK +74: OK OK OK OK +75: OK OK OK OK +76: OK OK OK OK +77: OK OK OK OK +78: OK OK OK OK +79: OK OK OK OK +80: OK OK OK OK +81: OK OK OK OK +82: OK OK OK OK +83: OK OK OK OK +84: OK OK OK OK +85: OK OK OK OK +86: OK OK OK OK +87: OK OK OK OK +88: OK OK OK OK +89: OK OK OK OK +90: OK OK OK OK +91: OK OK OK OK +92: OK OK OK OK +93: OK OK OK OK +94: OK OK OK OK +95: OK OK OK OK +96: OK OK OK OK +97: OK OK OK OK +98: OK OK OK OK +99: OK OK OK OK +100: OK OK OK OK +101: OK OK OK OK +102: OK OK OK OK +103: OK OK OK OK +104: OK OK OK OK +105: OK OK OK OK +106: OK OK OK OK +107: OK OK OK OK +108: OK OK OK OK +109: OK OK OK OK +110: OK OK OK OK +111: OK OK OK OK +112: OK OK OK OK +113: OK OK OK OK +114: OK OK OK OK +115: OK OK OK OK +116: OK OK OK OK +117: OK OK OK OK +118: OK OK OK OK +119: OK OK OK OK +120: OK OK OK OK +121: OK OK OK OK +122: OK OK OK OK +123: OK OK OK OK +124: OK OK OK OK +125: OK OK OK OK +126: OK OK OK OK +127: OK OK OK OK +128: OK OK OK OK diff --git a/tests/intern.output3264 b/tests/intern.output3264 new file mode 100644 index 0000000..bcacdfb --- /dev/null +++ b/tests/intern.output3264 @@ -0,0 +1,113 @@ +16: OK OK OK OK +17: OK OK OK OK +18: OK OK OK OK +19: OK OK OK OK +20: OK OK OK OK +21: OK OK OK OK +22: OK OK OK OK +23: OK OK OK OK +24: OK OK OK OK +25: OK OK OK OK +26: OK OK OK OK +27: OK OK OK OK +28: OK OK OK OK +29: OK OK OK OK +30: Fail OK OK Fail +31: Fail Fail Fail Fail +32: Fail Fail Fail Fail +33: Fail Fail Fail Fail +34: Fail Fail Fail Fail +35: Fail Fail Fail Fail +36: Fail Fail Fail Fail +37: Fail Fail Fail Fail +38: Fail Fail Fail Fail +39: Fail Fail Fail Fail +40: Fail Fail Fail Fail +41: Fail Fail Fail Fail +42: Fail Fail Fail Fail +43: Fail Fail Fail Fail +44: Fail Fail Fail Fail +45: Fail Fail Fail Fail +46: Fail Fail Fail Fail +47: Fail Fail Fail Fail +48: Fail Fail Fail Fail +49: Fail Fail Fail Fail +50: Fail Fail Fail Fail +51: Fail Fail Fail Fail +52: Fail Fail Fail Fail +53: Fail Fail Fail Fail +54: Fail Fail Fail Fail +55: Fail Fail Fail Fail +56: Fail Fail Fail Fail +57: Fail Fail Fail Fail +58: Fail Fail Fail Fail +59: Fail Fail Fail Fail +60: Fail Fail Fail Fail +61: Fail Fail Fail Fail +62: OK Fail Fail OK +63: OK OK OK OK +64: OK OK OK OK +65: OK OK OK OK +66: OK OK OK OK +67: OK OK OK OK +68: OK OK OK OK +69: OK OK OK OK +70: OK OK OK OK +71: OK OK OK OK +72: OK OK OK OK +73: OK OK OK OK +74: OK OK OK OK +75: OK OK OK OK +76: OK OK OK OK +77: OK OK OK OK +78: OK OK OK OK +79: OK OK OK OK +80: OK OK OK OK +81: OK OK OK OK +82: OK OK OK OK +83: OK OK OK OK +84: OK OK OK OK +85: OK OK OK OK +86: OK OK OK OK +87: OK OK OK OK +88: OK OK OK OK +89: OK OK OK OK +90: OK OK OK OK +91: OK OK OK OK +92: OK OK OK OK +93: OK OK OK OK +94: OK OK OK OK +95: OK OK OK OK +96: OK OK OK OK +97: OK OK OK OK +98: OK OK OK OK +99: OK OK OK OK +100: OK OK OK OK +101: OK OK OK OK +102: OK OK OK OK +103: OK OK OK OK +104: OK OK OK OK +105: OK OK OK OK +106: OK OK OK OK +107: OK OK OK OK +108: OK OK OK OK +109: OK OK OK OK +110: OK OK OK OK +111: OK OK OK OK +112: OK OK OK OK +113: OK OK OK OK +114: OK OK OK OK +115: OK OK OK OK +116: OK OK OK OK +117: OK OK OK OK +118: OK OK OK OK +119: OK OK OK OK +120: OK OK OK OK +121: OK OK OK OK +122: OK OK OK OK +123: OK OK OK OK +124: OK OK OK OK +125: OK OK OK OK +126: OK OK OK OK +127: OK OK OK OK +128: OK OK OK OK diff --git a/tests/intern.output6432 b/tests/intern.output6432 new file mode 100644 index 0000000..bcacdfb --- /dev/null +++ b/tests/intern.output6432 @@ -0,0 +1,113 @@ +16: OK OK OK OK +17: OK OK OK OK +18: OK OK OK OK +19: OK OK OK OK +20: OK OK OK OK +21: OK OK OK OK +22: OK OK OK OK +23: OK OK OK OK +24: OK OK OK OK +25: OK OK OK OK +26: OK OK OK OK +27: OK OK OK OK +28: OK OK OK OK +29: OK OK OK OK +30: Fail OK OK Fail +31: Fail Fail Fail Fail +32: Fail Fail Fail Fail +33: Fail Fail Fail Fail +34: Fail Fail Fail Fail +35: Fail Fail Fail Fail +36: Fail Fail Fail Fail +37: Fail Fail Fail Fail +38: Fail Fail Fail Fail +39: Fail Fail Fail Fail +40: Fail Fail Fail Fail +41: Fail Fail Fail Fail +42: Fail Fail Fail Fail +43: Fail Fail Fail Fail +44: Fail Fail Fail Fail +45: Fail Fail Fail Fail +46: Fail Fail Fail Fail +47: Fail Fail Fail Fail +48: Fail Fail Fail Fail +49: Fail Fail Fail Fail +50: Fail Fail Fail Fail +51: Fail Fail Fail Fail +52: Fail Fail Fail Fail +53: Fail Fail Fail Fail +54: Fail Fail Fail Fail +55: Fail Fail Fail Fail +56: Fail Fail Fail Fail +57: Fail Fail Fail Fail +58: Fail Fail Fail Fail +59: Fail Fail Fail Fail +60: Fail Fail Fail Fail +61: Fail Fail Fail Fail +62: OK Fail Fail OK +63: OK OK OK OK +64: OK OK OK OK +65: OK OK OK OK +66: OK OK OK OK +67: OK OK OK OK +68: OK OK OK OK +69: OK OK OK OK +70: OK OK OK OK +71: OK OK OK OK +72: OK OK OK OK +73: OK OK OK OK +74: OK OK OK OK +75: OK OK OK OK +76: OK OK OK OK +77: OK OK OK OK +78: OK OK OK OK +79: OK OK OK OK +80: OK OK OK OK +81: OK OK OK OK +82: OK OK OK OK +83: OK OK OK OK +84: OK OK OK OK +85: OK OK OK OK +86: OK OK OK OK +87: OK OK OK OK +88: OK OK OK OK +89: OK OK OK OK +90: OK OK OK OK +91: OK OK OK OK +92: OK OK OK OK +93: OK OK OK OK +94: OK OK OK OK +95: OK OK OK OK +96: OK OK OK OK +97: OK OK OK OK +98: OK OK OK OK +99: OK OK OK OK +100: OK OK OK OK +101: OK OK OK OK +102: OK OK OK OK +103: OK OK OK OK +104: OK OK OK OK +105: OK OK OK OK +106: OK OK OK OK +107: OK OK OK OK +108: OK OK OK OK +109: OK OK OK OK +110: OK OK OK OK +111: OK OK OK OK +112: OK OK OK OK +113: OK OK OK OK +114: OK OK OK OK +115: OK OK OK OK +116: OK OK OK OK +117: OK OK OK OK +118: OK OK OK OK +119: OK OK OK OK +120: OK OK OK OK +121: OK OK OK OK +122: OK OK OK OK +123: OK OK OK OK +124: OK OK OK OK +125: OK OK OK OK +126: OK OK OK OK +127: OK OK OK OK +128: OK OK OK OK diff --git a/tests/intern.output6464 b/tests/intern.output6464 new file mode 100644 index 0000000..9029dd2 --- /dev/null +++ b/tests/intern.output6464 @@ -0,0 +1,113 @@ +16: OK OK OK OK +17: OK OK OK OK +18: OK OK OK OK +19: OK OK OK OK +20: OK OK OK OK +21: OK OK OK OK +22: OK OK OK OK +23: OK OK OK OK +24: OK OK OK OK +25: OK OK OK OK +26: OK OK OK OK +27: OK OK OK OK +28: OK OK OK OK +29: OK OK OK OK +30: OK OK OK OK +31: OK OK OK OK +32: OK OK OK OK +33: OK OK OK OK +34: OK OK OK OK +35: OK OK OK OK +36: OK OK OK OK +37: OK OK OK OK +38: OK OK OK OK +39: OK OK OK OK +40: OK OK OK OK +41: OK OK OK OK +42: OK OK OK OK +43: OK OK OK OK +44: OK OK OK OK +45: OK OK OK OK +46: OK OK OK OK +47: OK OK OK OK +48: OK OK OK OK +49: OK OK OK OK +50: OK OK OK OK +51: OK OK OK OK +52: OK OK OK OK +53: OK OK OK OK +54: OK OK OK OK +55: OK OK OK OK +56: OK OK OK OK +57: OK OK OK OK +58: OK OK OK OK +59: OK OK OK OK +60: OK OK OK OK +61: OK OK OK OK +62: OK OK OK OK +63: OK OK OK OK +64: OK OK OK OK +65: OK OK OK OK +66: OK OK OK OK +67: OK OK OK OK +68: OK OK OK OK +69: OK OK OK OK +70: OK OK OK OK +71: OK OK OK OK +72: OK OK OK OK +73: OK OK OK OK +74: OK OK OK OK +75: OK OK OK OK +76: OK OK OK OK +77: OK OK OK OK +78: OK OK OK OK +79: OK OK OK OK +80: OK OK OK OK +81: OK OK OK OK +82: OK OK OK OK +83: OK OK OK OK +84: OK OK OK OK +85: OK OK OK OK +86: OK OK OK OK +87: OK OK OK OK +88: OK OK OK OK +89: OK OK OK OK +90: OK OK OK OK +91: OK OK OK OK +92: OK OK OK OK +93: OK OK OK OK +94: OK OK OK OK +95: OK OK OK OK +96: OK OK OK OK +97: OK OK OK OK +98: OK OK OK OK +99: OK OK OK OK +100: OK OK OK OK +101: OK OK OK OK +102: OK OK OK OK +103: OK OK OK OK +104: OK OK OK OK +105: OK OK OK OK +106: OK OK OK OK +107: OK OK OK OK +108: OK OK OK OK +109: OK OK OK OK +110: OK OK OK OK +111: OK OK OK OK +112: OK OK OK OK +113: OK OK OK OK +114: OK OK OK OK +115: OK OK OK OK +116: OK OK OK OK +117: OK OK OK OK +118: OK OK OK OK +119: OK OK OK OK +120: OK OK OK OK +121: OK OK OK OK +122: OK OK OK OK +123: OK OK OK OK +124: OK OK OK OK +125: OK OK OK OK +126: OK OK OK OK +127: OK OK OK OK +128: OK OK OK OK From 5f8e5e2ded3eaea063ac1a48029a9572069e1af8 Mon Sep 17 00:00:00 2001 From: Xavier Leroy Date: Wed, 3 Jan 2024 17:31:03 +0100 Subject: [PATCH 46/49] CI: use OCaml 5.1.x instead of 5.0 Except on Windows, as I'm unsure why there was a Windows exception in the first place. --- .github/workflows/build.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index ce6e2e6..ccfa6c6 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -22,9 +22,9 @@ jobs: - 4.14.x include: - os: ubuntu-latest - ocaml-compiler: 5.0.x + ocaml-compiler: 5.1.x - os: macos-latest - ocaml-compiler: 5.0.x + ocaml-compiler: 5.1.x - os: windows-latest ocaml-compiler: ocaml.5.0.0,ocaml-option-mingw From f71e8594aa796bcc3d2fc44bed89a398892ac4bc Mon Sep 17 00:00:00 2001 From: hhugo Date: Sun, 7 Jul 2024 19:15:30 +0200 Subject: [PATCH 47/49] Switch to opam 2.2 for CI (#153) * Switch to opam 2.2 * Apply suggestions from code review Co-authored-by: Hugo Heuzard Co-authored-by: Sora Morimoto --- .github/workflows/build.yml | 36 +++++++----------------------------- 1 file changed, 7 insertions(+), 29 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index ccfa6c6..425a3b9 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -19,45 +19,24 @@ jobs: - windows-latest - macos-latest ocaml-compiler: - - 4.14.x - include: - - os: ubuntu-latest - ocaml-compiler: 5.1.x - - os: macos-latest - ocaml-compiler: 5.1.x - - os: windows-latest - ocaml-compiler: ocaml.5.0.0,ocaml-option-mingw + - "4.14" + - "5.2" runs-on: ${{ matrix.os }} steps: - name: Checkout code - uses: actions/checkout@v3 + uses: actions/checkout@v4 - - name: Use OCaml ${{ matrix.ocaml-compiler }} - uses: ocaml/setup-ocaml@v2 - if: runner.os != 'Windows' + - name: Set-up OCaml ${{ matrix.ocaml-compiler }} + uses: ocaml/setup-ocaml@v3 with: ocaml-compiler: ${{ matrix.ocaml-compiler }} - dune-cache: true - opam-depext: true - opam-depext-flags: --with-test - - name: Use OCaml ${{ matrix.ocaml-compiler }} - uses: ocaml/setup-ocaml@v2 - if: runner.os == 'Windows' - with: - ocaml-compiler: ${{ matrix.ocaml-compiler }} - opam-repositories: | - dra27: https://github.com/dra27/opam-repository.git#windows-5.0 - default: https://github.com/ocaml-opam/opam-repository-mingw.git#sunset - opam: https://github.com/ocaml/opam-repository.git - dune-cache: true - opam-depext: true - opam-depext-flags: --with-test + - run: opam install . --with-test --deps-only - name: configure tree - run: opam exec -- ./configure + run: opam exec -- sh ./configure - name: Build run: opam exec -- make @@ -68,4 +47,3 @@ jobs: - run: opam install . --with-test - run: opam exec -- git diff --exit-code - if: ${{ !matrix.skip-test }} From 667d742948914aa1f80d5ad5abb98bc412335e51 Mon Sep 17 00:00:00 2001 From: Xavier Leroy Date: Wed, 10 Jul 2024 09:33:30 +0200 Subject: [PATCH 48/49] Updates for release 1.14 --- Changes | 5 +++++ META | 2 +- zarith.opam | 1 + 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/Changes b/Changes index f4d2082..3d7e413 100644 --- a/Changes +++ b/Changes @@ -1,3 +1,8 @@ +Release 1.14 (2024-07-10) +- #148, #149: Fail unmarshaling when it would produce non-canonical big ints +- #145, #150: Use standard hash function for `Z.hash` and add `Z.seeded_hash` +- #140, #147: Add fast path for `Z.divisible` on small arguments + Release 1.13 (2023-07-19) - #113: add conversions to/from small unsigned integers `(to|fits)_(int32|int64|nativeint)_unsigned` [Antoine Miné] - #128: add functions to pseudo-randomly generate integers [Xavier Leroy] diff --git a/META b/META index a409856..72bd4ca 100644 --- a/META +++ b/META @@ -1,6 +1,6 @@ description = "Arbitrary precision integers" requires = "" -version = "1.13" +version = "1.14" archive(byte) = "zarith.cma" archive(native) = "zarith.cmxa" plugin(byte) = "zarith.cma" diff --git a/zarith.opam b/zarith.opam index 2c406c9..34a5eab 100644 --- a/zarith.opam +++ b/zarith.opam @@ -1,5 +1,6 @@ opam-version: "2.0" name: "zarith" +version: "1.14" maintainer: "Xavier Leroy " authors: [ "Antoine Miné" From a079848a25b2d4759a2413e6aa5b468d977135c0 Mon Sep 17 00:00:00 2001 From: Xavier Leroy Date: Mon, 15 Jul 2024 14:53:42 +0200 Subject: [PATCH 49/49] Update local OPAM file to reflect the one in the OPAM repository Especially the use of pkg-config for configuration. --- zarith.opam | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/zarith.opam b/zarith.opam index 34a5eab..995af2f 100644 --- a/zarith.opam +++ b/zarith.opam @@ -12,25 +12,16 @@ bug-reports: "https://github.com/ocaml/Zarith/issues" dev-repo: "git+https://github.com/ocaml/Zarith.git" license: "LGPL-2.0-only WITH OCaml-LGPL-linking-exception" build: [ - ["./configure"] {os != "openbsd" & os != "freebsd" & os != "macos"} - [ - "sh" - "-exc" - "LDFLAGS=\"$LDFLAGS -L/usr/local/lib\" CFLAGS=\"$CFLAGS -I/usr/local/include\" ./configure" - ] {os = "openbsd" | os = "freebsd"} - [ - "sh" - "-exc" - "LDFLAGS=\"$LDFLAGS -L/opt/local/lib -L/usr/local/lib\" CFLAGS=\"$CFLAGS -I/opt/local/include -I/usr/local/include\" ./configure" - ] {os = "macos"} + ["./configure"] [make] ] install: [ [make "install"] ] depends: [ - "ocaml" {>= "4.04.0"} + "ocaml" {>= "4.07.0"} "ocamlfind" + "conf-pkg-config" "conf-gmp" ] synopsis: