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