7d0cf3d87fa963ae5066d0b0409b56f46a8aa536
[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
14 all:
15         @echo "fastbulk build options"
16         @echo "    make scratch      - cleanup, setup, cpdup /etc, bootstrap"
17         @echo "    make build        - iterate all dirs / build package"
18         @echo "    make setup        - setup/mount the build environment"
19         @echo "    make cleanup      - unmount the build environment"
20         @echo "    make realclean    - rm -rf the build env except for"
21         @echo "                        packages and distfiles"
22         @echo "    make changes      - deinstall modified packages"
23         @echo "make variables (defaults shown):"
24         @echo ""
25         @echo "    BUILDBASE=/build/fastbulk     all fastbulk-generated files"
26         @echo "    SYSPKGSRC=/usr/pkgsrc         where to get pkgsrc from"
27         @echo "    SYSROOT=/                     rootenv to replicate"
28         @echo "    NPARALLEL=8                   maximum concurrency"
29         @echo ""
30         @echo "NOTE: ${BUILDBASE}/{distfiles,packages} are normally retained"
31         @echo "      to avoid having to re-pull and for incremental operation"
32         @echo ""
33
34 scratch: cleanup
35         rm -rf ${BUILDBASE}/var.db
36         rm -rf ${BUILDBASE}/var.db.pkg
37         rm -rf ${BUILDBASE}/var.db.pkg.refcount
38         rm -rf ${BUILDBASE}/etc
39         rm -rf ${BUILDBASE}/usr.pkg
40         rm -rf ${BUILDBASE}/usr.obj/work
41         rm -rf ${BUILDBASE}/tmp/logs
42         rm -rf ${BUILDBASE}/tmp/track
43         cpdup ${SYSROOT}/etc ${BUILDBASE}/etc
44         cpdup ${SYSROOT}/var/db ${BUILDBASE}/var.db
45         rm -rf ${BUILDBASE}/var.db/pkg
46         rm -rf ${BUILDBASE}/var.db/pkg.refcount
47         ${MAKE} setup bootstrap
48         #${MAKE} build
49
50 setup: cleanup
51         mkdir -p ${SYSROOT}/var/db/pkg
52         mkdir -p ${SYSROOT}/var/db/pkg.refcount
53         mkdir -p ${SYSROOT}/usr/pkgsrc
54         mkdir -p ${SYSROOT}/usr/pkg
55         mkdir -p ${BUILDBASE}
56         mkdir -p ${BUILDBASE}/packages
57         mkdir -p ${BUILDBASE}/distfiles
58         mkdir -p ${BUILDBASE}/bin
59         mkdir -p ${BUILDBASE}/tmp
60         mkdir -p ${BUILDBASE}/tmp/track
61         mkdir -p ${BUILDBASE}/tmp/logs
62         mkdir -p ${BUILDBASE}/tmp/logs/run
63         mkdir -p ${BUILDBASE}/tmp/logs/good
64         mkdir -p ${BUILDBASE}/tmp/logs/bad
65         mkdir -p ${BUILDBASE}/etc
66         mkdir -p ${BUILDBASE}/usr.pkg
67         mkdir -p ${BUILDBASE}/usr.pkgsrc
68         mkdir -p ${BUILDBASE}/usr.obj
69         mkdir -p ${BUILDBASE}/var.db
70         mkdir -p ${BUILDBASE}/var.db/pkg
71         mkdir -p ${BUILDBASE}/var.db/pkg.refcount
72         mkdir -p ${BUILDBASE}/var.db.pkg
73         mkdir -p ${BUILDBASE}/var.db.pkg.refcount
74         mkdir -p ${BUILDBASE}/track
75         mkdir -p ${BUILDROOT}
76         mount_null -o ro ${SYSROOT} ${BUILDROOT}
77         mount_null -o ro ${SYSROOT}/usr ${BUILDROOT}/usr
78         mount_null -o ro ${SYSROOT}/var ${BUILDROOT}/var
79         mount_null ${BUILDBASE}/tmp ${BUILDROOT}/tmp
80         mount_null ${BUILDBASE}/tmp ${BUILDROOT}/var/tmp
81         mount_null ${BUILDBASE}/track ${BUILDROOT}/tmp/track
82         mount_null ${BUILDBASE}/etc ${BUILDROOT}/etc
83         mount_null ${BUILDBASE}/usr.pkg ${BUILDROOT}/usr/pkg
84         mount_null ${BUILDBASE}/usr.pkgsrc ${BUILDROOT}/usr/pkgsrc
85         mount_null ${BUILDBASE}/usr.obj ${BUILDROOT}/usr/obj
86         mount_null ${BUILDBASE}/var.db ${BUILDROOT}/var/db
87         mount_null ${BUILDBASE}/var.db.pkg ${BUILDROOT}/var/db/pkg
88         mount_null ${BUILDBASE}/var.db.pkg.refcount \
89                         ${BUILDROOT}/var/db/pkg.refcount
90         mount_null ${SYSROOT}/dev ${BUILDROOT}/dev
91         cpdup -v -s0 -i0 -X ${.CURDIR}/pkgsrc.ign \
92                         ${SYSPKGSRC} ${BUILDROOT}/usr/pkgsrc
93         find ${BUILDROOT}/usr/pkgsrc -name work | xargs rm -rf
94         mkdir -p ${BUILDROOT}/usr/pkgsrc/packages
95         mkdir -p ${BUILDROOT}/usr/pkgsrc/distfiles
96         mount_null ${BUILDBASE}/packages ${BUILDROOT}/usr/pkgsrc/packages
97         mount_null ${BUILDBASE}/distfiles ${BUILDROOT}/usr/pkgsrc/distfiles
98         echo "finding and removing work directories"
99
100 cleanup:
101         -resident -d ${BUILDROOT}/usr/pkg/bin/bmake
102         -umount ${BUILDROOT}/usr/pkgsrc/distfiles > /dev/null 2>&1
103         -umount ${BUILDROOT}/usr/pkgsrc/packages > /dev/null 2>&1
104         -umount ${BUILDROOT}/usr/pkgsrc > /dev/null 2>&1
105         -umount ${BUILDROOT}/dev > /dev/null 2>&1
106         -umount ${BUILDROOT}/var/db/pkg.refcount > /dev/null 2>&1
107         -umount ${BUILDROOT}/var/db/pkg > /dev/null 2>&1
108         -umount ${BUILDROOT}/var/db > /dev/null 2>&1
109         -umount ${BUILDROOT}/usr/obj > /dev/null 2>&1
110         -umount ${BUILDROOT}/usr/pkg > /dev/null 2>&1
111         -umount ${BUILDROOT}/etc > /dev/null 2>&1
112         -umount ${BUILDROOT}/var/tmp > /dev/null 2>&1
113         -umount ${BUILDROOT}/tmp/track > /dev/null 2>&1
114         -umount ${BUILDROOT}/tmp > /dev/null 2>&1
115         -umount ${BUILDROOT}/var > /dev/null 2>&1
116         -umount ${BUILDROOT}/usr > /dev/null 2>&1
117         -umount ${BUILDROOT} > /dev/null 2>&1
118
119 # Cleans everything except packages and distfiles
120 #
121 realclean: cleanup
122         rm -rf ${BUILDBASE}/bin
123         rm -rf ${BUILDBASE}/tmp
124         rm -rf ${BUILDBASE}/track
125         rm -rf ${BUILDBASE}/usr.pkg
126         rm -rf ${BUILDBASE}/usr.pkgsrc
127         rm -rf ${BUILDBASE}/usr.obj
128         rm -rf ${BUILDBASE}/var.db.pkg
129         rm -rf ${BUILDBASE}/var.db.pkg.refcount
130
131 # Bootstrap an empty chroot setup
132 #
133 bootstrap:
134         rm -rf ${BUILDBASE}/usr.obj/work
135         ${CHROOTENV} "cd /usr/pkgsrc/bootstrap; ./bootstrap --workdir=/usr/obj/work"
136         resident ${BUILDROOT}/usr/pkg/bin/bmake
137
138 # Figure out what has changed and deinstall the related packages
139 #
140
141 PRESTAGE= ${BUILDBASE}/bin/getpkgsrcdir
142 PRESTAGE+= ${BUILDBASE}/bin/fastbulk
143 PRESTAGE+= ${BUILDBASE}/track/Makefile
144 PRESTAGE+= ${BUILDBASE}/track/dochanges
145 PRESTAGE+= ${BUILDBASE}/track/dobuild
146 PRESTAGE+= ${BUILDBASE}/track/fastbulk
147
148 changes: ${PRESTAGE}
149         @if [ ! -f ${BUILDBASE}/track/dochanges ]; then \
150                 touch ${BUILDBASE}/track/dochanges; fi
151         @if [ ! -f ${BUILDBASE}/track/changes.raw ]; then \
152                 touch ${BUILDBASE}/track/changes.raw; fi
153         ( cat ${BUILDBASE}/track/changes.raw; \
154           find ${SYSPKGSRC} -mnewer ${BUILDBASE}/track/dochanges ) | \
155             sort | uniq | ${BUILDBASE}/bin/getpkgsrcdir ${SYSPKGSRC} | \
156             sort | uniq > ${BUILDBASE}/track/changes.raw.new
157         mv ${BUILDBASE}/track/changes.raw.new ${BUILDBASE}/track/changes.raw
158         ${BUILDBASE}/bin/getpkgsrcdir -s ${SYSPKGSRC} < \
159                 ${BUILDBASE}/track/changes.raw > \
160                 ${BUILDBASE}/track/changes.txt
161         cp Makefile ${BUILDBASE}/track/Makefile
162         ${CHROOTENV} "cd /tmp/track; ./dochanges"
163
164 build: ${PRESTAGE}
165         rm -rf ${BUILDBASE}/usr.obj/work
166         mkdir -p ${BUILDBASE}/usr.obj/work
167         ${CHROOTENV} "cd /tmp/track; ./fastbulk -j ${NPARALLEL} /usr/pkgsrc"
168
169 ${BUILDBASE}/bin/getpkgsrcdir: getpkgsrcdir.c
170         cc getpkgsrcdir.c -o ${BUILDBASE}/bin/getpkgsrcdir
171
172 ${BUILDBASE}/bin/fastbulk: fastbulk.c
173         cc fastbulk.c -o ${BUILDBASE}/bin/fastbulk
174
175 ${BUILDBASE}/track/Makefile: ${.CURDIR}/Makefile
176         cp -p ${.CURDIR}/Makefile ${BUILDBASE}/track/Makefile
177
178 ${BUILDBASE}/track/dochanges: ${.CURDIR}/dochanges
179         cp -p ${.CURDIR}/dochanges ${BUILDBASE}/track/dochanges
180
181 ${BUILDBASE}/track/dobuild: ${.CURDIR}/dobuild
182         cp -p ${.CURDIR}/dobuild ${BUILDBASE}/track/dobuild
183
184 ${BUILDBASE}/track/fastbulk: ${BUILDBASE}/bin/fastbulk
185         cp -p ${BUILDBASE}/bin/fastbulk ${BUILDBASE}/track/fastbulk