sort: fix hang with sort --compress
[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-2010 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        \
28   df            \
29   hostid        \
30   libstdbuf.so  \
31   nice          \
32   pinky         \
33   stdbuf        \
34   stty          \
35   su            \
36   uptime        \
37   users         \
38   who
39
40 AM_CFLAGS = $(WARN_CFLAGS) $(WERROR_CFLAGS)
41
42 EXTRA_PROGRAMS = \
43   $(no_install__progs) \
44   $(build_if_possible__progs) \
45   [             \
46   base64        \
47   basename      \
48   cat           \
49   chcon         \
50   chgrp         \
51   chmod         \
52   chown         \
53   cksum         \
54   comm          \
55   cp            \
56   csplit        \
57   cut           \
58   date          \
59   dd            \
60   dir           \
61   dircolors     \
62   dirname       \
63   du            \
64   echo          \
65   env           \
66   expand        \
67   expr          \
68   factor        \
69   false         \
70   fmt           \
71   fold          \
72   ginstall      \
73   groups        \
74   head          \
75   id            \
76   join          \
77   kill          \
78   link          \
79   ln            \
80   logname       \
81   ls            \
82   md5sum        \
83   mkdir         \
84   mkfifo        \
85   mknod         \
86   mktemp        \
87   mv            \
88   nl            \
89   nproc         \
90   nohup         \
91   od            \
92   paste         \
93   pathchk       \
94   pr            \
95   printenv      \
96   printf        \
97   ptx           \
98   pwd           \
99   readlink      \
100   rm            \
101   rmdir         \
102   runcon        \
103   seq           \
104   sha1sum       \
105   sha224sum     \
106   sha256sum     \
107   sha384sum     \
108   sha512sum     \
109   shred         \
110   shuf          \
111   sleep         \
112   sort          \
113   split         \
114   stat          \
115   sum           \
116   sync          \
117   tac           \
118   tail          \
119   tee           \
120   test          \
121   timeout       \
122   touch         \
123   tr            \
124   true          \
125   truncate      \
126   tsort         \
127   tty           \
128   uname         \
129   unexpand      \
130   uniq          \
131   unlink        \
132   vdir          \
133   wc            \
134   whoami        \
135   yes
136
137 bin_PROGRAMS = $(OPTIONAL_BIN_PROGS)
138
139 noinst_PROGRAMS = setuidgid getlimits
140
141 pkglib_PROGRAMS = $(OPTIONAL_PKGLIB_PROGS)
142
143 noinst_HEADERS =        \
144   chown-core.h          \
145   copy.h                \
146   cp-hash.h             \
147   dircolors.h           \
148   find-mount-point.h    \
149   fs.h                  \
150   group-list.h          \
151   ls.h                  \
152   operand2sig.h         \
153   prog-fprintf.h        \
154   remove.h              \
155   system.h              \
156   wheel-size.h          \
157   wheel.h               \
158   uname.h
159
160 EXTRA_DIST = dcgen dircolors.hin tac-pipe.c \
161   wheel-gen.pl extract-magic c99-to-c89.diff
162 BUILT_SOURCES =
163 CLEANFILES = $(SCRIPTS) su
164
165 # Also remove these sometimes-built programs.
166 # For example, even when excluded, they're built via sc_check-AUTHORS.
167 CLEANFILES += $(no_install__progs)
168
169 AM_CPPFLAGS = -I$(top_srcdir)/lib
170
171 noinst_LIBRARIES = libver.a
172 nodist_libver_a_SOURCES = version.c version.h
173
174 # Tell the linker to omit references to unused shared libraries.
175 AM_LDFLAGS = $(IGNORE_UNUSED_LIBRARIES_CFLAGS)
176
177 # Sometimes, the expansion of $(LIBINTL) includes -lc which may
178 # include modules defining variables like `optind', so libcoreutils.a
179 # must precede $(LIBINTL) in order to ensure we use GNU getopt.
180 # But libcoreutils.a must also follow $(LIBINTL), since libintl uses
181 # replacement functions defined in libcoreutils.a.
182 LDADD = libver.a ../lib/libcoreutils.a $(LIBINTL) ../lib/libcoreutils.a
183
184 # First, list all programs, to make listing per-program libraries easier.
185 # See [ below.
186 arch_LDADD = $(LDADD)
187 base64_LDADD = $(LDADD)
188 basename_LDADD = $(LDADD)
189 cat_LDADD = $(LDADD)
190 chcon_LDADD = $(LDADD)
191 chgrp_LDADD = $(LDADD)
192 chmod_LDADD = $(LDADD)
193 chown_LDADD = $(LDADD)
194 chroot_LDADD = $(LDADD)
195 cksum_LDADD = $(LDADD)
196 comm_LDADD = $(LDADD)
197 nproc_LDADD = $(LDADD)
198 cp_LDADD = $(LDADD)
199 csplit_LDADD = $(LDADD)
200 cut_LDADD = $(LDADD)
201 date_LDADD = $(LDADD)
202 dd_LDADD = $(LDADD)
203 df_LDADD = $(LDADD)
204 # See dir_LDADD below
205 dircolors_LDADD = $(LDADD)
206 dirname_LDADD = $(LDADD)
207 du_LDADD = $(LDADD)
208 echo_LDADD = $(LDADD)
209 env_LDADD = $(LDADD)
210 expand_LDADD = $(LDADD)
211 expr_LDADD = $(LDADD)
212 factor_LDADD = $(LDADD)
213 false_LDADD = $(LDADD)
214 fmt_LDADD = $(LDADD)
215 fold_LDADD = $(LDADD)
216 getlimits_LDADD = $(LDADD)
217 ginstall_LDADD = $(LDADD)
218 groups_LDADD = $(LDADD)
219 head_LDADD = $(LDADD)
220 hostid_LDADD = $(LDADD)
221 hostname_LDADD = $(LDADD)
222 id_LDADD = $(LDADD)
223 join_LDADD = $(LDADD)
224 kill_LDADD = $(LDADD)
225 link_LDADD = $(LDADD)
226 ln_LDADD = $(LDADD)
227 logname_LDADD = $(LDADD)
228 ls_LDADD = $(LDADD)
229 md5sum_LDADD = $(LDADD)
230 mkdir_LDADD = $(LDADD)
231 mkfifo_LDADD = $(LDADD)
232 mknod_LDADD = $(LDADD)
233 mktemp_LDADD = $(LDADD)
234 mv_LDADD = $(LDADD)
235 nice_LDADD = $(LDADD)
236 nl_LDADD = $(LDADD)
237 nohup_LDADD = $(LDADD)
238 od_LDADD = $(LDADD)
239 paste_LDADD = $(LDADD)
240 pathchk_LDADD = $(LDADD)
241 pinky_LDADD = $(LDADD)
242 pr_LDADD = $(LDADD)
243 printenv_LDADD = $(LDADD)
244 printf_LDADD = $(LDADD)
245 ptx_LDADD = $(LDADD)
246 pwd_LDADD = $(LDADD)
247 readlink_LDADD = $(LDADD)
248 rm_LDADD = $(LDADD)
249 rmdir_LDADD = $(LDADD)
250 runcon_LDADD = $(LDADD)
251 seq_LDADD = $(LDADD)
252 setuidgid_LDADD = $(LDADD)
253 sha1sum_LDADD = $(LDADD)
254 sha224sum_LDADD = $(LDADD)
255 sha256sum_LDADD = $(LDADD)
256 sha384sum_LDADD = $(LDADD)
257 sha512sum_LDADD = $(LDADD)
258 shred_LDADD = $(LDADD)
259 shuf_LDADD = $(LDADD)
260 sleep_LDADD = $(LDADD)
261 sort_LDADD = $(LDADD)
262 split_LDADD = $(LDADD)
263 stat_LDADD = $(LDADD)
264 stdbuf_LDADD = $(LDADD)
265 stty_LDADD = $(LDADD)
266 su_LDADD = $(LDADD)
267 sum_LDADD = $(LDADD)
268 sync_LDADD = $(LDADD)
269 tac_LDADD = $(LDADD)
270 tail_LDADD = $(LDADD)
271 tee_LDADD = $(LDADD)
272 test_LDADD = $(LDADD)
273 timeout_LDADD = $(LDADD)
274 touch_LDADD = $(LDADD)
275 tr_LDADD = $(LDADD)
276 true_LDADD = $(LDADD)
277 truncate_LDADD = $(LDADD)
278 tsort_LDADD = $(LDADD)
279 tty_LDADD = $(LDADD)
280 uname_LDADD = $(LDADD)
281 unexpand_LDADD = $(LDADD)
282 uniq_LDADD = $(LDADD)
283 unlink_LDADD = $(LDADD)
284 uptime_LDADD = $(LDADD)
285 users_LDADD = $(LDADD)
286 # See vdir_LDADD below
287 wc_LDADD = $(LDADD)
288 who_LDADD = $(LDADD)
289 whoami_LDADD = $(LDADD)
290 yes_LDADD = $(LDADD)
291
292 # Synonyms.  Recall that Automake transliterates '[' to '_'.
293 __LDADD = $(test_LDADD)
294 dir_LDADD = $(ls_LDADD)
295 vdir_LDADD = $(ls_LDADD)
296
297 # Shared files
298 copy_LDADD =
299 cp_LDADD += $(copy_LDADD)
300 ginstall_LDADD += $(copy_LDADD)
301 mv_LDADD += $(copy_LDADD)
302
303 remove_LDADD =
304 mv_LDADD += $(remove_LDADD)
305 rm_LDADD += $(remove_LDADD)
306
307 # for eaccess, euidaccess
308 copy_LDADD += $(LIB_EACCESS)
309 remove_LDADD += $(LIB_EACCESS)
310 test_LDADD += $(LIB_EACCESS)
311
312 # for selinux use
313 chcon_LDADD += $(LIB_SELINUX)
314 copy_LDADD += $(LIB_SELINUX)
315 ginstall_LDADD += $(LIB_SELINUX)
316 id_LDADD += $(LIB_SELINUX)
317 ls_LDADD += $(LIB_SELINUX)
318 mkdir_LDADD += $(LIB_SELINUX)
319 mkfifo_LDADD += $(LIB_SELINUX)
320 mknod_LDADD += $(LIB_SELINUX)
321 runcon_LDADD += $(LIB_SELINUX)
322 stat_LDADD += $(LIB_SELINUX)
323
324 # for gettime, settime, utimecmp, utimens
325 copy_LDADD += $(LIB_CLOCK_GETTIME)
326 date_LDADD += $(LIB_CLOCK_GETTIME)
327 ginstall_LDADD += $(LIB_CLOCK_GETTIME)
328 ls_LDADD += $(LIB_CLOCK_GETTIME)
329 pr_LDADD += $(LIB_CLOCK_GETTIME)
330 touch_LDADD += $(LIB_CLOCK_GETTIME)
331
332 # for gethrxtime
333 dd_LDADD += $(LIB_GETHRXTIME)
334
335 # for cap_get_file
336 ls_LDADD += $(LIB_CAP)
337
338 # for fdatasync
339 dd_LDADD += $(LIB_FDATASYNC)
340 shred_LDADD += $(LIB_FDATASYNC)
341
342 # for xnanosleep
343 sleep_LDADD += $(LIB_NANOSLEEP)
344 sort_LDADD += $(LIB_NANOSLEEP)
345 tail_LDADD += $(LIB_NANOSLEEP)
346
347 # for various GMP functions
348 expr_LDADD += $(LIB_GMP)
349 factor_LDADD += $(LIB_GMP)
350
351 # for getloadavg
352 uptime_LDADD += $(GETLOADAVG_LIBS)
353
354 # for crypt
355 su_LDADD += $(LIB_CRYPT)
356
357 # for various ACL functions
358 copy_LDADD += $(LIB_ACL)
359 ls_LDADD += $(LIB_ACL)
360
361 # for various xattr functions
362 copy_LDADD += $(LIB_XATTR)
363
364 # for print_unicode_char, proper_name_utf8
365 cat_LDADD += $(LIBICONV)
366 cp_LDADD += $(LIBICONV)
367 df_LDADD += $(LIBICONV)
368 du_LDADD += $(LIBICONV)
369 getlimits_LDADD += $(LIBICONV)
370 printf_LDADD += $(LIBICONV)
371 ptx_LDADD += $(LIBICONV)
372 split_LDADD += $(LIBICONV)
373 stdbuf_LDADD += $(LIBICONV)
374 timeout_LDADD += $(LIBICONV)
375 truncate_LDADD += $(LIBICONV)
376
377 # for canon_host
378 pinky_LDADD += $(GETADDRINFO_LIB)
379 who_LDADD += $(GETADDRINFO_LIB)
380
381 # for gethostname, uname
382 hostname_LDADD += $(GETHOSTNAME_LIB)
383 uname_LDADD += $(GETHOSTNAME_LIB)
384
385 # for strsignal
386 kill_LDADD += $(LIBTHREAD)
387
388 # for pthread
389 sort_LDADD += $(LIB_PTHREAD)
390
391 $(PROGRAMS): ../lib/libcoreutils.a
392
393 # Get the release year from ../lib/version-etc.c.
394 RELEASE_YEAR = \
395   `sed -n '/.*COPYRIGHT_YEAR = \([0-9][0-9][0-9][0-9]\) };/s//\1/p' \
396     $(top_srcdir)/lib/version-etc.c`
397
398 all-local: su$(EXEEXT)
399
400 installed_su = $(DESTDIR)$(bindir)/`echo su|sed '$(transform)'`
401
402 setuid_root_mode = a=rx,u+s
403
404 install_su =                                            \
405   if test "$(INSTALL_SU)" = yes; then                   \
406     p=su;                                               \
407     echo " $(INSTALL_PROGRAM) $$p $(installed_su)";     \
408     $(INSTALL_PROGRAM) $$p $(installed_su);             \
409     echo " chown root $(installed_su)";                 \
410     chown root $(installed_su);                         \
411     echo " chmod $(setuid_root_mode) $(installed_su)";  \
412     chmod $(setuid_root_mode) $(installed_su);          \
413   else                                                  \
414     :;                                                  \
415   fi
416
417 install-root: su$(EXEEXT)
418         @$(install_su)
419
420 install-exec-hook: su$(EXEEXT)
421         @if test "$(INSTALL_SU)" = yes; then                    \
422           TMPFILE=$(DESTDIR)$(bindir)/.su-$$$$;                 \
423           rm -f $$TMPFILE;                                      \
424           echo > $$TMPFILE;                                     \
425 ## See if we can create a setuid root executable in $(bindir).
426 ## If not, then don't even try to install su.
427           can_create_suid_root_executable=no;                   \
428           chown root $$TMPFILE > /dev/null 2>&1                 \
429             && chmod $(setuid_root_mode) $$TMPFILE > /dev/null 2>&1 \
430             && can_create_suid_root_executable=yes;             \
431           rm -f $$TMPFILE;                                      \
432           if test $$can_create_suid_root_executable = yes; then \
433             $(install_su);                                      \
434           else                                                  \
435             echo "WARNING: insufficient access; not installing su"; \
436             echo "NOTE: to install su, run 'make install-root' as root"; \
437             rm -f $(installed_su);                              \
438           fi;                                                   \
439         else :;                                                 \
440         fi
441
442 uninstall-local:
443 # Remove su only if it's one we installed.
444         @if test "$(INSTALL_SU)" = yes; then                    \
445           if grep '$(PACKAGE_NAME)' $(installed_su) > /dev/null 2>&1; then \
446             echo "  rm -f $(installed_su)"; \
447             rm -f $(installed_su); \
448           else :; \
449           fi; \
450         fi
451
452 copy_sources = copy.c cp-hash.c
453
454 # Use `ginstall' in the definition of PROGRAMS and in dependencies to avoid
455 # confusion with the `install' target.  The install rule transforms `ginstall'
456 # to install before applying any user-specified name transformations.
457
458 transform = s/ginstall/install/; $(program_transform_name)
459 ginstall_SOURCES = install.c prog-fprintf.c $(copy_sources)
460
461 # This is for the '[' program.  Automake transliterates '[' to '_'.
462 __SOURCES = lbracket.c
463
464 cp_SOURCES = cp.c $(copy_sources)
465 dir_SOURCES = ls.c ls-dir.c
466 vdir_SOURCES = ls.c ls-vdir.c
467 id_SOURCES = id.c group-list.c
468 groups_SOURCES = groups.c group-list.c
469 ln_SOURCES = ln.c
470 ls_SOURCES = ls.c ls-ls.c
471 chown_SOURCES = chown.c chown-core.c
472 chgrp_SOURCES = chgrp.c chown-core.c
473 kill_SOURCES = kill.c operand2sig.c
474 timeout_SOURCES = timeout.c operand2sig.c
475
476 mv_SOURCES = mv.c remove.c $(copy_sources)
477 rm_SOURCES = rm.c remove.c
478
479 mkdir_SOURCES = mkdir.c prog-fprintf.c
480 rmdir_SOURCES = rmdir.c prog-fprintf.c
481
482 df_SOURCES = df.c find-mount-point.c
483 stat_SOURCES = stat.c find-mount-point.c
484
485 uname_SOURCES = uname.c uname-uname.c
486 arch_SOURCES = uname.c uname-arch.c
487 nproc_SOURCES = nproc.c
488
489 md5sum_SOURCES = md5sum.c
490 md5sum_CPPFLAGS = -DHASH_ALGO_MD5=1 $(AM_CPPFLAGS)
491 sha1sum_SOURCES = md5sum.c
492 sha1sum_CPPFLAGS = -DHASH_ALGO_SHA1=1 $(AM_CPPFLAGS)
493 sha224sum_SOURCES = md5sum.c
494 sha224sum_CPPFLAGS = -DHASH_ALGO_SHA224=1 $(AM_CPPFLAGS)
495 sha256sum_SOURCES = md5sum.c
496 sha256sum_CPPFLAGS = -DHASH_ALGO_SHA256=1 $(AM_CPPFLAGS)
497 sha384sum_SOURCES = md5sum.c
498 sha384sum_CPPFLAGS = -DHASH_ALGO_SHA384=1 $(AM_CPPFLAGS)
499 sha512sum_SOURCES = md5sum.c
500 sha512sum_CPPFLAGS = -DHASH_ALGO_SHA512=1 $(AM_CPPFLAGS)
501
502 ginstall_CPPFLAGS = -DENABLE_MATCHPATHCON=1 $(AM_CPPFLAGS)
503
504 # Ensure we don't link against libcoreutils.a as that lib is
505 # not compiled with -fPIC which causes issues on 64 bit at least
506 libstdbuf_so_LDADD =
507
508 # Note libstdbuf is only compiled if GCC is available
509 # (as per the check in configure.ac), so these flags should be available.
510 # libtool is probably required to relax this dependency.
511 libstdbuf_so_LDFLAGS = -shared
512 libstdbuf_so_CFLAGS = -fPIC $(AM_CFLAGS)
513
514 editpl = sed -e 's,@''PERL''@,$(PERL),g'
515
516 BUILT_SOURCES += dircolors.h
517 dircolors.h: dcgen dircolors.hin
518         $(AM_V_GEN)rm -f $@ $@-t
519         $(AM_V_at)$(PERL) -w -- $(srcdir)/dcgen $(srcdir)/dircolors.hin > $@-t
520         $(AM_V_at)chmod a-w $@-t
521         $(AM_V_at)mv $@-t $@
522
523 wheel_size = 5
524
525 BUILT_SOURCES += wheel-size.h
526 wheel-size.h: Makefile.am
527         $(AM_V_GEN)rm -f $@ $@-t
528         $(AM_V_at)echo '#define WHEEL_SIZE $(wheel_size)' > $@-t
529         $(AM_V_at)chmod a-w $@-t
530         $(AM_V_at)mv $@-t $@
531
532 BUILT_SOURCES += wheel.h
533 wheel.h: wheel-gen.pl Makefile.am
534         $(AM_V_GEN)rm -f $@ $@-t
535         $(AM_V_at)$(srcdir)/wheel-gen.pl $(wheel_size) > $@-t
536         $(AM_V_at)chmod a-w $@-t
537         $(AM_V_at)mv $@-t $@
538
539 # false exits nonzero even with --help or --version.
540 # test doesn't support --help or --version.
541 # Tell automake to exempt then from that installcheck test.
542 AM_INSTALLCHECK_STD_OPTIONS_EXEMPT = false test
543
544 # Compare fs.h with the list of file system names/magic-numbers in the
545 # Linux statfs man page.  This target prints any new name/number pairs.
546 # Also compare against /usr/include/linux/magic.h
547 .PHONY: fs-magic-compare
548 fs-magic-compare: fs-magic fs-kernel-magic fs-def
549         join -v1 -t@ fs-magic fs-def
550         join -v1 -t@ fs-kernel-magic fs-def
551
552 CLEANFILES += fs-def
553 fs-def: fs.h
554         grep '^# *define ' $< | $(ASSORT) > $@-t && mv $@-t $@
555
556 # Massage bits of the statfs man page and definitions from
557 # /usr/include/linux/magic.h to be in a form consistent with what's in fs.h.
558 fs_normalize_perl_subst =                       \
559   -e 's/MINIX_SUPER_MAGIC\b/MINIX/;'            \
560   -e 's/MINIX_SUPER_MAGIC2\b/MINIX_30/;'        \
561   -e 's/MINIX2_SUPER_MAGIC\b/MINIX_V2/;'        \
562   -e 's/MINIX2_SUPER_MAGIC2\b/MINIX_V2_30/;'    \
563   -e 's/MINIX3_SUPER_MAGIC\b/MINIX_V3/;'        \
564   -e 's/CIFS_MAGIC_NUMBER/CIFS/;'               \
565   -e 's/(_SUPER)?_MAGIC//;'                     \
566   -e 's/\s+0x(\S+)/" 0x" . uc $$1/e;'           \
567   -e 's/(\s+0x)(\X{3})\b/$${1}0$$2/;'           \
568   -e 's/(\s+0x)(\X{6})\b/$${1}00$$2/;'          \
569   -e 's/(\s+0x)(\X{7})\b/$${1}0$$2/;'           \
570   -e 's/^\s+//;'                                \
571   -e 's/^\#define\s+//;'                        \
572   -e 's/^_(XIAFS)/$$1/;'                        \
573   -e 's/^USBDEVICE/USBDEVFS/;'                  \
574   -e 's/NTFS_SB/NTFS/;'                         \
575   -e 's/^/\# define S_MAGIC_/;'                 \
576   -e 's,\s*/\* .*? \*/,,;'
577
578 CLEANFILES += fs-magic
579 fs-magic: Makefile
580         man statfs \
581           |perl -ne '/File system types:/.../Nobody kno/ and print'     \
582           |grep 0x | perl -p                                            \
583             $(fs_normalize_perl_subst)                                  \
584           | grep -Ev 'S_MAGIC_EXT[34]|STACK_END'                        \
585           | LC_ALL=C sort                                               \
586           > $@-t && mv $@-t $@
587
588 CLEANFILES += fs-kernel-magic
589 fs-kernel-magic: Makefile
590         perl -ne '/^#define.*0x/ and print' /usr/include/linux/magic.h  \
591           | perl -p                                                     \
592             $(fs_normalize_perl_subst)                                  \
593           | grep -Ev 'S_MAGIC_EXT[34]|STACK_END'                        \
594           | LC_ALL=C sort                                               \
595           > $@-t && mv $@-t $@
596
597 BUILT_SOURCES += fs.h
598 fs.h: stat.c extract-magic
599         $(AM_V_GEN)rm -f $@
600         $(AM_V_at)$(PERL) $(srcdir)/extract-magic $(srcdir)/stat.c > $@t
601         $(AM_V_at)chmod a-w $@t
602         $(AM_V_at)mv $@t $@
603
604 BUILT_SOURCES += version.c
605 version.c: Makefile
606         $(AM_V_GEN)rm -f $@
607         $(AM_V_at)printf '#include <config.h>\n' > $@t
608         $(AM_V_at)printf 'char const *Version = "$(PACKAGE_VERSION)";\n' >> $@t
609         $(AM_V_at)chmod a-w $@t
610         $(AM_V_at)mv $@t $@
611
612 BUILT_SOURCES += version.h
613 version.h: Makefile
614         $(AM_V_GEN)rm -f $@
615         $(AM_V_at)printf 'extern char const *Version;\n' > $@t
616         $(AM_V_at)chmod a-w $@t
617         $(AM_V_at)mv $@t $@
618
619 DISTCLEANFILES = version.c version.h
620 MAINTAINERCLEANFILES = $(BUILT_SOURCES)
621
622 # Sort in traditional ASCII order, regardless of the current locale;
623 # otherwise we may get into trouble with distinct strings that the
624 # current locale considers to be equal.
625 ASSORT = LC_ALL=C sort
626
627 all_programs = \
628     $(bin_PROGRAMS) \
629     $(bin_SCRIPTS) \
630   $(EXTRA_PROGRAMS)
631
632 built_programs.list:
633         @echo $(bin_PROGRAMS) $(bin_SCRIPTS) | tr ' ' '\n' \
634           | sed -e 's,$(EXEEXT)$$,,' | $(ASSORT) -u | tr '\n' ' '
635
636 all_programs.list:
637         @echo $(all_programs) | tr ' ' '\n' | sed -e 's,$(EXEEXT)$$,,' \
638           | sed /libstdbuf/d \
639           | $(ASSORT) -u
640
641 # This is required because we have broken inter-directory dependencies:
642 # in order to generate all man pages, even those for which we don't
643 # install a binary, require that all programs be built at distribution time.
644 dist-hook: $(all_programs)
645
646 # Ensure that all programs are built so we can for example
647 # subsequently syntax check all man pages.
648 .PHONY: all_programs
649 all_programs: $(all_programs)
650
651 pm = progs-makefile
652 pr = progs-readme
653 # Ensure that the list of programs in README matches the list
654 # of programs we can build.
655 check: check-README check-duplicate-no-install
656 .PHONY: check-README
657 check-README:
658         $(AM_V_GEN)rm -rf $(pr) $(pm)
659         $(AM_V_at)echo $(all_programs) \
660          | tr -s ' ' '\n' | sed -e 's,$(EXEEXT)$$,,;s/ginstall/install/' \
661          | sed /libstdbuf/d \
662          | $(ASSORT) -u > $(pm) && \
663         sed -n '/^The programs .* are:/,/^[a-zA-Z]/p' $(top_srcdir)/README \
664           | sed -n '/^   */s///p' | tr -s ' ' '\n' > $(pr)
665         $(AM_V_at)diff $(pm) $(pr) && rm -rf $(pr) $(pm)
666
667 # Ensure that a by-default-not-installed program (listed in
668 # $(no_install__progs) is not also listed in $(EXTRA_PROGRAMS), because
669 # if that were to happen, it *would* be installed by default.
670 .PHONY: check-duplicate-no-install
671 check-duplicate-no-install: tr
672         $(AM_V_GEN)test -z "`echo '$(EXTRA_PROGRAMS)'| ./tr ' ' '\n' | uniq -d`"
673
674 # Ensure that the list of programs and author names is accurate.
675 # We need a UTF8 locale.  If a lack of locale support or a missing
676 # translation inhibits printing of UTF-8 names, just skip this test.
677 au_dotdot = authors-dotdot
678 au_actual = authors-actual
679 .PHONY: sc_check-AUTHORS
680 sc_check-AUTHORS: $(all_programs)
681         @locale=en_US.UTF-8;                            \
682         LC_ALL=$$locale ./cat --version         \
683             | grep ' Torbjorn ' > /dev/null             \
684           && { echo "$@: skipping this check"; exit 0; }; \
685         rm -f $(au_actual) $(au_dotdot);                \
686         for i in `ls $(all_programs) | sed -e 's,$(EXEEXT)$$,,' \
687             | sed /libstdbuf/d                          \
688             | $(ASSORT) -u`; do                         \
689           test "$$i" = '[' && continue;                 \
690           exe=$$i;                                      \
691           if test "$$i" = install; then                 \
692             exe=ginstall;                               \
693           elif test "$$i" = test; then                  \
694             exe='[';                                    \
695           fi;                                           \
696           LC_ALL=$$locale ./$$exe --version             \
697             | perl -0 -pi -e 's/,\n/, /gm'              \
698             | sed -n -e '/Written by /{ s//'"$$i"': /;' \
699                   -e 's/,* and /, /; s/\.$$//; p; }';   \
700         done > $(au_actual) &&                          \
701         sed -n '/^[^ ][^ ]*:/p' $(top_srcdir)/AUTHORS > $(au_dotdot) && \
702         diff $(au_actual) $(au_dotdot) && rm -f $(au_actual) $(au_dotdot)
703
704 # The following rule is not designed to be portable,
705 # and relies on tools that not everyone has.
706
707 # Most functions in src/*.c should have static scope.
708 # Any that don't must be marked with `extern', but `main'
709 # and `usage' are exceptions.  They're always extern, but
710 # don't need to be marked. Also functions starting with __
711 # are exempted due to possibly being added by the compiler
712 # (when compiled as a shared library for example).
713 #
714 # The second nm|grep checks for file-scope variables with `extern' scope.
715 .PHONY: sc_tight_scope
716 sc_tight_scope: $(bin_PROGRAMS)
717         @t=exceptions-$$$$;                                             \
718         trap 's=$$?; rm -f $$t; exit $$s' 0;                            \
719         am__exit='(exit $s); exit $s';                                  \
720         trap "s=129; $$am__exit" 1; trap "s=130; $$am__exit" 2;         \
721         trap "s=141; $$am__exit" 13; trap "s=143; $$am__exit" 15;       \
722         src=`for f in $(SOURCES); do                                    \
723                test -f $$f && d= || d=$(srcdir)/; echo $$d$$f; done`;   \
724         hdr=`for f in $(noinst_HEADERS); do                             \
725                test -f $$f && d= || d=$(srcdir)/; echo $$d$$f; done`;   \
726         ( printf 'main\nusage\n_.*\n';                                  \
727           grep -h -A1 '^extern .*[^;]$$' $$src                          \
728             | grep -vE '^(extern |--)' | sed 's/ .*//';                 \
729           perl -ne '/^extern (?:enum )?\S+ (\S*) \(/ and print "$$1\n"' $$hdr;  \
730         ) | $(ASSORT) -u | sed 's/^/^/;s/$$/$$/' > $$t;                 \
731         nm -e *.$(OBJEXT)                                               \
732             | sed -n 's/.* T //p'                                       \
733             | sed 's/^_//'                                              \
734             | grep -Ev -f $$t &&                                        \
735           { echo 'the above functions should have static scope' 1>&2;   \
736             exit 1; } || : ;                                            \
737         ( printf '^program_name$$\n';                                   \
738           perl -ne '/^extern .*?\**(\w+);/ and print "^$$1\$$\n"'       \
739             $$hdr *.h ) | $(ASSORT) -u > $$t;                           \
740         nm -e *.$(OBJEXT)                                               \
741             | sed -n 's/.* [BD] //p'                                    \
742             | sed 's/^_//'                                              \
743             | grep -Ev -f $$t &&                                        \
744           { echo 'the above variables should have static scope' 1>&2;   \
745             exit 1; } || :
746
747 # Use the just-built ./ginstall, when not cross-compiling.
748 if CROSS_COMPILING
749 cu_install_program = @INSTALL_PROGRAM@
750 else
751 cu_install_program = ./ginstall
752 endif
753 INSTALL_PROGRAM = $(cu_install_program)