0.7.12.28
[sbcl.git] / contrib / sb-bsd-sockets / sb-bsd-sockets.asd
1 ;;; -*-  Lisp -*-
2
3 (defpackage #:sb-bsd-sockets-system (:use #:asdf #:cl))
4 (in-package #:sb-bsd-sockets-system)
5
6 ;;; constants.lisp requires special treatment
7
8 (defclass constants-file (cl-source-file) ())
9
10 (defmethod perform ((op compile-op) (component constants-file))
11   ;; we want to generate all our temporary files in the fasl directory
12   ;; because that's where we have write permission.  Can't use /tmp;
13   ;; it's insecure (these files will later be owned by root)
14   (let* ((output-file (car (output-files op component)))
15          (filename (component-pathname component))
16          (real-output-file
17           (if (typep output-file 'logical-pathname)
18               (translate-logical-pathname output-file)
19               (pathname output-file)))
20          (tmp-c-source (merge-pathnames #p"foo.c" real-output-file))
21          (tmp-a-dot-out (merge-pathnames #p"a.out" real-output-file))
22          (tmp-constants (merge-pathnames #p"constants.lisp-temp"
23                                          real-output-file)))
24     (princ (list filename output-file real-output-file
25                  tmp-c-source tmp-a-dot-out tmp-constants))
26     (terpri)
27     (funcall (intern "C-CONSTANTS-EXTRACT" (find-package "BSD-SOCKETS-SYSTEM"))
28              filename tmp-c-source :bsd-sockets-internal)
29     (and
30      (= (run-shell-command
31          "/usr/bin/gcc -o ~S ~S" (namestring tmp-a-dot-out)
32          (namestring tmp-c-source)) 0)
33      (= (run-shell-command "~A >~A"
34                            (namestring tmp-a-dot-out)
35                            (namestring tmp-constants)) 0)
36      (compile-file tmp-constants :output-file output-file))))
37
38
39 ;;; we also have a shared library with some .o files in it
40
41 (defclass unix-dso (module) ())
42 (defun unix-name (pathname)
43   (namestring 
44    (typecase pathname
45      (logical-pathname (translate-logical-pathname pathname))
46      (t pathname))))
47
48 (defmethod asdf::input-files ((operation compile-op) (dso unix-dso))
49   (mapcar #'component-pathname (module-components dso)))
50
51 (defmethod output-files ((operation compile-op) (dso unix-dso))
52   (let ((dir (component-pathname dso)))
53     (list
54      (make-pathname :type "so"
55                     :name (car (last (pathname-directory dir)))
56                     :directory (butlast (pathname-directory dir))
57                     :defaults dir))))
58
59
60 (defmethod perform :after ((operation compile-op) (dso unix-dso))
61   (let ((dso-name (unix-name (car (output-files operation dso)))))
62     (unless (zerop
63              (run-shell-command
64               "gcc -shared -o ~S ~{~S ~}"
65               dso-name
66               (mapcar #'unix-name
67                       (mapcan (lambda (c)
68                                 (output-files operation c))
69                               (module-components dso)))))
70       (error 'operation-error :operation operation :component dso))))
71
72 ;;; if this goes into the standard asdf, it could reasonably be extended
73 ;;; to allow cflags to be set somehow
74 (defmethod output-files ((op compile-op) (c c-source-file))
75   (list 
76    (make-pathname :type "o" :defaults
77                   (component-pathname c))))
78 (defmethod perform ((op compile-op) (c c-source-file))
79   (unless
80       (= 0 (run-shell-command "/usr/bin/gcc -fPIC -o ~S -c ~S"
81                               (unix-name (car (output-files op c)))
82                               (unix-name (component-pathname c))))
83     (error 'operation-error :operation op :component c)))
84
85 (defmethod perform ((operation load-op) (c c-source-file))
86   t)
87   
88 (defmethod perform ((o load-op) (c unix-dso))
89   (let ((co (make-instance 'compile-op)))
90     (let ((filename (car (output-files co c))))
91       #+cmu (ext:load-foreign filename)
92       #+sbcl (sb-alien:load-1-foreign filename))))
93
94 (defsystem bsd-sockets
95     :version "0.58"
96     :components ((:file "defpackage" :depends-on ("rt"))
97                  (:file "split" :depends-on ("defpackage"))
98                  (:file "array-data" :depends-on ("defpackage"))
99                  (:unix-dso "alien"
100                             :components ((:c-source-file "undefs")
101                                          (:c-source-file "get-h-errno")))
102                  (:file "malloc" :depends-on ("defpackage"))
103                  (:file "foreign-glue" :depends-on ("defpackage" "malloc"))
104                  (:constants-file "constants"
105                                   :pathname "constants.lisp"
106                                   :depends-on
107                                   ("def-to-lisp" "defpackage" "foreign-glue"))
108                  (:file "sockets"
109                         :depends-on ("constants" "array-data"))
110                  
111                  (:file "sockopt" :depends-on ("sockets"))
112                  (:file "inet" :depends-on ("sockets" "split"  "constants" ))
113                  (:file "unix" :depends-on ("sockets" "split" "constants" ))
114                  (:file "name-service" :depends-on ("sockets" "constants" "alien"))
115                  (:file "misc" :depends-on ("sockets" "constants"))
116
117                  (:file "rt")
118                  (:file "def-to-lisp")
119                  (:file "tests" :depends-on ("inet" "sockopt" "rt"))
120
121                  (:static-file "NEWS")
122                  (:static-file "INSTALL")
123                  (:static-file "README")
124                  (:static-file "index" :pathname "index.html")
125                  (:static-file "doc" :pathname "doc.lisp")
126                  (:static-file "TODO")))
127