install, rmdir: write --verbose output to stdout, not to stderr.
[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 true 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   prog-fprintf.h \
58   remove.h \
59   system.h \
60   wheel-size.h \
61   wheel.h \
62   uname.h
63
64 EXTRA_DIST = dcgen dircolors.hin tac-pipe.c \
65   wheel-gen.pl extract-magic c99-to-c89.diff
66 BUILT_SOURCES =
67 CLEANFILES = $(SCRIPTS) su
68
69 AM_CPPFLAGS = -I$(top_srcdir)/lib
70
71 # Sometimes, the expansion of $(LIBINTL) includes -lc which may
72 # include modules defining variables like `optind', so libcoreutils.a
73 # must precede $(LIBINTL) in order to ensure we use GNU getopt.
74 # But libcoreutils.a must also follow $(LIBINTL), since libintl uses
75 # replacement functions defined in libcoreutils.a.
76 LDADD = ../lib/libcoreutils.a $(LIBINTL) ../lib/libcoreutils.a
77
78 # for eaccess in lib/euidaccess.c.
79 chcon_LDADD = $(LDADD) $(LIB_SELINUX)
80 cp_LDADD = $(LDADD) $(LIB_EACCESS) $(LIB_SELINUX)
81 ginstall_LDADD = $(LDADD) $(LIB_EACCESS) $(LIB_SELINUX)
82 mkdir_LDADD = $(LDADD) $(LIB_SELINUX)
83 mkfifo_LDADD = $(LDADD) $(LIB_SELINUX)
84 mknod_LDADD = $(LDADD) $(LIB_SELINUX)
85 mv_LDADD = $(LDADD) $(LIB_EACCESS) $(LIB_SELINUX)
86 runcon_LDADD = $(LDADD) $(LIB_SELINUX)
87 pathchk_LDADD = $(LDADD) $(LIB_EACCESS)
88 rm_LDADD = $(LDADD) $(LIB_EACCESS)
89 test_LDADD = $(LDADD) $(LIB_EACCESS)
90 # This is for the '[' program.  Automake transliterates '[' to '_'.
91 __LDADD = $(LDADD) $(LIB_EACCESS)
92
93 # for clock_gettime and fdatasync
94 dd_LDADD = $(LDADD) $(LIB_GETHRXTIME) $(LIB_FDATASYNC)
95 dir_LDADD = $(LDADD) $(LIB_CLOCK_GETTIME) $(LIB_SELINUX)
96 id_LDADD = $(LDADD) $(LIB_SELINUX)
97 ls_LDADD = $(LDADD) $(LIB_CLOCK_GETTIME) $(LIB_SELINUX)
98 pr_LDADD = $(LDADD) $(LIB_CLOCK_GETTIME)
99 shred_LDADD = $(LDADD) $(LIB_GETHRXTIME) $(LIB_FDATASYNC)
100 shuf_LDADD = $(LDADD) $(LIB_GETHRXTIME)
101 mktemp_LDADD = $(LDADD) $(LIB_GETHRXTIME)
102 vdir_LDADD = $(LDADD) $(LIB_CLOCK_GETTIME) $(LIB_SELINUX)
103
104 ## If necessary, add -lm to resolve use of pow in lib/strtod.c.
105 sort_LDADD = $(LDADD) $(POW_LIB) $(LIB_GETHRXTIME)
106
107 # for get_date and gettime
108 date_LDADD = $(LDADD) $(LIB_CLOCK_GETTIME)
109 touch_LDADD = $(LDADD) $(LIB_CLOCK_GETTIME)
110
111 # If necessary, add -lm to resolve use of pow in lib/strtod.c.
112 # If necessary, add -liconv to resolve use of iconv in lib/unicodeio.c.
113 printf_LDADD = $(LDADD) $(POW_LIB) $(LIBICONV)
114
115 # If necessary, add -lm to resolve use of pow in lib/strtod.c.
116 seq_LDADD = $(LDADD) $(POW_LIB)
117
118 # If necessary, add libraries to resolve the `pow' reference in lib/strtod.c
119 # and the `nanosleep' reference in lib/xnanosleep.c.
120 nanosec_libs = $(LDADD) $(POW_LIB) $(LIB_NANOSLEEP)
121
122 sleep_LDADD = $(nanosec_libs)
123 tail_LDADD = $(nanosec_libs)
124
125 # If necessary, add -lm to resolve use of pow in lib/strtod.c.
126 uptime_LDADD = $(LDADD) $(POW_LIB) $(GETLOADAVG_LIBS)
127
128 su_LDADD = $(LDADD) $(LIB_CRYPT)
129
130 dir_LDADD += $(LIB_ACL)
131 ls_LDADD += $(LIB_ACL)
132 vdir_LDADD += $(LIB_ACL)
133 cp_LDADD += $(LIB_ACL)
134 mv_LDADD += $(LIB_ACL)
135 ginstall_LDADD += $(LIB_ACL)
136
137 stat_LDADD = $(LDADD) $(LIB_SELINUX)
138
139 $(PROGRAMS): ../lib/libcoreutils.a
140
141 # Get the release year from ../lib/version-etc.c.
142 RELEASE_YEAR = \
143   `sed -n '/.*COPYRIGHT_YEAR = \([0-9][0-9][0-9][0-9]\) };/s//\1/p' \
144     $(top_srcdir)/lib/version-etc.c`
145
146 all-local: su$(EXEEXT)
147
148 installed_su = $(DESTDIR)$(bindir)/`echo su|sed '$(transform)'`
149
150 setuid_root_mode = a=rx,u+s
151
152 install_su =                                            \
153   if test "$(INSTALL_SU)" = yes; then                   \
154     p=su;                                               \
155     echo " $(INSTALL_PROGRAM) $$p $(installed_su)";     \
156     $(INSTALL_PROGRAM) $$p $(installed_su);             \
157     echo " chown root $(installed_su)";                 \
158     chown root $(installed_su);                         \
159     echo " chmod $(setuid_root_mode) $(installed_su)";  \
160     chmod $(setuid_root_mode) $(installed_su);          \
161   else                                                  \
162     :;                                                  \
163   fi
164
165 install-root: su$(EXEEXT)
166         @$(install_su)
167
168 install-exec-hook: su$(EXEEXT)
169         @if test "$(INSTALL_SU)" = yes; then                    \
170           TMPFILE=$(DESTDIR)$(bindir)/.su-$$$$;                 \
171           rm -f $$TMPFILE;                                      \
172           echo > $$TMPFILE;                                     \
173 ## See if we can create a setuid root executable in $(bindir).
174 ## If not, then don't even try to install su.
175           can_create_suid_root_executable=no;                   \
176           chown root $$TMPFILE > /dev/null 2>&1                 \
177             && chmod $(setuid_root_mode) $$TMPFILE > /dev/null 2>&1 \
178             && can_create_suid_root_executable=yes;             \
179           rm -f $$TMPFILE;                                      \
180           if test $$can_create_suid_root_executable = yes; then \
181             $(install_su);                                      \
182           else                                                  \
183             echo "WARNING: insufficient access; not installing su"; \
184             echo "NOTE: to install su, run 'make install-root' as root"; \
185             rm -f $(installed_su);                              \
186           fi;                                                   \
187         else :;                                                 \
188         fi
189
190 uninstall-local:
191 # Remove su only if it's one we installed.
192         @if test "$(INSTALL_SU)" = yes; then                    \
193           if grep '$(PACKAGE_NAME)' $(installed_su) > /dev/null 2>&1; then \
194             echo "  rm -f $(installed_su)"; \
195             rm -f $(installed_su); \
196           else :; \
197           fi; \
198         fi
199
200 copy_sources = copy.c cp-hash.c
201
202 # Use `ginstall' in the definition of PROGRAMS and in dependencies to avoid
203 # confusion with the `install' target.  The install rule transforms `ginstall'
204 # to install before applying any user-specified name transformations.
205
206 transform = s/ginstall/install/; @program_transform_name@
207 ginstall_SOURCES = install.c prog-fprintf.c $(copy_sources)
208
209 # This is for the '[' program.  Automake transliterates '[' to '_'.
210 __SOURCES = lbracket.c
211
212 cp_SOURCES = cp.c $(copy_sources)
213 dir_SOURCES = ls.c ls-dir.c
214 vdir_SOURCES = ls.c ls-vdir.c
215 id_SOURCES = id.c group-list.c
216 groups_SOURCES = groups.c group-list.c
217 ln_SOURCES = ln.c
218 ls_SOURCES = ls.c ls-ls.c
219 chown_SOURCES = chown.c chown-core.c
220 chgrp_SOURCES = chgrp.c chown-core.c
221
222 mv_SOURCES = mv.c remove.c $(copy_sources)
223 rm_SOURCES = rm.c remove.c
224
225 mkdir_SOURCES = mkdir.c prog-fprintf.c
226 rmdir_SOURCES = rmdir.c prog-fprintf.c
227
228 uname_SOURCES = uname.c uname-uname.c
229 arch_SOURCES = uname.c uname-arch.c
230
231 md5sum_SOURCES = md5sum.c
232 md5sum_CPPFLAGS = -DHASH_ALGO_MD5=1 $(AM_CPPFLAGS)
233 sha1sum_SOURCES = md5sum.c
234 sha1sum_CPPFLAGS = -DHASH_ALGO_SHA1=1 $(AM_CPPFLAGS)
235 sha224sum_SOURCES = md5sum.c
236 sha224sum_CPPFLAGS = -DHASH_ALGO_SHA224=1 $(AM_CPPFLAGS)
237 sha256sum_SOURCES = md5sum.c
238 sha256sum_CPPFLAGS = -DHASH_ALGO_SHA256=1 $(AM_CPPFLAGS)
239 sha384sum_SOURCES = md5sum.c
240 sha384sum_CPPFLAGS = -DHASH_ALGO_SHA384=1 $(AM_CPPFLAGS)
241 sha512sum_SOURCES = md5sum.c
242 sha512sum_CPPFLAGS = -DHASH_ALGO_SHA512=1 $(AM_CPPFLAGS)
243
244 editpl = sed -e 's,@''PERL''@,$(PERL),g'
245
246 BUILT_SOURCES += dircolors.h
247 dircolors.h: dcgen dircolors.hin
248         @rm -f $@ $@-t
249         $(PERL) -w -- $(srcdir)/dcgen $(srcdir)/dircolors.hin > $@-t
250         @chmod a-w $@-t
251         mv $@-t $@
252
253 wheel_size = 5
254
255 BUILT_SOURCES += wheel-size.h
256 wheel-size.h: Makefile.am
257         @rm -f $@ $@-t
258         echo '#define WHEEL_SIZE $(wheel_size)' > $@-t
259         @chmod a-w $@-t
260         mv $@-t $@
261
262 BUILT_SOURCES += wheel.h
263 wheel.h: wheel-gen.pl Makefile.am
264         @rm -f $@ $@-t
265         $(srcdir)/wheel-gen.pl $(wheel_size) > $@-t
266         @chmod a-w $@-t
267         mv $@-t $@
268
269 # false exits nonzero even with --help or --version.
270 # test doesn't support --help or --version.
271 # Tell automake to exempt then from that installcheck test.
272 AM_INSTALLCHECK_STD_OPTIONS_EXEMPT = false test
273
274 BUILT_SOURCES += fs.h
275 fs.h: stat.c extract-magic
276         rm -f $@
277         $(PERL) $(srcdir)/extract-magic $(srcdir)/stat.c > $@t
278         @chmod a-w $@t
279         mv $@t $@
280
281 MAINTAINERCLEANFILES = $(BUILT_SOURCES)
282
283 # Sort in traditional ASCII order, regardless of the current locale;
284 # otherwise we may get into trouble with distinct strings that the
285 # current locale considers to be equal.
286 ASSORT = LC_ALL=C sort
287
288 all_programs = \
289     $(bin_PROGRAMS) \
290     $(bin_SCRIPTS) \
291   $(EXTRA_PROGRAMS)
292
293 built_programs.list:
294         @echo $(bin_PROGRAMS) $(bin_SCRIPTS) | tr ' ' '\n' \
295           | sed -e 's,$(EXEEXT)$$,,' | $(ASSORT) -u | tr '\n' ' '
296
297 all_programs.list:
298         @echo $(all_programs) | tr ' ' '\n' | sed -e 's,$(EXEEXT)$$,,' \
299           | $(ASSORT) -u
300
301 pm = progs-makefile
302 pr = progs-readme
303 # Ensure that the list of programs in README matches the list
304 # of programs we can build.
305 check: check-README check-misc check-duplicate-no-install
306 .PHONY: check-README
307 check-README:
308         rm -rf $(pr) $(pm)
309         echo $(all_programs) \
310          | tr -s ' ' '\n' | sed -e 's,$(EXEEXT)$$,,;s/ginstall/install/' \
311          | $(ASSORT) -u > $(pm) && \
312         sed -n '/^The programs .* are:/,/^[a-zA-Z]/p' $(top_srcdir)/README \
313           | sed -n '/^   */s///p' | tr -s ' ' '\n' > $(pr)
314         diff $(pm) $(pr) && rm -rf $(pr) $(pm)
315
316 # Ensure that a by-default-not-installed program (listed in
317 # $(no_install__progs) is not also listed in $(EXTRA_PROGRAMS), because
318 # if that were to happen, it *would* be installed by default.
319 .PHONY: check-duplicate-no-install
320 check-duplicate-no-install: tr
321         test -z "`echo '$(EXTRA_PROGRAMS)'| ./tr ' ' '\n' | uniq -d`"
322
323 # Ensure that the list of programs and author names is accurate.
324 au_dotdot = authors-dotdot
325 au_actual = authors-actual
326 .PHONY: check-AUTHORS
327 check-AUTHORS: $(all_programs)
328         rm -f $(au_actual) $(au_dotdot)
329         for i in `ls $(all_programs) | sed -e 's,$(EXEEXT)$$,,' \
330             | $(ASSORT) -u`; do                         \
331           test "$$i" = '[' && continue;                 \
332           exe=$$i;                                      \
333           if test "$$i" = install; then                 \
334             exe=ginstall;                               \
335           elif test "$$i" = test; then                  \
336             exe='[';                                    \
337           fi;                                           \
338           ./$$exe --version                             \
339             |sed -n '/Written by /{ s//'"$$i"': /; s/,* and /, /; s/\.$$//; p; }'; \
340         done > $(au_actual)
341         sed -n '/:/p' $(top_srcdir)/AUTHORS > $(au_dotdot)
342         diff $(au_actual) $(au_dotdot) && rm -f $(au_actual) $(au_dotdot)
343
344 # Make sure we don't define any S_IS* macros in src/*.c files.
345 # Not a big deal, but they're already defined via system.h.
346 #
347 # Also make sure we don't use st_blocks.  Use ST_NBLOCKS instead.
348 # This is a bit of a kludge, since it prevents use of the string
349 # even in comments, but for now it does the job with no false positives.
350 .PHONY: check-misc
351 check-misc:
352         cd $(srcdir); grep '^# *define  *S_IS' $(SOURCES) && exit 1 || :
353         cd $(srcdir); grep st_blocks $(SOURCES) && exit 1 || :
354         cd $(srcdir); grep '^# *define .*defined' $(SOURCES) && exit 1 || :
355
356 # Extract the list of authors from each file.
357 sed_filter = s/^ *//;s/N_ (//;s/^"//;s/")*$$//
358 # Sometimes the string is on the same line as the #define...
359 s1 = '/^\#define AUTHORS \([^\\]\)/{;s//\1/;$(sed_filter);p;q;}'
360 # Sometimes the string is on the backslash-continued line after the #define.
361 s2 = '/^\#define AUTHORS \\\\/{;n;$(sed_filter);p;q;}'
362 # FIXME: handle *.sh;  and use $(all_programs), not $(SOURCES)
363 ../AUTHORS: $(SOURCES)
364         rm -f $@-t
365         (                                               \
366           set -e;                                       \
367           echo "Here are the names of the programs in this package,";   \
368           echo "each followed by the name(s) of its author(s).";        \
369           echo;                                         \
370           for i in $(SOURCES); do                       \
371             a=`sed -n $(s1) $$i`;                       \
372             test "$$a" && :                             \
373               || a=`sed -n $(s2) $$i`;                  \
374             if test "$$a"; then                         \
375               prog=`echo $$i|sed 's/\.c$$//'`;          \
376               echo "$$prog: $$a";                       \
377             fi;                                         \
378           done | $(ASSORT) -u ) > $@-t
379         chmod a-w $@-t
380         mv $@-t $@
381
382 # The following rule is not designed to be portable,
383 # and relies on tools that not everyone has.
384
385 # Most functions in src/*.c should have static scope.
386 # Any that don't must be marked with `extern', but `main'
387 # and `usage' are exceptions.  They're always extern, but
388 # don't need to be marked.
389 #
390 # The second nm|grep checks for file-scope variables with `extern' scope.
391 .PHONY: sc_tight_scope
392 sc_tight_scope: $(all_programs)
393         @t=exceptions-$$$$;                                             \
394         trap "s=$$?; rm -f $$t; exit $$s" 0 1 2 13 15;                  \
395         ( printf 'main\nusage\n';                                       \
396           grep -h -A1 '^extern .*[^;]$$' $(SOURCES)                     \
397             | grep -vE '^(extern |--)' | sed 's/ .*//';                 \
398           perl -ne '/^extern \S+ (\S*) \(/ and print "$$1\n"'           \
399             $(noinst_HEADERS);                                          \
400         ) | $(ASSORT) -u | sed 's/^/^/;s/$$/$$/' > $$t;                 \
401         nm -e *.$(OBJEXT)                                               \
402             | sed -n 's/.* T //p'                                       \
403             | grep -Ev -f $$t &&                                        \
404           { echo 'the above functions should have static scope' 1>&2;   \
405             exit 1; } || : ;                                            \
406         ( printf '^program_name$$\n';                                   \
407           sed -n 's/^extern int \([^ ][^ ]*\);$$/^\1$$/p'               \
408             $(noinst_HEADERS) ) > $$t;                                  \
409         nm -e *.$(OBJEXT)                                               \
410             | sed -n 's/.* [BD] //p'                                    \
411             | grep -Ev -f $$t &&                                        \
412           { echo 'the above variables should have static scope' 1>&2;   \
413             exit 1; } || :