a4fe2d9a90481acc235182d6b8d5b86a512eeca0
[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.obj
68         mkdir -p ${BUILDBASE}/var.db
69         mkdir -p ${BUILDBASE}/var.db/pkg
70         mkdir -p ${BUILDBASE}/var.db/pkg.refcount
71         mkdir -p ${BUILDBASE}/var.db.pkg
72         mkdir -p ${BUILDBASE}/var.db.pkg.refcount
73         mkdir -p ${BUILDBASE}/track
74         mkdir -p ${BUILDROOT}
75         mount_null -o ro ${SYSROOT} ${BUILDROOT}
76         mount_null -o ro ${SYSROOT}/usr ${BUILDROOT}/usr
77         mount_null -o ro ${SYSROOT}/var ${BUILDROOT}/var
78         mount_null ${BUILDBASE}/tmp ${BUILDROOT}/tmp
79         mount_null ${BUILDBASE}/tmp ${BUILDROOT}/var/tmp
80         mount_null ${BUILDBASE}/track ${BUILDROOT}/tmp/track
81         mount_null ${BUILDBASE}/etc ${BUILDROOT}/etc
82         mount_null ${BUILDBASE}/usr.pkg ${BUILDROOT}/usr/pkg
83         mount_null ${BUILDBASE}/usr.obj ${BUILDROOT}/usr/obj
84         mount_null ${BUILDBASE}/var.db ${BUILDROOT}/var/db
85         mount_null ${BUILDBASE}/var.db.pkg ${BUILDROOT}/var/db/pkg
86         mount_null ${BUILDBASE}/var.db.pkg.refcount \
87                         ${BUILDROOT}/var/db/pkg.refcount
88         mount_null ${SYSROOT}/dev ${BUILDROOT}/dev
89         mount_null ${SYSPKGSRC} ${BUILDROOT}/usr/pkgsrc
90         mount_null ${BUILDBASE}/packages ${BUILDROOT}/usr/pkgsrc/packages
91         mount_null ${BUILDBASE}/distfiles ${BUILDROOT}/usr/pkgsrc/distfiles
92
93 cleanup:
94         -umount ${BUILDROOT}/usr/pkgsrc/distfiles > /dev/null 2>&1
95         -umount ${BUILDROOT}/usr/pkgsrc/packages > /dev/null 2>&1
96         -umount ${BUILDROOT}/usr/pkgsrc > /dev/null 2>&1
97         -umount ${BUILDROOT}/dev > /dev/null 2>&1
98         -umount ${BUILDROOT}/var/db/pkg.refcount > /dev/null 2>&1
99         -umount ${BUILDROOT}/var/db/pkg > /dev/null 2>&1
100         -umount ${BUILDROOT}/var/db > /dev/null 2>&1
101         -umount ${BUILDROOT}/usr/obj > /dev/null 2>&1
102         -umount ${BUILDROOT}/usr/pkg > /dev/null 2>&1
103         -umount ${BUILDROOT}/etc > /dev/null 2>&1
104         -umount ${BUILDROOT}/var/tmp > /dev/null 2>&1
105         -umount ${BUILDROOT}/tmp/track > /dev/null 2>&1
106         -umount ${BUILDROOT}/tmp > /dev/null 2>&1
107         -umount ${BUILDROOT}/var > /dev/null 2>&1
108         -umount ${BUILDROOT}/usr > /dev/null 2>&1
109         -umount ${BUILDROOT} > /dev/null 2>&1
110
111 # Cleans everything except packages and distfiles
112 #
113 realclean: cleanup
114         rm -rf ${BUILDBASE}/bin
115         rm -rf ${BUILDBASE}/tmp
116         rm -rf ${BUILDBASE}/track
117         rm -rf ${BUILDBASE}/usr.pkg
118         rm -rf ${BUILDBASE}/usr.obj
119         rm -rf ${BUILDBASE}/var.db.pkg
120         rm -rf ${BUILDBASE}/var.db.pkg.refcount
121
122 # Bootstrap an empty chroot setup
123 #
124 bootstrap:
125         rm -rf ${BUILDBASE}/usr.obj/work
126         ${CHROOTENV} "cd /usr/pkgsrc/bootstrap; ./bootstrap --workdir=/usr/obj/work"
127
128 # Figure out what has changed and deinstall the related packages
129 #
130
131 PRESTAGE= ${BUILDBASE}/bin/getpkgsrcdir
132 PRESTAGE+= ${BUILDBASE}/bin/fastbulk
133 PRESTAGE+= ${BUILDBASE}/track/Makefile
134 PRESTAGE+= ${BUILDBASE}/track/dochanges
135 PRESTAGE+= ${BUILDBASE}/track/dobuild
136 PRESTAGE+= ${BUILDBASE}/track/fastbulk
137
138 changes: ${PRESTAGE}
139         @if [ ! -f ${BUILDBASE}/track/dochanges ]; then \
140                 touch ${BUILDBASE}/track/dochanges; fi
141         @if [ ! -f ${BUILDBASE}/track/changes.raw ]; then \
142                 touch ${BUILDBASE}/track/changes.raw; fi
143         ( cat ${BUILDBASE}/track/changes.raw; \
144           find ${SYSPKGSRC} -mnewer ${BUILDBASE}/track/dochanges ) | \
145             sort | uniq | ${BUILDBASE}/bin/getpkgsrcdir ${SYSPKGSRC} | \
146             sort | uniq > ${BUILDBASE}/track/changes.raw.new
147         mv ${BUILDBASE}/track/changes.raw.new ${BUILDBASE}/track/changes.raw
148         ${BUILDBASE}/bin/getpkgsrcdir -s ${SYSPKGSRC} < \
149                 ${BUILDBASE}/track/changes.raw > \
150                 ${BUILDBASE}/track/changes.txt
151         cp Makefile ${BUILDBASE}/track/Makefile
152         ${CHROOTENV} "cd /tmp/track; ./dochanges"
153
154 build: ${PRESTAGE}
155         rm -rf ${BUILDBASE}/usr.obj/work
156         mkdir -p ${BUILDBASE}/usr.obj/work
157         ${CHROOTENV} "cd /tmp/track; ./fastbulk -j ${NPARALLEL} /usr/pkgsrc"
158
159 ${BUILDBASE}/bin/getpkgsrcdir: getpkgsrcdir.c
160         cc getpkgsrcdir.c -o ${BUILDBASE}/bin/getpkgsrcdir
161
162 ${BUILDBASE}/bin/fastbulk: fastbulk.c
163         cc fastbulk.c -o ${BUILDBASE}/bin/fastbulk
164
165 ${BUILDBASE}/track/Makefile: ${.CURDIR}/Makefile
166         cp -p ${.CURDIR}/Makefile ${BUILDBASE}/track/Makefile
167
168 ${BUILDBASE}/track/dochanges: ${.CURDIR}/dochanges
169         cp -p ${.CURDIR}/dochanges ${BUILDBASE}/track/dochanges
170
171 ${BUILDBASE}/track/dobuild: ${.CURDIR}/dobuild
172         cp -p ${.CURDIR}/dobuild ${BUILDBASE}/track/dobuild
173
174 ${BUILDBASE}/track/fastbulk: ${BUILDBASE}/bin/fastbulk
175         cp -p ${BUILDBASE}/bin/fastbulk ${BUILDBASE}/track/fastbulk