Skip to content

Commit 85a9a47

Browse files
authored
Merge pull request #1 from nx-python/dev3
Python 3
2 parents 9da4f90 + c2f0f6c commit 85a9a47

File tree

9 files changed

+3467
-176
lines changed

9 files changed

+3467
-176
lines changed

Makefile

+5-5
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,14 @@ TARGET := $(notdir $(CURDIR))
3333
BUILD := build
3434
PY_BUILD := python_build
3535
DIST_DIR := $(BUILD)/$(TARGET)
36-
LIBDIR := $(DIST_DIR)/lib/python2.7
36+
LIBDIR := $(DIST_DIR)/lib/python3.5
3737
SOURCES := source
3838
DATA := data
3939
INCLUDES := include
4040
EXEFS_SRC := exefs_src
4141
APP_TITLEID := Pynx
4242
APP_AUTHOR := nx-python Authors, Python Software Foundation
43-
APP_VERSION := 0.1.0-alpha
43+
APP_VERSION := 0.2.0-alpha
4444

4545
#---------------------------------------------------------------------------------
4646
# options for code generation
@@ -57,13 +57,13 @@ CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions -std=gnu++11
5757
ASFLAGS := -g $(ARCH)
5858
LDFLAGS = -specs=$(DEVKITPRO)/libnx/switch.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map)
5959

60-
LIBS := -lpython2.7 -lm -lnx
60+
LIBS := -lpython3.5 -lm -lnx
6161

6262
#---------------------------------------------------------------------------------
6363
# list of directories containing libraries, this must be the top level containing
6464
# include and lib
6565
#---------------------------------------------------------------------------------
66-
NXPY := $(CURDIR)/python_build/nxpy2.7.12
66+
NXPY := $(CURDIR)/python_build/nxpy3.5.3
6767
LIBDIRS := $(PORTLIBS) $(LIBNX) $(NXPY)
6868

6969

@@ -151,7 +151,7 @@ cpython:
151151

152152
dist: $(BUILD)
153153
mkdir -p $(LIBDIR)
154-
unzip $(PY_BUILD)/nxpy2.7.12/python.zip -d $(LIBDIR)
154+
unzip $(PY_BUILD)/nxpy3.5.3/python.zip -d $(LIBDIR)
155155
cp $(OUTPUT).{nro,nacp} $(DIST_DIR)/
156156
cp examples/hello.py $(DIST_DIR)/main.py
157157
cd $(BUILD) && zip -r $(TARGET)-$(APP_VERSION).zip $(TARGET)

examples/hello.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
print """
1+
print("""
22
_ _ _
33
| | | | | |
44
| | | | ___| | ___ ___ _ __ ___ ___
@@ -22,4 +22,4 @@
2222
__/ |
2323
|___/
2424
25-
Replace this file (main.py) with your own to get started. """
25+
Replace this file (main.py) with your own to get started. """)

python_build/Makefile

+15-11
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ CFLAGS += $(INCLUDE) -DSWITCH
3939

4040

4141
ifndef PYVERS
42-
PYVERS := 2.7.12
42+
PYVERS := 3.5.3
4343
endif
4444

4545
ANAME := libpython$(shell echo $(PYVERS) | sed 's/\([0-9]*\.\([0-9]*\)\).*/\1/').a
@@ -65,29 +65,33 @@ distfPY: linkPY
6565
cp $(PYDIR)/Lib/socket.py $(PYDIR)/Lib/socket.pyX
6666
cat $(PYDIR)/Lib/socket.pyX | sed 's/'"'"'getpeername'"'"', //g' >$(PYDIR)/Lib/socket.py
6767
rm $(PYDIR)/Lib/socket.pyX
68-
cd $(PYDIR)/Lib && ls *.py -1 | xargs zip ../../$(OUTDIR)/python.zip && find json/ encodings/ -type f | xargs zip ../../$(OUTDIR)/python.zip
68+
cd $(PYDIR)/Lib && ls *.py -1 | xargs zip ../../$(OUTDIR)/python.zip && find json/ encodings/ html/ http/ test/ urllib/ collections/ email/ sqlite3/ logging/ xml/ -type f | xargs zip ../../$(OUTDIR)/python.zip
6969

7070
touch distfPY
7171

7272
linkPY: soospatchPY
7373
cd $(PYDIR) && make $(MAKEFLAGS) LIBRARY="$(ANAME)" LDLIBRARY="$(ANAME)" $(ANAME) && cd .. && cp $(PYDIR)/$(ANAME) . && touch linkPY
7474

7575
soospatchPY: compilePY
76-
cp $(PYCONFIG_DIR)/pyconfig.h $(PYDIR)/pyconfig.h
76+
cp $(PYCONFIG_DIR)/pyconfig.h $(PYDIR)/
77+
cp $(PYCONFIG_DIR)/intrcheck.c $(PYDIR)/Parser/
78+
cp $(PYCONFIG_DIR)/pytime.c $(PYDIR)/Python/
79+
cp $(PYCONFIG_DIR)/random.c $(PYDIR)/Python/
80+
cp $(PYCONFIG_DIR)/fileutils.c $(PYDIR)/Python/
7781
cp $(PYDIR)/Modules/posixmodule.c $(PYDIR)/Modules/posixmodule.c_old
78-
cat $(PYDIR)/Modules/posixmodule.c_old | sed 's/access(path, mode)/1/' | sed 's/\(^[^rt]*time_t atime, mtime;.*\)/return NULL; \1/' | sed 's/\(^[^ri]*i = (int)umask(i);.*\)/return NULL; \1/' | sed 's/^\([^#][^#]*#undef HAVE_FSTATVFS.*\)/\#undef HAVE_FSTATVFS \1/' | sed 's/#define HAVE_\(EXECV\|FORK\|GETEGID\|GETEUID\|GETGID\|GETPPID\|GETUID\|KILL\|PIPE\|POPEN\|SYSTEM\|TTYNAME\|SYMLINK\|UTIME_H\|FDATASYNC\).*/#undef HAVE_\1/g' | sed 's/^#define HAVE_\(STATVFS\|SYS_STATVFS_H\|FDATASYNC\|FTIME\|SYMLINK\|EXECV\|FORK\|GETEGID\|GETEUID\|GETGID\|GETPPID\|GETUID\|KILL\|PIPE\|POPEN\|SYSTEM\|TTYNAME\|SYMLINK\|UTIME_H\|FDATASYNC\).*/#undef HAVE_\1/' >$(PYDIR)/Modules/posixmodule.c
82+
cat $(PYDIR)/Modules/posixmodule.c_old | sed 's/return utime(path, time)/errno=ENOENT; return -1/g' | sed 's/define LSTAT lstat/define LSTAT stat/' | sed '1s/^/#include <sys\/socket.h>/' | sed 's/access(path->narrow, mode)/1/' | sed 's/\(^[^rt]*time_t atime, mtime;.*\)/return NULL; \1/' | sed 's/\(^[^ri]*int i = (int)umask(mask);.*\)/int i=0; return NULL;/' | sed 's/^\([^#][^#]*#undef HAVE_FSTATVFS.*\)/\#undef HAVE_FSTATVFS \1/' | sed 's/#define HAVE_\(EXECV\|FORK\|GETEGID\|GETEUID\|GETGID\|GETPPID\|GETUID\|KILL\|PIPE\|POPEN\|SYSTEM\|TTYNAME\|SYMLINK\|UTIME_H\|FDATASYNC\).*/#undef HAVE_\1/g' | sed 's/^#define HAVE_\(STATVFS\|SYS_STATVFS_H\|FDATASYNC\|FTIME\|SYMLINK\|EXECV\|FORK\|GETEGID\|GETEUID\|GETGID\|GETPPID\|GETUID\|KILL\|PIPE\|POPEN\|SYSTEM\|TTYNAME\|SYMLINK\|UTIME_H\|FDATASYNC\).*/#undef HAVE_\1/' >$(PYDIR)/Modules/posixmodule.c
7983
cp $(PYDIR)/Modules/socketmodule.c $(PYDIR)/Modules/socketmodule.c_old
8084
cat $(PYDIR)/Modules/socketmodule.c_old | sed 's/send(s->sock_fd, buf, len, flags);/send(s->sock_fd, buf, len<4096?len:4096, flags);/g' | sed 's/ sizeof(addr->sa_data)/ 28/g' >$(PYDIR)/Modules/socketmodule.c
81-
#cp $(PYDIR)/Objects/exceptions.c $(PYDIR)/Objects/exceptions.c_old
82-
#cat $(PYDIR)/Objects/exceptions.c_old | sed 's/ESHUTDOWN/110/g' >$(PYDIR)/Objects/exceptions.c
83-
#cp $(PYDIR)/Python/pytime.c $(PYDIR)/Python/pytime.c_old
84-
#cat $(PYDIR)/Python/pytime.c_old | sed 's/CLOCK_MONOTONIC/(clockid_t)4/g' >$(PYDIR)/Python/pytime.c
85+
cp $(PYDIR)/Objects/exceptions.c $(PYDIR)/Objects/exceptions.c_old
86+
cat $(PYDIR)/Objects/exceptions.c_old | sed 's/ESHUTDOWN/EPIPE/g' >$(PYDIR)/Objects/exceptions.c
87+
cp $(PYDIR)/Python/pytime.c $(PYDIR)/Python/pytime.c_old
88+
cat $(PYDIR)/Python/pytime.c_old | sed 's/CLOCK_MONOTONIC/(clockid_t)4/g' >$(PYDIR)/Python/pytime.c
8589
cp $(PYDIR)/Makefile $(PYDIR)/Makefile_old
86-
cat $(PYDIR)/Makefile_old | sed 's/Python\/$$(DYNLOADFILE) \\/\\/' >$(PYDIR)/Makefile
90+
cat $(PYDIR)/Makefile_old | sed 's/-Werror=declaration-after-statement//' | sed 's/Python\/$$(DYNLOADFILE) \\/\\/' >$(PYDIR)/Makefile
8791
touch soospatchPY
8892

8993
compilePY: extractedPY patchPY
90-
cd $(PYDIR) && ./configure CC="$(CC)" CXX="$(CXX)" AS="$(AS)" AR="$(AR)" OBJCOPY="$(OBJCOPY)" STRIP="$(STRIP)" NM="$(NM)" RANLIB="$(RANLIB)" CFLAGS="$(CFLAGS)" CXXFLAGS="$(CXXFLAGS)" ASFLAGS="$(ASFLAGS)" LDFLAGS="$(LDFLAGS)" CONFIG_SITE="config.site" --disable-shared --without-threads --without-doc-strings --disable-ipv6 --host=aarch64-none-elf --build=`./config.guess` && cd .. && touch compilePY
94+
cd $(PYDIR) && ./configure CC="$(CC)" CXX="$(CXX)" AS="$(AS)" AR="$(AR)" OBJCOPY="$(OBJCOPY)" STRIP="$(STRIP)" NM="$(NM)" RANLIB="$(RANLIB)" CFLAGS="$(CFLAGS)" CXXFLAGS="$(CXXFLAGS)" ASFLAGS="$(ASFLAGS)" LDFLAGS="$(LDFLAGS)" CONFIG_SITE="config.site" --disable-shared --without-threads --without-doc-strings --without-signal-module --disable-ipv6 --host=aarch64-none-elf --build=`./config.guess` && cd .. && touch compilePY
9195

9296
patchPY:
9397
cp $(PYDIR)/configure $(PYDIR)/configure_old
@@ -96,7 +100,7 @@ patchPY:
96100
echo ac_cv_file__dev_ptc=no >>$(PYDIR)/config.site
97101
echo ac_cv_lib_dl_dlopen=no >>$(PYDIR)/config.site
98102
cp $(PYDIR)/Modules/Setup.dist $(PYDIR)/Modules/Setup.dist_old
99-
cat $(PYDIR)/Modules/Setup.dist_old | sed 's/^\([^#].* pwdmodule\.c.*\)/#\1/' | sed 's/^#\(array\|cmath\|math\|_struct\|operator\|_random\|_collections\|itertools\|strop\|unicodedata\|_io\|_csv\|_md5\|_sha\|_sha256\|_sha512\|binascii\|select\|cStringIO\|time\|_functools\|_socket\|datetime\|_bisect\)\(.*\)/\1\2/' >$(PYDIR)/Modules/Setup.dist
103+
cat $(PYDIR)/Modules/Setup.dist_old | sed 's/^\([^#].* pwdmodule\.c.*\)/#\1/' | sed 's/^#\(array\|cmath\|math\|_struct\|operator\|_random\|_collections\|itertools\|signal\|strop\|unicodedata\|_io\|_csv\|_md5\|_sha\|_sha256\|_sha512\|binascii\|select\|cStringIO\|time\|_functools\|_socket\|datetime\|_bisect\)\(.*\)/\1\2/' | sed "s#\\(zlib[^\$$]*\\)\$$(prefix)\\([^\$$]*\\)\$$(exec_prefix)\\(.*\\)#\1$(DEVKITPRO)/portlibs/switch\2$(DEVKITPRO)/portlibs/switch\3#" >$(PYDIR)/Modules/Setup.dist
100104

101105
touch patchPY
102106

0 commit comments

Comments
 (0)