The unpac monorepo manager self-hosting as a monorepo using unpac
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Generate an opam .install file and support script

make INSTALL_MODE=opam install generates $OPAM_PACKAGE_NAME.install and
$OPAM_PACKAGE_NAME-fixup.sh ($OPAM_PACKAGE_NAME defaults to
ocaml-compiler). Nothing is installed by this mode. The fixup.sh script
is intentionally not made executable (it should be invoked explicitly
with sh) and creates symbolic links, if required, and also manually
copies the files to the doc dir, as the .install file format doesn't
allow the correct location to be specified.

+205
+118
Makefile.common
··· 266 266 INSTALL_DESPATCH_list_BEGIN = @ 267 267 INSTALL_DESPATCH_list_END = @ 268 268 269 + OPAM_PACKAGE_NAME ?= ocaml-compiler 270 + 271 + # Generate $(OPAM_PACKAGE_NAME).install and $(OPAM_PACKAGE_NAME)-fixup.sh 272 + # (INSTALL_MODE=opam) 273 + # opam's .install format isn't quite rich enough at present to express the 274 + # installation of the compiler. In particular, we can't install the doc files to 275 + # doc/ocaml using a .install and we can't create symlinks. The things which 276 + # can't be handled by the .install file are dealt with by the fixup script 277 + # instead. 278 + 279 + INVOKE = $(strip $(1)) $(call QUOTE_SINGLE,$(strip $(2))) 280 + ADD_LINE = $(call INVOKE, echo, $(2)) >> $(1) 281 + 282 + # RECORD_SYMLINK_TO_INSTALL 283 + # $1 = file to install, implicitly relative to $(ROOTDIR) 284 + # $2 = section 285 + # $3 = subdirectory within $2 (may be empty) 286 + # $4 = name to install $1 (must be specified) 287 + # $5 = single name of symlink 288 + # If symlinks are supported, $1 is ignored and the three pieces of information 289 + # are recorded in create-symlinks: the directory, implicitly relative to the 290 + # prefix, in which the symlink is to be created, the source file and name of the 291 + # symlink. 292 + # These can then be munged to a cd + ln combination in the fixup script. 293 + # If symlinks are not supported, $1 is instead used to create an additional copy 294 + # of the file, using the .install file. 295 + ifeq "$(firstword $(LN))" "ln" 296 + RECORD_SYMLINK_TO_INSTALL = \ 297 + $(call ADD_LINE, $(ROOTDIR)/create-symlinks, \ 298 + $(patsubst lib%,lib,$(2))$(addprefix /,$(3)) $(4) $(5)) 299 + else 300 + # Symlinks aren't available, so copy the file again using the target name 301 + RECORD_SYMLINK_TO_INSTALL = \ 302 + $(call RECORD_opam_ITEM_TO_INSTALL,$(1),$(2),$(3),$(5)) 303 + endif 304 + 305 + # Process the arguments to pass to RECORD_opam_ITEM_TO_INSTALL: 306 + # - Items installed to the stublibs section need to be remapped to the stublibs 307 + # subdirectory of libexec (since we install to lib/ocaml/stublibs rather than 308 + # opam's default lib/stublibs) 309 + # - Source files must be given implicitly relative to $(ROOTDIR), so prefix with 310 + # $(SUBDIR_NAME) if necessary 311 + # - Items installed to the lib/libexec sections will in fact be installed to 312 + # lib_root/libexec_root, so remap the installation directory to ocaml (i.e. to 313 + # install to lib/ocaml rather than lib) 314 + # - If no target basename has been explictly given, use the source's basename 315 + RECORD_ITEM_TO_INSTALL = \ 316 + $(if $(filter stublibs,$(2)),\ 317 + $(call RECORD_ITEM_TO_INSTALL,$\ 318 + $(1),libexec,stublibs$(addprefix /,$(3)),$(4),$(5)),\ 319 + $(call RECORD_opam_ITEM_TO_INSTALL,$\ 320 + $(addsuffix /,$(SUBDIR_NAME))$(1),$\ 321 + $(2),$\ 322 + $(if $(filter doc lib%,$(2)),ocaml$(addprefix /,$(3)),$(3)),$\ 323 + $(if $(4),$(4),$(notdir $(1))),$\ 324 + $(5))) 325 + 326 + # All files must be explicitly installed, so evaluate the wildcards and call 327 + # INSTALL_DESPATCH_opam_ITEM for each file. 328 + INSTALL_EVALUATE_GLOBS = \ 329 + $(foreach file, $(wildcard $(1)), \ 330 + $(call INSTALL_DESPATCH_$(INSTALL_MODE)_ITEM,$(file),$(2),$(3));) \ 331 + true 332 + 333 + # RECORD_FILE_TO_INSTALL 334 + # $1 = file to install, implicitly relative to $(ROOTDIR) 335 + # $2 = bin/lib/libexec/man 336 + # $3 = subdirectory within $2 (may be empty, but otherwise must end with "/") 337 + # $4 = name to install $1 (must be specified) 338 + # Writes an opam .install line to the section file for $(2). Each line consists 339 + # of a double-quoted implicit filename relative to $(ROOTDIR) and optionally a 340 + # second double-quoted implicit filename relative to the $(2) for the name to 341 + # install the file under. 342 + # e.g. "lex/ocamllex" {"ocamllex.byte"} or "expunge" {"ocaml/expunge"} 343 + RECORD_FILE_TO_INSTALL = \ 344 + $(call ADD_LINE, $(ROOTDIR)/opam-$(2), \ 345 + "$(1)" $(if $(3)$(filter-out $(notdir $(1)),$(4)), {"$(3)$(4)"})) 346 + 347 + # RECORD_FILE_TO_CLONE 348 + # $1 = file to install, implicitly relative to $(ROOTDIR) 349 + # $2 = subdirectory (may be empty, but otherwise must end with "/") 350 + # $3 = name to install $1 (must be specified) 351 + # The compiler is installed as the ocaml package in opam, but the actual files 352 + # are installed from other packages (typically ocaml-compiler). For the lib 353 + # directory, the lib_root and libexec_root sections allow files to be installed 354 + # to lib/ocaml, but there's no equivalent mechanism for the doc directory. These 355 + # files are recorded to be copied manually in the fixup script. 356 + RECORD_FILE_TO_CLONE = \ 357 + $(call ADD_LINE, $(ROOTDIR)/clone-$(subst /,@,$(2)), $(1) $(3)) 358 + 359 + # RECORD_opam_ITEM_TO_INSTALL despatches the processed arguments of 360 + # INSTALL_DESPATCH_opam_ITEM to the appropriate RECORD_ macro. 361 + RECORD_opam_ITEM_TO_INSTALL = \ 362 + $(if $(filter doc,$(2)),\ 363 + $(call RECORD_FILE_TO_CLONE,$(1),doc/$(3),$(4)), \ 364 + $(call RECORD_FILE_TO_INSTALL,$(1),$(2),$(addsuffix /,$(3)),$(4))) \ 365 + $(foreach link, $(5), && \ 366 + $(call RECORD_SYMLINK_TO_INSTALL,$(1),$(2),$(3),$(4),$(link))) 367 + 368 + INSTALL_DESPATCH_opam_ITEM = $(RECORD_ITEM_TO_INSTALL) 369 + 370 + INSTALL_DESPATCH_opam_ITEMS = $(INSTALL_EVALUATE_GLOBS) 371 + 372 + INSTALL_opam_PREFIX = @ 373 + 374 + INSTALL_DESPATCH_opam_RM = @ 375 + 376 + # INSTALL_MKDIR is ignored (opam creates them when executing the .install file) 377 + INSTALL_DESPATCH_opam_MKDIR = 378 + 379 + INSTALL_DESPATCH_opam_BEGIN = \ 380 + rm -f opam-bin clone-* opam-lib opam-libexec opam-man create-symlinks 381 + 382 + # Munge opam-bin, opam-lib, opam-libexec and opam-man into a .install file and 383 + # then munge clone-* and create-symlinks into the fixup script. 384 + INSTALL_DESPATCH_opam_END = \ 385 + tools/opam/generate-install.sh $(OPAM_PACKAGE_NAME) $(UNIX_OR_WIN32) '$(LN)' 386 + 269 387 FLEXDLL_SUBMODULE_PRESENT := $(wildcard $(ROOTDIR)/flexdll/Makefile) 270 388 271 389 IN_COREBOOT_CYCLE ?= false
+87
tools/opam/generate-install.sh
··· 1 + #!/bin/sh -e 2 + #************************************************************************** 3 + #* * 4 + #* OCaml * 5 + #* * 6 + #* David Allsopp, University of Cambridge & Tarides * 7 + #* * 8 + #* Copyright 2025 David Allsopp Ltd. * 9 + #* * 10 + #* All rights reserved. This file is distributed under the terms of * 11 + #* the GNU Lesser General Public License version 2.1, with the * 12 + #* special exception on linking described in the file LICENSE. * 13 + #* * 14 + #************************************************************************** 15 + 16 + # This script is called from the root of the repository at the end of 17 + # `make INSTALL_MODE=opam install` and is responsible for converting the various 18 + # files generated by the opam installation backend into a .install file and a 19 + # -fixup.sh script. 20 + # Parameters are the following Makefile variables: 21 + # $1 = $(OPAM_PACKAGE_NAME) 22 + # $2 = $(UNIX_OR_WIN32) 23 + # $3 = $(LN) 24 + 25 + # The opam packaging for the compiler installs config.cache and config.status 26 + # (when building with opam, it is required to have configure with -C). 27 + # config.cache is installed in order to speed-up the legacy `make reconfigure` 28 + # and config.status is installed in order to allow the source-tree to be 29 + # re-configured the autoconf way. 30 + cat > opam-share <<"EOF" 31 + "config.cache" {"ocaml/config.cache"} 32 + "config.status" {"ocaml/config.status"} 33 + EOF 34 + 35 + # Generate the .install file 36 + for section in bin lib_root libexec_root man share_root; do 37 + file="opam-${section%_root}" 38 + if [ -e "$file" ]; then 39 + echo "$section: [" 40 + sed -e 's/^/ /' "$file" 41 + echo ']' 42 + rm -f "$file" 43 + fi 44 + done > "$1.install" 45 + 46 + { 47 + echo '#!/bin/sh' 48 + echo 'set -eu' 49 + for fileset in clone-*; do 50 + # There isn't a portable way to test that a glob doesn't match, hence the 51 + # redundant-appearing `test -f` (if there are no matches, some shells will 52 + # not execute the loop at all - which is what we want. Some shells will 53 + # instead run the loop once with `fileset='clone-*'`) 54 + if [ -f "$fileset" ]; then 55 + dir="$(echo "${fileset#clone-}" | sed -e 's|@|/|g')" 56 + echo 'mkdir -p "$1"'"'/$dir'" 57 + sed -e 's|\(.*\) \(.*\)|cp '"'\\1'"' "$1"'"'/$dir/\\2'|" "$fileset" 58 + fi 59 + done 60 + rm -f clone-* 61 + if [ -f create-symlinks ]; then 62 + echo 'cd "$1"' 63 + # opam runs this script _before_ processing the .install file, which means 64 + # that only the root switch directories will exist (in particular, lib/ocaml 65 + # will not yet have been created). This incantation creates any required 66 + # subdirectories. On Windows, create-symlinks will only have been used if 67 + # symbolic links are available, and we never symlink directories. We use 68 + # mklink, as that allows symlinks to files which don't exist yet to be 69 + # created on Windows (where `CYGWIN=winsymlinks:nativestrict ln -s` can't) 70 + cut -f 1 -d ' ' create-symlinks | sort -u | sed -ne "s|.*/.*|mkdir -p '&'|p" 71 + if [ "$2" = 'win32' ]; then 72 + echo 'cmd /c "mklink __ln_test mklink-test"' 73 + echo 'if test -L "$1/__ln_test"; then' 74 + sed -e 's|\(.*\) \(.*\) \(.*\)|mklink \1/\3 \2|' \ 75 + -e 's|/|\\\\|g' \ 76 + -e 's|.*| cmd /c "&"|' create-symlinks 77 + echo 'else' 78 + sed -e 's|\(.*\) \(.*\) \(.*\)| $CP '"'\\1/\\2' '\\1/\\3'|" \ 79 + create-symlinks 80 + echo 'fi' 81 + echo 'rm -f __ln_test' 82 + else 83 + sed -e 's|\(.*\) \(.*\) \(.*\)|'"$3 '\\2' '\\1/\\3'|" create-symlinks 84 + fi 85 + rm create-symlinks 86 + fi 87 + } > "$1-fixup.sh"