common-lisp-3.eclass: Updates header info
[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() { true; }
45
46 # @FUNCTION: absolute-path-p
47 # @DESCRIPTION:
48 # Returns true if ${1} is an absolute path.
49 absolute-path-p() {
50         [[ $# -eq 1 ]] || die "${FUNCNAME[0]} must receive one argument"
51         [[ ${1} == /* ]]
52 }
53
54 # @FUNCTION: common-lisp-install-one-source
55 # @DESCRIPTION:
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"
59
60         local fpredicate=${1}
61         local source=${2}
62         local target="${CLSOURCEROOT}/${CLPACKAGE}/${3}"
63
64         if absolute-path-p "${source}" ; then
65                 die "Cannot install files with absolute path: ${source}"
66         fi
67
68         if ${fpredicate} "${source}" ; then
69                 insinto "${target}"
70                 doins "${source}" || die "Failed to install ${source} into $(dirname "${target}")"
71         fi
72 }
73
74 # @FUNCTION: lisp-file-p
75 # @DESCRIPTION:
76 # Returns true if ${1} is lisp source file.
77 lisp-file-p() {
78         [[ $# -eq 1 ]] || die "${FUNCNAME[0]} must receive one argument"
79
80         [[ ${1} =~ \.(lisp|lsp|cl)$ ]]
81 }
82
83 # @FUNCTION: common-lisp-get-fpredicate
84 # @DESCRIPTION:
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"
88
89         local ftype=${1}
90         case ${ftype} in
91                 "lisp") echo "lisp-file-p" ;;
92                 "all" ) echo "true" ;;
93                 * ) die "Unknown filetype specifier ${ftype}" ;;
94         esac
95 }
96
97 # @FUNCTION: common-lisp-install-sources
98 # @USAGE: common-lisp-install-sources path [<other_paths>...]
99 # @DESCRIPTION:
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() {
104         local ftype="lisp"
105         if [[ ${1} == "-t" ]] ; then
106                 ftype=${2}
107                 shift ; shift
108         fi
109
110         [[ $# -ge 1 ]] || die "${FUNCNAME[0]} must receive one non-option argument"
111
112         local fpredicate=$(common-lisp-get-fpredicate "${ftype}")
113
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)
119                 else
120                         die "${path} it neither a regular file nor a directory"
121                 fi
122         done
123 }
124
125 # @FUNCTION: common-lisp-install-one-asdf
126 # @DESCRIPTION:
127 # Installs ${1} asdf file in CLSOURCEROOT/CLPACKAGE and symlinks it in
128 # CLSYSTEMROOT.
129 common-lisp-install-one-asdf() {
130         [[ $# != 1 ]] && die "${FUNCNAME[0]} must receive exactly one argument"
131
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})"
137 }
138
139 # @FUNCTION: common-lisp-install-asdf
140 # @USAGE: common-lisp-install-asdf path [<other_paths>...]
141 # @DESCRIPTION:
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}"
147
148         [[ $# = 0 ]] && set - ${CLSYSTEMS}
149         [[ $# = 0 ]] && set - $(find . -type f -name \*.asd)
150         for sys in "${@}" ; do
151                 common-lisp-install-one-asdf ${sys}
152         done
153 }
154
155 # @FUNCTION: common-lisp-3_src_install
156 # @DESCRIPTION:
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}
163         done
164 }
165
166 # @FUNCTION: common-lisp-export-impl-args
167 # @USAGE: common-lisp-export-impl-args <lisp-implementation>
168 # @DESCRIPTION:
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: $#"
178         fi
179         case ${1} in
180                 clisp)
181                         CL_NORC="-norc"
182                         CL_LOAD="-i"
183                         CL_EVAL="-x"
184                         ;;
185                 clozure | ccl | openmcl)
186                         CL_NORC="--no-init"
187                         CL_LOAD="--load"
188                         CL_EVAL="--eval"
189                         ;;
190                 cmucl)
191                         CL_NORC="-nositeinit -noinit"
192                         CL_LOAD="-load"
193                         CL_EVAL="-eval"
194                         ;;
195                 ecl)
196                         CL_NORC="-norc"
197                         CL_LOAD="-load"
198                         CL_EVAL="-eval"
199                         ;;
200                 sbcl)
201                         CL_NORC="--sysinit /dev/null --userinit /dev/null"
202                         CL_LOAD="--load"
203                         CL_EVAL="--eval"
204                         ;;
205                 *)
206                         die ${1} is not supported by ${0}
207                         ;;
208         esac
209         export CL_NORC CL_LOAD CL_EVAL
210 }