src/clfswm.lisp (main-unprotected): Destroy the notify window before closing the...
[clfswm.git] / contrib / clfswm
blobf461d07ecede20b74ac9235071c506dae3cfcc27
1 #!/bin/bash -e
3 # (C) 2008 Xavier Maillard <xma@gnu.org>
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 # --------------------------------------------------------------------------
21 # Documentation:
23 # Original code and idea: http://stumpwm.antidesktop.net/cgi-bin/wiki/SetUp
25 # Installation:
26 # Put this script wherever you want and just call it from your .xinitrc file
28 # The first time you will launch it, it will build the final
29 # executable and then call it. To force a rebuild of your executable
30 # (say you have updated something in the CLFSWM source tree), just
31 # delete the image and restart your X session.
32 # --------------------------------------------------------------------------
35 no_start=no
37 lisp=clisp # +config+
38 lisp_opt='' # +config+
39 dump_path="$XDG_CACHE_HOME/clfswm/" # +config+
40 clfswm_asd_path="$(pwd)" # +config+
41 asdf_path="$(pwd)/contrib" # +config+
43 tmp_dir=/tmp
46 usage() {
48 echo "$0 [options]
49 -n, --no-start don't start CLFSWM after image dump
50 -f, --force force image dump
51 --rebuild same as -f, --force
52 -l, --with-lisp use <lisp> as the common lisp implementation [$lisp]
53 -o, --lisp-opt use <opt> as lisp option [$lisp_opt]
54 -d, --dump-path path to the dump directory [$dump_path]
55 --with-clfswm path to clfswm.asd file [$clfswm_asd_path]
56 --with-asdf path to the asdf.lisp file [$asdf_path]"
58 exit 0
61 die() {
62 echo >&2 "$@"
63 exit 1
66 build_clisp ()
68 clisp $lisp_opt -m 8MB -E ISO-8859-1 -q -i "$asdf_path"/asdf.lisp -x "(load \"$clfswm_asd_path/clfswm.asd\")
69 (asdf:oos 'asdf:load-op :clfswm) \
70 (EXT:SAVEINITMEM \"$dump_image\" :INIT-FUNCTION (lambda () (clfswm:main) (quit)) :EXECUTABLE t :norc t)"
73 build_sbcl()
75 sbcl $lisp_opt --disable-debugger --eval "(require :asdf)" \
76 --eval "(require :sb-posix)" \
77 --eval "(load \"$clfswm_asd_path/clfswm.asd\")" \
78 --eval "(require :clfswm)" \
79 --eval "(save-lisp-and-die \"$dump_image\" :toplevel 'clfswm:main)"
82 build_cmucl()
84 cmucl $lisp_opt -eval "(load \"$asdf_path/asdf.lisp\")" \
85 -eval "(load \"$clfswm_asd_path/clfswm.asd\")" \
86 -eval "(require :clx)" \
87 -eval "(asdf:oos 'asdf:load-op :clfswm)" \
88 -eval "(save-lisp \"$dump_image\" :init-function (lambda () (clfswm:main) (quit)))"
91 build_ccl()
93 ccl $lisp_opt --eval "(require :asdf)" \
94 --eval "(load \"$clfswm_asd_path/clfswm.asd\")" \
95 --eval "(asdf:oos 'asdf:load-op :clfswm)" \
96 --eval "(save-application \"$dump_image\" :toplevel-function (lambda () (clfswm:main) (quit)))"
99 build_ecl()
101 ecl $lisp_opt -eval "(require :asdf)" \
102 -eval "(load \"$clfswm_asd_path/clfswm.asd\")" \
103 -eval "(asdf:make-build :clfswm :type :program :monolithic t :move-here \".\" :prologue-code '(progn (require :asdf) (require :clx)))" \
104 -eval "(ext:quit 0)"
105 mv ./clfswm-mono "$dump_image"
106 echo "$dump_image"
110 while test $# != 0
112 case "$1" in
113 -n|--no-start)
114 no_start=yes ;;
115 -f|--force|--rebuild)
116 force=yes ;;
117 -d|--dump-path)
118 shift
119 dump_path="$1" ;;
120 --with-clfswm)
121 shift
122 clfswm_asd_path="$1" ;;
123 --with-asdf)
124 shift
125 asdf_path="$1" ;;
126 -l|--with-lisp)
127 shift
128 case "$1" in
130 usage;;
131 clisp|sbcl|cmucl|ccl|ecl)
132 lisp="$1" ;;
133 esac
135 -o|--lisp-opt)
136 shift
137 lisp_opt="$1" ;;
139 shift
140 break ;;
141 -h|--help)
142 usage ;;
144 ARGS="$ARGS $1" ;;
145 esac
146 shift
147 done
150 dump_image="$dump_path/clfswm-$(cksum $(type -p $lisp) | cut -d ' ' -f 1).core"
152 if test yes = "$force" && test -e "$dump_image"
153 then
154 echo "Removing old image."
155 rm -f "$dump_image"
158 clfswm_asd="$clfswm_asd_path"/clfswm.asd
159 if test -L "$clfswm_asd_path"; then
160 clfswm_asd=$(readlink "$clfswm_asd")
163 older_image=0
164 for i in "$(dirname $clfswm_asd)"/src/*.lisp; do
165 test "$dump_image" -ot "$i" && older_image=1
166 done
168 if test ! -e "$dump_image" || test $older_image -eq 1
169 then
170 echo "Image is nonexistent or older than sources. Rebuilding clfswm."
171 test -x $(type -p "$lisp") || die "$lisp can't be found."
172 test -e "$clfswm_asd_path"/clfswm.asd || die "can't find clfswm.asd in $clfswm_asd_path"
173 test -e "$asdf_path"/asdf.lisp || die "can't find asdf.lisp in $asdf_path"
175 # Move clfswm sources to $tmp_dir if there is no write permission on $clfswm_asd_path
176 if test ! -w "$clfswm_asd_path" ; then
177 echo "* Note: No write access in sources ($clfswm_asd_path),
178 -> copying in a writable directory ($tmp_dir/clfswm-tmp)"
179 rm -rf "$tmp_dir"/clfswm-tmp
180 mkdir "$tmp_dir"/clfswm-tmp
181 cp -R "$clfswm_asd_path"/* "$tmp_dir"/clfswm-tmp
182 clfswm_asd_path="$tmp_dir"/clfswm-tmp
183 asdf_path="$tmp_dir"/clfswm-tmp/contrib
186 mkdir -p "$dump_path"
187 mkdir -p "$dump_path/contrib"
188 eval build_"$lisp"
189 rm -rf "$dump_path/contrib"
190 cp -R "$clfswm_asd_path/contrib/" "$dump_path/"
191 rm -rf $(find "$dump_path/" -name "*svn")
193 rm -rf "$tmp_dir"/clfswm-tmp
195 echo "CLFSWM image is: $dump_image"
198 # Run the resulting image
199 if test no = "$no_start"
200 then
201 cd "$dump_path"
202 echo "Arguments: $* and $ARGS"
203 case $lisp in
204 clisp ) "$dump_image" -- $ARGS ;;
205 sbcl ) exec sbcl --core "$dump_image" $ARGS ;;
206 cmucl ) exec cmucl -core "$dump_image" $ARGS ;;
207 ccl ) exec ccl -I "$dump_image" -- $ARGS ;;
208 ecl ) "$dump_image" -eval "(progn (clfswm:main) (ext:quit 0))" $ARGS ;;
209 *) echo "..." ;;
210 esac
211 else
212 echo "As requested, we have just dumped the image."