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 # CL packages in the overlay don't have their tarballs on the mirrors
15 # so it's useless to mirror them
18 # @ECLASS-VARIABLE: CLSOURCEROOT
20 # Default path of Common Lisp libraries sources. Sources will
21 # be installed into ${CLSOURCEROOT}/${CLPACKAGE}.
22 CLSOURCEROOT="${ROOT%/}"/usr/share/common-lisp/source
24 # @ECLASS-VARIABLE: CLSYSTEMROOT
26 # Default path to find any asdf file. Any asdf files will be
27 # symlinked in ${CLSYSTEMROOT}/${CLSYSTEM} as they may be in
28 # an arbitrarily deeply nested directory under ${CLSOURCEROOT}/${CLPACKAGE}.
29 CLSYSTEMROOT="${ROOT%/}"/usr/share/common-lisp/systems
31 # @ECLASS-VARIABLE: CLPACKAGE
33 # Default package name. To override, set these after inheriting this eclass.
36 PDEPEND="virtual/commonlisp"
38 EXPORT_FUNCTIONS src_compile src_install
40 # @FUNCTION: common-lisp-3_src_compile
42 # Since there's nothing to build in most cases, default doesn't do
44 common-lisp-3_src_compile() { true; }
46 # @FUNCTION: absolute-path-p
48 # Returns true if ${1} is an absolute path.
50 [[ $# -eq 1 ]] || die "${FUNCNAME[0]} must receive one argument"
54 # @FUNCTION: common-lisp-install-one-source
56 # Installs ${2} source file in ${3} inside CLSOURCEROOT/CLPACKAGE.
57 common-lisp-install-one-source() {
58 [[ $# -eq 3 ]] || die "${FUNCNAME[0]} must receive exactly three arguments"
62 local target="${CLSOURCEROOT}/${CLPACKAGE}/${3}"
64 if absolute-path-p "${source}" ; then
65 die "Cannot install files with absolute path: ${source}"
68 if ${fpredicate} "${source}" ; then
70 doins "${source}" || die "Failed to install ${source} into $(dirname "${target}")"
74 # @FUNCTION: lisp-file-p
76 # Returns true if ${1} is lisp source file.
78 [[ $# -eq 1 ]] || die "${FUNCNAME[0]} must receive one argument"
80 [[ ${1} =~ \.(lisp|lsp|cl)$ ]]
83 # @FUNCTION: common-lisp-get-fpredicate
85 # Outputs the corresponding predicate to check files of type ${1}.
86 common-lisp-get-fpredicate() {
87 [[ $# -eq 1 ]] || die "${FUNCNAME[0]} must receive one argument"
91 "lisp") echo "lisp-file-p" ;;
92 "all" ) echo "true" ;;
93 * ) die "Unknown filetype specifier ${ftype}" ;;
97 # @FUNCTION: common-lisp-install-sources
98 # @USAGE: common-lisp-install-sources path [<other_paths>...]
100 # Recursively install lisp sources of type ${2} if ${1} is -t or
101 # Lisp by default. When given a directory, it will be recursively
102 # scanned for Lisp source files with suffixes: .lisp, .lsp or .cl.
103 common-lisp-install-sources() {
105 if [[ ${1} == "-t" ]] ; then
110 [[ $# -ge 1 ]] || die "${FUNCNAME[0]} must receive one non-option argument"
112 local fpredicate=$(common-lisp-get-fpredicate "${ftype}")
114 for path in "${@}" ; do
115 if [[ -f ${path} ]] ; then
116 common-lisp-install-one-source ${fpredicate} "${path}" "$(dirname "${path}")"
117 elif [[ -d ${path} ]] ; then
118 common-lisp-install-sources -t ${ftype} $(find "${path}" -type f)
120 die "${path} it neither a regular file nor a directory"
125 # @FUNCTION: common-lisp-install-one-asdf
127 # Installs ${1} asdf file in CLSOURCEROOT/CLPACKAGE and symlinks it in
129 common-lisp-install-one-asdf() {
130 [[ $# != 1 ]] && die "${FUNCNAME[0]} must receive exactly one argument"
132 # the suffix «.asd» is optional
133 local source=${1/.asd}.asd
134 common-lisp-install-one-source true "${source}" "$(dirname "${source}")"
135 local target="${CLSOURCEROOT%/}/${CLPACKAGE}/${source}"
136 dosym "${target}" "${CLSYSTEMROOT%/}/$(basename ${target})"
139 # @FUNCTION: common-lisp-install-asdf
140 # @USAGE: common-lisp-install-asdf path [<other_paths>...]
142 # Installs all ASDF files and creates symlinks in CLSYSTEMROOT.
143 # When given a directory, it will be recursively scanned for ASDF
144 # files with extension .asd.
145 common-lisp-install-asdf() {
146 dodir "${CLSYSTEMROOT}"
148 [[ $# = 0 ]] && set - ${CLSYSTEMS}
149 [[ $# = 0 ]] && set - $(find . -type f -name \*.asd)
150 for sys in "${@}" ; do
151 common-lisp-install-one-asdf ${sys}
155 # @FUNCTION: common-lisp-3_src_install
157 # Recursively install Lisp sources, asdf files and most common doc files.
158 common-lisp-3_src_install() {
159 common-lisp-install-sources .
160 common-lisp-install-asdf
161 for i in AUTHORS README* HEADER TODO* CHANGELOG Change[lL]og CHANGES BUGS CONTRIBUTORS *NEWS* ; do
162 [[ -f ${i} ]] && dodoc ${i}
166 # @FUNCTION: common-lisp-export-impl-args
167 # @USAGE: common-lisp-export-impl-args <lisp-implementation>
169 # Export a few variables containing the switches necessary
170 # to make the CL implementation perform basic functions:
171 # * CL_NORC: don't load syste-wide or user-specific initfiles
172 # * CL_LOAD: load a certain file
173 # * CL_EVAL: eval a certain expression at startup
174 common-lisp-export-impl-args() {
175 if [[ $# != 1 ]]; then
176 eerror "Usage: ${FUNCNAME[0]} lisp-implementation"
177 die "${FUNCNAME[0]}: wrong number of arguments: $#"
185 clozure | ccl | openmcl)
191 CL_NORC="-nositeinit -noinit"
201 CL_NORC="--sysinit /dev/null --userinit /dev/null"
206 die ${1} is not supported by ${0}
209 export CL_NORC CL_LOAD CL_EVAL