dd: clarify meaning of multiplication factors; put xM in order
[platform/upstream/coreutils.git] / src / Makefile.am
1 ## Process this file with automake to produce Makefile.in -*-Makefile-*-
2
3 ## Copyright (C) 1990, 1991, 1993-2008 Free Software Foundation, Inc.
4
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.
14 ##
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/>.
17
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
25
26 build_if_possible__progs = \
27   chroot df hostid nice pinky stty su uname uptime users who
28
29 EXTRA_PROGRAMS = \
30   $(no_install__progs) \
31   $(build_if_possible__progs) \
32   [ chcon chgrp chown chmod cp dd dircolors du \
33   ginstall link ln dir vdir ls mkdir \
34   mkfifo mknod mktemp \
35   mv nohup readlink rm rmdir shred stat sync touch unlink \
36   cat cksum comm csplit cut expand fmt fold head join groups md5sum \
37   nl od paste pr ptx sha1sum sha224sum sha256sum sha384sum sha512sum \
38   shuf sort split sum tac tail tr tsort unexpand uniq wc \
39   basename date dirname echo env expr factor false \
40   id kill logname pathchk printenv printf pwd \
41   runcon seq sleep tee \
42   test timeout true truncate tty whoami yes \
43   base64
44
45 bin_PROGRAMS = $(OPTIONAL_BIN_PROGS)
46
47 noinst_PROGRAMS = setuidgid
48
49 noinst_HEADERS = \
50   chown-core.h \
51   copy.h \
52   cp-hash.h \
53   dircolors.h \
54   fs.h \
55   group-list.h \
56   ls.h \
57   operand2sig.h \
58   prog-fprintf.h \
59   remove.h \
60   system.h \
61   wheel-size.h \
62   wheel.h \
63   uname.h
64
65 EXTRA_DIST = dcgen dircolors.hin tac-pipe.c \
66   wheel-gen.pl extract-magic c99-to-c89.diff
67 BUILT_SOURCES =
68 CLEANFILES = $(SCRIPTS) su
69
70 AM_CPPFLAGS = -I$(top_srcdir)/lib
71
72 # Sometimes, the expansion of $(LIBINTL) includes -lc which may
73 # include modules defining variables like `optind', so libcoreutils.a
74 # must precede $(LIBINTL) in order to ensure we use GNU getopt.
75 # But libcoreutils.a must also follow $(LIBINTL), since libintl uses
76 # replacement functions defined in libcoreutils.a.
77 LDADD = ../lib/libcoreutils.a $(LIBINTL) ../lib/libcoreutils.a
78
79 cat_LDADD = $(LDADD)
80 df_LDADD = $(LDADD)
81 du_LDADD = $(LDADD)
82 ptx_LDADD = $(LDADD)
83 split_LDADD = $(LDADD)
84 timeout_LDADD = $(LDADD)
85 truncate_LDADD = $(LDADD)
86
87 # for eaccess in lib/euidaccess.c.
88 chcon_LDADD = $(LDADD) $(LIB_SELINUX)
89 cp_LDADD = $(LDADD) $(LIB_EACCESS) $(LIB_SELINUX)
90 ginstall_LDADD = $(LDADD) $(LIB_EACCESS) $(LIB_SELINUX)
91 mkdir_LDADD = $(LDADD) $(LIB_SELINUX)
92 mkfifo_LDADD = $(LDADD) $(LIB_SELINUX)
93 mknod_LDADD = $(LDADD) $(LIB_SELINUX)
94 mv_LDADD = $(LDADD) $(LIB_EACCESS) $(LIB_SELINUX)
95 runcon_LDADD = $(LDADD) $(LIB_SELINUX)
96 pathchk_LDADD = $(LDADD) $(LIB_EACCESS)
97 rm_LDADD = $(LDADD) $(LIB_EACCESS)
98 test_LDADD = $(LDADD) $(LIB_EACCESS)
99 # This is for the '[' program.  Automake transliterates '[' to '_'.
100 __LDADD = $(LDADD) $(LIB_EACCESS)
101
102 # for clock_gettime and fdatasync
103 dd_LDADD = $(LDADD) $(LIB_GETHRXTIME) $(LIB_FDATASYNC)
104 dir_LDADD = $(LDADD) $(LIB_CLOCK_GETTIME) $(LIB_SELINUX) $(LIB_CAP)
105 id_LDADD = $(LDADD) $(LIB_SELINUX)
106 ls_LDADD = $(LDADD) $(LIB_CLOCK_GETTIME) $(LIB_SELINUX) $(LIB_CAP)
107 mktemp_LDADD = $(LDADD) $(LIB_GETHRXTIME)
108 pr_LDADD = $(LDADD) $(LIB_CLOCK_GETTIME)
109 shred_LDADD = $(LDADD) $(LIB_GETHRXTIME) $(LIB_FDATASYNC)
110 shuf_LDADD = $(LDADD) $(LIB_GETHRXTIME)
111 tac_LDADD = $(LDADD) $(LIB_CLOCK_GETTIME)
112 vdir_LDADD = $(LDADD) $(LIB_CLOCK_GETTIME) $(LIB_SELINUX) $(LIB_CAP)
113
114 ## If necessary, add -lm to resolve use of pow in lib/strtod.c.
115 sort_LDADD = $(LDADD) $(POW_LIB) $(LIB_GETHRXTIME)
116
117 # for get_date and gettime
118 date_LDADD = $(LDADD) $(LIB_CLOCK_GETTIME)
119 touch_LDADD = $(LDADD) $(LIB_CLOCK_GETTIME)
120
121 # If necessary, add -lm to resolve use of pow in lib/strtod.c.
122 # If necessary, add -liconv to resolve use of iconv in lib/unicodeio.c.
123 printf_LDADD = $(LDADD) $(POW_LIB) $(LIBICONV)
124
125 # If necessary, add -lm to resolve use of pow in lib/strtod.c.
126 seq_LDADD = $(LDADD) $(POW_LIB)
127
128 # If necessary, add libraries to resolve the `pow' reference in lib/strtod.c
129 # and the `nanosleep' reference in lib/xnanosleep.c.
130 nanosec_libs = $(LDADD) $(POW_LIB) $(LIB_NANOSLEEP)
131
132 # for various GMP functions
133 expr_LDADD = $(LDADD) $(LIB_GMP)
134
135 # for various GMP functions
136 factor_LDADD = $(LDADD) $(LIB_GMP)
137
138 sleep_LDADD = $(nanosec_libs)
139 tail_LDADD = $(nanosec_libs)
140
141 # If necessary, add -lm to resolve use of pow in lib/strtod.c.
142 uptime_LDADD = $(LDADD) $(POW_LIB) $(GETLOADAVG_LIBS)
143
144 su_LDADD = $(LDADD) $(LIB_CRYPT)
145
146 dir_LDADD += $(LIB_ACL)
147 ls_LDADD += $(LIB_ACL)
148 vdir_LDADD += $(LIB_ACL)
149 cp_LDADD += $(LIB_ACL)
150 mv_LDADD += $(LIB_ACL)
151 ginstall_LDADD += $(LIB_ACL)
152
153 stat_LDADD = $(LDADD) $(LIB_SELINUX)
154
155 # Append $(LIBICONV) to each program that uses proper_name_utf8.
156 cat_LDADD += $(LIBICONV)
157 cp_LDADD += $(LIBICONV)
158 df_LDADD += $(LIBICONV)
159 du_LDADD += $(LIBICONV)
160 ptx_LDADD += $(LIBICONV)
161 split_LDADD += $(LIBICONV)
162 timeout_LDADD += $(LIBICONV)
163 truncate_LDADD += $(LIBICONV)
164
165 $(PROGRAMS): ../lib/libcoreutils.a
166
167 # Get the release year from ../lib/version-etc.c.
168 RELEASE_YEAR = \
169   `sed -n '/.*COPYRIGHT_YEAR = \([0-9][0-9][0-9][0-9]\) };/s//\1/p' \
170     $(top_srcdir)/lib/version-etc.c`
171
172 all-local: su$(EXEEXT)
173
174 installed_su = $(DESTDIR)$(bindir)/`echo su|sed '$(transform)'`
175
176 setuid_root_mode = a=rx,u+s
177
178 install_su =                                            \
179   if test "$(INSTALL_SU)" = yes; then                   \
180     p=su;                                               \
181     echo " $(INSTALL_PROGRAM) $$p $(installed_su)";     \
182     $(INSTALL_PROGRAM) $$p $(installed_su);             \
183     echo " chown root $(installed_su)";                 \
184     chown root $(installed_su);                         \
185     echo " chmod $(setuid_root_mode) $(installed_su)";  \
186     chmod $(setuid_root_mode) $(installed_su);          \
187   else                                                  \
188     :;                                                  \
189   fi
190
191 install-root: su$(EXEEXT)
192         @$(install_su)
193
194 install-exec-hook: su$(EXEEXT)
195         @if test "$(INSTALL_SU)" = yes; then                    \
196           TMPFILE=$(DESTDIR)$(bindir)/.su-$$$$;                 \
197           rm -f $$TMPFILE;                                      \
198           echo > $$TMPFILE;                                     \
199 ## See if we can create a setuid root executable in $(bindir).
200 ## If not, then don't even try to install su.
201           can_create_suid_root_executable=no;                   \
202           chown root $$TMPFILE > /dev/null 2>&1                 \
203             && chmod $(setuid_root_mode) $$TMPFILE > /dev/null 2>&1 \
204             && can_create_suid_root_executable=yes;             \
205           rm -f $$TMPFILE;                                      \
206           if test $$can_create_suid_root_executable = yes; then \
207             $(install_su);                                      \
208           else                                                  \
209             echo "WARNING: insufficient access; not installing su"; \
210             echo "NOTE: to install su, run 'make install-root' as root"; \
211             rm -f $(installed_su);                              \
212           fi;                                                   \
213         else :;                                                 \
214         fi
215
216 uninstall-local:
217 # Remove su only if it's one we installed.
218         @if test "$(INSTALL_SU)" = yes; then                    \
219           if grep '$(PACKAGE_NAME)' $(installed_su) > /dev/null 2>&1; then \
220             echo "  rm -f $(installed_su)"; \
221             rm -f $(installed_su); \
222           else :; \
223           fi; \
224         fi
225
226 copy_sources = copy.c cp-hash.c
227
228 # Use `ginstall' in the definition of PROGRAMS and in dependencies to avoid
229 # confusion with the `install' target.  The install rule transforms `ginstall'
230 # to install before applying any user-specified name transformations.
231
232 transform = s/ginstall/install/; $(program_transform_name)
233 ginstall_SOURCES = install.c prog-fprintf.c $(copy_sources)
234
235 # This is for the '[' program.  Automake transliterates '[' to '_'.
236 __SOURCES = lbracket.c
237
238 cp_SOURCES = cp.c $(copy_sources)
239 dir_SOURCES = ls.c ls-dir.c
240 vdir_SOURCES = ls.c ls-vdir.c
241 id_SOURCES = id.c group-list.c
242 groups_SOURCES = groups.c group-list.c
243 ln_SOURCES = ln.c
244 ls_SOURCES = ls.c ls-ls.c
245 chown_SOURCES = chown.c chown-core.c
246 chgrp_SOURCES = chgrp.c chown-core.c
247 kill_SOURCES = kill.c operand2sig.c
248 timeout_SOURCES = timeout.c operand2sig.c
249
250 mv_SOURCES = mv.c remove.c $(copy_sources)
251 rm_SOURCES = rm.c remove.c
252
253 mkdir_SOURCES = mkdir.c prog-fprintf.c
254 rmdir_SOURCES = rmdir.c prog-fprintf.c
255
256 uname_SOURCES = uname.c uname-uname.c
257 arch_SOURCES = uname.c uname-arch.c
258
259 md5sum_SOURCES = md5sum.c
260 md5sum_CPPFLAGS = -DHASH_ALGO_MD5=1 $(AM_CPPFLAGS)
261 sha1sum_SOURCES = md5sum.c
262 sha1sum_CPPFLAGS = -DHASH_ALGO_SHA1=1 $(AM_CPPFLAGS)
263 sha224sum_SOURCES = md5sum.c
264 sha224sum_CPPFLAGS = -DHASH_ALGO_SHA224=1 $(AM_CPPFLAGS)
265 sha256sum_SOURCES = md5sum.c
266 sha256sum_CPPFLAGS = -DHASH_ALGO_SHA256=1 $(AM_CPPFLAGS)
267 sha384sum_SOURCES = md5sum.c
268 sha384sum_CPPFLAGS = -DHASH_ALGO_SHA384=1 $(AM_CPPFLAGS)
269 sha512sum_SOURCES = md5sum.c
270 sha512sum_CPPFLAGS = -DHASH_ALGO_SHA512=1 $(AM_CPPFLAGS)
271
272 ginstall_CPPFLAGS = -DENABLE_MATCHPATHCON=1 $(AM_CPPFLAGS)
273
274 editpl = sed -e 's,@''PERL''@,$(PERL),g'
275
276 BUILT_SOURCES += dircolors.h
277 dircolors.h: dcgen dircolors.hin
278         @rm -f $@ $@-t
279         $(PERL) -w -- $(srcdir)/dcgen $(srcdir)/dircolors.hin > $@-t
280         @chmod a-w $@-t
281         mv $@-t $@
282
283 wheel_size = 5
284
285 BUILT_SOURCES += wheel-size.h
286 wheel-size.h: Makefile.am
287         @rm -f $@ $@-t
288         echo '#define WHEEL_SIZE $(wheel_size)' > $@-t
289         @chmod a-w $@-t
290         mv $@-t $@
291
292 BUILT_SOURCES += wheel.h
293 wheel.h: wheel-gen.pl Makefile.am
294         @rm -f $@ $@-t
295         $(srcdir)/wheel-gen.pl $(wheel_size) > $@-t
296         @chmod a-w $@-t
297         mv $@-t $@
298
299 # false exits nonzero even with --help or --version.
300 # test doesn't support --help or --version.
301 # Tell automake to exempt then from that installcheck test.
302 AM_INSTALLCHECK_STD_OPTIONS_EXEMPT = false test
303
304 BUILT_SOURCES += fs.h
305 fs.h: stat.c extract-magic
306         rm -f $@
307         $(PERL) $(srcdir)/extract-magic $(srcdir)/stat.c > $@t
308         @chmod a-w $@t
309         mv $@t $@
310
311 MAINTAINERCLEANFILES = $(BUILT_SOURCES)
312
313 # Sort in traditional ASCII order, regardless of the current locale;
314 # otherwise we may get into trouble with distinct strings that the
315 # current locale considers to be equal.
316 ASSORT = LC_ALL=C sort
317
318 all_programs = \
319     $(bin_PROGRAMS) \
320     $(bin_SCRIPTS) \
321   $(EXTRA_PROGRAMS)
322
323 built_programs.list:
324         @echo $(bin_PROGRAMS) $(bin_SCRIPTS) | tr ' ' '\n' \
325           | sed -e 's,$(EXEEXT)$$,,' | $(ASSORT) -u | tr '\n' ' '
326
327 all_programs.list:
328         @echo $(all_programs) | tr ' ' '\n' | sed -e 's,$(EXEEXT)$$,,' \
329           | $(ASSORT) -u
330
331 pm = progs-makefile
332 pr = progs-readme
333 # Ensure that the list of programs in README matches the list
334 # of programs we can build.
335 check: check-README check-misc check-duplicate-no-install
336 .PHONY: check-README
337 check-README:
338         rm -rf $(pr) $(pm)
339         echo $(all_programs) \
340          | tr -s ' ' '\n' | sed -e 's,$(EXEEXT)$$,,;s/ginstall/install/' \
341          | $(ASSORT) -u > $(pm) && \
342         sed -n '/^The programs .* are:/,/^[a-zA-Z]/p' $(top_srcdir)/README \
343           | sed -n '/^   */s///p' | tr -s ' ' '\n' > $(pr)
344         diff $(pm) $(pr) && rm -rf $(pr) $(pm)
345
346 # Ensure that a by-default-not-installed program (listed in
347 # $(no_install__progs) is not also listed in $(EXTRA_PROGRAMS), because
348 # if that were to happen, it *would* be installed by default.
349 .PHONY: check-duplicate-no-install
350 check-duplicate-no-install: tr
351         test -z "`echo '$(EXTRA_PROGRAMS)'| ./tr ' ' '\n' | uniq -d`"
352
353 # Ensure that the list of programs and author names is accurate.
354 au_dotdot = authors-dotdot
355 au_actual = authors-actual
356 .PHONY: check-AUTHORS
357 check-AUTHORS: $(all_programs)
358         rm -f $(au_actual) $(au_dotdot)
359         for i in `ls $(all_programs) | sed -e 's,$(EXEEXT)$$,,' \
360             | $(ASSORT) -u`; do                         \
361           test "$$i" = '[' && continue;                 \
362           exe=$$i;                                      \
363           if test "$$i" = install; then                 \
364             exe=ginstall;                               \
365           elif test "$$i" = test; then                  \
366             exe='[';                                    \
367           fi;                                           \
368           LC_ALL=en_US.UTF-8 ./$$exe --version                  \
369             | perl -0 -pi -e 's/,\n/, /gm'              \
370             |sed -n '/Written by /{ s//'"$$i"': /; s/,* and /, /; s/\.$$//; p; }'; \
371         done > $(au_actual)
372         sed -n '/^[^ ][^ ]*:/p' $(top_srcdir)/AUTHORS > $(au_dotdot)
373         diff $(au_actual) $(au_dotdot) && rm -f $(au_actual) $(au_dotdot)
374
375 # Make sure we don't define any S_IS* macros in src/*.c files.
376 # Not a big deal, but they're already defined via system.h.
377 #
378 # Also make sure we don't use st_blocks.  Use ST_NBLOCKS instead.
379 # This is a bit of a kludge, since it prevents use of the string
380 # even in comments, but for now it does the job with no false positives.
381 .PHONY: check-misc
382 check-misc:
383         cd $(srcdir); grep '^# *define  *S_IS' $(SOURCES) && exit 1 || :
384         cd $(srcdir); grep st_blocks $(SOURCES) && exit 1 || :
385         cd $(srcdir); grep '^# *define .*defined' $(SOURCES) && exit 1 || :
386
387 # Extract the list of authors from each file.
388 sed_filter = s/^ *//;s/N_ (//;s/^"//;s/")*$$//
389 # Sometimes the string is on the same line as the #define...
390 s1 = '/^\#define AUTHORS \([^\\]\)/{;s//\1/;$(sed_filter);p;q;}'
391 # Sometimes the string is on the backslash-continued line after the #define.
392 s2 = '/^\#define AUTHORS \\\\/{;n;$(sed_filter);p;q;}'
393 # FIXME: handle *.sh;  and use $(all_programs), not $(SOURCES)
394 ../AUTHORS: $(SOURCES)
395         rm -f $@-t
396         (                                               \
397           set -e;                                       \
398           echo "Here are the names of the programs in this package,";   \
399           echo "each followed by the name(s) of its author(s).";        \
400           echo;                                         \
401           for i in $(SOURCES); do                       \
402             a=`sed -n $(s1) $$i`;                       \
403             test "$$a" && :                             \
404               || a=`sed -n $(s2) $$i`;                  \
405             if test "$$a"; then                         \
406               prog=`echo $$i|sed 's/\.c$$//'`;          \
407               echo "$$prog: $$a";                       \
408             fi;                                         \
409           done | $(ASSORT) -u ) > $@-t
410         chmod a-w $@-t
411         mv $@-t $@
412
413 # The following rule is not designed to be portable,
414 # and relies on tools that not everyone has.
415
416 # Most functions in src/*.c should have static scope.
417 # Any that don't must be marked with `extern', but `main'
418 # and `usage' are exceptions.  They're always extern, but
419 # don't need to be marked.
420 #
421 # The second nm|grep checks for file-scope variables with `extern' scope.
422 .PHONY: sc_tight_scope
423 sc_tight_scope: $(all_programs)
424         @t=exceptions-$$$$;                                             \
425         trap "s=$$?; rm -f $$t; exit $$s" 0 1 2 13 15;                  \
426         ( printf 'main\nusage\n';                                       \
427           grep -h -A1 '^extern .*[^;]$$' $(SOURCES)                     \
428             | grep -vE '^(extern |--)' | sed 's/ .*//';                 \
429           perl -ne '/^extern \S+ (\S*) \(/ and print "$$1\n"'           \
430             $(noinst_HEADERS);                                          \
431         ) | $(ASSORT) -u | sed 's/^/^/;s/$$/$$/' > $$t;                 \
432         nm -e *.$(OBJEXT)                                               \
433             | sed -n 's/.* T //p'                                       \
434             | grep -Ev -f $$t &&                                        \
435           { echo 'the above functions should have static scope' 1>&2;   \
436             exit 1; } || : ;                                            \
437         ( printf '^program_name$$\n';                                   \
438           sed -n 's/^extern int \([^ ][^ ]*\);$$/^\1$$/p'               \
439             $(noinst_HEADERS) ) > $$t;                                  \
440         nm -e *.$(OBJEXT)                                               \
441             | sed -n 's/.* [BD] //p'                                    \
442             | grep -Ev -f $$t &&                                        \
443           { echo 'the above variables should have static scope' 1>&2;   \
444             exit 1; } || :
445
446 # Use the just-built ./ginstall, when not cross-compiling.
447 # Override automake's install-one-at-a-time rule, when possible.
448 install-exec-am:
449         @(./ginstall --version) > /dev/null 2>&1                \
450           && install=./ginstall                                 \
451           || install='$(INSTALL_PROGRAM)';                      \
452         case '$(program_transform_name):$(EXEEXT)' in           \
453           's,x,x,:') cu=cu-;; *) cu= ;; esac;                   \
454         $(MAKE) $(AM_MAKEFLAGS) binPROGRAMS_INSTALL="$$install" \
455           $${cu}install-binPROGRAMS
456         @$(NORMAL_INSTALL)
457         $(MAKE) $(AM_MAKEFLAGS) install-exec-hook
458
459 # The following rule is used only when --program-transform-name
460 # has not been used and there is no .exe "extension".
461 # Override the automake-generated rule so that we can install
462 # all binaries with a single install command.  However, ...
463 # install ginstall and [ separately.  "ginstall" because we rename
464 # it to "install", and "[" because using it unquoted will cause a
465 # syntax error with some shells.  Be careful to install each of these
466 # exceptions only if it is to be installed (i.e., not excluded via
467 # --enable-no-install-program=PROG_LIST.
468 filtered_PROGS = \
469   `echo "$(bin_PROGRAMS)" | sed 's/ *\<ginstall\> */ /;s/ *\[ */ /'`
470 d_bindir = $(DESTDIR)$(bindir)
471 .PHONY: cu-install-binPROGRAMS
472 cu-install-binPROGRAMS: $(bin_PROGRAMS)
473         $(NORMAL_INSTALL)
474         test -z "$(bindir)" || $(MKDIR_P) "$(d_bindir)"
475         test x = 'x$(bin_PROGRAMS)' && exit || :
476         case '$(bin_PROGRAMS)' in *\[*) \
477           echo "$(binPROGRAMS_INSTALL) '[' '$(d_bindir)/['"; \
478           $(binPROGRAMS_INSTALL) '[' '$(d_bindir)/[';; esac
479         case '$(bin_PROGRAMS)' in *ginstall*) \
480           echo "$(binPROGRAMS_INSTALL) ginstall '$(d_bindir)/install'";\
481           $(binPROGRAMS_INSTALL) ginstall '$(d_bindir)/install';; esac
482         $(binPROGRAMS_INSTALL) $(filtered_PROGS) '$(d_bindir)'