d9125247b31b8385c9fe4a9ed5bff9cae4e9a3c9
[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"
28                      (find-package "SB-BSD-SOCKETS-SYSTEM"))
29              filename tmp-c-source :sb-bsd-sockets-internal)
30     (and
31      (= (run-shell-command
32          "/usr/bin/gcc -o ~S ~S" (namestring tmp-a-dot-out)
33          (namestring tmp-c-source)) 0)
34      (= (run-shell-command "~A >~A"
35                            (namestring tmp-a-dot-out)
36                            (namestring tmp-constants)) 0)
37      (compile-file tmp-constants :output-file output-file))))
38
39
40 ;;; we also have a shared library with some .o files in it
41
42 (defclass unix-dso (module) ())
43 (defun unix-name (pathname)
44   (namestring 
45    (typecase pathname
46      (logical-pathname (translate-logical-pathname pathname))
47      (t pathname))))
48
49 (defmethod asdf::input-files ((operation compile-op) (dso unix-dso))
50   (mapcar #'component-pathname (module-components dso)))
51
52 (defmethod output-files ((operation compile-op) (dso unix-dso))
53   (let ((dir (component-pathname dso)))
54     (list
55      (make-pathname :type "so"
56                     :name (car (last (pathname-directory dir)))
57                     :directory (butlast (pathname-directory dir))
58                     :defaults dir))))
59
60
61 (defmethod perform :after ((operation compile-op) (dso unix-dso))
62   (let ((dso-name (unix-name (car (output-files operation dso)))))
63     (unless (zerop
64              (run-shell-command
65               "gcc -shared -o ~S ~{~S ~}"
66               dso-name
67               (mapcar #'unix-name
68                       (mapcan (lambda (c)
69                                 (output-files operation c))
70                               (module-components dso)))))
71       (error 'operation-error :operation operation :component dso))))
72
73 ;;; if this goes into the standard asdf, it could reasonably be extended
74 ;;; to allow cflags to be set somehow
75 (defmethod output-files ((op compile-op) (c c-source-file))
76   (list 
77    (make-pathname :type "o" :defaults
78                   (component-pathname c))))
79 (defmethod perform ((op compile-op) (c c-source-file))
80   (unless
81       (= 0 (run-shell-command "/usr/bin/gcc -fPIC -o ~S -c ~S"
82                               (unix-name (car (output-files op c)))
83                               (unix-name (component-pathname c))))
84     (error 'operation-error :operation op :component c)))
85
86 (defmethod perform ((operation load-op) (c c-source-file))
87   t)
88   
89 (defmethod perform ((o load-op) (c unix-dso))
90   (let ((co (make-instance 'compile-op)))
91     (let ((filename (car (output-files co c))))
92       #+cmu (ext:load-foreign filename)
93       #+sbcl (sb-alien:load-1-foreign filename))))
94
95 (defsystem sb-bsd-sockets
96     :version "0.58"
97     :components ((:file "defpackage" :depends-on ("rt"))
98                  (:file "split" :depends-on ("defpackage"))
99                  (:file "array-data" :depends-on ("defpackage"))
100                  (:unix-dso "alien"
101                             :components ((:c-source-file "undefs")
102                                          (:c-source-file "get-h-errno")))
103                  (:file "malloc" :depends-on ("defpackage"))
104                  (:file "foreign-glue" :depends-on ("defpackage" "malloc"))
105                  (:constants-file "constants"
106                                   :pathname "constants.lisp"
107                                   :depends-on
108                                   ("def-to-lisp" "defpackage" "foreign-glue"))
109                  (:file "sockets"
110                         :depends-on ("constants" "array-data"))
111                  
112                  (:file "sockopt" :depends-on ("sockets"))
113                  (:file "inet" :depends-on ("sockets" "split"  "constants" ))
114                  (:file "unix" :depends-on ("sockets" "split" "constants" ))
115                  (:file "name-service" :depends-on ("sockets" "constants" "alien"))
116                  (:file "misc" :depends-on ("sockets" "constants"))
117
118                  (:file "rt")
119                  (:file "def-to-lisp")
120                  (:file "tests" :depends-on ("inet" "sockopt" "rt"))
121
122                  (:static-file "NEWS")
123                  ;; (:static-file "INSTALL")
124                  (:static-file "README")
125                  (:static-file "index" :pathname "index.html")
126                  (:static-file "doc" :pathname "doc.lisp")
127                  (:static-file "TODO")))
128