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