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