-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathbuild-emacs
executable file
·171 lines (130 loc) · 3.99 KB
/
build-emacs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
#!/bin/sh
set -e
ROOT_DIR="`pwd`"
BUILD_DIR=/tmp/emacs-build
SRC_DIR=emacs
cd ${SRC_DIR}
if test -n "$1"; then
commit="$1"
else
commit="origin/master"
git pull
fi
REV=`git log -n 1 --no-color --pretty='format:%h' ${commit}`
TIMESTAMP=`git log -n 1 --no-color --pretty='format:%at' ${commit}`
PATCH_LIST=`find ${ROOT_DIR}/patches/ -name '*.patch'`
DAY=`date -u -r $TIMESTAMP +"%Y-%m-%d_%H-%M-%S"`
ORIG=`git show $commit:configure.ac | grep ^AC_INIT`
VNUM=`echo $ORIG | sed 's#^AC_INIT(\(.*\))#\1#; s/ //g' | cut -f2 -d,`
VNUM_ONLY=$(echo "$VNUM" | sed -e 's,\[,,g' -e 's,\],,g')
VERS="$DAY Git $REV"
DESCR="Emacs_Cocoa_${VNUM_ONLY}_${DAY}_Git_${REV}"
NCPU=$(getconf _NPROCESSORS_ONLN)
# Use Homebrew libxml pkgconfig
export PKG_CONFIG_PATH=../pkgconfig
CFLAGS="${CFLAGS} -pipe -march=nocona"
export CC=gcc
export CFLAGS
function cleanup_build_dir() {
rm -rf ${BUILD_DIR}
}
function initialize_build_dir() {
if test -e ${BUILD_DIR}/configure.ac; then
return
fi
mkdir ${BUILD_DIR}
git archive --format tar $commit | tar -C ${BUILD_DIR} -xvf -
cd ${BUILD_DIR}
rsync -aE ${ROOT_DIR}/site-lisp lisp
sed -e "s/@@GIT_COMMIT@@/$REV/" -i '' lisp/site-lisp/early-site-start.el
for f in ${PATCH_LIST}; do
echo "Applying patch `basename $f`"
patch -p1 -i $f
done
}
function build_bootstrap_emacs() {
if test -e ${BUILD_DIR}/configure.ac; then
return
fi
cd ${BUILD_DIR}
#autogen/copy_autogen
./autogen.sh
for f in $STRINGS; do
sed -e "s/@version@/@version@ $VERS/" -i '' $f
done
./configure \
--build=x86_64-apple-darwin \
--without-dbus \
--with-imagemagick \
--with-ns
make bootstrap -j$NCPU || exit 1 && make install -j$NCPU
}
function build_emacs() {
make -j$NCPU || exit 1 && make install -j$NCPU
}
function build_pkg_dir() {
cd ${BUILD_DIR}
rsync -aE nextstep/Emacs.app _out
rsync -aE ${ROOT_DIR}/emacs-dmg/* _out
rsync -aE ${ROOT_DIR}/emacs/src _out/Emacs.app/Contents/Resources/
mkdir -p dir _out/Emacs.app/Contents/Resources/patches
cp ${PATCH_LIST} _out/Emacs.app/Contents/Resources/patches
rsync -aE ${ROOT_DIR}/bin/* _out/Emacs.app/Contents/MacOS/bin/
Rez -o "_out/More.../Alternative Icon" _out/icon.r
rm _out/icon.r
# Set the finder info bit that says the file has a custom icon.
xattr -x -w com.apple.FinderInfo "00 00 00 00 00 00 00 00 04 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00" "_out/More.../Alternative Icon"
mv _out/dot-DS_Store _out/.DS_Store
SetFile -a Vc _out/background.*
}
function fix_dynlib() {
local f=$1
local indent="$2"
local loader_path="$3"
local target
local lib
local rpath=$(otool -l $f | grep RPATH -A2 | awk '{if($1=="path"){print $2}}')
echo "$indent* Examinating $f"
for lib in $(otool -L $f | grep -F '.dylib ' | grep -v '/usr/lib/' |\
grep -v '[[:space:]]\+@executable_path/' |\
sed -n 's/^[[:space:]]*\(.*\) (.*/\1/p' | uniq); do
target="_out/Emacs.app/Contents/Resources/lib/$(basename $lib)"
if ! test -e "$target"; then
resolved_lib=$(echo $lib | sed "s,@rpath,$rpath,")
if test -n "$loader_path"; then
resolved_lib=$(echo $resolved_lib | sed "s,@loader_path,$loader_path,")
fi
echo "$indent - copying $lib ($resolved_lib)"
cp "$resolved_lib" "$target"
chmod 644 "$target"
install_name_tool -id \
@executable_path/../Resources/lib/$(basename $lib) \
"$target"
fix_dynlib "$target" " $indent" $(dirname $resolved_lib)
fi
echo "$indent - fixing $(basename $lib)"
install_name_tool -change $lib \
@executable_path/../Resources/lib/$(basename $lib) $f
done
}
function fix_libs() {
cd ${BUILD_DIR}
mkdir -p _out/Emacs.app/Contents/Resources/lib
for f in `find _out/Emacs.app/Contents/MacOS/ -type f`; do
fix_dynlib $f
done
}
function build_dmg() {
cd ${BUILD_DIR}
rm -f ../tmp.dmg
hdiutil makehybrid -hfs -hfs-volume-name "$DESCR" -hfs-openfolder _out _out -o ../tmp.dmg
hdiutil convert -format UDZO ../tmp.dmg -o "${ROOT_DIR}/${DESCR}.dmg"
rm -rf tmp.dmg
}
initialize_build_dir
build_bootstrap_emacs
build_emacs
build_pkg_dir
fix_libs
build_dmg
exit