Add an installer-fetchpkgs target and other related stuff to reduce the
[dragonfly.git] / release / scripts / X11 / build_x.sh
1 #!/bin/sh
2 #
3 # This script builds X 3.3.x from the XFree86 and XFree86-contrib ports and
4 # installs it into a work directory.  Once that is done, it uses XFree86's
5 # build-bindist command to package up the binary dists leaving them stored
6 # in the 'dist/bindist' subdirectory of the specified output directory.
7
8 # usage information
9 #
10 usage() {
11         echo "$0 <work dir> <output dir>"
12         echo
13         echo "Where <output dir> is the base directory to install X into,"
14         echo "and <work dir> is a scratch directory that the XFree86 ports"
15         echo "can be checked out into and built.  This script also assumes"
16         echo "that it can get the distfiles from /usr/ports/distfiles (or"
17         echo "fetch them into that directory).  The CVSROOT environment"
18         echo "variable should point to a FreeBSD CVS repository."
19         echo
20         echo "Before running this script, the following packages should be"
21         echo "installed:"
22         echo "  XFree86"
23         echo "  Tcl83, Tk83"
24         echo "  ja-Tcl80, ja-Tk80"
25         echo
26         echo "Also, this should really be run as root."
27         exit 1
28 }
29
30 # check the command line
31 if [ $# -ne 2 ]; then
32         usage
33 fi
34
35 # check $CVSROOT
36 if [ -z "$CVSROOT" ]; then
37         echo "\$CVSROOT not set!"
38         echo
39         usage
40 fi
41
42 # setup the output directory
43 output_dir=$2
44 echo ">>> preparing output directory: ${output_dir}"
45 case $output_dir in
46         /*)
47                 ;;
48         *)
49                 output_dir=`pwd`/${output_dir}
50                 ;;
51 esac
52 if [ -r ${output_dir} ]; then
53         if ! rm -rf ${output_dir}; then
54                 echo "Could not remove ${output_dir}!"
55                 echo
56                 usage
57         fi
58 fi
59 if ! mkdir -p ${output_dir}; then
60         echo "Could not create ${output_dir}!"
61         echo
62         usage
63 fi
64 if ! rmdir ${output_dir}; then
65         echo "Could not remove ${output_dir} the second time!"
66         echo
67         usage
68 fi
69
70 # setup the work directory
71 work_dir=$1
72 echo ">>> preparing work directory: ${work_dir}"
73 if [ -r ${work_dir} ]; then
74         if ! rm -rf ${work_dir}; then
75                 echo "Could not remove ${work_dir}!"
76                 echo
77                 usage
78         fi
79 fi
80 if ! mkdir -p ${work_dir}; then
81         echo "Could not create ${work_dir}!"
82         echo
83         usage
84 fi
85 if ! mkdir ${work_dir}/base; then
86         echo "Could not create ${work_dir}/base!"
87         echo
88         usage
89 fi
90 if ! mkdir ${work_dir}/dist; then
91         echo "Could not create ${work_dir}/dist!"
92         echo
93         usage
94 fi
95 if ! mkdir ${work_dir}/ports; then
96         echo "Could not create ${work_dir}/ports!"
97         echo
98         usage
99 fi
100
101 # check out the XFree86 and XFree86-contrib ports and set them up
102 echo ">>> checking out ports"
103 if ! ( cd ${work_dir}/ports && \
104     cvs -R -d ${CVSROOT} co -P XFree86 XFree86-contrib ); then
105         echo "Could not checkout the XFree86 port!"
106         echo
107         usage
108 fi
109 if [ -r  XF86.patch ]; then
110         echo ">>> patching ports"
111         if ! patch -d ${work_dir}/ports/XFree86 < XF86.patch; then
112                 echo "Could not patch the XFree86 port!"
113                 echo
114                 usage
115         fi
116 fi
117
118 # actually build X
119 echo ">>> building X"
120 if ! ( cd ${work_dir}/ports/XFree86 && \
121     make BUILD_XDIST=yes DISTDIR=/usr/ports/distfiles \
122     DESTDIR=${work_dir}/base NO_PKG_REGISTER=yes all install ); then
123         echo "Could not build XFree86!"
124         echo
125         usage
126 fi
127 if ! ( cd ${work_dir}/ports/XFree86-contrib && \
128     make DISTDIR=/usr/ports/distfiles DESTDIR=${work_dir}/base \
129     NO_PKG_REGISTER=yes all install ); then
130         echo "Could not build XFree86-contrib!"
131         echo
132         usage
133 fi
134
135 # now package up the bindists
136 echo ">>> building bindist"
137 bindist_dir=${work_dir}/ports/XFree86/work/xc/programs/Xserver/hw/xfree86/etc/bindist
138 if ! cp ${bindist_dir}/FreeBSD-ELF/* ${work_dir}/dist; then
139         echo "Could not copy over distribution lists!"
140         echo
141         usage
142 fi
143 if ! cp ${bindist_dir}/common/* ${work_dir}/dist; then
144         echo "Could not copy over distribution lists!"
145         echo
146         usage
147 fi
148 if ! ${bindist_dir}/build-bindist X ${work_dir}/base ${work_dir}/dist; then
149         echo "Could not package up binary dists!"
150         echo
151         usage
152 fi
153 if ! mv ${work_dir}/dist/bindist ${output_dir}; then
154         echo "Could not move binary dists into ${output_dir}!"
155         echo
156         usage
157 fi