Skip to content

Commit 10ed15a

Browse files
committed
starting to include build methods for embedded python
1 parent a993484 commit 10ed15a

8 files changed

+369
-1
lines changed
+110
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
#!/usr/bin/env bash
2+
# build_python.sh
3+
4+
# This should be run in the root of the Python source directory
5+
6+
# NOTE: need os.py to remain in site-packages or it will fail
7+
8+
9+
10+
11+
VERSION=3.7
12+
VER="${VERSION//./}"
13+
NAME=xpython-${VERSION}
14+
PWD=$(pwd)
15+
PREFIX=${PWD}/${NAME}
16+
LIB=${PREFIX}/lib/python${VERSION}
17+
MAC_DEP_TARGET=10.13
18+
19+
20+
remove() {
21+
echo "removing $1"
22+
rm -rf $1
23+
}
24+
25+
rm_lib() {
26+
echo "removing $1"
27+
rm -rf ${LIB}/$1
28+
}
29+
30+
31+
clean() {
32+
echo "removing __pycache__ .pyc/o from $1"
33+
find $1 | grep -E "(__pycache__|\.pyc|\.pyo$)" | xargs rm -rf
34+
}
35+
36+
clean_tests() {
37+
echo "removing 'test' dirs from $1"
38+
find $1 | grep -E "(tests|test)" | xargs rm -rf
39+
}
40+
41+
clean_site_packages() {
42+
echo "removing everything in $LIB/site-packages"
43+
rm -rf $LIB/site-packages/*
44+
}
45+
46+
rm_ext() {
47+
echo "removing $LIB/lib-dynload/$1.cpython-${VER}m-darwin.so"
48+
rm -rf $LIB/lib-dynload/$1.cpython-${VER}m-darwin.so
49+
}
50+
51+
rm_bin() {
52+
echo "removing $PREFIX/bin/$1"
53+
rm -rf $PREFIX/bin/$1
54+
}
55+
56+
./configure MACOSX_DEPLOYMENT_TARGET=${MAC_DEP_TARGET} \
57+
--prefix=$PREFIX \
58+
--enable-shared \
59+
--with-lto \
60+
--enable-optimizations
61+
62+
make altinstall
63+
64+
clean $PREFIX
65+
clean_tests $LIB
66+
clean_site_packages
67+
remove ${LIB}/site-packages
68+
69+
rm_lib config-${VERSION}m-darwin
70+
rm_lib idlelib
71+
rm_lib lib2to3
72+
rm_lib tkinter
73+
rm_lib turtledemo
74+
rm_lib turtle.py
75+
rm_lib ensurepip
76+
rm_lib venv
77+
78+
remove $LIB/distutils/command/*.exe
79+
remove $PREFIX/lib/pkgconfig
80+
remove $PREFIX/share
81+
82+
rm_ext _tkinter
83+
rm_ext _codecs_jp
84+
rm_ext _codecs_hk
85+
rm_ext _codecs_cn
86+
rm_ext _codecs_kr
87+
rm_ext _codecs_tw
88+
89+
rm_bin 2to3-${VERSION}
90+
rm_bin idle${VERSION}
91+
rm_bin easy_install-${VERSION}
92+
rm_bin pip${VERSION}
93+
94+
mv $LIB/lib-dynload $PREFIX
95+
cp $LIB/os.py $PREFIX
96+
clean $PREFIX
97+
python -m zipfile -c $PREFIX/lib/python${VER}.zip $LIB/*
98+
remove $LIB
99+
mkdir -p $LIB
100+
mv $PREFIX/lib-dynload $LIB
101+
mv $PREFIX/os.py $LIB
102+
mkdir $LIB/site-packages
103+
104+
# otool -L $PREFIX/lib/libpython${VERSION}.dylib
105+
# cp /usr/local/opt/gettext/lib/libintl.8.dylib ${PREFIX}/LIB/
106+
# chmod 777 ${PREFIX}/LIB/libintl.8.dylib
107+
# install_name_tool -id @executable_path/libintl.8.dylib ${PREFIX}/LIB/libintl.8.dylib
108+
# install_name_tool -change /usr/local/opt/gettext/lib/libintl.8.dylib @executable_path/libintl.8.dylib libpython${VERSION}.dylib
109+
110+

source/py/scripts/build_python38.sh source/py/scripts/_old/build_python-3.8.sh

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/usr/bin/env bash
22
# build_python.sh
33

4+
# This should be run in the root of the Python source directory
45

56
# NOTE: need os.py to remain in site-packages or it will fail
67

@@ -54,7 +55,6 @@ rm_bin() {
5455
./configure MACOSX_DEPLOYMENT_TARGET=${MAC_DEP_TARGET} \
5556
--prefix=$PREFIX \
5657
--enable-shared \
57-
--with-universal-archs=64-bit \
5858
--with-lto \
5959
--enable-optimizations
6060

@@ -100,4 +100,10 @@ mv $PREFIX/lib-dynload $LIB
100100
mv $PREFIX/os.py $LIB
101101
mkdir $LIB/site-packages
102102

103+
# otool -L $PREFIX/lib/libpython${VERSION}.dylib
104+
# cp /usr/local/opt/gettext/lib/libintl.8.dylib ${PREFIX}/LIB/
105+
# chmod 777 ${PREFIX}/LIB/libintl.8.dylib
106+
# install_name_tool -id @executable_path/libintl.8.dylib ${PREFIX}/LIB/libintl.8.dylib
107+
# install_name_tool -change /usr/local/opt/gettext/lib/libintl.8.dylib @executable_path/libintl.8.dylib libpython${VERSION}.dylib
108+
103109

source/py/scripts/common.h

+92
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
#ifndef COMMON_H
2+
#define COMMON_H
3+
4+
// common stdlibs
5+
#include <stdio.h>
6+
#include <stdlib.h>
7+
#include <errno.h>
8+
#include <string.h>
9+
10+
// common externs (for remove c99 warning)
11+
extern char *strdup(const char *s);
12+
13+
// array size
14+
#define ARRAY_SIZE(array) sizeof(array) / sizeof(array[0])
15+
16+
// bools
17+
typedef int BOOLEAN;
18+
#define TRUE (1)
19+
#define FALSE (0)
20+
21+
// colors
22+
#define COLOR_RESET "\033[m"
23+
#define COLOR_BOLD "\033[1m"
24+
#define COLOR_RED "\033[31m"
25+
#define COLOR_GREEN "\033[32m"
26+
#define COLOR_YELLOW "\033[33m"
27+
#define COLOR_BLUE "\033[34m"
28+
#define COLOR_MAGENTA "\033[35m"
29+
#define COLOR_CYAN "\033[36m"
30+
#define COLOR_BOLD_RED "\033[1;31m"
31+
#define COLOR_BOLD_GREEN "\033[1;32m"
32+
#define COLOR_BOLD_YELLOW "\033[1;33m"
33+
#define COLOR_BOLD_BLUE "\033[1;34m"
34+
#define COLOR_BOLD_MAGENTA "\033[1;35m"
35+
#define COLOR_BOLD_CYAN "\033[1;36m"
36+
37+
// debugging
38+
#define debug(M, ...) fprintf(stderr, "[" COLOR_BOLD_CYAN "DEBUG" COLOR_RESET "] %s:%d: " M "\n", __FILE__, __LINE__, ##__VA_ARGS__)
39+
#define clean_errno() (errno == 0 ? "None" : strerror(errno))
40+
#define log_err(M, ...) fprintf(stderr, "[" COLOR_BOLD_RED "ERROR" COLOR_RESET "] (%s:%d: errno: %s) " M "\n", __FILE__, __LINE__, clean_errno(), ##__VA_ARGS__)
41+
#define log_warn(M, ...) fprintf(stderr, "[" COLOR_BOLD_YELLOW "WARN" COLOR_RESET "] (%s:%d: errno: %s) " M "\n", __FILE__, __LINE__, clean_errno(), ##__VA_ARGS__)
42+
#define log_info(M, ...) fprintf(stderr, "[" COLOR_BOLD_GREEN "INFO" COLOR_RESET "] (%s:%d) " M "\n", __FILE__, __LINE__, ##__VA_ARGS__)
43+
#define check(A, M, ...) if(!(A)) { log_err(M, ##__VA_ARGS__); errno=0; goto error; }
44+
#define sentinel(M, ...) { log_err(M, ##__VA_ARGS__); errno=0; goto error; }
45+
#define check_mem(A) check((A), "Out of memory.")
46+
#define check_debug(A, M, ...) if(!(A)) { debug(M, ##__VA_ARGS__); errno=0; goto error; }
47+
48+
49+
// utils
50+
#define foreach(i, n) \
51+
int i; \
52+
for(i=0; i < n; i++)
53+
54+
// error reporting
55+
// if global errorno is set print the error
56+
// otherwise print the error msg
57+
static inline void die(const char *message)
58+
{
59+
if(errno) {
60+
perror(message);
61+
} else {
62+
log_err("%s", message);
63+
}
64+
exit(EXIT_FAILURE);
65+
}
66+
67+
68+
// testing
69+
#define mu_suite_start() char *message = NULL
70+
71+
#define mu_assert(test, message) if (!(test)) { log_err(message); return message; }
72+
#define mu_run_test(test) debug("\n-----%s", " " #test); \
73+
message = test(); tests_run++; if (message) return message;
74+
75+
#define RUN_TESTS(name) int main(int argc, char *argv[]) {\
76+
argc = 1; \
77+
printf(COLOR_BOLD_MAGENTA "----- RUNNING: %s -----" COLOR_RESET "\n", argv[0]);\
78+
char *result = name();\
79+
if (result != 0) {\
80+
printf(COLOR_BOLD_RED "FAILED: %s\n" COLOR_RESET, result);\
81+
}\
82+
else {\
83+
printf(COLOR_BOLD_GREEN "ALL TESTS PASSED\n" COLOR_RESET);\
84+
}\
85+
printf("Tests run: %d\n", tests_run);\
86+
exit(result != 0);\
87+
}
88+
89+
90+
int tests_run;
91+
92+
#endif // COMMON_H

source/py/scripts/homebrew-3.7.7.sh

Whitespace-only changes.

source/py/scripts/homebrew-3.8.3.sh

Whitespace-only changes.

source/py/scripts/python-org-3.7.7.sh

+160
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
#!/usr/bin/env bash
2+
# build_python.sh
3+
4+
# WITHOUT SSL (STILL TBD)
5+
6+
7+
SHORTNAME=xpython
8+
VERSION_MAJOR=3.7
9+
VERSION_MINOR=7
10+
MAC_DEP_TARGET=10.13
11+
12+
# --- do not modify below
13+
14+
SEMVER=${VERSION_MAJOR}.${VERSION_MINOR}
15+
VERSION=${VERSION_MAJOR}
16+
VER="${VERSION//./}"
17+
NAME=${SHORTNAME}-${VERSION}
18+
URL=https://www.python.org/ftp/python/${SEMVER}/Python-${SEMVER}.tgz
19+
20+
ROOT=$(pwd)
21+
SUPPORT=${ROOT}/support
22+
SRC=${ROOT}/source
23+
PY=${SRC}/py
24+
BUILD=${PY}/build
25+
PYTHON=${BUILD}/Python-${SEMVER}
26+
PREFIX=${SUPPORT}/${NAME}
27+
LIB=${PREFIX}/lib/python${VERSION}
28+
29+
TMP=${BUILD}/_tmp
30+
ARCHIVE=$(basename ${URL})
31+
32+
get_python() {
33+
mkdir $TMP
34+
wget -P $TMP $URL
35+
tar -C $BUILD -xvf $TMP/$ARCHIVE
36+
rm -rf $TMP
37+
}
38+
39+
40+
reset() {
41+
rm -rf $PYTHON
42+
}
43+
44+
reset_support() {
45+
rm -rf $PREFIX
46+
}
47+
48+
remove() {
49+
echo "removing $1"
50+
rm -rf $1
51+
}
52+
53+
rm_lib() {
54+
echo "removing $1"
55+
rm -rf ${LIB}/$1
56+
}
57+
58+
clean() {
59+
echo "removing __pycache__ .pyc/o from $1"
60+
find $1 | grep -E "(__pycache__|\.pyc|\.pyo$)" | xargs rm -rf
61+
}
62+
63+
clean_tests() {
64+
echo "removing 'test' dirs from $1"
65+
find $1 | grep -E "(tests|test)" | xargs rm -rf
66+
}
67+
68+
clean_site_packages() {
69+
echo "removing everything in $LIB/site-packages"
70+
rm -rf $LIB/site-packages/*
71+
}
72+
73+
rm_ext() {
74+
echo "removing $LIB/lib-dynload/$1.cpython-${VER}m-darwin.so"
75+
rm -rf $LIB/lib-dynload/$1.cpython-${VER}m-darwin.so
76+
}
77+
78+
rm_bin() {
79+
echo "removing $PREFIX/bin/$1"
80+
rm -rf $PREFIX/bin/$1
81+
}
82+
83+
testcd() {
84+
cd $PYTHON
85+
touch demo.txt
86+
cd $ROOT
87+
touch demo.txt
88+
}
89+
90+
build() {
91+
cd $PYTHON
92+
93+
./configure MACOSX_DEPLOYMENT_TARGET=${MAC_DEP_TARGET} \
94+
--prefix=$PREFIX \
95+
--enable-shared \
96+
--with-lto \
97+
--enable-optimizations
98+
99+
make altinstall
100+
101+
clean $PREFIX
102+
clean_tests $LIB
103+
clean_site_packages
104+
remove ${LIB}/site-packages
105+
106+
rm_lib config-${VERSION}m-darwin
107+
rm_lib idlelib
108+
rm_lib lib2to3
109+
rm_lib tkinter
110+
rm_lib turtledemo
111+
rm_lib turtle.py
112+
rm_lib ensurepip
113+
rm_lib venv
114+
115+
remove $LIB/distutils/command/*.exe
116+
remove $PREFIX/lib/pkgconfig
117+
remove $PREFIX/share
118+
119+
rm_ext _tkinter
120+
rm_ext _codecs_jp
121+
rm_ext _codecs_hk
122+
rm_ext _codecs_cn
123+
rm_ext _codecs_kr
124+
rm_ext _codecs_tw
125+
126+
rm_bin 2to3-${VERSION}
127+
rm_bin idle${VERSION}
128+
rm_bin easy_install-${VERSION}
129+
rm_bin pip${VERSION}
130+
131+
mv $LIB/lib-dynload $PREFIX
132+
cp $LIB/os.py $PREFIX
133+
clean $PREFIX
134+
python -m zipfile -c $PREFIX/lib/python${VER}.zip $LIB/*
135+
remove $LIB
136+
mkdir -p $LIB
137+
mv $PREFIX/lib-dynload $LIB
138+
# Need to have a copy of os.py to remain in site-packages
139+
# or it will fail to pick up library.zip
140+
mv $PREFIX/os.py $LIB
141+
mkdir $LIB/site-packages
142+
143+
cd $ROOT
144+
}
145+
146+
fix() {
147+
otool -L $PREFIX/lib/libpython${VERSION}.dylib
148+
cp /usr/local/opt/gettext/lib/libintl.8.dylib ${PREFIX}/LIB/
149+
chmod 777 ${PREFIX}/LIB/libintl.8.dylib
150+
install_name_tool -id @executable_path/libintl.8.dylib ${PREFIX}/LIB/libintl.8.dylib
151+
install_name_tool -change /usr/local/opt/gettext/lib/libintl.8.dylib @executable_path/libintl.8.dylib libpython${VERSION}.dylib
152+
}
153+
154+
155+
install_python() {
156+
get_python
157+
build
158+
}
159+
160+

source/py/scripts/python-org-3.8.3.sh

Whitespace-only changes.

support/.keep

Whitespace-only changes.

0 commit comments

Comments
 (0)