Skip to content
Newer
Older
100755 359 lines (337 sloc) 8.95 KB
dbea655 @azman Update Commit
authored Aug 2, 2011
1 #!/bin/sh
2
3 # INFO FOR PROGRAM TO BE BUILT
4 THIS_NAME="$(basename $0)"
5 THIS_PATH="$(dirname $0)"
6 PROG_NAME=${PROG_NAME:="$(basename $THIS_NAME .${THIS_NAME##*.})"}
440b14a @azman Update Commit
authored Nov 27, 2011
7 PROG_VERS=${PROG_VERS:="1.3.2"} # CHANGE TO WHAT WE NEED
dbea655 @azman Update Commit
authored Aug 1, 2011
8 PROG_FULL="$PROG_NAME-$PROG_VERS" # SHOULD BE TOP FOLDER'S NAME
9 PROG_BALL="$PROG_FULL.tar.gz" # CAN BE OTHER THAN $PROG_FULL
10 # PLACE URL ACCORDINGLY!
1a8afc0 @azman Dirty Commit
authored Dec 10, 2011
11 PROG_PATH="http://downloads.xvid.org/downloads/"
12 PROG_LOAD="${PROG_PATH}${PROG_BALL}"
dbea655 @azman Update Commit
authored Aug 1, 2011
13 # ASSIGN DOCS ACCORDINGLY!
14 PROG_DOCS="AUTHORS ChangeLog* CodingStyle LICENSE README TODO doc"
f7b644f @azman Update Commit
authored Oct 6, 2012
15 # DEPS LIST? (build-time?)
16 PROG_DEPS=""
1a8afc0 @azman Dirty Commit
authored Dec 10, 2011
17 # CHECK MACHINE ARCH!
18 if [[ "$ARCH" == "" ]]; then
19 ARCH="$(uname -m)"
20 case "$ARCH" in
21 i?86) ARCH="i486" ;;
22 arm*) ARCH="arm" ;;
23 esac
24 fi
dbea655 @azman Update Commit
authored Aug 1, 2011
25 # OUTPUT PACKAGE PARAMS
26 BUILD_TAG=${BUILD_TAG:="1_my1"}
27 PACK_TYPE=${PACK_TYPE:="tgz"}
1a8afc0 @azman Dirty Commit
authored Dec 10, 2011
28 PACK_ARCH=${PACK_ARCH:="$ARCH"}
dbea655 @azman Update Commit
authored Aug 1, 2011
29 PACK_PATH=${PACK_PATH:="/tmp"}
30 PACK_BALL=${PACK_BALL:="$PROG_NAME-$PROG_VERS-$PACK_ARCH-$BUILD_TAG.$PACK_TYPE"}
31 # BUILD-RELATED PATH
32 CURR_PATH=$(cd $THIS_PATH; pwd)
33 TEMP_PATH=${TEMP_PATH:="/tmp/my1/slackbuild"}
34 DEST_PATH=$TEMP_PATH/package-$PROG_NAME
35 # COMMAND-LINE OPTIONS
36 CHK_DOWNLOAD=${CHK_DOWNLOAD:="NO"}
37 CHK_LOADONLY=${CHK_LOADONLY:="NO"}
1a8afc0 @azman Dirty Commit
authored Dec 10, 2011
38 CHK_MOVEPACK=${CHK_MOVEPACK:="NO"}
dbea655 @azman Update Commit
authored Aug 1, 2011
39
1a8afc0 @azman Dirty Commit
authored Dec 10, 2011
40 function prepare_source()
41 {
42 # PREPARE SOURCE MANUALLY
a43a3d7 @azman Update Commit
authored Oct 8, 2012
43 return 0
1a8afc0 @azman Dirty Commit
authored Dec 10, 2011
44 }
dbea655 @azman Update Commit
authored Aug 1, 2011
45
1a8afc0 @azman Dirty Commit
authored Dec 10, 2011
46 function do_build()
47 {
48 # ACTUAL BUILD PROCESS
49 CFLAGS="$SLACKCFLAGS" \
50 CXXFLAGS="$SLACKCFLAGS" \
51 ./configure --prefix=/usr \
52 --sysconfdir=/etc \
53 --localstatedir=/var \
54 --libdir=/usr/lib${LIBDIRSUFFIX} \
55 --mandir=/usr/man \
56 --build=$PACK_ARCH-slackware-linux$ARCHQUADLET
57 # PLACE ADDITIONAL CONFIG HERE
58 make
59 make install DESTDIR=$DEST_PATH
60 }
dbea655 @azman Update Commit
authored Aug 1, 2011
61
1a8afc0 @azman Dirty Commit
authored Dec 10, 2011
62 function do_pre_build()
63 {
64 # PLACE FIX/PRE-BUILD SCRIPT HERE!
65 # Fix detecting yasm - taken from the gentoo ebuild for xvid
66 sed -i -e '/^minimum_yasm_minor_version/s:=.*:=0:' build/generic/configure
67 cd build/generic
68 }
69
70 function do_post_build()
71 {
72 # PLACE FIX/POST-BUILD SCRIPT HERE!
73 cd ../..
74 # Per doc/INSTALL, create some symlinks to the shared object. This
75 # should be safe, as the maintainers assure that they won't change the
76 # major library number unless there is an incompatible ABI change:
77 ( cd $DEST_PATH/usr/lib${LIBDIRSUFFIX}
78 ln -s libxvidcore.so.4.2 libxvidcore.so.4
79 ln -s libxvidcore.so.4.2 libxvidcore.so
80 )
81 }
dbea655 @azman Update Commit
authored Aug 1, 2011
82
1a8afc0 @azman Dirty Commit
authored Dec 10, 2011
83 function do_install_stuff()
84 {
85 # COPY INSTALLATION-RELATED FILE(S)
86 mkdir -p $DEST_PATH/install
87 RULER_SPC="$(printf "%*s" ${#PROG_NAME} "")";
dbea655 @azman Update Commit
authored Aug 1, 2011
88 THIS_SLACKDESC=$(cat <<SLACK-DESC
89 # HOW TO EDIT THIS FILE:
90 # The "handy ruler" below makes it easier to edit a package description. Line
91 # up the first '|' above the ':' following the base package name, and the '|'
92 # on the right side marks the last column you can put a character in. You must
93 # make exactly 11 lines for the formatting to be correct. It's also
94 # customary to leave one space after the ':'.
95
96 ${RULER_SPC}|-----handy-ruler------------------------------------------------------|
97 xvidcore: Xvid (MPEG-4 Compliant Video Codec)
98 xvidcore:
99 xvidcore: Xvid is an ISO MPEG-4 compliant video codec. It is an open source
100 xvidcore: project that is developed and maintained by people from all over
101 xvidcore: the world. Xvid claims to be the best currently available MPEG-4
102 xvidcore: video codec solution, and it is free software.
103 xvidcore:
104 xvidcore: Homepage: http://www.xvid.org/
105 xvidcore:
106 xvidcore:
107 xvidcore:
108 SLACK-DESC
109 )
1a8afc0 @azman Dirty Commit
authored Dec 10, 2011
110 echo "$THIS_SLACKDESC" > $DEST_PATH/install/slack-desc
dbea655 @azman Update Commit
authored Aug 1, 2011
111 #THIS_DOINSTSH=$(cat <<DOINSTSH
112 #if [ -x /usr/bin/update-desktop-database ]; then
113 # /usr/bin/update-desktop-database -q usr/share/applications
114 #fi
115 #DOINSTSH
116 #)
1a8afc0 @azman Dirty Commit
authored Dec 10, 2011
117 #echo "$THIS_DOINSTSH" > $DEST_PATH/install/doinst.sh
118 }
119
a43a3d7 @azman Update Commit
authored Oct 7, 2012
120 function do_post_package()
121 {
122 # PLACE POST-PACKAGE SCRIPT HERE!
123 show_deps
124 }
125
1a8afc0 @azman Dirty Commit
authored Dec 10, 2011
126 # ONLY TEMPLATES BELOW THIS LINE
127
a43a3d7 @azman Update Commit
authored Oct 7, 2012
128 function show_deps()
129 {
130 if [[ "$PROG_DEPS" != "" ]] ; then
131 echo -n "This software '$PROG_NAME' requires: "
132 for dep in "$PROG_DEPS" ; do
133 echo -n "$dep "
134 dep="$(cd ${THIS_PATH};pwd)/${dep}.SlackBuild"
135 if [[ -r "$dep" ]] ; then
136 echo -n "($dep)"
137 else
138 echo -n "(not found!)"
139 fi
140 done
141 echo
142 fi
143 }
144
1a8afc0 @azman Dirty Commit
authored Dec 10, 2011
145 function check_param()
146 {
147 while [[ "$1" != "" ]]; do
148 case $1 in
149 --load )
150 CHK_DOWNLOAD="YES"
151 ;;
152 --load-only )
153 CHK_DOWNLOAD="YES"
154 CHK_LOADONLY="YES"
155 ;;
156 --move-here )
1907db9 @azman Update Commit
authored Sep 3, 2012
157 MOVE_PATH=$CURR_PATH
1a8afc0 @azman Dirty Commit
authored Dec 10, 2011
158 CHK_MOVEPACK="YES"
159 ;;
1907db9 @azman Update Commit
authored Sep 3, 2012
160 --move )
161 shift
162 MOVE_PATH=$1
163 CHK_MOVEPACK="YES"
164 [[ ! -d "$MOVE_PATH" ]] &&
165 echo "Invalid '--move' path ($MOVE_PATH)!" && exit 1
166 MOVE_PATH=$(cd $MOVE_PATH;pwd)
167 ;;
f7b644f @azman Update Commit
authored Oct 6, 2012
168 --show-deps )
a43a3d7 @azman Update Commit
authored Oct 7, 2012
169 show_deps
170 exit 0
f7b644f @azman Update Commit
authored Oct 6, 2012
171 ;;
1a8afc0 @azman Dirty Commit
authored Dec 10, 2011
172 * )
173 echo "Unknown parameter ($1)!" && exit 1
174 ;;
175 esac
176 shift
177 done
178 # set these as early as possible?
179 set -e # exit immediately when non-zero exit status
180 trap 'echo "$0 FAILED at line $LINENO!"' ERR
181 }
182
183 function do_download()
184 {
185 local fname="$1"
186 local label="$2"
6a659fd @azman Update Commit
authored Oct 8, 2012
187 local cpath="$(pwd)"
1a8afc0 @azman Dirty Commit
authored Dec 10, 2011
188 [[ "$fname" == "" ]] && exit 1 # shouldn't be here?
189 [[ "$label" == "" ]] && label="$fname"
190 echo -n "Downloading $label: "
191 wget --progress=dot "$fname" 2>&1 | grep --line-buffered "%" | \
192 sed -u -e "s,\.,,g" | awk '{printf("\b\b\b\b%4s", $2)}'
193 echo -ne "\b\b\b\b DONE!\n"
6a659fd @azman Update Commit
authored Oct 8, 2012
194 [[ ! -r "$label" ]] &&
195 echo "Cannot download source $cpath/$label!" && exit 1
196 local chk_perm=$(get_userngrp $cpath)
197 [[ "$chk_perm" != "" ]] && chown $chk_perm $cpath/$label
1a8afc0 @azman Dirty Commit
authored Dec 10, 2011
198 }
199
200 function check_source()
201 {
202 local chk_path="$(pwd)"
203 cd $CURR_PATH
204 if [[ ! -r "$PROG_BALL" ]]; then
205 if [[ "$CHK_DOWNLOAD" == "YES" ]]; then
206 do_download $PROG_LOAD $PROG_BALL
207 else
208 echo "Source $CURR_PATH/$PROG_BALL not found!" && exit 1
209 fi
210 fi
211 cd $chk_path
212 [[ "$CHK_LOADONLY" == "YES" ]] && exit 0
213 return 0
214 }
215
216 function check_buildenv()
217 {
218 # CHECK ENVIRONMENT!
219 case "$PACK_ARCH" in
220 "i486")
221 SLACKCFLAGS="-O2 -march=i486 -mtune=i686"
222 LIBDIRSUFFIX=""
223 ARCHQUADLET=""
224 ;;
225 "i686")
226 SLACKCFLAGS="-O2 -march=i686 -mtune=i686"
227 LIBDIRSUFFIX=""
228 ARCHQUADLET=""
229 ;;
230 "x86_64")
231 SLACKCFLAGS="-O2 -fPIC"
232 LIBDIRSUFFIX="64"
233 ARCHQUADLET=""
234 ;;
235 "arm")
236 SLACKCFLAGS="-O2 -march=armv4t"
237 LIBDIRSUFFIX=""
238 ARCHQUADLET="-gnueabi"
239 ;;
240 *)
241 SLACKCFLAGS="-O2"
242 LIBDIRSUFFIX=""
243 ARCHQUADLET=""
244 ;;
245 esac
246 }
247
248 function prepare_build()
249 {
f7b644f @azman Update Commit
authored Oct 6, 2012
250 rm -rf $DEST_PATH
1a8afc0 @azman Dirty Commit
authored Dec 10, 2011
251 mkdir -p $TEMP_PATH $DEST_PATH $PACK_PATH
252 cd $TEMP_PATH
f7b644f @azman Update Commit
authored Oct 6, 2012
253 rm -rf $PROG_FULL
254 tar xvf $CURR_PATH/$PROG_BALL
1a8afc0 @azman Dirty Commit
authored Dec 10, 2011
255 if [[ -d $PROG_FULL ]]; then
256 cd $PROG_FULL
257 elif [[ -d $PROG_NAME ]]; then
258 cd $PROG_NAME
259 else
260 echo "Cannot find path '$PROG_FULL' or '$PROG_NAME'! Aborting!"
261 exit 1
262 fi
f7b644f @azman Update Commit
authored Oct 6, 2012
263 chown -R root:root .
264 chmod -R u+r+w,go+r-w,a+X-s-t .
1a8afc0 @azman Dirty Commit
authored Dec 10, 2011
265 }
266
267 function strip_binaries()
268 {
269 find $DEST_PATH | xargs file | grep -e "executable" | grep ELF \
270 | cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null || true
271 find $DEST_PATH | xargs file | grep -e "shared object" | grep ELF \
272 | cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null || true
273 }
274
275 function check_manual_info()
276 {
277 # PREPARE MAN PAGES?
278 if [[ -d $DEST_PATH/usr/man ]]; then
279 find $DEST_PATH/usr/man -type f -exec gzip -9 {} \;
280 for i in $(find $DEST_PATH/usr/man -type l) ; do
281 ln -s $( readlink $i ).gz $i.gz
282 rm $i
283 done
284 fi
285 # PREPARE INFO PAGES?
286 if [[ -d $DEST_PATH/usr/info ]]; then
287 gzip -9 $DEST_PATH/usr/info/*.info
288 rm -f $DEST_PATH/usr/info/dir
289 fi
290 }
291
292 function check_documentation()
293 {
294 mkdir -p $DEST_PATH/usr/doc/$PROG_FULL
295 cat $CURR_PATH/$THIS_NAME > $DEST_PATH/usr/doc/$PROG_FULL/$THIS_NAME
296 [[ "$the_docs" == "" ]] && return
297 cp -a $PROG_DOCS $DEST_PATH/usr/doc/$PROG_FULL
298 }
299
1907db9 @azman Update Commit
authored Sep 3, 2012
300 function get_userngrp()
301 {
302 local chk_this=$1
303 local chk_path
304 local chk_user chk_grpn
305 [[ "$chk_this" == "." ]] && chk_this=$(pwd)
306 [[ "$chk_this" == ".." ]] && chk_this=$(cd .. ;pwd)
307 [[ ! -r "$chk_this" ]] && echo -e "Cannot read '$chk_this'!" 1>&2 && return
308 chk_path=$(cd $(dirname $chk_this);pwd)
309 chk_this=$(basename $chk_this)
310 chk_user=$(ls -l "${chk_path}/" | grep -e "${chk_this}$")
311 set -- $chk_user
312 chk_user=$3
313 chk_grpn=$4
314 echo -n "$chk_user:$chk_grpn"
315 }
316
1a8afc0 @azman Dirty Commit
authored Dec 10, 2011
317 function make_slackpkg()
318 {
319 cd $DEST_PATH
320 /sbin/makepkg -l y -c n $PACK_PATH/$PACK_BALL
badc042 @azman Update Commit
authored Dec 19, 2011
321 if [[ "$CHK_MOVEPACK" == "YES" ]]; then
1907db9 @azman Update Commit
authored Sep 3, 2012
322 local chk_perm=$(get_userngrp $MOVE_PATH)
323 [[ "$chk_perm" != "" ]] && chown $chk_perm $PACK_PATH/$PACK_BALL
324 mv $PACK_PATH/$PACK_BALL $MOVE_PATH/
325 echo -e "\nPackage $PACK_PATH/$PACK_BALL moved to $MOVE_PATH!\n"
badc042 @azman Update Commit
authored Dec 19, 2011
326 fi
1a8afc0 @azman Dirty Commit
authored Dec 10, 2011
327 }
328
329 # CHECK COMMAND-LINE PARAMETER - TEMPLATE
330 check_param $@
f7b644f @azman Update Commit
authored Oct 6, 2012
331 # ONLY ROOT CAN BUILD!
332 [[ $UID -ne 0 ]] && echo "[ERROR] Must run as root! Aborting!" && exit 1
1a8afc0 @azman Dirty Commit
authored Dec 10, 2011
333 # IN CASE SOURCE FROM REPO - CUSTOM (OPTIONAL)
334 prepare_source
335 # CHECK IF SOURCE EXISTS - TEMPLATE
336 check_source
337 # CHECK THE BUILD ENVIRONMENT - TEMPLATE
338 check_buildenv
339 # PREPARE FOR THE BUILD - TEMPLATE
340 prepare_build
341 # EXTRA STUFF - CUSTOM (OPTIONAL)
342 do_pre_build
343 # ACTUAL BUILD PROCESS - CUSTOM (STANDARD)
344 do_build
345 # EXTRA STUFF - CUSTOM (OPTIONAL)
346 do_post_build
347 # STRIP SIZE OF BINARIES - TEMPLATE
348 strip_binaries
349 # PREPARE MAN & INFO PAGES - TEMPLATE
350 check_manual_info
351 # COPY DOCUMENTATION FILE(S) - TEMPLATE
352 check_documentation
353 # PREP FOR INSTALLATION - CUSTOM (STANDARD)
354 do_install_stuff
355 # MAKE SLACKWARE PACKAGE - TEMPLATE
356 make_slackpkg
a43a3d7 @azman Update Commit
authored Oct 7, 2012
357 # EXTRA POST-PACKAGING - CUSTOM (OPTIONAL)
358 do_post_package
Something went wrong with that request. Please try again.