1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677(************************************************************************)(* * 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) *)(************************************************************************)letparse_env_linel=tryScanf.sscanfl"%[^=]=%S"(funnamevalue->Some(name,value))with_->Noneletwith_icfilef=letic=open_infileintryletrc=ficinclose_inic;rcwithe->close_inic;raiseeletgetenv_from_filename=letbase=Filename.dirnameSys.executable_nameintrywith_ic(base^"/coq_environment.txt")(funic->letrecfind()=letl=input_lineicinmatchparse_env_linelwith|Some(n,v)whenn=name->v|_->find()infind())with|Sys_errors->raiseNot_found|End_of_file->raiseNot_foundletsystem_getenvname=trySys.getenvnamewithNot_found->getenv_from_filenameletgetenv_elsesdft=trysystem_getenvswithNot_found->dft()(** Add a local installation suffix (unless the suffix is itself
absolute in which case the prefix does not matter) *)letuse_suffixprefixsuffix=ifString.lengthsuffix>0&&suffix.[0]='/'thensuffixelseFilename.concatprefixsuffixletcanonical_path_namep=letcurrent=Sys.getcwd()intrySys.chdirp;letp'=Sys.getcwd()inSys.chdircurrent;p'withSys_error_->(* We give up to find a canonical name and just simplify it... *)Filename.concatcurrentpletcoqbin=canonical_path_name(Filename.dirnameSys.executable_name)(** The following only makes sense when executables are running from
source tree (e.g. during build or in local mode). *)letcoqroot=Filename.dirnamecoqbin(** [check_file_else ~dir ~file oth] checks if [file] exists in
the installation directory [dir] given relatively to [coqroot],
which maybe has been relocated.
If the check fails, then [oth ()] is evaluated.
Using file system equality seems well enough for this heuristic *)letcheck_file_else~dir~fileoth=letpath=use_suffixcoqrootdirinifSys.file_exists(Filename.concatpathfile)thenpathelseoth()