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() {
48 # @FUNCTION: absolute-path-p
50 # Returns true if ${1} is an absolute path.
52 [[ $# -eq 1 ]] || die "${FUNCNAME[0]} must receive one argument"
56 # @FUNCTION: common-lisp-install-one-source
58 # Installs ${2} source file in ${3} inside CLSOURCEROOT/CLPACKAGE.
59 common-lisp-install-one-source() {
60 [[ $# -eq 3 ]] || die "${FUNCNAME[0]} must receive exactly three arguments"
64 local target="${CLSOURCEROOT}/${CLPACKAGE}/${3}"
66 if absolute-path-p "${source}" ; then
67 die "Cannot install files with absolute path: ${source}"
70 if ${fpredicate} "${source}" ; then
72 doins "${source}" || die "Failed to install ${source} into $(dirname "${target}")"
76 # @FUNCTION: lisp-file-p
78 # Returns true if ${1} is lisp source file.
80 [[ $# -eq 1 ]] || die "${FUNCNAME[0]} must receive one argument"
82 [[ ${1} =~ \.(lisp|lsp|cl)$ ]]
85 # @FUNCTION: common-lisp-get-fpredicate
87 # Outputs the corresponding predicate to check files of type ${1}.
88 common-lisp-get-fpredicate() {
89 [[ $# -eq 1 ]] || die "${FUNCNAME[0]} must receive one argument"
93 "lisp") echo "lisp-file-p" ;;
94 "all" ) echo "true" ;;
95 * ) die "Unknown filetype specifier ${ftype}" ;;
99 # @FUNCTION: common-lisp-install-sources
100 # @USAGE: common-lisp-install-sources path [<other_paths>...]
102 # Recursively install lisp sources of type ${2} if ${1} is -t or
103 # Lisp by default. When given a directory, it will be recursively
104 # scanned for Lisp source files with suffixes: .lisp, .lsp or .cl.
105 common-lisp-install-sources() {
107 if [[ ${1} == "-t" ]] ; then
112 [[ $# -ge 1 ]] || die "${FUNCNAME[0]} must receive one non-option argument"
114 local fpredicate=$(common-lisp-get-fpredicate "${ftype}")
116 for path in "${@}" ; do
117 if [[ -f ${path} ]] ; then
118 common-lisp-install-one-source ${fpredicate} "${path}" "$(dirname "${path}")"
119 elif [[ -d ${path} ]] ; then
120 common-lisp-install-sources -t ${ftype} $(find "${path}" -type f)
122 die "${path} is neither a regular file nor a directory"
127 # @FUNCTION: common-lisp-install-one-asdf
129 # Installs ${1} asdf file in CLSOURCEROOT/CLPACKAGE and symlinks it in
131 common-lisp-install-one-asdf() {
132 [[ $# != 1 ]] && die "${FUNCNAME[0]} must receive exactly one argument"
134 # the suffix «.asd» is optional
135 local source=${1/.asd}.asd
136 common-lisp-install-one-source true "${source}" "$(dirname "${source}")"
137 local target="${CLSOURCEROOT%/}/${CLPACKAGE}/${source}"
138 dosym "${target}" "${CLSYSTEMROOT%/}/$(basename ${target})"
141 # @FUNCTION: common-lisp-install-asdf
142 # @USAGE: common-lisp-install-asdf path [<other_paths>...]
144 # Installs all ASDF files and creates symlinks in CLSYSTEMROOT.
145 # When given a directory, it will be recursively scanned for ASDF
146 # files with extension .asd.
147 common-lisp-install-asdf() {
148 dodir "${CLSYSTEMROOT}"
150 [[ $# = 0 ]] && set - ${CLSYSTEMS}
151 [[ $# = 0 ]] && set - $(find . -type f -name \*.asd)
152 for sys in "${@}" ; do
153 common-lisp-install-one-asdf ${sys}
157 # @FUNCTION: common-lisp-3_src_install
159 # Recursively install Lisp sources, asdf files and most common doc files.
160 common-lisp-3_src_install() {
161 common-lisp-install-sources .
162 common-lisp-install-asdf
163 for i in AUTHORS README* HEADER TODO* CHANGELOG Change[lL]og CHANGES BUGS CONTRIBUTORS *NEWS* ; do
164 [[ -f ${i} ]] && dodoc ${i}
168 # @FUNCTION: common-lisp-export-impl-args
169 # @USAGE: common-lisp-export-impl-args <lisp-implementation>
171 # Export a few variables containing the switches necessary
172 # to make the CL implementation perform basic functions:
173 # * CL_BINARY: Common Lisp implementation
174 # * CL_NORC: don't load syste-wide or user-specific initfiles
175 # * CL_LOAD: load a certain file
176 # * CL_EVAL: eval a certain expression at startup
177 common-lisp-export-impl-args() {
178 if [[ $# != 1 ]]; then
179 eerror "Usage: ${FUNCNAME[0]} lisp-implementation"
180 die "${FUNCNAME[0]}: wrong number of arguments: $#"
183 case "${CL_BINARY}" in
189 clozure | clozurecl | ccl | openmcl)
196 CL_NORC="-nositeinit -noinit"
207 CL_NORC="--sysinit /dev/null --userinit /dev/null"
212 die "${CL_BINARY} is not supported by ${0}"
215 export CL_BINARY CL_NORC CL_LOAD CL_EVAL