tests: avoid false failure due to mismatched isblank()
[coreutils.git] / build-aux / gen-single-binary.sh
blob7d15b9bfc2dc5e5bc9b5cff10e0206964347faa3
1 #!/bin/sh
3 # Generate the list of rules for the single-binary option based on all the other
4 # binaries found in src/local.mk.
6 # We need to duplicate the specific rules to build each program into a new
7 # static library target. We can't reuse the existing target since we need to
8 # create a .a file instead of linking the program. We can't do this at
9 # ./configure since the file names need to be available when automake runs
10 # to let it generate all the required rules in Makefile.in. The configure
11 # step will select which ones will be used to build, but they need to be
12 # generated beforehand.
14 # Instead of maintaining a duplicated list of rules, we generate the
15 # single-binary required rules based on the normal configuration found on
16 # src/local.mk with this script.
18 if test "x$1" = "x"; then
19 echo "Usage: $0 path/to/src/local.mk" >&2
20 exit 1
23 set -e
25 LOCAL_MK=$1
26 GEN_LISTS_OF_PROGRAMS="`dirname "$0"`/gen-lists-of-programs.sh"
28 ALL_PROGRAMS=$($GEN_LISTS_OF_PROGRAMS --list-progs \
29 | grep -v -F -e coreutils -e libstdbuf.so \
30 | tr '[' '_')
32 # Compute default SOURCES. automake will assume the source file for the
33 # src_${cmd} target to be src/${cmd}.c, but we will add rules to generate
34 # the lib src_libsinglebin_${cmd}_a which won't match the autogenerated source
35 # file. This loop will initialize the default source file and will be reset
36 # later if needed.
37 for cmd in $ALL_PROGRAMS; do
38 eval "src_${cmd}_SOURCES=src/${cmd}.c"
39 done
41 # Load actual values from src/local.mk. This will read all the variables from
42 # the local.mk matching the src_${cmd}_... case.
43 while read l; do
44 if echo "$l" | grep -E '^src_[_[:alnum:]]+ +\+?=' > /dev/null; then
45 var=$(echo $l | cut -f 1 -d ' ')
46 value=$(echo $l | cut -f 2- -d =)
47 if [ "$value" != " \$(LDADD)" ]; then
48 oldvalue=""
49 if echo $l | grep -F '+=' >/dev/null; then
50 eval "oldvalue=\${$var}"
52 value=$(echo "$value" | sed "s/'/'\"'\"'/g")
53 eval "$var='$oldvalue "$value"'"
56 done < $LOCAL_MK
58 me=`echo "$0" | sed 's,.*/,,'`
59 echo "## Automatically generated by $me. DO NOT EDIT BY HAND!"
61 # Override the sources for some tools, to use smaller variants
62 override_single() {
63 from="$1"; to="$2";
65 eval "src_${from}_SOURCES='src/coreutils-${from}.c'"
66 eval "src_from_LDADD=\$src_${from}_LDADD"
67 eval "src_${from}_LDADD='$src_from_LDADD src/libsinglebin_${to}.a'"
68 eval "src_libsinglebin_${from}_a_DEPENDENCIES='src/libsinglebin_${to}.a'"
69 echo "src_libsinglebin_${from}_a_DEPENDENCIES = src/libsinglebin_${to}.a"
71 override_single dir ls
72 override_single vdir ls
73 override_single arch uname
74 override_single chgrp chown
76 for cmd in $ALL_PROGRAMS; do
77 echo "# Command $cmd"
78 echo noinst_LIBRARIES += src/libsinglebin_${cmd}.a
79 base="src_libsinglebin_${cmd}_a"
80 # SOURCES
81 var=src_${cmd}_SOURCES
82 eval "value=\$$var"
83 echo "${base}_SOURCES = $value"
85 # LDADD
86 var=src_${cmd}_LDADD
87 eval "value=\$$var"
88 if [ "x$value" != "x" ]; then
89 echo "${base}_ldadd = $value"
92 # DEPENDENCIES
93 var=src_libsinglebin_${cmd}_a_DEPENDENCIES
94 eval "value=\$$var"
95 if [ "x$value" = "x" ]; then
96 echo "$var = \$(src_${cmd}_DEPENDENCIES)"
99 # CFLAGS
100 # Hack any other program defining a main() replacing its main by
101 # single_binary_main_$PROGRAM_NAME.
102 echo "${base}_CFLAGS = \"-Dmain=single_binary_main_${cmd} (int, char **);" \
103 " int single_binary_main_${cmd}\" " \
104 "-Dusage=_usage_${cmd} \$(src_coreutils_CFLAGS)"
105 var=src_${cmd}_CFLAGS
106 eval "value=\$$var"
107 if [ "x$value" != "x" ]; then
108 echo "${base}_CFLAGS += $value"
111 # CPPFLAGS
112 var=src_${cmd}_CPPFLAGS
113 eval "value=\$$var"
114 if [ "x$value" != "x" ]; then
115 echo "${base}_CPPFLAGS = $value"
117 done
119 exit 0