catchup with lots of updates
[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 m cd /a/opt/emacs
101
102 if [[ -e $dir ]]; then
103 m cd $dir
104 rev=$(cat $last_build 2>/dev/null) ||:
105 head=$(git rev-parse HEAD)
106 if ! $recompile && ! $bootstrap && [[ $rev == "$head" ]]; then
107 echo "already compiled, exiting"
108 exit 0
109 fi
110 if [[ $rev != "$head" ]]; then
111 bootstrap=true
112 fi
113 else
114 head=$(git rev-parse HEAD)
115 bootstrap=true
116 fi
117
118 if $dryrun; then
119 echo recompile=$recompile bootstrap=$bootstrap update=$update
120 exit 0
121 fi
122
123 if $bootstrap; then
124 m rsync --delete -ra /a/opt/emacs/ $dir
125 recompile=true
126 fi
127
128 case $(distro-name) in
129 fedora )
130 logq s yum-builddep -y emacs
131 logq pi texlive-dvipng
132 ;;&
133 debian|ubuntu|trisquel)
134 # todo: unknown for other distros, this will fail
135 logq p -y build-dep maildir-utils
136 # oddly, on ubuntu 14.04 this installs postfix, but I dun care
137 # ubuntu 14.04 gave this error message
138 # Unable to satisfy the build-depends: Build-Depends: libpng-dev
139 # this is satisfied by dvipng. the build-dep is just wrong
140 # minor bug I'm not going to bother reporting.
141 #
142 # note, useful command to see build dep packagages:
143 # apt-rdepends --build-depends --follow=DEPENDS emacs25
144 logq p -y build-dep $latest_emacs
145 ;;&
146 esac
147
148 if $recompile; then
149
150 nox=false
151 for d in ${dirs[@]}; do
152 if $nox; then
153 # Commented stuff in this block had something to do with ssh / autofs, im not really using nox right now,
154 # so unless I figure out why it was this way, ignore this.
155 # m mkdir -p ${d%/*}
156 m rsync --delete -ra $dir/ $d
157 #
158 # mp=$HOME/.iank/e/e
159 # if mountpoint $mp &>/dev/null; then
160 # m sudo umount $mp
161 # fi
162 # m mkdir -p $mp
163 # m sudo mount -o bind $d $mp
164 # m sudo chown $USER:$USER $mp
165 # m cd $mp
166
167 # instead of $mp above
168 m cd $d
169 else
170 m cd $d
171 fi
172 # todo, consider when this should be uncommented
173 #logq s make uninstall
174 m find ~/.emacs.d/ -name '*.elc' -delete
175
176 # git version
177 if [[ $1 ]]; then
178 m i clean -xxxfd
179 elif $update; then
180 m i fetch
181 m i clean -xxxffd
182 m i reset --hard origin/master
183 m i clean -xxxffd
184 fi
185 # autogen is usually only for the first build, assume it works
186 logq ./autogen.sh all
187 # I tried changing O2 to O3, don't know if it made it faster or slower so I went back to 02.
188 # Also, link-time-optimization based on ./INSTALL
189
190 # for debugging, use -Og, or -O0 to make debug really correspond to sources
191 # dunno why I have had -std=gnu99 in the past
192 #CFLAGS='-std=gnu99 -g3 -Og'
193 export CFLAGS='-g3 -Og'
194 #CFLAGS='-std=gnu99 -g3 -O2' logq ./configure --enable-link-time-optimization
195 # on ubuntu 12.04, the above fails, says my c compiler won't work, so intead, just use defaults
196 if $nox; then
197 # mix of flags from arch and debians build flags
198 # note, youd think we could just run make again, but the
199 # build system isnt smart enough, we have to recompile
200 # from scratch.
201 logq ./configure --without-x --without-sound --without-gsettings --without-gconf
202 ln -s ~/.emacs.d .
203 else
204 logq ./configure
205 fi
206 logq make -j `nproc` bootstrap
207 logq make -j `nproc`
208 if ! $nox; then
209 logq sudo make install
210 # make emacs always work for root
211 sudo /a/exe/lnf /usr/local/bin/emacs /usr/bin
212 fi
213 nox=true
214 done
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
229 if $recompile; then
230 # note, not totally sure its right to put this within recompile, but its taking up most of the time, so going for it.
231 logq emacs --batch -l ~/.emacs.d/compile-init-dir.el
232 fi
233
234 # as of 01-2017, built-in org mode has a bug that
235 # org-edit-src-exit does not get bound, so using latest
236 #/a/bin/buildscripts/org-mode
237
238 # disabled as i haven't used it in a while
239 # if $update; then
240 # logq pi bzr
241 # cd ~/.emacs.d/src/mediawiki-el
242 # bzr pull
243 # fi
244
245
246 # not keeping up with the latest gnus development.
247 # # instructions from the README
248 # # the byte-recompile-directory seems to compile gnus,
249 # # but gnus complains that it should be compiled when it starts
250 # cd ~/.emacs.d/src/gnus
251 # if [[ $1 == *u* ]]; then
252 # i pull
253 # fi
254 # logq ./configure
255 # logq make
256
257 my-update-info-dir
258
259 echo $head >$last_build