Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Steps towards MSVC support #157

Merged
merged 5 commits into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
*.a
*.lib
*.cm?
*.cmxa
*.cmxs
*.cmti
*.exe
*.byt
*.o
*.obj
*.so
Makefile
*.dll
Makefile.config
depend
zarith_version.ml
20 changes: 2 additions & 18 deletions project.mak → Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,7 @@
# ENS (École normale supérieure, Paris, France),
# INRIA Rocquencourt (Institut national de recherche en informatique, France).

ifeq "$(shell $(OCAMLC) -config |grep ccomp_type)" "ccomp_type: msvc"
OBJSUFFIX := obj
LIBSUFFIX := lib
DLLSUFFIX := dll
EXE := .exe
else
OBJSUFFIX := o
LIBSUFFIX := a
ifeq "$(findstring mingw,$(shell $(OCAMLC) -config |grep system))" "mingw"
DLLSUFFIX := dll
EXE := .exe
else
DLLSUFFIX := so
EXE :=
endif
endif

include Makefile.config

# project files
###############
Expand Down Expand Up @@ -145,7 +129,7 @@ endif
$(OCAMLC) -ccopt "$(CFLAGS)" -c $<

clean:
/bin/rm -rf *.$(OBJSUFFIX) *.$(LIBSUFFIX) *.$(DLLSUFFIX) *.cmi *.cmo *.cmx *.cmxa *.cmxs *.cma *.cmt *.cmti *~ \#* depend test $(AUTOGEN) tmp.c depend
/bin/rm -rf *.o *.obj *.lib *.a *.cmi *.cmo *.cmx *.cmxa *.cmxs *.cma *.cmt *.cmti *~ \#* depend test $(AUTOGEN) tmp.c depend
make -C tests clean

depend: $(AUTOGEN)
Expand Down
42 changes: 34 additions & 8 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ ccdef=''
mlflags="$OCAMLFLAGS"
mloptflags="$OCAMLOPTFLAGS"
mlinc="$OCAMLINC"
objsuffix="o"
ocamlfind="auto"

# sanitize
Expand Down Expand Up @@ -209,6 +208,30 @@ else
ccopt="-O3 -Wall -Wextra $CFLAGS"
fi

case "$("$ocamlc" -config | tr -d '\r' | sed -ne '/^system:/s/.*: //p')" in
win32|win64)
# MSVC
objsuffix='obj'
libsuffix='lib'
dllsuffix='dll'
exe='.exe'
;;
mingw|mingw64)
# mingw-w64
objsuffix='o'
libsuffix='a'
dllsuffix='dll'
exe='.exe'
;;
*)
# Unix
objsuffix='o'
libsuffix='a'
dllsuffix='so'
exe=''
;;
esac

# optional native-code generation

hasocamlopt='no'
Expand All @@ -231,7 +254,7 @@ fi
# directories

if test "$ocamllibdir" = "auto"
then ocamllibdir=`ocamlc -where | sed 's/\r$//'`
then ocamllibdir="$(ocamlc -where | tr -d '\r')"
fi

if test ! -f "$ocamllibdir/caml/mlvalues.h"
Expand All @@ -258,7 +281,7 @@ searchbin ocamlfind
if test $? -eq 1 && test $ocamlfind != "no"; then
instmeth='findlib'
if test "$installdir" = "auto"
then installdir=`ocamlfind printconf destdir`; fi
then installdir="$(ocamlfind printconf destdir | tr -d '\r')"; fi
else
searchbin install
if test $? -eq 1; then instmeth='install'
Expand All @@ -270,7 +293,7 @@ fi
# detect OCaml's word-size

echo "print_int (Sys.word_size);;" > tmp.ml
wordsize=`ocaml tmp.ml`
wordsize="$(ocaml tmp.ml)"
echo "OCaml's word size is $wordsize"
rm -f tmp.ml

Expand Down Expand Up @@ -312,7 +335,7 @@ if test "$gmp" != 'OK'; then echo "cannot find GMP nor MPIR"; exit 2; fi

# OCaml version

ocamlver=`ocamlc -version`
ocamlver="$(ocamlc -version)"

# OCaml version 4.04 or later is required

Expand Down Expand Up @@ -340,7 +363,7 @@ esac

# dump Makefile

cat > Makefile <<EOF
cat > Makefile.config <<EOF
# generated by ./configure

OCAMLC=$ocamlc
Expand All @@ -359,11 +382,14 @@ INSTALL=install
OCAMLFIND=ocamlfind
INSTMETH=$instmeth
OBJSUFFIX=$objsuffix
LIBSUFFIX=$libsuffix
DLLSUFFIX=$dllsuffix
EXESUFFIX=$exe
HASOCAMLOPT=$hasocamlopt
HASDYNLINK=$hasdynlink
HASBINANNOT=$hasbinannot

include project.mak
WORDSIZE=$wordsize
STDLIBDIR=$ocamllibdir
EOF


Expand Down
12 changes: 6 additions & 6 deletions tests/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
WORDSIZE:=$(shell echo 'print_int Sys.word_size' | ocaml -stdin)
STDLIBDIR:=$(shell ocamlc -where)
ifeq ($(wildcard $(STDLIBDIR)/big_int.cmi),)
HAS_NUM=false
NUMS_CMA=
Expand All @@ -10,6 +8,8 @@ NUMS_CMA=nums.cma
NUMS_CMXA=nums.cmxa
endif

include ../Makefile.config

test:: zq.exe
@echo "Testing zq (native)..."
@if ./zq.exe | cmp -s zq.output$(WORDSIZE) - ; then echo "zq: passed"; else echo "zq: FAILED"; exit 2; fi
Expand Down Expand Up @@ -58,16 +58,16 @@ test:: intern.exe
extern.data$(WORDSIZE): extern.exe
./extern.exe extern.data$(WORDSIZE)

tofloat.exe: tofloat.ml setround.o ../zarith.cmxa
tofloat.exe: tofloat.ml setround.$(OBJSUFFIX) ../zarith.cmxa
ocamlopt -I .. -ccopt "-L.." zarith.cmxa -o tofloat.exe \
setround.o tofloat.ml
setround.$(OBJSUFFIX) tofloat.ml

%.exe: %.ml ../zarith.cmxa
ocamlopt -I .. -ccopt "-L.." zarith.cmxa $(NUMS_CMXA) -o $*.exe $*.ml
%.byt: %.ml ../zarith.cma
ocamlc -I .. -ccopt "-L.." zarith.cma $(NUMS_CMA) -o $*.byt $*.ml
%.o: %.c
%.$(OBJSUFFIX): %.c
ocamlc -c $*.c

clean:
rm -f *.cm[iox] *.o *.exe *.byt
rm -f *.cm[iox] *.o *.obj *.exe *.byt
Loading