Merge branch 'maint'
[platform/upstream/automake.git] / lib / am / progs.am
1 ## automake - create Makefile.in from Makefile.am
2 ## Copyright (C) 1994-2012 Free Software Foundation, Inc.
3
4 ## This program is free software; you can redistribute it and/or modify
5 ## it under the terms of the GNU General Public License as published by
6 ## the Free Software Foundation; either version 2, or (at your option)
7 ## any later version.
8
9 ## This program is distributed in the hope that it will be useful,
10 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
11 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 ## GNU General Public License for more details.
13
14 ## You should have received a copy of the GNU General Public License
15 ## along with this program.  If not, see <http://www.gnu.org/licenses/>.
16
17 ## ------------ ##
18 ## Installing.  ##
19 ## ------------ ##
20
21 if %?INSTALL%
22 am__installdirs += "$(DESTDIR)$(%NDIR%dir)"
23 .PHONY install-%EXEC?exec:data%-am: install-%DIR%PROGRAMS
24 install-%DIR%PROGRAMS: $(%DIR%_PROGRAMS)
25         @$(NORMAL_INSTALL)
26 ## Funny invocation because Makefile variable can be empty, leading to
27 ## a syntax error in sh.
28         @list='$(%DIR%_PROGRAMS)'; test -n "$(%NDIR%dir)" || list=; \
29         if test -n "$$list"; then \
30           echo " $(MKDIR_P) '$(DESTDIR)$(%NDIR%dir)'"; \
31           $(MKDIR_P) "$(DESTDIR)$(%NDIR%dir)" || exit 1; \
32         fi; \
33         for p in $$list; do echo "$$p $$p"; done | \
34 ## On Cygwin with libtool test won't see 'foo.exe' but instead 'foo'.
35 ## So we check for both.
36         sed 's/$(EXEEXT)$$//' | \
37         while read p p1; do if test -f $$p%LIBTOOL? || test -f $$p1%; \
38           then echo "$$p"; echo "$$p"; else :; fi; \
39         done | \
40 ## We now have a list of sourcefile pairs, separated by newline.
41 ## Turn that into "sourcefile source_base target_dir xformed_target_base",
42 ## with newlines being turned into spaces in a second step.
43         sed -e 'p;s,.*/,,;n;h' -e '%BASE?s|.*|.|:s|[^/]*$$||; s|^$$|.|%' \
44             -e 'p;x;s,.*/,,;s/$(EXEEXT)$$//;$(transform);s/$$/$(EXEEXT)/' | \
45         sed 'N;N;N;s,\n, ,g' | \
46 ## The following awk script turns that into one line containing directories
47 ## and then lines of 'type target_name_or_directory sources ...', with type
48 ## 'd' designating directories, and 'f' files.
49         $(AWK) 'BEGIN { files["."] = ""; dirs["."] = 1 } \
50           { d=$$3; if (dirs[d] != 1) { print "d", d; dirs[d] = 1 } \
51             if ($$2 == $$4) files[d] = files[d] " " $$1; \
52             else { print "f", $$3 "/" $$4, $$1; } } \
53           END { for (d in files) print "f", d, files[d] }' | \
54         while read type dir files; do \
55 ?!BASE?   case $$type in \
56 ?!BASE?   d) echo " $(MKDIR_P) '$(DESTDIR)$(%NDIR%dir)/$$dir'"; \
57 ?!BASE?      $(MKDIR_P) "$(DESTDIR)$(%NDIR%dir)/$$dir" || exit $$?;; \
58 ?!BASE?   f) \
59             if test "$$dir" = .; then dir=; else dir=/$$dir; fi; \
60             test -z "$$files" || { \
61 ?!LIBTOOL?            echo " $(INSTALL_PROGRAM_ENV) $(INSTALL_PROGRAM) $$files '$(DESTDIR)$(%NDIR%dir)$$dir'"; \
62 ?!LIBTOOL?            $(INSTALL_PROGRAM_ENV) $(INSTALL_PROGRAM) $$files "$(DESTDIR)$(%NDIR%dir)$$dir" || exit $$?; \
63 ## Note that we explicitly set the libtool mode.  This avoids any
64 ## lossage if the install program doesn't have a name that libtool
65 ## expects.
66 ?LIBTOOL?           echo " $(INSTALL_PROGRAM_ENV) $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL_PROGRAM) $$files '$(DESTDIR)$(%NDIR%dir)$$dir'"; \
67 ?LIBTOOL?           $(INSTALL_PROGRAM_ENV) $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL_PROGRAM) $$files "$(DESTDIR)$(%NDIR%dir)$$dir" || exit $$?; \
68             } \
69 ?!BASE?   ;; esac \
70         ; done
71
72 endif %?INSTALL%
73
74
75 ## -------------- ##
76 ## Uninstalling.  ##
77 ## -------------- ##
78
79 if %?INSTALL%
80 .PHONY uninstall-am: uninstall-%DIR%PROGRAMS
81 uninstall-%DIR%PROGRAMS:
82         @$(NORMAL_UNINSTALL)
83         @list='$(%DIR%_PROGRAMS)'; test -n "$(%NDIR%dir)" || list=; \
84         files=`for p in $$list; do echo "$$p"; done | \
85 ## Remove any leading directory before applying $(transform),
86 ## but keep the directory part in the hold buffer, in order to
87 ## reapply it again afterwards in the nobase case.  Append $(EXEEXT).
88           sed -e 'h;s,^.*/,,;s/$(EXEEXT)$$//;$(transform)' \
89               -e 's/$$/$(EXEEXT)/'%BASE? : -e 'x;s,[^/]*$$,,;G;s,\n,,'%`; \
90         test -n "$$list" || exit 0; \
91         echo " ( cd '$(DESTDIR)$(%NDIR%dir)' && rm -f" $$files ")"; \
92         cd "$(DESTDIR)$(%NDIR%dir)" && rm -f $$files
93 endif %?INSTALL%
94
95
96 ## ---------- ##
97 ## Cleaning.  ##
98 ## ---------- ##
99
100 .PHONY clean-am: clean-%DIR%PROGRAMS
101 clean-%DIR%PROGRAMS:
102 ?!LIBTOOL?      -test -z "$(%DIR%_PROGRAMS)" || rm -f $(%DIR%_PROGRAMS)
103 ## Under Cygwin, we build 'program$(EXEEXT)'.  However, if this
104 ## program uses a Libtool library, Libtool will move it in
105 ## '_libs/program$(EXEEXT)' and create a 'program' wrapper (without
106 ## '$(EXEEXT)').  Therefore, if Libtool is used, we must try to erase
107 ## both 'program$(EXEEXT)' and 'program'.
108 ## Cleaning the '_libs/' or '.libs/' directory is done from clean-libtool.
109 ## FIXME: In the future (i.e., when it works) it would be nice to delegate
110 ## this task to "libtool --mode=clean".
111 ?LIBTOOL?       @list='$(%DIR%_PROGRAMS)'; test -n "$$list" || exit 0; \
112 ?LIBTOOL?       echo " rm -f" $$list; \
113 ?LIBTOOL?       rm -f $$list || exit $$?; \
114 ?LIBTOOL?       test -n "$(EXEEXT)" || exit 0; \
115 ?LIBTOOL?       list=`for p in $$list; do echo "$$p"; done | sed 's/$(EXEEXT)$$//'`; \
116 ?LIBTOOL?       echo " rm -f" $$list; \
117 ?LIBTOOL?       rm -f $$list
118
119
120 ## ---------- ##
121 ## Checking.  ##
122 ## ---------- ##
123
124 if %?CK-OPTS%
125 .PHONY installcheck-am: installcheck-%DIR%PROGRAMS
126 installcheck-%DIR%PROGRAMS: $(%DIR%_PROGRAMS)
127         bad=0; pid=$$$$; list="$(%DIR%_PROGRAMS)"; for p in $$list; do \
128           case ' $(AM_INSTALLCHECK_STD_OPTIONS_EXEMPT) ' in \
129 ## Match $(srcdir)/$$p in addition to $$p because Sun make might rewrite
130 ## filenames in AM_INSTALLCHECK_STD_OPTIONS_EXEMPT during VPATH builds.
131            *" $$p "* | *" $(srcdir)/$$p "*) continue;; \
132           esac; \
133 ## Strip the directory and $(EXEEXT) before applying $(transform).
134           f=`echo "$$p" | \
135              sed 's,^.*/,,;s/$(EXEEXT)$$//;$(transform);s/$$/$(EXEEXT)/'`; \
136 ## Insert the directory back if nobase_ is used.
137 ?!BASE?   f=`echo "$$p" | sed 's|[^/]*$$||'`"$$f"; \
138           for opt in --help --version; do \
139             if "$(DESTDIR)$(%NDIR%dir)/$$f" $$opt >c$${pid}_.out \
140                  2>c$${pid}_.err </dev/null \
141                  && test -n "`cat c$${pid}_.out`" \
142                  && test -z "`cat c$${pid}_.err`"; then :; \
143             else echo "$$f does not support $$opt" 1>&2; bad=1; fi; \
144           done; \
145         done; rm -f c$${pid}_.???; exit $$bad
146 endif %?CK-OPTS%