ocaml / Zarith

The Zarith library implements arithmetic and logical operations over arbitrary-precision integers and rational numbers. The implementation, based on GMP, is very efficient.
Other
231 stars 70 forks source link

Building with ocamlc: make: posix_spawn: ocamlopt: No such file or directory #125

Closed barracuda156 closed 2 years ago

barracuda156 commented 2 years ago

I try to build ocaml-zarith with ocamlc bytecode compiler. I cannot find an explicit build target for that, and relying on configure fails, it still tries to invoke ocamlopt, which is absent.

ocamlmklib -failsafe -o zarith zarith_version.cmo z.cmo q.cmo big_int_Z.cmo -L/opt/local/lib -Wl,-headerpad_max_install_names -lgmp
Unknown option -Wl,-headerpad_max_install_names
ocamlc -ccopt "-I/opt/local/lib/ocaml -I/opt/local/include -DHAS_GMP  -pipe -Os" -c caml_z.c
ocamlmklib -failsafe -o zarith caml_z.o -L/opt/local/lib -Wl,-headerpad_max_install_names -lgmp
Unknown option -Wl,-headerpad_max_install_names
ocamlc -I +compiler-libs -bin-annot  -c zarith_top.ml
ocamlc -o zarith_top.cma -a zarith_top.cmo
ocamlopt -I +compiler-libs  -c zarith_version.ml
make: posix_spawn: ocamlopt: No such file or directory

macOS 10.6 PPC (that is why no native compiler, PPC assembler is broken) ocaml 4.14.0

xavierleroy commented 2 years ago

Can you please post the contents of the Makefile that is generated by configure ?

barracuda156 commented 2 years ago

Can you please post the contents of the Makefile that is generated by configure ?

@xavierleroy Thank you very much for responding. I will post it tomorrow, once I am back to that machine.

barracuda156 commented 2 years ago

@xavierleroy Yes, Makefile has ocamlopt, which is not in fact available on the system.

# generated by ./configure

CC=/opt/local/bin/gcc-mp-11
OCAMLC=ocamlc
OCAMLOPT=ocamlopt
OCAMLDEP=ocamldep
OCAMLMKLIB=ocamlmklib
OCAMLDOC=ocamldoc
OCAMLFLAGS=
OCAMLOPTFLAGS=
OCAMLINC=
CFLAGS=-I/opt/local/lib/ocaml -I/opt/local/include -DHAS_GMP  -pipe -Os
LIBS=-L/opt/local/lib -Wl,-headerpad_max_install_names -lgmp
INSTALLDIR=/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_macports_release_tarballs_ports_ocaml_ocaml-zarith/ocaml-zarith/work/destroot/opt/local/lib/ocaml/site-lib
INSTALL=install
OCAMLFIND=ocamlfind
INSTMETH=findlib
OBJSUFFIX=o
HASOCAMLOPT=yes
HASDYNLINK=no
HASBINANNOT=yes

include project.mak
barracuda156 commented 2 years ago

Here is what actually installed:

/opt/local/bin/ocaml
/opt/local/bin/ocamlbuild
/opt/local/bin/ocamlbuild.byte
/opt/local/bin/ocamlc
/opt/local/bin/ocamlc.byte
/opt/local/bin/ocamlcmt
/opt/local/bin/ocamlcp
/opt/local/bin/ocamlcp.byte
/opt/local/bin/ocamldebug
/opt/local/bin/ocamldep
/opt/local/bin/ocamldep.byte
/opt/local/bin/ocamldoc
/opt/local/bin/ocamlfind
/opt/local/bin/ocamllex
/opt/local/bin/ocamllex.byte
/opt/local/bin/ocamlmklib
/opt/local/bin/ocamlmklib.byte
/opt/local/bin/ocamlmktop
/opt/local/bin/ocamlmktop.byte
/opt/local/bin/ocamlobjinfo
/opt/local/bin/ocamlobjinfo.byte
/opt/local/bin/ocamloptp
/opt/local/bin/ocamloptp.byte
/opt/local/bin/ocamlprof
/opt/local/bin/ocamlprof.byte
/opt/local/bin/ocamlrun
/opt/local/bin/ocamlrund
/opt/local/bin/ocamlruni
/opt/local/bin/ocamlyacc
36-111% port -v installed | grep ocaml
  ocaml @4.14.0_0 requested_variants='' platform='darwin 10' archs='ppc' date='2022-05-07T17:29:35+0800'
  ocaml @4.14.0_1 (active) requested_variants='' platform='darwin 10' archs='ppc' date='2022-05-22T09:34:20+0800'
  ocaml-camlp4 @4.14-1_0 (active) requested_variants='' platform='darwin 10' archs='ppc' date='2022-05-22T08:29:08+0800'
  ocaml-csexp @1.5.1_1 (active) requested_variants='' platform='darwin 10' archs='ppc' date='2022-05-22T12:31:27+0800'
  ocaml-dune @3.2.0_0 (active) requested_variants='' platform='darwin 10' archs='ppc' date='2022-05-22T09:25:00+0800'
  ocaml-findlib @1.9.3_0 (active) requested_variants='' platform='darwin 10' archs='ppc' date='2022-05-22T07:08:38+0800'
  ocaml-ocamlbuild @0.14.1_0 (active) requested_variants='' platform='darwin 10' archs='ppc' date='2022-05-22T07:56:52+0800'
xavierleroy commented 2 years ago

Well, I tried on a Linux x86-64 machine with a custom bytecode-only installation of OCaml. Zarith's configure correctly produces

HASOCAMLOPT=no
HASDYNLINK=no
HASBINANNOT=yes

and running make compiles Zarith to bytecode only, as expected.

If I run sh -x ./configure I can see ocamlopt being searched for and not found:

...
+ echo binary ocamlopt: 
+ tr -d \012
binary ocamlopt: + IFS=:
+ test -z /usr/local/ocaml-experimental/bin
+ test -f /usr/local/ocaml-experimental/bin/ocamlopt
+ test -z /usr/local/bin
+ test -f /usr/local/bin/ocamlopt
+ test -z /usr/bin
+ test -f /usr/bin/ocamlopt
+ test -z /bin
+ test -f /bin/ocamlopt
+ test -z /usr/sbin
+ test -f /usr/sbin/ocamlopt
+ test -z /sbin
+ test -f /sbin/ocamlopt
+ echo not found
not found
...

Could you please run sh -x ./configure and see what happens around the "binary ocamlopt" lines?

barracuda156 commented 2 years ago

@xavierleroy Thank you for advice. I ran the code from the build directory, and here is the output:

36-111% cd /opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_macports_release_tarballs_ports_ocaml_ocaml-zarith/ocaml-zarith/work/ocaml-Zarith-39df015 
36-111% sh -x ./configure
+ installdir=auto
+ ocamllibdir=auto
+ host=auto
+ gmp=auto
+ perf=no
+ ocaml=ocaml
+ ocamlc=ocamlc
+ ocamlopt=ocamlopt
+ ocamlmklib=ocamlmklib
+ ocamldep=ocamldep
+ ocamldoc=ocamldoc
+ ccinc=
+ cclib=
+ ccdef=
+ mlflags=
+ mloptflags=
+ mlinc=
+ objsuffix=o
+ ocamlfind=auto
+ LC_ALL=C
+ export LC_ALL
+ unset IFS
+ :
+ case "$1" in
+ break
+ test no = yes
+ searchbinreq ocaml
+ searchbin ocaml
+ return 1
+ test 1 -eq 0
+ searchbinreq ocamlc
+ searchbin ocamlc
+ return 1
+ test 1 -eq 0
+ searchbinreq ocamldep
+ searchbin ocamldep
+ return 1
+ test 1 -eq 0
+ searchbinreq ocamlmklib
+ searchbin ocamlmklib
+ return 1
+ test 1 -eq 0
+ searchbinreq ocamldoc
+ searchbin ocamldoc
+ return 1
+ test 1 -eq 0
+ test -n ''
+ searchbin gcc
+ return 1
+ cc=gcc
+ ccopt='-O3 -Wall -Wextra '
+ hasocamlopt=no
+ searchbin ocamlopt
+ return 1
+ test 1 -eq 1
+ hasocamlopt=yes
+ checkcc
+ echo_n 'checking compilation with gcc -O3 -Wall -Wextra : '
+ echo 'checking compilation with gcc -O3 -Wall -Wextra : '
+ tr -d '\012'
checking compilation with gcc -O3 -Wall -Wextra : + rm -f tmp.c tmp.out
+ echo 'int main() { return 1; }'
+ r=1
+ gcc -O3 -Wall -Wextra tmp.c -o tmp.out
+ test '!' -x tmp.out
+ rm -f tmp.c tmp.o tmp.out
+ test 1 -eq 0
+ echo working
working
+ return 1
+ test 1 -eq 0
+ test auto = auto
++ ocamlc -where
++ sed 's/\r$//'
+ ocamllibdir=/opt/local/lib/ocaml
+ test '!' -f /opt/local/lib/ocaml/caml/mlvalues.h
+ ccinc='-I/opt/local/lib/ocaml '
+ checkinc caml/mlvalues.h
+ echo_n 'include caml/mlvalues.h: '
+ echo 'include caml/mlvalues.h: '
+ tr -d '\012'
include caml/mlvalues.h: + rm -f tmp.c tmp.o
+ echo '#include <caml/mlvalues.h>'
+ echo 'int main() { return 1; }'
+ r=1
+ gcc -O3 -Wall -Wextra -I/opt/local/lib/ocaml -c tmp.c -o tmp.o
+ test '!' -f tmp.o
+ rm -f tmp.c tmp.o
+ test 1 -eq 0
+ echo found
found
+ return 1
+ test 1 -eq 0
+ hasdynlink=no
+ test yes = yes
+ checkcmxalib dynlink.cmxa
+ echo_n 'library dynlink.cmxa: '
+ echo 'library dynlink.cmxa: '
+ tr -d '\012'
library dynlink.cmxa: + ocamlopt dynlink.cmxa -o tmp.out
+ r=0
+ test '!' -x tmp.out
+ r=0
+ rm -f tmp.out
+ test 0 -eq 0
+ echo 'not found'
not found
+ return 0
+ test 0 -eq 1
+ searchbin ocamlfind
+ return 1
+ test 1 -eq 1 -a auto '!=' no
+ instmeth=findlib
+ test auto = auto
++ ocamlfind printconf destdir
+ installdir=/opt/local/lib/ocaml/site-lib
+ echo 'print_int (Sys.word_size);;'
++ ocaml tmp.ml
+ wordsize=32
+ echo 'OCaml'\''s word size is 32'
OCaml's word size is 32
+ rm -f tmp.ml
+ test xauto = xauto
+ searchbin uname
+ return 1
+ test 1 -eq 0
++ . ./config.guess
+++ timestamp=2010-09-24
++++ echo ./configure
++++ sed -e 's,.*/,,'
+++ me=configure
+++ usage='Usage: ./configure [OPTION]

Output the configuration name of the system `configure'\'' is run on.

Operation modes:
  -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 <config-patches@gnu.org>.'
+++ version='GNU config.guess (2010-09-24)

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.

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 `configure --help'\'' for more information.'
+++ test 0 -gt 0
+++ test 0 '!=' 0
+++ trap 'exit 1' HUP INT TERM
+++ 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= ;'
+++ UNAME_MACHINE='Power Macintosh'
+++ UNAME_RELEASE=10.0.0d2
+++ UNAME_SYSTEM=Darwin
+++ UNAME_VERSION='Darwin Kernel Version 10.0.0d2: Fri Oct 10 19:37:52 PDT 2008; root:xnu-1346.7~1/RELEASE_PPC'
+++ case "${UNAME_SYSTEM}" in
+++ case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in
++++ uname -p
+++ UNAME_PROCESSOR=powerpc
+++ case $UNAME_PROCESSOR in
+++ echo powerpc-apple-darwin10.0.0d2
+++ exit
+ host=powerpc-apple-darwin10.0.0d2
+ test auto = gmp -o auto = auto
+ checkinc gmp.h
+ echo_n 'include gmp.h: '
+ echo 'include gmp.h: '
+ tr -d '\012'
include gmp.h: + rm -f tmp.c tmp.o
+ echo '#include <gmp.h>'
+ echo 'int main() { return 1; }'
+ r=1
+ gcc -O3 -Wall -Wextra -I/opt/local/lib/ocaml -c tmp.c -o tmp.o
+ r=0
+ test '!' -f tmp.o
+ r=0
+ rm -f tmp.c tmp.o
+ test 0 -eq 0
+ echo 'not found'
not found
+ return 0
+ test 0 -eq 1
+ test auto = mpir -o auto = auto
+ checkinc mpir.h
+ echo_n 'include mpir.h: '
+ echo 'include mpir.h: '
+ tr -d '\012'
include mpir.h: + rm -f tmp.c tmp.o
+ echo '#include <mpir.h>'
+ echo 'int main() { return 1; }'
+ r=1
+ gcc -O3 -Wall -Wextra -I/opt/local/lib/ocaml -c tmp.c -o tmp.o
+ r=0
+ test '!' -f tmp.o
+ r=0
+ rm -f tmp.c tmp.o
+ test 0 -eq 0
+ echo 'not found'
not found
+ return 0
+ test 0 -eq 1
+ test auto '!=' OK
+ echo 'cannot find GMP nor MPIR'
cannot find GMP nor MPIR
+ exit 2

That is, it does report the following re ocamlopt:

+ hasocamlopt=no
+ searchbin ocamlopt
+ return 1
+ test 1 -eq 1
+ hasocamlopt=yes
antoinemine commented 2 years ago

This is strange. It looks like searchbin x does not actually call the searchbin() function defined in the script. It should at least execute test, echo, etc. Here, it returns directly with 1....

Is it an error in the script? A different version of sh? Some program called searchbin that get precedence?

barracuda156 commented 2 years ago

@antoinemine I am unsure what’s going wrong, but I tried now on a different machine – Intel Mac with 10.6.8, which allows me to build for ppc, and got the same failure:

ocamlopt -I +compiler-libs  -c zarith_version.ml
make: ocamlopt: No such file or directory
make: *** [zarith_version.cmx] Error 1
make: Leaving directory `/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_macports_release_tarballs_ports_ocaml_ocaml-zarith/ocaml-zarith/work/ocaml-Zarith-39df015'
xavierleroy commented 2 years ago

Do you have a program named "searchbin" in the PATH on your machines?

xavierleroy commented 2 years ago

Also, bash -x configure could give a more informative trace.

barracuda156 commented 2 years ago

@xavierleroy Thank you for your help! There is no such program, but I have found a source of the error due to your suggestion: Macports for unknown reason had a patch applied to configure:

--- configure.orig
+++ configure
@@ -112,6 +112,7 @@

 searchbin()
 {
+return 1;
     if test "x$1" = "x"; then return 0; fi
     echo_n "binary $1: "
     case "$1" in

It builds and installs fine without said patch:

macmini:~ svacchanda$ port -v installed ocaml-zarith
The following ports are currently installed:
  ocaml-zarith @1.12_0 (active) requested_variants='' platform='darwin 10' archs='ppc' date='2022-05-26T08:02:49+0800'
barracuda156 commented 2 years ago

@xavierleroy @antoinemine Thank you again!