Skip to content

Commit

Permalink
Added makefile for building 32 bit Windows version of JyNI.
Browse files Browse the repository at this point in the history
  • Loading branch information
Stewori committed Sep 21, 2017
1 parent 0511a32 commit d3c83cf
Show file tree
Hide file tree
Showing 2 changed files with 161 additions and 1 deletion.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,8 @@ To run tests and demos, see section [Test Example](#test-example)
- for Linux/GCC type `make`
- for Linux/CLANG type `make -f makefile.clang`
- for OS-X type `make -f makefile.osx`
- for Windows type `make -f makefile.win64`
- for Windows (64 bit) type `make -f makefile.win64`
- for Windows (32 bit) type `make -f makefile.win32` (not tested)

Optionally run `make clean` or e.g. `make -f makefile.osx clean` respectively.
The resulting binaries are placed in the subfolder named `build`.
Expand Down
159 changes: 159 additions & 0 deletions makefile.win32
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
# Copyright of JyNI:
# Copyright (c) 2013, 2014, 2015, 2016, 2017 Stefan Richthofer.
# All rights reserved.
#
#
# Copyright of Python and Jython:
# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008,
# 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017
# Python Software Foundation.
# All rights reserved.
#
#
# This file is part of JyNI.
#
# JyNI is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as
# published by the Free Software Foundation, either version 3 of
# the License, or (at your option) any later version.
#
# JyNI is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with JyNI. If not, see <http://www.gnu.org/licenses/>.
#
#
#
# makefile for JyNI on Windows
#
# Author: Stefan Richthofer
#

# These variables might need adjustment by the user:
# PYTHON_HOME, JYTHON, JAVA_HOME, VC_Python, JAVA, JC

# PYTHON_HOME = "C:\Program Files\Python\Python2.7.13"
# With Python 2.7: python -c "import os, sys; print os.path.dirname(sys.executable)"
PYTHON_HOME = "$(shell python JyNI-Lib\python_home_winreg.py)"

# Adjust the following line to point to Jython >=2.7.1
JYTHON = jython.jar
# for instance, if you extracted it to your home folder:
# JYTHON = /home/your_name/jython.jar

SHELL = cmd

# You can explicitly set JAVA_HOME here.
# By default it will be guessed via "where javac", see lower line.
# Note that predefined JAVA_HOME might not be quoted, which is required for whitespaces.
# JAVA_HOME = "C:\Program Files\Java\jdk1.8.0_121"
JAVA_HOME = $(subst \bin\javac.exe,, "$(shell where javac)")

# (get the compiler from https://www.microsoft.com/en-us/download/details.aspx?id=44266)
# We set VC_Python to the default install location for a user-install.
# This might need adjustment in some cases.
USER = $(shell echo %username%)
VC_Python = "C:\Users\$(USER)\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\9.0"

CC = $(VC_Python)\VC\bin\cl
LK = $(VC_Python)\VC\bin\link
MT = $(VC_Python)\WinSDK\Bin\mt
JC = javac
JAVA = java
OUTPUTDIR = build

PLATFORM = win32

JYNI = JyNI-Java\src
JYNIBIN = JyNI-Java\bin
JYNIBIN2 = JyNI-Java\\bin

JYNI_INCLUDES = /I./JyNI-C/include /I./JyNI-C/include/Python_JyNI /I./JyNI-Java/include /I./JyNI-C/src/PC /I $(JAVA_HOME)/include /I $(JAVA_HOME)/include/$(PLATFORM)
INCLUDES = /I$(VC_Python)/VC/Include /I$(VC_Python)/WinSDK/Include $(JYNI_INCLUDES) /I$(PYTHON_HOME)/include

LIBS = $(VC_Python)/VC/lib/msvcrt.lib $(VC_Python)/VC/lib/libcmt.lib $(VC_Python)/VC/lib/OLDNAMES.lib $(VC_Python)/WinSDK/lib/Kernel32.lib $(VC_Python)/WinSDK/lib/uuid.lib $(VC_Python)/WinSDK/lib/User32.lib $(VC_Python)/WinSDK/lib/Dbghelp.lib $(VC_Python)/WinSDK/lib/AdvAPI32.lib

CFLAGS = /w $(INCLUDES) /DPy_BUILD_CORE /MD /nologo /Ox /GS- /DNDEBUG

# You can optionally remove -source 1.7 -target 1.7. It's purpose is to achieve maximal compatibility by default.
JFLAGS= -cp $(JYTHON);$(JYNI) -d $(JYNIBIN) -source 1.7 -target 1.7

SOURCES = $(wildcard JyNI-C/src/*.c) $(wildcard JyNI-C/src/Python/*.c) $(wildcard JyNI-C/src/Objects/*.c) $(wildcard JyNI-C/src/Modules/*.c) $(wildcard JyNI-C/src/PC/*.c)
OBJECTS = $(SOURCES:.c=.obj)
JSOURCES = $(wildcard JyNI-Java/src/JyNI/*.java) $(wildcard JyNI-Java/src/JyNI/gc/*.java)

all: $(OUTPUTDIR) libJyNI JyNI
@echo.
@echo Build successful.

$(OUTPUTDIR):
mkdir $(OUTPUTDIR)

$(OUTPUTDIR)/JyNI.dll:
mkdir $(OUTPUTDIR)\JyNI.dll

%.obj: %.c
$(CC) /c /Fo./$@ $(CFLAGS) $<

JyNI-C/src/Python/dynload_win.obj:
$(CC) /c /Fo./JyNI-C/src/Python/dynload_win.obj $(CFLAGS) JyNI-C/src/Python/dynload/dynload_win.c

$(JYTHON):
@echo.
@echo ------------------------------------------------
@echo Fatal error: Could not find jython.jar.
@echo Either put jython.jar into the JyNI base folder,
@echo or adjust the JYTHON-variable at the top of
@echo makefile to point to your installed jython.jar.
@echo Be sure to use Jython 2.7.1 or newer.
@echo ------------------------------------------------
@echo.
@false

libJyNI: $(OUTPUTDIR)/JyNI.dll $(OBJECTS) JyNI-C/src/Python/dynload_win.obj
$(LK) /DLL /OUT:$(OUTPUTDIR)/JyNI.dll/python27.dll $(OBJECTS) JyNI-C/src/Python/dynload_win.obj $(LIBS)
$(MT) -nologo -manifest JyNI-C/python27.dll.manifest -outputresource:$(OUTPUTDIR)/JyNI.dll/python27.dll;2
del $(OUTPUTDIR)\JyNI.dll\python27.lib
del $(OUTPUTDIR)\JyNI.dll\python27.exp
del $(OUTPUTDIR)\JyNI.dll\python27.dll.manifest
# We delete JyNI.dll\python27.lib here, because in any case one should link against original python27.lib.
# So this is a useless file and we avoid confusion and invalid linking.

$(JYNIBIN):
mkdir $(JYNIBIN)
mkdir $(JYNIBIN)\ctypes
mkdir $(JYNIBIN)\ctypes\macholib
mkdir $(JYNIBIN)\sqlite3
mkdir $(JYNIBIN)\META-INF\services

$(JYNIBIN)/JyNI: $(JYNIBIN)
$(JC) $(JFLAGS) $(JSOURCES)

$(JYNIBIN)/Lib: $(JYTHON) $(JYNIBIN)
copy JyNI-Lib\*.py $(JYNIBIN)
copy JyNI-Lib\ctypes\*.py $(JYNIBIN)\ctypes
copy JyNI-Lib\ctypes\macholib\*.py $(JYNIBIN)\ctypes\macholib
copy JyNI-Lib\sqlite3\*.py $(JYNIBIN)\sqlite3
$(JAVA) -cp $(JYTHON) org.python.util.jython -c "import compileall; compileall.compile_dir('$(JYNIBIN2)')"

JyNI: $(JYTHON) $(JYNIBIN)/JyNI $(JYNIBIN)/Lib
copy JyNI-Java\META-INF\services\org.python.core.JythonInitializer $(JYNIBIN)\META-INF\services
jar cvf $(OUTPUTDIR)\JyNI.jar -C $(JYNIBIN) .

cleanJ:
RD /S /Q $(JYNIBIN)

clean:
del JyNI-C\src\*.obj
del JyNI-C\src\Python\*.obj
del JyNI-C\src\Objects\*.obj
del JyNI-C\src\Modules\*.obj
del JyNI-C\src\PC\*.obj
RD /S /Q $(JYNIBIN)

#.PHONY: JyNI libJyNI libJyNI-Loader clean cleanJ JAVA_HOME_hint all
.PHONY: all

0 comments on commit d3c83cf

Please sign in to comment.