fastbulk - Commit to /usr/src/test/fastbulk
[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 setup          - setup/mount the build environment"
17         @echo "    make cleanup        - unmount the build environment"
18         @echo "    make changes      - deinstall modified packages"
19         @echo "    make build        - iterate all dirs / build package"
20
21 scratch: cleanup
22         rm -rf ${BUILDBASE}/var.db
23         rm -rf ${BUILDBASE}/var.db.pkg
24         rm -rf ${BUILDBASE}/var.db.pkg.refcount
25         rm -rf ${BUILDBASE}/etc
26         rm -rf ${BUILDBASE}/usr.pkg
27         rm -rf ${BUILDBASE}/usr.obj/work
28         rm -rf ${BUILDBASE}/tmp/logs
29         rm -rf ${BUILDBASE}/tmp/track
30         cpdup ${SYSROOT}/etc ${BUILDBASE}/etc
31         cpdup ${SYSROOT}/var/db ${BUILDBASE}/var.db
32         rm -rf ${BUILDBASE}/var.db/pkg
33         rm -rf ${BUILDBASE}/var.db/pkg.refcount
34         ${MAKE} setup bootstrap
35         #${MAKE} build
36
37 setup: cleanup
38         mkdir -p ${SYSROOT}/var/db/pkg
39         mkdir -p ${SYSROOT}/var/db/pkg.refcount
40         mkdir -p ${SYSROOT}/usr/pkgsrc
41         mkdir -p ${SYSROOT}/usr/pkg
42         mkdir -p ${BUILDBASE}
43         mkdir -p ${BUILDBASE}/packages
44         mkdir -p ${BUILDBASE}/distfiles
45         mkdir -p ${BUILDBASE}/bin
46         mkdir -p ${BUILDBASE}/tmp
47         mkdir -p ${BUILDBASE}/tmp/track
48         mkdir -p ${BUILDBASE}/tmp/logs
49         mkdir -p ${BUILDBASE}/tmp/logs/run
50         mkdir -p ${BUILDBASE}/tmp/logs/good
51         mkdir -p ${BUILDBASE}/tmp/logs/bad
52         mkdir -p ${BUILDBASE}/etc
53         mkdir -p ${BUILDBASE}/usr.pkg
54         mkdir -p ${BUILDBASE}/usr.obj
55         mkdir -p ${BUILDBASE}/var.db
56         mkdir -p ${BUILDBASE}/var.db.pkg
57         mkdir -p ${BUILDBASE}/var.db.pkg.refcount
58         mkdir -p ${BUILDBASE}/track
59         mkdir -p ${BUILDROOT}
60         mount_null -o ro ${SYSROOT} ${BUILDROOT}
61         mount_null -o ro ${SYSROOT}/usr ${BUILDROOT}/usr
62         mount_null -o ro ${SYSROOT}/var ${BUILDROOT}/var
63         mount_null ${BUILDBASE}/tmp ${BUILDROOT}/tmp
64         mount_null ${BUILDBASE}/tmp ${BUILDROOT}/var/tmp
65         mount_null ${BUILDBASE}/track ${BUILDROOT}/tmp/track
66         mount_null ${BUILDBASE}/etc ${BUILDROOT}/etc
67         mount_null ${BUILDBASE}/usr.pkg ${BUILDROOT}/usr/pkg
68         mount_null ${BUILDBASE}/usr.obj ${BUILDROOT}/usr/obj
69         mount_null ${BUILDBASE}/var.db ${BUILDROOT}/var/db
70         mount_null ${BUILDBASE}/var.db.pkg ${BUILDROOT}/var/db/pkg
71         mount_null ${BUILDBASE}/var.db.pkg.refcount \
72                         ${BUILDROOT}/var/db/pkg.refcount
73         mount_null ${SYSROOT}/dev ${BUILDROOT}/dev
74         mount_null ${SYSPKGSRC} ${BUILDROOT}/usr/pkgsrc
75         mount_null ${BUILDBASE}/packages ${BUILDROOT}/usr/pkgsrc/packages
76         mount_null ${BUILDBASE}/distfiles ${BUILDROOT}/usr/pkgsrc/distfiles
77
78 cleanup:
79         -umount ${BUILDROOT}/usr/pkgsrc/distfiles > /dev/null 2>&1
80         -umount ${BUILDROOT}/usr/pkgsrc/packages > /dev/null 2>&1
81         -umount ${BUILDROOT}/usr/pkgsrc > /dev/null 2>&1
82         -umount ${BUILDROOT}/dev > /dev/null 2>&1
83         -umount ${BUILDROOT}/var/db/pkg.refcount > /dev/null 2>&1
84         -umount ${BUILDROOT}/var/db/pkg > /dev/null 2>&1
85         -umount ${BUILDROOT}/var/db > /dev/null 2>&1
86         -umount ${BUILDROOT}/usr/obj > /dev/null 2>&1
87         -umount ${BUILDROOT}/usr/pkg > /dev/null 2>&1
88         -umount ${BUILDROOT}/etc > /dev/null 2>&1
89         -umount ${BUILDROOT}/var/tmp > /dev/null 2>&1
90         -umount ${BUILDROOT}/tmp/track > /dev/null 2>&1
91         -umount ${BUILDROOT}/tmp > /dev/null 2>&1
92         -umount ${BUILDROOT}/var > /dev/null 2>&1
93         -umount ${BUILDROOT}/usr > /dev/null 2>&1
94         -umount ${BUILDROOT} > /dev/null 2>&1
95
96 # Cleans everything except packages and distfiles
97 #
98 realclean: cleanup
99         rm -rf ${BUILDBASE}/bin
100         rm -rf ${BUILDBASE}/tmp
101         rm -rf ${BUILDBASE}/track
102         rm -rf ${BUILDBASE}/usr.pkg
103         rm -rf ${BUILDBASE}/usr.obj
104         rm -rf ${BUILDBASE}/var.db.pkg
105         rm -rf ${BUILDBASE}/var.db.pkg.refcount
106
107 # Bootstrap an empty chroot setup
108 #
109 bootstrap:
110         rm -rf ${BUILDBASE}/usr.obj/work
111         ${CHROOTENV} "cd /usr/pkgsrc/bootstrap; ./bootstrap --workdir=/usr/obj/work"
112
113 # Figure out what has changed and deinstall the related packages
114 #
115
116 PRESTAGE= ${BUILDBASE}/bin/getpkgsrcdir
117 PRESTAGE+= ${BUILDBASE}/bin/fastbulk
118 PRESTAGE+= ${BUILDBASE}/track/Makefile
119 PRESTAGE+= ${BUILDBASE}/track/dochanges
120 PRESTAGE+= ${BUILDBASE}/track/dobuild
121 PRESTAGE+= ${BUILDBASE}/track/fastbulk
122
123 changes: ${PRESTAGE}
124         @if [ ! -f ${BUILDBASE}/track/dochanges ]; then \
125                 touch ${BUILDBASE}/track/dochanges; fi
126         @if [ ! -f ${BUILDBASE}/track/changes.raw ]; then \
127                 touch ${BUILDBASE}/track/changes.raw; fi
128         ( cat ${BUILDBASE}/track/changes.raw; \
129           find ${SYSPKGSRC} -mnewer ${BUILDBASE}/track/dochanges ) | \
130             sort | uniq | ${BUILDBASE}/bin/getpkgsrcdir ${SYSPKGSRC} | \
131             sort | uniq > ${BUILDBASE}/track/changes.raw.new
132         mv ${BUILDBASE}/track/changes.raw.new ${BUILDBASE}/track/changes.raw
133         ${BUILDBASE}/bin/getpkgsrcdir -s ${SYSPKGSRC} < \
134                 ${BUILDBASE}/track/changes.raw > \
135                 ${BUILDBASE}/track/changes.txt
136         cp Makefile ${BUILDBASE}/track/Makefile
137         ${CHROOTENV} "cd /tmp/track; ./dochanges"
138
139 build: ${PRESTAGE}
140         rm -rf ${BUILDBASE}/usr.obj/work
141         mkdir -p ${BUILDBASE}/usr.obj/work
142         ${CHROOTENV} "cd /tmp/track; ./fastbulk -j ${NPARALLEL} /usr/pkgsrc"
143
144 ${BUILDBASE}/bin/getpkgsrcdir: getpkgsrcdir.c
145         cc getpkgsrcdir.c -o ${BUILDBASE}/bin/getpkgsrcdir
146
147 ${BUILDBASE}/bin/fastbulk: fastbulk.c
148         cc fastbulk.c -o ${BUILDBASE}/bin/fastbulk
149
150 ${BUILDBASE}/track/Makefile: ${.CURDIR}/Makefile
151         cp -p ${.CURDIR}/Makefile ${BUILDBASE}/track/Makefile
152
153 ${BUILDBASE}/track/dochanges: ${.CURDIR}/dochanges
154         cp -p ${.CURDIR}/dochanges ${BUILDBASE}/track/dochanges
155
156 ${BUILDBASE}/track/dobuild: ${.CURDIR}/dobuild
157         cp -p ${.CURDIR}/dobuild ${BUILDBASE}/track/dobuild
158
159 ${BUILDBASE}/track/fastbulk: ${BUILDBASE}/bin/fastbulk
160         cp -p ${BUILDBASE}/bin/fastbulk ${BUILDBASE}/track/fastbulk