cp/mv: add xattr support
[coreutils.git] / src / Makefile.am
blob907b9e79970239643a20a972f24d851535a9592b
1 ## Process this file with automake to produce Makefile.in -*-Makefile-*-
3 ## Copyright (C) 1990, 1991, 1993-2008 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 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 noinst_HEADERS = \
52   chown-core.h \
53   copy.h \
54   cp-hash.h \
55   dircolors.h \
56   fs.h \
57   group-list.h \
58   ls.h \
59   operand2sig.h \
60   prog-fprintf.h \
61   remove.h \
62   system.h \
63   wheel-size.h \
64   wheel.h \
65   uname.h
67 EXTRA_DIST = dcgen dircolors.hin tac-pipe.c \
68   wheel-gen.pl extract-magic c99-to-c89.diff
69 BUILT_SOURCES =
70 CLEANFILES = $(SCRIPTS) su
72 AM_CPPFLAGS = -I$(top_srcdir)/lib
74 noinst_LIBRARIES = libver.a
75 nodist_libver_a_SOURCES = version.c version.h
77 # Sometimes, the expansion of $(LIBINTL) includes -lc which may
78 # include modules defining variables like `optind', so libcoreutils.a
79 # must precede $(LIBINTL) in order to ensure we use GNU getopt.
80 # But libcoreutils.a must also follow $(LIBINTL), since libintl uses
81 # replacement functions defined in libcoreutils.a.
82 LDADD = libver.a ../lib/libcoreutils.a $(LIBINTL) ../lib/libcoreutils.a
84 cat_LDADD = $(LDADD)
85 df_LDADD = $(LDADD)
86 du_LDADD = $(LDADD)
87 getlimits_LDADD = $(LDADD)
88 ptx_LDADD = $(LDADD)
89 split_LDADD = $(LDADD)
90 timeout_LDADD = $(LDADD)
91 truncate_LDADD = $(LDADD)
93 # for eaccess in lib/euidaccess.c.
94 chcon_LDADD = $(LDADD) $(LIB_SELINUX)
95 cp_LDADD = $(LDADD) $(LIB_EACCESS) $(LIB_SELINUX)
96 ginstall_LDADD = $(LDADD) $(LIB_EACCESS) $(LIB_SELINUX)
97 mkdir_LDADD = $(LDADD) $(LIB_SELINUX)
98 mkfifo_LDADD = $(LDADD) $(LIB_SELINUX)
99 mknod_LDADD = $(LDADD) $(LIB_SELINUX)
100 mv_LDADD = $(LDADD) $(LIB_EACCESS) $(LIB_SELINUX)
101 runcon_LDADD = $(LDADD) $(LIB_SELINUX)
102 pathchk_LDADD = $(LDADD) $(LIB_EACCESS)
103 rm_LDADD = $(LDADD) $(LIB_EACCESS)
104 test_LDADD = $(LDADD) $(LIB_EACCESS)
105 # This is for the '[' program.  Automake transliterates '[' to '_'.
106 __LDADD = $(LDADD) $(LIB_EACCESS)
108 # for clock_gettime and fdatasync
109 dd_LDADD = $(LDADD) $(LIB_GETHRXTIME) $(LIB_FDATASYNC)
110 dir_LDADD = $(LDADD) $(LIB_CLOCK_GETTIME) $(LIB_SELINUX) $(LIB_CAP)
111 id_LDADD = $(LDADD) $(LIB_SELINUX)
112 ls_LDADD = $(LDADD) $(LIB_CLOCK_GETTIME) $(LIB_SELINUX) $(LIB_CAP)
113 mktemp_LDADD = $(LDADD) $(LIB_GETHRXTIME)
114 pr_LDADD = $(LDADD) $(LIB_CLOCK_GETTIME)
115 shred_LDADD = $(LDADD) $(LIB_GETHRXTIME) $(LIB_FDATASYNC)
116 shuf_LDADD = $(LDADD) $(LIB_GETHRXTIME)
117 tac_LDADD = $(LDADD) $(LIB_CLOCK_GETTIME)
118 vdir_LDADD = $(LDADD) $(LIB_CLOCK_GETTIME) $(LIB_SELINUX) $(LIB_CAP)
120 ## If necessary, add -lm to resolve use of pow in lib/strtod.c.
121 sort_LDADD = $(LDADD) $(POW_LIB) $(LIB_GETHRXTIME)
123 # for get_date and gettime
124 date_LDADD = $(LDADD) $(LIB_CLOCK_GETTIME)
125 touch_LDADD = $(LDADD) $(LIB_CLOCK_GETTIME)
127 # If necessary, add -lm to resolve use of pow in lib/strtod.c.
128 # If necessary, add -liconv to resolve use of iconv in lib/unicodeio.c.
129 printf_LDADD = $(LDADD) $(POW_LIB) $(LIBICONV)
131 # If necessary, add -lm to resolve use of pow in lib/strtod.c.
132 seq_LDADD = $(LDADD) $(POW_LIB)
134 # If necessary, add libraries to resolve the `pow' reference in lib/strtod.c
135 # and the `nanosleep' reference in lib/xnanosleep.c.
136 nanosec_libs = $(LDADD) $(POW_LIB) $(LIB_NANOSLEEP)
138 # for various GMP functions
139 expr_LDADD = $(LDADD) $(LIB_GMP)
141 # for various GMP functions
142 factor_LDADD = $(LDADD) $(LIB_GMP)
144 sleep_LDADD = $(nanosec_libs)
145 tail_LDADD = $(nanosec_libs)
147 # If necessary, add -lm to resolve use of pow in lib/strtod.c.
148 uptime_LDADD = $(LDADD) $(POW_LIB) $(GETLOADAVG_LIBS)
150 su_LDADD = $(LDADD) $(LIB_CRYPT)
152 dir_LDADD += $(LIB_ACL)
153 ls_LDADD += $(LIB_ACL)
154 vdir_LDADD += $(LIB_ACL)
155 cp_LDADD += $(LIB_ACL) $(LIB_XATTR)
156 mv_LDADD += $(LIB_ACL) $(LIB_XATTR)
157 ginstall_LDADD += $(LIB_ACL) $(LIB_XATTR)
159 stat_LDADD = $(LDADD) $(LIB_SELINUX)
161 # Append $(LIBICONV) to each program that uses proper_name_utf8.
162 cat_LDADD += $(LIBICONV)
163 cp_LDADD += $(LIBICONV)
164 df_LDADD += $(LIBICONV)
165 du_LDADD += $(LIBICONV)
166 getlimits_LDADD += $(LIBICONV)
167 ptx_LDADD += $(LIBICONV)
168 split_LDADD += $(LIBICONV)
169 timeout_LDADD += $(LIBICONV)
170 truncate_LDADD += $(LIBICONV)
172 # programs that use getaddrinfo (e.g., via canon_host)
173 pinky_LDADD = $(LDADD) $(GETADDRINFO_LIB)
174 who_LDADD = $(LDADD) $(GETADDRINFO_LIB)
176 $(PROGRAMS): ../lib/libcoreutils.a
178 # Get the release year from ../lib/version-etc.c.
179 RELEASE_YEAR = \
180   `sed -n '/.*COPYRIGHT_YEAR = \([0-9][0-9][0-9][0-9]\) };/s//\1/p' \
181     $(top_srcdir)/lib/version-etc.c`
183 all-local: su$(EXEEXT)
185 installed_su = $(DESTDIR)$(bindir)/`echo su|sed '$(transform)'`
187 setuid_root_mode = a=rx,u+s
189 install_su =                                            \
190   if test "$(INSTALL_SU)" = yes; then                   \
191     p=su;                                               \
192     echo " $(INSTALL_PROGRAM) $$p $(installed_su)";     \
193     $(INSTALL_PROGRAM) $$p $(installed_su);             \
194     echo " chown root $(installed_su)";                 \
195     chown root $(installed_su);                         \
196     echo " chmod $(setuid_root_mode) $(installed_su)";  \
197     chmod $(setuid_root_mode) $(installed_su);          \
198   else                                                  \
199     :;                                                  \
200   fi
202 install-root: su$(EXEEXT)
203         @$(install_su)
205 install-exec-hook: su$(EXEEXT)
206         @if test "$(INSTALL_SU)" = yes; then                    \
207           TMPFILE=$(DESTDIR)$(bindir)/.su-$$$$;                 \
208           rm -f $$TMPFILE;                                      \
209           echo > $$TMPFILE;                                     \
210 ## See if we can create a setuid root executable in $(bindir).
211 ## If not, then don't even try to install su.
212           can_create_suid_root_executable=no;                   \
213           chown root $$TMPFILE > /dev/null 2>&1                 \
214             && chmod $(setuid_root_mode) $$TMPFILE > /dev/null 2>&1 \
215             && can_create_suid_root_executable=yes;             \
216           rm -f $$TMPFILE;                                      \
217           if test $$can_create_suid_root_executable = yes; then \
218             $(install_su);                                      \
219           else                                                  \
220             echo "WARNING: insufficient access; not installing su"; \
221             echo "NOTE: to install su, run 'make install-root' as root"; \
222             rm -f $(installed_su);                              \
223           fi;                                                   \
224         else :;                                                 \
225         fi
227 uninstall-local:
228 # Remove su only if it's one we installed.
229         @if test "$(INSTALL_SU)" = yes; then                    \
230           if grep '$(PACKAGE_NAME)' $(installed_su) > /dev/null 2>&1; then \
231             echo "  rm -f $(installed_su)"; \
232             rm -f $(installed_su); \
233           else :; \
234           fi; \
235         fi
237 copy_sources = copy.c cp-hash.c
239 # Use `ginstall' in the definition of PROGRAMS and in dependencies to avoid
240 # confusion with the `install' target.  The install rule transforms `ginstall'
241 # to install before applying any user-specified name transformations.
243 transform = s/ginstall/install/; $(program_transform_name)
244 ginstall_SOURCES = install.c prog-fprintf.c $(copy_sources)
246 # This is for the '[' program.  Automake transliterates '[' to '_'.
247 __SOURCES = lbracket.c
249 cp_SOURCES = cp.c $(copy_sources)
250 dir_SOURCES = ls.c ls-dir.c
251 vdir_SOURCES = ls.c ls-vdir.c
252 id_SOURCES = id.c group-list.c
253 groups_SOURCES = groups.c group-list.c
254 ln_SOURCES = ln.c
255 ls_SOURCES = ls.c ls-ls.c
256 chown_SOURCES = chown.c chown-core.c
257 chgrp_SOURCES = chgrp.c chown-core.c
258 kill_SOURCES = kill.c operand2sig.c
259 timeout_SOURCES = timeout.c operand2sig.c
261 mv_SOURCES = mv.c remove.c $(copy_sources)
262 rm_SOURCES = rm.c remove.c
264 mkdir_SOURCES = mkdir.c prog-fprintf.c
265 rmdir_SOURCES = rmdir.c prog-fprintf.c
267 uname_SOURCES = uname.c uname-uname.c
268 arch_SOURCES = uname.c uname-arch.c
270 md5sum_SOURCES = md5sum.c
271 md5sum_CPPFLAGS = -DHASH_ALGO_MD5=1 $(AM_CPPFLAGS)
272 sha1sum_SOURCES = md5sum.c
273 sha1sum_CPPFLAGS = -DHASH_ALGO_SHA1=1 $(AM_CPPFLAGS)
274 sha224sum_SOURCES = md5sum.c
275 sha224sum_CPPFLAGS = -DHASH_ALGO_SHA224=1 $(AM_CPPFLAGS)
276 sha256sum_SOURCES = md5sum.c
277 sha256sum_CPPFLAGS = -DHASH_ALGO_SHA256=1 $(AM_CPPFLAGS)
278 sha384sum_SOURCES = md5sum.c
279 sha384sum_CPPFLAGS = -DHASH_ALGO_SHA384=1 $(AM_CPPFLAGS)
280 sha512sum_SOURCES = md5sum.c
281 sha512sum_CPPFLAGS = -DHASH_ALGO_SHA512=1 $(AM_CPPFLAGS)
283 ginstall_CPPFLAGS = -DENABLE_MATCHPATHCON=1 $(AM_CPPFLAGS)
285 editpl = sed -e 's,@''PERL''@,$(PERL),g'
287 BUILT_SOURCES += dircolors.h
288 dircolors.h: dcgen dircolors.hin
289         @rm -f $@ $@-t
290         $(PERL) -w -- $(srcdir)/dcgen $(srcdir)/dircolors.hin > $@-t
291         @chmod a-w $@-t
292         mv $@-t $@
294 wheel_size = 5
296 BUILT_SOURCES += wheel-size.h
297 wheel-size.h: Makefile.am
298         @rm -f $@ $@-t
299         echo '#define WHEEL_SIZE $(wheel_size)' > $@-t
300         @chmod a-w $@-t
301         mv $@-t $@
303 BUILT_SOURCES += wheel.h
304 wheel.h: wheel-gen.pl Makefile.am
305         @rm -f $@ $@-t
306         $(srcdir)/wheel-gen.pl $(wheel_size) > $@-t
307         @chmod a-w $@-t
308         mv $@-t $@
310 # false exits nonzero even with --help or --version.
311 # test doesn't support --help or --version.
312 # Tell automake to exempt then from that installcheck test.
313 AM_INSTALLCHECK_STD_OPTIONS_EXEMPT = false test
315 BUILT_SOURCES += fs.h
316 fs.h: stat.c extract-magic
317         rm -f $@
318         $(PERL) $(srcdir)/extract-magic $(srcdir)/stat.c > $@t
319         @chmod a-w $@t
320         mv $@t $@
322 BUILT_SOURCES += version.c
323 version.c: Makefile
324         rm -f $@
325         printf '#include <config.h>\n' > $@t
326         printf 'char const *Version = "$(PACKAGE_VERSION)";\n' >> $@t
327         @chmod a-w $@t
328         mv $@t $@
330 BUILT_SOURCES += version.h
331 version.h: Makefile
332         rm -f $@
333         printf 'extern char const *Version;\n' > $@t
334         @chmod a-w $@t
335         mv $@t $@
337 DISTCLEANFILES = version.c version.h
338 MAINTAINERCLEANFILES = $(BUILT_SOURCES)
340 # Sort in traditional ASCII order, regardless of the current locale;
341 # otherwise we may get into trouble with distinct strings that the
342 # current locale considers to be equal.
343 ASSORT = LC_ALL=C sort
345 all_programs = \
346     $(bin_PROGRAMS) \
347     $(bin_SCRIPTS) \
348   $(EXTRA_PROGRAMS)
350 built_programs.list:
351         @echo $(bin_PROGRAMS) $(bin_SCRIPTS) | tr ' ' '\n' \
352           | sed -e 's,$(EXEEXT)$$,,' | $(ASSORT) -u | tr '\n' ' '
354 all_programs.list:
355         @echo $(all_programs) | tr ' ' '\n' | sed -e 's,$(EXEEXT)$$,,' \
356           | $(ASSORT) -u
358 pm = progs-makefile
359 pr = progs-readme
360 # Ensure that the list of programs in README matches the list
361 # of programs we can build.
362 check: check-README check-duplicate-no-install
363 .PHONY: check-README
364 check-README:
365         rm -rf $(pr) $(pm)
366         echo $(all_programs) \
367          | tr -s ' ' '\n' | sed -e 's,$(EXEEXT)$$,,;s/ginstall/install/' \
368          | $(ASSORT) -u > $(pm) && \
369         sed -n '/^The programs .* are:/,/^[a-zA-Z]/p' $(top_srcdir)/README \
370           | sed -n '/^   */s///p' | tr -s ' ' '\n' > $(pr)
371         diff $(pm) $(pr) && rm -rf $(pr) $(pm)
373 # Ensure that a by-default-not-installed program (listed in
374 # $(no_install__progs) is not also listed in $(EXTRA_PROGRAMS), because
375 # if that were to happen, it *would* be installed by default.
376 .PHONY: check-duplicate-no-install
377 check-duplicate-no-install: tr
378         test -z "`echo '$(EXTRA_PROGRAMS)'| ./tr ' ' '\n' | uniq -d`"
380 # Ensure that the list of programs and author names is accurate.
381 au_dotdot = authors-dotdot
382 au_actual = authors-actual
383 .PHONY: check-AUTHORS
384 check-AUTHORS: $(all_programs)
385         rm -f $(au_actual) $(au_dotdot)
386         for i in `ls $(all_programs) | sed -e 's,$(EXEEXT)$$,,' \
387             | $(ASSORT) -u`; do                         \
388           test "$$i" = '[' && continue;                 \
389           exe=$$i;                                      \
390           if test "$$i" = install; then                 \
391             exe=ginstall;                               \
392           elif test "$$i" = test; then                  \
393             exe='[';                                    \
394           fi;                                           \
395           LC_ALL=en_US.UTF-8 ./$$exe --version                  \
396             | perl -0 -pi -e 's/,\n/, /gm'              \
397             |sed -n '/Written by /{ s//'"$$i"': /; s/,* and /, /; s/\.$$//; p; }'; \
398         done > $(au_actual)
399         sed -n '/^[^ ][^ ]*:/p' $(top_srcdir)/AUTHORS > $(au_dotdot)
400         diff $(au_actual) $(au_dotdot) && rm -f $(au_actual) $(au_dotdot)
402 # Extract the list of authors from each file.
403 sed_filter = s/^ *//;s/N_ (//;s/^"//;s/")*$$//
404 # Sometimes the string is on the same line as the #define...
405 s1 = '/^\#define AUTHORS \([^\\]\)/{;s//\1/;$(sed_filter);p;q;}'
406 # Sometimes the string is on the backslash-continued line after the #define.
407 s2 = '/^\#define AUTHORS \\\\/{;n;$(sed_filter);p;q;}'
408 # FIXME: handle *.sh;  and use $(all_programs), not $(SOURCES)
409 ../AUTHORS: $(SOURCES)
410         rm -f $@-t
411         (                                               \
412           set -e;                                       \
413           echo "Here are the names of the programs in this package,";   \
414           echo "each followed by the name(s) of its author(s).";        \
415           echo;                                         \
416           for i in $(SOURCES); do                       \
417             a=`sed -n $(s1) $$i`;                       \
418             test "$$a" && :                             \
419               || a=`sed -n $(s2) $$i`;                  \
420             if test "$$a"; then                         \
421               prog=`echo $$i|sed 's/\.c$$//'`;          \
422               echo "$$prog: $$a";                       \
423             fi;                                         \
424           done | $(ASSORT) -u ) > $@-t
425         chmod a-w $@-t
426         mv $@-t $@
428 # The following rule is not designed to be portable,
429 # and relies on tools that not everyone has.
431 # Most functions in src/*.c should have static scope.
432 # Any that don't must be marked with `extern', but `main'
433 # and `usage' are exceptions.  They're always extern, but
434 # don't need to be marked.
436 # The second nm|grep checks for file-scope variables with `extern' scope.
437 .PHONY: sc_tight_scope
438 sc_tight_scope: $(all_programs)
439         @t=exceptions-$$$$;                                             \
440         trap "s=$$?; rm -f $$t; exit $$s" 0 1 2 13 15;                  \
441         src=`for f in $(SOURCES); do                                    \
442                test -f $$f && d= || d=$(srcdir)/; echo $$d$$f; done`;   \
443         hdr=`for f in $(noinst_HEADERS); do                             \
444                test -f $$f && d= || d=$(srcdir)/; echo $$d$$f; done`;   \
445         ( printf 'main\nusage\n';                                       \
446           grep -h -A1 '^extern .*[^;]$$' $$src                          \
447             | grep -vE '^(extern |--)' | sed 's/ .*//';                 \
448           perl -ne '/^extern \S+ (\S*) \(/ and print "$$1\n"' $$hdr;    \
449         ) | $(ASSORT) -u | sed 's/^/^/;s/$$/$$/' > $$t;                 \
450         nm -e *.$(OBJEXT)                                               \
451             | sed -n 's/.* T //p'                                       \
452             | grep -Ev -f $$t &&                                        \
453           { echo 'the above functions should have static scope' 1>&2;   \
454             exit 1; } || : ;                                            \
455         ( printf '^program_name$$\n';                                   \
456           perl -ne '/^extern .*?\**(\w+);/ and print "^$$1\$$\n"'       \
457             $$hdr *.h ) | $(ASSORT) -u > $$t;                           \
458         nm -e *.$(OBJEXT)                                               \
459             | sed -n 's/.* [BD] //p'                                    \
460             | grep -Ev -f $$t &&                                        \
461           { echo 'the above variables should have static scope' 1>&2;   \
462             exit 1; } || :
464 # Use the just-built ./ginstall, when not cross-compiling.
465 if CROSS_COMPILING
466 cu_install_program = @INSTALL_PROGRAM@
467 else
468 cu_install_program = ./ginstall
469 endif
470 INSTALL_PROGRAM = $(cu_install_program)