nrelease - fix/improve livecd
[dragonfly.git] / etc / Makefile.usr
1 # Makefile.usr - installed as /usr/Makefile
2 #
3 # Provides simple targets to download and maintain /usr/src, /usr/dports etc.
4
5 # DragonFly BSD source repository
6 GITURL_SRC?=git://git.dragonflybsd.org/dragonfly.git
7 # DragonFly BSD projects repository
8 GITURL_PROJECTS?=git://git.dragonflybsd.org/projects.git
9 # Branch to be fetched & checked out
10 # * master - latest development branch
11 # * DragonFly_RELEASE_x_y - stable release branch x.y
12 BRANCH?=master
13 BRANCH_PROJECTS?=master
14
15 # DPorts source repository
16 GITURL_DPORTS?=git://mirror-master.dragonflybsd.org/dports.git
17
18 # Mirror from which to fetch the pkg bootstrap
19 MIRROR?=https://mirror-master.dragonflybsd.org
20
21 DPDLURL=https://api.github.com/repos/DragonFlyBSD/DPorts/tarball/
22 PKGBOOT_VERSION=04
23 PKGBOOT_x86_64=bootstrap_pkg_${PKGBOOT_VERSION}_x86-64.tar.xz
24 PKGBOOT=${MIRROR}/dports/bootstraps/${PKGBOOT_${MACHINE_ARCH}}
25 WSTARS="***************************************************************"
26 WARNPS="  Warning: Delete or move ${.CURDIR}/pkg before building any dport!"
27 LPATT="   make %-23s- %s\n"
28
29 help all:
30         @echo "HELP:"
31         @echo
32 .if exists(${.CURDIR}/dports/.git)
33         @printf ${LPATT} "dports-update"         "update your dports repository from the net"
34 .else
35 .  if exists(${.CURDIR}/dports)
36         @printf ${LPATT} "dports-replace"        "Replace dports with latest tarball (Github)"
37 .  else
38         @printf ${LPATT} "dports-create"         "fetch initial dports repository from the net"
39         @printf ${LPATT} "dports-create-shallow" "fetch initial history-free dports repository"
40         @printf ${LPATT} "dports-download"       "download & install dports tarball (Github)"
41 .  endif
42 .endif
43         @echo
44         @printf ${LPATT} "pkg-bootstrap"        "Use pre-built pkg to install dports packages"
45         @printf ${LPATT} "pkg-bootstrap-force"  "Force it (pkg.conf will be overwritten)"
46         @echo
47
48 .if exists(${.CURDIR}/src/.git)
49         @printf ${LPATT} "src-update"         "update your src repository from the net"
50 .else
51         @printf ${LPATT} "src-create"         "fetch initial src repository from the net"
52         @printf ${LPATT} "src-create-shallow" "fetch initial history-free src repository"
53 .endif
54 .if exists(${.CURDIR}/projects/.git)
55         @printf ${LPATT} "projects-update"         "update your projects repository from the net"
56 .else
57         @printf ${LPATT} "projects-create"         "fetch initial projects repository from the net"
58         @printf ${LPATT} "projects-create-shallow" "fetch initial history-free projects repository"
59 .endif
60         @echo
61 .if exists(${.CURDIR}/src-sys.tar.bz2)
62         @printf ${LPATT} "release-sys-extract" "extract the pre-packaged sys-only sources"
63         @echo
64 .endif
65         @echo "src checkout branch: ${BRANCH}"
66
67 git-check:
68         @/usr/bin/which -s git || \
69                 (echo "git must be present on the system to use this option."; /usr/bin/false)
70
71 src-check: git-check
72         @/bin/test ! -d ${.CURDIR}/src/.git || \
73                 (echo "Error: ${.CURDIR}/src already exists"; /usr/bin/false)
74
75 projects-check: git-check
76         @/bin/test ! -d ${.CURDIR}/projects/.git || \
77                 (echo "Error: ${.CURDIR}/projects already exists"; /usr/bin/false)
78
79 src-check-hasdir: git-check
80         @/bin/test -d ${.CURDIR}/src/.git || \
81                 (echo "Error: ${.CURDIR}/src does not exist"; /usr/bin/false)
82
83 src-create: src-check
84         @echo "If problems occur you may have to 'rm -rf src' and try again."
85         @echo
86         git clone --branch ${BRANCH} -- ${GITURL_SRC} ${.CURDIR}/src
87
88 src-create-shallow: src-check
89         @echo "If problems occur you may have to 'rm -rf src' and try again."
90         @echo
91         git clone --depth 1 --branch ${BRANCH} -- ${GITURL_SRC} ${.CURDIR}/src
92
93 projects-create: projects-check
94         @echo "If problems occur you may have to 'rm -rf projects' and try again."
95         @echo
96         git clone --branch ${BRANCH_PROJECTS} -- ${GITURL_PROJECTS} ${.CURDIR}/projects
97
98 projects-create-shallow: projects-check
99         @echo "If problems occur you may have to 'rm -rf projects' and try again."
100         @echo
101         git clone --depth 1 --branch ${BRANCH_PROJECTS} -- ${GITURL_PROJECTS} ${.CURDIR}/projects
102
103 src-update: src-check-hasdir
104         cd ${.CURDIR}/src && git pull --ff-only
105         @echo
106         @echo "To automate, feel free to run this task from cron(8)."
107
108 projects-update: projects-check-hasdir
109         cd ${.CURDIR}/projects && git pull --ff-only
110         @echo
111         @echo "To automate, feel free to run this task from cron(8)."
112
113 .if exists(${.CURDIR}/src-sys.tar.bz2)
114 release-sys-extract:
115         cd ${.CURDIR} && tar xvpjf src-sys.tar.bz2
116 .endif
117
118 dports-check: git-check
119         @/bin/test ! -d ${.CURDIR}/dports/.git || \
120                    (echo "Error: ${.CURDIR}/dports already exists"; /usr/bin/false)
121
122 dports-check-hasdir: git-check
123         @/bin/test -d ${.CURDIR}/dports/.git || \
124                    (echo "Error: ${.CURDIR}/dports does not exist"; /usr/bin/false)
125
126 dports-create: dports-check
127         @echo "If problems occur you may have to 'rm -rf dports' and try again."
128         @echo
129         git clone ${GITURL_DPORTS} ${.CURDIR}/dports
130 .if exists(${.CURDIR}/pkg)
131         @echo ${WSTARS}
132         @echo ${WARNPS}
133         @echo ${WSTARS}
134 .endif
135
136 dports-create-shallow: dports-check
137         @echo "If problems occur you may have to 'rm -rf dports' and try again."
138         @echo
139         git clone --depth 1 ${GITURL_DPORTS} ${.CURDIR}/dports
140 .if exists(${.CURDIR}/pkg)
141         @echo ${WSTARS}
142         @echo ${WARNPS}
143         @echo ${WSTARS}
144 .endif
145
146 dports-update: dports-check-hasdir
147         cd ${.CURDIR}/dports && git pull --ff-only
148         @echo
149         @echo "To automate, feel free to run this task from cron(8)."
150
151 dports-download:
152 .if exists(${.CURDIR}/dports)
153         @echo "Error: ${.CURDIR}/dports already exists"
154         @/usr/bin/false
155 .endif
156         mkdir ${.CURDIR}/dports
157         fetch -o - ${DPDLURL} | \
158                 tar -xf - -C ${.CURDIR}/dports --strip-components 1
159 .if exists(${.CURDIR}/pkg)
160         @echo ${WSTARS}
161         @echo ${WARNPS}
162         @echo ${WSTARS}
163 .endif
164
165 # NOTE: Ignore error from rm -rf because /usr/dports might be
166 #       a null-mount.  Be safe, do not wildcard /usr/dports/*.
167 #
168 dports-replace:
169 .if exists(${.CURDIR}/dports/.git)
170         @echo "Error: ${.CURDIR}/dports is a git repository currently."
171         @echo "Remove ${.CURDIR}/dports and execute 'make dports-download' if you want"
172         @echo "to convert to a non-git version."
173         @/usr/bin/false
174 .else
175         -rm -rf ${.CURDIR}/dports
176         [ -d "${.CURDIR}/dports" ] || mkdir ${.CURDIR}/dports
177         fetch -o - ${DPDLURL} | \
178                 tar -xf - -C ${.CURDIR}/dports --strip-components 1
179 .endif
180
181 PKG_ENV=
182 .if !exists(/etc/ssl/cert.pem)  # from port 'security/ca_root_nss'
183 # Disable SSL verification for fetch(1) and pkg-static(8)
184 PKG_ENV+=       SSL_NO_VERIFY_PEER=1
185 .endif
186 .if defined(ABIVERS)
187 PKG_ENV+=       ABI=${ABIVERS}
188 .endif
189
190 pkg-bootstrap-fetch:
191         ${PKG_ENV} fetch -o - ${PKGBOOT} | \
192                 tar -xf - -C ${.CURDIR}/local
193
194 # This is a bit problematic
195 #
196 pkg-bootstrap-install:
197         ${PKG_ENV} ${.CURDIR}/local/sbin/pkg-static \
198                 install -y ${PKG_FLAGS} pkg ca_root_nss
199         [ -f ${.CURDIR}/local/etc/pkg/repos/df-latest.conf ] || \
200                 cp -f ${.CURDIR}/local/etc/pkg/repos/df-latest.conf.sample \
201                 ${.CURDIR}/local/etc/pkg/repos/df-latest.conf \
202
203 pkg-bootstrap:
204 .if exists(${.CURDIR}/local/sbin/pkg)
205         @echo "Error: Bootstrap not necessary, ${.CURDIR}/local/sbin/pkg already exists"
206         @/usr/bin/false
207 .elif exists(${.CURDIR}/local/etc/pkg.conf)
208         @echo "Error: ${.CURDIR}/local/etc/pkg.conf will be overwritten"
209         @echo "Please move this file and rerun 'make pkg-bootstrap'"
210         @/usr/bin/false
211 .else
212         @(cd ${.CURDIR} && make pkg-bootstrap-fetch)
213         @(cd ${.CURDIR} && make pkg-bootstrap-install)
214 .endif
215
216 # NOTE: In force mode we also have to remove any old pkg.conf
217 #       which might interfere with the newer pkg bootstrap.
218 #
219 pkg-bootstrap-force:
220         rm -f ${.CURDIR}/local/etc/pkg.conf
221         @(cd ${.CURDIR} && make pkg-bootstrap-fetch)
222         @(cd ${.CURDIR} && make pkg-bootstrap-install PKG_FLAGS="-f")