build: fix missing renameat() on OS X 10.5.8
[coreutils.git] / build-aux / gen-single-binary.sh
blob4e07cfdaa38348dfd0b1a11b171c2d314bd08ea3
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_\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
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 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
76 echo "# Command $cmd"
77 echo noinst_LIBRARIES += src/libsinglebin_${cmd}.a
78 base="src_libsinglebin_${cmd}_a"
79 # SOURCES
80 var=src_${cmd}_SOURCES
81 eval "value=\$$var"
82 echo "${base}_SOURCES = $value"
84 # LDADD
85 var=src_${cmd}_LDADD
86 eval "value=\$$var"
87 if [ "x$value" != "x" ]; then
88 echo "${base}_ldadd = $value"
91 # CFLAGS
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)"
97 var=src_${cmd}_CFLAGS
98 eval "value=\$$var"
99 if [ "x$value" != "x" ]; then
100 echo "${base}_CFLAGS += $value"
103 # CPPFLAGS
104 var=src_${cmd}_CPPFLAGS
105 eval "value=\$$var"
106 if [ "x$value" != "x" ]; then
107 echo "${base}_CPPFLAGS = $value"
109 done
111 exit 0