1 # Copyright 1999-2017 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
4 # @ECLASS: common-lisp-3.eclass
6 # Common Lisp project <common-lisp@gentoo.org>
7 # @BLURB: functions to support the installation of Common Lisp libraries
9 # Since Common Lisp libraries share similar structure, this eclass aims
10 # to provide a simple way to write ebuilds with these characteristics.
14 # @ECLASS-VARIABLE: CLIMPLEMENTATIONS
16 # Common Lisp implementations
17 CLIMPLEMENTATIONS="sbcl clisp clozurecl cmucl ecls gcl abcl"
19 # @ECLASS-VARIABLE: CLSOURCEROOT
21 # Default path of Common Lisp libraries sources. Sources will
22 # be installed into ${CLSOURCEROOT}/${CLPACKAGE}.
23 CLSOURCEROOT="${ROOT%/}"/usr/share/common-lisp/source
25 # @ECLASS-VARIABLE: CLSYSTEMROOT
27 # Default path to find any asdf file. Any asdf files will be
28 # symlinked in ${CLSYSTEMROOT}/${CLSYSTEM} as they may be in
29 # an arbitrarily deeply nested directory under ${CLSOURCEROOT}/${CLPACKAGE}.
30 CLSYSTEMROOT="${ROOT%/}"/usr/share/common-lisp/systems
32 # @ECLASS-VARIABLE: CLPACKAGE
34 # Default package name. To override, set these after inheriting this eclass.
37 PDEPEND="virtual/commonlisp"
39 EXPORT_FUNCTIONS src_compile src_install
41 # @FUNCTION: common-lisp-3_src_compile
43 # Since there's nothing to build in most cases, default doesn't do
45 common-lisp-3_src_compile() {
49 # @FUNCTION: absolute-path-p
51 # Returns true if ${1} is an absolute path.
53 [[ $# -eq 1 ]] || die "${FUNCNAME[0]} must receive one argument"
57 # @FUNCTION: common-lisp-install-one-source
59 # Installs ${2} source file in ${3} inside CLSOURCEROOT/CLPACKAGE.
60 common-lisp-install-one-source() {
61 [[ $# -eq 3 ]] || die "${FUNCNAME[0]} must receive exactly three arguments"
65 local target="${CLSOURCEROOT}/${CLPACKAGE}/${3}"
67 if absolute-path-p "${source}" ; then
68 die "Cannot install files with absolute path: ${source}"
71 if ${fpredicate} "${source}" ; then
73 doins "${source}" || die "Failed to install ${source} into $(dirname "${target}")"
77 # @FUNCTION: lisp-file-p
79 # Returns true if ${1} is lisp source file.
81 [[ $# -eq 1 ]] || die "${FUNCNAME[0]} must receive one argument"
83 [[ ${1} =~ \.(lisp|lsp|cl)$ ]]
86 # @FUNCTION: common-lisp-get-fpredicate
88 # Outputs the corresponding predicate to check files of type ${1}.
89 common-lisp-get-fpredicate() {
90 [[ $# -eq 1 ]] || die "${FUNCNAME[0]} must receive one argument"
94 "lisp") echo "lisp-file-p" ;;
95 "all" ) echo "true" ;;
96 * ) die "Unknown filetype specifier ${ftype}" ;;
100 # @FUNCTION: common-lisp-install-sources
101 # @USAGE: common-lisp-install-sources path [<other_paths>...]
103 # Recursively install lisp sources of type ${2} if ${1} is -t or
104 # Lisp by default. When given a directory, it will be recursively
105 # scanned for Lisp source files with suffixes: .lisp, .lsp or .cl.
106 common-lisp-install-sources() {
108 if [[ ${1} == "-t" ]] ; then
113 [[ $# -ge 1 ]] || die "${FUNCNAME[0]} must receive one non-option argument"
115 local fpredicate=$(common-lisp-get-fpredicate "${ftype}")
117 for path in "${@}" ; do
118 if [[ -f ${path} ]] ; then
119 common-lisp-install-one-source ${fpredicate} "${path}" "$(dirname "${path}")"
120 elif [[ -d ${path} ]] ; then
121 common-lisp-install-sources -t ${ftype} $(find "${path}" -type f)
123 die "${path} is neither a regular file nor a directory"
128 # @FUNCTION: common-lisp-install-one-asdf
130 # Installs ${1} asdf file in CLSOURCEROOT/CLPACKAGE and symlinks it in
132 common-lisp-install-one-asdf() {
133 [[ $# != 1 ]] && die "${FUNCNAME[0]} must receive exactly one argument"
135 # the suffix «.asd» is optional
136 local source=${1/.asd}.asd
137 common-lisp-install-one-source true "${source}" "$(dirname "${source}")"
138 local target="${CLSOURCEROOT%/}/${CLPACKAGE}/${source}"
139 dosym "${target}" "${CLSYSTEMROOT%/}/$(basename ${target})"
142 # @FUNCTION: common-lisp-install-asdf
143 # @USAGE: common-lisp-install-asdf path [<other_paths>...]
145 # Installs all ASDF files and creates symlinks in CLSYSTEMROOT.
146 # When given a directory, it will be recursively scanned for ASDF
147 # files with extension .asd.
148 common-lisp-install-asdf() {
149 dodir "${CLSYSTEMROOT}"
151 [[ $# = 0 ]] && set - ${CLSYSTEMS}
152 [[ $# = 0 ]] && set - $(find . -type f -name \*.asd)
153 for sys in "${@}" ; do
154 common-lisp-install-one-asdf ${sys}
158 # @FUNCTION: common-lisp-3_src_install
160 # Recursively install Lisp sources, asdf files and most common doc files.
161 common-lisp-3_src_install() {
162 common-lisp-install-sources .
163 common-lisp-install-asdf
164 for i in AUTHORS README* HEADER TODO* CHANGELOG Change[lL]og CHANGES BUGS CONTRIBUTORS *NEWS* ; do
165 [[ -f ${i} ]] && dodoc ${i}
169 # @FUNCTION: common-lisp-find-lisp-impl
170 # @USAGE: common-lisp-find-lisp-impl
172 # Outputs an installed Common Lisp implementation. Transverses
173 # CLIMPLEMENTATIONS to find it.
174 common-lisp-find-lisp-impl() {
175 for lisp in ${CLIMPLEMENTATIONS} ; do
176 [[ "$(best_version dev-lisp/${lisp})" ]] && echo "${lisp}" && return
178 die "No CommonLisp implementation found"
181 # @FUNCTION: common-lisp-export-impl-args
182 # @USAGE: common-lisp-export-impl-args <lisp-implementation>
184 # Export a few variables containing the switches necessary
185 # to make the CL implementation perform basic functions:
186 # * CL_BINARY: Common Lisp implementation
187 # * CL_NORC: don't load syste-wide or user-specific initfiles
188 # * CL_LOAD: load a certain file
189 # * CL_EVAL: eval a certain expression at startup
190 common-lisp-export-impl-args() {
191 if [[ $# != 1 ]]; then
192 eerror "Usage: ${FUNCNAME[0]} lisp-implementation"
193 die "${FUNCNAME[0]}: wrong number of arguments: $#"
196 case "${CL_BINARY}" in
198 CL_NORC="--sysinit /dev/null --userinit /dev/null"
207 clozure | clozurecl | ccl | openmcl)
214 CL_NORC="-nositeinit -noinit"
230 die "${CL_BINARY} is not supported by ${0}"
233 export CL_BINARY CL_NORC CL_LOAD CL_EVAL