fastbulk - Remove core files & empty dirs from /var/pkg/db
[dragonfly.git] / test / fastbulk / Makefile
CommitLineData
b050e616
MD
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
7BUILDBASE=/build/fastbulk
8BUILDROOT=${BUILDBASE}/root
9SYSPKGSRC=/usr/pkgsrc
10SYSROOT=/
11CHROOTENV=chroot ${BUILDROOT} /bin/sh -c
12NPARALLEL?= 8
1b3b024a 13# -DNOTMPFS
b050e616
MD
14
15all:
16 @echo "fastbulk build options"
3c86cbff 17 @echo " make scratch - cleanup, setup, cpdup /etc, bootstrap"
b050e616 18 @echo " make build - iterate all dirs / build package"
3c86cbff
MD
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 ""
1b3b024a
MD
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"
b050e616
MD
37
38scratch: 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
54setup: 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
5b966949 71 mkdir -p ${BUILDBASE}/usr.pkgsrc
b050e616
MD
72 mkdir -p ${BUILDBASE}/usr.obj
73 mkdir -p ${BUILDBASE}/var.db
3c86cbff
MD
74 mkdir -p ${BUILDBASE}/var.db/pkg
75 mkdir -p ${BUILDBASE}/var.db/pkg.refcount
b050e616
MD
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
5b966949 88 mount_null ${BUILDBASE}/usr.pkgsrc ${BUILDROOT}/usr/pkgsrc
1b3b024a 89.if defined(NOTMPFS)
b050e616 90 mount_null ${BUILDBASE}/usr.obj ${BUILDROOT}/usr/obj
1b3b024a
MD
91.else
92 mount_tmpfs dummy ${BUILDROOT}/usr/obj
93.endif
b050e616
MD
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
1b3b024a 99 cpdup -s0 -i0 -X ${.CURDIR}/pkgsrc.ign \
5b966949
MD
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
b050e616
MD
104 mount_null ${BUILDBASE}/packages ${BUILDROOT}/usr/pkgsrc/packages
105 mount_null ${BUILDBASE}/distfiles ${BUILDROOT}/usr/pkgsrc/distfiles
5b966949 106 echo "finding and removing work directories"
b050e616
MD
107
108cleanup:
5b966949 109 -resident -d ${BUILDROOT}/usr/pkg/bin/bmake
b050e616
MD
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#
129realclean: cleanup
130 rm -rf ${BUILDBASE}/bin
131 rm -rf ${BUILDBASE}/tmp
132 rm -rf ${BUILDBASE}/track
133 rm -rf ${BUILDBASE}/usr.pkg
5b966949 134 rm -rf ${BUILDBASE}/usr.pkgsrc
b050e616
MD
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#
141bootstrap:
142 rm -rf ${BUILDBASE}/usr.obj/work
143 ${CHROOTENV} "cd /usr/pkgsrc/bootstrap; ./bootstrap --workdir=/usr/obj/work"
5b966949 144 resident ${BUILDROOT}/usr/pkg/bin/bmake
1b3b024a 145 cat mk.conf.add >> ${BUILDROOT}/usr/pkg/etc/mk.conf
b050e616
MD
146
147# Figure out what has changed and deinstall the related packages
148#
149
150PRESTAGE= ${BUILDBASE}/bin/getpkgsrcdir
151PRESTAGE+= ${BUILDBASE}/bin/fastbulk
152PRESTAGE+= ${BUILDBASE}/track/Makefile
153PRESTAGE+= ${BUILDBASE}/track/dochanges
154PRESTAGE+= ${BUILDBASE}/track/dobuild
155PRESTAGE+= ${BUILDBASE}/track/fastbulk
156
157changes: ${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
173build: ${PRESTAGE}
174 rm -rf ${BUILDBASE}/usr.obj/work
175 mkdir -p ${BUILDBASE}/usr.obj/work
1b3b024a 176 -rm ${BUILDROOT}/tmp/logs/run/*
e0b03599
MD
177 find ${BUILDROOT}/var/db/pkg -name '*.core' -delete
178 find ${BUILDROOT}/var/db/pkg -type d -depth 1 -delete
179 #${CHROOTENV} "pkg_admin -K /var/db/pkg fetch-pkg-vulnerabilities"
180 #${CHROOTENV} "pkg_admin rebuild"
b050e616
MD
181 ${CHROOTENV} "cd /tmp/track; ./fastbulk -j ${NPARALLEL} /usr/pkgsrc"
182
183${BUILDBASE}/bin/getpkgsrcdir: getpkgsrcdir.c
184 cc getpkgsrcdir.c -o ${BUILDBASE}/bin/getpkgsrcdir
185
186${BUILDBASE}/bin/fastbulk: fastbulk.c
187 cc fastbulk.c -o ${BUILDBASE}/bin/fastbulk
188
189${BUILDBASE}/track/Makefile: ${.CURDIR}/Makefile
190 cp -p ${.CURDIR}/Makefile ${BUILDBASE}/track/Makefile
191
192${BUILDBASE}/track/dochanges: ${.CURDIR}/dochanges
193 cp -p ${.CURDIR}/dochanges ${BUILDBASE}/track/dochanges
194
195${BUILDBASE}/track/dobuild: ${.CURDIR}/dobuild
196 cp -p ${.CURDIR}/dobuild ${BUILDBASE}/track/dobuild
197
198${BUILDBASE}/track/fastbulk: ${BUILDBASE}/bin/fastbulk
199 cp -p ${BUILDBASE}/bin/fastbulk ${BUILDBASE}/track/fastbulk