coreutils/man/local.mk
Alex Deymo 71e2ea7734 build: support building all tools in a single binary
Add the --enable-single-binary option to the configure file.
When enabled, this option builds a single binary file containing
the selected tools.  Which tool gets executed depends on the value
of argv[0] which can be set implicitly through symlinks to the
single program.

This setup reduces significantly the size of a complete coreutils
install, since code from lib/libcoreutils.a is not duplicated in
every one of the more than 100 binaries.  Runtime overhead is
increased due to more dynamic libraries being loaded, and extra
initialization being performed for all utils.  Also initially
a larger binary is loaded from storage, though this is usually
alleviated due to caching and lazy mmaping of unused blocks,
and in fact the single binary should have better caching
characteristics.

Comparing the size of the individual versus single binary on x86_64:
  $ cd src
  $ size coreutils
  $ size -t $(../build-aux/gen-lists-of-programs.sh --list-progs |
              grep -Ev '(coreutils|libstdbuf)') | tail -n1
     text    data     bss     dec     hex filename
  1097416    5388   88432 1191236  122d44 src/coreutils
  4901010  124964  163768 5189742  4f306e (TOTALS)

Storage requirements are reduced similarly:
  $ cd src
  $ du -h coreutils
  $ du -ch $(../build-aux/gen-lists-of-programs.sh --list-progs |
             grep -Ev '(coreutils|libstdbuf)') | tail -n1
  1.2M    coreutils
  5.3M    total

When installing, the makefile will create either symlinks or
shebangs based on the --enable-single-binary setting, for
each configured tool. In this way, all the tools are still
callable individually, but they are all implemented by the same
"coreutils" binary installed on the same directory.

* .gitignore: Add new generated files.
* Makefile.am: New rules to generate build-aux/gen-single-binary.sh
  and install symlinks.
* NEWS: Mention the new feature.
* README: Add "coreutils" to the list of utils.
* bootstrap.conf: Regenerate src/single-binary.mk
* build-aux/gen-lists-of-programs.sh: New --list-progs option.
* build-aux/gen-single-binary.sh: Regenerate
* configure.ac: New --enable-single-binary option and other variables.
Disallow --enable-single-binary=symlinks with --program-prefix et. al.
* man/coreutils.x: Manpage hook.
* man/local.mk: Add manpage hook and fix dependencies.
* src/coreutils.c: Multicall implementation.
* src/local.mk: New rules for the single binary option.
* tests/local.mk: Add $single_binary_progs to support
require_built_() from init.cfg
* tests/misc/env.sh: Avoid the use of symlink to echo.
* tests/misc/help-version.sh: Add exception for coreutils.
* tests/install/basic-1.sh: Really avoid using ginstall strip
functionality if there is an issue with the independent strip command.
* src/kill.c: Changes to call exit() in main.
* src/readlink.c: Likewise.
* src/shuf.c: Likewise.
* src/timeout.c: Likewise.
* src/truncate.c: Likewise.
2014-07-13 14:23:09 +01:00

114 lines
3.8 KiB
Makefile

# Make coreutils man pages. -*-Makefile-*-
# This is included by the top-level Makefile.am.
# Copyright (C) 2002-2014 Free Software Foundation, Inc.
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
EXTRA_DIST += man/help2man man/dummy-man
## Graceful degradation for systems lacking perl.
if HAVE_PERL
run_help2man = $(PERL) -- $(srcdir)/man/help2man
else
run_help2man = $(SHELL) $(srcdir)/man/dummy-man
endif
man1_MANS = @man1_MANS@
EXTRA_DIST += $(man1_MANS:.1=.x)
EXTRA_MANS = @EXTRA_MANS@
EXTRA_DIST += $(EXTRA_MANS:.1=.x)
ALL_MANS = $(man1_MANS) $(EXTRA_MANS)
CLEANFILES += $(ALL_MANS)
# This is a kludge to remove generated 'man/*.1' from a non-srcdir build.
# Without this, "make distcheck" might fail.
distclean-local:
test x$(srcdir) = x$(builddir) || rm -f $(ALL_MANS)
# Dependencies common to all man pages. Updated below.
mandeps =
# Depend on this to get version number changes.
mandeps += .version
# This is required so that changes to e.g., emit_bug_reporting_address
# provoke regeneration of all the manpages.
mandeps += $(top_srcdir)/src/system.h
$(ALL_MANS): $(mandeps)
# Most prog.1 man pages depend on src/$prog, except when they are part of a
# single binary, in which case they depend on src/coreutils. The exceptions
# are handled by converting $name to $prog on the following code.
# $(ALL_MANS) includes the $(EXTRA_MANS) so even the programs that are not
# being installed will have the right dependency for the manpages.
CLEANFILES += man/dynamic-deps.mk
man/dynamic-deps.mk: Makefile
$(AM_V_GEN)rm -f $@ $@-t
$(AM_V_at)for man in $(ALL_MANS); do \
name=$${man:4: -2} ; # Space is important \
case $$name in \
arch) prog='uname';; \
install) prog='ginstall';; \
test) prog='[';; \
*) prog=$$name;; \
esac; \
case " $(single_binary_progs) " in \
*" $$prog "*) \
echo $$man: src/coreutils$(EXEEXT);; \
*) \
echo $$man: src/$$prog$(EXEEXT);; \
esac \
done > $@-t \
&& chmod a-w $@-t \
&& mv $@-t $@
# Include the generated man dependencies.
-include man/dynamic-deps.mk
.x.1:
$(AM_V_GEN)name=`echo $@ | sed 's|.*/||; s|\.1$$||'` || exit 1; \
## Ensure that help2man runs the 'src/ginstall' binary as 'install' when
## creating 'install.1'. Similarly, ensure that it uses the 'src/[' binary
## to create 'test.1'.
case $$name in \
install) prog='ginstall'; argv=$$name;; \
test) prog='['; argv='[';; \
*) prog=$$name; argv=$$prog;; \
esac; \
## Note the use of $$t/$*, rather than just '$*' as in other packages.
## That is necessary to avoid failures for programs that are also shell
## built-in functions like echo, false, printf, pwd.
rm -f $@ $@-t \
&& t=$*.td \
&& rm -rf $$t \
&& $(MKDIR_P) $$t \
&& (cd $$t && $(LN_S) '$(abs_top_builddir)/src/'$$prog $$argv) \
&& $(run_help2man) \
--source='$(PACKAGE_STRING)' \
--include=$(srcdir)/man/$$name.x \
--output=$$t/$$name.1 $$t/$$argv \
--info-page='coreutils \(aq'$$name' invocation\(aq' \
&& sed \
-e 's|$*\.td/||g' \
-e '/For complete documentation/d' \
$$t/$$name.1 > $@-t \
&& rm -rf $$t \
&& chmod a-w $@-t \
&& mv $@-t $@