Skip to content
Snippets Groups Projects
cclan.lisp 5.18 KiB
Newer Older
(in-package :cclan)

;;;; This file contains functions, classes etc that are not part of
;;;; asdf itself, but extend it in various ways useful for maintainers
;;;; of new-style cCLan packages

;;;; The public interface consists of the functions whose symbols are 
;;;; exported from the package

;;;; This file does not contain references to asdf internals - or
;;;; shouldn't, anyway.  Send bug reports

    
(defun mapappend (function list)
  (let ((f (coerce function 'function)))
    (loop for i in list append (funcall f i))))

(defgeneric all-components (component))
(defmethod all-components ((source-file source-file))
  (list source-file))

(defmethod all-components ((module module))
  (cons module (mapappend #'all-components (module-components module))))

(defmethod all-components ((module symbol))
  (all-components (find-system module)))

(defun cvs-tag (system)
  (let* ((system (find-system system))
	 (directory (component-pathname system))
	 (version (component-version system)))
    (run-shell-command "cd ~A && cvs tag -F cclan_version_~A"
		       (namestring directory)
		       (substitute #\_ #\. version))))
(defun write-readme-file (stream suggested-registry system-name)
  "Write a README.install file detailing a possible sequence of commands to use the newly-untarred system."
  (format stream "~
1.  Make a symlink in ~W[*] pointing to the .asd file
2.  Start your asdf-enabled lisp
2a. Ensure that ~W[*] is in asdf:*central-registry*
3.  At the lisp prompt, type '(asdf:oos 'asdf:load-op ~W)'. This
    will compile and load the system into your running lisp.

[*] This path (~W) is only a suggestion; the important
thing is that asdf know where to find the .asd file. Adsf uses the
contents of the variable ASDF:*CENTRAL-REGISTRY* to find its system
definitions.

These instructions were automatically generated by cCLan software. Use
at your own peril.~%" suggested-registry suggested-registry system-name suggested-registry))


(defun make-tar-file (system)
  "Make a tar file named SYSTEM-NAME_VERSION.tar containing all the files in SYSTEM.  The file is created in the directory containing the system directory.  Returns T on success"
  (let* ((system (find-system system))
	 (sys-path  (component-pathname system))
	 (base-path (make-pathname
		     :directory (butlast (pathname-directory sys-path))
		     :defaults sys-path))
	 (readme-path (make-pathname 
		       :directory (pathname-directory sys-path)
		       :name "README"
		       :type "cCLan-install"))
	 (files
	  (mapcar (lambda (x) (enough-namestring x base-path))
		   (truename (system-definition-pathname system))
		   (mapcar #'component-pathname (all-components system))))))
    (with-open-file (s readme-path :direction :output :if-exists :supersede)
      (write-readme-file s "~/lisp-systems/" (component-name system)))
    (= 0
       (run-shell-command "cd ~A && tar cf ~A_~A.tar  ~{~D ~}"
			  (namestring base-path)
			  (component-name system)
			  (component-version system)			  
			  (remove-if-not #'pathname-name files)))))
(defun class-name-of (x)
  (class-name (class-of x)))

(defun write-debian-rules (stream system)
  (let ((changelog-file-name (enough-namestring
			      (component-pathname (find 'changelog-source-file (all-components system) :key #'class-name-of :test #'string=))
			      (component-pathname system))))
    (format stream "#!/usr/bin/make -f
# debian/rules generated by cCLan tools

# This is the debhelper compatibility version to use.
export DH_COMPAT=3

configure: configure-stamp
configure-stamp:
	dh_testdir
	touch configure-stamp

build: build-stamp
build-stamp:
	dh_testdir
	touch build-stamp

clean:
	dh_testdir
	dh_testroot
	rm -f build-stamp configure-stamp
	dh_clean

install: build
	dh_testdir
	dh_testroot
	dh_clean -k
	dh_installdirs

	$(MAKE) -f Makefile.cCLan-deb install DESTDIR=($CURDIR)/debian/~A

binary-indep: build install

binary-arch: build install
	dh_testdir
	dh_testroot
	dh_installdocs
	dh_installexamples
	dh_installman
	dh_installinfo
	dh_installchangelogs ~A
	dh_link
	dh_strip
	dh_compress
	dh_fixperms
	dh_installdeb
	dh_shlibdeps
	dh_gencontrol
	dh_md5sums
	dh_builddeb

binary: binary-indep binary-arch
.PHONY: build clean binary-indep binary-arch binary install configure
" (component-name system) changelog-file-name)))
    

(defun make-debian-package (system)
  "Make a Debian package, compliant with Debian policy in as much as
that is possible, containing the system named in SYSTEM.  The file will be produced in the directory containing the system directory."
  (let* ((system (find-system system))
	 (components (all-components system))
	 (path (component-pathname system))
	 (debian-directory (merge-pathnames (make-pathname :directory '(:relative "debian"))
					    path)))
    (ensure-directories-exist debian-directory)
    (with-open-file (s (merge-pathnames "rules" debian-directory)
		       :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
    ))