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