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