3 (defpackage #:sb-bsd-sockets-system (:use #:asdf #:cl))
4 (in-package #:sb-bsd-sockets-system)
6 ;;; constants.lisp requires special treatment
8 (defclass constants-file (cl-source-file) ())
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))
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"
24 (princ (list filename output-file real-output-file
25 tmp-c-source tmp-a-dot-out tmp-constants))
27 (funcall (intern "C-CONSTANTS-EXTRACT"
28 (find-package "SB-BSD-SOCKETS-SYSTEM"))
29 filename tmp-c-source :sb-bsd-sockets-internal)
31 (= (run-shell-command "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))))
39 ;;; we also have a shared library with some .o files in it
41 (defclass unix-dso (module) ())
42 (defun unix-name (pathname)
45 (logical-pathname (translate-logical-pathname pathname))
48 (defmethod asdf::input-files ((operation compile-op) (dso unix-dso))
49 (mapcar #'component-pathname (module-components dso)))
51 (defmethod output-files ((operation compile-op) (dso unix-dso))
52 (let ((dir (component-pathname dso)))
54 (make-pathname :type "so"
55 :name (car (last (pathname-directory dir)))
56 :directory (butlast (pathname-directory dir))
60 (defmethod perform :after ((operation compile-op) (dso unix-dso))
61 (let ((dso-name (unix-name (car (output-files operation dso)))))
64 #+sunos "gcc -shared -lresolv -lsocket -lnsl -o ~S ~{~S ~}"
65 #-sunos "gcc -shared -o ~S ~{~S ~} "
69 (output-files operation c))
70 (module-components dso)))))
71 (error 'operation-error :operation operation :component dso))))
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))
77 (make-pathname :type "o" :defaults
78 (component-pathname c))))
79 (defmethod perform ((op compile-op) (c c-source-file))
81 (= 0 (run-shell-command "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)))
86 (defmethod perform ((operation load-op) (c c-source-file))
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))))
95 (defsystem sb-bsd-sockets
97 :components ((:file "defpackage" :depends-on ("rt"))
98 (:file "split" :depends-on ("defpackage"))
99 (:file "array-data" :depends-on ("defpackage"))
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"
108 ("def-to-lisp" "defpackage" "foreign-glue"))
110 :depends-on ("constants" "array-data"))
112 (:file "sockopt" :depends-on ("sockets"))
113 (:file "inet" :depends-on ("sockets" "split" "constants" ))
114 (:file "local" :depends-on ("sockets" "split" "constants" ))
115 (:file "name-service" :depends-on ("sockets" "constants" "alien"))
116 (:file "misc" :depends-on ("sockets" "constants"))
119 (:file "def-to-lisp")
120 (:file "tests" :depends-on ("inet" "sockopt" "rt"))
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")))
129 (defmethod perform ((o test-op) (c (eql (find-system :sb-bsd-sockets))))
130 (or (funcall (intern "DO-TESTS" (find-package "RT")))
131 (error "test-op failed")))