diff --git a/cclan.lisp b/cclan.lisp
index e9044a502e90da1b04f38c6c80e701f7f5a240ec..ca903efcf4ff42d031a923ffb03f7506b6c22198 100644
--- a/cclan.lisp
+++ b/cclan.lisp
@@ -112,7 +112,7 @@ install: build
 	dh_clean -k
 	dh_installdirs
 
-	$(MAKE) -f Makefile.cCLan-deb install DESTDIR=($CURDIR)/debian/~A
+	$(MAKE) -f Makefile.cCLan-deb install DESTDIR=$(CURDIR)/debian/~A
 
 binary-indep: build install
 
@@ -137,7 +137,140 @@ binary-arch: build install
 binary: binary-indep binary-arch
 .PHONY: build clean binary-indep binary-arch binary install configure
 " (component-name system) changelog-file-name)))
-    
+
+(defun write-debian-control (stream system)
+  (format stream "Source: ~A
+Section: devel
+Priority: optional
+Maintainer: ~A
+Build-Depends: debhelper (>> 3.0.0)
+Standards-Version: 3.5.2
+
+Package: ~A
+Architecture: all
+Depends: common-lisp-controller~{~^, ~A~}
+Description: ~A
+ ~{~<~% ~1:;~A ~>~}
+"
+	  ;; FIXME: Clearly this argument list is not
+	  ;; sustainable. Also the split should be split-sequence,
+	  ;; clearly.
+	  (component-name system) (infix-system::debian-maintainer system) (component-name system) (infix-system::debian-dependencies system) (infix-system::short-description system) (asdf::split (infix-system::long-description system))))
+
+(defun write-debian-prerm (stream system)
+  (format stream "#! /bin/sh
+# prerm script for ~A.
+set -e
+case \"$1\" in
+  remove|upgrade|deconfigure)
+    unregister-common-lisp-source ~A
+    ;;
+  failed-upgrade)
+    ;;
+  *)
+    echo \"prerm called with unknown argument \\`$1'\" >&2
+    exit 1
+    ;;
+esac
+
+# dh_installdeb will replace this with shell code automatically
+# generated by other debhelper scripts.
+
+#DEBHELPER#
+
+exit 0
+"
+    (component-name system) (component-name system)))
+
+(defun write-debian-postrm (stream system)
+  (format stream "#! /bin/sh
+# postrm for ~A.
+set -e
+case \"$1\" in
+  purge|remove|upgrade|failed-upgrade|abort-install|abort-upgrade|disappear)
+    rm -f /usr/share/common-lisp/source/~A
+    ;;
+  *)
+    echo \"postrm called with unknown argument \\`$1'\" >&2
+    exit 1
+
+esac
+
+# dh_installdeb will replace this with shell code automatically
+# generated by other debhelper scripts.
+
+#DEBHELPER#
+
+exit 0
+" (component-name system) (component-name system)))
+
+(defun write-debian-postinst (stream system)
+  (format stream "#! /bin/sh
+# postinst script for ~A.
+set -e
+case \"$1\" in
+  configure)
+    ln -sf /usr/share/common-lisp/repositories/~:*~A \\
+      /usr/share/common-lisp/source/~:*~A
+    register-common-lisp-source ~:*~A
+  ;;
+  abort-upgrade|abort-remove|abort-deconfigure)
+    unregister-common-lisp-source ~:*~A
+    rm -f /usr/share/common-lisp/source/~:*~A
+  ;;
+  *)
+    echo \"postinst called with unknown argument \\`$1'\" >&2
+    exit 1
+  ;;
+esac
+
+#DEBHELPER#
+exit 0
+" (component-name system)))
+
+(defun print-debian-date (stream arg colonp atsignp &rest params)
+  (declare (ignore colonp atsignp params))
+  (multiple-value-bind (sec min hr day mon year dow dst tz)
+      (decode-universal-time arg)
+    (format stream "~[Mon~;Tue~;Wed~;Thu~;Fri~;Sat~;Sun~], ~
+~d ~[Jan~;Feb~;Mar~;Apr~;May~;Jun~;Jul~;Aug~;Sep~;Oct~;Nov~;Dec~] ~d ~
+~2,'0d:~2,'0d:~2,'0d ~:[+~;-~]~4,'0d"
+	    dow
+	    day
+	    (1- mon)
+	    year
+	    hr min sec
+	    (minusp tz)
+	    ;; FIXME: I'm sure this is wrong
+	    (+ (* (truncate tz) 100) (mod (* tz 60) 60)))))
+		     
+
+(defun write-debian-changelog (stream system)
+  (format stream "~A (~A-1) cclan; urgency=low
+
+  * Package generated by cCLan scripts
+
+ -- ~A  ~/cclan:print-debian-date/
+" (component-name system) (component-version system) (infix-system::debian-maintainer system) (get-universal-time)))
+
+(defun write-debian-dirs (stream system)
+  (format stream "~
+/usr/share/doc/~A
+/usr/share/common-lisp/systems
+/usr/share/common-lisp/repositories/~:*~A
+" (component-name system)))
+
+(defun write-deb-install-makefile (stream system)
+  (let ((components (all-components system))
+	(*default-pathname-defaults* (component-pathname system)))
+    (format stream "install:
+	install -m 644 ~A $(DESTDIR)/usr/share/common-lisp/systems/
+~{	install -m 644 ~A $(DESTDIR)/usr/share/common-lisp/repositories/~A~%~}"
+	    (enough-namestring (component-pathname (find 'mk-defsystem-source-file components :key #'class-name-of :test #'string=)))
+	    (loop for x in components
+		  when (typep x 'cl-source-file)
+		    collect (enough-namestring (component-pathname x))
+		    and collect (format nil "~A/~A" (component-name system) (enough-namestring (component-pathname x)))))))
 
 (defun make-debian-package (system)
   "Make a Debian package, compliant with Debian policy in as much as
@@ -152,13 +285,39 @@ that is possible, containing the system named in SYSTEM.  The file will be produ
 		       :direction :output
 		       :if-exists :supersede)
       (write-debian-rules s system))
-	      
-    ;; write debian/control
-    ;; write debian/preinst, postinst, prerm, postrm.
-    ;; write debian/changelog
-
-    ;; write Makefile.cCLan-deb
-    ;; chmod +x debian/rules
-    ;; ln -s copyright-source-file debian/copyright
-    ;; call dpkg-buildpackage -us -uc -rfakeroot -b
+    (with-open-file (s (merge-pathnames "control" debian-directory)
+		       :direction :output
+		       :if-exists :supersede)
+      (write-debian-control s system))
+    (with-open-file (s (merge-pathnames "postinst" debian-directory)
+		       :direction :output
+		       :if-exists :supersede)
+      (write-debian-postinst s system))
+    (with-open-file (s (merge-pathnames "prerm" debian-directory)
+		       :direction :output
+		       :if-exists :supersede)
+      (write-debian-prerm s system))
+    (with-open-file (s (merge-pathnames "postrm" debian-directory)
+		       :direction :output
+		       :if-exists :supersede)
+      (write-debian-postrm s system))
+    (with-open-file (s (merge-pathnames "changelog" debian-directory)
+		       :direction :output
+		       :if-exists :supersede)
+      (write-debian-changelog s system))
+    (with-open-file (s (merge-pathnames "dirs" debian-directory)
+		       :direction :output
+		       :if-exists :supersede)
+      (write-debian-dirs s system))
+    (with-open-file (s (merge-pathnames "Makefile.cCLan-deb" path)
+		       :direction :output
+		       :if-exists :supersede)
+      (write-deb-install-makefile s system))
+    (run-shell-command "cd ~A && chmod +x rules"
+		       (directory-namestring debian-directory))
+    (run-shell-command "cd ~A && ln -s ~A copyright"
+		       (directory-namestring debian-directory)
+		       (namestring (component-pathname (find 'licence-source-file components :key #'class-name-of :test #'string=))))
+    (run-shell-command "cd ~A && dpkg-buildpackage -us -uc -rfakeroot -b"
+		       (directory-namestring path))
     ))