1# Make coreutils programs.                             -*-Makefile-*-
2# This is included by the top-level Makefile.am.
3
4## Copyright (C) 1990-2023 Free Software Foundation, Inc.
5
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 3 of the License, or
9## (at your option) any later version.
10##
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.
15##
16## You should have received a copy of the GNU General Public License
17## along with this program.  If not, see <https://www.gnu.org/licenses/>.
18
19# FIXME: once lib/ and gnulib-tests/ are also converted, hoist to Makefile.am
20AM_CFLAGS = $(WERROR_CFLAGS)
21
22# The list of all programs (separated in different variables to express
23# the how and when they should be installed) is defined in this makefile
24# fragment, autogenerated by the 'gen-lists-of-programs.sh' auxiliary
25# script.
26include $(srcdir)/src/cu-progs.mk
27
28EXTRA_PROGRAMS = \
29   $(no_install__progs) \
30   $(build_if_possible__progs) \
31   $(default__progs)
32
33# The user can tweak these lists at configure time.
34bin_PROGRAMS = @bin_PROGRAMS@
35pkglibexec_PROGRAMS = @pkglibexec_PROGRAMS@
36
37# Needed by the testsuite.
38noinst_PROGRAMS =		\
39  src/getlimits			\
40  src/make-prime-list
41
42noinst_HEADERS =		\
43  src/chown-core.h		\
44  src/copy.h			\
45  src/cp-hash.h			\
46  src/dircolors.h		\
47  src/expand-common.h		\
48  src/find-mount-point.h	\
49  src/fs.h			\
50  src/fs-is-local.h		\
51  src/group-list.h		\
52  src/ioblksize.h		\
53  src/iopoll.h			\
54  src/longlong.h		\
55  src/ls.h			\
56  src/operand2sig.h		\
57  src/prog-fprintf.h		\
58  src/remove.h			\
59  src/set-fields.h		\
60  src/statx.h			\
61  src/system.h			\
62  src/temp-stream.h		\
63  src/uname.h			\
64  src/wc.h
65
66EXTRA_DIST +=		\
67  src/dcgen		\
68  src/dircolors.hin	\
69  src/primes.h		\
70  src/tac-pipe.c	\
71  src/extract-magic
72
73CLEANFILES += $(SCRIPTS)
74
75# Also remove these sometimes-built programs.
76# For example, even when excluded, they're built via 'sc_check-AUTHORS'
77# or 'dist'.
78CLEANFILES += $(no_install__progs)
79
80noinst_LIBRARIES += src/libver.a
81nodist_src_libver_a_SOURCES = src/version.c src/version.h
82
83# Tell the linker to omit references to unused shared libraries.
84AM_LDFLAGS = $(IGNORE_UNUSED_LIBRARIES_CFLAGS)
85
86# Extra libraries needed by more than one program.  Will be updated later.
87copy_ldadd =
88remove_ldadd =
89
90# Sometimes, the expansion of $(LIBINTL) includes -lc which may
91# include modules defining variables like 'optind', so libcoreutils.a
92# must precede $(LIBINTL) in order to ensure we use GNU getopt.
93# But libcoreutils.a must also follow $(LIBINTL), since libintl uses
94# replacement functions defined in libcoreutils.a.
95# Similarly for $(MBRTOWC_LIB).
96LDADD = src/libver.a lib/libcoreutils.a $(LIBINTL) $(MBRTOWC_LIB) \
97  lib/libcoreutils.a
98
99# First, list all programs, to make listing per-program libraries easier.
100# See [ below.
101src_arch_LDADD = $(LDADD)
102src_base64_LDADD = $(LDADD)
103src_base32_LDADD = $(LDADD)
104src_basenc_LDADD = $(LDADD)
105src_basename_LDADD = $(LDADD)
106src_cat_LDADD = $(LDADD)
107src_chcon_LDADD = $(LDADD)
108src_chgrp_LDADD = $(LDADD)
109src_chmod_LDADD = $(LDADD)
110src_chown_LDADD = $(LDADD)
111src_chroot_LDADD = $(LDADD)
112src_cksum_LDADD = $(LDADD)
113src_comm_LDADD = $(LDADD)
114src_nproc_LDADD = $(LDADD)
115src_cp_LDADD = $(LDADD)
116if !SINGLE_BINARY
117src_coreutils_LDADD = $(LDADD)
118endif
119src_csplit_LDADD = $(LDADD)
120src_cut_LDADD = $(LDADD)
121src_date_LDADD = $(LDADD)
122src_dd_LDADD = $(LDADD)
123src_df_LDADD = $(LDADD)
124# See dir_LDADD below
125src_dircolors_LDADD = $(LDADD)
126src_dirname_LDADD = $(LDADD)
127src_du_LDADD = $(LDADD)
128src_echo_LDADD = $(LDADD)
129src_env_LDADD = $(LDADD)
130src_expand_LDADD = $(LDADD)
131src_expr_LDADD = $(LDADD)
132src_factor_LDADD = $(LDADD)
133src_false_LDADD = $(LDADD)
134src_fmt_LDADD = $(LDADD)
135src_fold_LDADD = $(LDADD)
136src_getlimits_LDADD = $(LDADD)
137src_ginstall_LDADD = $(LDADD)
138src_groups_LDADD = $(LDADD)
139src_head_LDADD = $(LDADD)
140src_hostid_LDADD = $(LDADD)
141src_hostname_LDADD = $(LDADD)
142src_id_LDADD = $(LDADD)
143src_join_LDADD = $(LDADD)
144src_kill_LDADD = $(LDADD)
145src_link_LDADD = $(LDADD)
146src_ln_LDADD = $(LDADD)
147src_logname_LDADD = $(LDADD)
148src_ls_LDADD = $(LDADD)
149
150# This must *not* depend on anything in lib/, since it is used to generate
151# src/primes.h.  If it depended on libcoreutils.a, that would pull all lib/*.c
152# into BUILT_SOURCES.
153src_make_prime_list_LDADD =
154
155src_md5sum_LDADD = $(LDADD)
156src_mkdir_LDADD = $(LDADD)
157src_mkfifo_LDADD = $(LDADD)
158src_mknod_LDADD = $(LDADD)
159src_mktemp_LDADD = $(LDADD)
160src_mv_LDADD = $(LDADD)
161src_nice_LDADD = $(LDADD)
162src_nl_LDADD = $(LDADD)
163src_nohup_LDADD = $(LDADD)
164src_numfmt_LDADD = $(LDADD)
165src_od_LDADD = $(LDADD)
166src_paste_LDADD = $(LDADD)
167src_pathchk_LDADD = $(LDADD)
168src_pinky_LDADD = $(LDADD)
169src_pr_LDADD = $(LDADD)
170src_printenv_LDADD = $(LDADD)
171src_printf_LDADD = $(LDADD)
172src_ptx_LDADD = $(LDADD)
173src_pwd_LDADD = $(LDADD)
174src_readlink_LDADD = $(LDADD)
175src_realpath_LDADD = $(LDADD)
176src_rm_LDADD = $(LDADD)
177src_rmdir_LDADD = $(LDADD)
178src_runcon_LDADD = $(LDADD)
179src_seq_LDADD = $(LDADD)
180src_sha1sum_LDADD = $(LDADD)
181src_sha224sum_LDADD = $(LDADD)
182src_sha256sum_LDADD = $(LDADD)
183src_sha384sum_LDADD = $(LDADD)
184src_sha512sum_LDADD = $(LDADD)
185src_shred_LDADD = $(LDADD)
186src_shuf_LDADD = $(LDADD)
187src_sleep_LDADD = $(LDADD)
188src_sort_LDADD = $(LDADD)
189src_split_LDADD = $(LDADD)
190src_stat_LDADD = $(LDADD)
191src_stdbuf_LDADD = $(LDADD)
192src_stty_LDADD = $(LDADD)
193src_sum_LDADD = $(LDADD)
194src_sync_LDADD = $(LDADD)
195src_tac_LDADD = $(LDADD)
196src_tail_LDADD = $(LDADD)
197src_tee_LDADD = $(LDADD)
198src_test_LDADD = $(LDADD)
199src_timeout_LDADD = $(LDADD)
200src_touch_LDADD = $(LDADD)
201src_tr_LDADD = $(LDADD)
202src_true_LDADD = $(LDADD)
203src_truncate_LDADD = $(LDADD)
204src_tsort_LDADD = $(LDADD)
205src_tty_LDADD = $(LDADD)
206src_uname_LDADD = $(LDADD)
207src_unexpand_LDADD = $(LDADD)
208src_uniq_LDADD = $(LDADD)
209src_unlink_LDADD = $(LDADD)
210src_uptime_LDADD = $(LDADD)
211src_users_LDADD = $(LDADD)
212# See vdir_LDADD below
213src_wc_LDADD = $(LDADD)
214src_who_LDADD = $(LDADD)
215src_whoami_LDADD = $(LDADD)
216src_yes_LDADD = $(LDADD)
217
218# Synonyms.  Recall that Automake transliterates '[' and '/' to '_'.
219src___LDADD = $(src_test_LDADD)
220src_dir_LDADD = $(src_ls_LDADD)
221src_vdir_LDADD = $(src_ls_LDADD)
222
223src_cp_LDADD += $(copy_ldadd)
224src_ginstall_LDADD += $(copy_ldadd)
225src_mv_LDADD += $(copy_ldadd)
226
227src_mv_LDADD += $(remove_ldadd)
228src_rm_LDADD += $(remove_ldadd)
229
230# for eaccess, euidaccess
231copy_ldadd += $(EUIDACCESS_LIBGEN)
232remove_ldadd += $(EUIDACCESS_LIBGEN)
233src_sort_LDADD += $(EUIDACCESS_LIBGEN)
234src_test_LDADD += $(EUIDACCESS_LIBGEN)
235
236# for selinux use
237copy_ldadd += $(LIB_SELINUX)
238src_chcon_LDADD += $(LIB_SELINUX)
239src_ginstall_LDADD += $(LIB_SELINUX)
240src_id_LDADD += $(LIB_SELINUX)
241src_id_LDADD += $(LIB_SMACK)
242src_ls_LDADD += $(LIB_SELINUX)
243src_ls_LDADD += $(LIB_SMACK)
244src_mkdir_LDADD += $(LIB_SELINUX)
245src_mkdir_LDADD += $(LIB_SMACK)
246src_mkfifo_LDADD += $(LIB_SELINUX)
247src_mkfifo_LDADD += $(LIB_SMACK)
248src_mknod_LDADD += $(LIB_SELINUX)
249src_mknod_LDADD += $(LIB_SMACK)
250src_runcon_LDADD += $(LIB_SELINUX)
251src_stat_LDADD += $(LIB_SELINUX)
252
253# for nvlist_lookup_uint64_array
254src_stat_LDADD += $(LIB_NVPAIR)
255
256# for gettime, settime, tempname, utimecmp, utimens
257copy_ldadd += $(CLOCK_TIME_LIB)
258src_date_LDADD += $(CLOCK_TIME_LIB)
259src_ginstall_LDADD += $(CLOCK_TIME_LIB)
260src_ln_LDADD += $(CLOCK_TIME_LIB)
261src_ls_LDADD += $(CLOCK_TIME_LIB)
262src_mktemp_LDADD += $(CLOCK_TIME_LIB)
263src_pr_LDADD += $(CLOCK_TIME_LIB)
264src_sort_LDADD += $(CLOCK_TIME_LIB)
265src_split_LDADD += $(CLOCK_TIME_LIB)
266src_tac_LDADD += $(CLOCK_TIME_LIB)
267src_timeout_LDADD += $(TIMER_TIME_LIB)
268src_touch_LDADD += $(CLOCK_TIME_LIB)
269
270# for gethrxtime
271src_dd_LDADD += $(GETHRXTIME_LIB)
272
273# for cap_get_file
274src_ls_LDADD += $(LIB_CAP)
275
276# for fdatasync
277src_dd_LDADD += $(FDATASYNC_LIB)
278src_shred_LDADD += $(FDATASYNC_LIB)
279src_sync_LDADD += $(FDATASYNC_LIB)
280
281# for xnanosleep
282src_sleep_LDADD += $(NANOSLEEP_LIB)
283src_sort_LDADD += $(NANOSLEEP_LIB)
284src_tail_LDADD += $(NANOSLEEP_LIB)
285
286# for various GMP functions
287src_expr_LDADD += $(LIBGMP)
288src_factor_LDADD += $(LIBGMP)
289
290# for getloadavg
291src_uptime_LDADD += $(GETLOADAVG_LIBS)
292
293# for various ACL functions
294copy_ldadd += $(LIB_ACL)
295src_ls_LDADD += $(FILE_HAS_ACL_LIB)
296
297# for various xattr functions
298copy_ldadd += $(LIB_XATTR)
299
300# for print_unicode_char
301src_printf_LDADD += $(LIBICONV)
302
303# for libcrypto hash routines
304src_md5sum_LDADD += $(LIB_CRYPTO)
305src_sort_LDADD += $(LIB_CRYPTO)
306src_sha1sum_LDADD += $(LIB_CRYPTO)
307src_sha224sum_LDADD += $(LIB_CRYPTO)
308src_sha256sum_LDADD += $(LIB_CRYPTO)
309src_sha384sum_LDADD += $(LIB_CRYPTO)
310src_sha512sum_LDADD += $(LIB_CRYPTO)
311src_cksum_LDADD += $(LIB_CRYPTO)
312
313# for canon_host
314src_pinky_LDADD += $(GETADDRINFO_LIB)
315src_who_LDADD += $(GETADDRINFO_LIB)
316
317# for gethostname, uname
318src_hostname_LDADD += $(GETHOSTNAME_LIB)
319src_uname_LDADD += $(GETHOSTNAME_LIB)
320
321# for read_utmp
322src_pinky_LDADD += $(READUTMP_LIB)
323src_uptime_LDADD += $(READUTMP_LIB)
324src_users_LDADD += $(READUTMP_LIB)
325src_who_LDADD += $(READUTMP_LIB)
326
327# for strsignal
328src_kill_LDADD += $(LIBTHREAD)
329
330# for pthread-cond, pthread-mutex, pthread-thread
331src_sort_LDADD += $(LIBPMULTITHREAD)
332
333# for pthread_sigmask
334src_sort_LDADD += $(PTHREAD_SIGMASK_LIB)
335
336# Get the release year from lib/version-etc.c.
337RELEASE_YEAR = \
338  `sed -n '/.*COPYRIGHT_YEAR = \([0-9][0-9][0-9][0-9]\) };/s//\1/p' \
339    $(top_srcdir)/lib/version-etc.c`
340
341selinux_sources = \
342  src/selinux.c \
343  src/selinux.h
344
345copy_sources = \
346  src/copy.c \
347  src/cp-hash.c \
348  src/force-link.c \
349  src/force-link.h
350
351# Use 'ginstall' in the definition of PROGRAMS and in dependencies to avoid
352# confusion with the 'install' target.  The install rule transforms 'ginstall'
353# to install before applying any user-specified name transformations.
354
355# Don't apply prefix transformations to libstdbuf shared lib
356# as that's not generally needed, and we need to reference the
357# name directly in LD_PRELOAD etc.  In general it's surprising
358# that $(transform) is applied to libexec at all given that is
359# for internal package naming, not privy to $(transform).
360
361transform = s/ginstall/install/;/libstdbuf/!$(program_transform_name)
362
363src_ginstall_SOURCES = src/install.c src/prog-fprintf.c $(copy_sources) \
364		       $(selinux_sources)
365
366# This is for the '[' program.  Automake transliterates '[' and '/' to '_'.
367src___SOURCES = src/lbracket.c
368
369nodist_src_coreutils_SOURCES = src/coreutils.h
370src_coreutils_SOURCES = src/coreutils.c
371
372src_cp_SOURCES = src/cp.c $(copy_sources) $(selinux_sources)
373src_dir_SOURCES = src/ls.c src/ls-dir.c
374src_env_SOURCES = src/env.c src/operand2sig.c
375src_vdir_SOURCES = src/ls.c src/ls-vdir.c
376src_id_SOURCES = src/id.c src/group-list.c
377src_groups_SOURCES = src/groups.c src/group-list.c
378src_ls_SOURCES = src/ls.c src/ls-ls.c
379src_ln_SOURCES = src/ln.c \
380  src/force-link.c src/force-link.h \
381  src/relpath.c src/relpath.h
382src_chown_SOURCES = src/chown.c src/chown-core.c
383src_chgrp_SOURCES = src/chgrp.c src/chown-core.c
384src_kill_SOURCES = src/kill.c src/operand2sig.c
385src_realpath_SOURCES = src/realpath.c src/relpath.c src/relpath.h
386src_timeout_SOURCES = src/timeout.c src/operand2sig.c
387
388src_mv_SOURCES = src/mv.c src/remove.c $(copy_sources) $(selinux_sources)
389src_rm_SOURCES = src/rm.c src/remove.c
390
391src_mkdir_SOURCES = src/mkdir.c src/prog-fprintf.c $(selinux_sources)
392src_rmdir_SOURCES = src/rmdir.c src/prog-fprintf.c
393
394src_mkfifo_SOURCES = src/mkfifo.c $(selinux_sources)
395src_mknod_SOURCES = src/mknod.c $(selinux_sources)
396
397src_df_SOURCES = src/df.c src/find-mount-point.c
398src_stat_SOURCES = src/stat.c src/find-mount-point.c
399
400src_uname_SOURCES = src/uname.c src/uname-uname.c
401src_arch_SOURCES = src/uname.c src/uname-arch.c
402
403src_cut_SOURCES = src/cut.c src/set-fields.c
404src_numfmt_SOURCES = src/numfmt.c src/set-fields.c
405
406src_split_SOURCES = src/split.c src/temp-stream.c
407src_tac_SOURCES = src/tac.c src/temp-stream.c
408
409src_tail_SOURCES = src/tail.c src/iopoll.c
410src_tee_SOURCES = src/tee.c src/iopoll.c
411
412src_sum_SOURCES = src/sum.c src/sum.h src/digest.c
413src_sum_CPPFLAGS = -DHASH_ALGO_SUM=1 $(AM_CPPFLAGS)
414
415src_md5sum_SOURCES = src/digest.c
416src_md5sum_CPPFLAGS = -DHASH_ALGO_MD5=1 $(AM_CPPFLAGS)
417src_sha1sum_SOURCES = src/digest.c
418src_sha1sum_CPPFLAGS = -DHASH_ALGO_SHA1=1 $(AM_CPPFLAGS)
419src_sha224sum_SOURCES = src/digest.c
420src_sha224sum_CPPFLAGS = -DHASH_ALGO_SHA224=1 $(AM_CPPFLAGS)
421src_sha256sum_SOURCES = src/digest.c
422src_sha256sum_CPPFLAGS = -DHASH_ALGO_SHA256=1 $(AM_CPPFLAGS)
423src_sha384sum_SOURCES = src/digest.c
424src_sha384sum_CPPFLAGS = -DHASH_ALGO_SHA384=1 $(AM_CPPFLAGS)
425src_sha512sum_SOURCES = src/digest.c
426src_sha512sum_CPPFLAGS = -DHASH_ALGO_SHA512=1 $(AM_CPPFLAGS)
427src_b2sum_CPPFLAGS = -DHASH_ALGO_BLAKE2=1 -DHAVE_CONFIG_H $(AM_CPPFLAGS)
428src_b2sum_SOURCES = src/digest.c \
429		    src/blake2/blake2.h src/blake2/blake2-impl.h \
430		    src/blake2/blake2b-ref.c \
431		    src/blake2/b2sum.c src/blake2/b2sum.h
432
433src_cksum_SOURCES = $(src_b2sum_SOURCES) src/sum.c src/sum.h \
434		    src/cksum.c src/cksum.h src/crctab.c
435src_cksum_CPPFLAGS = -DHASH_ALGO_CKSUM=1 -DHAVE_CONFIG_H $(AM_CPPFLAGS)
436if USE_PCLMUL_CRC32
437noinst_LIBRARIES += src/libcksum_pclmul.a
438src_libcksum_pclmul_a_SOURCES = src/cksum_pclmul.c src/cksum.h
439cksum_pclmul_ldadd = src/libcksum_pclmul.a
440src_cksum_LDADD += $(cksum_pclmul_ldadd)
441src_libcksum_pclmul_a_CFLAGS = -mavx -mpclmul $(AM_CFLAGS)
442endif
443
444src_base64_SOURCES = src/basenc.c
445src_base64_CPPFLAGS = -DBASE_TYPE=64 $(AM_CPPFLAGS)
446src_base32_SOURCES = src/basenc.c
447src_base32_CPPFLAGS = -DBASE_TYPE=32 $(AM_CPPFLAGS)
448src_basenc_SOURCES = src/basenc.c
449src_basenc_CPPFLAGS = -DBASE_TYPE=42 $(AM_CPPFLAGS)
450
451src_expand_SOURCES = src/expand.c src/expand-common.c
452src_unexpand_SOURCES = src/unexpand.c src/expand-common.c
453
454src_wc_SOURCES = src/wc.c
455if USE_AVX2_WC_LINECOUNT
456noinst_LIBRARIES += src/libwc_avx2.a
457src_libwc_avx2_a_SOURCES = src/wc_avx2.c
458wc_avx2_ldadd = src/libwc_avx2.a
459src_wc_LDADD += $(wc_avx2_ldadd)
460src_libwc_avx2_a_CFLAGS = -mavx2 $(AM_CFLAGS)
461endif
462
463# Ensure we don't link against libcoreutils.a as that lib is
464# not compiled with -fPIC which causes issues on 64 bit at least
465src_libstdbuf_so_LDADD = $(LIBINTL)
466
467# Note libstdbuf is only compiled if GCC is available
468# (as per the check in configure.ac), so these flags should be available.
469# libtool is probably required to relax this dependency.
470src_libstdbuf_so_LDFLAGS = -shared
471src_libstdbuf_so_CFLAGS = -fPIC $(AM_CFLAGS)
472
473BUILT_SOURCES += src/coreutils.h
474if SINGLE_BINARY
475# Single binary dependencies
476src_coreutils_CFLAGS = -DSINGLE_BINARY $(AM_CFLAGS)
477#src_coreutils_LDFLAGS = $(AM_LDFLAGS)
478src_coreutils_LDADD = $(single_binary_deps) $(LDADD) $(single_binary_libs)
479src_coreutils_DEPENDENCIES = $(LDADD) $(single_binary_deps)
480
481include $(top_srcdir)/src/single-binary.mk
482
483# Creates symlinks or shebangs to the installed programs when building
484# coreutils single binary.
485EXTRA_src_coreutils_DEPENDENCIES = src/coreutils_$(single_binary_install_type)
486endif SINGLE_BINARY
487
488CLEANFILES += src/coreutils_symlinks
489src/coreutils_symlinks: Makefile
490	$(AM_V_GEN)touch $@
491	$(AM_V_at)${MKDIR_P} src
492	$(AM_V_at)for i in x $(single_binary_progs); do \
493		test $$i = x && continue; \
494		rm -f src/$$i$(EXEEXT) || exit $$?; \
495		$(LN_S) -s coreutils$(EXEEXT) src/$$i$(EXEEXT) || exit $$?; \
496	done
497
498CLEANFILES += src/coreutils_shebangs
499src/coreutils_shebangs: Makefile
500	$(AM_V_GEN)touch $@
501	$(AM_V_at)${MKDIR_P} src
502	$(AM_V_at)for i in x $(single_binary_progs); do \
503		test $$i = x && continue; \
504		rm -f src/$$i$(EXEEXT) || exit $$?; \
505		printf '#!%s --coreutils-prog-shebang=%s\n' \
506			$(abs_top_builddir)/src/coreutils$(EXEEXT) $$i \
507			>src/$$i$(EXEEXT) || exit $$?; \
508		chmod a+x,a-w src/$$i$(EXEEXT) || exit $$?; \
509	done
510
511clean-local:
512	$(AM_V_at)for i in x $(single_binary_progs); do \
513		test $$i = x && continue; \
514		rm -f src/$$i$(EXEEXT) || exit $$?; \
515	done
516
517
518BUILT_SOURCES += src/dircolors.h
519src/dircolors.h: src/dcgen src/dircolors.hin
520	$(AM_V_GEN)rm -f $@ $@-t
521	$(AM_V_at)${MKDIR_P} src
522	$(AM_V_at)$(PERL) -w -- $(srcdir)/src/dcgen \
523				$(srcdir)/src/dircolors.hin > $@-t
524	$(AM_V_at)chmod a-w $@-t
525	$(AM_V_at)mv $@-t $@
526
527# This file is built by maintainers.  It's architecture-independent,
528# and it needs to be built on a widest-known-int architecture, so it's
529# built only if absent.  It is not cleaned because we don't want to
530# insist that maintainers must build on hosts that support the widest
531# known ints (currently 128-bit).
532BUILT_SOURCES += $(top_srcdir)/src/primes.h
533$(top_srcdir)/src/primes.h:
534	$(AM_V_at)${MKDIR_P} src
535	$(MAKE) src/make-prime-list$(EXEEXT)
536	$(AM_V_GEN)rm -f $@ $@-t
537	$(AM_V_at)src/make-prime-list$(EXEEXT) 5000 > $@-t
538	$(AM_V_at)chmod a-w $@-t
539	$(AM_V_at)mv $@-t $@
540
541# false exits nonzero even with --help or --version.
542# test doesn't support --help or --version.
543# Tell automake to exempt then from that installcheck test.
544AM_INSTALLCHECK_STD_OPTIONS_EXEMPT = src/false src/test
545
546# Compare fs.h with the list of file system names/magic-numbers in the
547# Linux statfs man page.  This target prints any new name/number pairs.
548# Also compare against /usr/include/linux/magic.h
549.PHONY: src/fs-magic-compare
550src/fs-magic-compare: src/fs-magic src/fs-kernel-magic src/fs-def
551	@join -v1 -t@ src/fs-magic src/fs-def
552	@join -v1 -t@ src/fs-kernel-magic src/fs-def
553
554CLEANFILES += src/fs-def
555src/fs-def: src/fs.h
556	@grep '^# *define ' src/fs.h | $(ASSORT) > $@-t && mv $@-t $@
557
558# Massage bits of the statfs man page and definitions from
559# /usr/include/linux/magic.h to be in a form consistent with what's in fs.h.
560fs_normalize_perl_subst =			\
561  -e 's/MINIX_SUPER_MAGIC\b/MINIX/;'		\
562  -e 's/MINIX_SUPER_MAGIC2\b/MINIX_30/;'	\
563  -e 's/MINIX2_SUPER_MAGIC\b/MINIX_V2/;'	\
564  -e 's/MINIX2_SUPER_MAGIC2\b/MINIX_V2_30/;'	\
565  -e 's/MINIX3_SUPER_MAGIC\b/MINIX_V3/;'	\
566  -e 's/CIFS_MAGIC_NUMBER/CIFS/;'		\
567  -e 's/AFS_FS/KAFS/;'				\
568  -e 's/(_SUPER)?_MAGIC//;'			\
569  -e 's/\s+0x(\S+)/" 0x" . uc $$1/e;'		\
570  -e 's/(\s+0x)(\X{2})\b/$${1}00$$2/;'		\
571  -e 's/(\s+0x)(\X{3})\b/$${1}0$$2/;'		\
572  -e 's/(\s+0x)(\X{6})\b/$${1}00$$2/;'		\
573  -e 's/(\s+0x)(\X{7})\b/$${1}0$$2/;'		\
574  -e 's/^\s+//;'				\
575  -e 's/^\043define\s+//;'			\
576  -e 's/^_(XIAFS)/$$1/;'			\
577  -e 's/^USBDEVICE/USBDEVFS/;'			\
578  -e 's/NTFS_SB/NTFS/;'				\
579  -e 's/^/\043 define S_MAGIC_/;'		\
580  -e 's,\s*/\* .*? \*/,,;'
581
582CLEANFILES += src/fs-magic
583src/fs-magic: Makefile
584	@MANPAGER= man statfs \
585	  |perl -ne '/File system types:/.../Nobody kno/ and print'	\
586	  |grep 0x | perl -p						\
587	    $(fs_normalize_perl_subst)					\
588	  | grep -Ev 'S_MAGIC_EXT[34]|STACK_END'			\
589	  | $(ASSORT)							\
590	  > $@-t && mv $@-t $@
591
592DISTCLEANFILES += src/fs-latest-magic.h
593# This rule currently gets the latest header, but probably isn't general
594# enough to enable by default.
595#	@kgit='https://git.kernel.org/cgit/linux/kernel/git'; \
596#	wget -q $$kgit/torvalds/linux.git/plain/include/uapi/linux/magic.h \
597#	  -O $@
598src/fs-latest-magic.h:
599	@touch $@
600
601CLEANFILES += src/fs-kernel-magic
602src/fs-kernel-magic: Makefile src/fs-latest-magic.h
603	@perl -ne '/^#define.*0x/ and print'				\
604	  /usr/include/linux/magic.h src/fs-latest-magic.h		\
605	  | perl -p							\
606	    $(fs_normalize_perl_subst)					\
607	  | grep -Ev 'S_MAGIC_EXT[34]|STACK_END'			\
608	  | $(ASSORT) -u						\
609	  > $@-t && mv $@-t $@
610
611BUILT_SOURCES += src/fs-is-local.h
612src/fs-is-local.h: src/stat.c src/extract-magic
613	$(AM_V_GEN)rm -f $@
614	$(AM_V_at)${MKDIR_P} src
615	$(AM_V_at)$(PERL) $(srcdir)/src/extract-magic \
616			  --local $(srcdir)/src/stat.c > $@t
617	$(AM_V_at)chmod a-w $@t
618	$(AM_V_at)mv $@t $@
619
620BUILT_SOURCES += src/fs.h
621src/fs.h: src/stat.c src/extract-magic
622	$(AM_V_GEN)rm -f $@
623	$(AM_V_at)${MKDIR_P} src
624	$(AM_V_at)$(PERL) $(srcdir)/src/extract-magic \
625			  $(srcdir)/src/stat.c > $@t
626	$(AM_V_at)chmod a-w $@t
627	$(AM_V_at)mv $@t $@
628
629BUILT_SOURCES += src/version.c
630src/version.c: Makefile
631	$(AM_V_GEN)rm -f $@
632	$(AM_V_at)${MKDIR_P} src
633	$(AM_V_at)printf '#include <config.h>\n' > $@t
634	$(AM_V_at)printf 'char const *Version = "$(PACKAGE_VERSION)";\n' >> $@t
635	$(AM_V_at)chmod a-w $@t
636	$(AM_V_at)mv $@t $@
637
638BUILT_SOURCES += src/version.h
639src/version.h: Makefile
640	$(AM_V_GEN)rm -f $@
641	$(AM_V_at)${MKDIR_P} src
642	$(AM_V_at)printf 'extern char const *Version;\n' > $@t
643	$(AM_V_at)chmod a-w $@t
644	$(AM_V_at)mv $@t $@
645
646# Generates a list of macro invocations like:
647#   SINGLE_BINARY_PROGRAM(program_name_str, main_name)
648# once for each program list on $(single_binary_progs). Note that
649# for [ the macro invocation is:
650#   SINGLE_BINARY_PROGRAM("[", _)
651DISTCLEANFILES += src/coreutils.h
652src/coreutils.h: Makefile
653	$(AM_V_GEN)rm -f $@
654	$(AM_V_at)${MKDIR_P} src
655	$(AM_V_at)for prog in x $(single_binary_progs); do	\
656	  test $$prog = x && continue;				\
657	  prog=`basename $$prog`;				\
658	  main=`echo $$prog | tr '[' '_'`;			\
659	  echo "SINGLE_BINARY_PROGRAM(\"$$prog\", $$main)";	\
660	done | sort > $@t
661	$(AM_V_at)chmod a-w $@t
662	$(AM_V_at)mv $@t $@
663
664DISTCLEANFILES += src/version.c src/version.h
665MAINTAINERCLEANFILES += $(BUILT_SOURCES)
666
667all_programs = \
668    $(bin_PROGRAMS) \
669    $(bin_SCRIPTS) \
670    $(EXTRA_PROGRAMS)
671
672pm = progs-makefile
673pr = progs-readme
674# Ensure that the list of programs in README matches the list
675# of programs we can build.
676check-local: check-README check-duplicate-no-install
677.PHONY: check-README
678check-README:
679	$(AM_V_GEN)rm -rf $(pr) $(pm)
680	$(AM_V_at)echo $(all_programs) \
681	 | tr -s ' ' '\n' \
682	 | sed -e 's,$(EXEEXT)$$,,' \
683	       -e 's,^src/,,' \
684	       -e 's/^ginstall$$/install/' \
685	 | sed /libstdbuf/d \
686	 | $(ASSORT) -u > $(pm) && \
687	sed -n '/^The programs .* are:/,/^[a-zA-Z]/p' $(top_srcdir)/README \
688	  | sed -n '/^   */s///p' | tr -s ' ' '\n' > $(pr)
689	$(AM_V_at)diff $(pm) $(pr) && rm -rf $(pr) $(pm)
690
691# Ensure that a by-default-not-installed program (listed in
692# $(no_install__progs) is not also listed as another $(EXTRA_PROGRAMS)
693# entry, because if that were to happen, it *would* be installed
694# by default.
695.PHONY: check-duplicate-no-install
696check-duplicate-no-install:
697	$(AM_V_GEN)test -z "`echo '$(EXTRA_PROGRAMS)' | tr ' ' '\n' | uniq -d`"
698
699# Use the just-built 'ginstall', when not cross-compiling.
700if CROSS_COMPILING
701cu_install_program = @INSTALL@
702else
703cu_install_program = src/ginstall
704endif
705INSTALL = $(cu_install_program) -c
706