1 # Copyright 2012 Google Inc.
4 # Redistribution and use in source and binary forms, with or without
5 # modification, are permitted provided that the following conditions are
8 # * Redistributions of source code must retain the above copyright
9 # notice, this list of conditions and the following disclaimer.
10 # * Redistributions in binary form must reproduce the above copyright
11 # notice, this list of conditions and the following disclaimer in the
12 # documentation and/or other materials provided with the distribution.
13 # * Neither the name of Google Inc. nor the names of its contributors
14 # may be used to endorse or promote products derived from this software
15 # without specific prior written permission.
17 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 # Dumps a file to the test's stdout for debugging purposes.
31 local file="${1}"; shift
33 echo "==== BEGIN ${file}"
35 echo "==== END ${file}"
38 # Creates a C source file with a single symbol in it.
40 # The file parameter specifies the path to the file to create, WITHOUT the
41 # C extension. Both a source file and a header file are created. Any
42 # intermediate directories are created too.
44 # The symbol parameter specifies the name of the symbol to place in the
45 # module, which is defined as a string holding the name of the module.
47 local file="${1}"; shift
48 local symbol="${1}"; shift
50 mkdir -p "$(dirname ${file})"
51 echo "extern const char *${symbol};" >"${file}.h"
52 echo "const char *${symbol} = \"${file}\";" >"${file}.c"
58 # Creates a main C source file that references a set of modules.
60 # The modules to be referenced should have been created with
61 # create_c_module. The generated source file ensures that all the modules
62 # are referenced in some way, which helps in testing that the generated
63 # binary holds all the necessary objects.
65 # The file parameter specifies the name of the file to create.
67 # The rest of the parameters are module:symbol pairs that specify the
68 # module to include and the symbol within them to reference.
69 create_main_using_modules() {
70 local file="${1}"; shift
74 for spec in "${@}"; do
75 modules="${modules} $(echo ${spec} | cut -d : -f 1)"
76 symbols="${symbols} $(echo ${spec} | cut -d : -f 2)"
79 echo '#include <stdio.h>' >"${file}"
80 for module in ${modules}; do
81 echo "#include \"${module}\"" >>"${file}"
83 echo 'int main(void) {' >>"${file}"
84 for symbol in ${symbols}; do
85 echo "printf(\"%s\n\", ${symbol});" >>"${file}"
87 echo 'return 0; }' >>"${file}"
92 # Creates a mk.conf file and points MAKECONF to it.
94 # The first argument specifies the name of the configuration file to
97 # The rest of the arguments include a collection of modifiers for the
98 # generated configuration file and/or a collection of explicit variable
99 # names and their values to set.
101 # The qualifiers can be one of:
102 # - owngrp: Override the *OWN and *GRP variables to point to the current
105 local file="${1}"; shift
107 echo "# Test configuration file" >"${file}"
108 for arg in "${@}"; do
111 echo "${arg}" >>"${file}"
114 for class in BIN DOC LIB LINKS MAN; do
115 echo "${class}OWN=$(id -un)" >>"${file}"
116 echo "${class}GRP=$(id -gn)" >>"${file}"
124 MAKECONF="${file}"; export MAKECONF
127 MAKECONF="$(pwd)/${file}"; export MAKECONF