Protect against error in user home directory computation
[clon.git] / com.dvlsoft.clon.asd
blob57a0f932231b2fe534d5818cb052707de25db08f
1 ;;; com.dvlsoft.clon.asd --- ASDF system definition
3 ;; Copyright (C) 2010, 2011, 2012 Didier Verna.
5 ;; Author:     Didier Verna <didier@lrde.epita.fr>
6 ;; Maintainer: Didier Verna <didier@lrde.epita.fr>
8 ;; This file is part of clon.
10 ;; Permission to use, copy, modify, and distribute this software for any
11 ;; purpose with or without fee is hereby granted, provided that the above
12 ;; copyright notice and this permission notice appear in all copies.
14 ;; THIS SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
15 ;; WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
16 ;; MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
17 ;; ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
18 ;; WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
19 ;; ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
20 ;; OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
23 ;;; Commentary:
25 ;; Contents management by FCM version 0.1.
28 ;;; Code:
30 (in-package :cl-user)
33 ;; ------------------
34 ;; Package definition
35 ;; ------------------
37 (defpackage :com.dvlsoft.clon.asdf
38   (:documentation "The Command-Line Options Nuker package for ASDF.")
39   (:use :cl))
41 (in-package :com.dvlsoft.clon.asdf)
44 ;; --------------------
45 ;; Very early utilities
46 ;; --------------------
48 ;; Configuration
50 (defvar cl-user::com.dvlsoft.clon.configuration nil
51   "The Clon configuration settings.
52 This variable contains a property list of configuration options.
53 Current options are:
54 - :swank-eval-in-emacs (Boolean)
55 - :restricted (Boolean)
56 - :dump (Boolean)
58 See section A.1 of the user manual for more information.")
60 (defun configuration (key)
61   "Return KEY's value in the current Clon configuration."
62   (getf cl-user::com.dvlsoft.clon.configuration key))
64 (defun set-configuration (key value)
65   "Set KEY to VALUE in the current Clon configuration."
66   (setf (getf cl-user::com.dvlsoft.clon.configuration key) value))
68 (defsetf configuration set-configuration)
71 ;; Versionning
73 (defmacro define-constant (name value &optional doc)
74   `(defconstant ,name (if (boundp ',name) (symbol-value ',name) ,value)
75      ,@(when doc (list doc))))
77 (defconstant +release-major-level+ 1
78   "The major level of this release.")
80 (defconstant +release-minor-level+ 0
81   "The minor level of this release.")
83 (defconstant +release-status+ :beta
84   "The status of this release.")
86 (defconstant +release-status-level+ 23
87   "The status level of this release.")
89 (define-constant +release-name+ "Michael Brecker"
90   "The name of this release.")
92 ;; #### TODO: I'm sure the format strings can be improved
93 (defun %version (type major minor status level name)
94   (ecase type
95     (:number
96      (apply #'+
97        (* major 10000)
98        (* minor 100)
99        (when (eq status :patchlevel)
100          (list level))))
101     (:short
102      (format nil "~S.~S~
103                  ~[~
104                    a~*~S~;~
105                    b~*~S~;~
106                    rc~*~S~;~
107                    ~:[.~S~;~*~]~
108                  ~]"
109        major
110        minor
111        (ecase status
112          (:alpha 0)
113          (:beta 1)
114          (:rc 2)
115          (:patchlevel 3))
116        (zerop level)
117        level))
118     (:long
119      (format nil "~S.~S ~
120                  ~[~
121                    alpha ~*~S ~;~
122                    beta ~*~S ~;~
123                    release candidate ~*~S ~;~
124                    ~:[patchlevel ~S ~;~*~]~
125                  ~]~
126                  ~S"
127        major
128        minor
129        (ecase status
130          (:alpha 0)
131          (:beta 1)
132          (:rc 2)
133          (:patchlevel 3))
134        (zerop level)
135        level
136        name))))
138 (defun version (&optional (type :number))
139   "Return the current version of Clon.
140 TYPE can be one of :number, :short or :long.
142 A version number is computed as major*10000 + minor*100 + patchlevel, leaving
143 two digits for each level. Alpha, beta and rc status are ignored in version
144 numbers.
146 A short version is something like 1.3{a,b,rc}4, or 1.3.4 for patchlevel.
147 Alpha, beta or rc levels start at 1. Patchlevels start at 0 but are ignored
148 in the output, so that 1.3.0 appears as just 1.3.
150 A long version is something like
151 1.3 {alpha,beta,release candidate,patchlevel} 4 \"Michael Brecker\". As for
152 the short version, a patchlevel of 0 is ignored in the output."
153   (%version type +release-major-level+ +release-minor-level+
154             +release-status+ +release-status-level+
155             +release-name+))
158 ;; -------------------
159 ;; System requirements
160 ;; -------------------
162 (defun restrict-because (reason)
163   "Put Clon in restricted mode because of REASON."
164   (format *error-output* "~
165 *******************************************************************
166 * WARNING: ~A.~66T*
167 * Clon will be loaded without support for terminal autodetection. *
168 * See sections 2 and A.1 of the user manual for more information. *
169 *******************************************************************"
170     reason)
171   (setf (configuration :restricted) t))
173 (unless (configuration :restricted)
174   #+sbcl
175   (progn
176     (require :sb-posix)
177     (unless (funcall (intern "GETENV" :sb-posix) "CC")
178       (restrict-because "the CC environment variable is not set"))
179     (handler-case (asdf:load-system :sb-grovel)
180       (error ()
181         (restrict-because "unable to load module SB-GROVEL"))))
182   #+clisp
183   (cond ((member :ffi *features*)
184          (handler-case (asdf:load-system :cffi-grovel)
185            (error ()
186              (restrict-because
187               "unable to load ASDF component CFFI-GROVEL"))))
188         (t
189          (restrict-because
190           "CLISP is compiled without FFI support")))
191   #+(or allegro lispworks)
192   (handler-case (asdf:load-system :cffi-grovel)
193     (error ()
194       (restrict-because
195        "unable to load ASDF component CFFI-GROVEL")))
196   #+abcl
197   (restrict-because "ABCL is in use"))
199 (if (configuration :restricted)
200     (setq *features* (delete  :com.dvlsoft.clon.termio *features*))
201   (pushnew :com.dvlsoft.clon.termio *features*))
204 ;; -----------------
205 ;; System definition
206 ;; -----------------
208 (asdf:defsystem :com.dvlsoft.clon
209   :description "The Command-Line Options Nuker."
210   :long-description "Clon is a library for command-line option management.
211 It is intended to ease the creation of standalone Common Lisp applications by
212 providing a powerful and uniform command-line option interface.
213 The most important features of Clon are:
214 - [from the programmer's point of view] Centralized command-line options
215   specification and management, including automatic generation of help
216   strings, conversion from command-line / environment strings to
217   application-level option values, global or on-demand option retrieval, and
218   extensibility (the programmer can define his own option types).
219 - [from the end-user's point of view] Uniform command-line option syntax
220   across Clonified applications, including customization of the help strings
221   layout (with optional ISO6429 coloring on terminals that support it),
222   possibly abbreviated option calls and short/long syntax."
223   :author "Didier Verna <didier@lrde.epita.fr>"
224   :maintainer "Didier Verna <didier@lrde.epita.fr>"
225   :license "BSD"
226   :version #.(version :short)
227   :depends-on (#+sbcl :sb-posix
228                #+(and clisp com.dvlsoft.clon.termio) :cffi)
229   :serial t
230   :components ((:file "package")
231                #+com.dvlsoft.clon.termio
232                (:module "termio"
233                 :serial t
234                 :components
235                 (#+sbcl
236                  (:module "sbcl"
237                   :components ((sb-grovel:grovel-constants-file "constants"
238                                 :package :com.dvlsoft.clon)))
239                  #+(or clisp allegro lispworks)
240                  (:module "cffi"
241                   :components ((cffi-grovel:grovel-file "constants")))
242                  (:file "termio")))
243                (:module "src"
244                 :depends-on (#+com.dvlsoft.clon.termio "termio")
245                 :components ((:file "util")
246                              (:file "item" :depends-on ("util"))
247                              (:file "text" :depends-on ("item"))
248                              (:module "options"
249                               :depends-on ("text")
250                               :components ((:file "option")
251                                            (:file "flag"
252                                             :depends-on ("option"))
253                                            (:file "valued"
254                                             :depends-on ("option"))
255                                            (:file "negatable"
256                                             :depends-on ("valued"))
257                                            (:file "switch-base"
258                                             :depends-on ("negatable"))
259                                            (:file "switch"
260                                             :depends-on
261                                                   ("switch-base"))
262                                            (:file "stropt"
263                                             :depends-on ("valued"))
264                                            (:file "lispobj"
265                                             :depends-on ("valued"))
266                                            (:file "path"
267                                             :depends-on ("valued"))
268                                            (:file "enum-base")
269                                            (:file "enum"
270                                             :depends-on
271                                                   ("valued"
272                                                    "enum-base"))
273                                            (:file
274                                             "xswitch"
275                                             :depends-on ("valued"
276                                                          "switch-base"
277                                                          "enum-base"))))
278                              (:file "container" :depends-on ("options"))
279                              (:file "group" :depends-on ("container"))
280                              (:module "retrieval"
281                               :depends-on ("options")
282                               :components ((:file "cmdline")
283                                            (:file "environ")))
284                              (:file "synopsis" :depends-on ("group"))
285                              (:module "output"
286                               :depends-on ("synopsis" "retrieval")
287                               :components ((:file "face")
288                                            (:file "sheet"
289                                             :depends-on ("face"))))
290                              (:file "context"
291                               :depends-on ("output"))))))
294 ;;; com.dvlsoft.clon.asd ends here