lalsuite_python.am 4.68 KB
Newer Older
1
SUFFIXES = .py
2

3
.PHONY: pymodule-all-local
4
.PHONY: pyscripts-all-local
5
.PHONY: pymodule-mostlyclean-local
6
.PHONY: pyscripts-mostlyclean-local
7
.PHONY: py-mostlyclean-local
8
.PHONY: pybin-install-exec-local
9
.PHONY: pybin-uninstall-local
10 11 12 13
.PHONY: pybin-dist-hook

if HAVE_PYTHON

14
BUILT_SOURCES += $(pybin_scripts)
15
MOSTLYCLEANFILES += $(pybin_scripts)
16 17 18 19

uninstalled_runner = $(top_srcdir)/gnuscripts/lalsuite_run_uninstalled
uninstalled_compiler = $(uninstalled_runner) '$(abs_top_builddir)' '$(abs_builddir)' '$(LDADD)'
EXTRA_DIST += $(uninstalled_runner)
20

21
all-local: pymodule-all-local pyscripts-all-local
22
pymodule-all-local:
23 24 25
	$(AM_V_at)if test "x$(builddir)" != "x$(srcdir)"; then \
		for file in $(pymodule_PYTHON); do \
			if test -r "$(srcdir)/$${file}"; then \
26
				rm -f "$(builddir)/$${file}" || exit 1; \
27 28 29 30
				$(LN_S) "$(srcdir)/$${file}" "$(builddir)/$${file}" || exit 1; \
			fi; \
		done; \
	fi
31
pyscripts-all-local:
32 33 34
	$(AM_V_at)if test "x$(builddir)" != "x$(srcdir)"; then \
		for file in $(pybin_scripts); do \
			if test -r "$(srcdir)/$${file}.py"; then \
35
				rm -f "$(builddir)/$${file}.py" || exit 1; \
36 37 38 39
				cp -p "$(srcdir)/$${file}.py" "$(builddir)/$${file}.py" || exit 1; \
			fi; \
		done; \
	fi
40

41
mostlyclean-local: pymodule-mostlyclean-local pyscripts-mostlyclean-local py-mostlyclean-local
42 43 44 45
pymodule-mostlyclean-local:
	$(AM_V_at)if test "x$(builddir)" != "x$(srcdir)"; then \
		for file in $(pymodule_PYTHON); do \
			if test -r "$(srcdir)/$${file}"; then \
46 47
				echo " rm -f $(builddir)/$${file}"; \
				rm -f "$(builddir)/$${file}" || exit 1; \
48 49
			fi; \
		done; \
50 51 52 53 54
	fi; \
	for file in $(pymodule_PYTHON); do \
		echo " rm -f $(builddir)/$${file}c $(builddir)/$${file}o"; \
		rm -f "$(builddir)/$${file}c" "$(builddir)/$${file}o" || exit 1; \
	done
55 56 57 58
pyscripts-mostlyclean-local:
	$(AM_V_at)if test "x$(builddir)" != "x$(srcdir)"; then \
		for file in $(pybin_scripts); do \
			if test -r "$(srcdir)/$${file}.py"; then \
59
				echo " rm -f $(builddir)/$${file}.py"; \
60 61 62 63
				rm -f "$(builddir)/$${file}.py" || exit 1; \
			fi; \
		done; \
	fi
64 65
py-mostlyclean-local:
	-rm -rf __pycache__
66

67
$(pybin_scripts): Makefile pyscripts-all-local
68
.py:
69 70
	$(AM_V_GEN)shebang='#!'; \
	rm -f $@ $@.tmp || exit 1; \
71 72
	if test -x $(srcdir)/$@.py; then \
		printf "\nERROR: $(srcdir)/$@.py must not be executable\n\n" >&2; \
73 74
		exit 1; \
	fi; \
75
	if test "x`$(SED) -n -e /^$${shebang}/p $(srcdir)/$@.py`" != x; then \
76
		printf "\nERROR: $(srcdir)/$@.py must not contain a $${shebang} command line\n\n" >&2; \
77 78
		exit 1; \
	fi; \
79
	echo "$${shebang}/bin/sh" > $@.tmp; \
80
	echo "PYTHONPATH=\"$(abs_builddir):$(abs_srcdir):$(LAL_PYTHON_PATH):\$${PYTHONPATH}\"" >> $@.tmp; \
81
	echo "export PYTHONPATH" >> $@.tmp; \
82
	echo "exec $(uninstalled_compiler) $(PYTHON) \"$(abs_builddir)/$@.py\" \"\$$@\"" >> $@.tmp; \
83
	echo "exit 1" >> $@.tmp; \
84 85 86
	chmod +x $@.tmp || exit 1; \
	mv -f $@.tmp $@

87 88 89 90 91 92 93 94 95 96 97 98 99
install-exec-local: pybin-install-exec-local
pybin-install-exec-local:
	$(AM_V_at)shebang='#!'; \
	if test "x$(pybin_scripts)" != x; then \
		pypath="$(pyexecdir)"; \
		if test "$(pythondir)" != "$(pyexecdir)"; then \
			pypath="$${pypath}:$(pythondir)"; \
		fi; \
		echo " $(MKDIR_P) '$(DESTDIR)$(bindir)'"; \
		$(MKDIR_P) "$(DESTDIR)$(bindir)" || exit 1; \
		if test "x$(exec_prefix)" != "x$(python_exec_prefix)"; then \
			echo " $(MKDIR_P) '$(DESTDIR)$(pkglibexecdir)'"; \
			$(MKDIR_P) "$(DESTDIR)$(pkglibexecdir)" || exit 1; \
100
		fi; \
101 102 103 104 105
		for file in $(pybin_scripts); do \
			rm -f $${file}.tmp || exit 1; \
			if test "x$(exec_prefix)" = "x$(python_exec_prefix)"; then \
				echo "$${shebang}$(PYTHON)" > $${file}.tmp; \
				cat $(srcdir)/$${file}.py >> $${file}.tmp; \
106
			else \
107
				sed_regex="s|^PYTHONPATH=.*$$|PYTHONPATH=\"$${pypath}:\$${PYTHONPATH}\"|;s|^exec .*$$|exec $(PYTHON) \"$(pkglibexecdir)/$${file}.py\" \"\$$@\"|"; \
108 109 110
				$(SED) -e "$${sed_regex}" $${file} > $${file}.tmp || exit 1; \
				echo " $(INSTALL_DATA) $(srcdir)/$${file}.py '$(DESTDIR)$(pkglibexecdir)/$${file}.py'"; \
				$(INSTALL_DATA) $(srcdir)/$${file}.py "$(DESTDIR)$(pkglibexecdir)/$${file}.py" || exit 1; \
111
			fi; \
112
			echo " $(INSTALL_SCRIPT) $${file} '$(DESTDIR)$(bindir)/$${file}'"; \
113 114
			$(INSTALL_SCRIPT) $${file}.tmp "$(DESTDIR)$(bindir)/$${file}" || exit 1; \
			rm -f $${file}.tmp || exit 1; \
115 116 117 118 119
		done; \
	fi

uninstall-local: pybin-uninstall-local
pybin-uninstall-local:
120 121 122 123 124 125
	-for file in $(pybin_scripts); do \
		rm -f "$(DESTDIR)$(bindir)/$${file}"; \
		if test "x$(exec_prefix)" != "x$(python_exec_prefix)"; then \
			rm -f "$(DESTDIR)$(pkglibexecdir)/$${file}.py"; \
		fi; \
	done
126 127 128

dist-hook: pybin-dist-hook
pybin-dist-hook:
129 130
	for file in $(pybin_scripts); do \
		cp "$(srcdir)/$${file}.py" "$(distdir)/$${file}.py"; \
131
	done
132 133 134 135 136

else # !HAVE_PYTHON

pymoduledir =
pymodule_PYTHON =
137 138
pybin_scripts =
pkgpython_PYTHON =
139 140

endif # HAVE_PYTHON