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