summaryrefslogtreecommitdiff
path: root/project/pydist.sh
blob: 26701d05bff9fbbf9a2a3785ec2eb0694f90fd5d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#!/bin/sh

# pydist.sh: a reference-only, development-time script
# objective: generate pydist.mk based on the scripts found
#            under $PYTHON_SRCDIR/Lib, excluding the 'test'
#            and 'plat-*' sub-directories.

if [ -z "$PYTHON_SRCDIR" ]; then
	printf 'Variable PYTHON_SRCDIR is not set!\n'
	exit 2
fi

cd "$PYTHON_SRCDIR"/Lib || exit 2

pydirs=$(find . -type d | grep -v -e '^\./test' -e '^./plat-' | sort)
pysrcs=$(mktemp)
pypycs=$(mktemp)

if [ -z $pysrcs ]; then
	exit 2
fi

if [ -z $pypycs ]; then
	exit 2
fi

printf 'PYCOPY        = $(PROJECT_DIR)/project/pycopy.sh\n'
printf 'PYCOPY_PYTHON = $(NICKNAME)\n'
printf 'PYCOPY_PREFIX = $(PREFIX)\n\n'

printf 'PYDIST_LIBDIR = lib\n'
printf 'PYDIST_PYCDIR = lib/$(NICKNAME)\n\n\n'

printf 'PYDIST_SYSCFG_SRCS = \\\n'
printf '\t$(PYDIST_PYCDIR)/./_sysconfigdata.py\n\n'

cpvar=$(printf '\tcp -p $(%s)' 'PYDIST_SYSCFG_SRCS')
printf '%-64s$(DESTDIR)/$(LIBDIR)/$(PACKAGE)\n' "$cpvar" >> $pysrcs

cpvar=$(printf '\tcp -p $(%s:%s.py=%s.pyc)' 'PYDIST_SYSCFG_SRCS' '%' '%')
printf '%-68s$(DESTDIR)/$(LIBDIR)/$(PACKAGE)\n' "$cpvar" >> $pypycs

for pydir in $pydirs; do
	if [ $(find "$pydir" -maxdepth 1 -name '*.py' | wc -l) != '0' ]; then
		pyvar=$(printf "PYDIST_%s_SRCS" $pydir \
			| sed -e 's@\_\.@@g' -e 's@/@_@g' -e 's@-@_@g' \
			| tr "[:lower:]" "[:upper:]")

		printf "%s = "'\\'"\n" "$pyvar"
		pyvars="$pyvars $pyvar"

		cpvar=$(printf '\tcp -p $(%s)' "$pyvar")
		printf '%-64s$(DESTDIR)/$(LIBDIR)/$(PACKAGE)/%s\n' "$cpvar" "$pydir" >> $pysrcs

		cpvar=$(printf '\tcp -p $(%s:%s.py=%s.pyc)' "$pyvar" '%' '%')
		printf '%-68s$(DESTDIR)/$(LIBDIR)/$(PACKAGE)/%s\n' "$cpvar" "$pydir" >> $pypycs

		for pysrc in $pydir/*.py; do
			if [ $pysrc != $pydir/py3_test_grammar.py ]; then
				printf "\t"'$(PYDIST_PYCDIR)/'"%s "'\\'"\n" $pysrc
			fi
		done | sort;

		echo
	fi
done

printf '\n\n'
printf 'pydist.tag:\n'

for pydir in $pydirs; do
	if [ $pydir != '.' ]; then
		printf '\tmkdir -p $(PYDIST_PYCDIR)/%s\n' $pydir
	fi
done

printf '\ttouch pydist.tag\n'
printf '\n\n'

for pydir in $pydirs; do
	pyrule=$(printf '$(PYDIST_PYCDIR)/'"%s/%s.py:" "$pydir" '%')
	printf "%-64s"'$(SOURCE_DIR)/Lib/'"%s/%s.py"' pydist.tag\n' "$pyrule" "$pydir" '%'

	pyrule_python=$(printf "\t\t"'PYCOPY_PYTHON=$(PYCOPY_PYTHON)')
	pyrule_prefix=$(printf "\t\t"'PYCOPY_PREFIX=$(PYCOPY_PREFIX)')
	pyrule_dstdir=$(printf "\t\t"'PYCOPY_DSTDIR=$(PYDIST_PYCDIR)/'"%s" "$pydir")

	printf "%s"' \\\n' "$pyrule_python"
	printf "%s"' \\\n' "$pyrule_prefix"
	printf "%s"' \\\n' "$pyrule_dstdir"
	printf '\t\t$(PYCOPY) $<\n\n'
done

printf 'PYDIST_PY_SRCS = \\\n'

for pyvar in PYDIST_SYSCFG_SRCS $pyvars; do
	printf "\t"'$('"%s"') \\\n' $pyvar
done

printf '\n\n'
printf 'pydist-py-srcs:\t$(PYDIST_PY_SRCS)\n\n'
printf 'pydist-py-srcs-clean:\n'
printf '\trm -f $(PYDIST_PY_SRCS)\n'
printf '\trm -f pydist.tag\n\n'
printf 'clean:\tpydist-py-srcs-clean\n\n'

printf '\n\n'
printf 'pydist-install-tree:\n'

for pydir in $pydirs; do
	if [ $pydir != '.' ]; then
		printf '\tmkdir -p $(DESTDIR)/$(LIBDIR)/$(PACKAGE)/%s\n' $pydir
	fi
done

printf '\n\n'
printf 'pydist-install-py: $(PYDIST_PY_SRCS)\n'
printf 'pydist-install-py: pydist-install-tree\n'
printf 'pydist-install-py:\n'
cat $pysrcs

printf '\n\n'
printf 'pydist-install-pyc: $(PYCGEN_OBJS)\n'
printf 'pydist-install-pyc: pydist-install-tree\n'
printf 'pydist-install-pyc:\n'
cat $pypycs

printf '\n\n'
printf 'install-app:\tpydist-install-py\n'
printf 'install-app:\tpydist-install-pyc\n'

printf '\n\n'
printf '.PHONY:\tpydist-py-srcs\n'
printf '.PHONY:\tpydist-py-srcs-clean\n\n'

printf '.PHONY:\tpydist-install-tree\n'
printf '.PHONY:\tpydist-install-py\n'
printf '.PHONY:\tpydist-install-pyc\n'

exit 0