-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmakepkg
More file actions
executable file
·317 lines (281 loc) · 7.96 KB
/
makepkg
File metadata and controls
executable file
·317 lines (281 loc) · 7.96 KB
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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
#!/bin/bash -e
# ================ #
# HELPER FUNCTIONS #
# ================ #
make_shlib()
{
local libname=$(basename ${1%.*})
local soversion=${2}
local compatversion=$(echo ${soversion} | cut -d"." -f1).$(echo ${soversion} | cut -d"." -f2)
local soname=${libname}.dylib.${soversion}
local sonamemajor=${libname}.dylib.$(echo $soversion | cut -d"." -f1)
echo "Building ${libname}.dylib ..."
shift 2
${LINK} ${LDFLAGS} -dynamiclib \
-install_name `pwd`/${sonamemajor} \
-Wl,-force_load ${libname}.a \
-multiply_defined warning \
-current_version ${soversion} \
-compatibility_version ${compatversion} \
"$@" -o ${soname}
ln -svf ${soname} ${libname}.dylib
ln -svf ${soname} ${libname}.dylib.${compatversion}
ln -svf ${soname} ${sonamemajor}
}
makepkg_download()
{
# prefer wget to curl, if available
if hash wget 2>/dev/null; then
wget -N $1
else
local pkgfile=`basename $1`
[ -f $pkgfile ] || curl -O -L $1
fi
}
makepkg_git()
{
# download or update a git repository
if [ -d $2/.git ]; then
git -C $2 rebase
else
git clone $1 $2
fi
}
makepkg_svn()
{
if [ -d $2/.svn ]; then
pushd $2
svn update
popd
else
svn checkout $1 $2
fi
}
makepkg_untar()
{
# prefer bsdtar if available
if hash bsdtar 2>/dev/null; then
bsdtar -xf $1
else
# get the mime-type from the downloaded file
local mime=`file --mime-type $1 | cut -d":" -f2 | tr -d " "`
# untar accordingly to the mimetype
case $mime in
"application/x-bzip2")
tar xvfj $1 -C $tmpdir
;;
"application/x-gzip")
tar xvfz $1 -C $tmpdir
;;
*)
echo "Error: filetype '$mime' not recognized!"
exit 1
;;
esac
fi
}
# ================= #
# DEFAULT FUNCTIONS #
# ================= #
apply_patch() { :; }
prepare()
{
# create a tempdir for the source if not present
local pkgfile=`basename $pkgurl`
mkdir -pv $tmpdir && pushd $tmpdir
# check if git repository
if [ "${pkgfile##*.}" == "git" ]; then
makepkg_git $pkgurl $srcdir
elif [ "${pkgurl::3}" == "svn" ]; then
makepkg_svn $pkgurl $srcdir
else
# standard download
makepkg_download $pkgurl
# remove old source dir
rm -rf $srcdir
# untar, again prefer bsdtar
makepkg_untar $pkgfile
fi
# apply patches
pushd $srcdir
apply_patch
popd
popd
}
configure()
{
# check if the build directory is not the source directory
echo $tmpdir/$srcdir
echo $builddir
if [ "x${tmpdir}/${srcdir}" != "x${builddir}" ]; then
# create a build directory
[[ -d $builddir ]] && rm -rf $builddir
mkdir $builddir
fi
pushd $builddir
# check if cmake or autoconf
if [[ ! -z ${USE_CMAKE+x} ]]; then
cmake -DCMAKE_INSTALL_PREFIX=$destdir $confopts $tmpdir/$srcdir
else
$tmpdir/$srcdir/configure --prefix=$destdir $confopts
fi
popd
}
build()
{
make -C $builddir -j$MAKE_NUMJOBS
}
testing()
{
make -C $builddir check
}
pre_package()
{
#remove old installation
if [[ -d $destdir ]]; then
echo "${bold}Removing old installation${norm}"
rm -rfv $destdir
fi
}
package()
{
make -C $builddir install
pushd $destdir
if [ -f "share/info/dir" ]; then
rm share/info/dir
fi
popd
}
post_package() { :; }
# Generate the modulefile for the package that we built.
# If the variable $pkgmodule is not set, we generate our
# own module file looking for default directories to
# expose.
# If the variable $pkgmodule is empty we do not create
# the module file.
# If a variable $pkgmodule_extra is set, we include it
# into the modulefiles after the header but before the
# prepend-path calls. This is useful to load additional
# dependencies.
feedmodule()
{
# Create the directory
if [ ! -d `dirname "${modulefile}"` ]; then
echo `dirname "${modulefile}"`
mkdir -pv `dirname $modulefile`
fi
if [ ! -n "${pkgmodule+x}" ]; then
# Generate our own modulefile
echo "Generate modulefile '$modulefile'..."
echo "#%Module1.0" > $modulefile
# We set an environment variable [PKGNAME]_DIR to
# $destdir for convenience, to use as dependency
local PKGDIR="$(echo $pkgname | gawk '{print toupper(gensub(/[-]/,"","g"))}')_DIR"
echo "set ${PKGDIR} $destdir" >> $modulefile
echo "setenv ${PKGDIR} \$${PKGDIR}" >> $modulefile
# Add extra module dependencies
if [ ! ${#moduledeps[@]} -eq 0 ]; then
echo "module load ${moduledeps[*]}" >> $modulefile
fi
# Add extra things
if [ -n "${pkgmodule_extra+x}" ]; then
echo "${pkgmodule_extra}" >> $modulefile
fi
# Add binaries
if [ -d "${destdir}/bin" ]; then
echo "prepend-path PATH \$${PKGDIR}/bin" >> $modulefile
fi
# Add libraries (only on Unix)
if [ "x$OSTYPE" = "xlinux-gnu" -a -z "${pkgmodule_skip_lib+x}" ]; then
if [ -d "${destdir}/lib" ]; then
echo "prepend-path LD_LIBRARY_PATH \$${PKGDIR}/lib" >> $modulefile
fi
if [ -d "${destdir}/lib64" ]; then
echo "prepend-path LD_LIBRARY_PATH \$${PKGDIR}/lib64" >> $modulefile
fi
fi
# Add pkg-config, man and info
if [ -d "${destdir}/lib/pkgconfig" ]; then
echo "prepend-path PKG_CONFIG_PATH \$${PKGDIR}/lib/pkgconfig" >> $modulefile
fi
if [ -d "${destdir}/share/man" ]; then
echo "prepend-path MANPATH \$${PKGDIR}/share/man" >> $modulefile
fi
if [ -d "${destdir}/share/info" ]; then
echo "prepend-path INFOPATH \$${PKGDIR}/share/info" >> $modulefile
fi
# Add python directories
_pythoncmd="from distutils.sysconfig import get_python_lib;\
print(get_python_lib(False,False,\"\$$PKGDIR\"));"
PYTHONDIR=$(echo -e $_pythoncmd | $PYTHON)
if [ -d "${PYTHONDIR/\$$PKGDIR/$destdir}" ]; then
echo "prepend-path PYTHONPATH $PYTHONDIR" >> $modulefile
fi
# create the default file
if [ -n "${pkgmodule_default+x}" ]; then
echo "#%Module1.0" > `dirname $modulefile`/.version
echo "set ModulesVersion \"$pkgver\"" >> `dirname $modulefile`/.version
fi
elif [ ! "x${pkgmodule}" = "x" ]; then
# Dump to file
echo "$pkgmodule" > $modulefile
fi
}
# ============== #
# MAIN EXECUTION #
# ============== #
bold=$(tput bold)
norm=$(tput sgr0)
# check if repo is set, otherwise we locally set it just for installation
[ -z ${REPO+set} ] && source pkgs.conf
echo "${bold}Using repository:${norm} $REPO"
# check if the requested package exists
pkgsource=$1
if [ ! -f $pkgsource ]; then
echo "'$pkgsource' not found!"
exit 1
fi
# define variables before sourcing the file... so they can be overridden
tmpdir=$REPO/src/$(basename "$pkgsource")
destdir=$REPO/opt/$(basename "$pkgsource")
# this works most of the time, but not always, for instance when the name
# contains a dash... in which case we simply define these variables in
# the source
pkgname=$(echo $(basename "$pkgsource")|cut -d"-" -f1)
pkgver=$(echo $(basename "$pkgsource")|cut -d"-" -f2)
moduledeps=()
MAKE_NUMJOBS=4
echo "${bold}Destination directory:${norm} $destdir"
echo "${bold}Temporary directory:${norm} $tmpdir"
# source the content of the package makefile
# this will override functions defined above, if necessary
source $pkgsource
echo "${bold}Sourced file:${norm} $pkgsource"
echo "${bold}Building package:${norm} $pkgname $pkgver"
# we handle special case for these variables
[ -z ${srcdir+x} ] && srcdir=$pkgname-$pkgver
[ -z ${builddir+x} ] && builddir=$tmpdir/$srcdir/build
[ -z ${modulefile+x} ] && modulefile=$REPO/modulefiles/$pkgname/$pkgver
echo "${bold}Source directory:${norm} $srcdir"
echo "${bold}Build directory:${norm} $builddir"
echo "${bold}Module file:${norm} $modulefile"
[ -z ${onlymodule+x} ] && onlymodule=no
# By default we don't create a module .version file
[ -z ${pkgmodule_default+x} ] && pkgmodule_default=no
# check who is PYTHON
[ -z ${PYTHON+x} ] && PYTHON=python
if [ "x$2" == "x" ]; then
# run all the commands
if [ "x$onlymodule" == "xno" ]; then
prepare
configure
build
pre_package
package
post_package
fi
feedmodule
else
# run only the requested command
"${2}"
fi