[minor] harden config/Makefile against '#' in PREFIX

The opam-compiler-conf script will generate an opam switch name
(and thus a directory name) from the name of the current git
branch. Branches named 'PR#1234-foo-bar' would have the ./configure
script generate a config/Makefile with the lines

    PREFIX=~/.opam/4.06.0+local-git-PR#1234-foo-bar
    BINDIR=$(PREFIX)/bin
    BYTERUN=$(BINDIR)/ocamlrun
    LIBDIR=$(PREFIX)/lib/ocaml

The '#' in the first line parses as the start of a comment, so
the second part is ignored and the build system would then install
in ~/.opam/4.06.0+local-git-PR instead.

After this change, config/Makefile starts with:

    # generated by ./configure --prefix ~/.opam/4.06.0+local-git-PR#1234-foo-bar
    CONFIGURE_ARGS=--prefix ~/.opam/4.06.0+local-git-PR\#1234-foo-bar
    PREFIX=~/.opam/4.06.0+local-git-PR\#1234-foo-bar
master
Gabriel Scherer 2017-06-26 20:53:22 -04:00
parent 393ff30948
commit 890c8bb2ca
2 changed files with 128 additions and 104 deletions

View File

@ -230,6 +230,9 @@ Working version
- GPR#1203: speed up the manual build by using ocamldoc.opt
(Gabriel Scherer, review by Florian Angeletti)
- GPR#1214: harden config/Makefile against '#' characters in PREFIX
(Gabriel Scherer, review by David Allsopp and Damien Doligez)
- GPR#1242: disable C plugins loading by default
(Alexey Egorov)

229
configure vendored
View File

@ -259,33 +259,54 @@ touch s.h m.h Makefile
# Write options to Makefile
config() {
# This function hardens the generated Makefile against '#' symbols
# present in a source path (opam-compiler-conf may pick such directory
# names if working from a branch named 'PR#4242-answer-all-questions')
# by escaping them into '\#'.
# When injecting data in Makefiles, it is customary to also escape
# '$', which get turned into '$$'. However, this transformation is
# invalid here as some of the variables are meant to be code
# interpreted by make: for example, passing
# --bindir "$(PREFIX)/bin2"
# is explicitly supported (see "or relative to $(PREFIX)" messages above).
# Finally, it is also impossible for the user to escape the '#' signs
# before calling this configure script, given that
# $(PREFIX) is also injected in C code where this escape is invalid
# -- see the definition of the OCAML_STDLIB_DIR macro below.
echo "$1=$2" | sed 's/#/\\#/g' >> Makefile
}
echo "# generated by ./configure $configure_options" >> Makefile
echo "CONFIGURE_ARGS=$configure_options" >> Makefile
config CONFIGURE_ARGS "$configure_options"
# Where to install
echo "PREFIX=$prefix" >> Makefile
config PREFIX "$prefix"
case "$bindir" in
"") echo 'BINDIR=$(PREFIX)/bin' >> Makefile
"") config BINDIR '$(PREFIX)/bin'
bindir="$prefix/bin";;
*) echo "BINDIR=$bindir" >> Makefile;;
*) config BINDIR "$bindir";;
esac
echo 'BYTERUN=$(BINDIR)/ocamlrun' >> Makefile
config BYTERUN '$(BINDIR)/ocamlrun'
case "$libdir" in
"") echo 'LIBDIR=$(PREFIX)/lib/ocaml' >> Makefile
"") config LIBDIR '$(PREFIX)/lib/ocaml'
libdir="$prefix/lib/ocaml";;
*) echo "LIBDIR=$libdir" >> Makefile;;
*) config LIBDIR "$libdir";;
esac
echo 'STUBLIBDIR=$(LIBDIR)/stublibs' >> Makefile
config STUBLIBDIR '$(LIBDIR)/stublibs'
case "$mandir" in
"") echo 'MANDIR=$(PREFIX)/man' >> Makefile
"") config MANDIR '$(PREFIX)/man'
mandir="$prefix/man";;
*) echo "MANDIR=$mandir" >> Makefile;;
*) config MANDIR "$mandir";;
esac
echo "PROGRAMS_MAN_SECTION=$programs_man_section" >> Makefile
echo "LIBRARIES_MAN_SECTION=$libraries_man_section" >> Makefile
config PROGRAMS_MAN_SECTION "$programs_man_section"
config LIBRARIES_MAN_SECTION "$libraries_man_section"
# Determine the system type
@ -560,7 +581,7 @@ if $cross_compiler; then
"($ocaml_system_version) doesn't match the version of these\n" \
"sources ($ocaml_source_version)."
else
echo "CAMLRUN=`./searchpath -p ocamlrun`" >> Makefile
config CAMLRUN "`./searchpath -p ocamlrun`"
fi
fi
@ -572,14 +593,14 @@ if $cross_compiler; then
err "While you have an ocamlyacc binary, it cannot be executed" \
"successfully."
else
echo "CAMLYACC=`./searchpath -p ocamlyacc`" >> Makefile
config CAMLYACC "`./searchpath -p ocamlyacc`"
fi
fi
if [ -z "$target_bindir" ]; then
err "Cross-compilation requires -target-bindir."
else
echo "TARGET_BINDIR=$target_bindir" >> Makefile
config TARGET_BINDIR "$target_bindir"
fi
fi # cross-compiler
@ -1039,15 +1060,15 @@ esac
if sh ./searchpath ${TOOLPREF}ranlib; then
inf "ranlib found"
echo "RANLIB=${TOOLPREF}ranlib" >> Makefile
echo "RANLIBCMD=${TOOLPREF}ranlib" >> Makefile
config RANLIB "${TOOLPREF}ranlib"
config RANLIBCMD "${TOOLPREF}ranlib"
else
inf "ranlib not used"
echo "RANLIB=${TOOLPREF}ar rs" >> Makefile
echo "RANLIBCMD=" >> Makefile
config RANLIB "${TOOLPREF}ar rs"
config RANLIBCMD ""
fi
echo "ARCMD=${TOOLPREF}ar" >> Makefile
config ARCMD "${TOOLPREF}ar"
# Write the OS type (Unix or Cygwin)
@ -1066,21 +1087,21 @@ if ( (./hashbang || ./hashbang2 || ./hashbang3 || ./hashbang4) >/dev/null); then
*-*-sunos*|*-*-unicos*)
wrn "We won't use it, though, because under SunOS and Unicos it breaks " \
"on pathnames longer than 30 characters"
echo "HASHBANGSCRIPTS=false" >> Makefile;;
config HASHBANGSCRIPTS "false";;
*-*-cygwin*)
wrn "We won't use it, though, because of conflicts with .exe extension " \
"under Cygwin"
echo "HASHBANGSCRIPTS=false" >> Makefile;;
config HASHBANGSCRIPTS "false";;
*-*-mingw*)
inf "We won't use it, though, because it's on the target platform " \
"it would be used and windows doesn't support it."
echo "HASHBANGSCRIPTS=false" >> Makefile;;
config HASHBANGSCRIPTS "false";;
*)
echo "HASHBANGSCRIPTS=true" >> Makefile;;
config HASHBANGSCRIPTS "true";;
esac
else
inf "No support for #! in shell scripts"
echo "HASHBANGSCRIPTS=false" >> Makefile
config HASHBANGSCRIPTS "false"
fi
# Use 64-bit file offset if possible
@ -1175,9 +1196,9 @@ case "$system" in
*) unix_or_win32="unix"; unixlib="unix"; graphlib="graph";;
esac
echo "UNIX_OR_WIN32=$unix_or_win32" >> Makefile
echo "UNIXLIB=$unixlib" >> Makefile
echo "GRAPHLIB=$graphlib" >> Makefile
config UNIX_OR_WIN32 "$unix_or_win32"
config UNIXLIB "$unixlib"
config GRAPHLIB "$graphlib"
otherlibraries="$unixlib str num dynlink bigarray"
@ -1558,8 +1579,8 @@ case "$arch" in
*) bng_arch=generic; bng_asm_level=0;;
esac
echo "BNG_ARCH=$bng_arch" >> Makefile
echo "BNG_ASM_LEVEL=$bng_asm_level" >> Makefile
config BNG_ARCH "$bng_arch"
config BNG_ASM_LEVEL "$bng_asm_level"
# Determine if the POSIX threads library is supported
@ -1604,8 +1625,8 @@ if test "$pthread_wanted" = "yes"; then
else
pthread_link=""
fi
echo "PTHREAD_LINK=$pthread_link" >> Makefile
echo "PTHREAD_CAML_LINK=$pthread_caml_link" >> Makefile
config PTHREAD_LINK "$pthread_link"
config PTHREAD_CAML_LINK "$pthread_caml_link"
# Determine if the bytecode thread library is supported
@ -2000,22 +2021,22 @@ fi
cclibs="$cclibs $mathlib"
echo CC="$cc" >> Makefile
echo "CFLAGS=$common_cflags $internal_cflags" >> Makefile
echo "CPPFLAGS=$common_cppflags $internal_cppflags" >> Makefile
echo "OCAMLC_CFLAGS=$common_cflags $sharedcccompopts" >> Makefile
echo "OCAMLC_CPPFLAGS=$common_cppflags" >> Makefile
echo "LDFLAGS=$ldflags" >> Makefile
echo "BYTECCLIBS=$cclibs $dllib $curseslibs $pthread_link \
$instrumented_runtime_libs" >> Makefile
echo "RPATH=$rpath" >> Makefile
echo "EXE=$exe" >> Makefile
echo "EMPTY=" >> Makefile
echo "OUTPUTEXE=-o \$(EMPTY)" >> Makefile
echo "SUPPORTS_SHARED_LIBRARIES=$shared_libraries_supported" >> Makefile
echo "SHAREDCCCOMPOPTS=$sharedcccompopts" >> Makefile
echo "MKSHAREDLIBRPATH=$mksharedlibrpath" >> Makefile
echo "NATDYNLINKOPTS=$natdynlinkopts" >> Makefile
config CC "$cc"
config CFLAGS "$common_cflags $internal_cflags"
config CPPFLAGS "$common_cppflags $internal_cppflags"
config OCAMLC_CFLAGS "$common_cflags $sharedcccompopts"
config OCAMLC_CPPFLAGS "$common_cppflags"
config LDFLAGS "$ldflags"
config BYTECCLIBS "$cclibs $dllib $curseslibs $pthread_link \
$instrumented_runtime_libs"
config RPATH "$rpath"
config EXE "$exe"
config EMPTY ""
config OUTPUTEXE "-o \$(EMPTY)"
config SUPPORTS_SHARED_LIBRARIES "$shared_libraries_supported"
config SHAREDCCCOMPOPTS "$sharedcccompopts"
config MKSHAREDLIBRPATH "$mksharedlibrpath"
config NATDYNLINKOPTS "$natdynlinkopts"
cat >> Makefile <<EOF
SYSLIB=-l\$(1)
#ml let syslib x = "-l"^x;;
@ -2026,64 +2047,64 @@ MKLIB=${TOOLPREF}ar rc \$(1) \$(2); ${TOOLPREF}ranlib \$(1)
#ml Printf.sprintf "${TOOLPREF}ar rc %s %s %s; ${TOOLPREF}ranlib %s"
#ml out opts files out;;
EOF
echo "ARCH=$arch" >> Makefile
echo "MODEL=$model" >> Makefile
echo "SYSTEM=$system" >> Makefile
echo "OCAMLOPT_CFLAGS=$common_cflags" >> Makefile
echo "OCAMLOPT_CPPFLAGS=$common_cppflags" >> Makefile
echo "NATIVECCPROFOPTS=$nativeccprofopts" >> Makefile
echo "NATIVECCLIBS=$cclibs $dllib" >> Makefile
echo "ASM=$as" >> Makefile
echo "ASPP=$aspp" >> Makefile
echo "ASPPPROFFLAGS=$asppprofflags" >> Makefile
echo "PROFILING=$profiling" >> Makefile
echo "DYNLINKOPTS=$dllib" >> Makefile
echo "OTHERLIBRARIES=$otherlibraries" >> Makefile
echo "CC_PROFILE=$cc_profile" >> Makefile
echo "SYSTHREAD_SUPPORT=$systhread_support" >> Makefile
echo "PACKLD=$partialld -o\\ " >> Makefile
echo "IFLEXDIR=$iflexdir" >> Makefile
echo "O=o" >> Makefile
echo "A=a" >> Makefile
echo "SO=$SO" >> Makefile
echo "EXT_OBJ=.o" >> Makefile
echo "OUTPUTOBJ=-o \$(EMPTY)" >> Makefile
echo "EXT_ASM=.s" >> Makefile
echo "EXT_LIB=.a" >> Makefile
echo "EXT_DLL=.$SO" >> Makefile
echo "EXTRALIBS=" >> Makefile
echo "CCOMPTYPE=cc" >> Makefile
echo "TOOLCHAIN=$TOOLCHAIN" >> Makefile
echo "NATDYNLINK=$natdynlink" >> Makefile
echo "CMXS=$cmxs" >> Makefile
echo "MKEXE=$mkexe" >> Makefile
echo "MKEXEDEBUGFLAG=$mkexedebugflag" >> Makefile
echo "MKDLL=$mksharedlib" >> Makefile
echo "MKMAINDLL=$mkmaindll" >> Makefile
echo "RUNTIMED=${debugruntime}" >>Makefile
echo "RUNTIMEI=${with_instrumented_runtime}" >>Makefile
echo "WITH_DEBUGGER=${with_debugger}" >>Makefile
echo "WITH_OCAMLDOC=${with_ocamldoc}" >>Makefile
echo "ASM_CFI_SUPPORTED=$asm_cfi_supported" >> Makefile
echo "WITH_FRAME_POINTERS=$with_frame_pointers" >> Makefile
echo "WITH_SPACETIME=$with_spacetime" >> Makefile
echo "WITH_SPACETIME_CALL_COUNTS=$with_spacetime_call_counts" >> Makefile
echo "WITH_PROFINFO=$with_profinfo" >> Makefile
echo "LIBUNWIND_AVAILABLE=$libunwind_available" >> Makefile
echo "LIBUNWIND_INCLUDE_FLAGS=$libunwind_include" >> Makefile
echo "LIBUNWIND_LINK_FLAGS=$libunwind_lib" >> Makefile
echo "PROFINFO_WIDTH=$profinfo_width" >> Makefile
echo "WITH_CPLUGINS=$with_cplugins" >> Makefile
echo "WITH_FPIC=$with_fpic" >> Makefile
echo "TARGET=$target" >> Makefile
echo "HOST=$host" >> Makefile
config ARCH "$arch"
config MODEL "$model"
config SYSTEM "$system"
config OCAMLOPT_CFLAGS "$common_cflags"
config OCAMLOPT_CPPFLAGS "$common_cppflags"
config NATIVECCPROFOPTS "$nativeccprofopts"
config NATIVECCLIBS "$cclibs $dllib"
config ASM "$as"
config ASPP "$aspp"
config ASPPPROFFLAGS "$asppprofflags"
config PROFILING "$profiling"
config DYNLINKOPTS "$dllib"
config OTHERLIBRARIES "$otherlibraries"
config CC_PROFILE "$cc_profile"
config SYSTHREAD_SUPPORT "$systhread_support"
config PACKLD "$partialld -o\\ \$(EMPTY)"
config IFLEXDIR "$iflexdir"
config O "o"
config A "a"
config SO "$SO"
config EXT_OBJ ".o"
config OUTPUTOBJ "-o \$(EMPTY)"
config EXT_ASM ".s"
config EXT_LIB ".a"
config EXT_DLL ".$SO"
config EXTRALIBS ""
config CCOMPTYPE "cc"
config TOOLCHAIN "$TOOLCHAIN"
config NATDYNLINK "$natdynlink"
config CMXS "$cmxs"
config MKEXE "$mkexe"
config MKEXEDEBUGFLAG "$mkexedebugflag"
config MKDLL "$mksharedlib"
config MKMAINDLL "$mkmaindll"
config RUNTIMED "${debugruntime}"
config RUNTIMEI "${with_instrumented_runtime}"
config WITH_DEBUGGER "${with_debugger}"
config WITH_OCAMLDOC "${with_ocamldoc}"
config ASM_CFI_SUPPORTED "$asm_cfi_supported"
config WITH_FRAME_POINTERS "$with_frame_pointers"
config WITH_SPACETIME "$with_spacetime"
config WITH_SPACETIME_CALL_COUNTS "$with_spacetime_call_counts"
config WITH_PROFINFO "$with_profinfo"
config LIBUNWIND_AVAILABLE "$libunwind_available"
config LIBUNWIND_INCLUDE_FLAGS "$libunwind_include"
config LIBUNWIND_LINK_FLAGS "$libunwind_lib"
config PROFINFO_WIDTH "$profinfo_width"
config WITH_CPLUGINS "$with_cplugins"
config WITH_FPIC "$with_fpic"
config TARGET "$target"
config HOST "$host"
if [ "$ostype" = Cygwin ]; then
echo "DIFF=diff -q --strip-trailing-cr" >>Makefile
config DIFF "diff -q --strip-trailing-cr"
fi
echo "FLAMBDA=$flambda" >> Makefile
echo "SAFE_STRING=$safe_string" >> Makefile
echo "AFL_INSTRUMENT=$afl_instrument" >> Makefile
echo "MAX_TESTSUITE_DIR_RETRIES=$max_testsuite_dir_retries" >> Makefile
config FLAMBDA "$flambda"
config SAFE_STRING "$safe_string"
config AFL_INSTRUMENT "$afl_instrument"
config MAX_TESTSUITE_DIR_RETRIES "$max_testsuite_dir_retries"
rm -f tst hasgot.c