008b87de600b839b7da12292c1158e2d01f4c81f
[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   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   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 all-local: su$(EXEEXT)
146
147 installed_su = $(DESTDIR)$(bindir)/`echo su|sed '$(transform)'`
148
149 setuid_root_mode = a=rx,u+s
150
151 install_su =                                            \
152   if test "$(INSTALL_SU)" = yes; then                   \
153     p=su;                                               \
154     echo " $(INSTALL_PROGRAM) $$p $(installed_su)";     \
155     $(INSTALL_PROGRAM) $$p $(installed_su);             \
156     echo " chown root $(installed_su)";                 \
157     chown root $(installed_su);                         \
158     echo " chmod $(setuid_root_mode) $(installed_su)";  \
159     chmod $(setuid_root_mode) $(installed_su);          \
160   else                                                  \
161     :;                                                  \
162   fi
163
164 install-root: su$(EXEEXT)
165         @$(install_su)
166
167 install-exec-hook: su$(EXEEXT)
168         @if test "$(INSTALL_SU)" = yes; then                    \
169           TMPFILE=$(DESTDIR)$(bindir)/.su-$$$$;                 \
170           rm -f $$TMPFILE;                                      \
171           echo > $$TMPFILE;                                     \
172 ## See if we can create a setuid root executable in $(bindir).
173 ## If not, then don't even try to install su.
174           can_create_suid_root_executable=no;                   \
175           chown root $$TMPFILE > /dev/null 2>&1                 \
176             && chmod $(setuid_root_mode) $$TMPFILE > /dev/null 2>&1 \
177             && can_create_suid_root_executable=yes;             \
178           rm -f $$TMPFILE;                                      \
179           if test $$can_create_suid_root_executable = yes; then \
180             $(install_su);                                      \
181           else                                                  \
182             echo "WARNING: insufficient access; not installing su"; \
183             echo "NOTE: to install su, run 'make install-root' as root"; \
184             rm -f $(installed_su);                              \
185           fi;                                                   \
186         else :;                                                 \
187         fi
188
189 uninstall-local:
190 # Remove su only if it's one we installed.
191         @if test "$(INSTALL_SU)" = yes; then                    \
192           if grep '$(PACKAGE_NAME)' $(installed_su) > /dev/null 2>&1; then \
193             echo "  rm -f $(installed_su)"; \
194             rm -f $(installed_su); \
195           else :; \
196           fi; \
197         fi
198
199 copy_sources = copy.c cp-hash.c
200
201 # Use `ginstall' in the definition of PROGRAMS and in dependencies to avoid
202 # confusion with the `install' target.  The install rule transforms `ginstall'
203 # to install before applying any user-specified name transformations.
204
205 transform = s/ginstall/install/; @program_transform_name@
206 ginstall_SOURCES = install.c $(copy_sources)
207
208 # This is for the '[' program.  Automake transliterates '[' to '_'.
209 __SOURCES = lbracket.c
210
211 cp_SOURCES = cp.c $(copy_sources)
212 dir_SOURCES = ls.c ls-dir.c
213 vdir_SOURCES = ls.c ls-vdir.c
214 id_SOURCES = id.c group-list.c
215 groups_SOURCES = groups.c group-list.c
216 ln_SOURCES = ln.c
217 ls_SOURCES = ls.c ls-ls.c
218 chown_SOURCES = chown.c chown-core.c
219 chgrp_SOURCES = chgrp.c chown-core.c
220
221 mv_SOURCES = mv.c remove.c $(copy_sources)
222 rm_SOURCES = rm.c remove.c
223
224 uname_SOURCES = uname.c uname-uname.c
225 arch_SOURCES = uname.c uname-arch.c
226
227 md5sum_SOURCES = md5sum.c
228 md5sum_CPPFLAGS = -DHASH_ALGO_MD5=1 $(AM_CPPFLAGS)
229 sha1sum_SOURCES = md5sum.c
230 sha1sum_CPPFLAGS = -DHASH_ALGO_SHA1=1 $(AM_CPPFLAGS)
231 sha224sum_SOURCES = md5sum.c
232 sha224sum_CPPFLAGS = -DHASH_ALGO_SHA224=1 $(AM_CPPFLAGS)
233 sha256sum_SOURCES = md5sum.c
234 sha256sum_CPPFLAGS = -DHASH_ALGO_SHA256=1 $(AM_CPPFLAGS)
235 sha384sum_SOURCES = md5sum.c
236 sha384sum_CPPFLAGS = -DHASH_ALGO_SHA384=1 $(AM_CPPFLAGS)
237 sha512sum_SOURCES = md5sum.c
238 sha512sum_CPPFLAGS = -DHASH_ALGO_SHA512=1 $(AM_CPPFLAGS)
239
240 editpl = sed -e 's,@''PERL''@,$(PERL),g'
241
242 BUILT_SOURCES += dircolors.h
243 dircolors.h: dcgen dircolors.hin
244         @rm -f $@ $@-t
245         $(PERL) -w -- $(srcdir)/dcgen $(srcdir)/dircolors.hin > $@-t
246         @chmod a-w $@-t
247         mv $@-t $@
248
249 wheel_size = 5
250
251 BUILT_SOURCES += wheel-size.h
252 wheel-size.h: Makefile.am
253         @rm -f $@ $@-t
254         echo '#define WHEEL_SIZE $(wheel_size)' > $@-t
255         @chmod a-w $@-t
256         mv $@-t $@
257
258 BUILT_SOURCES += wheel.h
259 wheel.h: wheel-gen.pl Makefile.am
260         @rm -f $@ $@-t
261         $(srcdir)/wheel-gen.pl $(wheel_size) > $@-t
262         @chmod a-w $@-t
263         mv $@-t $@
264
265 # false exits nonzero even with --help or --version.
266 # test doesn't support --help or --version.
267 # Tell automake to exempt then from that installcheck test.
268 AM_INSTALLCHECK_STD_OPTIONS_EXEMPT = false test
269
270 BUILT_SOURCES += fs.h
271 fs.h: stat.c extract-magic
272         rm -f $@
273         $(PERL) $(srcdir)/extract-magic $(srcdir)/stat.c > $@t
274         @chmod a-w $@t
275         mv $@t $@
276
277 MAINTAINERCLEANFILES = $(BUILT_SOURCES)
278
279 # Sort in traditional ASCII order, regardless of the current locale;
280 # otherwise we may get into trouble with distinct strings that the
281 # current locale considers to be equal.
282 ASSORT = LC_ALL=C sort
283
284 all_programs = \
285     $(bin_PROGRAMS) \
286     $(bin_SCRIPTS) \
287   $(EXTRA_PROGRAMS)
288
289 built_programs.list:
290         @echo $(bin_PROGRAMS) $(bin_SCRIPTS) | tr ' ' '\n' \
291           | sed -e 's,$(EXEEXT)$$,,' | $(ASSORT) -u | tr '\n' ' '
292
293 all_programs.list:
294         @echo $(all_programs) | tr ' ' '\n' | sed -e 's,$(EXEEXT)$$,,' \
295           | $(ASSORT) -u
296
297 pm = progs-makefile
298 pr = progs-readme
299 # Ensure that the list of programs in README matches the list
300 # of programs we can build.
301 check: check-README check-misc check-duplicate-no-install
302 .PHONY: check-README
303 check-README:
304         rm -rf $(pr) $(pm)
305         echo $(all_programs) \
306          | tr -s ' ' '\n' | sed -e 's,$(EXEEXT)$$,,;s/ginstall/install/' \
307          | $(ASSORT) -u > $(pm) && \
308         sed -n '/^The programs .* are:/,/^[a-zA-Z]/p' $(top_srcdir)/README \
309           | sed -n '/^   */s///p' | tr -s ' ' '\n' > $(pr)
310         diff $(pm) $(pr) && rm -rf $(pr) $(pm)
311
312 # Ensure that a by-default-not-installed program (listed in
313 # $(no_install__progs) is not also listed in $(EXTRA_PROGRAMS), because
314 # if that were to happen, it *would* be installed by default.
315 .PHONY: check-duplicate-no-install
316 check-duplicate-no-install: tr
317         test -z "`echo '$(EXTRA_PROGRAMS)'| ./tr ' ' '\n' | uniq -d`"
318
319 # Ensure that the list of programs and author names is accurate.
320 au_dotdot = authors-dotdot
321 au_actual = authors-actual
322 .PHONY: check-AUTHORS
323 check-AUTHORS: $(all_programs)
324         rm -f $(au_actual) $(au_dotdot)
325         for i in `ls $(all_programs) | sed -e 's,$(EXEEXT)$$,,' \
326             | $(ASSORT) -u`; do                         \
327           test "$$i" = '[' && continue;                 \
328           exe=$$i;                                      \
329           if test "$$i" = install; then                 \
330             exe=ginstall;                               \
331           elif test "$$i" = test; then                  \
332             exe='[';                                    \
333           fi;                                           \
334           ./$$exe --version                             \
335             |sed -n '/Written by /{ s//'"$$i"': /; s/,* and /, /; s/\.$$//; p; }'; \
336         done > $(au_actual)
337         sed -n '/:/p' $(top_srcdir)/AUTHORS > $(au_dotdot)
338         diff $(au_actual) $(au_dotdot) && rm -f $(au_actual) $(au_dotdot)
339
340 # Make sure we don't define any S_IS* macros in src/*.c files.
341 # Not a big deal, but they're already defined via system.h.
342 #
343 # Also make sure we don't use st_blocks.  Use ST_NBLOCKS instead.
344 # This is a bit of a kludge, since it prevents use of the string
345 # even in comments, but for now it does the job with no false positives.
346 .PHONY: check-misc
347 check-misc:
348         cd $(srcdir); grep '^# *define  *S_IS' $(SOURCES) && exit 1 || :
349         cd $(srcdir); grep st_blocks $(SOURCES) && exit 1 || :
350         cd $(srcdir); grep '^# *define .*defined' $(SOURCES) && exit 1 || :
351
352 # Extract the list of authors from each file.
353 sed_filter = s/^ *//;s/N_ (//;s/^"//;s/")*$$//
354 # Sometimes the string is on the same line as the #define...
355 s1 = '/^\#define AUTHORS \([^\\]\)/{;s//\1/;$(sed_filter);p;q;}'
356 # Sometimes the string is on the backslash-continued line after the #define.
357 s2 = '/^\#define AUTHORS \\\\/{;n;$(sed_filter);p;q;}'
358 # FIXME: handle *.sh;  and use $(all_programs), not $(SOURCES)
359 ../AUTHORS: $(SOURCES)
360         rm -f $@-t
361         (                                               \
362           set -e;                                       \
363           echo "Here are the names of the programs in this package,";   \
364           echo "each followed by the name(s) of its author(s).";        \
365           echo;                                         \
366           for i in $(SOURCES); do                       \
367             a=`sed -n $(s1) $$i`;                       \
368             test "$$a" && :                             \
369               || a=`sed -n $(s2) $$i`;                  \
370             if test "$$a"; then                         \
371               prog=`echo $$i|sed 's/\.c$$//'`;          \
372               echo "$$prog: $$a";                       \
373             fi;                                         \
374           done | $(ASSORT) -u ) > $@-t
375         chmod a-w $@-t
376         mv $@-t $@
377
378 # The following rule is not designed to be portable,
379 # and relies on tools that not everyone has.
380
381 # Most functions in src/*.c should have static scope.
382 # Any that don't must be marked with `extern', but `main'
383 # and `usage' are exceptions.  They're always extern, but
384 # don't need to be marked.
385 #
386 # The second nm|grep checks for file-scope variables with `extern' scope.
387 .PHONY: sc_tight_scope
388 sc_tight_scope: $(all_programs)
389         @t=exceptions-$$$$;                                             \
390         trap "s=$$?; rm -f $$t; exit $$s" 0 1 2 13 15;                  \
391         ( printf '^main$$\n^usage$$\n';                                 \
392           grep -h -A1 '^extern .*[^;]$$' $(SOURCES)                     \
393             | grep -vE '^(extern |--)' |sed 's/^/^/;s/ .*/$$/' ) > $$t; \
394         nm -e *.$(OBJEXT)                                               \
395             | sed -n 's/.* T //p'                                       \
396             | grep -Ev -f $$t &&                                        \
397           { echo 'the above functions should have static scope' 1>&2;   \
398             exit 1; } || : ;                                            \
399         ( printf '^program_name$$\n';                                   \
400           sed -n 's/^extern int \([^ ][^ ]*\);$$/^\1$$/p'               \
401             $(noinst_HEADERS) ) > $$t;                                  \
402         nm -e *.$(OBJEXT)                                               \
403             | sed -n 's/.* [BD] //p'                                    \
404             | grep -Ev -f $$t &&                                        \
405           { echo 'the above variables should have static scope' 1>&2;   \
406             exit 1; } || :