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