aboutsummaryrefslogtreecommitdiff
path: root/Tools/portbuild/scripts/buildscript
blob: 986d2ff8e0972bbabc3d66c9ed5b9480a0917fc3 (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
#!/bin/sh

# usage: $0 DIRNAME PHASE
#   PHASE is 1 (checksum) or 2 (package)

cleanup() {
  status=$1

  if [ -e ${dir}/.keep ]; then
    cd ${dir}
    objdir=$(make -V WRKDIR)
    tar cfjC /tmp/work.tbz ${objdir}/.. work
  fi

  cat /tmp/make.log${status}
  echo 1 > /tmp/status
  echo "================================================================"
  echo -n "build ended at "
  date

  exit 0
}

add_pkg() {
  pkgs=$*

  echo add_pkg $pkgs
  cd /tmp/depends
  export PKG_PATH=/tmp/depends
  if [ ! -z "${pkgs}" ]; then
    echo "adding dependencies"
    for i in $pkgs; do
      echo "pkg_add $i"
      base=$(basename $i .tgz)
      base=$(basename $base .tbz)
      if pkg_info -q -e $base; then
        echo "skipping $base, already added"
      else
        if ! pkg_add $i; then
          echo "error in dependency $i, exiting"
          echo "1" > /tmp/status
          exit 1
        fi
      fi
    done
  fi
}

del_pkg() {
  pkgs=$*

  cd /tmp/depends
  export PKG_PATH=/tmp/depends
  if [ ! -z "${pkgs}" ]; then
    unset delpkg
    for i in $pkgs; do
      base=$(basename $i .tgz)
      base=$(basename $base .tbz)
      if ! pkg_info -q -e $base; then
        echo "skipping $base, already deleted"
      else
	delpkg="${base} ${delpkg}"
      fi
    done
    echo "Deleting $delpkg"
    if ! (echo ${delpkg} | xargs pkg_delete -f); then
      echo "error in pkg_delete, exiting"
      echo "1" > /tmp/status
      exit 1
    fi
  fi
}

dir=$1
phase=$2

ED=$3
PD=$4
FD=$5
BD=$6
RD=$7

if [ $phase = 1 ]; then

  cd $dir || exit 1
  echo "maintained by: $(make maintainer)"
  echo "port directory: ${dir}"
  echo "build started at $(date)"

  echo "FETCH_DEPENDS=${FD}"
  echo "PATCH_DEPENDS=${PD}"
  echo "EXTRACT_DEPENDS=${ED}"
  echo "BUILD_DEPENDS=${BD}"
  echo "RUN_DEPENDS=${RD}"

  add_pkg $FD

  #Allow ports to notice they're being run on bento
  export PACKAGE_BUILDING=1

  cd $dir || exit 1
  pkgname=$(make package-name)
  echo "================================================================"
  echo "====================<phase 1: make checksum>===================="

  if /pnohang $TIMEOUT /tmp/make.log1 ${pkgname} make checksum; then
    cat /tmp/make.log1
    echo "0" > /tmp/status
  else
    cleanup 1
  fi

else

  xvfb=0
  if which -s Xvfb; then
    xvfb=1
    pid=$(echo $$ % 32768 | bc)
    X11BASE=$(which Xvfb | sed -e 's./bin/Xvfb..')
    Xvfb :${pid} -fp ${X11BASE}/lib/X11/fonts/misc &
    DISPLAY=:${pid}
    export DISPLAY
  fi

  cd $dir || exit 1
  pkgname=$(make package-name)

  echo "================================================================"
  echo "====================<phase 2: make extract>===================="
  add_pkg ${ED}
  cd $dir
  /pnohang $TIMEOUT /tmp/make.log2 ${pkgname} make extract || cleanup 2
  cat /tmp/make.log2
  del_pkg ${ED}

  echo "================================================================"
  echo "====================<phase 3: make patch>===================="
  add_pkg ${PD}
  cd $dir
  /pnohang $TIMEOUT /tmp/make.log3 ${pkgname} make patch || cleanup 3
  cat /tmp/make.log3
  del_pkg ${PD}

  echo "================================================================"
  echo "====================<phase 4: make build>===================="
  add_pkg ${BD}
  cd $dir
  /pnohang $TIMEOUT /tmp/make.log4 ${pkgname} make build || cleanup 4
  cat /tmp/make.log4

  echo "================================================================"
  echo "====================<phase 5: make package>===================="
  add_pkg ${RD}
  cat > /tmp/mtree.exclude <<EOF
./var/*
./tmp/*
EOF
  mtree -X /tmp/mtree.exclude -xcn -k uid,gid,mode -p / > /tmp/mtree
  cd $dir
  if /pnohang $TIMEOUT /tmp/make.log5 ${pkgname} make package; then
    cat /tmp/make.log5
    echo "0" > /tmp/status
    prefix=$(make -V PREFIX)
    del_pkg ${pkgname}

    mtree -X /tmp/mtree.exclude -x -f /tmp/mtree -p / | egrep -v '^(usr/local/share/nls/POSIX|usr/local/share/nls/en_US.US-ASCII|etc/shells.bak|etc/services|compat |usr/X11R6 |etc/manpath.config|usr/local/info/dir)' > /tmp/list3

    # BUILD_DEPENDS need to be present at install-time, e.g. gmake
    # Concatenate and remove duplicates
    BRD=$(echo $BD $RD | tr ' ' '\n' | sort -u | tr '\n' ' ')
    del_pkg ${BRD}
    cd /var/db/pkg
    if [ $(echo $(echo * | wc -c)) != 2 ]; then
      echo "leftover packages:" *
      del_pkg *
    fi

    if [ -s /tmp/list3 ]; then
      echo "================================================================"
      echo "list of extra files and directories in /"
      cat /tmp/list3
      if [ "x${PLISTCHECK}" != "x" ]; then
        echo "1" > /tmp/status
      fi
    fi
  else
    cleanup 5
  fi

  if [ ${xvfb} = 1 ]; then
    kill $(jobid %1)
  fi

  if [ -e ${dir}/.keep ]; then
    cd ${dir}
    objdir=$(make -V WRKDIR)
    tar cfjC /tmp/work.tbz ${objdir}/.. work
  fi

fi

exit 0