99TOPDIR ?= $(CURDIR )
1010include $(DEVKITPRO ) /libnx/switch_rules
1111
12-
13- # ---------------------------------------------------------------------------------
14- # options for code generation
15- # ---------------------------------------------------------------------------------
16- ARCH := -march=armv8-a -mtune=cortex-a57 -mtp=soft -fPIE
17-
18- CFLAGS := -g -Wall -O2 -ffunction-sections \
19- $(ARCH ) $(DEFINES )
20-
21- CXXFLAGS := $(CFLAGS ) -fno-rtti -fno-exceptions -std=gnu++11
22-
23- ASFLAGS := -g $(ARCH )
24- LDFLAGS = -specs=$(DEVKITPRO ) /libnx/switch.specs -g $(ARCH ) -Wl,-Map,$(notdir $* .map)
25-
26- LIBS := -lnx
27-
28- # ---------------------------------------------------------------------------------
29- # list of directories containing libraries, this must be the top level containing
30- # include and lib
31- # ---------------------------------------------------------------------------------
32-
33- LIBDIRS := $(PORTLIBS ) $(LIBNX )
34- export INCLUDE := $(foreach dir,$(LIBDIRS ) ,-I$(dir ) /include) \
35- -I$(CURDIR ) /$(BUILD )
36- CFLAGS += $(INCLUDE ) -DSWITCH
37-
38-
39- ifndef PYVERS
40- PYVERS := 2.7.12
41- endif
42-
43- ANAME := libpython$(shell echo $(PYVERS ) | sed 's/\([0-9]* \.\([0-9]* \) \).*/\1/').a
44-
45- OUTDIR := nxpy$(PYVERS )
46-
47- PYDIR := Python-$(PYVERS )
48- PYLINK := https://www.python.org/ftp/python/$(PYVERS ) /Python-$(PYVERS ) .tgz
49- PYFILE := py.tgz
50-
51- .PHONY : all clean
52-
53- distfPY : linkPY
54- @[ -d " $( OUTDIR) " ] || mkdir -p $(OUTDIR )
55- @[ -d " $( OUTDIR) /include" ] || mkdir -p $(OUTDIR ) /include
56- @[ -d " $( OUTDIR) /include/nxpy" ] || mkdir -p $(OUTDIR ) /include/nxpy
57- @[ -d " $( OUTDIR) /lib" ] || mkdir -p $(OUTDIR ) /lib
58- cp $(ANAME ) $(OUTDIR ) /lib/
59- cp $(PYDIR ) /Include/* $(OUTDIR ) /include/nxpy
60- cp $(PYDIR ) /pyconfig.h $(OUTDIR ) /include/nxpy/
61- cp $(PYDIR ) /Lib/socket.py $(PYDIR ) /Lib/socket.pyX
62- cat $(PYDIR ) /Lib/socket.pyX | sed ' s/' " '" ' getpeername' " '" ' , //g' > $(PYDIR ) /Lib/socket.py
63- rm $(PYDIR ) /Lib/socket.pyX
64- cd $(PYDIR ) /Lib && ls * .py -1 | xargs zip ../../$(OUTDIR ) /python.zip && find json/ encodings/ -type f | xargs zip ../../$(OUTDIR ) /python.zip
65-
66- touch distfPY
67-
68- linkPY : soospatchPY
69- cd $(PYDIR ) && make $(MAKEFLAGS ) LIBRARY=" $( ANAME) " LDLIBRARY=" $( ANAME) " $(ANAME ) && cd .. && cp $(PYDIR ) /$(ANAME ) . && touch linkPY
70-
71- soospatchPY : compilePY
72- cp python_config/pyconfig.h $(PYDIR ) /pyconfig.h
73- cp $(PYDIR ) /Modules/posixmodule.c $(PYDIR ) /Modules/posixmodule.c_old
74- 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
75- cp $(PYDIR ) /Modules/socketmodule.c $(PYDIR ) /Modules/socketmodule.c_old
76- 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
77- # cp $(PYDIR)/Objects/exceptions.c $(PYDIR)/Objects/exceptions.c_old
78- # cat $(PYDIR)/Objects/exceptions.c_old | sed 's/ESHUTDOWN/110/g' >$(PYDIR)/Objects/exceptions.c
79- # cp $(PYDIR)/Python/pytime.c $(PYDIR)/Python/pytime.c_old
80- # cat $(PYDIR)/Python/pytime.c_old | sed 's/CLOCK_MONOTONIC/(clockid_t)4/g' >$(PYDIR)/Python/pytime.c
81- cp $(PYDIR ) /Makefile $(PYDIR ) /Makefile_old
82- cat $(PYDIR ) /Makefile_old | sed ' s/Python\/$$(DYNLOADFILE) \\/\\/' > $(PYDIR ) /Makefile
83- touch soospatchPY
84-
85- compilePY : extractedPY patchPY
86- 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
87-
88- patchPY :
89- cp $(PYDIR ) /configure $(PYDIR ) /configure_old
90- cat $(PYDIR ) /configure_old | sed ' s/ \*\-\*\-linux\*)/ \*\-\*\-linux\*\|aarch64\-none\-elf)/g' > $(PYDIR ) /configure
91- echo ac_cv_file__dev_ptmx=no > $(PYDIR ) /config.site
92- echo ac_cv_file__dev_ptc=no >> $(PYDIR ) /config.site
93- echo ac_cv_lib_dl_dlopen=no >> $(PYDIR ) /config.site
94- cp $(PYDIR ) /Modules/Setup.dist $(PYDIR ) /Modules/Setup.dist_old
95- 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
96-
97- touch patchPY
98-
99- extractedPY : $(PYFILE )
100- tar xfzv $(PYFILE ) && touch extractedPY
101-
102- $(PYFILE ) :
103- wget -O " $( PYFILE) " " $( PYLINK) " || curl -Lo " $( PYFILE) " " $( PYLINK) "
104-
105- cleanPY :
106- @rm -rf $(PYDIR ) $(PYFILE ) patchPY extractedPY compilePY linkPY distfPY soospatchPY libpython* .a
107-
108-
10912# ---------------------------------------------------------------------------------
11013# TARGET is the name of the output
11114# BUILD is the directory where object files & intermediate files will be placed
@@ -132,9 +35,31 @@ SOURCES := source
13235DATA := data
13336INCLUDES := include
13437EXEFS_SRC := exefs_src
135- APP_TITLEID := Pynx
136- APP_AUTHOR := nx-python Authors, Python Software Foundation
137- APP_VERSION := 0.1.0-alpha
38+
39+ # ---------------------------------------------------------------------------------
40+ # options for code generation
41+ # ---------------------------------------------------------------------------------
42+ ARCH := -march=armv8-a -mtune=cortex-a57 -mtp=soft -fPIE
43+
44+ CFLAGS := -g -Wall -O2 -ffunction-sections \
45+ $(ARCH ) $(DEFINES )
46+
47+ CFLAGS += $(INCLUDE ) -D__SWITCH__
48+
49+ CXXFLAGS := $(CFLAGS ) -fno-rtti -fno-exceptions -std=gnu++11
50+
51+ ASFLAGS := -g $(ARCH )
52+ LDFLAGS = -specs=$(DEVKITPRO ) /libnx/switch.specs -g $(ARCH ) -Wl,-Map,$(notdir $* .map)
53+
54+ LIBS := -lpython2.7 -lm -lnx
55+
56+ # ---------------------------------------------------------------------------------
57+ # list of directories containing libraries, this must be the top level containing
58+ # include and lib
59+ # ---------------------------------------------------------------------------------
60+ NXPY := $(CURDIR ) /python_build/nxpy2.7.12
61+ LIBDIRS := $(PORTLIBS ) $(LIBNX ) $(NXPY )
62+
13863
13964# ---------------------------------------------------------------------------------
14065# no real need to edit anything past this point unless you need to add additional
@@ -211,12 +136,12 @@ endif
211136# ---------------------------------------------------------------------------------
212137all : $(BUILD )
213138
214- $(BUILD ) : distfPY
139+ $(BUILD ) :
215140 @[ -d $@ ] || mkdir -p $@
216141 @$(MAKE ) --no-print-directory -C $(BUILD ) -f $(CURDIR ) /Makefile
217142
218143# ---------------------------------------------------------------------------------
219- clean : cleanPY
144+ clean :
220145 @echo clean ...
221146 @rm -fr $(BUILD ) $(TARGET ) .pfs0 $(TARGET ) .nso $(TARGET ) .nro $(TARGET ) .nacp $(TARGET ) .elf
222147
0 commit comments