svn commit: r190762 - stable/7/release/picobsd/build

Luigi Rizzo luigi at FreeBSD.org
Mon Apr 6 04:16:18 PDT 2009


Author: luigi
Date: Mon Apr  6 11:15:28 2009
New Revision: 190762
URL: http://svn.freebsd.org/changeset/base/190762

Log:
  MFC: bring in recent fixes to the picobsd script
  
  Approved by:	re (blanket on picobsd)

Modified:
  stable/7/release/picobsd/build/picobsd

Modified: stable/7/release/picobsd/build/picobsd
==============================================================================
--- stable/7/release/picobsd/build/picobsd	Mon Apr  6 11:14:30 2009	(r190761)
+++ stable/7/release/picobsd/build/picobsd	Mon Apr  6 11:15:28 2009	(r190762)
@@ -3,17 +3,17 @@
 # $FreeBSD$
 # This file requires sysutils/makefs to run
 #
-# The new PicoBSD build script. Invoked as
+# The PicoBSD build script. Invoked as
 #
-# picobsd [options] floppy_type site_name
+#	picobsd [options] image_type [site_name]
 #
-# Where floppy_type is a directory where the picobsd config info
-# is held, and ${floppy_type}/floppy.tree.${site_name} contains
+# Where image_type is a directory with the picobsd config info,
+# and ${image_type}/floppy.tree.${site_name} contains
 # optional site-specific configuration.
 #
 # For Options, see the bottom of the file where the processing is
 # done. The picobsd(8) manpage might be of some help, but code and docs
-# tend to lose sync over time...
+# tend to lose sync over time.
 #
 # This script depends on the following files:
 #
@@ -33,36 +33,42 @@
 #   floppy.tree/	local additions to ${PICO_TREE}/mfs_free
 #   floppy.tree.${site}/ same as above, site specific.
 #   mfs_tree/		local additions to the mfs_free
-#   buildtree.mk	optional makefile to build an extension for floppy tree
+#   buildtree.mk	optional Makefile to build an extension for floppy tree
 #			(generated in buildtree/ )
 
 #
 #--- The main entry point is at the end.
 #
 
-# There are two set of initialization. The first one (set_defaults)
-# is done on entry to the script, and is used to set default values
-# for all variables which do not depend on floppy type and source tree.
+# There are two initialization functions:
 #
-# The second set is done after command line parsing, e.g.
-# to resolve dependencies on the source tree.
+# + set_defaults
+#   is run on entry to the script, and is used to set default values
+#   for all variables that do not depend on image type and source tree.
 #
-# Naming:
+# + set_build_parameters
+#   is run after command line parsing
+#
+# VARIABLE NAMES:
 # + variables that control operation (e.g. verbosity) and are generally
 #   set from the command line have o_ ("option") as a name prefix
 #
-# + variables which contain pathnames and values that should not change
+# + variables that contain pathnames and values that should not change
 #   have c_ ("constant") as a name prefix
 #
 # + variables exported to Makefiles and subshells are CAPITAL
 #
 # + variables local to the script are lowercase, possibly with
-#   an l_ ("local") prefix
+#   an l_ ("local") prefix.
+#
+# There are unfortunately exceptions:
+# name, l_usrtree, l_objtree
 
 # SRC points to your FreeBSD source tree.
 # l_usrtree points to the /usr subdir for the source tree.
 #     Normally /usr or ${SRC}/../usr
 # l_objtree points to the obj tree. Normally ${l_usrtree}/obj-pico
+# c_label is either bsdlabel or disklabel
 # PICO_TREE is where standard picobsd stuff resides.
 #     Normally ${SRC}/release/picobsd
 # You can set SRC with --src <directory>
@@ -71,28 +77,27 @@
 # MY_TREE (set later) is where this floppy type resides.
 # BUILDDIR is the build directory
 
-# set some default values for variables.
-# needs to be done as the first thing in the script.
-
 # log something on stdout if verbose.
 o_verbose=0	# this needs to be here!
-log() {
+log() {	#	message
     local foo
     [ ${o_verbose} -gt 0 ] && printf "\n*** %s\n" "$*"
     [ ${o_verbose}  -gt 1 ] && read -p "=== Press enter to continue" foo
     return 0
 }
 
-logverbose() {
+# unconditionally log and wait for input
+logverbose() {	# message
     local foo
     printf "\n*** %s\n" "$*"
     read -p "=== Press enter to continue" foo
     return 0
 }
 
-set_defaults() {
-    # no way to use logging in this function, variable not set yet.
+# set some default values for variables.
+# needs to be done as the first thing in the script.
 
+set_defaults() {	# no arguments
     # EDITOR is the editor you use
     # fd_size  floppy size in KB (default to 1440). You can use 1480,
     #	1720, 2880, etc. but beware that only 1440 and 1480 will boot
@@ -101,15 +106,20 @@ set_defaults() {
     fd_size=${fd_size:-1440}
 
     o_use_loader="yes"		# use /boot/loader
-    o_all_in_mfs="yes"		# put all files in mfs so you can boot and run
-				# the image via diskless boot.
-    o_clean=""			# do not clean
+	# You should not change it unless you are really short
+	# of space, and your kernel is small enough that the
+	# bootblocks manage to load it.
+
+    o_all_in_mfs="yes"		# put all files in mfs so you can boot
+				# and run the image via diskless boot.
+    o_clean=""			# set if you want to clean prev.builds.
     o_interactive=""		# default is interactive
     o_verbose=0			# verbose level, 0 is silent
     o_tarv=""			# tar verbose flag, "" or "v"
-    o_init_src=""		# non "" if we need to init libs and includes.
+    o_init_src=""		# set to build libs and includes.
     o_makeopts=${MAKEOPTS:--s}	# make options, be silent by default
-    o_no_devfs=yes		# we do not want devfs
+    o_no_devfs=			# default is use devfs.
+	# You should only set it when building 4.x images
     o_do_modules=""		# do not build modules
 
     SRC="/usr/src"		# default location for sources
@@ -132,13 +142,13 @@ set_defaults() {
     c_img=picobsd.bin		# filename used for the picobsd image
     generate_iso="NO"		# don't generate the iso image
 
-    # select the right memory disk name
+    # select the right disklabel program
     case `uname -r` in
-	7.*|6.*|5.*)
-	    l_label="bsdlabel"
+	4.*)
+	    c_label="disklabel"
 	    ;;
 	*)
-	    l_label="disklabel"
+	    c_label="bsdlabel"
 	    ;;
     esac
 
@@ -150,8 +160,9 @@ set_defaults() {
     trap fail 15
 }
 
-# use the new build infrastructure
-create_includes_and_libraries2() {
+# use the new build infrastructure to create libraries
+# and also to build a specific target
+create_includes_and_libraries2() { # opt_dir opt_target
     local no
     log "create_includes_and_libraries2() for ${SRC}"
     if [ ${OSVERSION} -ge 600000 ] ; then
@@ -163,7 +174,11 @@ create_includes_and_libraries2() {
     export MAKEOBJDIRPREFIX
     ( cd ${SRC};
     # make -DNOCLEAN -DNOPROFILE -DNOGAMES -DNOLIBC_R -DPICOBSD buildworld
-    make _+_= $no toolchain _includes _libraries
+    if [ -d "$1" ] ; then
+	cd $1 ; make $2	# specific target, e.g. ld-elf.so
+    else
+	make _+_= $no toolchain _includes _libraries
+    fi
     )
 }
 
@@ -173,7 +188,7 @@ create_includes_and_libraries() {
 
     log "create_includes_and_libraries() for ${SRC}"
     # Optionally creates include directory and libraries.
-    mkdir -p ${l_usrtree}/include		# the include directory...
+    mkdir -p ${l_usrtree}/include	# the include directory...
     mkdir -p ${l_usrtree}/share/misc	# a few things go here
     mkdir -p ${l_usrtree}/lib		# libraries
     mkdir -p ${l_usrtree}/sbin		# some binaries
@@ -210,11 +225,12 @@ create_includes_and_libraries() {
     log "Libraries done"
 }
 
-# set_type <type> looks in user or system directories for the floppy type
-# specified as first argument, and sets variables according to the config.
-# file. Also sets MY_TREE and BUILDDIR and SITE
+# set_type <the_type> [the_site] looks in user or system directories
+# for the directory named as the first argument, reads the configuration
+# files and sets variables according to the config.
+# Also sets MY_TREE and BUILDDIR and SITE
 
-set_type() {
+set_type() {	# the_type the_site
     local a i
 
     log "set_type() : Type '$1' site '$2'"
@@ -242,7 +258,7 @@ set_type() {
 
 clean_tree() {
     log "clean_tree()"
-    if [ "${name}" = "" ] ; then
+    if [ -z "${name}" ] ; then
 	echo "---> Wrong floppy type"
 	exit 3
     fi
@@ -271,7 +287,7 @@ build_iso_image() {
 # Main build procedure.
 build_image() {
     log "build_image() <${name}>"
-    [ "${name}" != "" ] || fail $? bad_type
+    [ -n "${name}" ] || fail $? bad_type
     clear
     set_msgs
     printf "${MSG}---> We'll use the sources living in ${SRC}\n\n"
@@ -281,12 +297,8 @@ build_image() {
     # variables.
     # 
     . ${PICO_TREE}/build/config
-    if [ -f ${MY_TREE}/config ] ; then
-	. ${MY_TREE}/config
-    fi
-    if [ -f ${o_additional_config} ] ; then
-	. ${o_additional_config}
-    fi
+    [ -f "${MY_TREE}/config" ]		&& . ${MY_TREE}/config
+    [ -f "${o_additional_config}" ]	&& . ${o_additional_config}
 
     # location of the object directory
     PICO_OBJ=${l_objtree}/picobsd/${THETYPE}
@@ -312,34 +324,13 @@ build_image() {
     fill_floppy_image # copies everything into the floppy
 }
 
-build_package() {
-    local z msg
-
-    log "build_package()"
-    rm -rf build.status
-    echo "##############################################" >>build.status
-    echo "## `date` ">>build.status
-    echo "##############################################" >>build.status
-    for z in bridge dial router net isp ; do
-	set_type ${z}
-	echo "---------------------------------------------">>build.status
-	echo "Building TYPE=${z}, SIZE=${MFS_SIZE}" >>build.status
-	msg="(ok)"	# error message
-	build_image || msg="** FAILED! **"
-        echo "	${msg}">>build.status
-	# where do i put things ?
-	# clean_tree
-    done
-    exit 0
-}
-
 # Set build parameters interactively
 
 main_dialog() {
   local ans i l
 
   log "main_dialog()"
-  while [ true ] ; do
+  while true ; do
     set_msgs
     rm ${c_reply}
     dialog --menu "PicoBSD build menu -- (29 sep 2001)" 19 70 12 \
@@ -547,7 +538,7 @@ do_copyfiles() {	# rootdir varname
 	eval set "\${${2}}"
         srcs=""
 	for dst in $* ; do
-		[ x"$srcs" = x ] && srcs=$dst && continue
+		[ -z "$srcs" ] && srcs=$dst && continue
 		eval srcs="$srcs"	# expand wildcard and vars
 		case x"$dst" in
 		*/ )	mkdir -p ${root}/${dst} ;;
@@ -558,6 +549,80 @@ do_copyfiles() {	# rootdir varname
         done
 }
 
+# do_links is a helper function to create links between programs
+# in stand/
+# This is done reading the names and destination from variable
+# links in a config file, in the format
+#	: dst names
+
+do_links() {	# rootdir varname
+	local root=$1
+	local l i dst
+	eval l="\${${2}}"
+        dst=""
+	log "Create links for ${l}"
+	(cd ${root}/stand
+	for i in $l ; do
+	    if [ "$dst" = ":" -o "$i" = ":" ] ; then
+		dst=$i
+	    elif [ -n "${dst}" ] ; then
+		ln -s ${dst} ${i}
+	    fi
+	done
+	)
+}
+
+# find_progs is a helper function to locate the named programs
+# or libraries in ${o_objdir} or ${_SHLIBDIRPREFIX},
+# and return the full pathnames.
+# Sets ${u_progs} to the list of programs, and ${u_libs}
+# to the list of shared libraries used.
+#
+# You can use it e.g. in a local configuration file by writing
+#
+#  do_copyfiles_user() {
+#	local dst=$1
+#	find_progs nvi sed less grep
+#	cp -p ${u_progs} ${dst}/bin
+#	cp -p ${u_libs} ${dst}/lib
+#	mkdir -p ${dst}/libexec
+#	find_progs ld-elf.so.1
+#	cp -p ${u_progs} ${dst}/libexec
+#  }
+
+find_progs() {	# programs
+	local i
+	u_progs="`find_progs_helper $*`"
+	local o=${o_objdir:-${_SHLIBDIRPREFIX}}
+	[ -z "${u_progs}" ] && return 1	# not found, error
+	i="`ldd ${u_progs} | grep -v '^/' | awk '{print $1}' | sort | uniq`"
+	u_libs="`find_progs_helper $i`"
+	return 0
+}
+
+find_progs_helper() {	# programs
+	local progs="$*"
+	local i o places names
+	local subdirs="bin sbin usr.bin usr.sbin libexec lib \
+		gnu/usr.bin gnu/lib \
+		secure/usr.bin secure/usr.sbin secure/libexec secure/lib"
+	names=""	# files to search
+	o=""
+	for i in $progs ; do
+		# plain programs come out verbatim
+		[ -f "$i" ] && echo $i && continue
+		names="${names} ${o} -name $i"
+		o="-o"
+	done
+	[ -z "${names}" ] && return 0
+	places=""				# places to search
+	o=${o_objdir:-${_SHLIBDIRPREFIX}/..}
+	for i in $subdirs ; do
+		[ -d "${o}/${i}" ] && places="${places} ${o}/${i}"
+	done
+	find ${places} -type f \( ${names} \)
+}
+
 # Populate the memory filesystem with binaries and non-variable
 # configuration files.
 # First do an mtree pass, then create directory links and device entries,
@@ -647,7 +712,7 @@ populate_mfs_tree() {
     fi
 
     # 4.x compatibility - create device nodes
-    if [ "${o_no_devfs}" != "" ] ; then
+    if [ -n "${o_no_devfs}" ] ; then
 	# create device entries using MAKEDEV
 	(cd ${dst}/dev
 	ln -s ${SRC}/etc/MAKEDEV ; chmod 555 MAKEDEV
@@ -661,10 +726,21 @@ populate_mfs_tree() {
 	(cd ${dst}; chown -R root . )
     fi
 
-    if [ -n "${copy_files}" ] ; then
-	do_copyfiles ${dst} copy_files
+    # If we are building a shared 'crunch', take the libraries
+    # and the dynamic loader as well
+    find_progs ${dst}/stand/crunch
+    if [ -n "${u_libs}" ] ; then
+	mkdir -p ${dst}/lib && cp -p ${u_libs} ${dst}/lib
+	mkdir -p ${dst}/libexec
+        create_includes_and_libraries2 libexec/rtld-elf
+        find_progs ld-elf.so.1 && cp -p ${u_progs} ${dst}/libexec
     fi
 
+    [ -n "${copy_files}" ] && do_copyfiles ${dst} copy_files
+    do_copyfiles_user ${dst} || true
+    [ -n "${links}" ] && do_links ${dst} links
+    strip ${dst}/libexec/* ${dst}/lib/* ${dst}/stand/* 2> /dev/null || true
+
     # The 'import_files' mechanism is deprecated, as it requires
     # root permissions to follow the symlinks, and also does
     # not let you rename the entries.
@@ -829,22 +905,22 @@ fill_floppy_image() {
     (cd ${BUILDDIR}
     makefs -t ffs -o bsize=4096 -o fsize=512 \
 	-s ${blocks}k -f 50 ${c_img} ${dst}
-    # ${l_label} -f `pwd`/${c_img}
-    ${l_label} -w -f `pwd`/${c_img} auto # write in a label
+
+    ${c_label} -w -f `pwd`/${c_img} auto # write in a label
     # copy partition c: into a: with some sed magic
-    ${l_label} -f `pwd`/${c_img} | sed -e '/  c:/{p;s/c:/a:/;}' | \
-	${l_label} -R -f `pwd`/${c_img} /dev/stdin
-    ${l_label} -f `pwd`/${c_img}
+    ${c_label} -f `pwd`/${c_img} | sed -e '/  c:/{p;s/c:/a:/;}' | \
+	${c_label} -R -f `pwd`/${c_img} /dev/stdin
+    ${c_label} -f `pwd`/${c_img}
 
     ls -l ${c_img}
-    ${l_label} -f `pwd`/${c_img}
+    ${c_label} -f `pwd`/${c_img}
     logverbose "after disklabel"
     )
 
     echo "BUILDDIR ${BUILDDIR}"
     if [ "${generate_iso}" = "YES" ]; then
 	echo "generate_iso ${generate_iso}"
-	#build_iso_image()
+	# build_iso_image	# XXX not implemented yet
 	exit 1
     fi
 
@@ -872,7 +948,6 @@ fill_floppy_image() {
 # needs to be done once).
 
 set_build_parameters() {
-    log "set_build_parameters() SRC is ${SRC}"
     if [ "${SRC}" = "/usr/src" ] ; then
 	l_usrtree=${USR:-/usr}
     else
@@ -899,6 +974,19 @@ set_build_parameters() {
 	CONFIG=${l_usrtree}/sbin/config
 	export CONFIG
     fi
+
+    # if we have o_objdir, find where bin/ is
+    if [ ! -z "${o_objdir}" ] ; then
+	if [ -d ${o_objdir}/bin ] ; then
+	    # fine
+	elif [ -d "${o_objdir}${SRC}/bin" ] ; then
+	    o_objdir="${o_objdir}${SRC}"
+	    log "Changing objdir to ${o_objdir}"
+	else
+	    log "Cannot find objdir in ${o_objdir}, sorry"
+	    o_objdir=""
+	fi
+    fi
 }
 
 #-------------------------------------------------------------------
@@ -907,9 +995,10 @@ set_build_parameters() {
 
 set_defaults
 while [ true ]; do
+    log "Parsing $1"
     case $1 in
     --src)	# set the source path instead of /usr/src
-	SRC=`(cd $2; pwd)`
+	SRC=`realpath $2`
 	shift
 	;;
     --init)
@@ -961,6 +1050,12 @@ while [ true ]; do
 	shift
 	;;
 
+    --objdir)	# Place with results of a previous buildworld
+		# useful if you want to copy shared binaries and libs
+	o_objdir=`realpath $2`
+	shift
+	;;
+
     *)
 	break
 	;;
@@ -968,12 +1063,10 @@ while [ true ]; do
     esac
     shift
 done
+
 set_build_parameters	# things that depend on ${SRC}
 set_type $1 $2		# type and site, respectively
 
-# If $1="package", it creates a neat set of floppies
-[ "$1" = "package" ] && build_package
-
 [ "${o_interactive}" != "NO" ] && main_dialog
 
 if [ "${o_clean}" = "YES" ] ; then


More information about the svn-src-all mailing list