Skip to content

Commit

Permalink
Detect Microsoft C Compiler from installation
Browse files Browse the repository at this point in the history
Allow configure to detect cl from a Windows SDK or Visual Studio
installation, even if cl.exe isn't in the PATH.

Simplifies the launching of bash for multiple compiler architectures as
PATH doesn't require manual editing.
  • Loading branch information
dra27 committed Jan 11, 2018
1 parent 556c88e commit c85ca73
Show file tree
Hide file tree
Showing 5 changed files with 1,209 additions and 6 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*.zsh text eol=lf
configure text eol=lf
configure.ac text eol=lf
msvs-detect text eol=lf
check_linker text eol=lf
*.m4 text eol=lf

Expand Down
4 changes: 3 additions & 1 deletion Makefile.config.in
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@ EXE = @EXE@
WIN32 = @WIN32@

PATH:=@PATH_PREPEND@$(PATH)
INCLUDE:=@INC_PREPEND@$(INCLUDE)
LIB:=@LIB_PREPEND@$(LIB)

LIB_PREFIX = @LIB_PREFIX@
CPATH = @CPATH@
LIBRARY_PATH = @LIBRARY_PATH@

export OCAMLVERSION OCAMLFIND OCAML OCAMLC OCAMLOPT EXE PATH CPATH LIBRARY_PATH
export OCAMLVERSION OCAMLFIND OCAML OCAMLC OCAMLOPT EXE PATH INCLUDE LIB CPATH LIBRARY_PATH
80 changes: 77 additions & 3 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,8 @@ JBUILDER
FETCH
OCAMLFIND
OCAMLOBJINFO
INC_PREPEND
LIB_PREPEND
PATH_PREPEND
EXE
WIN32
Expand Down Expand Up @@ -3169,19 +3171,85 @@ x$ax_compare_version_B" | sed 's/^ *//' | sort -r | sed "s/x${ax_compare_version
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for compiler type" >&5
$as_echo_n "checking for compiler type... " >&6; }
CCOMP_TYPE=`$OCAML shell/print_config.ml ccomp_type 2>/dev/null | fgrep -v "Cannot find" || $OCAMLC -config | tr -d '\r' | sed -n -e "s/ccomp_type: //p"`
if test "$?" -eq 0 ; then :
else
as_fn_error $? "failed" "$LINENO" 5
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $CCOMP_TYPE" >&5
$as_echo "$CCOMP_TYPE" >&6; }
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for compiler architecture" >&5
$as_echo_n "checking for compiler architecture... " >&6; }
ARCH=`$OCAML shell/print_config.ml arch 2>/dev/null | fgrep -v "Cannot find" || $OCAMLC -config | tr -d '\r' | sed -n -e "s/architecture: //p"`
if test "$?" -eq 0 ; then :
else
as_fn_error $? "failed" "$LINENO" 5
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ARCH" >&5
$as_echo "$ARCH" >&6; }
LIB_PREPEND=
INC_PREPEND=
# Need the C compiler used for OCaml (important on Windows, as both x86 and x64 are used)
if test "$OCAMLBEST" = "opt"; then :
OCAMLBESTCC=$OCAMLOPT
else
OCAMLBESTCC=$OCAMLC
fi
OCAML_CC="$($OCAMLBESTCC -config | sed -n -e "s/native_c_compiler: \(.*\) .*/\1/p")"
set dummy ${OCAML_CC}; OCAML_TEST_CC=$2
if test ! -x ${OCAML_TEST_CC}; then :
if test "x${CCOMP_TYPE}" = "xmsvc"; then :
if test "${ARCH}" = "i386"; then :
SDK_ARCH=x86
else
SDK_ARCH=x64
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for an installed Microsoft C Compiler for ${SDK_ARCH}" >&5
$as_echo_n "checking for an installed Microsoft C Compiler for ${SDK_ARCH}... " >&6; }
eval `./shell/msvs-detect --arch=$SDK_ARCH; echo RESULT=$?`
if test "x$MSVS_NAME" = "x" ; then :
if test ${RESULT} -eq 0 ; then :
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: from PATH" >&5
$as_echo "from PATH" >&6; }
else
as_fn_error $? "no" "$LINENO" 5
fi
else
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: from $MSVS_NAME" >&5
$as_echo "from $MSVS_NAME" >&6; }
export PATH_PREPEND="${MSVS_PATH}:${PATH_PREPEND}"
export PATH="${PATH_PREPEND}$PATH"
LIB_PREPEND="${MSVS_LIB};"
INC_PREPEND="${MSVS_INC};"
export Lib="${MSVS_LIB};$LIB"
export Include="${MSVS_INC};$INCLUDE"
fi
fi
fi
ac_ext=c
ac_cpp='$CPP $CPPFLAGS'
ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
ac_compiler_gnu=$ac_cv_c_compiler_gnu
if test -n "$ac_tool_prefix"; then
for ac_prog in $($OCAMLBESTCC -config | sed -n -e "s/native_c_compiler: \(.*\) .*/\1/p") gcc cl cc
for ac_prog in "${OCAML_CC}" gcc cc
do
# Extract the first word of "$ac_tool_prefix$ac_prog", so it can be a program name with args.
set dummy $ac_tool_prefix$ac_prog; ac_word=$2
Expand Down Expand Up @@ -3225,7 +3293,7 @@ fi
fi
if test -z "$CC"; then
ac_ct_CC=$CC
for ac_prog in $($OCAMLBESTCC -config | sed -n -e "s/native_c_compiler: \(.*\) .*/\1/p") gcc cl cc
for ac_prog in "${OCAML_CC}" gcc cc
do
# Extract the first word of "$ac_prog", so it can be a program name with args.
set dummy $ac_prog; ac_word=$2
Expand Down Expand Up @@ -3819,12 +3887,18 @@ if test ${WIN32} -eq 1 -a "$GCC" != "yes" ; then :
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether Microsoft Linker needs a PATH shim" >&5
$as_echo_n "checking whether Microsoft Linker needs a PATH shim... " >&6; }
PREV_PREPEND="$PATH_PREPEND"
PATH_PREPEND=$(bash ./shell/check_linker)
if test "x${PATH_PREPEND}" = "x" ; then :
if test "x${PATH_PREPEND}" = "x${PREV_PREPEND}" ; then :
PATH_PREPEND_RESULT=no
else
PATH_PREPEND_RESULT=yes
fi
PATH_PREPEND=`echo "${PATH_PREPEND}" | sed -e 's/#/\\\\#/g' -e 's/\\$/$$/g'`
LIB_PREPEND=`echo ${LIB_PREPEND} | sed -e 's/#/\\\\#/g' -e 's/\\$/$$/g'`
INC_PREPEND=`echo ${INC_PREPEND} | sed -e 's/#/\\\\#/g' -e 's/\\$/$$/g'`
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $PATH_PREPEND_RESULT" >&5
$as_echo "$PATH_PREPEND_RESULT" >&6; }
Expand Down
45 changes: 43 additions & 2 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,44 @@ AS_IF([test "x${enable_version_check}" != "xno"], [
AC_MSG_ERROR([Your version of OCaml: $OCAMLVERSION is not supported]))
])

AC_MSG_CHECKING([for compiler type])
CCOMP_TYPE=`$OCAML shell/print_config.ml ccomp_type 2>/dev/null | fgrep -v "Cannot find" || $OCAMLC -config | tr -d '\r' | sed -n -e "s/ccomp_type: //p"`
AS_IF([ test "$?" -eq 0 ],,[AC_MSG_ERROR([failed])] )
AC_MSG_RESULT([$CCOMP_TYPE])
AC_MSG_CHECKING([for compiler architecture])
ARCH=`$OCAML shell/print_config.ml arch 2>/dev/null | fgrep -v "Cannot find" || $OCAMLC -config | tr -d '\r' | sed -n -e "s/architecture: //p"`
AS_IF([ test "$?" -eq 0 ],,[AC_MSG_ERROR([failed])] )
AC_MSG_RESULT([$ARCH])

LIB_PREPEND=
INC_PREPEND=
# Need the C compiler used for OCaml (important on Windows, as both x86 and x64 are used)
AS_IF([test "$OCAMLBEST" = "opt"],[OCAMLBESTCC=$OCAMLOPT],[OCAMLBESTCC=$OCAMLC])
AC_PROG_CC([$($OCAMLBESTCC -config | sed -n -e "s/native_c_compiler: \(.*\) .*/\1/p") gcc cl cc])
OCAML_CC="$($OCAMLBESTCC -config | sed -n -e "s/native_c_compiler: \(.*\) .*/\1/p")"
set dummy ${OCAML_CC}; OCAML_TEST_CC=$2
AS_IF([test ! -x ${OCAML_TEST_CC}],[
AS_IF([test "x${CCOMP_TYPE}" = "xmsvc"],[
AS_IF([test "${ARCH}" = "i386"],[SDK_ARCH=x86],[SDK_ARCH=x64])
AC_MSG_CHECKING([for an installed Microsoft C Compiler for ${SDK_ARCH}])
eval `./shell/msvs-detect --arch=$SDK_ARCH; echo RESULT=$?`
AS_IF([ test "x$MSVS_NAME" = "x" ], [
AS_IF([ test ${RESULT} -eq 0 ], [
AC_MSG_RESULT([from PATH])
],[
AC_MSG_ERROR([no])
])
],[
AC_MSG_RESULT([from $MSVS_NAME])
export PATH_PREPEND="${MSVS_PATH}:${PATH_PREPEND}"
export PATH="${PATH_PREPEND}$PATH"
LIB_PREPEND="${MSVS_LIB};"
INC_PREPEND="${MSVS_INC};"
export Lib="${MSVS_LIB};$LIB"
export Include="${MSVS_INC};$INCLUDE"
])
])
])
AC_PROG_CC(["${OCAML_CC}" gcc cc])

AS_IF([test "x${enable_developer_mode}" = "xyes"], [AC_SUBST(DEVELOPER,true)], [AC_SUBST(DEVELOPER,false)])

Expand All @@ -78,9 +113,15 @@ AC_SUBST(EXE)

AS_IF([ test ${WIN32} -eq 1 -a "$GCC" != "yes" ],[
AC_MSG_CHECKING([whether Microsoft Linker needs a PATH shim])
PREV_PREPEND="$PATH_PREPEND"
PATH_PREPEND=$(bash ./shell/check_linker)
AS_IF([test "x${PATH_PREPEND}" = "x" ],[PATH_PREPEND_RESULT=no],[PATH_PREPEND_RESULT=yes])
AS_IF([test "x${PATH_PREPEND}" = "x${PREV_PREPEND}" ],[PATH_PREPEND_RESULT=no],[PATH_PREPEND_RESULT=yes])
PATH_PREPEND=`echo "${PATH_PREPEND}" | sed -e 's/#/\\\\#/g' -e 's/\\$/$$/g'`
LIB_PREPEND=`echo ${LIB_PREPEND} | sed -e 's/#/\\\\#/g' -e 's/\\$/$$/g'`
INC_PREPEND=`echo ${INC_PREPEND} | sed -e 's/#/\\\\#/g' -e 's/\\$/$$/g'`
AC_SUBST(PATH_PREPEND)
AC_SUBST(LIB_PREPEND)
AC_SUBST(INC_PREPEND)
AC_MSG_RESULT([$PATH_PREPEND_RESULT])
])

Expand Down
Loading

0 comments on commit c85ca73

Please sign in to comment.