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