missing: shellcheck disable=SC2006,SC2268
[automake.git] / lib / am / python.am
blob5ef447a100537967ca4e084e1aa2d6b554c0c756
1 ## automake - create Makefile.in from Makefile.am
2 ## Copyright (C) 1999-2024 Free Software Foundation, Inc.
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.
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.
14 ## You should have received a copy of the GNU General Public License
15 ## along with this program.  If not, see <https://www.gnu.org/licenses/>.
17 if %?INSTALL%
18 include inst-vars.am
19 endif %?INSTALL%
21 ?FIRST?am__py_compile = PYTHON=$(PYTHON) $(SHELL) $(py_compile)
23 ## ------------ ##
24 ## Installing.  ##
25 ## ------------ ##
27 if %?INSTALL%
28 am__installdirs += "$(DESTDIR)$(%NDIR%dir)"
29 ?EXEC?.PHONY install-exec-am: install-%DIR%PYTHON
30 ?!EXEC?.PHONY install-data-am: install-%DIR%PYTHON
31 install-%DIR%PYTHON: $(%DIR%_PYTHON)
32         @$(NORMAL_INSTALL)
33 if %?BASE%
34         @list='$(%DIR%_PYTHON)'; dlist=; list2=; test -n "$(%NDIR%dir)" || list=; \
35         if test -n "$$list"; then \
36           echo " $(MKDIR_P) '$(DESTDIR)$(%NDIR%dir)'"; \
37           $(MKDIR_P) "$(DESTDIR)$(%NDIR%dir)" || exit 1; \
38         fi; \
39         for p in $$list; do \
40 ## A file can be in the source directory or the build directory.
41           if test -f "$$p"; then b=; else b="$(srcdir)/"; fi; \
42           if test -f $$b$$p; then \
43 ## Compute basename of source file.  Unless this is a nobase_ target, we
44 ## want to install 'python/foo.py' as '$(DESTDIR)$(%NDIR%dir)/foo.py',
45 ## not '$(DESTDIR)$(%NDIR%dir)/python/foo.py'.
46             $(am__strip_dir) \
47             dlist="$$dlist $$f"; \
48             list2="$$list2 $$b$$p"; \
49           else :; fi; \
50         done; \
51         for file in $$list2; do echo $$file; done | $(am__base_list) | \
52         while read files; do \
53 ## Don't perform translation, since script name is important.
54           echo " $(INSTALL_DATA) $$files '$(DESTDIR)$(%NDIR%dir)'"; \
55           $(INSTALL_DATA) $$files "$(DESTDIR)$(%NDIR%dir)" || exit $$?; \
56         done || exit $$?; \
57 ## Byte-compile must be done at install time, since file times are
58 ## encoded in the actual files.
59         if test -n "$$dlist"; then \
60           $(am__py_compile) --destdir "$(DESTDIR)" \
61                             --basedir "$(%NDIR%dir)" $$dlist; \
62         else :; fi
63 else !%?BASE%
64         @list='$(%DIR%_PYTHON)'; test -n "$(%NDIR%dir)" || list=; \
65         if test -n "$$list"; then \
66           echo " $(MKDIR_P) '$(DESTDIR)$(%NDIR%dir)'"; \
67           $(MKDIR_P) "$(DESTDIR)$(%NDIR%dir)" || exit 1; \
68         fi; \
69         $(am__nobase_list) | { while read dir files; do \
70           xfiles=; for p in $$files; do \
71 ## A file can be in the source directory or the build directory.
72             if test -f "$$p"; then b=; else b="$(srcdir)/"; fi; \
73             if test -f "$$b$$p"; then xfiles="$$xfiles $$b$$p"; dlist="$$dlist $$p"; \
74             else :; fi; done; \
75           test -z "$$xfiles" || { \
76             test "x$$dir" = x. || { \
77               echo "$(MKDIR_P) '$(DESTDIR)$(%NDIR%dir)/$$dir'"; \
78               $(MKDIR_P) "$(DESTDIR)$(%NDIR%dir)/$$dir"; }; \
79 ## Don't perform translation, since script name is important.
80             echo " $(INSTALL_DATA) $$xfiles '$(DESTDIR)$(%NDIR%dir)/$$dir'"; \
81             $(INSTALL_DATA) $$xfiles "$(DESTDIR)$(%NDIR%dir)/$$dir" || exit $$?; }; \
82         done; \
83 ## Byte-compile must be done at install time, since file times are
84 ## encoded in the actual files.
85         if test -n "$$dlist"; then \
86           $(am__py_compile) --destdir "$(DESTDIR)" \
87                             --basedir "$(%NDIR%dir)" $$dlist; \
88         else :; fi; }
89 endif !%?BASE%
90 endif %?INSTALL%
93 ## -------------- ##
94 ## Uninstalling.  ##
95 ## -------------- ##
97 ?FIRST?am__pep3147_tweak = \
98 ?FIRST?  sed -e 's|\.py$$||' -e 's|[^/]*$$|__pycache__/&.*.pyc __pycache__/&.*.pyo|'
100 if %?INSTALL%
102 .PHONY uninstall-am: uninstall-%DIR%PYTHON
103 uninstall-%DIR%PYTHON:
104         @$(NORMAL_UNINSTALL)
105         @list='$(%DIR%_PYTHON)'; test -n "$(%NDIR%dir)" || list=; \
106 ?BASE?  py_files=`for p in $$list; do echo $$p; done | sed -e 's|^.*/||'`; \
107 ?!BASE? $(am__nobase_strip_setup); py_files=`$(am__nobase_strip)`; \
108         test -n "$$py_files" || exit 0; \
109         dir='$(DESTDIR)$(%NDIR%dir)'; \
110 ## Also remove the .pyc and .pyo byte compiled versions.
111         pyc_files=`echo "$$py_files" | sed 's|$$|c|'`; \
112         pyo_files=`echo "$$py_files" | sed 's|$$|o|'`; \
113         st=0; \
114         for files in "$$py_files" "$$pyc_files" "$$pyo_files"; do \
115           $(am__uninstall_files_from_dir) || st=$$?; \
116         done; \
117 ## This is somewhat tricky, because for newer pythons we have to take PEP-3147
118 ## into account.  Avoid exceeding the command-line length limit.
119         dir='$(DESTDIR)$(%NDIR%dir)'; \
120         files=`echo "$$py_files" | $(am__pep3147_tweak)`; \
121         $(am__uninstall_files_from_dir) || st=$$?; \
122         exit $$st
123 endif %?INSTALL%
126 ## ---------- ##
127 ## Cleaning.  ##
128 ## ---------- ##
130 ## There is nothing to clean here since files are
131 ## byte-compiled when (and where) they are installed.
133 ## -------------- ##
134 ## Distributing.  ##
135 ## -------------- ##
137 if %?DIST%
138 DIST_COMMON += %DISTVAR%
139 endif %?DIST%