summaryrefslogtreecommitdiffstats
path: root/contrib/mingw/build-autotools.sh
blob: f72ffbe9e119b5b34354a5cba589ab045eb64d19 (plain) (blame)
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
#! /bin/sh

terminate()
{
  echo "error: $*" >&2
  if [ $? -eq 0 ]; then
    exit 222
  fi
  exit $?
}

check()
{
  if [ $? -ne 0 ]; then
    terminate $*
  fi
}

source=$(dirname $0)

if [ "$source" = "." ]; then
  source=$(pwd)
fi

build=none
clean=no
prefix=none

while [ $# -gt 0 ];
do
  case $1 in
    -b)
      shift
      build=$1
      ;;
    -c)
      shift
      config=$1
      ;;
    -d)
      set -x
      ;;
    -h)
      usage
      exit 223
      ;;
    -p)
      shift
      prefix=$1
      ;;
    -s)
      shift
      source=$1
      ;;
    *)
      terminate "invalid option (try -h): $1"
      ;;
  esac
  shift
done

#
# dirdepth: find the depth of a directory
#
# $1 : path
#
dirdepth()
{
  local depth=0
  local p=$1
  p=$(echo $p | sed -e "s/^\///g")
  p=$(echo $p | sed -e "s/\/$//g")
  while [ $p != . ];
  do
    depth=$(expr $depth + 1)
    p=$(dirname $p)
  done
  echo $depth
}

#
# build_package()
#
# $1 : package
# $2 : package source
# $3 : tar options
# $4 : patch list
#
build_package()
{
  local mydir=$(pwd)

  if [ ! -f $source/$2 ]; then
    terminate "$1 source is not present or not a file: $2"
  fi

  for p in $4
  do
    if [ ! -f $source/$p ]; then
      terminate "$1 patch is not present or not a file: $p"
    fi
  done

  echo "cd $build"
  cd $build
  check "changing to $build directory"

  echo "tar $3 $source/$2"
  tar $3 $source/$2
  check "extraction of source: $2"

  echo "cd $build/$1"
  cd $build/$1
  check "changing to $build/$1 directory"

  for p in $4
  do
    echo "patch -p0 < $source/$p"
    patch -p0 < $source/$p
    check "patching $autoconf with $p"
  done

  echo "cd $build"
  cd $build
  check "changing to $build directory"

  echo "rm -rf mingw32-$1"
  rm -rf mingw32-$1
  check "removing mingw32-$1 build directory"

  echo "mkdir mingw32-$1"
  mkdir mingw32-$1
  check "creating mingw32-$1"

  echo "cd $build/mingw32-$1"
  cd $build/mingw32-$1
  check "changing to $build/mingw32-$1"

  echo "$build/$1/configure --prefix=$prefix"
  $build/$1/configure --prefix=$prefix
  check "configuring $1"

  echo "make"
  make
  check "building $1"

  echo "make DESTDIR=$build/install-$1 install"
  make DESTDIR=$build/install-$1 install
  check "installing to $build/install-$1"

  echo find $build/install-$1$prefix -type f
  local files=$(find $build/install-$1$prefix -type f)
  check "reading $1 file list"

  of=$prefix/Uninstall/$1-files
  echo "b install-$1$prefix" | sed -e "s/\//\\\\/g" >> $of

  re_path=$(echo $build/install-$1$prefix/ | sed -e 's/\//\\\//g' -e 's/\./\\\./g')

  dirs=
  for f in $files
  do
    if [ $(basename $f) = dir ]; then
      continue
    fi
    f=$(echo $f | sed -e "s/$re_path//g")
    found=no
    fd=$(dirname $f)
    for d in $dirs
    do
      if [ $d = $fd ]; then
        found=yes
        break;
      fi
    done
    if [ $found = no ]; then
      echo "d $fd" | sed -e "s/\//\\\\/g" >> $of
      dirs="$fd $dirs"
    fi
    echo "f $f" | sed -e "s/\//\\\\/g" >> $of
  done

  for d in $dirs
  do
    while [ $d != . ]
    do
      found=no
      for rd in $dirs
      do
        if [ "$d" = "$rd" ]; then
          found=yes
          break
        fi
      done
      if [ $found = no ]; then
        dirs="$dirs $d"
      fi
      d=$(dirname $d)
    done
  done

  sorted_dirs=
  for d in $dirs
  do
    depth=$(dirdepth $d)
    nsp=
    for sd in $sorted_dirs
    do
      if [ ! -z "$d" ]; then
        spd=$(dirdepth $sd)
        if [ $depth -ge $spd ]; then
          sd="$d $sd"
          d=
        fi
      fi
      nsp="$nsp $sd"
    done
    if [ ! -z "$d" ]; then
      nsp="$nsp $d"
    fi
    sorted_dirs=$nsp
  done

  for d in $sorted_dirs
  do
    echo "D $d" | sed -e "s/\//\\\\/g" >> $of
  done

  echo "cd $mydir"
  cd $mydir
  check "changing to $mydir"
}

munch_path()
{
  local p=$1
  if [ $(echo $p | sed -e "s/[a-zA-Z]:.*/yes/g") = yes ]; then
    p=$(echo $p | sed -e "s/^[a-zA-Z]:/\/\0/g" -e "s/://g")
  fi
  echo $p
}

if [ $build = none ]; then
  terminate "no build specified (try -h)"
fi

if [ $prefix = none ]; then
  terminate "no prefix specified (try -h)"
fi

source=$(munch_path $source)
build=$(munch_path $build)
prefix=$(munch_path $prefix)
config=$(munch_path $config)

if [ ! -d $build ]; then
  terminate "build path is not a directory or does not exist: $build"
fi

if [ ! -d $prefix ]; then
  terminate "prefix path is not a directory or does not exist: $prefix"
fi

if [ ! -f $config ]; then
  terminate "could find package configuration file: $config"
fi

. $config

# Need to handle paths carefully as a problem seems to exist
# with autoconf when it is in the path.
if [ $(echo $package_name | sed -e "s/autoconf-.*/yes/g") != yes ]; then
 export PATH=$prefix/bin:$PATH
fi

build_package $package_name \
              $package_source \
              $package_taropts \
              "$package_patches"

exit $?