]> CyberLeo.Net >> Repos - CDN/Mosi.git/blob - script/makepkg
script/makepkg: whitespace?
[CDN/Mosi.git] / script / makepkg
1 #!/bin/sh
2
3 # Load shlib and modules
4 _root="$(dirname "${0}")"; . "${_root}/lib/sh/env.sh"
5 want log root
6
7 ########
8 #
9 # Chroot handling
10 #
11 ########
12
13 # Prepare a chroot for work
14 chprepare() {
15   # Verify environment sanity
16   [ -d "${chroot_dir}" ] && omg "${chroot_dir}: directory exists; purging" && chdestroy
17   mount | grep -q "${chroot_dir}" && wtf "Stuff is mounted under ${chroot_dir}; cannot continue"
18   [ -d "${seed_dir}" -a -f "${seed_dir}/COPYRIGHT" ] || wtf "Use 'makeworld' to create a root build first"
19   [ -f "/usr/ports/UPDATING" ] || wtf "Need ports tree in /usr/ports to build"
20   [ -f "/usr/src/sys/conf/newvers.sh" ] || omg "No base sourcetree in /usr/src"
21
22   meh "Setting up chroot tree"
23
24   # Just in case we're aborted partway through the prepare
25   trap "chdestroy" exit hup int term kill
26
27   # Make sure config dir exists for later save
28   [ -d "${conf_dir}" ] || mkdir -p "${conf_dir}"
29
30   # Populate initial seed
31   mkdir -p "$(dirname "${chroot_dir}")" || wtf "chroot path create failed"
32   cp -pR "${seed_dir}" "${chroot_dir}" || wtf "chroot seeding failed"
33
34   # Create distfile cache
35   mkdir -p "${dist_dir}" || wtf "mkdir ${dist_dir} failed"
36
37   # Create mountpoint directories
38   mkdir -p "${chroot_dir}/dev" || wtf "mkdir /dev failed"
39   mkdir -p "${chroot_dir}/usr/src" || wtf "mkdir /usr/src failed"
40   mkdir -p "${chroot_dir}/usr/obj" || wtf "mkdir /usr/obj failed"
41   mkdir -p "${chroot_dir}/usr/ports" || wtf "mkdir /usr/ports failed"
42   mkdir -p "${chroot_dir}/var/ports/distfiles" || wtf "mkdir /var/ports/distfiles failed"
43
44   # Create pkg directories
45   mkdir -p "${pkg_dir}" || wtf "mkdir ${chroot_pkg_dir} failed"
46   mkdir -p "${bdeps_dir}" || wtf "mkdir ${chroot_bdeps_dir} failed"
47
48   # Copy in cached configuration, if necessary
49   [ -f "${conf_dir}/make.conf" ] && cp -p "${conf_dir}/make.conf" "${chroot_dir}/etc/make.conf"
50
51   # If you have WITHOUT_INFO set in src.conf during buildworld/installworld, ports that need
52   # makeinfo and install-info will fail horribly; stub them
53   [ -f "${chroot_dir}/usr/bin/makeinfo" ] || ln -sf true "${chroot_dir}/usr/bin/makeinfo"
54   [ -f "${chroot_dir}/usr/bin/install-info" ] || ln -sf true "${chroot_dir}/usr/bin/install-info"
55
56   # Tweak make.conf to support read-only ports tree
57   cat <<EOF >> "${chroot_dir}/etc/make.conf"
58
59 # Read-only ports tree
60 DISTDIR=/var/ports/distfiles
61 PACKAGES=/var/ports/packages
62 WRKDIRPREFIX=/usr/obj
63 EOF
64
65   trap "" exit hup int term kill
66   meh "Chroot tree set up in ${chroot_dir}"
67
68   return 0
69 }
70
71 # Set up chroot mounts and runtime configuration
72 chstartup() {
73   [ -d "${chroot_dir}" -a -f "${chroot_dir}/COPYRIGHT" -a -d "${chroot_dir}/dev" ] || wtf "Chroot not prepared"
74   chup && return 0
75
76   # Rollback if a problem occurs during startup
77   trap "chshutdown" exit hup int term kill
78
79   meh "Starting up chroot"
80
81   # Necessary mountpoints
82   mount -t devfs devfs "${chroot_dir}/dev" || wtf "mount /dev failed"
83   mount -t nullfs -r /usr/src "${chroot_dir}/usr/src" || wtf "mount /usr/src failed"
84   mount -t nullfs -r /usr/ports "${chroot_dir}/usr/ports" || wtf "mount /usr/ports failed"
85   mount -t nullfs -w "${dist_dir}" "${chroot_dir}/var/ports/distfiles" || wtf "mount /var/ports/distfiles failed"
86
87   # Chroot configuration
88   cp -f /etc/resolv.conf "${chroot_dir}/etc/resolv.conf" || wtf "seeding /etc/resolv.conf failed"
89
90   # Load port configuration, now that chroot is running
91   port_load_config
92
93   # Update ld.so.hints
94   cheval "/etc/rc.d/ldconfig start"
95
96   trap "" exit hup int term kill
97   meh "Chroot up and running in ${chroot_dir}"
98
99   return 0
100 }
101
102 # Check if the chroot is probably ready for use
103 chup() {
104   [ -d "${chroot_dir}" -a -f "${chroot_dir}/COPYRIGHT" -a -c "${chroot_dir}/dev/null" ]
105   return $?
106 }
107
108 # Unmount all chroot directories
109 chshutdown() {
110   # Short-circuit if nothing is mounted
111   mount | grep -q "${chroot_dir}" || return 0
112   chup && port_save_config || meh "Not saving port config"
113   meh "Shutting down chroot"
114   umount "${chroot_dir}/var/ports/distfiles"
115   umount "${chroot_dir}/usr/ports"
116   umount "${chroot_dir}/usr/src"
117   umount "${chroot_dir}/dev"
118   return 0
119 }
120
121 # Remove all chroot contents
122 chdestroy() {
123   chshutdown
124   meh "Destroying chroot"
125   chflags -R noschg "${chroot_dir}" || wtf "noschg failed"
126   rm -Rf "${chroot_dir}" || wtf "chroot removal failed"
127   return 0
128 }
129
130 # Evaluate a command line within the chroot
131 cheval() {
132   chup || wtf "Chroot not ready"
133   chroot "${chroot_dir}" env -i ${chroot_env} /bin/sh -c "cd ${chroot_pkg_dir}; ${*}"
134   return $?
135 }
136
137 # Run chrooted make
138 chmake() {
139   local port="/usr/ports/${1##/usr/ports/}"
140   shift
141   cheval "make -C ${port} ${*}"
142   return $?
143 }
144
145 ########
146 #
147 # Port Dependency Tracking
148 #
149 ########
150
151 # Translate port origin to package name
152 port2pkg() {
153   while [ "${1}" ]
154   do
155     chmake "${1}" -V PKGNAME
156     shift
157   done
158 }
159
160 # Build dependencies (shallow, recursive, package)
161 port_bdeps() {
162   while [ "${1}" ]
163   do
164     chmake "${1}" build-depends-list | sed -e 's#^/usr/ports/##'
165     shift
166   done
167 }
168 port_all_bdeps() {
169   # Clear cache if first value isn't '-r'
170   [ "${1}" = '-r' ] && shift || { kvs_unset_all 'port_all_bdeps'; kvs_unset_all 'port_all_rdeps'; }
171   # rdeps for rdeps are rdeps, bdeps for rdeps are bdeps, rdeps for bdeps are bdeps; thus:
172   (
173     port_bdeps "${@}" | while read port
174     do
175       [ "${VERBOSE_CACHE}" ] && logf "**** bdep cache %s: '%s'\n" "$(kvs_has_key 'port_all_bdeps' "${port}" && echo "hit" || echo "miss")" "${port}" >&2
176       if ! kvs_has_key 'port_all_bdeps' "${port}"
177       then
178         kvs_set 'port_all_bdeps' "${port}" ""
179         echo "${port}"
180         port_all_bdeps -r "${port}"
181         port_all_rdeps -r "${port}"
182       fi
183     done
184     port_all_rdeps -r "${@}" | while read port
185     do
186       [ "${VERBOSE_CACHE}" ] && logf "**** bdep cache %s: '%s'\n" "$(kvs_has_key 'port_all_bdeps' "${port}" && echo "hit" || echo "miss")" "${port}" >&2
187       if ! kvs_has_key 'port_all_bdeps' "${port}"
188       then
189         kvs_set 'port_all_bdeps' "${port}" ""
190         port_all_bdeps -r "${port}"
191       fi
192     done
193   ) | sort | uniq
194 }
195 pkg_bdeps() {
196   port2pkg $(port_all_bdeps "${@}")
197 }
198
199 # Runtime dependencies (shallow, recursive, package)
200 port_rdeps() {
201   while [ "${1}" ]
202   do
203     chmake "${1}" run-depends-list | sed -e 's#^/usr/ports/##'
204     shift
205   done
206 }
207 port_all_rdeps() {
208   # Clear cache if first value isn't '-r'
209   [ "${1}" = '-r' ] && shift || kvs_unset_all 'port_all_rdeps'
210   port_rdeps "${@}" | while read port
211   do
212     [ "${VERBOSE_CACHE}" ] && logf "**** rdep cache %s: '%s'\n" "$(kvs_has_key 'port_all_rdeps' "${port}" && echo "hit" || echo "miss")"  "${port}" >&2
213     if ! kvs_has_key 'port_all_rdeps' "${port}"
214     then
215       kvs_set 'port_all_rdeps' "${port}"
216       echo "${port}"
217       port_all_rdeps -r "${port}"
218     fi
219   done | sort | uniq
220 }
221 pkg_rdeps() {
222   port2pkg $(port_all_rdeps "${@}")
223 }
224
225 # All dependencies (shallow, recursive, package)
226 port_deps() {
227   while [ "${1}" ]
228   do
229     chmake "${1}" all-depends-list | sed -e 's#^/usr/ports/##'
230     shift
231   done
232 }
233 port_all_deps() {
234   port_deps "${@}" | while read port
235   do
236     echo "${port}"
237     port_deps "${port}"
238   done | sort | uniq
239 }
240 pkg_deps() {
241   port2pkg $(port_all_deps "${@}")
242 }
243
244 # Dump a list of leaf ports from a working system
245 # Leaf ports are ports that have nothing depending upon them
246 # These are generally the top-level ports; everything else should
247 # be pulled in by them; on a system that has had updates applied
248 # this may pick up orphaned packages as well, so try cutleaves?
249 leaf_ports() {
250   ( cd /var/db/pkg; ls -1 ) | while read pkg
251   do
252     pkg_info -Rq "${pkg}" | grep -q '' || pkg_info -oq "${pkg}"
253   done | sort
254 }
255
256 # Display a tree of all build dependencies (and
257 # any runtime dependencies those build dependencies
258 # depend upon). Individual ports may appear more than
259 # once, as it is a tree and not a list.
260 port_bdep_tree() {
261   # Clear cache if first value isn't '-r'
262   [ "${1}" = '-r' ] && shift || {
263     [ ${VERBOSE_CACHE} ] && logf "**** bdep_tree cache cleared\n"
264     kvs_unset_all 'port_bdep_tree'
265   }
266   port="${1##/usr/ports/}"
267   printf "%${2}s%s\n" "" "${port}"
268   
269   [ "${VERBOSE_CACHE}" ] && logf "**** bdep_tree cache %s: '%s'\n" "$(kvs_has_key 'port_bdep_tree' "${port}" && echo "hit" || echo "miss")"  "${port}" >&2
270
271   if ! kvs_has_key 'port_bdep_tree' "${port}"
272   then
273     ( chmake "${port}" build-depends-list
274       chmake "${port}" run-depends-list
275     ) | sort -u | while read port
276     do
277       port_bdep_tree -r "${port}" $(( ${2:-0} + 1 ))
278       kvs_set 'port_bdep_tree' "${port}"
279     done
280   else
281     printf "%${2}s %s\n" "" "..."
282   fi
283 }
284
285 # Display a tree of all runtime dependencies. Individual
286 # ports may appear more than once, as it is a tree and
287 # not a list.
288 # Cache already-visted branches into ... to eliminate recursion delays
289 # (x11-drivers/xorg-drivers computes forever!)
290 port_rdep_tree() {
291   # Clear cache if first value isn't '-r'
292   [ "${1}" = '-r' ] && shift || {
293     [ ${VERBOSE_CACHE} ] && logf "**** rdep_tree cache cleared\n"
294     kvs_unset_all 'port_rdep_tree'
295   }
296   port="${1##/usr/ports/}"
297   printf "%${2}s%s\n" "" "${port}"
298
299   [ "${VERBOSE_CACHE}" ] && logf "**** rdep_tree cache %s: '%s'\n" "$(kvs_has_key 'port_rdep_tree' "${port}" && echo "hit" || echo "miss")"  "${port}" >&2
300
301   if ! kvs_has_key 'port_rdep_tree' "${port}"
302   then
303     chmake "${port}" run-depends-list | sort -u | while read port
304     do
305       port_rdep_tree -r "${port}" $(( ${2:-0} + 1 ))
306       kvs_set 'port_rdep_tree' "${port}"
307     done
308   else
309     printf "%${2}s %s\n" "" "..."
310   fi
311 }
312
313 ########
314 #
315 # Port Configuration Handling
316 #
317 ########
318
319 # Run make config on a list of ports
320 port_config() {
321   while [ "${1}" ]
322   do
323     meh "port config ${1}"
324     chmake "${1}" config < /dev/tty
325     shift
326   done
327 }
328
329 # Make config-conditional for a list of ports, and all dependencies
330 port_config_recursive() {
331   # Clear cache if first value isn't '-r'
332   [ "${1}" = '-r' ] && shift || kvs_unset_all 'port_config_recursive'
333   while [ "${1}" ]
334   do
335     # Do not use config-recursive because it computes the depchain first;
336     # instead, manually compute the depchain after each config to ensure the
337     # proper depchain is followed. Use config-conditional to avoid dialog
338     # if the config is already complete. Also use a cache to avoid re-config
339     # and re-recurse on previously handled port branches.
340     if ! kvs_has_key 'port_config_recursive' "${1}"
341     then
342       meh "port config-recursive ${1}"
343       chmake "${1}" config-conditional < /dev/tty
344       port_config_recursive -r $(port_deps "${1}")
345       kvs_set 'port_config_recursive' "${1}"
346     fi
347     shift
348   done
349 }
350
351 # Remove saved config for a list of ports
352 port_rmconfig() {
353   while [ "${1}" ]
354   do
355     meh "port rmconfig ${1}"
356     chmake "${1}" rmconfig
357     shift
358   done
359 }
360
361 # Remove saved config for a list of ports and all dependencies
362 port_rmconfig_recursive() {
363   meh "port rmconfig-recursive ${*}"
364   port_rmconfig $(echo "${@}" $(port_all_deps "${@}") | sort | uniq)
365 }
366
367 # Obliterate saved configuration for all ports
368 port_rmconfig_all() {
369   meh "port rmconfig-all"
370   cheval "cd /var/db/ports; find . -name 'options' -delete; find . -type d | xargs rmdir 2>/dev/null"
371 }
372
373 # Restore port build options from directory
374 port_load_config() {
375   [ -d "${conf_dir}/port.options" ] || return 0
376   meh "port load-config"
377   ( cd "${conf_dir}/port.options"; find . | cpio -oHnewc ) | cheval "cd /var/db/ports; cpio -i" || wtf "port load-config failed"
378 }
379
380 # Dump port build options to directory
381 port_save_config() {
382   meh "port save-config"
383   rm -Rf "${conf_dir}/port.options.tmp" "${conf_dir}/port.options.old"
384   mkdir -p "${conf_dir}/port.options" "${conf_dir}/port.options.tmp"
385   cheval "cd /var/db/ports; find . -type d -o -type f -name options | cpio -oHnewc" | ( cd "${conf_dir}/port.options.tmp"; cpio -i ) || wtf "port safe-config failed"
386   mv -f "${conf_dir}/port.options" "${conf_dir}/port.options.old" && \
387     mv -f "${conf_dir}/port.options.tmp" "${conf_dir}/port.options" && \
388     rm -Rf "${conf_dir}/port.options.old" || \
389     wtf "port save-config atomic commit failed"
390 }
391
392 ########
393 #
394 # Port distfile handling
395 #
396 ########
397
398 # Recursively retrieve distfiles
399 port_fetch_recursive() {
400   while [ "${1}" ]
401   do
402     meh "fetch-recursive ${1}"
403     chmake "${1}" fetch-recursive
404     shift
405   done
406 }
407
408 ########
409 #
410 # Port building and packaging
411 #
412 ########
413
414 # Recursively compute all dependencies to load; avoid loading packages whose
415 # depgraph is incomplete, since that can cause strange behaviour at build time
416 port_available_deps_recursive() {
417   local port="${1}"
418   local dependency
419   local good=good
420
421   if kvs_has_key 'port_available_deps' "${port}"
422   then
423     good="$(kvs_get 'port_available_deps' "${port}")"
424     #echo "S==> Skipping ${port} (${good:-not good})" >&2
425   else
426     #echo "D==> Port ${port} deps: $(port_deps "${port}" | sort | tr '\n' ' ')" >&2
427     for dependency in $(port_deps "${port}" | sort)
428     do
429       #echo "C==> Computing ${dependency}" >&2
430       # Recurse into dependency
431       port_available_deps_recursive "${dependency}" || unset good
432     done
433     local pkgfile="${final_bdeps_dir}/$(port2pkg "${port}").tbz"
434     [ "${good}" -a -f "${pkgfile}" ] && echo "${port}" || unset good
435     kvs_set 'port_available_deps' "${port}" "${good}"
436     #echo "R==> ${port} is ${good:-not good}"
437   fi
438   [ "${good}" ]
439 }
440
441 port_available_deps() {
442   local port="${1}"
443   kvs_unset_all 'port_available_deps'
444   port_available_deps_recursive "${port}" | grep -v "^${port}$" | sort
445 }
446
447 # Copy in and install dependency packages
448 # Missing dependencies are not fatal, since a port build will rebuild them anyways
449 port_load_deps() {
450   local port="${1}"
451   # Install portmaster: it's needed to clean up dependencies after an update build
452   portmaster_port="ports-mgmt/portmaster"
453   portmaster=$(port2pkg "${portmaster_port}")
454   if [ -f "${final_bdeps_dir}/${portmaster}.tbz" ]
455   then
456     cp -f "${final_bdeps_dir}/${portmaster}.tbz" "${bdeps_dir}" 2>/dev/null && meh "Loading ${portmaster}"
457   else
458     meh "No portmaster package exists; building one"
459     chmake "${portmaster_port}" BATCH=yes clean build install clean || wtf "port_build ${portmaster_port} failed"
460   fi
461
462   # And now for the dependencies
463   for pkg in $(port2pkg $(port_available_deps "${port}" | sort -u))
464   do
465     cp -f "${final_bdeps_dir}/${pkg}.tbz" "${bdeps_dir}" 2>/dev/null && meh "Loading dependent ${pkg}"
466   done
467
468   # Install all selected packages, ignoring already-installed packages and missing dependencies
469   if ls "${bdeps_dir}"/*.tbz >/dev/null 2>&1
470   then
471     meh "Installing dependencies"
472     cheval "cd ${chroot_bdeps_dir}; pkg_add -Ff *" || wtf "port_load_deps ${port} failed"
473     rm -f "${bdeps_dir}"/*.tbz
474   fi
475 }
476
477 # Build and install a port
478 port_build() {
479   local port="${1}"
480   meh "Building ${port}"
481   chmake "${port}" clean build deinstall install clean || wtf "port_build ${port} failed"
482 }
483
484 # Package a port
485 port_package() {
486   local port="${1}"
487   meh "Cleaning up dependency tree"
488   cheval "portmaster --check-depends"
489   meh "Creating rdep package tree for ${port}"
490   cheval "pkg_create -Rvb $(port2pkg "${port}")" || wtf "port_package ${port} failed"
491 }
492
493 # Package port build dependencies, unless they're already run deps
494 port_stash_bdeps() {
495   meh "Stashing unsaved bdeps"
496   # This doesn't work well, because there can be bdeps that aren't listed as bdeps (bison)
497   # Actually, that was due to a bug in port_all_bdeps; but I like the other solution better anyways
498   #for pkg in $(pkg_bdeps "${1}")
499   #do
500   #  [ ! -f "${pkg_dir}/${pkg}.tbz" ] && cheval "cd ${chroot_bdeps_dir}; pkg_create -vb ${pkg}"
501   #done
502   #
503   # Instead, just save everything that's not already in rdeps as bdeps
504   for pkg in $(cheval pkg_info | awk '{print $1}')
505   do
506     if [ ! -f "${pkg_dir}/${pkg}.tbz" -a ! -f "${bdeps_dir}/${pkg}.tbz" ]
507     then
508       cheval "cd ${chroot_bdeps_dir}; pkg_create -vb ${pkg}" || wtf "port_stash_bdeps failed"
509     fi
510   done
511 }
512
513 # Copy generated packages out of tree
514 pkg_final() {
515   meh "Moving created packages to repo"
516   mkdir -p "${final_pkg_dir}"
517   ls "${pkg_dir}"/*.tbz >/dev/null 2>&1 && mv -f "${pkg_dir}"/*.tbz "${final_pkg_dir}"
518   mkdir -p "${final_bdeps_dir}"
519   ls "${bdeps_dir}"/*.tbz >/dev/null 2>&1 && mv -f "${bdeps_dir}"/*.tbz "${final_bdeps_dir}"
520   # link everything into ${bdeps_dir} so we can find it easily later
521   ( cd "${final_pkg_dir}"; find . -type f | cpio -plu --quiet "${final_bdeps_dir}" )
522 }
523
524 # Delete all installed packages (hope you saved them first)
525 pkg_delete_all() {
526   meh "Clearing out installed packages"
527   cheval "pkg_delete -f \*" || wtf "pkg_delete_all failed"
528 }
529
530 # Fix up dependency information for already-built packages
531 pkg_fixdeps() {
532   while [ "${1}" ]
533   do
534     local port="${1}"
535
536     meh "Fixing up dependency information for ${port}"
537
538     # Load dependencies
539     port_load_deps "${port}"
540
541     # Load package
542     pkg="$(port2pkg "${port}")"
543     cp -f "${final_bdeps_dir}/${pkg}.tbz" "${bdeps_dir}" 2>/dev/null && meh "Loading package ${pkg}"
544     cheval "cd ${chroot_bdeps_dir}; pkg_add -Ff ${pkg}.tbz" || wtf "Installing ${port} failed"
545
546     # Fixup and stash package
547     port_package "${port}"
548
549     # Stash fixed bdeps
550     port_stash_bdeps
551
552     # Save them all
553     pkg_final
554
555     # Delete them all
556     pkg_delete_all
557
558     shift
559   done
560 }
561
562 ########
563 #
564 # All of the above?
565 #
566 ########
567
568 # Execute a complete port build, using prebuilt packages to fulfill dependencies when available
569 # Be sure to chsetup and populate your config before running!
570 chport() {
571   [ "${#}" -gt 0 ] || set -- $(cat ${conf_dir}/port.lst)
572
573   # Stash the current list of ports
574   kvs_unset_all 'chport'
575   kvs_set 'chport' 'port.lst' "${*}"
576
577   # Complete all config and fetch steps first
578   for step in port_config_recursive port_fetch_recursive
579   do
580     set -- $(kvs_get 'chport' 'port.lst')
581     while [ "${1}" ]
582     do
583       local port="${1}"
584       meh "=> Step ${step}"
585       ${step} ${port}
586       shift
587     done
588   done
589
590   # Now process the remaining steps
591   set -- $(kvs_get 'chport' 'port.lst')
592   while [ "${1}" ]
593   do
594     local port="${1}"
595     meh "load-deps"
596     port_load_deps "${port}"
597     meh "build"
598     # Avoid building ports-mgmt/portmaster because port_load_deps already has
599     [ "${port}" = "ports-mgmt/portmaster" ] || port_build "${port}"
600     meh "package"
601     port_package "${port}"
602     meh "stash-deps"
603     port_stash_bdeps
604     meh "final"
605     pkg_final
606     meh "delete-all"
607     pkg_delete_all
608     shift
609   done
610 }
611
612
613 ########
614 #
615 # Configuration variable setup
616 #
617 ########
618
619 ARCH="${ARCH:-$(uname -m)}"
620 CONF="${CONF:-GENERIC}"
621
622 # Root directory of makepkg
623 ROOT="$(realpath "$(dirname "${0}")/..")"
624
625 # Location of targets
626 TARGETS="${ROOT}/targets"
627
628 # Base directory for selected target
629 base_dir="${TARGETS}/${ARCH}/${CONF}"
630
631 # Link to appropriate world
632 world_dir="${base_dir}/world"
633
634 # Verify that world points to a proper world
635 if [ ! -d "${world_dir}" ]
636 then
637   omg "World link is not appropriate; defaulting to ${ARCH}/GENERIC"
638   world_dir="${ROOT}/worlds/${ARCH}/GENERIC"
639 fi
640
641 # Directory holding configuration
642 conf_dir="${base_dir}/config"
643
644 # Root tree for chroot seeding
645 seed_dir="${world_dir}/root"
646
647 # Directory where distfiles will be stored between builds (common to all targets)
648 dist_dir="${ROOT}/seed/distfiles"
649
650 # Final directory for built packages (Outside chroot)
651 final_pkg_dir="${base_dir}/pkg"
652 final_bdeps_dir="${base_dir}/bdeps"
653
654 # Chroot directory
655 chroot_dir="${base_dir}/chroot"
656
657 # Package directories (must be under ${chroot_dir})
658 pkg_dir="${chroot_dir}/pkg"
659 bdeps_dir="${pkg_dir}/bdeps"
660
661 # Compute in-chroot pkg and bdeps dirs
662 chroot_pkg_dir="${pkg_dir##${chroot_dir}}"
663 chroot_bdeps_dir="${bdeps_dir##${chroot_dir}}"
664
665 # Chroot environment
666 chroot_env="
667 USER=root
668 HOME=/root
669 LOGNAME=root
670 PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
671 SHELL=/bin/sh
672 TERM=${TERM}
673 "
674
675 # Configure and load kvs
676 kvs="${chroot_dir}/.makepkg.kvs"
677 want kvs
678
679 help() {
680   cat <<EOF
681 Configuration variables:
682
683 ARCH (${ARCH})
684 CONF (${CONF})
685
686 Functions:
687
688 Chroot Handling:
689 ------------------------------
690 chprepare      Prepare chroot
691 chstartup      Start up chroot
692 cheval         Evaluate a command string within chroot
693 chmake         Run port make within chroot
694 chshutdown     Shut down chroot
695 chdestroy      Destroy chroot
696
697 Port Dependency Tracking
698 ------------------------------
699 port2pkg       Translate a port dirname to a package name
700
701 port_bdeps     Compute port build dependencies
702 port_all_bdeps Recursively compute port build dependencies
703 pkg_bdeps      port2pkg port_all_bdeps
704
705 port_rdeps     Compute port run dependencies
706 port_all_rdeps Recursively compute port run dependencies
707 pkg_rdeps      port2pkg port_all_rdeps
708
709 port_deps      Compute port build and run dependencies
710 port_all_deps  Recursively compute port build and run dependencies
711 pkg_deps       port2pkg port_all_deps
712
713 leaf_ports     Dump a list of leaf ports (ports with nothing depending upon them) from a running system
714 port_bdep_tree Display a tree of all build dependencies
715 port_rdep_tree Display a tree of all run dependencies
716
717 Port Configuration Handling
718 ------------------------------
719 port_config              Make config for a port
720 port_config_recursive    Make config recursive, recomputing depchain for each
721 port_rmconfig            Remove saved configuration
722 port_rmconfig_recursive  Remove saved configuration for a port and all dependencies
723 port_rmconfig_all        Remove all saved configuration
724 port_load_config         Restore port configuration from cpio
725 port_save_config         Save port configuration to cpio
726
727 Port Distfile Handling
728 ------------------------------
729 port_fetch_recursive     fetch-recursive
730
731 Port Building And Packaging
732 ------------------------------
733 port_load_deps           
734 port_build               
735 port_package             
736 port_stash_bdeps         
737 pkg_final                
738 pkg_delete_all           
739
740 All Of The Above?
741 ------------------------------
742
743 chport <port>            
744 EOF
745 }
746
747 # Blind passthru for testing
748 [ "${#}" ] && "${@}"
749
750 # Todo: Clean up entrypoint to support proper options
751 # Todo: Add methods to autoprocess a ports.lst file to produce packages
752 # Todo: Unify chroot handling with makeworld
753