common-lisp-3.eclass: Add abct to common-lisp-export-impl-args
[gentoo.git] / eclass / common-lisp-3.eclass
1 # Copyright 1999-2017 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3
4 # @ECLASS: common-lisp-3.eclass
5 # @MAINTAINER:
6 # Common Lisp project <common-lisp@gentoo.org>
7 # @BLURB: functions to support the installation of Common Lisp libraries
8 # @DESCRIPTION:
9 # Since Common Lisp libraries share similar structure, this eclass aims
10 # to provide a simple way to write ebuilds with these characteristics.
11
12 inherit eutils
13
14 # @ECLASS-VARIABLE: CLIMPLEMENTATIONS
15 # @DESCRIPTION:
16 # Common Lisp implementations
17 CLIMPLEMENTATIONS="sbcl clisp clozurecl cmucl ecls gcl abcl"
18
19 # @ECLASS-VARIABLE: CLSOURCEROOT
20 # @DESCRIPTION:
21 # Default path of Common Lisp libraries sources. Sources will
22 # be installed into ${CLSOURCEROOT}/${CLPACKAGE}.
23 CLSOURCEROOT="${ROOT%/}"/usr/share/common-lisp/source
24
25 # @ECLASS-VARIABLE: CLSYSTEMROOT
26 # @DESCRIPTION:
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
31
32 # @ECLASS-VARIABLE: CLPACKAGE
33 # @DESCRIPTION:
34 # Default package name. To override, set these after inheriting this eclass.
35 CLPACKAGE="${PN}"
36
37 PDEPEND="virtual/commonlisp"
38
39 EXPORT_FUNCTIONS src_compile src_install
40
41 # @FUNCTION: common-lisp-3_src_compile
42 # @DESCRIPTION:
43 # Since there's nothing to build in most cases, default doesn't do
44 # anything.
45 common-lisp-3_src_compile() {
46         true;
47 }
48
49 # @FUNCTION: absolute-path-p
50 # @DESCRIPTION:
51 # Returns true if ${1} is an absolute path.
52 absolute-path-p() {
53         [[ $# -eq 1 ]] || die "${FUNCNAME[0]} must receive one argument"
54         [[ ${1} == /* ]]
55 }
56
57 # @FUNCTION: common-lisp-install-one-source
58 # @DESCRIPTION:
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"
62
63         local fpredicate=${1}
64         local source=${2}
65         local target="${CLSOURCEROOT}/${CLPACKAGE}/${3}"
66
67         if absolute-path-p "${source}" ; then
68                 die "Cannot install files with absolute path: ${source}"
69         fi
70
71         if ${fpredicate} "${source}" ; then
72                 insinto "${target}"
73                 doins "${source}" || die "Failed to install ${source} into $(dirname "${target}")"
74         fi
75 }
76
77 # @FUNCTION: lisp-file-p
78 # @DESCRIPTION:
79 # Returns true if ${1} is lisp source file.
80 lisp-file-p() {
81         [[ $# -eq 1 ]] || die "${FUNCNAME[0]} must receive one argument"
82
83         [[ ${1} =~ \.(lisp|lsp|cl)$ ]]
84 }
85
86 # @FUNCTION: common-lisp-get-fpredicate
87 # @DESCRIPTION:
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"
91
92         local ftype=${1}
93         case ${ftype} in
94                 "lisp") echo "lisp-file-p" ;;
95                 "all" ) echo "true" ;;
96                 * ) die "Unknown filetype specifier ${ftype}" ;;
97         esac
98 }
99
100 # @FUNCTION: common-lisp-install-sources
101 # @USAGE: common-lisp-install-sources path [<other_paths>...]
102 # @DESCRIPTION:
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() {
107         local ftype="lisp"
108         if [[ ${1} == "-t" ]] ; then
109                 ftype=${2}
110                 shift ; shift
111         fi
112
113         [[ $# -ge 1 ]] || die "${FUNCNAME[0]} must receive one non-option argument"
114
115         local fpredicate=$(common-lisp-get-fpredicate "${ftype}")
116
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)
122                 else
123                         die "${path} is neither a regular file nor a directory"
124                 fi
125         done
126 }
127
128 # @FUNCTION: common-lisp-install-one-asdf
129 # @DESCRIPTION:
130 # Installs ${1} asdf file in CLSOURCEROOT/CLPACKAGE and symlinks it in
131 # CLSYSTEMROOT.
132 common-lisp-install-one-asdf() {
133         [[ $# != 1 ]] && die "${FUNCNAME[0]} must receive exactly one argument"
134
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})"
140 }
141
142 # @FUNCTION: common-lisp-install-asdf
143 # @USAGE: common-lisp-install-asdf path [<other_paths>...]
144 # @DESCRIPTION:
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}"
150
151         [[ $# = 0 ]] && set - ${CLSYSTEMS}
152         [[ $# = 0 ]] && set - $(find . -type f -name \*.asd)
153         for sys in "${@}" ; do
154                 common-lisp-install-one-asdf ${sys}
155         done
156 }
157
158 # @FUNCTION: common-lisp-3_src_install
159 # @DESCRIPTION:
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}
166         done
167 }
168
169 # @FUNCTION: common-lisp-find-lisp-impl
170 # @USAGE: common-lisp-find-lisp-impl
171 # @DESCRIPTION:
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
177         done
178         die "No CommonLisp implementation found"
179 }
180
181 # @FUNCTION: common-lisp-export-impl-args
182 # @USAGE: common-lisp-export-impl-args <lisp-implementation>
183 # @DESCRIPTION:
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: $#"
194         fi
195         CL_BINARY="${1}"
196         case "${CL_BINARY}" in
197                 sbcl)
198                         CL_NORC="--sysinit /dev/null --userinit /dev/null"
199                         CL_LOAD="--load"
200                         CL_EVAL="--eval"
201                         ;;
202                 clisp)
203                         CL_NORC="-norc"
204                         CL_LOAD="-i"
205                         CL_EVAL="-x"
206                         ;;
207                 clozure | clozurecl | ccl | openmcl)
208                         CL_BINARY="ccl"
209                         CL_NORC="--no-init"
210                         CL_LOAD="--load"
211                         CL_EVAL="--eval"
212                         ;;
213                 cmucl)
214                         CL_NORC="-nositeinit -noinit"
215                         CL_LOAD="-load"
216                         CL_EVAL="-eval"
217                         ;;
218                 ecl | ecls)
219                         CL_BINARY="ecl"
220                         CL_NORC="-norc"
221                         CL_LOAD="-load"
222                         CL_EVAL="-eval"
223                         ;;
224                 abcl)
225                         CL_NORC="--noinit"
226                         CL_LOAD="--load"
227                         CL_EVAL="--eval"
228                         ;;
229                 *)
230                         die "${CL_BINARY} is not supported by ${0}"
231                         ;;
232         esac
233         export CL_BINARY CL_NORC CL_LOAD CL_EVAL
234 }