common-lisp-3.eclass: Adds missing lisp package names and exports CL_BINARY variable
[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 # CL packages in the overlay don't have their tarballs on the mirrors
15 # so it's useless to mirror them
16 RESTRICT="mirror"
17
18 # @ECLASS-VARIABLE: CLSOURCEROOT
19 # @DESCRIPTION:
20 # Default path of Common Lisp libraries sources. Sources will
21 # be installed into ${CLSOURCEROOT}/${CLPACKAGE}.
22 CLSOURCEROOT="${ROOT%/}"/usr/share/common-lisp/source
23
24 # @ECLASS-VARIABLE: CLSYSTEMROOT
25 # @DESCRIPTION:
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
30
31 # @ECLASS-VARIABLE: CLPACKAGE
32 # @DESCRIPTION:
33 # Default package name. To override, set these after inheriting this eclass.
34 CLPACKAGE="${PN}"
35
36 PDEPEND="virtual/commonlisp"
37
38 EXPORT_FUNCTIONS src_compile src_install
39
40 # @FUNCTION: common-lisp-3_src_compile
41 # @DESCRIPTION:
42 # Since there's nothing to build in most cases, default doesn't do
43 # anything.
44 common-lisp-3_src_compile() {
45         true;
46 }
47
48 # @FUNCTION: absolute-path-p
49 # @DESCRIPTION:
50 # Returns true if ${1} is an absolute path.
51 absolute-path-p() {
52         [[ $# -eq 1 ]] || die "${FUNCNAME[0]} must receive one argument"
53         [[ ${1} == /* ]]
54 }
55
56 # @FUNCTION: common-lisp-install-one-source
57 # @DESCRIPTION:
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"
61
62         local fpredicate=${1}
63         local source=${2}
64         local target="${CLSOURCEROOT}/${CLPACKAGE}/${3}"
65
66         if absolute-path-p "${source}" ; then
67                 die "Cannot install files with absolute path: ${source}"
68         fi
69
70         if ${fpredicate} "${source}" ; then
71                 insinto "${target}"
72                 doins "${source}" || die "Failed to install ${source} into $(dirname "${target}")"
73         fi
74 }
75
76 # @FUNCTION: lisp-file-p
77 # @DESCRIPTION:
78 # Returns true if ${1} is lisp source file.
79 lisp-file-p() {
80         [[ $# -eq 1 ]] || die "${FUNCNAME[0]} must receive one argument"
81
82         [[ ${1} =~ \.(lisp|lsp|cl)$ ]]
83 }
84
85 # @FUNCTION: common-lisp-get-fpredicate
86 # @DESCRIPTION:
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"
90
91         local ftype=${1}
92         case ${ftype} in
93                 "lisp") echo "lisp-file-p" ;;
94                 "all" ) echo "true" ;;
95                 * ) die "Unknown filetype specifier ${ftype}" ;;
96         esac
97 }
98
99 # @FUNCTION: common-lisp-install-sources
100 # @USAGE: common-lisp-install-sources path [<other_paths>...]
101 # @DESCRIPTION:
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() {
106         local ftype="lisp"
107         if [[ ${1} == "-t" ]] ; then
108                 ftype=${2}
109                 shift ; shift
110         fi
111
112         [[ $# -ge 1 ]] || die "${FUNCNAME[0]} must receive one non-option argument"
113
114         local fpredicate=$(common-lisp-get-fpredicate "${ftype}")
115
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)
121                 else
122                         die "${path} is neither a regular file nor a directory"
123                 fi
124         done
125 }
126
127 # @FUNCTION: common-lisp-install-one-asdf
128 # @DESCRIPTION:
129 # Installs ${1} asdf file in CLSOURCEROOT/CLPACKAGE and symlinks it in
130 # CLSYSTEMROOT.
131 common-lisp-install-one-asdf() {
132         [[ $# != 1 ]] && die "${FUNCNAME[0]} must receive exactly one argument"
133
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})"
139 }
140
141 # @FUNCTION: common-lisp-install-asdf
142 # @USAGE: common-lisp-install-asdf path [<other_paths>...]
143 # @DESCRIPTION:
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}"
149
150         [[ $# = 0 ]] && set - ${CLSYSTEMS}
151         [[ $# = 0 ]] && set - $(find . -type f -name \*.asd)
152         for sys in "${@}" ; do
153                 common-lisp-install-one-asdf ${sys}
154         done
155 }
156
157 # @FUNCTION: common-lisp-3_src_install
158 # @DESCRIPTION:
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}
165         done
166 }
167
168 # @FUNCTION: common-lisp-export-impl-args
169 # @USAGE: common-lisp-export-impl-args <lisp-implementation>
170 # @DESCRIPTION:
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: $#"
181         fi
182         CL_BINARY="${1}"
183         case "${CL_BINARY}" in
184                 clisp)
185                         CL_NORC="-norc"
186                         CL_LOAD="-i"
187                         CL_EVAL="-x"
188                         ;;
189                 clozure | clozurecl | ccl | openmcl)
190                         CL_BINARY="ccl"
191                         CL_NORC="--no-init"
192                         CL_LOAD="--load"
193                         CL_EVAL="--eval"
194                         ;;
195                 cmucl)
196                         CL_NORC="-nositeinit -noinit"
197                         CL_LOAD="-load"
198                         CL_EVAL="-eval"
199                         ;;
200                 ecl | ecls)
201                         CL_BINARY="ecl"
202                         CL_NORC="-norc"
203                         CL_LOAD="-load"
204                         CL_EVAL="-eval"
205                         ;;
206                 sbcl)
207                         CL_NORC="--sysinit /dev/null --userinit /dev/null"
208                         CL_LOAD="--load"
209                         CL_EVAL="--eval"
210                         ;;
211                 *)
212                         die "${CL_BINARY} is not supported by ${0}"
213                         ;;
214         esac
215         export CL_BINARY CL_NORC CL_LOAD CL_EVAL
216 }