Blame project/pydist.sh

b1b5c4
#!/bin/sh
b1b5c4
b1b5c4
# pydist.sh: a reference-only, development-time script
b1b5c4
# objective: generate pydist.mk based on the scripts found
b1b5c4
#            under $PYTHON_SRCDIR/Lib, excluding the 'test'
b1b5c4
#            and 'plat-*' sub-directories.
b1b5c4
b1b5c4
if [ -z "$PYTHON_SRCDIR" ]; then
b1b5c4
	printf 'Variable PYTHON_SRCDIR is not set!\n'
b1b5c4
	exit 2
b1b5c4
fi
b1b5c4
b1b5c4
cd "$PYTHON_SRCDIR"/Lib || exit 2
b1b5c4
b1b5c4
pydirs=$(find . -type d | grep -v -e '^\./test' -e '^./plat-' | sort)
b1b5c4
pysrcs=$(mktemp)
b1b5c4
pypycs=$(mktemp)
b1b5c4
b1b5c4
if [ -z $pysrcs ]; then
b1b5c4
	exit 2
b1b5c4
fi
b1b5c4
b1b5c4
if [ -z $pypycs ]; then
b1b5c4
	exit 2
b1b5c4
fi
b1b5c4
b1b5c4
printf 'PYCOPY        = $(PROJECT_DIR)/project/pycopy.sh\n'
b1b5c4
printf 'PYCABI        = cpython-$(PYTHON_MAJOR)$(PYTHON_MINOR)\n'
b1b5c4
printf 'PYCOPY_PYTHON = $(NICKNAME)\n'
b1b5c4
printf 'PYCOPY_PREFIX = $(PREFIX)\n\n'
b1b5c4
b1b5c4
printf 'PYDIST_LIBDIR = lib\n'
b1b5c4
printf 'PYDIST_PYCDIR = lib/$(NICKNAME)\n\n\n'
b1b5c4
b1b5c4
printf 'PYDIST_SYSCFG_SRCS = \\\n'
b6fc94
printf '\t$(PYDIST_PYCDIR)/./_sysconfigdata_$(PYTHON_ABIFL)_$(PYTHON_PLATFORM)_.py\n\n'
b1b5c4
b1b5c4
cpvar=$(printf '\tcp -p $(%s)' 'PYDIST_SYSCFG_SRCS')
b1b5c4
printf '%-80s$(DESTDIR)/$(LIBDIR)/$(PACKAGE)\n' "$cpvar" >> $pysrcs
b1b5c4
b1b5c4
cpvar=$(printf '\tcp -p $(%s:$(PYDIST_PYCDIR)/./%%.py=$(PYDIST_PYCDIR)/./__pycache__/%%.%s.pyc)' \
b1b5c4
	'PYDIST_SYSCFG_SRCS' '$(PYCABI)')
13a8bb
printf '%s \\\n\t\t$(DESTDIR)/$(LIBDIR)/$(PACKAGE)/./__pycache__\n' "$cpvar" >> $pypycs
b1b5c4
b1b5c4
for pydir in $pydirs; do
b1b5c4
	if [ $(find "$pydir" -maxdepth 1 -name '*.py' | wc -l) != '0' ]; then
b1b5c4
		pyvar=$(printf "PYDIST_%s_SRCS" $pydir \
b1b5c4
			| sed -e 's@\_\.@@g' -e 's@/@_@g' -e 's@-@_@g' \
b1b5c4
			| tr "[:lower:]" "[:upper:]")
b1b5c4
b1b5c4
		printf "%s = "'\\'"\n" "$pyvar"
b1b5c4
		pyvars="$pyvars $pyvar"
b1b5c4
b1b5c4
		cpvar=$(printf '\tcp -p $(%s)' "$pyvar")
b1b5c4
		printf '%-80s$(DESTDIR)/$(LIBDIR)/$(PACKAGE)/%s\n' "$cpvar" "$pydir" >> $pysrcs
b1b5c4
b1b5c4
		case $pydir/ in
b1b5c4
			./lib2to3/tests/data/* )
b1b5c4
				;;
b1b5c4
			* )
b1b5c4
				cpvar=$(printf '\tcp -p $(%s:$(PYDIST_PYCDIR)/%s/%%.py=$(PYDIST_PYCDIR)/%s/./__pycache__/%%.%s.pyc)' \
b1b5c4
					"$pyvar" $pydir $pydir '$(PYCABI)')
b1b5c4
				printf '%s \\\n\t\t$(DESTDIR)/$(LIBDIR)/$(PACKAGE)/%s/./__pycache__\n' "$cpvar" "$pydir" >> $pypycs
b1b5c4
		esac
b1b5c4
b1b5c4
		for pysrc in $pydir/*.py; do
b1b5c4
			if [ $pysrc != $pydir/py3_test_grammar.py ]; then
b1b5c4
				printf "\t"'$(PYDIST_PYCDIR)/'"%s "'\\'"\n" $pysrc
b1b5c4
			fi
b1b5c4
		done | sort;
b1b5c4
b1b5c4
		echo
b1b5c4
	fi
b1b5c4
done
b1b5c4
b1b5c4
printf '\n\n'
b1b5c4
printf 'pydist.tag:\n'
b1b5c4
b1b5c4
for pydir in $pydirs; do
b1b5c4
	if [ $pydir == '.' ]; then
b1b5c4
		printf '\tmkdir -p $(PYDIST_PYCDIR)/./__pycache__\n'
b1b5c4
	else
b1b5c4
		printf '\tmkdir -p $(PYDIST_PYCDIR)/%s\n' $pydir
b1b5c4
		printf '\tmkdir -p $(PYDIST_PYCDIR)/%s/./__pycache__\n' $pydir
b1b5c4
	fi
b1b5c4
done
b1b5c4
b1b5c4
printf '\ttouch pydist.tag\n'
b1b5c4
printf '\n\n'
b1b5c4
b1b5c4
for pydir in $pydirs; do
b1b5c4
	pyrule=$(printf '$(PYDIST_PYCDIR)/'"%s/%s.py:" "$pydir" '%')
b1b5c4
	printf "%-80s"'$(SOURCE_DIR)/Lib/'"%s/%s.py"' pydist.tag\n' "$pyrule" "$pydir" '%'
b1b5c4
b1b5c4
	pyrule_python=$(printf "\t\t"'PYCOPY_PYTHON=$(PYCOPY_PYTHON)')
b1b5c4
	pyrule_prefix=$(printf "\t\t"'PYCOPY_PREFIX=$(PYCOPY_PREFIX)')
b1b5c4
	pyrule_dstdir=$(printf "\t\t"'PYCOPY_DSTDIR=$(PYDIST_PYCDIR)/'"%s" "$pydir")
b1b5c4
b1b5c4
	printf "%s"' \\\n' "$pyrule_python"
b1b5c4
	printf "%s"' \\\n' "$pyrule_prefix"
b1b5c4
	printf "%s"' \\\n' "$pyrule_dstdir"
b1b5c4
	printf '\t\t$(PYCOPY) $<\n\n'
b1b5c4
done
b1b5c4
b1b5c4
printf 'PYDIST_PY_SRCS = \\\n'
b1b5c4
b1b5c4
for pyvar in PYDIST_SYSCFG_SRCS $pyvars; do
b1b5c4
	printf "\t"'$('"%s"') \\\n' $pyvar
b1b5c4
done
b1b5c4
b1b5c4
printf '\n\n'
b1b5c4
printf 'pydist-py-srcs:\t$(PYDIST_PY_SRCS)\n\n'
b1b5c4
printf 'pydist-py-srcs-clean:\n'
b1b5c4
printf '\trm -f $(PYDIST_PY_SRCS)\n'
b1b5c4
printf '\trm -f pydist.tag\n\n'
b1b5c4
printf 'clean:\tpydist-py-srcs-clean\n\n'
b1b5c4
b1b5c4
printf '\n\n'
b1b5c4
printf 'pydist-install-tree:\n'
b1b5c4
b1b5c4
for pydir in $pydirs; do
b1b5c4
	if [ $pydir == '.' ]; then
b1b5c4
		printf '\tmkdir -p $(DESTDIR)/$(LIBDIR)/$(PACKAGE)/./__pycache__\n'
b1b5c4
	else
b1b5c4
		printf '\tmkdir -p $(DESTDIR)/$(LIBDIR)/$(PACKAGE)/%s\n' $pydir
b1b5c4
		printf '\tmkdir -p $(DESTDIR)/$(LIBDIR)/$(PACKAGE)/%s/./__pycache__\n' $pydir
b1b5c4
	fi
b1b5c4
done
b1b5c4
b1b5c4
printf '\n\n'
b1b5c4
printf 'pydist-install-py: $(PYDIST_PY_SRCS)\n'
b1b5c4
printf 'pydist-install-py: pydist-install-tree\n'
b1b5c4
printf 'pydist-install-py:\n'
b1b5c4
cat $pysrcs
b1b5c4
b1b5c4
printf '\n\n'
b1b5c4
printf 'pydist-install-pyc: $(PYCGEN_OBJS)\n'
b1b5c4
printf 'pydist-install-pyc: pydist-install-tree\n'
b1b5c4
printf 'pydist-install-pyc:\n'
b1b5c4
cat $pypycs
b1b5c4
b1b5c4
printf '\n\n'
b1b5c4
printf 'install-app:\tpydist-install-py\n'
b1b5c4
printf 'install-app:\tpydist-install-pyc\n'
b1b5c4
b1b5c4
printf '\n\n'
b1b5c4
printf '.PHONY:\tpydist-py-srcs\n'
b1b5c4
printf '.PHONY:\tpydist-py-srcs-clean\n\n'
b1b5c4
b1b5c4
printf '.PHONY:\tpydist-install-tree\n'
b1b5c4
printf '.PHONY:\tpydist-install-py\n'
b1b5c4
printf '.PHONY:\tpydist-install-pyc\n'
b1b5c4
b1b5c4
exit 0