Fixe unmap-notify request
[clfswm.git] / contrib / clfswm
blob73532443ca32fbe3502dadf87cfae4780c99a108
1 #!/bin/bash -e
3 # (C) 2012 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_bin='' # +config+
39 lisp_opt='' # +config+
40 dump_path="$XDG_CACHE_HOME/clfswm/" # +config+
41 clfswm_asd_path="$(pwd)" # +config+
42 asdf_path="$(pwd)/contrib" # +config+
44 tmp_dir=/tmp
47 usage() {
49 echo "$0 [options]
50 -n, --no-start don't start CLFSWM after image dump
51 -f, --force force image dump
52 --rebuild same as -f, --force
53 -l, --with-lisp use <lisp> as the common lisp implementation [$lisp]
54 -b, --lisp-bin use <bin> as the common lisp program [$lisp_bin] (default: same as with-lisp type)
55 -o, --lisp-opt use <opt> as lisp option [$lisp_opt]
56 -d, --dump-path path to the dump directory [$dump_path]
57 --with-clfswm path to clfswm.asd file [$clfswm_asd_path]
58 --with-asdf path to the asdf.lisp file [$asdf_path]"
60 exit 0
63 die() {
64 echo >&2 "$@"
65 exit 1
68 build_clisp ()
70 $lisp_bin $lisp_opt -m 8MB -E ISO-8859-1 -q -i "$asdf_path"/asdf.lisp -x "(load \"$clfswm_asd_path/clfswm.asd\")
71 (asdf:oos 'asdf:load-op :clfswm) \
72 (EXT:SAVEINITMEM \"$dump_image\" :INIT-FUNCTION (lambda () (clfswm:main) (quit)) :EXECUTABLE t :norc t)"
75 build_sbcl()
77 $lisp_bin $lisp_opt --disable-debugger --eval "(require :asdf)" \
78 --eval "(require :sb-posix)" \
79 --eval "(load \"$clfswm_asd_path/clfswm.asd\")" \
80 --eval "(require :clfswm)" \
81 --eval "(save-lisp-and-die \"$dump_image\" :toplevel 'clfswm:main)"
84 build_cmucl()
86 $lisp_bin $lisp_opt -eval "(require :clx)" \
87 -eval "(load \"$asdf_path/asdf.lisp\")" \
88 -eval "(load \"$clfswm_asd_path/clfswm.asd\")" \
89 -eval "(asdf:oos 'asdf:load-op :clfswm)" \
90 -eval "(save-lisp \"$dump_image\" :init-function (lambda () (clfswm:main) (quit)))"
93 build_ccl()
95 $lisp_bin $lisp_opt --eval "(require :asdf)" \
96 --eval "(load \"$clfswm_asd_path/clfswm.asd\")" \
97 --eval "(asdf:oos 'asdf:load-op :clfswm)" \
98 --eval "(save-application \"$dump_image\" :toplevel-function (lambda () (clfswm:main) (quit)))"
101 build_ecl()
103 $lisp_bin $lisp_opt -eval "(require :asdf)" \
104 -eval "(load \"$clfswm_asd_path/clfswm.asd\")" \
105 -eval "(asdf:make-build :clfswm :type :program :monolithic t :move-here \".\" :prologue-code '(progn (require :asdf) (require :clx)))" \
106 -eval "(ext:quit 0)"
107 mv ./clfswm-mono "$dump_image"
108 echo "$dump_image"
112 while test $# != 0
114 case "$1" in
115 -n|--no-start)
116 no_start=yes ;;
117 -f|--force|--rebuild)
118 force=yes ;;
119 -d|--dump-path)
120 shift
121 dump_path="$1" ;;
122 --with-clfswm)
123 shift
124 clfswm_asd_path="$1" ;;
125 --with-asdf)
126 shift
127 asdf_path="$1" ;;
128 -l|--with-lisp)
129 shift
130 case "$1" in
132 usage;;
133 clisp|sbcl|cmucl|ccl|ecl)
134 lisp="$1" ;;
135 esac
137 -b|--lisp-bin)
138 shift
139 lisp_bin="$1" ;;
140 -o|--lisp-opt)
141 shift
142 lisp_opt="$1" ;;
144 shift
145 break ;;
146 -h|--help)
147 usage ;;
149 ARGS="$ARGS $1" ;;
150 esac
151 shift
152 done
154 if [ "x$lisp_bin" == "x" ]; then
155 lisp_bin=$lisp
158 #dump_image="$dump_path/clfswm-$(cksum $(type -p $lisp) | cut -d ' ' -f 1)-$(echo "$clfswm_asd_path"|md5sum|cut -d ' ' -f 1).core"
159 dump_image="$dump_path/clfswm-$(echo $(cksum $(type -p $lisp)) "$clfswm_asd_path" | md5sum |cut -d ' ' -f 1).core"
161 if test yes = "$force" && test -e "$dump_image"
162 then
163 echo "Removing old image."
164 rm -f "$dump_image"
167 clfswm_asd="$clfswm_asd_path"/clfswm.asd
168 if test -L "$clfswm_asd_path"; then
169 clfswm_asd=$(readlink "$clfswm_asd")
172 older_image=0
173 for i in "$(dirname $clfswm_asd)"/src/*.lisp; do
174 test "$dump_image" -ot "$i" && older_image=1
175 done
177 if test ! -e "$dump_image" || test $older_image -eq 1
178 then
179 echo "Image is nonexistent or older than sources. Rebuilding clfswm."
180 echo "This may take some times."
181 echo " lisp=$lisp"
182 echo " lisp_bin=$lisp_bin"
183 echo " lisp_opt=$lisp_opt"
184 echo " dump_path=$dump_path"
185 echo " clfswm_asd_path=$clfswm_asd_path"
186 echo " asdf_path=$asdf_path"
187 echo " dump_image=$dump_image"
189 PID=""
190 if test -x "$(which zenity)" ; then
191 zenity --info --text " Rebuilding CLFSWM:\n\n Image is nonexistent or older than sources.\n\nPlease wait, the next CLFSWM boot will be faster." &
192 PID=$!
195 test -x $(type -p "$lisp") || die "$lisp can't be found."
196 test -e "$clfswm_asd_path"/clfswm.asd || die "can't find clfswm.asd in $clfswm_asd_path"
197 test -e "$asdf_path"/asdf.lisp || die "can't find asdf.lisp in $asdf_path"
199 # Move clfswm sources to $tmp_dir if there is no write permission on $clfswm_asd_path
200 if test ! -w "$clfswm_asd_path" ; then
201 echo "* Note: No write access in sources ($clfswm_asd_path),
202 -> copying in a writable directory ($tmp_dir/clfswm-tmp)"
203 rm -rf "$tmp_dir"/clfswm-tmp
204 mkdir "$tmp_dir"/clfswm-tmp
205 cp -R "$clfswm_asd_path"/* "$tmp_dir"/clfswm-tmp
206 clfswm_asd_path="$tmp_dir"/clfswm-tmp
207 asdf_path="$tmp_dir"/clfswm-tmp/contrib
210 mkdir -p "$dump_path"
211 mkdir -p "$dump_path/contrib"
212 eval build_"$lisp"
213 rm -rf "$dump_path/contrib"
214 cp -R "$clfswm_asd_path/contrib/" "$dump_path/"
215 rm -rf $(find "$dump_path/" -name "*svn")
217 rm -rf "$tmp_dir"/clfswm-tmp
219 if test "$PID" != "" ; then
220 kill $PID
223 echo "CLFSWM image is: $dump_image"
226 # Run the resulting image
227 if test no = "$no_start"
228 then
229 cd "$dump_path"
230 echo "Arguments: $* and $ARGS"
231 case $lisp in
232 clisp ) "$dump_image" -- $ARGS ;;
233 sbcl ) exec $lisp_bin --core "$dump_image" $ARGS ;;
234 cmucl ) exec $lisp_bin -core "$dump_image" $ARGS ;;
235 ccl ) exec $lisp_bin -I "$dump_image" -- $ARGS ;;
236 ecl ) "$dump_image" -eval "(progn (clfswm:main) (ext:quit 0))" $ARGS ;;
237 *) echo "..." ;;
238 esac
239 else
240 echo "As requested, we have just dumped the image."