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