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