functions contains all shell functions that can be used by shell scripts to generate makefiles for building products using GNU make. The shell must probably be POSIX compliant.
To use these functions in a script, first source functions, like this:
. path/to/functions
or, like this:
source path/to/functions
The behaviour of the shell functions can be controlled by giving command line options to the configure(1) script (which are parsed and handled by functions).
The following functions are documented and available for use:
add the product configuration targets
set default buildtype target
check that a compiler exists and its version
fetch a file or package and reexecute conditionally
create the console link
create the makefile core
install a directory
specify the name of an environment variables init file
print an error message to stderr and exit
download a file or package
install a regular file
create the flashimage target and the HWID variable
include a makefile fragment
fetch a package and add it to the FUNCTESTS variable
create a help target
ignore any future references to a file or package
fetch a file and source it
print an informational message to stdout
conclude an informational message positively
conclude an informational message negatively
draw a spinner to stdout
create the install target
create the factorydefault image target
create the kernel target
set the path to the kernel source directory
include the rules file
specify the file name of the output file
override fetch-options for files or packages
add an entry to the partition table and/or a line to fstab
add directories to the PATH variable
create pre-recurse targets
protect files and packages from being fetched
add software release information
set the global repository root URL
fetch a package and add it to the SUBDIRS variable
create a symbolic link
fetch a tool and add it to the tools target
set the path to the top directory
create the unit test targets
extract a (compressed) tarball in current working directory
create a tarfile of the var directory
print a warning message to stderr
A configure script that uses functions to generate Makefile that builds a very small (and rather useless) product software:
#! /bin/sh
#
# Configuration script for Axis Product
#
SOURCE="configure-files/source"
SOURCE_REV="R1_2_0"
[ -z "$CVSROOT" ] && CVSROOT=":ext:mycvshost:/path/to/cvsroot"
if [ ! -f "$SOURCE/functions" ]; then
cvs -d "$CVSROOT" co -r "$SOURCE_REV" "$SOURCE" || exit 1
fi
. "$SOURCE/functions" || exit 1
repository_root "$CVSROOT"
conditional_reexec "$SOURCE" rev="$SOURCE_REV"
compiler gcc-cris rev=R56
buildtype cris-axis-linux-gnuuclibc librev=IR0_9_21-6--memfix
# Environment initialization file
envfile init_env
# This is usually included from a common include-file
core
make_rules
tool tools/build rev=R2_5_2
path tools/build/bin
# Software version
release "1.0" build=1
# Kernel version
kernel os/linux rev=R2_4_25_040223
# Partition table and fstab
partition ptable name=rescue size=0x010000 csum=yes type=rescue \
bin=rfl.bin
partition ptable name=flash1 size=0x350000 csum=yes type=kernel
partition fstab name=rootfs dev=/dev/flash3 mpoint=/ type=cramfs \
mopts=noauto dump=0 pass=1
partition ptable name=flash2 size=0x0a0000 csum=no type=jffs2 \
fstab dev=/dev/flash2 mpoint=/mnt/flash mopts=noauto \
dump=0 pass=2
partition fstab dev=proc mpoint=/proc type=proc dump=0 pass=0
partition fstab dev=tmpfs mpoint=/var type=tmpfs dump=0 pass=0
partition fstab dev=devpts mpoint=/dev/pts type=devpts dump=0 pass=0
# Flash image with hardware ID
flashimage 1
# Factorydefault image with JIMAGEID
jimage
# Files needed by a very small Linux system
sub packages/filesystem rev=R1_2_0
sub packages/base-files rev=R1_1_0
sub packages/devices/standard rev=R1_2_0
sub packages/devices/axis-2.4 rev=R1_0_7
sub apps/init rev=R1_3_4
sub packages/initscripts/common rev=R2_9_1
sub apps/shells/dash rev=IR0_4_17-4
symlink dash /bin/sh
sub apps/busybox rev=R1_3_1
sub packages/romfs_meta/common rev=R1_0_0
# Generate Makefile
output Makefile
A few rules that need to be followed when submitting changes:
Max 80 characters per line in functions and the files generated by functions (well, except for some long lines that will be shortened when written to the output file due to escaping, variable expansion etc).
The name of internal helper functions, that are never needed outside functions, starts with an '_'.
The name of internal variables starts with an '_' and are unset when no longer used.
The name of variables, used only within internal helper functions, starts with "__" to avoid name clash with variables in other functions.
Variables are unset when no longer used.
Mandatory parameters to functions are expected in a certain order, but Optional parameters are always "name=value" so that their position in the argument list does not matter.
functions should only use POSIX, but extensive testing has not been made yet. functions has only been verified to work with bash, but ought to work with any POSIX compliant shell, and maybe even some non-POSIX Bourne shells.
You are welcome to send bug reports and feedback to the author or to the dev-etrax mailing list <dev-etrax@axis.com>.