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
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 \
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
37 for cmd
in $ALL_PROGRAMS; do
38 eval "src_${cmd}_SOURCES=src/${cmd}.c"
41 # Load actual values from src/local.mk. This will read all the variables from
42 # the local.mk matching the src_${cmd}_... case.
44 if echo "$l" |
grep -E '^src_\w+ +\+?=' > /dev
/null
; then
45 var
=$
(echo $l | cut
-f 1 -d ' ')
46 value
=$
(echo $l | cut
-f 2- -d =)
47 if [ "$value" != " \$(LDADD)" ]; then
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"'"
58 me
=`echo "$0" | sed 's,.*/,,'`
59 echo "## Automatically generated by $me. DO NOT EDIT BY HAND!"
61 # Override the sources for dir and vdir. We use a smaller version of dir and
62 # vdir that relies on the ls main.
63 src_dir_SOURCES
="src/coreutils-dir.c"
64 src_dir_LDADD
="$src_dir_LDADD src/libsinglebin_ls.a"
65 echo src_libsinglebin_dir_a_DEPENDENCIES
= src
/libsinglebin_ls.a
66 src_vdir_SOURCES
="src/coreutils-vdir.c"
67 src_vdir_LDADD
="$src_vdir_LDADD src/libsinglebin_ls.a"
68 echo src_libsinglebin_vdir_a_DEPENDENCIES
= src
/libsinglebin_ls.a
70 # Override the sources for arch likewise, using the main from uname.
71 src_arch_SOURCES
="src/coreutils-arch.c"
72 src_arch_LDADD
="$src_arch_LDADD src/libsinglebin_uname.a"
73 echo src_libsinglebin_arch_a_DEPENDENCIES
= src
/libsinglebin_uname.a
75 for cmd
in $ALL_PROGRAMS; do
77 echo noinst_LIBRARIES
+= src
/libsinglebin_
${cmd}.a
78 base
="src_libsinglebin_${cmd}_a"
80 var
=src_
${cmd}_SOURCES
82 echo "${base}_SOURCES = $value"
87 if [ "x$value" != "x" ]; then
88 echo "${base}_ldadd = $value"
92 # Hack any other program defining a main() replacing its main by
93 # single_binary_main_$PROGRAM_NAME.
94 echo "${base}_CFLAGS = \"-Dmain=single_binary_main_${cmd} (int, char **);" \
95 " int single_binary_main_${cmd}\" " \
96 "-Dusage=_usage_${cmd} \$(src_coreutils_CFLAGS)"
99 if [ "x$value" != "x" ]; then
100 echo "${base}_CFLAGS += $value"
104 var
=src_
${cmd}_CPPFLAGS
106 if [ "x$value" != "x" ]; then
107 echo "${base}_CPPFLAGS = $value"