├── .gitignore ├── .travis.yml ├── AUTHORS ├── CHANGES ├── LICENSE ├── Makefile ├── OCamlMakefile ├── README.md ├── depext.ml ├── opam ├── opam-depext.install ├── shell ├── build.ml ├── gen-release.sh └── md5check.ml └── src_ext └── Makefile /.gitignore: -------------------------------------------------------------------------------- 1 | _build 2 | opam-depext 3 | depext.native 4 | shell/build.sh 5 | *.cmi 6 | *.cmo 7 | *.cmx 8 | *.cma 9 | *.cmxa 10 | *.a 11 | *.stamp 12 | src_ext/._bcdi/ 13 | src_ext/._d/ 14 | src_ext/._ncdi/ 15 | src_ext/cmdliner-0.9.8.tbz 16 | src_ext/cmdliner/ 17 | .*.swp 18 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: c 2 | sudo: false 3 | services: 4 | - docker 5 | install: wget https://raw.githubusercontent.com/ocaml/ocaml-ci-scripts/master/.travis-docker.sh 6 | script: bash ./.travis-docker.sh 7 | env: 8 | global: 9 | - PACKAGE="depext" 10 | - PRE_INSTALL_HOOK 11 | - POST_INSTALL_HOOK="opam depext --version && opam depext -ui ssl && opam depext -ui -j 2 -y -v pcre" 12 | matrix: 13 | - DISTRO=debian-stable OCAML_VERSION=4.00.1 14 | - DISTRO=debian-testing OCAML_VERSION=4.01.0 15 | - DISTRO=debian-unstable OCAML_VERSION=4.02.3 16 | - DISTRO=ubuntu-12.04 OCAML_VERSION=4.02.3 17 | - DISTRO=ubuntu-16.04 OCAML_VERSION=4.03.0 18 | - DISTRO=ubuntu-18.04 OCAML_VERSION=4.03.0 19 | - DISTRO=centos OCAML_VERSION=4.04.2 20 | - DISTRO=opensuse OCAML_VERSION=4.05 21 | - DISTRO=fedora OCAML_VERSION=4.06 22 | - DISTRO=alpine OCAML_VERSION=4.07 23 | -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | Louis Gesbert 2 | Anil Madhavapeddy 3 | Francois Berenger 4 | Juergen Hoetzel 5 | -------------------------------------------------------------------------------- /CHANGES: -------------------------------------------------------------------------------- 1 | 1.2.3 (2024-08-15): 2 | * Fix compilation in non-dev mode, broke by #149 (#153 by @kit-ty-kate) 3 | * Fix constant runtime error, broke by #150 (#153 by @kit-ty-kate) 4 | 5 | 1.2.2 (2024-08-05): 6 | * Fix build on bytecode-only systems (#149 by @dra27) 7 | * Fix opam-depext in the presence of OPAMCOLOR=always (#150 by @kit-ty-kate) 8 | * Improve the warning message displayed with opam >= 2.1 (#152 by @krtab) 9 | 10 | 1.2.1 (2022-01-21): 11 | * Add OCaml 5.00 compatibility (#147 by @dra27) 12 | 13 | 1.2.0 (2021-11-10): 14 | * Support opam 2.1 to allow workflows using OPAMCLI=2.0 (#142 by @rjbou) 15 | * Always upgrade installed packages when adding new packages on Arch 16 | (#138 by @kit-ty-kate) 17 | * Prevent yum-based distributions from upgrading during an update 18 | (#137 by @kit-ty-kate) 19 | 20 | 1.1.5 (2021-11-10): 21 | * Fix `depext -u` on Arch Linux and add more BSD support (#135 by @kit-ty-kate) 22 | * Fix Arch Linux and Oracle Linux support (#134 by @kit-ty-kate) 23 | 24 | 1.1.4 (2020-10-14): 25 | * Fix shell quoting when calling opam (#132 by @kit-ty-kate) 26 | * Display the correct licence in the man page (#98 by @avsm) 27 | * Make behaviour of interactive yes consistent across platforms, mirroring 28 | the integrated depext support in ocaml/opam#4168 (#123 by @kit-ty-kate) 29 | * Compatibility with opam 2.1.0~alpha (#126 by @rjbou) 30 | 31 | 1.1.3 (2019-04-24): 32 | * Support test-only and docs-only dependencies in opam files via 33 | `--with-test` and `--with-doc` to opam-depext. 34 | 35 | 1.1.2 (2018-06-05): 36 | * Fixed license 37 | * Specific fixes for OpenSuse, Fedora 38 | * Improved OpenBSD support 39 | 40 | 1.1.1 (2018-01-29): 41 | * Propagate exit codes of sub-commands 42 | * Fixes 43 | 44 | 1.1.0 (2017-10-17): 45 | * Separate output between comments (stderr) and information (stdout) 46 | * Switch to opam 2.0.0~beta5 CLI and variables (not backwards compatible) 47 | 48 | 1.0.6 (2017-07-24): 49 | * Really fix Zypper non-interactive installation by passing 50 | parameters in the right order (#68 by @jpdeplaix). 51 | 52 | 1.0.5 (2017-07-20): 53 | * Pass `--non-interactive` to zypper on OpenSUSE (#67 #62 by 54 | @yallop and @jpdeplaix) 55 | * Improve README to point to package descriptions (#65 by @dbuenzli) 56 | 57 | 1.0.4 (2017-03-30): 58 | * Fix build on FreeBSD (#61 by @sg2342) 59 | 60 | 1.0.3 (2017-03-08): 61 | * Vendor in cmdliner to remove the dependency on all external 62 | OCaml packages. This lets depext always be the first in the 63 | dependency order, including not needing ocamlfind or ocamlbuild. 64 | 65 | 1.0.2 (2016-08-11): 66 | * Fix uncaught exception on empty depexts 67 | 68 | 1.0.1 (2016-06-20): 69 | * Add support for `OPAMYES` and `OPAMVERBOSE` environment variables 70 | to force `-y` and `-v` respectively. 71 | 72 | 1.0.0 (2016-06-19): 73 | * Add support for `-y`, `-j ` and `-v` flags when used in 74 | conjunction with `opam depext -i`. These are passed through to 75 | the `opam install` command and allow non-interactive, parallel and 76 | verbose output to be activated in the OPAM source builds. This 77 | conveniently allows the most common flags to `opam install` to be 78 | used by an equivalent `opam depext -i` call. 79 | * Fix the debug printing when using `opam depext -d` to flush output 80 | more often and add newlines. 81 | * Add support for Oracle Linux via the `oraclelinux` tag. 82 | * Add support for Raspbian Linux via the `raspbian` tag (#41). 83 | * Add support for OpenSUSE via the `opensuse` tag. 84 | * Fix FreeBSD support. 85 | 86 | 0.9.1 (2016-02-22): 87 | * Do not assume that `bash` is installed for source depexts (#35). 88 | * Add support for Red Hat Enterprise Linux via `rhel` tag (#32). 89 | * Add multi-distro Docker-based Travis file. 90 | 91 | 0.9.0 (2016-01-04): 92 | * Add support for Alpine Linux. 93 | 94 | 0.8.1 (2015-08-03): 95 | * Repair OpenBSD depext support 96 | 97 | 0.8 (2015-07-27): 98 | * Detect and support opam 1.1.0 99 | * Revert unneeded #23 100 | 101 | 0.7 (2015-07-12): 102 | * Fix `os-release` detection by evaluating it through a shell rather 103 | than parsing the file directly. Repairs CentOS and RHEL detection. 104 | * Fix package detection on Ubuntu and Debian by doing a sequence of 105 | `dpkg` queries instead of a combined one. (#23 via Francois Berenger). 106 | 107 | 0.6 (2015-06-25): 108 | * Detect already installed packages and skip them 109 | * Better OS detection, use `os-release` 110 | * Added a `--dryrun` option 111 | 112 | 0.5 (2015-04-19): 113 | * Do not let `yum upgrade` go interactive. 114 | * Print commands before `sudo` so that they can be cut-and-pasted (#4). 115 | * Double-check the installation of multiple RPMs as the exit code 116 | can be unreliable (#9). 117 | * Add support for Gentoo and Arch Linux (#11). 118 | * Add Travis CI scripts. 119 | 120 | 0.4 (2015-03-22): 121 | * Add `-u` or `--update` flag to trigger an OS package set update 122 | before performing external dependency installation. This is useful 123 | on Debian or Ubuntu where package installation may fail if the 124 | sets are not up-to-date with respect to latest security updates. 125 | * Fix installation of source packages. 126 | * Detect the CentOS distribution correctly. 127 | * Fix external command detection to not go through a subshell. 128 | 129 | 0.3 (2015-01-27): 130 | * Add OCaml 3.12.1 compatibility. 131 | * Add `-i` flag to perform OPAM package installation after the 132 | external OS dependencies are installed. 133 | * Fixes for MacPorts and CentOS support. 134 | 135 | 0.2 (2015-01-21): 136 | * Initial public release. 137 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Opam-depext is distributed under the terms of the 2 | GNU Lesser General Public License (LGPL) version 2.1 (included below). 3 | 4 | As a special exception to the GNU Lesser General Public License, you may link, 5 | statically or dynamically, a "work that uses opam-depext" with a publicly distributed 6 | version of opam-depext to produce an executable file containing portions of opam-depext, and 7 | distribute that executable file under terms of your choice, without any of the 8 | additional requirements listed in clause 6 of the GNU Lesser General Public 9 | License. By "a publicly distributed version of opam-depext", we mean either the 10 | unmodified opam-depext as distributed by OCamlPro, or a modified version of the opam-depext 11 | that is distributed under the conditions defined in clause 2 of the GNU Lesser 12 | General Public License. This exception does not however invalidate any other 13 | reasons why the executable file might be covered by the GNU Lesser General 14 | Public License. 15 | 16 | ---------------------------------------------------------------------- 17 | 18 | GNU LESSER GENERAL PUBLIC LICENSE 19 | 20 | Version 2.1, February 1999 21 | 22 | Copyright (C) 1991, 1999 Free Software Foundation, Inc. 23 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 24 | Everyone is permitted to copy and distribute verbatim copies 25 | of this license document, but changing it is not allowed. 26 | 27 | [This is the first released version of the Lesser GPL. It also counts 28 | as the successor of the GNU Library Public License, version 2, hence 29 | the version number 2.1.] 30 | 31 | Preamble 32 | 33 | The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public Licenses are intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. 34 | 35 | This license, the Lesser General Public License, applies to some specially designated software packages--typically libraries--of the Free Software Foundation and other authors who decide to use it. You can use it too, but we suggest you first think carefully about whether this license or the ordinary General Public License is the better strategy to use in any particular case, based on the explanations below. 36 | 37 | When we speak of free software, we are referring to freedom of use, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish); that you receive source code or can get it if you want it; that you can change the software and use pieces of it in new free programs; and that you are informed that you can do these things. 38 | 39 | To protect your rights, we need to make restrictions that forbid distributors to deny you these rights or to ask you to surrender these rights. These restrictions translate to certain responsibilities for you if you distribute copies of the library or if you modify it. 40 | 41 | For example, if you distribute copies of the library, whether gratis or for a fee, you must give the recipients all the rights that we gave you. You must make sure that they, too, receive or can get the source code. If you link other code with the library, you must provide complete object files to the recipients, so that they can relink them with the library after making changes to the library and recompiling it. And you must show them these terms so they know their rights. 42 | 43 | We protect your rights with a two-step method: (1) we copyright the library, and (2) we offer you this license, which gives you legal permission to copy, distribute and/or modify the library. 44 | 45 | To protect each distributor, we want to make it very clear that there is no warranty for the free library. Also, if the library is modified by someone else and passed on, the recipients should know that what they have is not the original version, so that the original author's reputation will not be affected by problems that might be introduced by others. 46 | 47 | Finally, software patents pose a constant threat to the existence of any free program. We wish to make sure that a company cannot effectively restrict the users of a free program by obtaining a restrictive license from a patent holder. Therefore, we insist that any patent license obtained for a version of the library must be consistent with the full freedom of use specified in this license. 48 | 49 | Most GNU software, including some libraries, is covered by the ordinary GNU General Public License. This license, the GNU Lesser General Public License, applies to certain designated libraries, and is quite different from the ordinary General Public License. We use this license for certain libraries in order to permit linking those libraries into non-free programs. 50 | 51 | When a program is linked with a library, whether statically or using a shared library, the combination of the two is legally speaking a combined work, a derivative of the original library. The ordinary General Public License therefore permits such linking only if the entire combination fits its criteria of freedom. The Lesser General Public License permits more lax criteria for linking other code with the library. 52 | 53 | We call this license the "Lesser" General Public License because it does Less to protect the user's freedom than the ordinary General Public License. It also provides other free software developers Less of an advantage over competing non-free programs. These disadvantages are the reason we use the ordinary General Public License for many libraries. However, the Lesser license provides advantages in certain special circumstances. 54 | 55 | For example, on rare occasions, there may be a special need to encourage the widest possible use of a certain library, so that it becomes a de-facto standard. To achieve this, non-free programs must be allowed to use the library. A more frequent case is that a free library does the same job as widely used non-free libraries. In this case, there is little to gain by limiting the free library to free software only, so we use the Lesser General Public License. 56 | 57 | In other cases, permission to use a particular library in non-free programs enables a greater number of people to use a large body of free software. For example, permission to use the GNU C Library in non-free programs enables many more people to use the whole GNU operating system, as well as its variant, the GNU/Linux operating system. 58 | 59 | Although the Lesser General Public License is Less protective of the users' freedom, it does ensure that the user of a program that is linked with the Library has the freedom and the wherewithal to run that program using a modified version of the Library. 60 | 61 | The precise terms and conditions for copying, distribution and modification follow. Pay close attention to the difference between a "work based on the library" and a "work that uses the library". The former contains code derived from the library, whereas the latter must be combined with the library in order to run. 62 | 63 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 64 | 65 | 0. This License Agreement applies to any software library or other program which contains a notice placed by the copyright holder or other authorized party saying it may be distributed under the terms of this Lesser General Public License (also called "this License"). Each licensee is addressed as "you". 66 | 67 | A "library" means a collection of software functions and/or data prepared so as to be conveniently linked with application programs (which use some of those functions and data) to form executables. 68 | 69 | The "Library", below, refers to any such software library or work which has been distributed under these terms. A "work based on the Library" means either the Library or any derivative work under copyright law: that is to say, a work containing the Library or a portion of it, either verbatim or with modifications and/or translated straightforwardly into another language. (Hereinafter, translation is included without limitation in the term "modification".) 70 | 71 | "Source code" for a work means the preferred form of the work for making modifications to it. For a library, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the library. 72 | 73 | Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running a program using the Library is not restricted, and output from such a program is covered only if its contents constitute a work based on the Library (independent of the use of the Library in a tool for writing it). Whether that is true depends on what the Library does and what the program that uses the Library does. 74 | 75 | 1. You may copy and distribute verbatim copies of the Library's complete source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and distribute a copy of this License along with the Library. 76 | 77 | You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 78 | 79 | 2. You may modify your copy or copies of the Library or any portion of it, thus forming a work based on the Library, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: 80 | 81 | a) The modified work must itself be a software library. 82 | b) You must cause the files modified to carry prominent notices stating that you changed the files and the date of any change. 83 | c) You must cause the whole of the work to be licensed at no charge to all third parties under the terms of this License. 84 | d) If a facility in the modified Library refers to a function or a table of data to be supplied by an application program that uses the facility, other than as an argument passed when the facility is invoked, then you must make a good faith effort to ensure that, in the event an application does not supply such function or table, the facility still operates, and performs whatever part of its purpose remains meaningful. 85 | 86 | (For example, a function in a library to compute square roots has a purpose that is entirely well-defined independent of the application. Therefore, Subsection 2d requires that any application-supplied function or table used by this function must be optional: if the application does not supply it, the square root function must still compute square roots.) 87 | 88 | These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Library, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Library, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. 89 | 90 | Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Library. 91 | 92 | In addition, mere aggregation of another work not based on the Library with the Library (or with a work based on the Library) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 93 | 94 | 3. You may opt to apply the terms of the ordinary GNU General Public License instead of this License to a given copy of the Library. To do this, you must alter all the notices that refer to this License, so that they refer to the ordinary GNU General Public License, version 2, instead of to this License. (If a newer version than version 2 of the ordinary GNU General Public License has appeared, then you can specify that version instead if you wish.) Do not make any other change in these notices. 95 | 96 | Once this change is made in a given copy, it is irreversible for that copy, so the ordinary GNU General Public License applies to all subsequent copies and derivative works made from that copy. 97 | 98 | This option is useful when you wish to copy part of the code of the Library into a program that is not a library. 99 | 100 | 4. You may copy and distribute the Library (or a portion or derivative of it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange. 101 | 102 | If distribution of object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place satisfies the requirement to distribute the source code, even though third parties are not compelled to copy the source along with the object code. 103 | 104 | 5. A program that contains no derivative of any portion of the Library, but is designed to work with the Library by being compiled or linked with it, is called a "work that uses the Library". Such a work, in isolation, is not a derivative work of the Library, and therefore falls outside the scope of this License. 105 | 106 | However, linking a "work that uses the Library" with the Library creates an executable that is a derivative of the Library (because it contains portions of the Library), rather than a "work that uses the library". The executable is therefore covered by this License. Section 6 states terms for distribution of such executables. 107 | 108 | When a "work that uses the Library" uses material from a header file that is part of the Library, the object code for the work may be a derivative work of the Library even though the source code is not. Whether this is true is especially significant if the work can be linked without the Library, or if the work is itself a library. The threshold for this to be true is not precisely defined by law. 109 | 110 | If such an object file uses only numerical parameters, data structure layouts and accessors, and small macros and small inline functions (ten lines or less in length), then the use of the object file is unrestricted, regardless of whether it is legally a derivative work. (Executables containing this object code plus portions of the Library will still fall under Section 6.) 111 | 112 | Otherwise, if the work is a derivative of the Library, you may distribute the object code for the work under the terms of Section 6. Any executables containing that work also fall under Section 6, whether or not they are linked directly with the Library itself. 113 | 114 | 6. As an exception to the Sections above, you may also combine or link a "work that uses the Library" with the Library to produce a work containing portions of the Library, and distribute that work under terms of your choice, provided that the terms permit modification of the work for the customer's own use and reverse engineering for debugging such modifications. 115 | 116 | You must give prominent notice with each copy of the work that the Library is used in it and that the Library and its use are covered by this License. You must supply a copy of this License. If the work during execution displays copyright notices, you must include the copyright notice for the Library among them, as well as a reference directing the user to the copy of this License. Also, you must do one of these things: 117 | 118 | a) Accompany the work with the complete corresponding machine-readable source code for the Library including whatever changes were used in the work (which must be distributed under Sections 1 and 2 above); and, if the work is an executable linked with the Library, with the complete machine-readable "work that uses the Library", as object code and/or source code, so that the user can modify the Library and then relink to produce a modified executable containing the modified Library. (It is understood that the user who changes the contents of definitions files in the Library will not necessarily be able to recompile the application to use the modified definitions.) 119 | b) Use a suitable shared library mechanism for linking with the Library. A suitable mechanism is one that (1) uses at run time a copy of the library already present on the user's computer system, rather than copying library functions into the executable, and (2) will operate properly with a modified version of the library, if the user installs one, as long as the modified version is interface-compatible with the version that the work was made with. 120 | c) Accompany the work with a written offer, valid for at least three years, to give the same user the materials specified in Subsection 6a, above, for a charge no more than the cost of performing this distribution. 121 | d) If distribution of the work is made by offering access to copy from a designated place, offer equivalent access to copy the above specified materials from the same place. 122 | e) Verify that the user has already received a copy of these materials or that you have already sent this user a copy. 123 | 124 | For an executable, the required form of the "work that uses the Library" must include any data and utility programs needed for reproducing the executable from it. However, as a special exception, the materials to be distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. 125 | 126 | It may happen that this requirement contradicts the license restrictions of other proprietary libraries that do not normally accompany the operating system. Such a contradiction means you cannot use both them and the Library together in an executable that you distribute. 127 | 128 | 7. You may place library facilities that are a work based on the Library side-by-side in a single library together with other library facilities not covered by this License, and distribute such a combined library, provided that the separate distribution of the work based on the Library and of the other library facilities is otherwise permitted, and provided that you do these two things: 129 | 130 | a) Accompany the combined library with a copy of the same work based on the Library, uncombined with any other library facilities. This must be distributed under the terms of the Sections above. 131 | b) Give prominent notice with the combined library of the fact that part of it is a work based on the Library, and explaining where to find the accompanying uncombined form of the same work. 132 | 133 | 8. You may not copy, modify, sublicense, link with, or distribute the Library except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense, link with, or distribute the Library is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 134 | 135 | 9. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Library or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Library (or any work based on the Library), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Library or works based on it. 136 | 137 | 10. Each time you redistribute the Library (or any work based on the Library), the recipient automatically receives a license from the original licensor to copy, distribute, link with or modify the Library subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties with this License. 138 | 139 | 11. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Library at all. For example, if a patent license would not permit royalty-free redistribution of the Library by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Library. 140 | 141 | If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply, and the section as a whole is intended to apply in other circumstances. 142 | 143 | It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. 144 | 145 | This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 146 | 147 | 12. If the distribution and/or use of the Library is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Library under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 148 | 149 | 13. The Free Software Foundation may publish revised and/or new versions of the Lesser General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. 150 | 151 | Each version is given a distinguishing version number. If the Library specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Library does not specify a license version number, you may choose any version ever published by the Free Software Foundation. 152 | 153 | 14. If you wish to incorporate parts of the Library into other free programs whose distribution conditions are incompatible with these, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. 154 | 155 | NO WARRANTY 156 | 157 | 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 158 | 159 | 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 160 | END OF TERMS AND CONDITIONS 161 | 162 | How to Apply These Terms to Your New Libraries 163 | 164 | If you develop a new library, and you want it to be of the greatest possible use to the public, we recommend making it free software that everyone can redistribute and change. You can do so by permitting redistribution under these terms (or, alternatively, under the terms of the ordinary General Public License). 165 | 166 | To apply these terms, attach the following notices to the library. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. 167 | 168 | one line to give the library's name and an idea of what it does. 169 | Copyright (C) year name of author 170 | 171 | This library is free software; you can redistribute it and/or 172 | modify it under the terms of the GNU Lesser General Public 173 | License as published by the Free Software Foundation; either 174 | version 2.1 of the License, or (at your option) any later version. 175 | 176 | This library is distributed in the hope that it will be useful, 177 | but WITHOUT ANY WARRANTY; without even the implied warranty of 178 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 179 | Lesser General Public License for more details. 180 | 181 | You should have received a copy of the GNU Lesser General Public 182 | License along with this library; if not, write to the Free Software 183 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 184 | 185 | Also add information on how to contact you by electronic and paper mail. 186 | 187 | You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the library, if necessary. Here is a sample; alter the names: 188 | 189 | Yoyodyne, Inc., hereby disclaims all copyright interest in 190 | the library `Frob' (a library for tweaking knobs) written 191 | by James Random Hacker. 192 | 193 | signature of Ty Coon, 1 April 1990 194 | Ty Coon, President of Vice 195 | 196 | That's all there is to it! 197 | 198 | -------------------------------------------------- 199 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | all: shell/build.sh 2 | cd src_ext && $(MAKE) OCAMLOPT=no 3 | sh -ex shell/build.sh 4 | 5 | shell/build.sh: shell/build.ml 6 | ocaml $< byte > $@ 7 | chmod a+x $@ 8 | 9 | clean: 10 | rm -f opam-depext shell/build.sh *.cmi *.cma *.cmo *.cmx 11 | cd src_ext && $(MAKE) clean 12 | 13 | distclean: 14 | cd src_ext && $(MAKE) distclean 15 | 16 | install: 17 | opam-installer --prefix=$(PREFIX) 18 | 19 | distrib: 20 | cd src_ext && $(MAKE) archives 21 | -------------------------------------------------------------------------------- /OCamlMakefile: -------------------------------------------------------------------------------- 1 | ########################################################################### 2 | # OCamlMakefile 3 | # Copyright (C) 1999- Markus Mottl 4 | # 5 | # For updates see: 6 | # http://www.ocaml.info/home/ocaml_sources.html 7 | # 8 | ########################################################################### 9 | 10 | # Modified by damien for .glade.ml compilation 11 | 12 | # Set these variables to the names of the sources to be processed and 13 | # the result variable. Order matters during linkage! 14 | 15 | ifndef SOURCES 16 | SOURCES := foo.ml 17 | endif 18 | export SOURCES 19 | 20 | ifndef RES_CLIB_SUF 21 | RES_CLIB_SUF := _stubs 22 | endif 23 | export RES_CLIB_SUF 24 | 25 | ifndef RESULT 26 | RESULT := foo 27 | endif 28 | export RESULT := $(strip $(RESULT)) 29 | 30 | export LIB_PACK_NAME 31 | 32 | ifndef DOC_FILES 33 | DOC_FILES := $(filter %.mli, $(SOURCES)) 34 | endif 35 | export DOC_FILES 36 | FIRST_DOC_FILE := $(firstword $(DOC_FILES)) 37 | 38 | export BCSUFFIX 39 | export NCSUFFIX 40 | 41 | ifndef TOPSUFFIX 42 | TOPSUFFIX := .top 43 | endif 44 | export TOPSUFFIX 45 | 46 | # Eventually set include- and library-paths, libraries to link, 47 | # additional compilation-, link- and ocamlyacc-flags 48 | # Path- and library information needs not be written with "-I" and such... 49 | # Define THREADS if you need it, otherwise leave it unset (same for 50 | # USE_CAMLP4)! 51 | 52 | export THREADS 53 | export VMTHREADS 54 | export ANNOTATE 55 | export USE_CAMLP4 56 | 57 | export INCDIRS 58 | export LIBDIRS 59 | export EXTLIBDIRS 60 | export RESULTDEPS 61 | export OCAML_DEFAULT_DIRS 62 | 63 | export LIBS 64 | export CLIBS 65 | export CFRAMEWORKS 66 | 67 | export OCAMLFLAGS 68 | export OCAMLNCFLAGS 69 | export OCAMLBCFLAGS 70 | 71 | export OCAMLLDFLAGS 72 | export OCAMLNLDFLAGS 73 | export OCAMLBLDFLAGS 74 | 75 | export OCAMLMKLIB_FLAGS 76 | 77 | ifndef OCAMLCPFLAGS 78 | OCAMLCPFLAGS := a 79 | endif 80 | export OCAMLCPFLAGS 81 | 82 | ifndef DOC_DIR 83 | DOC_DIR := doc 84 | endif 85 | export DOC_DIR 86 | 87 | export PPFLAGS 88 | 89 | export LFLAGS 90 | export YFLAGS 91 | export IDLFLAGS 92 | 93 | export OCAMLDOCFLAGS 94 | 95 | export OCAMLFIND_INSTFLAGS 96 | 97 | export DVIPSFLAGS 98 | 99 | export STATIC 100 | 101 | # Add a list of optional trash files that should be deleted by "make clean" 102 | export TRASH 103 | 104 | ECHO := echo 105 | 106 | ifdef REALLY_QUIET 107 | export REALLY_QUIET 108 | ECHO := true 109 | LFLAGS := $(LFLAGS) -q 110 | YFLAGS := $(YFLAGS) -q 111 | endif 112 | 113 | #################### variables depending on your OCaml-installation 114 | 115 | SYSTEM := $(shell ocamlc -config 2>/dev/null | grep system | sed 's/system: //') 116 | # This may be 117 | # - mingw 118 | # - mingw64 119 | # - win32 120 | # - cygwin 121 | # - some other string means Unix 122 | # - empty means ocamlc does not support -config 123 | 124 | ifeq ($(SYSTEM),$(filter $(SYSTEM),mingw mingw64)) 125 | MINGW=1 126 | endif 127 | ifeq ($(SYSTEM),win32) 128 | MSVC=1 129 | endif 130 | 131 | ifdef MINGW 132 | export MINGW 133 | WIN32 := 1 134 | # The default value 'cc' makes 'ocamlc -cc "cc"' raises the error 'The 135 | # NTVDM CPU has encountered an illegal instruction'. 136 | ifndef CC 137 | MNO_CYGWIN := $(shell gcc -Wextra -v --help 2>/dev/null | grep -q '\-mno-cygwin'; echo $$?) 138 | CC := gcc 139 | else 140 | MNO_CYGWIN := $(shell $$CC -Wextra -v --help 2>/dev/null | grep -q '\-mno-cygwin'; echo $$?) 141 | endif 142 | # We are compiling with cygwin tools: 143 | ifeq ($(MNO_CYGWIN),0) 144 | CFLAGS_WIN32 := -mno-cygwin 145 | endif 146 | # The OCaml C header files use this flag: 147 | CFLAGS += -D__MINGW32__ 148 | endif 149 | ifdef MSVC 150 | export MSVC 151 | WIN32 := 1 152 | ifndef STATIC 153 | CPPFLAGS_WIN32 := -DCAML_DLL 154 | endif 155 | CFLAGS_WIN32 += -nologo 156 | EXT_OBJ := obj 157 | EXT_LIB := lib 158 | ifeq ($(CC),gcc) 159 | # work around GNU Make default value 160 | ifdef THREADS 161 | CC := cl -MT 162 | else 163 | CC := cl 164 | endif 165 | endif 166 | ifeq ($(CXX),g++) 167 | # work around GNU Make default value 168 | CXX := $(CC) 169 | endif 170 | CFLAG_O := -Fo 171 | endif 172 | ifdef WIN32 173 | EXT_CXX := cpp 174 | EXE := .exe 175 | endif 176 | 177 | ifndef EXT_OBJ 178 | EXT_OBJ := o 179 | endif 180 | ifndef EXT_LIB 181 | EXT_LIB := a 182 | endif 183 | ifndef EXT_CXX 184 | EXT_CXX := cc 185 | endif 186 | ifndef EXE 187 | EXE := # empty 188 | endif 189 | ifndef CFLAG_O 190 | CFLAG_O := -o # do not delete this comment (preserves trailing whitespace)! 191 | endif 192 | 193 | export CC 194 | export CXX 195 | export CFLAGS 196 | export CXXFLAGS 197 | export LDFLAGS 198 | export CPPFLAGS 199 | 200 | ifndef RPATH_FLAG 201 | ifdef ELF_RPATH_FLAG 202 | RPATH_FLAG := $(ELF_RPATH_FLAG) 203 | else 204 | RPATH_FLAG := -R 205 | endif 206 | endif 207 | export RPATH_FLAG 208 | 209 | ifndef MSVC 210 | ifndef PIC_CFLAGS 211 | PIC_CFLAGS := -fPIC 212 | endif 213 | ifndef PIC_CPPFLAGS 214 | PIC_CPPFLAGS := -DPIC 215 | endif 216 | endif 217 | 218 | export PIC_CFLAGS 219 | export PIC_CPPFLAGS 220 | 221 | BCRESULT := $(addsuffix $(BCSUFFIX), $(RESULT)) 222 | NCRESULT := $(addsuffix $(NCSUFFIX), $(RESULT)) 223 | TOPRESULT := $(addsuffix $(TOPSUFFIX), $(RESULT)) 224 | 225 | ifndef OCAMLFIND 226 | OCAMLFIND := ocamlfind 227 | endif 228 | export OCAMLFIND 229 | 230 | ifndef OCAML 231 | OCAML := ocaml 232 | endif 233 | export OCAML 234 | 235 | ifndef OCAMLC 236 | OCAMLC := ocamlc 237 | endif 238 | export OCAMLC 239 | 240 | ifndef OCAMLOPT 241 | OCAMLOPT := ocamlopt 242 | endif 243 | export OCAMLOPT 244 | 245 | ifndef OCAMLMKTOP 246 | OCAMLMKTOP := ocamlmktop 247 | endif 248 | export OCAMLMKTOP 249 | 250 | ifndef OCAMLCP 251 | OCAMLCP := ocamlcp 252 | endif 253 | export OCAMLCP 254 | 255 | ifndef OCAMLDEP 256 | OCAMLDEP := ocamldep 257 | endif 258 | export OCAMLDEP 259 | 260 | ifndef OCAMLLEX 261 | OCAMLLEX := ocamllex 262 | endif 263 | export OCAMLLEX 264 | 265 | ifndef OCAMLYACC 266 | OCAMLYACC := ocamlyacc 267 | endif 268 | export OCAMLYACC 269 | 270 | ifndef OCAMLMKLIB 271 | OCAMLMKLIB := ocamlmklib 272 | endif 273 | export OCAMLMKLIB 274 | 275 | ifndef OCAML_GLADECC 276 | OCAML_GLADECC := lablgladecc2 277 | endif 278 | export OCAML_GLADECC 279 | 280 | ifndef OCAML_GLADECC_FLAGS 281 | OCAML_GLADECC_FLAGS := 282 | endif 283 | export OCAML_GLADECC_FLAGS 284 | 285 | ifndef CAMELEON_REPORT 286 | CAMELEON_REPORT := report 287 | endif 288 | export CAMELEON_REPORT 289 | 290 | ifndef CAMELEON_REPORT_FLAGS 291 | CAMELEON_REPORT_FLAGS := 292 | endif 293 | export CAMELEON_REPORT_FLAGS 294 | 295 | ifndef CAMELEON_ZOGGY 296 | CAMELEON_ZOGGY := camlp4o pa_zog.cma pr_o.cmo 297 | endif 298 | export CAMELEON_ZOGGY 299 | 300 | ifndef CAMELEON_ZOGGY_FLAGS 301 | CAMELEON_ZOGGY_FLAGS := 302 | endif 303 | export CAMELEON_ZOGGY_FLAGS 304 | 305 | ifndef OXRIDL 306 | OXRIDL := oxridl 307 | endif 308 | export OXRIDL 309 | 310 | ifndef CAMLIDL 311 | CAMLIDL := camlidl 312 | endif 313 | export CAMLIDL 314 | 315 | ifndef CAMLIDLDLL 316 | CAMLIDLDLL := camlidldll 317 | endif 318 | export CAMLIDLDLL 319 | 320 | ifndef NOIDLHEADER 321 | MAYBE_IDL_HEADER := -header 322 | endif 323 | export NOIDLHEADER 324 | 325 | export NO_CUSTOM 326 | 327 | ifndef CAMLP4 328 | CAMLP4 := camlp4 329 | endif 330 | export CAMLP4 331 | 332 | ifndef REAL_OCAMLFIND 333 | ifdef PACKS 334 | ifndef CREATE_LIB 335 | ifdef THREADS 336 | PACKS += threads 337 | endif 338 | endif 339 | empty := 340 | space := $(empty) $(empty) 341 | comma := , 342 | ifdef PREDS 343 | PRE_OCAML_FIND_PREDICATES := $(subst $(space),$(comma),$(PREDS)) 344 | PRE_OCAML_FIND_PACKAGES := $(subst $(space),$(comma),$(PACKS)) 345 | OCAML_FIND_PREDICATES := -predicates $(PRE_OCAML_FIND_PREDICATES) 346 | # OCAML_DEP_PREDICATES := -syntax $(PRE_OCAML_FIND_PREDICATES) 347 | OCAML_FIND_PACKAGES := $(OCAML_FIND_PREDICATES) -package $(PRE_OCAML_FIND_PACKAGES) 348 | OCAML_DEP_PACKAGES := $(OCAML_DEP_PREDICATES) -package $(PRE_OCAML_FIND_PACKAGES) 349 | else 350 | OCAML_FIND_PACKAGES := -package $(subst $(space),$(comma),$(PACKS)) 351 | OCAML_DEP_PACKAGES := 352 | endif 353 | OCAML_FIND_LINKPKG := -linkpkg 354 | REAL_OCAMLFIND := $(OCAMLFIND) 355 | endif 356 | endif 357 | 358 | export OCAML_FIND_PACKAGES 359 | export OCAML_DEP_PACKAGES 360 | export OCAML_FIND_LINKPKG 361 | export REAL_OCAMLFIND 362 | 363 | ifndef OCAMLDOC 364 | OCAMLDOC := ocamldoc 365 | endif 366 | export OCAMLDOC 367 | 368 | ifndef LATEX 369 | LATEX := latex 370 | endif 371 | export LATEX 372 | 373 | ifndef DVIPS 374 | DVIPS := dvips 375 | endif 376 | export DVIPS 377 | 378 | ifndef PS2PDF 379 | PS2PDF := ps2pdf 380 | endif 381 | export PS2PDF 382 | 383 | ifndef OCAMLMAKEFILE 384 | OCAMLMAKEFILE := OCamlMakefile 385 | endif 386 | export OCAMLMAKEFILE 387 | 388 | ifndef OCAMLLIBPATH 389 | OCAMLLIBPATH := \ 390 | $(shell $(OCAMLC) 2>/dev/null -where || echo /usr/local/lib/ocaml) 391 | endif 392 | export OCAMLLIBPATH 393 | 394 | ifndef OCAML_LIB_INSTALL 395 | OCAML_LIB_INSTALL := $(OCAMLLIBPATH)/contrib 396 | endif 397 | export OCAML_LIB_INSTALL 398 | 399 | ########################################################################### 400 | 401 | #################### change following sections only if 402 | #################### you know what you are doing! 403 | 404 | # delete target files when a build command fails 405 | .PHONY: .DELETE_ON_ERROR 406 | .DELETE_ON_ERROR: 407 | 408 | # for pedants using "--warn-undefined-variables" 409 | export MAYBE_IDL 410 | export REAL_RESULT 411 | export CAMLIDLFLAGS 412 | export THREAD_FLAG 413 | export RES_CLIB 414 | export MAKEDLL 415 | export ANNOT_FLAG 416 | export C_OXRIDL 417 | export SUBPROJS 418 | export CFLAGS_WIN32 419 | export CPPFLAGS_WIN32 420 | 421 | INCFLAGS := 422 | 423 | SHELL := /bin/sh 424 | 425 | MLDEPDIR := ._d 426 | BCDIDIR := ._bcdi 427 | NCDIDIR := ._ncdi 428 | 429 | FILTER_EXTNS := %.mli %.ml %.mll %.mly %.idl %.oxridl %.c %.m %.$(EXT_CXX) %.rep %.zog %.glade 430 | 431 | FILTERED := $(filter $(FILTER_EXTNS), $(SOURCES)) 432 | SOURCE_DIRS := $(filter-out ./, $(sort $(dir $(FILTERED)))) 433 | 434 | FILTERED_REP := $(filter %.rep, $(FILTERED)) 435 | DEP_REP := $(FILTERED_REP:%.rep=$(MLDEPDIR)/%.d) 436 | AUTO_REP := $(FILTERED_REP:.rep=.ml) 437 | 438 | FILTERED_ZOG := $(filter %.zog, $(FILTERED)) 439 | DEP_ZOG := $(FILTERED_ZOG:%.zog=$(MLDEPDIR)/%.d) 440 | AUTO_ZOG := $(FILTERED_ZOG:.zog=.ml) 441 | 442 | FILTERED_GLADE := $(filter %.glade, $(FILTERED)) 443 | DEP_GLADE := $(FILTERED_GLADE:%.glade=$(MLDEPDIR)/%.d) 444 | AUTO_GLADE := $(FILTERED_GLADE:.glade=.ml) 445 | 446 | FILTERED_ML := $(filter %.ml, $(FILTERED)) 447 | DEP_ML := $(FILTERED_ML:%.ml=$(MLDEPDIR)/%.d) 448 | 449 | FILTERED_MLI := $(filter %.mli, $(FILTERED)) 450 | DEP_MLI := $(FILTERED_MLI:.mli=.di) 451 | 452 | FILTERED_MLL := $(filter %.mll, $(FILTERED)) 453 | DEP_MLL := $(FILTERED_MLL:%.mll=$(MLDEPDIR)/%.d) 454 | AUTO_MLL := $(FILTERED_MLL:.mll=.ml) 455 | 456 | FILTERED_MLY := $(filter %.mly, $(FILTERED)) 457 | DEP_MLY := $(FILTERED_MLY:%.mly=$(MLDEPDIR)/%.d) $(FILTERED_MLY:.mly=.di) 458 | AUTO_MLY := $(FILTERED_MLY:.mly=.mli) $(FILTERED_MLY:.mly=.ml) 459 | 460 | FILTERED_IDL := $(filter %.idl, $(FILTERED)) 461 | DEP_IDL := $(FILTERED_IDL:%.idl=$(MLDEPDIR)/%.d) $(FILTERED_IDL:.idl=.di) 462 | C_IDL := $(FILTERED_IDL:%.idl=%_stubs.c) 463 | ifndef NOIDLHEADER 464 | C_IDL += $(FILTERED_IDL:.idl=.h) 465 | endif 466 | OBJ_C_IDL := $(FILTERED_IDL:%.idl=%_stubs.$(EXT_OBJ)) 467 | AUTO_IDL := $(FILTERED_IDL:.idl=.mli) $(FILTERED_IDL:.idl=.ml) $(C_IDL) 468 | 469 | FILTERED_OXRIDL := $(filter %.oxridl, $(FILTERED)) 470 | DEP_OXRIDL := $(FILTERED_OXRIDL:%.oxridl=$(MLDEPDIR)/%.d) $(FILTERED_OXRIDL:.oxridl=.di) 471 | AUTO_OXRIDL := $(FILTERED_OXRIDL:.oxridl=.mli) $(FILTERED_OXRIDL:.oxridl=.ml) $(C_OXRIDL) 472 | 473 | FILTERED_C_CXX := $(filter %.c %.m %.$(EXT_CXX), $(FILTERED)) 474 | OBJ_C_CXX := $(FILTERED_C_CXX:.c=.$(EXT_OBJ)) 475 | OBJ_C_CXX := $(OBJ_C_CXX:.m=.$(EXT_OBJ)) 476 | OBJ_C_CXX := $(OBJ_C_CXX:.$(EXT_CXX)=.$(EXT_OBJ)) 477 | 478 | PRE_TARGETS += $(AUTO_MLL) $(AUTO_MLY) $(AUTO_IDL) $(AUTO_OXRIDL) $(AUTO_ZOG) $(AUTO_REP) $(AUTO_GLADE) 479 | 480 | ALL_DEPS := $(DEP_ML) $(DEP_MLI) $(DEP_MLL) $(DEP_MLY) $(DEP_IDL) $(DEP_OXRIDL) $(DEP_ZOG) $(DEP_REP) $(DEP_GLADE) 481 | 482 | MLDEPS := $(filter %.d, $(ALL_DEPS)) 483 | MLIDEPS := $(filter %.di, $(ALL_DEPS)) 484 | BCDEPIS := $(MLIDEPS:%.di=$(BCDIDIR)/%.di) 485 | NCDEPIS := $(MLIDEPS:%.di=$(NCDIDIR)/%.di) 486 | 487 | ALLML := $(filter %.mli %.ml %.mll %.mly %.idl %.oxridl %.rep %.zog %.glade, $(FILTERED)) 488 | 489 | IMPLO_INTF := $(ALLML:%.mli=%.mli.__) 490 | IMPLO_INTF := $(foreach file, $(IMPLO_INTF), \ 491 | $(basename $(file)).cmi $(basename $(file)).cmo) 492 | IMPLO_INTF := $(filter-out %.mli.cmo, $(IMPLO_INTF)) 493 | IMPLO_INTF := $(IMPLO_INTF:%.mli.cmi=%.cmi) 494 | 495 | IMPLX_INTF := $(IMPLO_INTF:.cmo=.cmx) 496 | 497 | INTF := $(filter %.cmi, $(IMPLO_INTF)) 498 | IMPL_CMO := $(filter %.cmo, $(IMPLO_INTF)) 499 | IMPL_CMX := $(IMPL_CMO:.cmo=.cmx) 500 | IMPL_ASM := $(IMPL_CMO:.cmo=.asm) 501 | IMPL_S := $(IMPL_CMO:.cmo=.s) 502 | 503 | OBJ_LINK := $(OBJ_C_IDL) $(OBJ_C_CXX) 504 | OBJ_FILES := $(IMPL_CMO:.cmo=.$(EXT_OBJ)) $(OBJ_LINK) 505 | 506 | EXECS := $(addsuffix $(EXE), \ 507 | $(sort $(TOPRESULT) $(BCRESULT) $(NCRESULT))) 508 | ifdef WIN32 509 | EXECS += $(BCRESULT).dll $(NCRESULT).dll 510 | endif 511 | 512 | CLIB_BASE := $(RESULT)$(RES_CLIB_SUF) 513 | ifneq ($(strip $(OBJ_LINK)),) 514 | RES_CLIB := lib$(CLIB_BASE).$(EXT_LIB) 515 | endif 516 | 517 | ifdef WIN32 518 | DLLSONAME := dll$(CLIB_BASE).dll 519 | else 520 | DLLSONAME := dll$(CLIB_BASE).so 521 | endif 522 | 523 | NONEXECS := $(INTF) $(IMPL_CMO) $(IMPL_CMX) $(IMPL_ASM) $(IMPL_S) \ 524 | $(OBJ_FILES) $(PRE_TARGETS) $(BCRESULT).cma $(NCRESULT).cmxa \ 525 | $(NCRESULT).$(EXT_LIB) $(BCRESULT).cmi $(BCRESULT).cmti $(BCRESULT).cmo \ 526 | $(NCRESULT).cmi $(NCRESULT).cmti $(NCRESULT).cmx $(NCRESULT).$(EXT_OBJ) \ 527 | $(RES_CLIB) $(IMPL_CMO:.cmo=.cmt) $(IMPL_CMO:.cmo=.cmti) \ 528 | $(LIB_PACK_NAME).cmi $(LIB_PACK_NAME).cmo $(LIB_PACK_NAME).cmx \ 529 | $(LIB_PACK_NAME).$(EXT_OBJ) 530 | 531 | ifndef STATIC 532 | NONEXECS += $(DLLSONAME) 533 | endif 534 | 535 | ifndef LIBINSTALL_FILES 536 | LIBINSTALL_FILES := $(RESULT).mli $(RESULT).cmi $(RESULT).cma \ 537 | $(RESULT).cmxa $(RESULT).$(EXT_LIB) $(RES_CLIB) 538 | ifndef STATIC 539 | ifneq ($(strip $(OBJ_LINK)),) 540 | LIBINSTALL_FILES += $(DLLSONAME) 541 | endif 542 | endif 543 | endif 544 | 545 | export LIBINSTALL_FILES 546 | 547 | ifdef WIN32 548 | # some extra stuff is created while linking DLLs 549 | NONEXECS += $(BCRESULT).$(EXT_LIB) $(BCRESULT).exp $(NCRESULT).exp $(CLIB_BASE).exp $(CLIB_BASE).lib 550 | endif 551 | 552 | TARGETS := $(EXECS) $(NONEXECS) 553 | 554 | # If there are IDL-files 555 | ifneq ($(strip $(FILTERED_IDL)),) 556 | MAYBE_IDL := -cclib -lcamlidl 557 | endif 558 | 559 | ifdef USE_CAMLP4 560 | CAMLP4PATH := \ 561 | $(shell $(CAMLP4) -where 2>/dev/null || echo /usr/local/lib/camlp4) 562 | INCFLAGS := -I $(CAMLP4PATH) 563 | CINCFLAGS := -I$(CAMLP4PATH) 564 | endif 565 | 566 | INCFLAGS := $(INCFLAGS) $(INCDIRS:%=-I %) $(SOURCE_DIRS:%=-I %) $(OCAML_DEFAULT_DIRS:%=-I %) 567 | CINCFLAGS += $(SOURCE_DIRS:%=-I%) $(INCDIRS:%=-I%) $(OCAML_DEFAULT_DIRS:%=-I%) 568 | 569 | ifndef MSVC 570 | CLIBFLAGS += $(SOURCE_DIRS:%=-L%) $(LIBDIRS:%=-L%) \ 571 | $(EXTLIBDIRS:%=-L%) $(OCAML_DEFAULT_DIRS:%=-L%) 572 | 573 | ifeq ($(ELF_RPATH), yes) 574 | CLIBFLAGS += $(EXTLIBDIRS:%=-Wl,$(RPATH_FLAG)%) 575 | endif 576 | endif 577 | 578 | ifndef PROFILING 579 | INTF_OCAMLC := $(OCAMLC) 580 | else 581 | ifndef THREADS 582 | INTF_OCAMLC := $(OCAMLCP) -p $(OCAMLCPFLAGS) 583 | else 584 | # OCaml does not support profiling byte code 585 | # with threads (yet), therefore we force an error. 586 | ifndef REAL_OCAMLC 587 | $(error Profiling of multithreaded byte code not yet supported by OCaml) 588 | endif 589 | INTF_OCAMLC := $(OCAMLC) 590 | endif 591 | endif 592 | 593 | ifndef MSVC 594 | COMMON_LDFLAGS := $(LDFLAGS:%=-ccopt %) $(SOURCE_DIRS:%=-ccopt -L%) \ 595 | $(LIBDIRS:%=-ccopt -L%) $(EXTLIBDIRS:%=-ccopt -L%) \ 596 | $(EXTLIBDIRS:%=-ccopt -Wl $(OCAML_DEFAULT_DIRS:%=-ccopt -L%)) 597 | 598 | ifeq ($(ELF_RPATH),yes) 599 | COMMON_LDFLAGS += $(EXTLIBDIRS:%=-ccopt -Wl,$(RPATH_FLAG)%) 600 | endif 601 | else 602 | COMMON_LDFLAGS := -ccopt "/link -NODEFAULTLIB:LIBC $(LDFLAGS:%=%) $(SOURCE_DIRS:%=-LIBPATH:%) \ 603 | $(LIBDIRS:%=-LIBPATH:%) $(EXTLIBDIRS:%=-LIBPATH:%) \ 604 | $(OCAML_DEFAULT_DIRS:%=-LIBPATH:%) " 605 | endif 606 | 607 | CLIBS_OPTS := $(CLIBS:%=-cclib -l%) $(CFRAMEWORKS:%=-cclib '-framework %') 608 | ifdef MSVC 609 | ifndef STATIC 610 | # MSVC libraries do not have 'lib' prefix 611 | CLIBS_OPTS := $(CLIBS:%=-cclib %.lib) 612 | endif 613 | endif 614 | 615 | ifneq ($(strip $(OBJ_LINK)),) 616 | ifdef CREATE_LIB 617 | OBJS_LIBS := -cclib -l$(CLIB_BASE) $(CLIBS_OPTS) $(MAYBE_IDL) 618 | else 619 | OBJS_LIBS := $(OBJ_LINK) $(CLIBS_OPTS) $(MAYBE_IDL) 620 | endif 621 | else 622 | OBJS_LIBS := $(CLIBS_OPTS) $(MAYBE_IDL) 623 | endif 624 | 625 | ifdef LIB_PACK_NAME 626 | FOR_PACK_NAME := $(shell echo $(LIB_PACK_NAME) | awk '{print toupper(substr($$0,1,1))substr($$0,2)}') 627 | endif 628 | 629 | # If we have to make byte-code 630 | ifndef REAL_OCAMLC 631 | BYTE_OCAML := y 632 | 633 | # EXTRADEPS is added dependencies we have to insert for all 634 | # executable files we generate. Ideally it should be all of the 635 | # libraries we use, but it's hard to find the ones that get searched on 636 | # the path since I don't know the paths built into the compiler, so 637 | # just include the ones with slashes in their names. 638 | EXTRADEPS := $(addsuffix .cma,$(foreach i,$(LIBS),$(if $(findstring /,$(i)),$(i)))) 639 | 640 | 641 | ifndef LIB_PACK_NAME 642 | SPECIAL_OCAMLFLAGS := $(OCAMLBCFLAGS) 643 | else 644 | SPECIAL_OCAMLFLAGS := -for-pack $(FOR_PACK_NAME) $(OCAMLBCFLAGS) 645 | endif 646 | 647 | REAL_OCAMLC := $(INTF_OCAMLC) 648 | 649 | REAL_IMPL := $(IMPL_CMO) 650 | REAL_IMPL_INTF := $(IMPLO_INTF) 651 | IMPL_SUF := .cmo 652 | 653 | DEPFLAGS := 654 | MAKE_DEPS := $(MLDEPS) $(BCDEPIS) 655 | 656 | ifdef CREATE_LIB 657 | override CFLAGS := $(PIC_CFLAGS) $(CFLAGS) 658 | override CPPFLAGS := $(PIC_CPPFLAGS) $(CPPFLAGS) 659 | ifndef STATIC 660 | ifneq ($(strip $(OBJ_LINK)),) 661 | MAKEDLL := $(DLLSONAME) 662 | ALL_LDFLAGS := -dllib $(DLLSONAME) 663 | endif 664 | endif 665 | endif 666 | 667 | ifndef NO_CUSTOM 668 | ifneq "$(strip $(OBJ_LINK) $(THREADS) $(MAYBE_IDL) $(CLIBS) $(CFRAMEWORKS))" "" 669 | ALL_LDFLAGS += -custom 670 | endif 671 | endif 672 | 673 | ALL_LDFLAGS += $(INCFLAGS) $(OCAMLLDFLAGS) $(OCAMLBLDFLAGS) \ 674 | $(COMMON_LDFLAGS) $(LIBS:%=%.cma) 675 | CAMLIDLDLLFLAGS := 676 | 677 | ifdef THREADS 678 | ifdef VMTHREADS 679 | THREAD_FLAG := -vmthread 680 | else 681 | THREAD_FLAG := -thread 682 | endif 683 | ALL_LDFLAGS := $(THREAD_FLAG) $(ALL_LDFLAGS) 684 | ifndef CREATE_LIB 685 | ifndef REAL_OCAMLFIND 686 | ALL_LDFLAGS := unix.cma threads.cma $(ALL_LDFLAGS) 687 | endif 688 | endif 689 | endif 690 | 691 | # we have to make native-code 692 | else 693 | EXTRADEPS := $(addsuffix .cmxa,$(foreach i,$(LIBS),$(if $(findstring /,$(i)),$(i)))) 694 | ifndef PROFILING 695 | SPECIAL_OCAMLFLAGS := $(OCAMLNCFLAGS) 696 | PLDFLAGS := 697 | else 698 | SPECIAL_OCAMLFLAGS := -p $(OCAMLNCFLAGS) 699 | PLDFLAGS := -p 700 | endif 701 | 702 | ifndef LIB_PACK_NAME 703 | SPECIAL_OCAMLFLAGS := $(OCAMLNCFLAGS) 704 | else 705 | SPECIAL_OCAMLFLAGS := -for-pack $(FOR_PACK_NAME) $(OCAMLNCFLAGS) 706 | endif 707 | REAL_IMPL := $(IMPL_CMX) 708 | REAL_IMPL_INTF := $(IMPLX_INTF) 709 | IMPL_SUF := .cmx 710 | 711 | override CPPFLAGS := -DNATIVE_CODE $(CPPFLAGS) 712 | 713 | DEPFLAGS := -native 714 | MAKE_DEPS := $(MLDEPS) $(NCDEPIS) 715 | 716 | ALL_LDFLAGS := $(PLDFLAGS) $(INCFLAGS) $(OCAMLLDFLAGS) \ 717 | $(OCAMLNLDFLAGS) $(COMMON_LDFLAGS) 718 | CAMLIDLDLLFLAGS := -opt 719 | 720 | ifndef CREATE_LIB 721 | ALL_LDFLAGS += $(LIBS:%=%.cmxa) 722 | else 723 | override CFLAGS := $(PIC_CFLAGS) $(CFLAGS) 724 | override CPPFLAGS := $(PIC_CPPFLAGS) $(CPPFLAGS) 725 | endif 726 | 727 | ifdef THREADS 728 | THREAD_FLAG := -thread 729 | ALL_LDFLAGS := $(THREAD_FLAG) $(ALL_LDFLAGS) 730 | ifndef CREATE_LIB 731 | ifndef REAL_OCAMLFIND 732 | ALL_LDFLAGS := unix.cmxa threads.cmxa $(ALL_LDFLAGS) 733 | endif 734 | endif 735 | endif 736 | endif 737 | 738 | export MAKE_DEPS 739 | 740 | ifdef ANNOTATE 741 | ANNOT_FLAG := -annot 742 | else 743 | endif 744 | 745 | ALL_OCAMLCFLAGS := $(THREAD_FLAG) $(ANNOT_FLAG) $(OCAMLFLAGS) \ 746 | $(INCFLAGS) $(SPECIAL_OCAMLFLAGS) 747 | 748 | ifdef make_deps 749 | -include $(MAKE_DEPS) 750 | PRE_TARGETS := 751 | endif 752 | 753 | ########################################################################### 754 | # USER RULES 755 | 756 | # Call "OCamlMakefile QUIET=" to get rid of all of the @'s. 757 | QUIET=@ 758 | 759 | # generates byte-code (default) 760 | byte-code: $(PRE_TARGETS) 761 | $(QUIET)$(MAKE) -r -f $(OCAMLMAKEFILE) $(BCRESULT) \ 762 | REAL_RESULT="$(BCRESULT)" make_deps=yes 763 | bc: byte-code 764 | 765 | byte-code-nolink: $(PRE_TARGETS) 766 | $(QUIET)$(MAKE) -r -f $(OCAMLMAKEFILE) nolink \ 767 | REAL_RESULT="$(BCRESULT)" make_deps=yes 768 | bcnl: byte-code-nolink 769 | 770 | top: $(PRE_TARGETS) 771 | $(QUIET)$(MAKE) -r -f $(OCAMLMAKEFILE) $(TOPRESULT) \ 772 | REAL_RESULT="$(BCRESULT)" make_deps=yes 773 | 774 | # generates native-code 775 | 776 | native-code: $(PRE_TARGETS) 777 | $(QUIET)$(MAKE) -r -f $(OCAMLMAKEFILE) $(NCRESULT) \ 778 | REAL_RESULT="$(NCRESULT)" \ 779 | REAL_OCAMLC="$(OCAMLOPT)" \ 780 | make_deps=yes 781 | nc: native-code 782 | 783 | native-code-nolink: $(PRE_TARGETS) 784 | $(QUIET)$(MAKE) -r -f $(OCAMLMAKEFILE) nolink \ 785 | REAL_RESULT="$(NCRESULT)" \ 786 | REAL_OCAMLC="$(OCAMLOPT)" \ 787 | make_deps=yes 788 | ncnl: native-code-nolink 789 | 790 | # generates byte-code libraries 791 | byte-code-library: $(PRE_TARGETS) 792 | $(QUIET)$(MAKE) -r -f $(OCAMLMAKEFILE) \ 793 | $(RES_CLIB) $(BCRESULT).cma \ 794 | REAL_RESULT="$(BCRESULT)" \ 795 | CREATE_LIB=yes \ 796 | make_deps=yes 797 | bcl: byte-code-library 798 | 799 | # generates native-code libraries 800 | native-code-library: $(PRE_TARGETS) 801 | $(QUIET)$(MAKE) -r -f $(OCAMLMAKEFILE) \ 802 | $(RES_CLIB) $(NCRESULT).cmxa \ 803 | REAL_RESULT="$(NCRESULT)" \ 804 | REAL_OCAMLC="$(OCAMLOPT)" \ 805 | CREATE_LIB=yes \ 806 | make_deps=yes 807 | ncl: native-code-library 808 | 809 | ifdef WIN32 810 | # generates byte-code dll 811 | byte-code-dll: $(PRE_TARGETS) 812 | $(QUIET)$(MAKE) -r -f $(OCAMLMAKEFILE) \ 813 | $(RES_CLIB) $(BCRESULT).dll \ 814 | REAL_RESULT="$(BCRESULT)" \ 815 | make_deps=yes 816 | bcd: byte-code-dll 817 | 818 | # generates native-code dll 819 | native-code-dll: $(PRE_TARGETS) 820 | $(QUIET)$(MAKE) -r -f $(OCAMLMAKEFILE) \ 821 | $(RES_CLIB) $(NCRESULT).dll \ 822 | REAL_RESULT="$(NCRESULT)" \ 823 | REAL_OCAMLC="$(OCAMLOPT)" \ 824 | make_deps=yes 825 | ncd: native-code-dll 826 | endif 827 | 828 | # generates byte-code with debugging information 829 | debug-code: $(PRE_TARGETS) 830 | $(QUIET)$(MAKE) -r -f $(OCAMLMAKEFILE) $(BCRESULT) \ 831 | REAL_RESULT="$(BCRESULT)" make_deps=yes \ 832 | OCAMLFLAGS="-g $(OCAMLFLAGS)" \ 833 | OCAMLLDFLAGS="-g $(OCAMLLDFLAGS)" 834 | dc: debug-code 835 | 836 | debug-code-nolink: $(PRE_TARGETS) 837 | $(QUIET)$(MAKE) -r -f $(OCAMLMAKEFILE) nolink \ 838 | REAL_RESULT="$(BCRESULT)" make_deps=yes \ 839 | OCAMLFLAGS="-g $(OCAMLFLAGS)" \ 840 | OCAMLLDFLAGS="-g $(OCAMLLDFLAGS)" 841 | dcnl: debug-code-nolink 842 | 843 | # generates byte-code with debugging information (native code) 844 | debug-native-code: $(PRE_TARGETS) 845 | $(QUIET)$(MAKE) -r -f $(OCAMLMAKEFILE) $(NCRESULT) \ 846 | REAL_RESULT="$(NCRESULT)" make_deps=yes \ 847 | REAL_OCAMLC="$(OCAMLOPT)" \ 848 | OCAMLFLAGS="-g $(OCAMLFLAGS)" \ 849 | OCAMLLDFLAGS="-g $(OCAMLLDFLAGS)" 850 | dnc: debug-native-code 851 | 852 | debug-native-code-nolink: $(PRE_TARGETS) 853 | $(QUIET)$(MAKE) -r -f $(OCAMLMAKEFILE) nolink \ 854 | REAL_RESULT="$(NCRESULT)" make_deps=yes \ 855 | REAL_OCAMLC="$(OCAMLOPT)" \ 856 | OCAMLFLAGS="-g $(OCAMLFLAGS)" \ 857 | OCAMLLDFLAGS="-g $(OCAMLLDFLAGS)" 858 | dncnl: debug-native-code-nolink 859 | 860 | # generates byte-code libraries with debugging information 861 | debug-code-library: $(PRE_TARGETS) 862 | $(QUIET)$(MAKE) -r -f $(OCAMLMAKEFILE) \ 863 | $(RES_CLIB) $(BCRESULT).cma \ 864 | REAL_RESULT="$(BCRESULT)" make_deps=yes \ 865 | CREATE_LIB=yes \ 866 | OCAMLFLAGS="-g $(OCAMLFLAGS)" \ 867 | OCAMLLDFLAGS="-g $(OCAMLLDFLAGS)" 868 | dcl: debug-code-library 869 | 870 | # generates byte-code libraries with debugging information (native code) 871 | debug-native-code-library: $(PRE_TARGETS) 872 | $(QUIET)$(MAKE) -r -f $(OCAMLMAKEFILE) \ 873 | $(RES_CLIB) $(NCRESULT).cmxa \ 874 | REAL_RESULT="$(NCRESULT)" make_deps=yes \ 875 | REAL_OCAMLC="$(OCAMLOPT)" \ 876 | CREATE_LIB=yes \ 877 | OCAMLFLAGS="-g $(OCAMLFLAGS)" \ 878 | OCAMLLDFLAGS="-g $(OCAMLLDFLAGS)" 879 | dncl: debug-native-code-library 880 | 881 | # generates byte-code for profiling 882 | profiling-byte-code: $(PRE_TARGETS) 883 | $(QUIET)$(MAKE) -r -f $(OCAMLMAKEFILE) $(BCRESULT) \ 884 | REAL_RESULT="$(BCRESULT)" PROFILING="y" \ 885 | make_deps=yes 886 | pbc: profiling-byte-code 887 | 888 | # generates native-code 889 | 890 | profiling-native-code: $(PRE_TARGETS) 891 | $(QUIET)$(MAKE) -r -f $(OCAMLMAKEFILE) $(NCRESULT) \ 892 | REAL_RESULT="$(NCRESULT)" \ 893 | REAL_OCAMLC="$(OCAMLOPT)" \ 894 | PROFILING="y" \ 895 | make_deps=yes 896 | pnc: profiling-native-code 897 | 898 | # generates byte-code libraries 899 | profiling-byte-code-library: $(PRE_TARGETS) 900 | $(QUIET)$(MAKE) -r -f $(OCAMLMAKEFILE) \ 901 | $(RES_CLIB) $(BCRESULT).cma \ 902 | REAL_RESULT="$(BCRESULT)" PROFILING="y" \ 903 | CREATE_LIB=yes \ 904 | make_deps=yes 905 | pbcl: profiling-byte-code-library 906 | 907 | # generates native-code libraries 908 | profiling-native-code-library: $(PRE_TARGETS) 909 | $(QUIET)$(MAKE) -r -f $(OCAMLMAKEFILE) \ 910 | $(RES_CLIB) $(NCRESULT).cmxa \ 911 | REAL_RESULT="$(NCRESULT)" PROFILING="y" \ 912 | REAL_OCAMLC="$(OCAMLOPT)" \ 913 | CREATE_LIB=yes \ 914 | make_deps=yes 915 | pncl: profiling-native-code-library 916 | 917 | # packs byte-code objects 918 | pack-byte-code: $(PRE_TARGETS) 919 | $(QUIET)$(MAKE) -r -f $(OCAMLMAKEFILE) $(BCRESULT).cmo \ 920 | REAL_RESULT="$(BCRESULT)" \ 921 | PACK_LIB=yes make_deps=yes 922 | pabc: pack-byte-code 923 | 924 | # packs native-code objects 925 | pack-native-code: $(PRE_TARGETS) 926 | $(QUIET)$(MAKE) -r -f $(OCAMLMAKEFILE) \ 927 | $(NCRESULT).cmx $(NCRESULT).$(EXT_OBJ) \ 928 | REAL_RESULT="$(NCRESULT)" \ 929 | REAL_OCAMLC="$(OCAMLOPT)" \ 930 | PACK_LIB=yes make_deps=yes 931 | panc: pack-native-code 932 | 933 | # generates HTML-documentation 934 | htdoc: $(DOC_DIR)/$(RESULT)/html/index.html 935 | 936 | # generates Latex-documentation 937 | ladoc: $(DOC_DIR)/$(RESULT)/latex/doc.tex 938 | 939 | # generates PostScript-documentation 940 | psdoc: $(DOC_DIR)/$(RESULT)/latex/doc.ps 941 | 942 | # generates PDF-documentation 943 | pdfdoc: $(DOC_DIR)/$(RESULT)/latex/doc.pdf 944 | 945 | # generates all supported forms of documentation 946 | doc: htdoc ladoc psdoc pdfdoc 947 | 948 | ########################################################################### 949 | # LOW LEVEL RULES 950 | 951 | $(REAL_RESULT): $(REAL_IMPL_INTF) $(OBJ_LINK) $(EXTRADEPS) $(RESULTDEPS) 952 | $(REAL_OCAMLFIND) $(REAL_OCAMLC) \ 953 | $(OCAML_FIND_PACKAGES) $(OCAML_FIND_LINKPKG) \ 954 | $(OBJS_LIBS) $(ALL_LDFLAGS) -o $@$(EXE) \ 955 | $(REAL_IMPL) 956 | 957 | nolink: $(REAL_IMPL_INTF) $(OBJ_LINK) 958 | 959 | ifdef WIN32 960 | $(REAL_RESULT).dll: $(REAL_IMPL_INTF) $(OBJ_LINK) 961 | $(CAMLIDLDLL) $(CAMLIDLDLLFLAGS) $(OBJ_LINK) $(CLIBS) \ 962 | -o $@ $(REAL_IMPL) 963 | endif 964 | 965 | %$(TOPSUFFIX): $(REAL_IMPL_INTF) $(OBJ_LINK) $(EXTRADEPS) 966 | $(REAL_OCAMLFIND) $(OCAMLMKTOP) \ 967 | $(OCAML_FIND_PACKAGES) $(OCAML_FIND_LINKPKG) \ 968 | $(OBJS_LIBS) $(ALL_LDFLAGS) -o $@$(EXE) \ 969 | $(REAL_IMPL) 970 | 971 | .SUFFIXES: .mli .ml .cmi .cmo .cmx .cma .cmxa .$(EXT_OBJ) \ 972 | .mly .di .d .$(EXT_LIB) .idl %.oxridl .c .m .$(EXT_CXX) .h .so \ 973 | .rep .zog .glade 974 | 975 | ifndef STATIC 976 | ifdef MINGW 977 | # From OCaml 3.11.0, ocamlmklib is available on windows 978 | OCAMLMLIB_EXISTS = $(shell which $(OCAMLMKLIB)) 979 | ifeq ($(strip $(OCAMLMLIB_EXISTS)),) 980 | $(DLLSONAME): $(OBJ_LINK) 981 | $(CC) $(CFLAGS) $(CFLAGS_WIN32) $(OBJ_LINK) -shared -o $@ \ 982 | $(wildcard $(foreach dir,$(LIBDIRS),$(CLIBS:%=$(dir)/lib%.a))) \ 983 | '$(OCAMLLIBPATH)/ocamlrun.a' \ 984 | -Wl,--whole-archive \ 985 | -Wl,--export-all-symbols \ 986 | -Wl,--allow-multiple-definition \ 987 | -Wl,--enable-auto-import 988 | else 989 | $(DLLSONAME): $(OBJ_LINK) 990 | $(OCAMLMKLIB) $(INCFLAGS) $(CLIBFLAGS) \ 991 | -o $(CLIB_BASE) $(OBJ_LINK) $(CLIBS:%=-l%) \ 992 | $(CFRAMEWORKS:%=-framework %) \ 993 | $(OCAMLMKLIB_FLAGS) 994 | endif 995 | else 996 | ifdef MSVC 997 | $(DLLSONAME): $(OBJ_LINK) 998 | link /NOLOGO /DLL /OUT:$@ $(OBJ_LINK) \ 999 | $(wildcard $(foreach dir,$(LIBDIRS),$(CLIBS:%=$(dir)/%.lib))) \ 1000 | '$(OCAMLLIBPATH)/ocamlrun.lib' 1001 | 1002 | else 1003 | $(DLLSONAME): $(OBJ_LINK) 1004 | $(OCAMLMKLIB) $(INCFLAGS) $(CLIBFLAGS) \ 1005 | -o $(CLIB_BASE) $(OBJ_LINK) $(CLIBS:%=-l%) $(CFRAMEWORKS:%=-framework %) \ 1006 | $(OCAMLMKLIB_FLAGS) 1007 | endif 1008 | endif 1009 | endif 1010 | 1011 | ifndef LIB_PACK_NAME 1012 | $(RESULT).cma: $(REAL_IMPL_INTF) $(MAKEDLL) $(EXTRADEPS) $(RESULTDEPS) 1013 | $(REAL_OCAMLFIND) $(REAL_OCAMLC) -a $(OBJS_LIBS) $(ALL_LDFLAGS) -o $@ $(REAL_IMPL) 1014 | 1015 | $(RESULT).cmxa $(RESULT).$(EXT_LIB): $(REAL_IMPL_INTF) $(EXTRADEPS) $(RESULTDEPS) 1016 | $(REAL_OCAMLFIND) $(OCAMLOPT) -a $(OBJS_LIBS) $(ALL_LDFLAGS) -o $@ $(REAL_IMPL) 1017 | else 1018 | # Packing a bytecode library 1019 | LIB_PACK_NAME_MLI = $(wildcard $(LIB_PACK_NAME).mli) 1020 | ifeq ($(LIB_PACK_NAME_MLI),) 1021 | LIB_PACK_NAME_CMI = $(LIB_PACK_NAME).cmi 1022 | else 1023 | # $(LIB_PACK_NAME).mli exists, it likely depends on other compiled interfaces 1024 | LIB_PACK_NAME_CMI = 1025 | $(LIB_PACK_NAME).cmi: $(REAL_IMPL_INTF) 1026 | endif 1027 | ifdef BYTE_OCAML 1028 | $(LIB_PACK_NAME_CMI) $(LIB_PACK_NAME).cmo: $(REAL_IMPL_INTF) 1029 | $(REAL_OCAMLFIND) $(REAL_OCAMLC) -pack -o $(LIB_PACK_NAME).cmo $(OCAMLLDFLAGS) $(REAL_IMPL) 1030 | # Packing into a unit which can be transformed into a library 1031 | # Remember the .ml's must have been compiled with -for-pack $(LIB_PACK_NAME) 1032 | else 1033 | $(LIB_PACK_NAME_CMI) $(LIB_PACK_NAME).cmx: $(REAL_IMPL_INTF) 1034 | $(REAL_OCAMLFIND) $(OCAMLOPT) -pack -o $(LIB_PACK_NAME).cmx $(OCAMLLDFLAGS) $(REAL_IMPL) 1035 | endif 1036 | 1037 | $(RESULT).cma: $(LIB_PACK_NAME).cmi $(LIB_PACK_NAME).cmo $(MAKEDLL) $(EXTRADEPS) $(RESULTDEPS) 1038 | $(REAL_OCAMLFIND) $(REAL_OCAMLC) -a $(OBJS_LIBS) $(ALL_LDFLAGS) -o $@ $(LIB_PACK_NAME).cmo 1039 | 1040 | $(RESULT).cmxa $(RESULT).$(EXT_LIB): $(LIB_PACK_NAME).cmi $(LIB_PACK_NAME).cmx $(EXTRADEPS) $(RESULTDEPS) 1041 | $(REAL_OCAMLFIND) $(OCAMLOPT) -a $(OBJS_LIBS) $(filter-out -custom, $(ALL_LDFLAGS)) -o $@ $(LIB_PACK_NAME).cmx 1042 | endif 1043 | 1044 | $(RES_CLIB): $(OBJ_LINK) 1045 | ifndef MSVC 1046 | ifneq ($(strip $(OBJ_LINK)),) 1047 | $(AR) rcs $@ $(OBJ_LINK) 1048 | endif 1049 | else 1050 | ifneq ($(strip $(OBJ_LINK)),) 1051 | lib -nologo -debugtype:cv -out:$(RES_CLIB) $(OBJ_LINK) 1052 | endif 1053 | endif 1054 | 1055 | %.cmi: %.mli 1056 | $(QUIET)pp=`sed -n -e '/^#/d' -e 's/(\*pp \([^*]*\) \*)/\1/p;q' $<`; \ 1057 | if [ -z "$$pp" ]; then \ 1058 | $(ECHO) $(REAL_OCAMLFIND) $(INTF_OCAMLC) $(OCAML_FIND_PACKAGES) \ 1059 | -c $(THREAD_FLAG) $(ANNOT_FLAG) \ 1060 | $(OCAMLFLAGS) $(INCFLAGS) $<; \ 1061 | $(REAL_OCAMLFIND) $(INTF_OCAMLC) $(OCAML_FIND_PACKAGES) \ 1062 | -c $(THREAD_FLAG) $(ANNOT_FLAG) \ 1063 | $(OCAMLFLAGS) $(INCFLAGS) $<; \ 1064 | else \ 1065 | $(ECHO) $(REAL_OCAMLFIND) $(INTF_OCAMLC) $(OCAML_FIND_PACKAGES) \ 1066 | -c -pp \"$$pp $(PPFLAGS)\" $(THREAD_FLAG) $(ANNOT_FLAG) \ 1067 | $(OCAMLFLAGS) $(INCFLAGS) $<; \ 1068 | $(REAL_OCAMLFIND) $(INTF_OCAMLC) $(OCAML_FIND_PACKAGES) \ 1069 | -c -pp "$$pp $(PPFLAGS)" $(THREAD_FLAG) $(ANNOT_FLAG) \ 1070 | $(OCAMLFLAGS) $(INCFLAGS) $<; \ 1071 | fi 1072 | 1073 | %.cmi: %$(IMPL_SUF); 1074 | 1075 | %$(IMPL_SUF) %.$(EXT_OBJ): %.ml 1076 | $(QUIET)pp=`sed -n -e '/^#/d' -e 's/(\*pp \([^*]*\) \*)/\1/p;q' $<`; \ 1077 | if [ -z "$$pp" ]; then \ 1078 | $(ECHO) $(REAL_OCAMLFIND) $(REAL_OCAMLC) $(OCAML_FIND_PACKAGES) \ 1079 | -c $(ALL_OCAMLCFLAGS) $<; \ 1080 | $(REAL_OCAMLFIND) $(REAL_OCAMLC) $(OCAML_FIND_PACKAGES) \ 1081 | -c $(ALL_OCAMLCFLAGS) $<; \ 1082 | else \ 1083 | $(ECHO) $(REAL_OCAMLFIND) $(REAL_OCAMLC) $(OCAML_FIND_PACKAGES) \ 1084 | -c -pp \"$$pp $(PPFLAGS)\" $(ALL_OCAMLCFLAGS) $<; \ 1085 | $(REAL_OCAMLFIND) $(REAL_OCAMLC) $(OCAML_FIND_PACKAGES) \ 1086 | -c -pp "$$pp $(PPFLAGS)" $(ALL_OCAMLCFLAGS) $<; \ 1087 | fi 1088 | 1089 | .PRECIOUS: %.ml 1090 | %.ml: %.mll 1091 | $(OCAMLLEX) $(LFLAGS) $< 1092 | 1093 | .PRECIOUS: %.ml %.mli 1094 | %.ml %.mli: %.mly 1095 | $(OCAMLYACC) $(YFLAGS) $< 1096 | $(QUIET)pp=`sed -n -e 's/.*(\*pp \([^*]*\) \*).*/\1/p;q' $<`; \ 1097 | if [ ! -z "$$pp" ]; then \ 1098 | mv $*.ml $*.ml.temporary; \ 1099 | echo "(*pp $$pp $(PPFLAGS)*)" > $*.ml; \ 1100 | cat $*.ml.temporary >> $*.ml; \ 1101 | rm $*.ml.temporary; \ 1102 | mv $*.mli $*.mli.temporary; \ 1103 | echo "(*pp $$pp $(PPFLAGS)*)" > $*.mli; \ 1104 | cat $*.mli.temporary >> $*.mli; \ 1105 | rm $*.mli.temporary; \ 1106 | fi 1107 | 1108 | 1109 | .PRECIOUS: %.ml 1110 | %.ml: %.rep 1111 | $(CAMELEON_REPORT) $(CAMELEON_REPORT_FLAGS) -gen $< 1112 | 1113 | .PRECIOUS: %.ml 1114 | %.ml: %.zog 1115 | $(CAMELEON_ZOGGY) $(CAMELEON_ZOGGY_FLAGS) -impl $< > $@ 1116 | 1117 | .PRECIOUS: %.ml 1118 | %.ml: %.glade 1119 | $(OCAML_GLADECC) $(OCAML_GLADECC_FLAGS) $< > $@ 1120 | 1121 | .PRECIOUS: %.ml %.mli 1122 | %.ml %.mli: %.oxridl 1123 | $(OXRIDL) $< 1124 | 1125 | .PRECIOUS: %.ml %.mli %_stubs.c %.h 1126 | %.ml %.mli %_stubs.c %.h: %.idl 1127 | $(CAMLIDL) $(MAYBE_IDL_HEADER) $(IDLFLAGS) \ 1128 | $(CAMLIDLFLAGS) $< 1129 | $(QUIET)if [ $(NOIDLHEADER) ]; then touch $*.h; fi 1130 | 1131 | %.$(EXT_OBJ): %.c 1132 | $(OCAMLC) -c -cc "$(CC)" -ccopt "$(CFLAGS) \ 1133 | $(CPPFLAGS) $(CPPFLAGS_WIN32) \ 1134 | $(CFLAGS_WIN32) $(CINCFLAGS) $(CFLAG_O)$@ " $< 1135 | 1136 | %.$(EXT_OBJ): %.m 1137 | $(CC) -c $(CFLAGS) $(CINCFLAGS) $(CPPFLAGS) \ 1138 | -I'$(OCAMLLIBPATH)' \ 1139 | $< $(CFLAG_O)$@ 1140 | 1141 | %.$(EXT_OBJ): %.$(EXT_CXX) 1142 | $(CXX) -c $(CXXFLAGS) $(CINCFLAGS) $(CPPFLAGS) \ 1143 | -I'$(OCAMLLIBPATH)' \ 1144 | $< $(CFLAG_O)$@ 1145 | 1146 | $(MLDEPDIR)/%.d: %.ml 1147 | $(QUIET)if [ ! -d $(@D) ]; then mkdir -p $(@D); fi 1148 | $(QUIET)pp=`sed -n -e '/^#/d' -e 's/(\*pp \([^*]*\) \*)/\1/p;q' $<`; \ 1149 | if [ -z "$$pp" ]; then \ 1150 | $(ECHO) $(REAL_OCAMLFIND) $(OCAMLDEP) $(OCAML_DEP_PACKAGES) \ 1151 | $(INCFLAGS) $< \> $@; \ 1152 | $(REAL_OCAMLFIND) $(OCAMLDEP) $(OCAML_DEP_PACKAGES) \ 1153 | $(INCFLAGS) $< > $@; \ 1154 | else \ 1155 | $(ECHO) $(REAL_OCAMLFIND) $(OCAMLDEP) $(OCAML_DEP_PACKAGES) \ 1156 | -pp \"$$pp $(PPFLAGS)\" $(INCFLAGS) $< \> $@; \ 1157 | $(REAL_OCAMLFIND) $(OCAMLDEP) $(OCAML_DEP_PACKAGES) \ 1158 | -pp "$$pp $(PPFLAGS)" $(INCFLAGS) $< > $@; \ 1159 | fi 1160 | 1161 | $(BCDIDIR)/%.di $(NCDIDIR)/%.di: %.mli 1162 | $(QUIET)if [ ! -d $(@D) ]; then mkdir -p $(@D); fi 1163 | $(QUIET)pp=`sed -n -e '/^#/d' -e 's/(\*pp \([^*]*\) \*)/\1/p;q' $<`; \ 1164 | if [ -z "$$pp" ]; then \ 1165 | $(ECHO) $(REAL_OCAMLFIND) $(OCAMLDEP) $(DEPFLAGS) $(INCFLAGS) $< \> $@; \ 1166 | $(REAL_OCAMLFIND) $(OCAMLDEP) $(DEPFLAGS) $(INCFLAGS) $< > $@; \ 1167 | else \ 1168 | $(ECHO) $(REAL_OCAMLFIND) $(OCAMLDEP) $(DEPFLAGS) \ 1169 | -pp \"$$pp $(PPFLAGS)\" $(INCFLAGS) $< \> $@; \ 1170 | $(REAL_OCAMLFIND) $(OCAMLDEP) $(DEPFLAGS) \ 1171 | -pp "$$pp $(PPFLAGS)" $(INCFLAGS) $< > $@; \ 1172 | fi 1173 | 1174 | $(DOC_DIR)/$(RESULT)/html: 1175 | mkdir -p $@ 1176 | 1177 | $(DOC_DIR)/$(RESULT)/html/index.html: $(DOC_DIR)/$(RESULT)/html $(DOC_FILES) 1178 | rm -rf $ 45 | -------------------------------------------------------------------------------- /depext.ml: -------------------------------------------------------------------------------- 1 | (* misc functions *) 2 | 3 | let debug = ref false 4 | 5 | let cli_2_0 = 6 | try Sys.getenv "OPAMCLI" = "2.0" 7 | with Not_found -> false 8 | 9 | let lines_of_channel ic = 10 | let rec aux acc = 11 | let line = try Some (input_line ic) with End_of_file -> None in 12 | match line with 13 | | Some s -> aux (s::acc) 14 | | None -> acc 15 | in 16 | List.rev (aux []) 17 | 18 | exception Fatal_error of string * int 19 | 20 | let fatal_error ?(exit_code=1) fmt = 21 | Printf.ksprintf (fun s -> raise (Fatal_error (s, exit_code))) fmt 22 | 23 | let lines_of_command c = 24 | if !debug then Printf.eprintf "+ %s\n%!" c; 25 | let ic = Unix.open_process_in c in 26 | let lines = lines_of_channel ic in 27 | match Unix.close_process_in ic with 28 | | Unix.WEXITED 0 -> lines 29 | | Unix.WEXITED 127 -> 30 | fatal_error "Command not found: %s" c 31 | | Unix.WEXITED i -> 32 | fatal_error ~exit_code:i "Command failed: %s returned %d" c i 33 | | Unix.WSIGNALED i -> 34 | fatal_error "Command failed: %s signal %d" c i 35 | | Unix.WSTOPPED i -> 36 | fatal_error "Command failed: %s stopped %d" c i 37 | 38 | let lines_of_file f = 39 | let ic = open_in f in 40 | let lines = lines_of_channel ic in 41 | close_in ic; 42 | lines 43 | 44 | let command_output c = 45 | match List.filter (fun s -> String.trim s <> "") (lines_of_command c) with 46 | | [s] -> s 47 | | _ -> fatal_error "Output of command too long: %S" c 48 | 49 | let string_split char str = 50 | let rec aux pos = 51 | try 52 | let i = String.index_from str pos char in 53 | String.sub str pos (i - pos) :: aux (succ i) 54 | with Not_found | Invalid_argument _ -> 55 | let l = String.length str in 56 | [ String.sub str pos (l - pos) ] 57 | in 58 | aux 0 59 | 60 | let filter_map f = 61 | let rec loop acc = function 62 | | [] -> List.rev acc 63 | | x :: l -> 64 | match f x with 65 | | None -> loop acc l 66 | | Some x -> loop (x::acc) l 67 | in loop [] 68 | 69 | let has_command c = 70 | let cmd = Printf.sprintf "command -v %s >/dev/null" c in 71 | try Sys.command cmd = 0 with Sys_error _ -> false 72 | 73 | let run_command ?(no_stderr=false) c = 74 | let c = if no_stderr then c @ ["2>/dev/null"] else c in 75 | let c = String.concat " " c in 76 | if !debug then Printf.eprintf "+ %s\n%!" c; 77 | Unix.system c 78 | 79 | let ask ?(default=false) fmt = 80 | Printf.ksprintf (fun s -> 81 | Printf.printf "%s [%s] %!" s (if default then "Y/n" else "y/N"); 82 | try match read_line () with 83 | | "y" | "Y" | "yes" | "Yes" | "yEs" | "yeS" | "YEs" | "yES" | "YeS" | "YES" -> true 84 | | "n" | "N" | "no" | "nO" | "No" | "NO" -> false 85 | | _ -> default 86 | with End_of_file -> false) 87 | fmt 88 | 89 | (* version *) 90 | 91 | let opam_version = lazy ( 92 | command_output "opam --version" 93 | ) 94 | 95 | (* system detection *) 96 | 97 | let has_prefix s pfx = 98 | let pfxlen = String.length pfx in 99 | pfxlen <= String.length s && 100 | try for i = 0 to pfxlen do 101 | if pfx.[i] <> s.[i] then raise Exit 102 | done; 103 | true 104 | with Exit -> false 105 | 106 | let is_opam_2_0 = 107 | let is = lazy (let v = Lazy.force opam_version in 108 | String.length v >= 4 && String.sub (Lazy.force opam_version) 0 4 = "2.0.") in 109 | fun () -> Lazy.force is 110 | 111 | let run_opam f fmt = 112 | let execute command = 113 | let opam = 114 | if is_opam_2_0 () then 115 | "opam " 116 | else 117 | "opam --cli=2.1 " 118 | in 119 | f (opam ^ command ^ " --color=never") 120 | in 121 | Printf.ksprintf execute fmt 122 | 123 | let lines_of_opam fmt = run_opam lines_of_command fmt 124 | 125 | let opam_output fmt = run_opam command_output fmt 126 | 127 | let run_opam ?(via=run_command ?no_stderr:None) args = 128 | let args = 129 | if is_opam_2_0 () then 130 | "opam" :: args 131 | else 132 | "opam" :: "--cli=2.1" :: args 133 | in 134 | via args 135 | 136 | let opam_query_global var = 137 | let opt = 138 | if is_opam_2_0 () then "" else " --global" 139 | in 140 | opam_output "var %s --readonly%s" var opt 141 | 142 | let arch = opam_query_global "arch" 143 | let os = opam_query_global "os" 144 | let distribution = opam_query_global "os-distribution" 145 | let family = opam_query_global "os-family" 146 | 147 | let opam_vars = [ 148 | "arch", arch; 149 | "os", os; 150 | "os-distribution", distribution; 151 | "os-family", family; 152 | ] 153 | 154 | (* processing *) 155 | 156 | let depexts ~with_tests ~with_docs opam_packages = 157 | let opam_version = Lazy.force opam_version in 158 | let recent_enough_opam = 159 | let newer_beta5 s = s = "" || s.[0] <> '~' || s >= "~beta5" in 160 | Scanf.sscanf opam_version "%d.%d.%d%s" 161 | (fun a b c s -> a = 2 && (b > 0 || c > 0 || newer_beta5 s) || a > 2) 162 | in 163 | if not recent_enough_opam then 164 | fatal_error 165 | "This version of opam-depext requires opam 2.0.0~beta5 or higher"; 166 | let s = lines_of_opam "list --readonly %s%s--external%s" 167 | (if with_tests then "--with-test " else "") 168 | (if with_docs then "--with-doc " else "") 169 | (match opam_packages with 170 | | [] -> "" 171 | | ps -> " " ^ Filename.quote ("--resolve=" ^ String.concat "," ps)) 172 | in 173 | let lines = List.filter (fun s -> String.length s > 0 && s.[0] <> '#') s in 174 | List.flatten (List.map (string_split ' ') lines) 175 | 176 | let install_packages_commands ~interactive packages = 177 | let yes ?(no=[]) yes r = 178 | if not interactive then yes @ r else no @ r 179 | in 180 | match family with 181 | | "homebrew" -> 182 | ["brew"::"install"::packages] 183 | | "macports" -> 184 | ["port"::"install"::packages] 185 | | "debian" -> 186 | ["apt-get"::"install"::yes ["-qq"; "-yy"] packages] 187 | | "rhel" | "centos" | "fedora" | "mageia" | "oraclelinux" | "ol" -> 188 | (* todo: check if they all declare "rhel" as primary family *) 189 | (* When opem-packages specify the epel-release package, usually it 190 | means that other dependencies require the EPEL repository to be 191 | already setup when yum-install is called. Cf. #70, #76. *) 192 | let epel_release = "epel-release" in 193 | let install_epel = 194 | try [ 195 | "yum"::"install"::yes ["-y"] [List.find ((=) epel_release) packages]; 196 | ] with _ -> [] in 197 | install_epel @ 198 | ["yum"::"install"::yes ["-y"] (List.filter ((<>) epel_release) packages); 199 | "rpm"::"-q"::"--whatprovides"::packages] 200 | | "bsd" -> 201 | if distribution = "freebsd" then ["pkg"::"install"::yes ["-y"] packages] 202 | else if distribution = "openbsd" then ["pkg_add"::yes ~no:["-i"] ["-I"] packages] 203 | else ["pkgin"::yes ["-y"] ("install"::packages)] 204 | | "archlinux" | "arch" -> 205 | ["pacman"::"-Su"::yes ["--noconfirm"] packages] 206 | | "gentoo" -> 207 | ["emerge"::yes ~no:["-a"] [] packages] 208 | | "alpine" -> 209 | ["apk"::"add"::yes ~no:["-i"] [] packages] 210 | | "suse" | "opensuse" -> 211 | ["zypper"::yes ["--non-interactive"] ("install"::packages)] 212 | | s -> 213 | fatal_error "Sorry, don't know how to install packages on your %s system" s 214 | 215 | let update_command = 216 | match family with 217 | | "debian" -> 218 | ["apt-get";"update"] 219 | | "homebrew" -> 220 | ["brew"; "update"] 221 | | "rhel" | "centos" | "fedora" | "mageia" | "oraclelinux" | "ol" -> 222 | ["yum"; "makecache"] 223 | | "archlinux" | "arch" -> 224 | ["pacman"; "-Sy"] 225 | | "gentoo" -> 226 | ["emerge"; "-u"] 227 | | "alpine" -> 228 | ["apk"; "update"] 229 | | "suse" | "opensuse" -> 230 | ["zypper"; "--non-interactive"; "update"] 231 | | _ -> ["echo"; "Skipping system update on this platform."] 232 | 233 | exception Signaled_or_stopped of string list * Unix.process_status 234 | 235 | module StringMap = Map.Make(String) 236 | 237 | (* filter 'packages' to retain only the installed ones *) 238 | let get_installed_packages (packages: string list): string list = 239 | match family with 240 | | "homebrew" -> 241 | let lines = try lines_of_command "brew list" with _ -> [] in 242 | let installed = List.flatten (List.map (string_split ' ') lines) in 243 | List.filter (fun p -> List.mem p packages) installed 244 | | "suse" | "opensuse" -> 245 | let lines = try lines_of_command "zypper --quiet se -i -t package|grep '^i '|awk -F'|' '{print $2}'|xargs echo" with _ -> [] in 246 | let installed = List.flatten (List.map (string_split ' ') lines) in 247 | List.filter (fun p -> List.mem p packages) installed 248 | | "debian" -> 249 | (* First query regular package *) 250 | let cmd = 251 | (* ${db:Status-Status} would give only the column we're interested in, but 252 | it's quite new in dpkg-query. *) 253 | String.concat " " 254 | ("dpkg-query -W -f '${Package} ${Status}\\n'" :: packages 255 | @ ["2>/dev/null"]) 256 | in 257 | let lines = try lines_of_command cmd with _ -> [] in 258 | let installed = 259 | List.fold_left 260 | (fun acc l -> match string_split ' ' l with 261 | | [pkg;_;_;"installed"] -> pkg :: acc 262 | | _ -> acc) 263 | [] lines in 264 | if List.length installed = List.length packages then installed else 265 | (* If package are missing look for virtual package. *) 266 | let missing = 267 | (* quadratic should not be a problem... *) 268 | List.filter (fun x -> not (List.mem x installed)) packages in 269 | let resolve_virtual name = 270 | let cmd = 271 | Printf.sprintf "apt-cache --names-only search '^%s$' 2>/dev/null" name in 272 | let lines = try lines_of_command cmd with _ -> [] in 273 | List.fold_left 274 | (fun acc l -> match string_split ' ' l with 275 | | pkg :: _ -> pkg :: acc 276 | | [] -> acc) 277 | [] lines in 278 | let virtual_map = 279 | List.fold_left 280 | (fun acc vpkg -> 281 | List.fold_left 282 | (fun acc pkg -> 283 | let old = try StringMap.find pkg acc with Not_found -> [] in 284 | StringMap.add pkg (vpkg :: old) acc) 285 | acc (resolve_virtual vpkg)) 286 | StringMap.empty missing in 287 | let real_packages = List.map fst (StringMap.bindings virtual_map) in 288 | let cmd = 289 | (* ${db:Status-Status} would give only the column we're interested in, but 290 | it's quite new in dpkg-query. *) 291 | String.concat " " 292 | ("dpkg-query -W -f '${Package} ${Status}\\n'" :: real_packages 293 | @ ["2>/dev/null"]) 294 | in 295 | let lines = try lines_of_command cmd with _ -> [] in 296 | List.fold_left 297 | (fun acc l -> match string_split ' ' l with 298 | | [pkg;_;_;"installed"] -> (try StringMap.find pkg virtual_map @ acc with Not_found -> acc) 299 | | _ -> acc) 300 | installed lines 301 | | "amzn" | "centos" | "fedora" | "mageia" | "archlinux" | "arch" | "gentoo" | "alpine" | "rhel" | "oraclelinux" | "ol" -> 302 | let query_command_prefix = match distribution with 303 | | "amzn" | "centos" | "fedora" | "mageia" | "rhel" | "oraclelinux" | "ol" -> ["rpm"; "-qi"] 304 | | "archlinux" | "arch" -> ["pacman"; "-Q"] 305 | | "gentoo" -> ["equery"; "list"] 306 | | "alpine" -> ["apk"; "info"; "-e"] 307 | | _ -> fatal_error "Distribution %s is not supported" distribution 308 | in 309 | List.filter 310 | (fun pkg_name -> 311 | let cmd = query_command_prefix @ [pkg_name] in 312 | match run_command ~no_stderr:true cmd with 313 | | Unix.WEXITED 0 -> true (* installed *) 314 | | Unix.WEXITED 1 -> false (* not installed *) 315 | | exit_status -> raise (Signaled_or_stopped (cmd, exit_status)) 316 | ) packages 317 | | "bsd" -> 318 | (match distribution with 319 | | "freebsd" -> 320 | let installed = try lines_of_command "pkg query %n" with _ -> [] in 321 | List.filter (fun p -> List.mem p packages) installed 322 | | "openbsd" -> 323 | let installed = try lines_of_command "pkg_info -mqP" with _ -> [] in 324 | List.filter (fun p -> List.mem p packages) installed 325 | | _ -> []) 326 | | "macports" -> [] 327 | | _ -> [] 328 | 329 | let sudo_run_command ~su ~interactive cmd = 330 | let cmd = 331 | match os, distribution with 332 | | "openbsd", _ -> 333 | if Unix.getuid () <> 0 then ( 334 | Printf.printf 335 | "The following command needs to be run through %S:\n %s\n%!" 336 | "doas" (String.concat " " cmd); 337 | if interactive && not (ask ~default:true "Allow ?") then 338 | exit 1; 339 | "doas"::cmd 340 | ) else cmd 341 | | ("linux" | "unix" | "freebsd" | "netbsd" | "dragonfly"), _ 342 | | "macos", "macports" -> 343 | (* not sure about this list *) 344 | if Unix.getuid () <> 0 then ( 345 | Printf.printf 346 | "The following command needs to be run through %S:\n %s\n%!" 347 | (if su then "su" else "sudo") (String.concat " " cmd); 348 | if interactive && not (ask ~default:true "Allow ?") then 349 | exit 1; 350 | if su then 351 | ["su"; "root"; "-c"; Printf.sprintf "%S" (String.concat " " cmd)] 352 | else 353 | "sudo"::cmd 354 | ) else cmd 355 | | _ -> cmd 356 | in 357 | run_command cmd 358 | 359 | let update ~su ~interactive = 360 | match sudo_run_command ~su ~interactive update_command with 361 | | Unix.WEXITED 0 -> 362 | Printf.eprintf "# OS package update successful\n%!" 363 | | _ -> fatal_error "OS package update failed" 364 | 365 | let install ~su ~interactive = function 366 | | [] -> () 367 | | os_packages -> 368 | let cmds = 369 | install_packages_commands ~interactive os_packages 370 | in 371 | let is_success r = (r = Unix.WEXITED 0) in 372 | let ok = 373 | List.fold_left (fun ok cmd -> 374 | ok && 375 | is_success (sudo_run_command ~su ~interactive cmd)) 376 | true cmds 377 | in 378 | if ok then Printf.eprintf "# OS packages installation successful\n%!" 379 | else fatal_error "OS package installation failed" 380 | 381 | 382 | (* Command-line handling *) 383 | 384 | let checkenv var opt = 385 | let v = try Unix.getenv var with _ -> "" in 386 | match v with 387 | |"true"|"1"|"yes"|"y" -> true 388 | |"false"|"0"|"no"|"n" -> false 389 | |_ -> opt 390 | 391 | let exec_opam = 392 | let via args = 393 | if !debug then Printf.eprintf "+ %s\n%!" (String.concat " " args); 394 | Unix.execvp "opam" (Array.of_list args) 395 | in 396 | run_opam ~via 397 | 398 | let main print_flags list short 399 | debug_arg install_arg update_arg dryrun_arg 400 | with_tests_arg with_docs_arg 401 | su_arg interactive_arg opam_args opam_packages = 402 | let with_tests_arg = checkenv "OPAMWITHTEST" with_tests_arg in 403 | let with_docs_arg = checkenv "OPAMWITHDOC" with_docs_arg in 404 | if debug_arg then debug := true; 405 | if not (is_opam_2_0 () || cli_2_0) then 406 | Printf.eprintf 407 | "Since version 2.1, opam now handles external dependencies alongside OCaml ones, \ 408 | and the `depext` plugin interface is provided for backwards compatibility only. \ 409 | Consider using your usual `opam install` command to install both OCaml and \ 410 | system dependencies, or `opam install --depext-only` if you want to only \ 411 | install external dependencies.\n"; 412 | if print_flags then 413 | (if short then 414 | List.iter (fun (v,x) -> Printf.eprintf "%s=%s\n" v x) opam_vars 415 | else 416 | Printf.eprintf "# Depexts vars detected on this system: %s\n%!" 417 | (String.concat ", " (List.map (fun (v,x) -> v^"="^x) opam_vars)); 418 | exit 0); 419 | if not short then 420 | Printf.eprintf "# Detecting depexts using vars: %s\n%!" 421 | (String.concat ", " (List.map (fun (v,x) -> v^"="^x) opam_vars)); 422 | let os_packages = 423 | depexts ~with_tests:with_tests_arg ~with_docs:with_docs_arg opam_packages 424 | in 425 | if os_packages <> [] && not short then 426 | begin 427 | prerr_endline "# The following system packages are needed:"; 428 | Printf.printf "%s\n%!" (String.concat "\n" os_packages) 429 | end 430 | else if list && not short then 431 | prerr_endline "# No required system packages found"; 432 | if list then exit 0; 433 | if os_packages = [] && not short then 434 | Printf.eprintf "# No extra OS packages requirements found.\n%!"; 435 | let interactive = match interactive_arg with 436 | | Some i -> i 437 | | None -> not (List.mem "--yes" opam_args) && Unix.isatty Unix.stdin 438 | in 439 | if not (is_opam_2_0 ()) then 440 | let opam_run_args = 441 | (if interactive then [] else ["--confirm-level=unsafe-yes"]) 442 | @ (if dryrun_arg then ["--dry-run"] else []) 443 | in 444 | let opam_install_args = 445 | opam_args 446 | @ (if with_tests_arg then ["--with-test"] else []) 447 | @ (if with_docs_arg then ["--with-doc"] else []) 448 | @ opam_run_args 449 | in 450 | (let opam_packages = 451 | let toreinstall = 452 | let pending = 453 | filter_map (fun nv -> 454 | match string_split '.' nv with 455 | | n::_ -> Some n 456 | | _ -> None) (lines_of_opam "reinstall --list-pending") 457 | in 458 | let pin = lines_of_opam ("pin list --short") in 459 | List.filter (fun p -> not (List.mem p pin)) pending 460 | in 461 | opam_packages @ toreinstall 462 | in 463 | if opam_packages <> [] then 464 | (if update_arg then 465 | (match run_opam ("update" :: "--depexts" :: opam_run_args) with 466 | | Unix.WEXITED 0 -> 467 | Printf.eprintf "# OS package update successful\n%!" 468 | | _ -> fatal_error "OS package update failed"); 469 | let opam_cmdline = 470 | let opam_install = 471 | "install" :: opam_packages @ opam_install_args 472 | in 473 | if install_arg then opam_install else 474 | if interactive && 475 | not (ask ~default:true "Allow installing depexts via opam ?") then 476 | exit 1 477 | else 478 | opam_install @ ["--depext-only"] 479 | in 480 | ignore (exec_opam opam_cmdline))) 481 | else 482 | (let installed = get_installed_packages os_packages in 483 | let os_packages = 484 | List.filter (fun p -> not (List.mem p installed)) os_packages 485 | in 486 | if short then List.iter print_endline os_packages 487 | else if installed <> [] then 488 | if os_packages <> [] then 489 | Printf.eprintf 490 | "# The following new OS packages need to be installed: %s\n%!" 491 | (String.concat " " os_packages) 492 | else 493 | Printf.eprintf 494 | "# All required OS packages found.\n%!"; 495 | if dryrun_arg then exit (if os_packages = [] then 0 else 1); 496 | let su = su_arg || not (has_command "sudo") in 497 | if (os_packages <> [] || opam_packages = []) && update_arg then 498 | update ~su ~interactive; 499 | install ~su ~interactive os_packages; 500 | let opam_cmdline = "install":: opam_args @ opam_packages in 501 | if install_arg && opam_packages <> [] then 502 | ((if not short then 503 | Printf.eprintf "# Now letting opam install the packages\n%!"); 504 | let opam_cmdline = 505 | opam_cmdline @ (if with_tests_arg then ["--with-test"] else []) 506 | @ (if with_docs_arg then ["--with-doc"] else []) 507 | in 508 | ignore (exec_opam opam_cmdline))) 509 | 510 | open Cmdliner 511 | 512 | let packages_arg = 513 | Arg.(value & pos_all string [] & 514 | info ~docv:"PACKAGES" 515 | ~doc:"opam packages to install external dependencies for. \ 516 | All installed packages if omitted" []) 517 | 518 | let print_flags_arg = 519 | Arg.(value & flag & 520 | info ~doc:"Only display the inferred \"depexts\" variables" ["flags"]) 521 | 522 | let list_arg = 523 | Arg.(value & flag & 524 | info ~doc:"Only list the system packages needed" ["l";"list"]) 525 | 526 | let short_arg = 527 | Arg.(value & flag & 528 | info ~doc:"Only output the raw item lists" ["s";"short"]) 529 | 530 | let debug_arg = 531 | Arg.(value & flag & 532 | info ~doc:"Print commands that are run by the program" ["d";"debug"]) 533 | 534 | let update_arg = 535 | Arg.(value & flag & 536 | info ~doc:"Update the OS package sets before installation" ["u";"update"]) 537 | 538 | let install_arg = 539 | Arg.(value & flag & 540 | info ~doc:"Install the packages through \"opam install\" after \ 541 | installing external dependencies" ["i";"install"]) 542 | 543 | let su_arg = 544 | Arg.(value & flag & 545 | info ~doc:"Attempt 'su' rather than 'sudo' when requiring root rights" 546 | ["su"]) 547 | 548 | let interactive_arg = 549 | Arg.(value & vflag None [ 550 | Some true, info 551 | ~doc:"Run the system package manager interactively (default if run \ 552 | from a tty and $(i,--yes) was not also specified)" 553 | ["interactive";"I"]; 554 | Some false, info 555 | ~doc:"Run the system package manager non-interactively \ 556 | (default when not running from a tty)" 557 | ["noninteractive"]; 558 | ]) 559 | 560 | let with_tests_arg = 561 | Arg.(value & flag & 562 | info ~doc:"Install test dependencies" ["with-test";"t"]) 563 | 564 | let with_docs_arg = 565 | Arg.(value & flag & 566 | info ~doc:"Install doc dependencies" ["with-doc"]) 567 | 568 | let dryrun_arg = 569 | Arg.(value & flag & 570 | info ~doc:"Only list the new system packages that would need to be \ 571 | installed, don't try to install them. Exits with 0 if all \ 572 | required system packages are already installed, 1 \ 573 | otherwise." 574 | ["n";"dry-run"]) 575 | 576 | let opam_args = 577 | let docs = "OPAM OPTIONS" in 578 | let flags = 579 | List.map 580 | (fun (fs,env) -> 581 | let term = Arg.(value & flag_all & info ?env ~docs fs) in 582 | Term.(pure (List.map (fun _ -> "--"^List.hd fs)) 583 | $ term)) 584 | [ ["verbose";"v"], (Some (Arg.env_var "OPAMVERBOSE" ~doc:"Force a verbose session")); 585 | ["yes";"y"], (Some (Arg.env_var "OPAMYES" ~doc:"Force a non-interactive session"))] 586 | in 587 | let options = 588 | List.map 589 | (fun fs -> 590 | let term = Arg.(value & opt_all string [] & info ~docs fs) in 591 | Term.(pure (List.map (Printf.sprintf "--%s=%s" (List.hd fs))) 592 | $ term)) 593 | [ ["jobs";"j"] ] 594 | in 595 | List.fold_left (fun acc t -> 596 | Term.(pure (@) $ acc $ t)) 597 | Term.(pure []) (flags @ options) 598 | 599 | let command = 600 | let man = [ 601 | `S "DESCRIPTION"; 602 | `P "$(b,opam-depext) is a simple program intended to facilitate the \ 603 | interaction between opam packages and the host package management \ 604 | system. It can perform OS and distribution detection, query opam for \ 605 | the right external dependencies on a set of packages, and call the OS \ 606 | package manager in the appropriate way to install then."; 607 | `S "OPAM OPTIONS"; 608 | `P "These options are passed through to the child opam process when used \ 609 | in conjunction with the $(i,-i) flag. Additionally, $(i,--yes) implies \ 610 | $(i,--noninteractive) unless $(i,--interactive) was made explicit."; 611 | `S "COPYRIGHT"; 612 | `P "$(b,opam-depext) is written by Louis Gesbert \ 613 | , copyright OCamlPro 2014-2021 with \ 614 | contributions from David Allsopp, Raja Boujbel, Kate Deplaix, \ 615 | Anil Madhavapeddy, distributed under the terms of \ 616 | the LGPL v2.1 with linking exception. Full source available at \ 617 | $(i,https://github.com/ocaml/opam-depext)"; 618 | `S "BUGS"; 619 | `P "Bugs are tracked at $(i,https://github.com/ocaml/opam-depext/issues) \ 620 | or can be reported to $(i,)."; 621 | ] in 622 | let doc = "Query and install external dependencies of opam packages" in 623 | Term.(pure main $ print_flags_arg $ list_arg $ short_arg $ 624 | debug_arg $ install_arg $ update_arg $ dryrun_arg $ 625 | with_tests_arg $ with_docs_arg $ 626 | su_arg $ interactive_arg $ opam_args $ 627 | packages_arg), 628 | Term.info "opam-depext" ~version:"1.2.3" ~doc ~man 629 | 630 | let () = 631 | Sys.catch_break true; 632 | Unix.putenv "OPAMCLI" "2.0"; 633 | try 634 | match Term.eval ~catch:false command with 635 | | `Ok () | `Version | `Help -> exit 0 636 | | `Error (`Parse | `Term) -> exit 2 637 | | `Error `Exn -> exit 1 638 | with 639 | | Sys.Break -> 640 | prerr_endline "Interrupted."; 641 | exit 130 642 | | Fatal_error (m, exit_code) -> 643 | prerr_endline m; 644 | exit exit_code 645 | -------------------------------------------------------------------------------- /opam: -------------------------------------------------------------------------------- 1 | opam-version: "2.0" 2 | name: "opam-depext" 3 | version: "1.2.3" 4 | maintainer: [ 5 | "Louis Gesbert " 6 | "Anil Madhavapeddy " 7 | ] 8 | authors: [ 9 | "Louis Gesbert " 10 | "Anil Madhavapeddy " 11 | ] 12 | license: "LGPL-2.1-only WITH OCaml-LGPL-linking-exception" 13 | homepage: "https://github.com/ocaml/opam-depext" 14 | bug-reports: "https://github.com/ocaml/opam-depext/issues" 15 | depends: [ 16 | "ocaml" {>= "4.00"} 17 | "base-unix" 18 | "cmdliner" {>= "0.9.8" & dev} 19 | "ocamlfind" {dev} 20 | ] 21 | available: opam-version >= "2.0.0~beta5" & os != "win32" 22 | flags: plugin 23 | build: [ 24 | [make] {!dev} 25 | ["ocamlfind" "%{ocaml:native?ocamlopt:ocamlc}%" 26 | "-package" "unix,cmdliner" "-linkpkg" 27 | "-o" "opam-depext" 28 | "depext.ml" 29 | ] {dev} 30 | ] 31 | dev-repo: "git+https://github.com/ocaml/opam-depext.git#2.0" 32 | synopsis: "Install OS distribution packages" 33 | description: """ 34 | opam-depext is a simple program intended to facilitate the interaction between 35 | OPAM packages and the host package management system. It can query OPAM for the 36 | right external dependencies on a set of packages, depending on the host OS, and 37 | call the OS's package manager in the appropriate way to install them. 38 | """ 39 | post-messages: [ 40 | "opam-depext is unnecessary when used with opam >= 2.1. Please use opam install directly instead" {opam-version >= "2.1"} 41 | ] 42 | -------------------------------------------------------------------------------- /opam-depext.install: -------------------------------------------------------------------------------- 1 | bin: [ "opam-depext" ] 2 | -------------------------------------------------------------------------------- /shell/build.ml: -------------------------------------------------------------------------------- 1 | module OCaml_version : sig 2 | type t 3 | val v : ?patch:int -> ?extra:string -> int -> int -> t 4 | val to_string : t -> string 5 | val of_string : string -> t 6 | val compare : t -> t -> int 7 | val t : t 8 | module Since : sig 9 | val bytes: t 10 | end 11 | module Has : sig 12 | val bytes : t -> bool 13 | end 14 | end = struct 15 | type t = { major: int; minor: int; patch: int option; extra: string option } 16 | 17 | let v ?patch ?extra major minor = { major; minor; patch; extra } 18 | 19 | let to_string = function 20 | |{major;minor;patch=None;extra=None} -> Printf.sprintf "%d.%d" major minor 21 | |{major;minor;patch=Some patch;extra=None} -> Printf.sprintf "%d.%d.%d" major minor patch 22 | |{major;minor;patch=Some patch;extra=Some extra} -> Printf.sprintf "%d.%d.%d+%s" major minor patch extra 23 | |{major;minor;patch=None;extra=Some extra} -> Printf.sprintf "%d.%d+%s" major minor extra 24 | 25 | let parse s = 26 | try Scanf.sscanf s "%d.%d.%d+%s" (fun major minor patch extra -> v ~patch ~extra major minor) 27 | with End_of_file | Scanf.Scan_failure _ -> begin 28 | try Scanf.sscanf s "%d.%d+%s" (fun major minor extra -> v ~extra major minor) 29 | with End_of_file | Scanf.Scan_failure _ -> begin 30 | try Scanf.sscanf s "%d.%d.%d" (fun major minor patch -> v ~patch major minor) 31 | with End_of_file | Scanf.Scan_failure _ -> begin 32 | Scanf.sscanf s "%d.%d" (fun major minor -> v major minor) 33 | end 34 | end 35 | end 36 | 37 | let of_string s = 38 | try parse s with 39 | | exn -> 40 | raise (Invalid_argument (Printf.sprintf "Unable to parse OCaml version '%s'" s)) 41 | 42 | let ( ++ ) x fn = 43 | match x with 44 | | 0 -> fn () 45 | | r -> r 46 | 47 | let compare {major; minor; patch; extra} a = 48 | compare major a.major ++ fun () -> 49 | compare minor a.minor ++ fun () -> 50 | compare patch a.patch ++ fun () -> 51 | compare extra a.extra 52 | 53 | let t = of_string Sys.ocaml_version 54 | 55 | module Since = struct 56 | let bytes = of_string "4.03.0" 57 | end 58 | 59 | module Has = struct 60 | let bytes v = 61 | match compare Since.bytes v with 62 | |(-1) | 0 -> true 63 | |n -> false 64 | end 65 | 66 | let test () = 67 | let vers = [ "3.12.1";"3.12";"4.00.1";"4.01.0+dev-foo";"4.04.0"; "4.04+additional"; "4.05"; "4.05.0+flambda"] in 68 | let vers_t = List.map parse vers in 69 | let ts = List.map parse vers in 70 | List.iter prerr_endline (List.map to_string ts); 71 | List.iter (fun v -> Printf.eprintf "%s compared to %s: %d\n%!" (to_string t) (to_string v) (compare t v)) vers_t 72 | end 73 | 74 | let build_bytecode () = 75 | print_endline "ocamlc -I src_ext/lib unix.cma cmdliner.cma -o opam-depext depext.ml" 76 | 77 | let build_native () = 78 | print_endline "ocamlopt -I src_ext unix.cmxa cmdliner.cmxa -o opam-depext depext.ml" 79 | 80 | let usage () = 81 | Printf.eprintf "Usage: ocaml build.ml [byte|native]\n\nDefaults to 'native' build.\n%!"; 82 | exit 1 83 | 84 | let _ = 85 | match Sys.argv with 86 | | [| _; "byte" |] -> build_bytecode () 87 | | [| _; "native" |] | [| _ |] -> build_native () 88 | | _ -> usage () 89 | -------------------------------------------------------------------------------- /shell/gen-release.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh -ex 2 | # Generate a release of a particular tag of opam-depext with 3 | # the vendor tarballs included. 4 | 5 | v=$1 6 | shift 7 | tag=$1 8 | shift 9 | 10 | if [ "$tag" = "" ]; then 11 | echo Usage: $0 version tag 12 | exit 1 13 | fi 14 | 15 | git archive --format=tar --prefix=opam-depext-$v/ $tag > ../opam-depext-$v.tar 16 | cd .. 17 | tar -xvf opam-depext-$v.tar 18 | cd opam-depext-$v 19 | make distrib 20 | cd .. 21 | tar -jcvf opam-depext-full-$v.tbz opam-depext-$v 22 | rm -f opam-depext-$v.tar 23 | -------------------------------------------------------------------------------- /shell/md5check.ml: -------------------------------------------------------------------------------- 1 | let file, md5 = 2 | if Array.length Sys.argv <> 3 then ( 3 | Printf.eprintf "usage: ocaml %s \n" Sys.argv.(0); 4 | exit 1 5 | ) else 6 | Sys.argv.(1), Sys.argv.(2) 7 | 8 | let md5_of_file = 9 | Digest.to_hex (Digest.file file) 10 | 11 | let () = 12 | if md5 <> md5_of_file then ( 13 | Printf.eprintf 14 | "MD5 for %s differ:\n\ 15 | \ expected: %s\n\ 16 | \ actual: %s\n" 17 | file md5 md5_of_file; 18 | Sys.remove file; 19 | exit 1 20 | ) else 21 | Printf.printf "%s has the expected MD5.\n" file 22 | -------------------------------------------------------------------------------- /src_ext/Makefile: -------------------------------------------------------------------------------- 1 | SHELL=sh 2 | FETCH=curl -OL 3 | OCAML=ocaml 4 | OCAMLC=ocamlc 5 | OCAMLOPT=ocamlopt 6 | SRC_EXTS = cmdliner 7 | 8 | URL_cmdliner = http://erratique.ch/software/cmdliner/releases/cmdliner-0.9.8.tbz 9 | MD5_cmdliner = fc67c937447cc223722f1419fa2189da 10 | 11 | ARCHIVES = $(foreach lib,$(SRC_EXTS),$(notdir $(URL_$(lib)))) 12 | lib_of = $(foreach lib,$(SRC_EXTS),$(if $(findstring $(1),$(URL_$(lib))),$(lib),,)) 13 | 14 | # Portable md5check 15 | MD5CHECK = $(OCAML) ../shell/md5check.ml 16 | 17 | lib-ext: clone build copy 18 | @ 19 | 20 | build: clone 21 | [ $(OCAMLC) = no ] || $(MAKE) -f $(OCAMLMAKEFILE) subprojs SUBTARGET=bcl 22 | [ $(OCAMLOPT) = no ] || $(MAKE) -f $(OCAMLMAKEFILE) subprojs SUBTARGET=ncl 23 | 24 | all: bcl ncl 25 | 26 | clone: $(SRC_EXTS:=.stamp) 27 | ifneq ($(filter 4.%,$(shell $(OCAMLC) -vnum)),) 28 | @ 29 | else 30 | @mv cmdliner/src/cmdliner.ml cmdliner/src/t 31 | @echo 'module String = struct include String' > cmdliner/src/cmdliner.ml 32 | @echo ' let uppercase = uppercase_ascii' >> cmdliner/src/cmdliner.ml 33 | @echo ' let lowercase = lowercase_ascii' >> cmdliner/src/cmdliner.ml 34 | @echo ' let capitalize = capitalize_ascii' >> cmdliner/src/cmdliner.ml 35 | @echo 'end' >> cmdliner/src/cmdliner.ml 36 | @cat cmdliner/src/t >> cmdliner/src/cmdliner.ml 37 | endif 38 | 39 | archives: $(SRC_EXTS:=.download) 40 | @ 41 | 42 | define cache_url 43 | https://opam.ocaml.org/2.0~dev/cache/md5/$(shell echo $(MD5_$(1)) | cut -c -2)/$(MD5_$(1)) 44 | endef 45 | 46 | define get_from_cache 47 | { $(FETCH) $(call cache_url,$(1)) && \ 48 | mv $(MD5_$(1)) $(notdir $(URL_$(1))) && \ 49 | $(MD5CHECK) $(notdir $(URL_$(1))) $(MD5_$(1)); } 50 | endef 51 | 52 | %.download: 53 | [ -e $(notdir $(URL_$*)) ] || \ 54 | $(FETCH) $(URL_$*) && $(MD5CHECK) $(notdir $(URL_$*)) $(MD5_$*) || \ 55 | $(call get_from_cache,$*) 56 | 57 | %.stamp: %.download 58 | mkdir -p tmp 59 | cd tmp && $(if $(patsubst %.tar.gz,,$(URL_$*)),bunzip2,gunzip) -c ../$(notdir $(URL_$*)) | tar xf - 60 | rm -rf $* 61 | @for ii in tmp/*; do if [ -d $${ii} ]; then mv $${ii} $*; fi; done; \ 62 | rm -rf tmp 63 | @if [ -d patches/$* ]; then \ 64 | cd $* && \ 65 | for p in ../patches/$*/*.patch; do \ 66 | patch -p1 < $$p; \ 67 | done; \ 68 | fi 69 | @touch $@ 70 | 71 | clean: 72 | rm -rf lib 73 | $(MAKE) -f $(OCAMLMAKEFILE) subprojs SUBTARGET=cleanup 74 | 75 | distclean: 76 | rm -rf cmdliner 77 | rm -f *.tar.gz *.tbz *.stamp 78 | rm -f *.cm* *.o *.a *.lib 79 | rm -rf lib 80 | 81 | LIB_EXTS = cmdliner 82 | 83 | inst_objs = cp $(1)/*.cm*i lib 84 | 85 | copy: build 86 | mkdir -p lib 87 | cp *.cma lib || true 88 | cp *.cmxa lib || true 89 | cp *.a lib || true 90 | cp *.lib lib || true 91 | $(call inst_objs,cmdliner/src) 92 | 93 | # -- 94 | 95 | addmli = $(foreach ml,$(2),$(wildcard $(addsuffix .mli,$(basename $(1)/$(ml)))) $(1)/$(ml)) 96 | 97 | SRC_cmdliner = cmdliner.ml 98 | 99 | define PROJ_cmdliner 100 | SOURCES = $(call addmli,cmdliner/src,$(SRC_cmdliner)) 101 | RESULT = cmdliner 102 | LIB_PACK_NAME = 103 | endef 104 | export PROJ_cmdliner 105 | 106 | # -- 107 | 108 | ifndef SUBROJS 109 | export SUBPROJS = $(LIB_EXTS) 110 | endif 111 | 112 | 113 | %: 114 | $(MAKE) -f $(OCAMLMAKEFILE) subprojs SUBTARGET=$@ 115 | 116 | OCAMLMAKEFILE = ../OCamlMakefile 117 | export OCAMLMAKEFILE 118 | --------------------------------------------------------------------------------