minor fixes
[buildscripts] / emacs
1 #!/bin/bash
2 # Copyright (C) 2016 Ian Kelling
3
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
7
8 # http://www.apache.org/licenses/LICENSE-2.0
9
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15
16 if [[ -s ~/.bashrc ]];then . ~/.bashrc;fi
17
18 #set -x
19 # arg = git commit to check out
20
21 update=false
22 bootstrap=false
23 recompile=false
24 show_pkgs=false
25
26 while [[ $1 == -* ]]; do
27 case $1 in
28 -b) bootstrap=true; recompile=true ;;
29 -r) recompile=true ;;
30 --no-r) recompile=false ;;
31 -u) update=true ;;
32 -p) show_pkgs=true ;;
33 --) break ;;
34 *) echo "$0: error: bad arg: $1" >&2; exit 1 ;;
35 esac
36 shift
37 done
38
39
40 # Og = optmize, but keep gdb working
41 export CFLAGS="-Og -g3"
42
43 export DEBIAN_FRONTEND=noninteractive
44 pupdate
45
46 # some distros, the package name is like emacs25, some its just emacs
47 ver=$(apt-cache showsrc emacs | sed -rn 's/^Version: 1:([0-9]+).*/\1/p' | sort -n | tail -n1) ||:
48 for x in {35..25} ""; do
49 if [[ $ver ]] && (( ver >= x )); then
50 echo latest_emacs=emacs
51 latest_emacs=emacs
52 break
53 fi
54 if apt-cache showsrc emacs$x 2>/dev/null |grep . &>/dev/null; then
55 echo latest_emacs=$x
56 latest_emacs=emacs$x
57 break
58 fi
59 done
60
61 pkgs=(gawk attr autoconf-archive git install-info)
62 ##### warning, apt-rdepends seems to look at the newest version of the package,
63 ##### not the one that build-dep would install.
64 if $show_pkgs; then
65 echo ${pkgs[*]}
66 for x in $latest_emacs maildir-utils; do
67 # todo, this gives fake provided packages like mailx, and then
68 # fai ignores them.
69 # https://askubuntu.com/questions/21379/how-do-i-find-the-build-dependencies-of-a-package
70 if ! type -p apt-rdepends &>/dev/null; then
71 sudo apt-get -y install --purge --auto-remove apt-rdepends
72 fi
73 apt-rdepends -p --build-depends --follow=DEPENDS $x/$(debian-codename)|sed -rn 's/^\s*Build-Depends: (\S+).*/\1/p'
74 done
75 exit 0
76 fi
77
78
79 #building emacs, INSTALL.BZR
80
81 # gawk and attr were no longer automatically installed in stretch,
82 # looking back, i assume i got some error.
83 # autoconf-archive due to come error
84 pi ${pkgs[@]}
85
86 #git repo
87 dir=/a/opt/emacs-$(distro-name)$(distro-num)
88 last_build=$dir/iank-emacs-build
89
90 # e/e because autofs failing to mount will make it so
91 # you cant ls whatever directory it is in, so we
92 # need an extra directory
93 dirs=($dir $dir-nox/.iank/e/e)
94
95 if [[ -e $dir ]]; then
96 m cd $dir
97 rev=$(cat $last_build 2>/dev/null) ||:
98 head=$(git rev-parse HEAD)
99 if ! $recompile && ! $bootstrap && [[ $rev == "$head" ]]; then
100 echo "already compiled, exiting"
101 fi
102 if [[ $rev != "$head" ]]; then
103 bootstrap=true
104 fi
105 else
106 m cd /a/opt/emacs
107 head=$(git rev-parse HEAD)
108 bootstrap=true
109 fi
110
111 if $bootstrap; then
112 m rsync --delete -ra /a/opt/emacs/ $dir
113 recompile=true
114 fi
115
116 case $(distro-name) in
117 fedora )
118 logq s yum-builddep -y emacs
119 logq pi texlive-dvipng
120 ;;&
121 debian|ubuntu|trisquel)
122 # todo: unknown for other distros, this will fail
123 logq p -y build-dep maildir-utils/$(debian-codename)
124 # oddly, on ubuntu 14.04 this installs postfix, but I dun care
125 # ubuntu 14.04 gave this error message
126 # Unable to satisfy the build-depends: Build-Depends: libpng-dev
127 # this is satisfied by dvipng. the build-dep is just wrong
128 # minor bug I'm not going to bother reporting.
129 #
130 # note, useful command to see build dep packagages:
131 # apt-rdepends --build-depends --follow=DEPENDS emacs25
132 logq p -y build-dep $latest_emacs
133 ;;&
134 esac
135
136 if $recompile; then
137
138 nox=false
139 for d in ${dirs[@]}; do
140 if $nox; then
141 # todo: this doesnt account for
142 m mkdir -p ${d%/*}
143 m rsync --delete -ra $dir/ $d
144 mp=$HOME/.iank/e/e
145 if mountpoint $mp &>/dev/null; then
146 m sudo umount $mp
147 fi
148 m mkdir -p $mp
149 m sudo mount -o bind $d $mp
150 m sudo chown $USER:$USER $mp
151 m cd $mp
152 else
153 m cd $d
154 fi
155 # todo, consider when this should be uncommented
156 #logq s make uninstall
157 m find ~/.emacs.d/ -name '*.elc' -delete
158
159 # git version
160 if [[ $1 ]]; then
161 m i clean -xxxfd
162 elif $update; then
163 m i fetch
164 m i clean -xxxffd
165 m i reset --hard origin/master
166 m i clean -xxxffd
167 fi
168 # autogen is usually only for the first build, assume it works
169 logq ./autogen.sh all
170 # I tried changing O2 to O3, don't know if it made it faster or slower so I went back to 02.
171 # Also, link-time-optimization based on ./INSTALL
172
173 # for debugging, use -Og, or -O0 to make debug really correspond to sources
174 # dunno why I have had -std=gnu99 in the past
175 #CFLAGS='-std=gnu99 -g3 -Og'
176 export CFLAGS='-g3 -Og'
177 #CFLAGS='-std=gnu99 -g3 -O2' logq ./configure --enable-link-time-optimization
178 # on ubuntu 12.04, the above fails, says my c compiler won't work, so intead, just use defaults
179 if $nox; then
180 # mix of flags from arch and debians build flags
181 # note, youd think we could just run make again, but the
182 # build system isnt smart enough, we have to recompile
183 # from scratch.
184 logq ./configure --without-x --without-sound --without-gsettings --without-gconf
185 ln -s ~/.emacs.d .
186 else
187 logq ./configure
188 fi
189 logq make -j `nproc` bootstrap
190 logq make -j `nproc`
191 if ! $nox; then
192 logq sudo make install
193 # make emacs always work for root
194 sudo /a/exe/lnf /usr/local/bin/emacs /usr/bin
195 fi
196 nox=true
197 done
198 echo $head >$last_build
199 else
200 m cd ${dirs[0]}
201 logq sudo make install
202 # make emacs always work for root
203 m sudo /a/exe/lnf /usr/local/bin/emacs /usr/bin
204 fi
205
206 #git clone https://github.com/djcb/mu
207 # note: master failed on t8, i moved back to the commit before a bug
208 # https://github.com/djcb/mu/issues/1400
209 # from its HACKING file
210
211
212 cd /a/opt/mu
213
214 last_build=$PWD/iank-mu-build
215
216 rev=$(cat $last_build 2>/dev/null) ||:
217 head=$(git rev-parse HEAD)
218
219 if [[ $(debian-codename) == flidas ]]; then
220 # use the flidas branch, stuck behind because
221 # needs newer crypt libraries that are too troublesome.
222 cd /a/opt/muflidas
223 else
224 # libgmime-3.0-dev is a newer version than build-dep installs for buster
225 m sudo apt-get -y install --purge --auto-remove libgmime-3.0-dev meson
226 fi
227 if $recompile || [[ $rev != "$head" ]]; then
228 m git clean -xfffd
229 m ./autogen.sh && make -j`nproc`
230 # note uninstall is implemented
231 m sudo make install
232 echo $head >$last_build
233 else
234 # Workaround for some indecipherable build error
235 # that only happens after syncing the mu dir and not building from
236 # scratch. It seems there is some state somewhere, like ~/.local
237 # that doesn't get copied. Found the workaround by reading the Makefile,
238 # then doing a more verbose build with:
239 # ninja -C $PWD/build -v -d explain
240 sudo touch -d @$(($(stat -c%Y build/build.ninja) - 100)) /usr/local/bin/emacs
241 m sudo make install
242 fi
243
244 if $recompile; then
245 # note, not totally sure its right to put this within recompile, but its taking up most of the time, so going for it.
246 logq emacs --batch -l ~/.emacs.d/compile-init-dir.el
247 fi
248
249 # as of 01-2017, built-in org mode has a bug that
250 # org-edit-src-exit does not get bound, so using latest
251 #/a/bin/buildscripts/org-mode
252
253 # disabled as i haven't used it in a while
254 # if $update; then
255 # logq pi bzr
256 # cd ~/.emacs.d/src/mediawiki-el
257 # bzr pull
258 # fi
259
260
261 # not keeping up with the latest gnus development.
262 # # instructions from the README
263 # # the byte-recompile-directory seems to compile gnus,
264 # # but gnus complains that it should be compiled when it starts
265 # cd ~/.emacs.d/src/gnus
266 # if [[ $1 == *u* ]]; then
267 # i pull
268 # fi
269 # logq ./configure
270 # logq make
271
272 my-update-info-dir