stdbuf: A new program to run a command with modified stdio buffering
[coreutils/ericb.git] / src / Makefile.am
blob4f21c863315c0d244b0c08d89de5e3558d04810c
1 ## Process this file with automake to produce Makefile.in -*-Makefile-*-
3 ## Copyright (C) 1990, 1991, 1993-2009 Free Software Foundation, Inc.
5 ## This program is free software: you can redistribute it and/or modify
6 ## it under the terms of the GNU General Public License as published by
7 ## the Free Software Foundation, either version 3 of the License, or
8 ## (at your option) any later version.
9 ##
10 ## This program is distributed in the hope that it will be useful,
11 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 ## GNU General Public License for more details.
15 ## You should have received a copy of the GNU General Public License
16 ## along with this program.  If not, see <http://www.gnu.org/licenses/>.
18 # These are the names of programs that are not installed by default.
19 # This list is *not* intended for programs like who, nice, chroot, etc.,
20 # that are built only when certain requisite system features are detected.
21 # Hence, if you want to install programs from this list anyway, say A and B,
22 # use --enable-install-program=A,B
23 no_install__progs = \
24   arch hostname su
26 build_if_possible__progs = \
27   chroot df hostid nice pinky stdbuf libstdbuf.so stty su uname uptime users who
29 AM_CFLAGS = $(WARN_CFLAGS) $(WERROR_CFLAGS)
31 EXTRA_PROGRAMS = \
32   $(no_install__progs) \
33   $(build_if_possible__progs) \
34   [ chcon chgrp chown chmod cp dd dircolors du \
35   ginstall link ln dir vdir ls mkdir \
36   mkfifo mknod mktemp \
37   mv nohup readlink rm rmdir shred stat sync touch unlink \
38   cat cksum comm csplit cut expand fmt fold head join groups md5sum \
39   nl od paste pr ptx sha1sum sha224sum sha256sum sha384sum sha512sum \
40   shuf sort split sum tac tail tr tsort unexpand uniq wc \
41   basename date dirname echo env expr factor false \
42   id kill logname pathchk printenv printf pwd \
43   runcon seq sleep tee \
44   test timeout true truncate tty whoami yes \
45   base64
47 bin_PROGRAMS = $(OPTIONAL_BIN_PROGS)
49 noinst_PROGRAMS = setuidgid getlimits
51 pkglib_PROGRAMS = $(OPTIONAL_PKGLIB_PROGS)
53 noinst_HEADERS = \
54   chown-core.h \
55   copy.h \
56   cp-hash.h \
57   dircolors.h \
58   fs.h \
59   group-list.h \
60   ls.h \
61   operand2sig.h \
62   prog-fprintf.h \
63   remove.h \
64   system.h \
65   wheel-size.h \
66   wheel.h \
67   uname.h
69 EXTRA_DIST = dcgen dircolors.hin tac-pipe.c \
70   wheel-gen.pl extract-magic c99-to-c89.diff
71 BUILT_SOURCES =
72 CLEANFILES = $(SCRIPTS) su
74 # Also remove these sometimes-built programs.
75 # For example, even when excluded, they're built via check-AUTHORS.
76 CLEANFILES += $(no_install__progs)
78 AM_CPPFLAGS = -I$(top_srcdir)/lib
80 noinst_LIBRARIES = libver.a
81 nodist_libver_a_SOURCES = version.c version.h
83 # Sometimes, the expansion of $(LIBINTL) includes -lc which may
84 # include modules defining variables like `optind', so libcoreutils.a
85 # must precede $(LIBINTL) in order to ensure we use GNU getopt.
86 # But libcoreutils.a must also follow $(LIBINTL), since libintl uses
87 # replacement functions defined in libcoreutils.a.
88 LDADD = libver.a ../lib/libcoreutils.a $(LIBINTL) ../lib/libcoreutils.a
90 cat_LDADD = $(LDADD)
91 df_LDADD = $(LDADD)
92 du_LDADD = $(LDADD)
93 getlimits_LDADD = $(LDADD)
94 ptx_LDADD = $(LDADD)
95 split_LDADD = $(LDADD)
96 stdbuf_LDADD = $(LDADD)
97 timeout_LDADD = $(LDADD)
98 truncate_LDADD = $(LDADD)
100 # for eaccess in lib/euidaccess.c.
101 chcon_LDADD = $(LDADD) $(LIB_SELINUX)
102 cp_LDADD = $(LDADD) $(LIB_EACCESS) $(LIB_SELINUX)
103 ginstall_LDADD = $(LDADD) $(LIB_EACCESS) $(LIB_SELINUX)
104 mkdir_LDADD = $(LDADD) $(LIB_SELINUX)
105 mkfifo_LDADD = $(LDADD) $(LIB_SELINUX)
106 mknod_LDADD = $(LDADD) $(LIB_SELINUX)
107 mv_LDADD = $(LDADD) $(LIB_EACCESS) $(LIB_SELINUX)
108 runcon_LDADD = $(LDADD) $(LIB_SELINUX)
109 pathchk_LDADD = $(LDADD) $(LIB_EACCESS)
110 rm_LDADD = $(LDADD) $(LIB_EACCESS)
111 test_LDADD = $(LDADD) $(LIB_EACCESS)
112 # This is for the '[' program.  Automake transliterates '[' to '_'.
113 __LDADD = $(LDADD) $(LIB_EACCESS)
115 # for clock_gettime and fdatasync
116 dd_LDADD = $(LDADD) $(LIB_GETHRXTIME) $(LIB_FDATASYNC)
117 dir_LDADD = $(LDADD) $(LIB_CLOCK_GETTIME) $(LIB_SELINUX) $(LIB_CAP)
118 id_LDADD = $(LDADD) $(LIB_SELINUX)
119 ls_LDADD = $(LDADD) $(LIB_CLOCK_GETTIME) $(LIB_SELINUX) $(LIB_CAP)
120 mktemp_LDADD = $(LDADD) $(LIB_GETHRXTIME)
121 pr_LDADD = $(LDADD) $(LIB_CLOCK_GETTIME)
122 shred_LDADD = $(LDADD) $(LIB_GETHRXTIME) $(LIB_FDATASYNC)
123 shuf_LDADD = $(LDADD) $(LIB_GETHRXTIME)
124 tac_LDADD = $(LDADD) $(LIB_CLOCK_GETTIME)
125 vdir_LDADD = $(LDADD) $(LIB_CLOCK_GETTIME) $(LIB_SELINUX) $(LIB_CAP)
127 ## If necessary, add -lm to resolve use of pow in lib/strtod.c.
128 sort_LDADD = $(LDADD) $(POW_LIB) $(LIB_GETHRXTIME)
130 # for get_date and gettime
131 date_LDADD = $(LDADD) $(LIB_CLOCK_GETTIME)
132 touch_LDADD = $(LDADD) $(LIB_CLOCK_GETTIME)
134 # If necessary, add -lm to resolve use of pow in lib/strtod.c.
135 # If necessary, add -liconv to resolve use of iconv in lib/unicodeio.c.
136 printf_LDADD = $(LDADD) $(POW_LIB) $(LIBICONV)
138 # If necessary, add -lm to resolve use of pow in lib/strtod.c.
139 seq_LDADD = $(LDADD) $(POW_LIB)
141 # If necessary, add libraries to resolve the `pow' reference in lib/strtod.c
142 # and the `nanosleep' reference in lib/xnanosleep.c.
143 nanosec_libs = $(LDADD) $(POW_LIB) $(LIB_NANOSLEEP)
145 # for various GMP functions
146 expr_LDADD = $(LDADD) $(LIB_GMP)
148 # for various GMP functions
149 factor_LDADD = $(LDADD) $(LIB_GMP)
151 sleep_LDADD = $(nanosec_libs)
152 tail_LDADD = $(nanosec_libs)
154 # If necessary, add -lm to resolve use of pow in lib/strtod.c.
155 uptime_LDADD = $(LDADD) $(POW_LIB) $(GETLOADAVG_LIBS)
157 su_LDADD = $(LDADD) $(LIB_CRYPT)
159 dir_LDADD += $(LIB_ACL)
160 ls_LDADD += $(LIB_ACL)
161 vdir_LDADD += $(LIB_ACL)
162 cp_LDADD += $(LIB_ACL) $(LIB_XATTR)
163 mv_LDADD += $(LIB_ACL) $(LIB_XATTR)
164 ginstall_LDADD += $(LIB_ACL) $(LIB_XATTR)
166 stat_LDADD = $(LDADD) $(LIB_SELINUX)
168 # Append $(LIBICONV) to each program that uses proper_name_utf8.
169 cat_LDADD += $(LIBICONV)
170 cp_LDADD += $(LIBICONV)
171 df_LDADD += $(LIBICONV)
172 du_LDADD += $(LIBICONV)
173 getlimits_LDADD += $(LIBICONV)
174 ptx_LDADD += $(LIBICONV)
175 split_LDADD += $(LIBICONV)
176 stdbuf_LDADD += $(LIBICONV)
177 timeout_LDADD += $(LIBICONV)
178 truncate_LDADD += $(LIBICONV)
180 # programs that use getaddrinfo (e.g., via canon_host)
181 pinky_LDADD = $(LDADD) $(GETADDRINFO_LIB)
182 who_LDADD = $(LDADD) $(GETADDRINFO_LIB)
184 $(PROGRAMS): ../lib/libcoreutils.a
186 # Get the release year from ../lib/version-etc.c.
187 RELEASE_YEAR = \
188   `sed -n '/.*COPYRIGHT_YEAR = \([0-9][0-9][0-9][0-9]\) };/s//\1/p' \
189     $(top_srcdir)/lib/version-etc.c`
191 all-local: su$(EXEEXT)
193 installed_su = $(DESTDIR)$(bindir)/`echo su|sed '$(transform)'`
195 setuid_root_mode = a=rx,u+s
197 install_su =                                            \
198   if test "$(INSTALL_SU)" = yes; then                   \
199     p=su;                                               \
200     echo " $(INSTALL_PROGRAM) $$p $(installed_su)";     \
201     $(INSTALL_PROGRAM) $$p $(installed_su);             \
202     echo " chown root $(installed_su)";                 \
203     chown root $(installed_su);                         \
204     echo " chmod $(setuid_root_mode) $(installed_su)";  \
205     chmod $(setuid_root_mode) $(installed_su);          \
206   else                                                  \
207     :;                                                  \
208   fi
210 install-root: su$(EXEEXT)
211         @$(install_su)
213 install-exec-hook: su$(EXEEXT)
214         @if test "$(INSTALL_SU)" = yes; then                    \
215           TMPFILE=$(DESTDIR)$(bindir)/.su-$$$$;                 \
216           rm -f $$TMPFILE;                                      \
217           echo > $$TMPFILE;                                     \
218 ## See if we can create a setuid root executable in $(bindir).
219 ## If not, then don't even try to install su.
220           can_create_suid_root_executable=no;                   \
221           chown root $$TMPFILE > /dev/null 2>&1                 \
222             && chmod $(setuid_root_mode) $$TMPFILE > /dev/null 2>&1 \
223             && can_create_suid_root_executable=yes;             \
224           rm -f $$TMPFILE;                                      \
225           if test $$can_create_suid_root_executable = yes; then \
226             $(install_su);                                      \
227           else                                                  \
228             echo "WARNING: insufficient access; not installing su"; \
229             echo "NOTE: to install su, run 'make install-root' as root"; \
230             rm -f $(installed_su);                              \
231           fi;                                                   \
232         else :;                                                 \
233         fi
235 uninstall-local:
236 # Remove su only if it's one we installed.
237         @if test "$(INSTALL_SU)" = yes; then                    \
238           if grep '$(PACKAGE_NAME)' $(installed_su) > /dev/null 2>&1; then \
239             echo "  rm -f $(installed_su)"; \
240             rm -f $(installed_su); \
241           else :; \
242           fi; \
243         fi
245 copy_sources = copy.c cp-hash.c
247 # Use `ginstall' in the definition of PROGRAMS and in dependencies to avoid
248 # confusion with the `install' target.  The install rule transforms `ginstall'
249 # to install before applying any user-specified name transformations.
251 transform = s/ginstall/install/; $(program_transform_name)
252 ginstall_SOURCES = install.c prog-fprintf.c $(copy_sources)
254 # This is for the '[' program.  Automake transliterates '[' to '_'.
255 __SOURCES = lbracket.c
257 cp_SOURCES = cp.c $(copy_sources)
258 dir_SOURCES = ls.c ls-dir.c
259 vdir_SOURCES = ls.c ls-vdir.c
260 id_SOURCES = id.c group-list.c
261 groups_SOURCES = groups.c group-list.c
262 ln_SOURCES = ln.c
263 ls_SOURCES = ls.c ls-ls.c
264 chown_SOURCES = chown.c chown-core.c
265 chgrp_SOURCES = chgrp.c chown-core.c
266 kill_SOURCES = kill.c operand2sig.c
267 timeout_SOURCES = timeout.c operand2sig.c
269 mv_SOURCES = mv.c remove.c $(copy_sources)
270 rm_SOURCES = rm.c remove.c
272 mkdir_SOURCES = mkdir.c prog-fprintf.c
273 rmdir_SOURCES = rmdir.c prog-fprintf.c
275 uname_SOURCES = uname.c uname-uname.c
276 arch_SOURCES = uname.c uname-arch.c
278 md5sum_SOURCES = md5sum.c
279 md5sum_CPPFLAGS = -DHASH_ALGO_MD5=1 $(AM_CPPFLAGS)
280 sha1sum_SOURCES = md5sum.c
281 sha1sum_CPPFLAGS = -DHASH_ALGO_SHA1=1 $(AM_CPPFLAGS)
282 sha224sum_SOURCES = md5sum.c
283 sha224sum_CPPFLAGS = -DHASH_ALGO_SHA224=1 $(AM_CPPFLAGS)
284 sha256sum_SOURCES = md5sum.c
285 sha256sum_CPPFLAGS = -DHASH_ALGO_SHA256=1 $(AM_CPPFLAGS)
286 sha384sum_SOURCES = md5sum.c
287 sha384sum_CPPFLAGS = -DHASH_ALGO_SHA384=1 $(AM_CPPFLAGS)
288 sha512sum_SOURCES = md5sum.c
289 sha512sum_CPPFLAGS = -DHASH_ALGO_SHA512=1 $(AM_CPPFLAGS)
291 ginstall_CPPFLAGS = -DENABLE_MATCHPATHCON=1 $(AM_CPPFLAGS)
293 # Ensure we don't link against libcoreutils.a as that lib is
294 # not compiled with -fPIC which causes issues on 64 bit at least
295 libstdbuf_so_LDADD =
297 # Note libstdbuf is only compiled if GCC is available
298 # (as per the check in configure.ac), so these flags should be available.
299 # libtool is probably required to relax this dependency.
300 libstdbuf_so_LDFLAGS = -shared
301 libstdbuf_so_CFLAGS = -fPIC $(AM_CFLAGS)
303 editpl = sed -e 's,@''PERL''@,$(PERL),g'
305 BUILT_SOURCES += dircolors.h
306 dircolors.h: dcgen dircolors.hin
307         $(AM_V_GEN)rm -f $@ $@-t
308         $(AM_V_at)$(PERL) -w -- $(srcdir)/dcgen $(srcdir)/dircolors.hin > $@-t
309         $(AM_V_at)chmod a-w $@-t
310         $(AM_V_at)mv $@-t $@
312 wheel_size = 5
314 BUILT_SOURCES += wheel-size.h
315 wheel-size.h: Makefile.am
316         $(AM_V_GEN)rm -f $@ $@-t
317         $(AM_V_at)echo '#define WHEEL_SIZE $(wheel_size)' > $@-t
318         $(AM_V_at)chmod a-w $@-t
319         $(AM_V_at)mv $@-t $@
321 BUILT_SOURCES += wheel.h
322 wheel.h: wheel-gen.pl Makefile.am
323         $(AM_V_GEN)rm -f $@ $@-t
324         $(AM_V_at)$(srcdir)/wheel-gen.pl $(wheel_size) > $@-t
325         $(AM_V_at)chmod a-w $@-t
326         $(AM_V_at)mv $@-t $@
328 # false exits nonzero even with --help or --version.
329 # test doesn't support --help or --version.
330 # Tell automake to exempt then from that installcheck test.
331 AM_INSTALLCHECK_STD_OPTIONS_EXEMPT = false test
333 BUILT_SOURCES += fs.h
334 fs.h: stat.c extract-magic
335         $(AM_V_GEN)rm -f $@
336         $(AM_V_at)$(PERL) $(srcdir)/extract-magic $(srcdir)/stat.c > $@t
337         $(AM_V_at)chmod a-w $@t
338         $(AM_V_at)mv $@t $@
340 BUILT_SOURCES += version.c
341 version.c: Makefile
342         $(AM_V_GEN)rm -f $@
343         $(AM_V_at)printf '#include <config.h>\n' > $@t
344         $(AM_V_at)printf 'char const *Version = "$(PACKAGE_VERSION)";\n' >> $@t
345         $(AM_V_at)chmod a-w $@t
346         $(AM_V_at)mv $@t $@
348 BUILT_SOURCES += version.h
349 version.h: Makefile
350         $(AM_V_GEN)rm -f $@
351         $(AM_V_at)printf 'extern char const *Version;\n' > $@t
352         $(AM_V_at)chmod a-w $@t
353         $(AM_V_at)mv $@t $@
355 DISTCLEANFILES = version.c version.h
356 MAINTAINERCLEANFILES = $(BUILT_SOURCES)
358 # Sort in traditional ASCII order, regardless of the current locale;
359 # otherwise we may get into trouble with distinct strings that the
360 # current locale considers to be equal.
361 ASSORT = LC_ALL=C sort
363 all_programs = \
364     $(bin_PROGRAMS) \
365     $(bin_SCRIPTS) \
366   $(EXTRA_PROGRAMS)
368 built_programs.list:
369         @echo $(bin_PROGRAMS) $(bin_SCRIPTS) | tr ' ' '\n' \
370           | sed -e 's,$(EXEEXT)$$,,' | $(ASSORT) -u | tr '\n' ' '
372 all_programs.list:
373         @echo $(all_programs) | tr ' ' '\n' | sed -e 's,$(EXEEXT)$$,,' \
374           | $(ASSORT) -u
376 pm = progs-makefile
377 pr = progs-readme
378 # Ensure that the list of programs in README matches the list
379 # of programs we can build.
380 check: check-README check-duplicate-no-install check-AUTHORS
381 .PHONY: check-README
382 check-README:
383         rm -rf $(pr) $(pm)
384         echo $(all_programs) \
385          | tr -s ' ' '\n' | sed -e 's,$(EXEEXT)$$,,;s/ginstall/install/' \
386          | sed /libstdbuf/d \
387          | $(ASSORT) -u > $(pm) && \
388         sed -n '/^The programs .* are:/,/^[a-zA-Z]/p' $(top_srcdir)/README \
389           | sed -n '/^   */s///p' | tr -s ' ' '\n' > $(pr)
390         diff $(pm) $(pr) && rm -rf $(pr) $(pm)
392 # Ensure that a by-default-not-installed program (listed in
393 # $(no_install__progs) is not also listed in $(EXTRA_PROGRAMS), because
394 # if that were to happen, it *would* be installed by default.
395 .PHONY: check-duplicate-no-install
396 check-duplicate-no-install: tr
397         test -z "`echo '$(EXTRA_PROGRAMS)'| ./tr ' ' '\n' | uniq -d`"
399 # Ensure that the list of programs and author names is accurate.
400 # We need a UTF8 locale.  If a lack of locale support or a missing
401 # translation inhibits printing of UTF-8 names, just skip this test.
402 au_dotdot = authors-dotdot
403 au_actual = authors-actual
404 .PHONY: check-AUTHORS
405 check-AUTHORS: $(all_programs)
406         $(AM_V_GEN)locale=en_US.UTF-8;                  \
407         LC_ALL="$$locale" ./cat --version               \
408             | grep ' Torbjorn ' > /dev/null             \
409           && { echo "$@: skipping this check"; exit 0; }; \
410         rm -f $(au_actual) $(au_dotdot);                \
411         for i in `ls $(all_programs) | sed -e 's,$(EXEEXT)$$,,' \
412             | sed /libstdbuf/d                          \
413             | $(ASSORT) -u`; do                         \
414           test "$$i" = '[' && continue;                 \
415           exe=$$i;                                      \
416           if test "$$i" = install; then                 \
417             exe=ginstall;                               \
418           elif test "$$i" = test; then                  \
419             exe='[';                                    \
420           fi;                                           \
421           LC_ALL="$$locale" ./$$exe --version           \
422             | perl -0 -pi -e 's/,\n/, /gm'              \
423             | sed -n -e '/Written by /{ s//'"$$i"': /;' \
424                   -e 's/,* and /, /; s/\.$$//; p; }';   \
425         done > $(au_actual) &&                          \
426         sed -n '/^[^ ][^ ]*:/p' $(top_srcdir)/AUTHORS > $(au_dotdot) && \
427         diff $(au_actual) $(au_dotdot) && rm -f $(au_actual) $(au_dotdot)
429 # The following rule is not designed to be portable,
430 # and relies on tools that not everyone has.
432 # Most functions in src/*.c should have static scope.
433 # Any that don't must be marked with `extern', but `main'
434 # and `usage' are exceptions.  They're always extern, but
435 # don't need to be marked. Also functions starting with __
436 # are exempted due to possibly being added by the compiler
437 # (when compiled as a shared library for example).
439 # The second nm|grep checks for file-scope variables with `extern' scope.
440 .PHONY: sc_tight_scope
441 sc_tight_scope: $(bin_PROGRAMS)
442         $(AM_V_GEN)t=exceptions-$$$$;                                   \
443         trap "s=$$?; rm -f $$t; exit $$s" 0 1 2 13 15;                  \
444         src=`for f in $(SOURCES); do                                    \
445                test -f $$f && d= || d=$(srcdir)/; echo $$d$$f; done`;   \
446         hdr=`for f in $(noinst_HEADERS); do                             \
447                test -f $$f && d= || d=$(srcdir)/; echo $$d$$f; done`;   \
448         ( printf 'main\nusage\n_.*\n';                                  \
449           grep -h -A1 '^extern .*[^;]$$' $$src                          \
450             | grep -vE '^(extern |--)' | sed 's/ .*//';                 \
451           perl -ne '/^extern \S+ (\S*) \(/ and print "$$1\n"' $$hdr;    \
452         ) | $(ASSORT) -u | sed 's/^/^/;s/$$/$$/' > $$t;                 \
453         nm -e *.$(OBJEXT)                                               \
454             | sed -n 's/.* T //p'                                       \
455             | sed 's/^_//'                                              \
456             | grep -Ev -f $$t &&                                        \
457           { echo 'the above functions should have static scope' 1>&2;   \
458             exit 1; } || : ;                                            \
459         ( printf '^program_name$$\n';                                   \
460           perl -ne '/^extern .*?\**(\w+);/ and print "^$$1\$$\n"'       \
461             $$hdr *.h ) | $(ASSORT) -u > $$t;                           \
462         nm -e *.$(OBJEXT)                                               \
463             | sed -n 's/.* [BD] //p'                                    \
464             | sed 's/^_//'                                              \
465             | grep -Ev -f $$t &&                                        \
466           { echo 'the above variables should have static scope' 1>&2;   \
467             exit 1; } || :
469 # Use the just-built ./ginstall, when not cross-compiling.
470 if CROSS_COMPILING
471 cu_install_program = @INSTALL_PROGRAM@
472 else
473 cu_install_program = ./ginstall
474 endif
475 INSTALL_PROGRAM = $(cu_install_program)