123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116(************************************************************************)(* * The Coq Proof Assistant / The Coq Development Team *)(* v * Copyright INRIA, CNRS and contributors *)(* <O___,, * (see version control and CREDITS file for authors & dates) *)(* \VV/ **************************************************************)(* // * This file is distributed under the terms of the *)(* * GNU Lesser General Public License Version 2.1 *)(* * (see LICENSE file for the text of the license) *)(************************************************************************)modulePath=structtypet=stringletrelative=Filename.concatletto_stringx=xletexistsx=Sys.file_existsxend(* For now just a pointer to coq/lib (for .vo) and coq-core/lib (for plugins) *)typet={core:Path.t;lib:Path.t}(* fatal error *)letfail_msg="cannot guess a path for Coq libraries; please use -coqlib option \
or ensure you have installed the package containing Coq's stdlib (coq-stdlib in OPAM) \
If you intend to use Coq without a standard library, the -boot -noinit options must be used."letfails=Format.eprintf"%s@\n%!"fail_msg;exit1(* This code needs to be refactored, for now it is just what used to be in envvars *)lettheories_dir="theories"letplugins_dir="plugins"letprelude=Filename.concattheories_dir"Init/Prelude.vo"letguess_coqlib()=Util.getenv_else"COQLIB"(fun()->Util.check_file_else~dir:Coq_config.coqlibsuffix~file:prelude(fun()->ifSys.file_exists(Filename.concatCoq_config.coqlibprelude)thenCoq_config.coqlibelsefail()))(* Build layout uses coqlib = coqcorelib *)letguess_coqcoreliblib=ifSys.file_exists(Path.relativelibplugins_dir)thenlibelsePath.relativelib"../coq-core"letfail_liblib=letopenPrintfineprintf"File not found: %s\n"lib;eprintf"The path for Coq libraries is wrong.\n";eprintf"Coq libraries are shipped in the coq-stdlib package.\n";eprintf"Please check the COQLIB env variable or the -coqlib option.\n";exit1letfail_coreplugin=letopenPrintfineprintf"File not found: %s\n"plugin;eprintf"The path for Coq plugins is wrong.\n";eprintf"Coq plugins are shipped in the coq-core package.\n";eprintf"Please check the COQCORELIB env variable.\n";exit1letvalidate_env({core;lib}asenv)=letlib=Filename.concatlibpreludeinifnot(Sys.file_existslib)thenfail_liblib;letplugin=Filename.concatcoreplugins_dirinifnot(Sys.file_existsplugin)thenfail_coreplugin;env(* Should we fail on double initialization? That seems a way to avoid
mis-use for example when we pass command line arguments *)letinit()=letlib=guess_coqlib()inletcore=Util.getenv_else"COQCORELIB"(fun()->guess_coqcoreliblib)invalidate_env{core;lib}letenv_ref=refNoneletinit()=match!env_refwith|None->letenv=init()inenv_ref:=Someenv;env|Someenv->envletset_coqliblib=letenv=validate_env{lib;core=guess_coqcoreliblib}inenv_ref:=Someenvletcoqlib{lib;_}=libletcorelib{core;_}=coreletplugins{core;_}=Path.relativecoreplugins_dirletstdlib{lib;_}=Path.relativelibtheories_dirletuser_contrib{lib;_}=Path.relativelib"user-contrib"lettool{core;_}tool=Path.(relative(relativecore"tools")tool)letrevision{core;_}=Path.relativecore"revision"letnative_cmi{core;_}lib=letinstall_path=Path.relativecorelibinifSys.file_existsinstall_paththeninstall_pathelse(* Dune build layout, we need to improve this *)letobj_dir=Format.asprintf".%s.objs"libinFilename.(concat(concat(concatcorelib)obj_dir)"byte")