Skip to content

Commit

Permalink
Clarify and slightly modify the use of C compiler related make variab…
Browse files Browse the repository at this point in the history
…les.

Before this commit, there was no distinction between the options
used to compile C source files coming with the OCaml distribution
and third-party C source files compiled by calling ocamlc or ocamlopt.

This commit makes it possible to use options when compiling C source
files that come with OCaml without imposing these options to the compilation
of third-party code.

More specifically, the options in the BYTECCCOMPOPTS and NATIVECCCOMPOPTS
variables are not passed to the C compiler when called by ocamlc and
ocamlopt any longer.

This commit also documents the role of each concerned variable.

In addition:

- On Unix:
  * The -Wall and -Werror options are no longer passed to the C
    compiler by ocamlc and ocamlopt for third-party C source files

- For the MinGW port:
  * The -O option has been removed from the SHAREDCCCOMPOPTS variable
  * The -Wall and -Wno-unused options are no longer passed to the C
    compiler by ocamlc and ocamlopt for third-party C source files

- For the msvc port: the
  * The -Ox option has been removed from the SHAREDCCCOMPOPTS variable.
  * The -Wall and -Wno-unused options are no longer passed to the C
    compiler by ocamlc and ocamlopt for third-party C source files
  • Loading branch information
shindere committed Nov 16, 2016
1 parent e530682 commit 3e81da2
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 31 deletions.
4 changes: 4 additions & 0 deletions Changes
Expand Up @@ -31,6 +31,10 @@ Next version (4.05.0):
- GPR#829: better error when opening a module aliased to a functor
(Alain Frisch)

- GPR#911: ocamlc/ocamlopt do not pass warnings-related options to C
compiler when called to compile third-party C source files
(Sébastien Hinderer)

### Standard library:

- GPR#760: Add a functions List.compare_lengths and
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Expand Up @@ -407,8 +407,8 @@ utils/config.ml: utils/config.mlp config/Makefile
sed -e 's|%%LIBDIR%%|$(LIBDIR)|' \
-e 's|%%BYTERUN%%|$(BINDIR)/ocamlrun|' \
-e 's|%%CCOMPTYPE%%|cc|' \
-e 's|%%BYTECC%%|$(BYTECC) $(BYTECCCOMPOPTS) $(SHAREDCCCOMPOPTS)|' \
-e 's|%%NATIVECC%%|$(NATIVECC) $(NATIVECCCOMPOPTS)|' \
-e 's|%%BYTECC%%|$(BYTECC) $(SHAREDCCCOMPOPTS)|' \
-e 's|%%NATIVECC%%|$(NATIVECC)|' \
-e '/c_compiler =/s| -Werror||' \
-e 's|%%PACKLD%%|$(PACKLD)|' \
-e 's|%%BYTECCLIBS%%|$(BYTECCLIBS)|' \
Expand Down
4 changes: 2 additions & 2 deletions Makefile.nt
Expand Up @@ -374,8 +374,8 @@ utils/config.ml: utils/config.mlp config/Makefile
sed -e "s|%%LIBDIR%%|$(LIBDIR)|" \
-e "s|%%BYTERUN%%|ocamlrun|" \
-e 's|%%CCOMPTYPE%%|$(CCOMPTYPE)|' \
-e "s|%%BYTECC%%|$(BYTECC) $(BYTECCCOMPOPTS)|" \
-e "s|%%NATIVECC%%|$(NATIVECC) $(NATIVECCCOMPOPTS)|" \
-e "s|%%BYTECC%%|$(BYTECC)|" \
-e "s|%%NATIVECC%%|$(NATIVECC)|" \
-e "s|%%PARTIALLD%%|$(PARTIALLD)|" \
-e "s|%%PACKLD%%|$(PACKLD)|" \
-e "s|%%BYTECCLIBS%%|$(BYTECCLIBS)|" \
Expand Down
8 changes: 4 additions & 4 deletions config/Makefile.mingw
Expand Up @@ -68,7 +68,7 @@ X11_INCLUDES=
X11_LINK=
BYTECCRPATH=
SUPPORTS_SHARED_LIBRARIES=true
SHAREDCCCOMPOPTS=-O
SHAREDCCCOMPOPTS=
MKSHAREDLIBRPATH=
NATIVECCPROFOPTS=
NATIVECCRPATH=
Expand Down Expand Up @@ -98,10 +98,10 @@ SAFE_STRING=false
########## Configuration for the bytecode compiler

### Which C compiler to use for the bytecode interpreter.
BYTECC=$(TOOLPREF)gcc
BYTECC=$(TOOLPREF)gcc -O -mms-bitfields

### Additional compile-time options for $(BYTECC). (For static linking.)
BYTECCCOMPOPTS=-O -mms-bitfields -Wall -Wno-unused
BYTECCCOMPOPTS=-Wall -Wno-unused

### Additional link-time options for $(BYTECC). (For static linking.)
BYTECCLINKOPTS=
Expand Down Expand Up @@ -168,7 +168,7 @@ SYSTEM=mingw
NATIVECC=$(BYTECC)

### Additional compile-time options for $(NATIVECC).
NATIVECCCOMPOPTS=-O -mms-bitfields -Wall -Wno-unused
NATIVECCCOMPOPTS=-Wall -Wno-unused

### Additional link-time options for $(NATIVECC)
NATIVECCLINKOPTS=
Expand Down
8 changes: 4 additions & 4 deletions config/Makefile.mingw64
Expand Up @@ -68,7 +68,7 @@ X11_INCLUDES=
X11_LINK=
BYTECCRPATH=
SUPPORTS_SHARED_LIBRARIES=true
SHAREDCCCOMPOPTS=-O
SHAREDCCCOMPOPTS=
MKSHAREDLIBRPATH=
NATIVECCPROFOPTS=
NATIVECCRPATH=
Expand Down Expand Up @@ -98,10 +98,10 @@ SAFE_STRING=false
########## Configuration for the bytecode compiler

### Which C compiler to use for the bytecode interpreter.
BYTECC=$(TOOLPREF)gcc
BYTECC=$(TOOLPREF)gcc -O -mms-bitfields

### Additional compile-time options for $(BYTECC). (For static linking.)
BYTECCCOMPOPTS=-O -mms-bitfields -Wall -Wno-unused
BYTECCCOMPOPTS=-Wall -Wno-unused

### Additional link-time options for $(BYTECC). (For static linking.)
BYTECCLINKOPTS=
Expand Down Expand Up @@ -168,7 +168,7 @@ SYSTEM=mingw64
NATIVECC=$(BYTECC)

### Additional compile-time options for $(NATIVECC).
NATIVECCCOMPOPTS=-O -mms-bitfields -Wall -Wno-unused
NATIVECCCOMPOPTS=-Wall -Wno-unused

### Additional link-time options for $(NATIVECC)
NATIVECCLINKOPTS=
Expand Down
10 changes: 5 additions & 5 deletions config/Makefile.msvc
Expand Up @@ -63,7 +63,7 @@ X11_INCLUDES=
X11_LINK=
BYTECCRPATH=
SUPPORTS_SHARED_LIBRARIES=true
SHAREDCCCOMPOPTS=-Ox
SHAREDCCCOMPOPTS=
NATIVECCPROFOPTS=
NATIVECCRPATH=
ASM=ml -nologo -coff -Cp -c -Fo
Expand Down Expand Up @@ -92,10 +92,10 @@ SAFE_STRING=false
########## Configuration for the bytecode compiler

### Which C compiler to use for the bytecode interpreter.
BYTECC=cl -nologo -D_CRT_SECURE_NO_DEPRECATE
BYTECC=cl -nologo -D_CRT_SECURE_NO_DEPRECATE -O2 -Gy- -MD

### Additional compile-time options for $(BYTECC). (For static linking.)
BYTECCCOMPOPTS=-O2 -Gy- -MD
BYTECCCOMPOPTS=

### Additional link-time options for $(BYTECC). (For static linking.)
BYTECCLINKOPTS=
Expand Down Expand Up @@ -163,10 +163,10 @@ MODEL=default
SYSTEM=win32

### Which C compiler to use for the native-code compiler.
NATIVECC=cl -nologo -D_CRT_SECURE_NO_DEPRECATE
NATIVECC=cl -nologo -D_CRT_SECURE_NO_DEPRECATE -O2 -Gy- -MD

### Additional compile-time options for $(NATIVECC).
NATIVECCCOMPOPTS=-O2 -Gy- -MD
NATIVECCCOMPOPTS=

### Additional link-time options for $(NATIVECC)
NATIVECCLINKOPTS=
Expand Down
10 changes: 5 additions & 5 deletions config/Makefile.msvc64
Expand Up @@ -63,7 +63,7 @@ X11_INCLUDES=
X11_LINK=
BYTECCRPATH=
SUPPORTS_SHARED_LIBRARIES=true
SHAREDCCCOMPOPTS=-Ox
SHAREDCCCOMPOPTS=
NATIVECCPROFOPTS=
NATIVECCRPATH=
ASM=ml64 -nologo -Cp -c -Fo
Expand Down Expand Up @@ -91,10 +91,10 @@ SAFE_STRING=false
########## Configuration for the bytecode compiler

### Which C compiler to use for the bytecode interpreter.
BYTECC=cl -nologo -D_CRT_SECURE_NO_DEPRECATE
BYTECC=cl -nologo -D_CRT_SECURE_NO_DEPRECATE -O2 -Gy- -MD

### Additional compile-time options for $(BYTECC). (For static linking.)
BYTECCCOMPOPTS=-O2 -Gy- -MD
BYTECCCOMPOPTS=

### Additional compile-time options for $(BYTECC). (For debug version.)
BYTECCDBGCOMPOPTS=-DDEBUG -Zi -W3 -Wp64
Expand Down Expand Up @@ -168,10 +168,10 @@ MODEL=default
SYSTEM=win64

### Which C compiler to use for the native-code compiler.
NATIVECC=cl -nologo
NATIVECC=cl -nologo -O2 -Gy- -MD

### Additional compile-time options for $(NATIVECC).
NATIVECCCOMPOPTS=-O2 -Gy- -MD
NATIVECCCOMPOPTS=

### Additional link-time options for $(NATIVECC)
NATIVECCLINKOPTS=
Expand Down
54 changes: 45 additions & 9 deletions configure
Expand Up @@ -328,10 +328,29 @@ esac

# Configure the bytecode compiler

# The BYTECC make variable defines which compiler and options to use
# to compile C code intended to be used by OCaml bytecode programs.
# It is used inside OCaml's build system, and also when ocamlc is
# called on a third-party C source file and no -cc command-line option
# has been specified.

# The BYTECCCOMPOPTS make variable contains options to pass to the C
# compiler but only when compiling C files that belong to the OCaml
# distribution.
# In other words, when ocamlc is called to compile a third-party C
# source file, it will _not_ pass these options to the C compiler.

# The SHAREDCCCOMPOPTS make variable contains options to use to compile C
# source files so that the resulting object files can then be integrated
# into shared libraries. It is passed to BYTECC for both C source files
# in the OCaml distribution and third-party C source files compiled
# with ocamlc.

bytecc="$cc"
mkexe="\$(BYTECC)"
mkexedebugflag="-g"
bytecccompopts=""
byteccprivatecompopts=""
bytecclinkopts=""
ostype="Unix"
exe=""
Expand All @@ -357,7 +376,8 @@ esac

case "$ccfamily" in
clang-*)
bytecccompopts="-O2 -fno-strict-aliasing -fwrapv $gcc_warnings";;
bytecccompopts="-O2 -fno-strict-aliasing -fwrapv";
byteccprivatecompopts="$gcc_warnings";;
gcc-[012]-*)
# Some versions known to miscompile OCaml, e,g, 2.7.2.1, some 2.96.
# Plus: C99 support unknown.
Expand All @@ -367,11 +387,14 @@ case "$ccfamily" in
# Known problems with -fwrapv fixed in 4.2 only.
wrn "This version of GCC is rather old. Reducing optimization level."
wrn "Consider using GCC version 4.2 or above."
bytecccompopts="-std=gnu99 -O $gcc_warnings";;
bytecccompopts="-std=gnu99 -O";
byteccprivatecompopts="$gcc_warnings";;
gcc-4-*)
bytecccompopts="-std=gnu99 -O2 -fno-strict-aliasing -fwrapv $gcc_warnings";;
bytecccompopts="-std=gnu99 -O2 -fno-strict-aliasing -fwrapv";
byteccprivatecompopts="$gcc_warnings";;
gcc-*)
bytecccompopts="-O2 -fno-strict-aliasing -fwrapv $gcc_warnings";;
bytecccompopts="-O2 -fno-strict-aliasing -fwrapv";
byteccprivatecompopts="$gcc_warnings";;
*)
bytecccompopts="-O";;
esac
Expand Down Expand Up @@ -487,7 +510,7 @@ export cc cclibs verbose

# Check C compiler.

cc="$bytecc $bytecccompopts $bytecclinkopts" sh ./runtest ansi.c
cc="$bytecc $bytecccompopts $byteccprivatecompopts $bytecclinkopts" sh ./runtest ansi.c
case $? in
0) inf "The C compiler is ISO C99 compliant." ;;
1) wrn "The C compiler is ANSI / ISO C90 compliant, but not ISO C99" \
Expand Down Expand Up @@ -843,6 +866,18 @@ fi

# Configure the native-code compiler

# The NATIVECC make variable defines which compiler and options to use
# to compile C code intended to be used by OCaml native programs.
# It is used inside OCaml's build system, and also when ocamlopt is
# called on a third-party C source file and no -cc command-line
# option has been specified.

# The NATIVECCCOMPOPTS make variable contains options to pass to the C
# compiler, but only when compiling C files that belong to the OCaml
# distribution.
# In other words, when ocamlopt is called to compile a third-party C
# source file, it will _not_ pass these options to the C compiler.

arch=none
model=default
system=unknown
Expand Down Expand Up @@ -925,6 +960,7 @@ else
fi

nativecccompopts="$bytecccompopts"
nativeccprivatecompopts=byteccprivatecompopts
nativeccprofopts=''
nativecclinkopts=''
# FIXME the naming of nativecclinkopts is broken: these are options for
Expand Down Expand Up @@ -1920,8 +1956,8 @@ fi

cclibs="$cclibs $mathlib"

echo "BYTECC=$bytecc" >> Makefile
echo "BYTECCCOMPOPTS=$bytecccompopts" >> Makefile
echo "BYTECC=$bytecc $bytecccompopts" >> Makefile
echo "BYTECCCOMPOPTS=$byteccprivatecompopts" >> Makefile
echo "BYTECCLINKOPTS=$bytecclinkopts" >> Makefile
echo "BYTECCLIBS=$cclibs $dllib $curseslibs $pthread_link \
$instrumented_runtime_libs" >> Makefile
Expand All @@ -1944,8 +1980,8 @@ EOF
echo "ARCH=$arch" >> Makefile
echo "MODEL=$model" >> Makefile
echo "SYSTEM=$system" >> Makefile
echo "NATIVECC=$nativecc" >> Makefile
echo "NATIVECCCOMPOPTS=$nativecccompopts" >> Makefile
echo "NATIVECC=$nativecc $nativecccompopts" >> Makefile
echo "NATIVECCCOMPOPTS=$nativeprivatecccompopts" >> Makefile
echo "NATIVECCPROFOPTS=$nativeccprofopts" >> Makefile
echo "NATIVECCLINKOPTS=$nativecclinkopts" >> Makefile
echo "NATIVECCRPATH=$nativeccrpath" >> Makefile
Expand Down

0 comments on commit 3e81da2

Please sign in to comment.