* src/dd.c (flags): noatime and nofollow now depend on
[coreutils/bo.git] / src / Makefile.am
blob8c39ee02f4830069e0c1d2257edf9d437b627663
1 ## Process this file with automake to produce Makefile.in -*-Makefile-*-
3 ## Copyright (C) 1990, 1991, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
4 ## 2000, 2001, 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
6 ## This program is free software; you can redistribute it and/or modify
7 ## it under the terms of the GNU General Public License as published by
8 ## the Free Software Foundation; either version 2, or (at your option)
9 ## any later version.
11 ## This program is distributed in the hope that it will be useful,
12 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
13 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 ## GNU General Public License for more details.
16 ## You should have received a copy of the GNU General Public License
17 ## along with this program; if not, write to the Free Software Foundation,
18 ## Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 EXTRA_PROGRAMS = chroot df hostid nice pinky stty su uname uptime users who
22 bin_SCRIPTS = groups
23 bin_PROGRAMS = [ chgrp chown chmod cp dd dircolors du \
24   ginstall link ln dir vdir ls mkdir \
25   mkfifo mknod mv nohup readlink rm rmdir shred stat sync touch unlink \
26   cat cksum comm csplit cut expand fmt fold head join md5sum \
27   nl od paste pr ptx sha1sum sha224sum sha256sum sha384sum sha512sum \
28   shuf sort split sum tac tail tr tsort unexpand uniq wc \
29   basename date dirname echo env expr factor false \
30   hostname id kill logname pathchk printenv printf pwd seq sleep tee \
31   test true tty whoami yes \
32   base64 \
33   $(OPTIONAL_BIN_PROGS) $(DF_PROG)
35 noinst_PROGRAMS = setuidgid
37 noinst_HEADERS = \
38   chown-core.h \
39   copy.h \
40   cp-hash.h \
41   dircolors.h \
42   fs.h \
43   ls.h \
44   remove.h \
45   system.h \
46   wheel-size.h \
47   wheel.h
49 EXTRA_DIST = dcgen dircolors.hin tac-pipe.c \
50   groups.sh wheel-gen.pl extract-magic c99-to-c89.diff
51 BUILT_SOURCES =
52 CLEANFILES = $(SCRIPTS) su
54 AM_CPPFLAGS = -I$(top_srcdir)/lib
56 # Sometimes, the expansion of $(LIBINTL) includes -lc which may
57 # include modules defining variables like `optind', so libcoreutils.a
58 # must precede $(LIBINTL) in order to ensure we use GNU getopt.
59 # But libcoreutils.a must also follow $(LIBINTL), since libintl uses
60 # replacement functions defined in libcoreutils.a.
61 LDADD = ../lib/libcoreutils.a $(LIBINTL) ../lib/libcoreutils.a
63 # for eaccess in lib/euidaccess.c.
64 cp_LDADD = $(LDADD) $(LIB_EACCESS)
65 ginstall_LDADD = $(LDADD) $(LIB_EACCESS)
66 mv_LDADD = $(LDADD) $(LIB_EACCESS)
67 pathchk_LDADD = $(LDADD) $(LIB_EACCESS)
68 rm_LDADD = $(LDADD) $(LIB_EACCESS)
69 test_LDADD = $(LDADD) $(LIB_EACCESS)
70 # This is for the '[' program.  Automake transliterates '[' to '_'.
71 __LDADD = $(LDADD) $(LIB_EACCESS)
73 # for clock_gettime and fdatasync
74 dd_LDADD = $(LDADD) $(LIB_GETHRXTIME) $(LIB_FDATASYNC)
75 dir_LDADD = $(LDADD) $(LIB_CLOCK_GETTIME)
76 ls_LDADD = $(LDADD) $(LIB_CLOCK_GETTIME)
77 pr_LDADD = $(LDADD) $(LIB_CLOCK_GETTIME)
78 shred_LDADD = $(LDADD) $(LIB_GETHRXTIME) $(LIB_FDATASYNC)
79 shuf_LDADD = $(LDADD) $(LIB_GETHRXTIME)
80 vdir_LDADD = $(LDADD) $(LIB_CLOCK_GETTIME)
82 ## If necessary, add -lm to resolve use of pow in lib/strtod.c.
83 sort_LDADD = $(LDADD) $(POW_LIB) $(LIB_GETHRXTIME)
85 # for get_date and gettime
86 date_LDADD = $(LDADD) $(LIB_CLOCK_GETTIME)
87 touch_LDADD = $(LDADD) $(LIB_CLOCK_GETTIME)
89 # If necessary, add -lm to resolve use of pow in lib/strtod.c.
90 # If necessary, add -liconv to resolve use of iconv in lib/unicodeio.c.
91 printf_LDADD = $(LDADD) $(POW_LIB) $(LIBICONV)
93 # If necessary, add -lm to resolve use of pow in lib/strtod.c.
94 seq_LDADD = $(LDADD) $(POW_LIB)
96 # If necessary, add libraries to resolve the `pow' reference in lib/strtod.c
97 # and the `nanosleep' reference in lib/xnanosleep.c.
98 nanosec_libs = $(LDADD) $(POW_LIB) $(LIB_NANOSLEEP)
100 sleep_LDADD = $(nanosec_libs)
101 tail_LDADD = $(nanosec_libs)
103 # If necessary, add -lm to resolve use of pow in lib/strtod.c.
104 uptime_LDADD = $(LDADD) $(POW_LIB) $(GETLOADAVG_LIBS)
106 su_LDADD = $(LDADD) $(LIB_CRYPT)
108 dir_LDADD += $(LIB_ACL)
109 ls_LDADD += $(LIB_ACL)
110 vdir_LDADD += $(LIB_ACL)
111 cp_LDADD += $(LIB_ACL)
112 mv_LDADD += $(LIB_ACL)
113 ginstall_LDADD += $(LIB_ACL)
115 $(PROGRAMS): ../lib/libcoreutils.a
117 SUFFIXES = .sh
119 .sh:
120         rm -f $@ $@-t
121         sed \
122           -e 's!@''bindir''@!$(bindir)!' \
123           -e 's/@''GNU_PACKAGE''@/$(GNU_PACKAGE)/' \
124           -e 's/@''PACKAGE_BUGREPORT''@/$(PACKAGE_BUGREPORT)/' \
125           -e 's/@''VERSION''@/$(VERSION)/' $< > $@-t
126         chmod +x $@-t
127         mv $@-t $@
129 all-local: su$(EXEEXT)
131 installed_su = $(DESTDIR)$(bindir)/`echo su|sed '$(transform)'`
133 setuid_root_mode = a=rx,u+s
135 INSTALL_SU = \
136   p=su; \
137   echo " $(INSTALL_PROGRAM) $$p $(installed_su)"; \
138   $(INSTALL_PROGRAM) $$p $(installed_su); \
139   echo " chown root $(installed_su)"; \
140   chown root $(installed_su); \
141   echo " chmod $(setuid_root_mode) $(installed_su)"; \
142   chmod $(setuid_root_mode) $(installed_su)
144 install-root: su$(EXEEXT)
145         @$(INSTALL_SU)
147 install-exec-local: su$(EXEEXT)
148         @TMPFILE=$(DESTDIR)$(bindir)/.su-$$$$; \
149         rm -f $$TMPFILE; \
150         echo > $$TMPFILE; \
151 ## See if we can create a setuid root executable in $(bindir).
152 ## If not, then don't even try to install su.
153         can_create_suid_root_executable=no; \
154         chown root $$TMPFILE > /dev/null 2>&1 \
155           && chmod $(setuid_root_mode) $$TMPFILE > /dev/null 2>&1 \
156           && can_create_suid_root_executable=yes; \
157         rm -f $$TMPFILE; \
158         if test $$can_create_suid_root_executable = yes; then \
159           $(INSTALL_SU); \
160         else \
161           echo "WARNING: insufficient access; not installing su"; \
162           echo "NOTE: to install su, run 'make install-root' as root"; \
163         fi
165 uninstall-local:
166 # Remove su only if it's one we installed.
167         @if grep '$(GNU_PACKAGE)' $(installed_su) > /dev/null 2>&1; then \
168           echo "  rm -f $(installed_su)"; \
169           rm -f $(installed_su); \
170         else :; fi
172 # Use `ginstall' in the definition of PROGRAMS and in dependencies to avoid
173 # confusion with the `install' target.  The install rule transforms `ginstall'
174 # to install before applying any user-specified name transformations.
176 transform = s/ginstall/install/; @program_transform_name@
177 ginstall_SOURCES = install.c copy.c cp-hash.c
179 # This is for the '[' program.  Automake transliterates '[' to '_'.
180 __SOURCES = lbracket.c
182 cp_SOURCES = cp.c copy.c cp-hash.c
183 dir_SOURCES = ls.c ls-dir.c
184 vdir_SOURCES = ls.c ls-vdir.c
185 ls_SOURCES = ls.c ls-ls.c
186 chown_SOURCES = chown.c chown-core.c
187 chgrp_SOURCES = chgrp.c chown-core.c
189 mv_SOURCES = mv.c copy.c cp-hash.c remove.c
190 rm_SOURCES = rm.c remove.c
192 md5sum_SOURCES = md5sum.c
193 md5sum_CPPFLAGS = -DHASH_ALGO_MD5=1 $(AM_CPPFLAGS)
194 sha1sum_SOURCES = md5sum.c
195 sha1sum_CPPFLAGS = -DHASH_ALGO_SHA1=1 $(AM_CPPFLAGS)
196 sha224sum_SOURCES = md5sum.c
197 sha224sum_CPPFLAGS = -DHASH_ALGO_SHA224=1 $(AM_CPPFLAGS)
198 sha256sum_SOURCES = md5sum.c
199 sha256sum_CPPFLAGS = -DHASH_ALGO_SHA256=1 $(AM_CPPFLAGS)
200 sha384sum_SOURCES = md5sum.c
201 sha384sum_CPPFLAGS = -DHASH_ALGO_SHA384=1 $(AM_CPPFLAGS)
202 sha512sum_SOURCES = md5sum.c
203 sha512sum_CPPFLAGS = -DHASH_ALGO_SHA512=1 $(AM_CPPFLAGS)
205 editpl = sed -e 's,@''PERL''@,$(PERL),g'
207 BUILT_SOURCES += dircolors.h
208 dircolors.h: dcgen dircolors.hin
209         @rm -f $@ $@-t
210         $(PERL) -w -- $(srcdir)/dcgen $(srcdir)/dircolors.hin > $@-t
211         @chmod a-w $@-t
212         mv $@-t $@
214 wheel_size = 5
216 BUILT_SOURCES += wheel-size.h
217 wheel-size.h: Makefile.am
218         @rm -f $@ $@-t
219         echo '#define WHEEL_SIZE $(wheel_size)' > $@-t
220         @chmod a-w $@-t
221         mv $@-t $@
223 BUILT_SOURCES += wheel.h
224 wheel.h: wheel-gen.pl Makefile.am
225         @rm -f $@ $@-t
226         $(srcdir)/wheel-gen.pl $(wheel_size) > $@-t
227         @chmod a-w $@-t
228         mv $@-t $@
230 # false exits nonzero even with --help or --version.
231 # test doesn't support --help or --version.
232 # Tell automake to exempt then from that installcheck test.
233 AM_INSTALLCHECK_STD_OPTIONS_EXEMPT = false test
235 BUILT_SOURCES += fs.h
236 fs.h: stat.c extract-magic
237         rm -f $@
238         $(PERL) $(srcdir)/extract-magic $(srcdir)/stat.c > $@t
239         @chmod a-w $@t
240         mv $@t $@
242 MAINTAINERCLEANFILES = $(BUILT_SOURCES)
244 # Sort in traditional ASCII order, regardless of the current locale;
245 # otherwise we may get into trouble with distinct strings that the
246 # current locale considers to be equal.
247 ASSORT = LC_ALL=C sort
249 all_programs = \
250     $(bin_PROGRAMS) \
251     $(bin_SCRIPTS) \
252   $(EXTRA_PROGRAMS)
254 all_programs.list:
255         @echo $(all_programs) | tr ' ' '\n' | sed -e 's,$(EXEEXT)$$,,' \
256           | $(ASSORT) -u
258 pm = progs-makefile
259 pr = progs-readme
260 # Ensure that the list of programs in README matches the list
261 # of programs we can build.
262 check: check-README check-misc
263 .PHONY: check-README
264 check-README:
265         rm -rf $(pr) $(pm)
266         echo $(all_programs) \
267          | tr -s ' ' '\n' | sed -e 's,$(EXEEXT)$$,,' \
268          | $(ASSORT) -u > $(pm) && \
269         sed -n '/^The programs .* are:/,/^[a-zA-Z]/p' $(top_srcdir)/README \
270           | sed -n '/^   */s///p' | tr -s ' ' '\n' > $(pr)
271         diff $(pm) $(pr) && rm -rf $(pr) $(pm)
273 # Ensure that the list of programs and author names is accurate.
274 au_dotdot = authors-dotdot
275 au_actual = authors-actual
276 .PHONY: check-AUTHORS
277 check-AUTHORS: $(all_programs)
278         rm -f $(au_actual) $(au_dotdot)
279         for i in `ls $(all_programs) | sed -e 's,$(EXEEXT)$$,,' \
280             | $(ASSORT) -u`; do                         \
281           test "$$i" = '[' && continue;                 \
282           exe=$$i;                                      \
283           if test "$$i" = install; then                 \
284             exe=ginstall;                               \
285           elif test "$$i" = test; then                  \
286             exe='[';                                    \
287           fi;                                           \
288           ./$$exe --version                             \
289             |sed -n '/Written by /{ s//'"$$i"': /; s/,* and /, /; s/\.$$//; p; }'; \
290         done > $(au_actual)
291         sed -n '/:/p' $(top_srcdir)/AUTHORS > $(au_dotdot)
292         diff $(au_actual) $(au_dotdot) && rm -f $(au_actual) $(au_dotdot)
294 # Make sure we don't define any S_IS* macros in src/*.c files.
295 # Not a big deal, but they're already defined via system.h.
297 # Also make sure we don't use st_blocks.  Use ST_NBLOCKS instead.
298 # This is a bit of a kludge, since it prevents use of the string
299 # even in comments, but for now it does the job with no false positives.
300 .PHONY: check-misc
301 check-misc:
302         cd $(srcdir); grep '^# *define  *S_IS' $(SOURCES) && exit 1 || :
303         cd $(srcdir); grep st_blocks $(SOURCES) && exit 1 || :
304         cd $(srcdir); grep '^# *define .*defined' $(SOURCES) && exit 1 || :
306 # Extract the list of authors from each file.
307 sed_filter = s/^ *//;s/N_ (//;s/^"//;s/")*$$//
308 # Sometimes the string is on the same line as the #define...
309 s1 = '/^\#define AUTHORS \([^\\]\)/{;s//\1/;$(sed_filter);p;q;}'
310 # Sometimes the string is on the backslash-continued line after the #define.
311 s2 = '/^\#define AUTHORS \\\\/{;n;$(sed_filter);p;q;}'
312 # FIXME: handle *.sh;  and use $(all_programs), not $(SOURCES)
313 ../AUTHORS: $(SOURCES)
314         rm -f $@-t
315         (                                               \
316           set -e;                                       \
317           echo "Here are the names of the programs in this package,";   \
318           echo "each followed by the name(s) of its author(s).";        \
319           echo;                                         \
320           for i in $(SOURCES); do                       \
321             a=`sed -n $(s1) $$i`;                       \
322             test "$$a" && :                             \
323               || a=`sed -n $(s2) $$i`;                  \
324             if test "$$a"; then                         \
325               prog=`echo $$i|sed 's/\.c$$//'`;          \
326               echo "$$prog: $$a";                       \
327             fi;                                         \
328           done | $(ASSORT) -u ) > $@-t
329         chmod a-w $@-t
330         mv $@-t $@
332 # The following rule is not designed to be portable,
333 # and relies on tools that not everyone has.
335 # Most functions in src/*.c should have static scope.
336 # Any that don't must be marked with `extern', but `main'
337 # and `usage' are exceptions.  They're always extern, but
338 # don't need to be marked.
340 # The second nm|grep checks for file-scope variables with `extern' scope.
341 .PHONY: sc_tight_scope
342 sc_tight_scope: $(all_programs)
343         @t=exceptions-$$$$;                                             \
344         trap "s=$$?; rm -f $$t; exit $$s" 0 1 2 13 15;                  \
345         ( printf '^main$$\n^usage$$\n';                                 \
346           grep -h -A1 '^extern .*[^;]$$' $(SOURCES)                     \
347             | grep -vE '^(extern |--)' |sed 's/^/^/;s/ .*/$$/' ) > $$t; \
348         nm -e *.$(OBJEXT)                                               \
349             | sed -n 's/.* T //p'                                       \
350             | grep -Ev -f $$t &&                                        \
351           { echo 'the above functions should have static scope' 1>&2;   \
352             exit 1; } || : ;                                            \
353         ( printf '^program_name$$\n';                                   \
354           sed -n 's/^extern int \([^ ][^ ]*\);$$/^\1$$/p'               \
355             $(noinst_HEADERS) ) > $$t;                                  \
356         nm -e *.$(OBJEXT)                                               \
357             | sed -n 's/.* [BD] //p'                                    \
358             | grep -Ev -f $$t &&                                        \
359           { echo 'the above variables should have static scope' 1>&2;   \
360             exit 1; } || :