fastbulk - More fixes and improvements
[dragonfly.git] / test / fastbulk / Makefile
1 # Makefile for fastbulk - fast incremental pkgsrc bulk [re]build
2 #
3 # deinstall _UPDATE_RUNNING=YES DEINSTALLDEPENDS=ALL
4 # package
5 # show-depends  (output format wildcard:relative_path_to_pkgsrc_dir)
6
7 BUILDBASE=/build/fastbulk
8 BUILDROOT=${BUILDBASE}/root
9 SYSPKGSRC=/usr/pkgsrc
10 SYSROOT=/
11 CHROOTENV=chroot ${BUILDROOT} /bin/sh -c
12 NPARALLEL?= 8
13 # -DNOTMPFS
14
15 all:
16         @echo "fastbulk build options"
17         @echo "    make scratch      - cleanup, setup, cpdup /etc, bootstrap"
18         @echo "    make build        - iterate all dirs / build package"
19         @echo "    make setup        - setup/mount the build environment"
20         @echo "    make cleanup      - unmount the build environment"
21         @echo "    make realclean    - rm -rf the build env except for"
22         @echo "                        packages and distfiles"
23         @echo "    make changes      - deinstall modified packages"
24         @echo "make variables (defaults shown):"
25         @echo ""
26         @echo "    BUILDBASE=/build/fastbulk     all fastbulk-generated files"
27         @echo "    SYSPKGSRC=/usr/pkgsrc         where to get pkgsrc from"
28         @echo "    SYSROOT=/                     rootenv to replicate"
29         @echo "    NPARALLEL=8                   maximum concurrency"
30         @echo ""
31         @echo "NOTE: ${BUILDBASE}/{distfiles,packages} are normally retained"
32         @echo "      to avoid having to re-pull and for incremental operation"
33         @echo ""
34         @echo "NOTE: When building with 'make build' the current progress"
35         @echo "      is in ${BUILDROOT}/tmp/logs/{run,good,bad}, each build"
36         @echo "      has its own log file named after the pkgsrc path"
37
38 scratch: cleanup
39         rm -rf ${BUILDBASE}/var.db
40         rm -rf ${BUILDBASE}/var.db.pkg
41         rm -rf ${BUILDBASE}/var.db.pkg.refcount
42         rm -rf ${BUILDBASE}/etc
43         rm -rf ${BUILDBASE}/usr.pkg
44         rm -rf ${BUILDBASE}/usr.obj/work
45         rm -rf ${BUILDBASE}/tmp/logs
46         rm -rf ${BUILDBASE}/tmp/track
47         cpdup ${SYSROOT}/etc ${BUILDBASE}/etc
48         cpdup ${SYSROOT}/var/db ${BUILDBASE}/var.db
49         rm -rf ${BUILDBASE}/var.db/pkg
50         rm -rf ${BUILDBASE}/var.db/pkg.refcount
51         ${MAKE} setup bootstrap
52         #${MAKE} build
53
54 setup: cleanup
55         mkdir -p ${SYSROOT}/var/db/pkg
56         mkdir -p ${SYSROOT}/var/db/pkg.refcount
57         mkdir -p ${SYSROOT}/usr/pkgsrc
58         mkdir -p ${SYSROOT}/usr/pkg
59         mkdir -p ${BUILDBASE}
60         mkdir -p ${BUILDBASE}/packages
61         mkdir -p ${BUILDBASE}/distfiles
62         mkdir -p ${BUILDBASE}/bin
63         mkdir -p ${BUILDBASE}/tmp
64         mkdir -p ${BUILDBASE}/tmp/track
65         mkdir -p ${BUILDBASE}/tmp/logs
66         mkdir -p ${BUILDBASE}/tmp/logs/run
67         mkdir -p ${BUILDBASE}/tmp/logs/good
68         mkdir -p ${BUILDBASE}/tmp/logs/bad
69         mkdir -p ${BUILDBASE}/etc
70         mkdir -p ${BUILDBASE}/usr.pkg
71         mkdir -p ${BUILDBASE}/usr.pkgsrc
72         mkdir -p ${BUILDBASE}/usr.obj
73         mkdir -p ${BUILDBASE}/var.db
74         mkdir -p ${BUILDBASE}/var.db/pkg
75         mkdir -p ${BUILDBASE}/var.db/pkg.refcount
76         mkdir -p ${BUILDBASE}/var.db.pkg
77         mkdir -p ${BUILDBASE}/var.db.pkg.refcount
78         mkdir -p ${BUILDBASE}/track
79         mkdir -p ${BUILDROOT}
80         mount_null -o ro ${SYSROOT} ${BUILDROOT}
81         mount_null -o ro ${SYSROOT}/usr ${BUILDROOT}/usr
82         mount_null -o ro ${SYSROOT}/var ${BUILDROOT}/var
83         mount_null ${BUILDBASE}/tmp ${BUILDROOT}/tmp
84         mount_null ${BUILDBASE}/tmp ${BUILDROOT}/var/tmp
85         mount_null ${BUILDBASE}/track ${BUILDROOT}/tmp/track
86         mount_null ${BUILDBASE}/etc ${BUILDROOT}/etc
87         mount_null ${BUILDBASE}/usr.pkg ${BUILDROOT}/usr/pkg
88         mount_null ${BUILDBASE}/usr.pkgsrc ${BUILDROOT}/usr/pkgsrc
89 .if defined(NOTMPFS)
90         mount_null ${BUILDBASE}/usr.obj ${BUILDROOT}/usr/obj
91 .else
92         mount_tmpfs dummy ${BUILDROOT}/usr/obj
93 .endif
94         mount_null ${BUILDBASE}/var.db ${BUILDROOT}/var/db
95         mount_null ${BUILDBASE}/var.db.pkg ${BUILDROOT}/var/db/pkg
96         mount_null ${BUILDBASE}/var.db.pkg.refcount \
97                         ${BUILDROOT}/var/db/pkg.refcount
98         mount_null ${SYSROOT}/dev ${BUILDROOT}/dev
99         cpdup -s0 -i0 -X ${.CURDIR}/pkgsrc.ign \
100                         ${SYSPKGSRC} ${BUILDROOT}/usr/pkgsrc
101         find ${BUILDROOT}/usr/pkgsrc -name work | xargs rm -rf
102         mkdir -p ${BUILDROOT}/usr/pkgsrc/packages
103         mkdir -p ${BUILDROOT}/usr/pkgsrc/distfiles
104         mount_null ${BUILDBASE}/packages ${BUILDROOT}/usr/pkgsrc/packages
105         mount_null ${BUILDBASE}/distfiles ${BUILDROOT}/usr/pkgsrc/distfiles
106         echo "finding and removing work directories"
107
108 cleanup:
109         -resident -d ${BUILDROOT}/usr/pkg/bin/bmake
110         -umount ${BUILDROOT}/usr/pkgsrc/distfiles > /dev/null 2>&1
111         -umount ${BUILDROOT}/usr/pkgsrc/packages > /dev/null 2>&1
112         -umount ${BUILDROOT}/usr/pkgsrc > /dev/null 2>&1
113         -umount ${BUILDROOT}/dev > /dev/null 2>&1
114         -umount ${BUILDROOT}/var/db/pkg.refcount > /dev/null 2>&1
115         -umount ${BUILDROOT}/var/db/pkg > /dev/null 2>&1
116         -umount ${BUILDROOT}/var/db > /dev/null 2>&1
117         -umount ${BUILDROOT}/usr/obj > /dev/null 2>&1
118         -umount ${BUILDROOT}/usr/pkg > /dev/null 2>&1
119         -umount ${BUILDROOT}/etc > /dev/null 2>&1
120         -umount ${BUILDROOT}/var/tmp > /dev/null 2>&1
121         -umount ${BUILDROOT}/tmp/track > /dev/null 2>&1
122         -umount ${BUILDROOT}/tmp > /dev/null 2>&1
123         -umount ${BUILDROOT}/var > /dev/null 2>&1
124         -umount ${BUILDROOT}/usr > /dev/null 2>&1
125         -umount ${BUILDROOT} > /dev/null 2>&1
126
127 # Cleans everything except packages and distfiles
128 #
129 realclean: cleanup
130         rm -rf ${BUILDBASE}/bin
131         rm -rf ${BUILDBASE}/tmp
132         rm -rf ${BUILDBASE}/track
133         rm -rf ${BUILDBASE}/usr.pkg
134         rm -rf ${BUILDBASE}/usr.pkgsrc
135         rm -rf ${BUILDBASE}/usr.obj
136         rm -rf ${BUILDBASE}/var.db.pkg
137         rm -rf ${BUILDBASE}/var.db.pkg.refcount
138
139 # Bootstrap an empty chroot setup
140 #
141 bootstrap:
142         rm -rf ${BUILDBASE}/usr.obj/work
143         ${CHROOTENV} "cd /usr/pkgsrc/bootstrap; ./bootstrap --workdir=/usr/obj/work"
144         resident ${BUILDROOT}/usr/pkg/bin/bmake
145         cat mk.conf.add >> ${BUILDROOT}/usr/pkg/etc/mk.conf
146
147 # Figure out what has changed and deinstall the related packages
148 #
149
150 PRESTAGE= ${BUILDBASE}/bin/getpkgsrcdir
151 PRESTAGE+= ${BUILDBASE}/bin/fastbulk
152 PRESTAGE+= ${BUILDBASE}/track/Makefile
153 PRESTAGE+= ${BUILDBASE}/track/dochanges
154 PRESTAGE+= ${BUILDBASE}/track/dobuild
155 PRESTAGE+= ${BUILDBASE}/track/fastbulk
156
157 changes: ${PRESTAGE}
158         @if [ ! -f ${BUILDBASE}/track/dochanges ]; then \
159                 touch ${BUILDBASE}/track/dochanges; fi
160         @if [ ! -f ${BUILDBASE}/track/changes.raw ]; then \
161                 touch ${BUILDBASE}/track/changes.raw; fi
162         ( cat ${BUILDBASE}/track/changes.raw; \
163           find ${SYSPKGSRC} -mnewer ${BUILDBASE}/track/dochanges ) | \
164             sort | uniq | ${BUILDBASE}/bin/getpkgsrcdir ${SYSPKGSRC} | \
165             sort | uniq > ${BUILDBASE}/track/changes.raw.new
166         mv ${BUILDBASE}/track/changes.raw.new ${BUILDBASE}/track/changes.raw
167         ${BUILDBASE}/bin/getpkgsrcdir -s ${SYSPKGSRC} < \
168                 ${BUILDBASE}/track/changes.raw > \
169                 ${BUILDBASE}/track/changes.txt
170         cp Makefile ${BUILDBASE}/track/Makefile
171         ${CHROOTENV} "cd /tmp/track; ./dochanges"
172
173 build: ${PRESTAGE}
174         # note: work dir might be either tmpfs or null mount
175         rm -rf ${BUILDROOT}/usr/obj/work
176         mkdir -p ${BUILDROOT}/usr/obj/work
177         -rm ${BUILDROOT}/tmp/logs/run/*
178         -rm ${BUILDROOT}/tmp/logs/bad/*
179         find ${BUILDROOT}/var/db/pkg -name '*.core' -delete
180         find ${BUILDROOT}/var/db/pkg -type d -depth 1 -delete
181         #${CHROOTENV} "pkg_admin -K /var/db/pkg fetch-pkg-vulnerabilities"
182         #${CHROOTENV} "pkg_admin rebuild"
183         ${CHROOTENV} "cd /tmp/track; ./fastbulk -j ${NPARALLEL} /usr/pkgsrc"
184
185 ${BUILDBASE}/bin/getpkgsrcdir: getpkgsrcdir.c
186         cc getpkgsrcdir.c -o ${BUILDBASE}/bin/getpkgsrcdir
187
188 ${BUILDBASE}/bin/fastbulk: fastbulk.c
189         cc fastbulk.c -o ${BUILDBASE}/bin/fastbulk
190
191 ${BUILDBASE}/track/Makefile: ${.CURDIR}/Makefile
192         cp -p ${.CURDIR}/Makefile ${BUILDBASE}/track/Makefile
193
194 ${BUILDBASE}/track/dochanges: ${.CURDIR}/dochanges
195         cp -p ${.CURDIR}/dochanges ${BUILDBASE}/track/dochanges
196
197 ${BUILDBASE}/track/dobuild: ${.CURDIR}/dobuild
198         cp -p ${.CURDIR}/dobuild ${BUILDBASE}/track/dobuild
199
200 ${BUILDBASE}/track/fastbulk: ${BUILDBASE}/bin/fastbulk
201         cp -p ${BUILDBASE}/bin/fastbulk ${BUILDBASE}/track/fastbulk