diff --git a/src/Makefile.win32 b/src/Makefile.win32 index 9827af5c..ecd962bc 100644 --- a/src/Makefile.win32 +++ b/src/Makefile.win32 @@ -22,27 +22,41 @@ # packaging script. -include version.mk +ifeq ($(OS),Windows_NT) +RM = del /Q /F +CP = copy /Y +ifdef ComSpec +SHELL := $(ComSpec) +endif +ifdef COMSPEC +SHELL := $(COMSPEC) +endif +else +RM = rm -rf +CP = cp -f +endif + LIB_VER=1 CFLAGS=-g -DXP_WIN -DWINVER=0x0501 -DVERSION=$(VERSION) -Ispidermonkey/js/src -Wall CC=gcc +PYTHON:=python .PHONY: clean pymod install-pymod -all: pacparser.dll pacparser.lib pactester +all: pacparser.dll pactester pacparser.o: pacparser.c pac_utils.h js.lib $(CC) $(CFLAGS) -c pacparser.c -o pacparser.o js.lib: $(MAKE) -C spidermonkey -f Makefile.win32 - cp spidermonkey/js.lib . -pacparser.dll: pacparser.o js.lib +pacparser.dll: pacparser.o spidermonkey/js.lib $(CC) -shared -o pacparser.dll \ -Wl,--output-def,pacparser.def \ -Wl,--out-implib,libpacparser.a \ -Wl,--export-all-symbols \ - pacparser.o -ljs -L. -lws2_32 + pacparser.o -ljs -Lspidermonkey -lws2_32 pacparser.lib: pacparser.dll pacparser.def lib /machine:i386 /def:pacparser.def @@ -50,25 +64,24 @@ pacparser.lib: pacparser.dll pacparser.def pactester: pactester.c pacparser.h pacparser.dll $(CC) pactester.c -o pactester -lpacparser -L. -I. -dist: pacparser.dll pactester +dist: pacparser.dll pactester pacparser.lib if exist dist rmdir /s /q dist mkdir dist copy pacparser.dll dist copy pacparser.h dist copy pactester.exe dist - if exist pacparser.lib copy pacparser.lib dist - copy ..\README.md dist\README.txt - copy ..\COPYING dist\COPYING.txt - copy ..\INSTALL dist\INSTALL.txt + $(CP) pacparser.lib dist + $(CP) ..\README.md dist\README.txt + $(CP) ..\COPYING dist\COPYING.txt + $(CP) ..\INSTALL dist\INSTALL.txt mkdir dist\docs - copy ..\README.win32 dist\docs + $(CP) ..\README.win32 dist\docs if exist ..\docs\html xcopy ..\docs\html dist\docs # Targets to build python module pymod: pacparser.h pacparser.dll pacparser.o js.lib - cp pacparser.o js.lib pymod/ cd pymod && $(PYTHON) setup.py build - cd .. && $(PYTHON) tests\runtests.py + cd .. && $(PYTHON) tests/runtests.py pymod2: pacparser.h pacparser.dll cd pymod && py -2.7-32 setup.py dist @@ -79,7 +92,7 @@ pymod3: pacparser.h pacparser.dll cd .. && py -3.6-32 tests\runtests.py clean: - del /F pacparser.dll *.lib pacparser.def pacparser.exp pacparser.o pactester.exe libpacparser.a + $(RM) pacparser.dll *.lib pacparser.def pacparser.exp pacparser.o pactester.exe libpacparser.a $(MAKE) -C spidermonkey -f Makefile.win32 clean - cd pymod && setup.py clean - if exist dist rmdir /s /q dist + cd pymod && $(PYTHON) setup.py clean --all + $(RM) dist diff --git a/src/pymod/Makefile.win32 b/src/pymod/Makefile.win32 deleted file mode 100644 index 9ce5275a..00000000 --- a/src/pymod/Makefile.win32 +++ /dev/null @@ -1,76 +0,0 @@ -# Copyright (C) 2007 Manu Garg. -# Author: Manu Garg -# -# Makefile for pacparser. Please read README file included with this package -# for more information about pacparser. -# -# pacparser 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 2.1 of the License, or (at your option) any later version. - -# pacparser 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 this library; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA - -CFLAGS=-g -DXP_WIN -Wall -I.. -CC=gcc - -ifndef PY_HOME - $(error PY_HOME is not defined. It should point to your installtion \ - directory e.g. C:\Python25. To avoid this error, this file should \ - be called by setup.py only, which takes care of setting that \ - variable.) -endif - -ifndef PY_DLL - $(error PY_DLL is not defined. It should point to python dll location e.g. \ - C:\Windows\System32\Python25.dll. To avoid this error, this \ - makefile should be called by setup.py only, which takes care \ - of setting that variable.) -endif - -ifndef PY_VER - $(error PY_VER is not defined. It should point to the python version \ - e.g. 27. To avoid this error, this file should \ - be called by setup.py only, which takes care of setting that \ - variable.) -endif -DISTDIR=pacparser-python$(PY_VER) - -CFLAGS+=-I"$(PY_HOME)\include" - -.PHONY: dist clean - -build: _pacparser$(PY_VER).pyd - -pacparser_py$(PY_VER).o: pacparser_py.c - $(CC) $(CFLAGS) -c pacparser_py.c -o pacparser_py$(PY_VER).o - -python$(PY_VER).dll: - cp $(PY_DLL) python$(PY_VER).dll - -_pacparser$(PY_VER).pyd: pacparser_py$(PY_VER).o python$(PY_VER).dll ..\pacparser.dll - $(CC) -shared -o _pacparser$(PY_VER).pyd pacparser_py$(PY_VER).o -lpython$(PY_VER) -L. -lpacparser -L.. -lws2_32 - -dist: build - if exist $(DISTDIR) rmdir /s /q $(DISTDIR) - mkdir $(DISTDIR) - mkdir $(DISTDIR)\pacparser - cp -a pacparser $(DISTDIR)\pacparser - cp _pacparser$(PY_VER).pyd $(DISTDIR)\pacparser\_pacparser.pyd - cp ..\pacparser.dll $(DISTDIR)\pacparser - cp install_win32.py $(DISTDIR)\install.py - cp ..\..\COPYING $(DISTDIR)\COPYING.txt - cp ..\..\README.md $(DISTDIR)\README.txt - cp ..\..\README.win32 $(DISTDIR)\README.win32.txt - cp ..\..\INSTALL $(DISTDIR)\INSTALL.txt - -clean: - rm -rf pacparser_py*.o _pacparser*.pyd - for /d %%a in (pacparser-python*) do rmdir /s /q "%%a" diff --git a/src/pymod/pacparser/__init__.py b/src/pymod/pacparser/__init__.py index a07a67aa..b4a81e1f 100644 --- a/src/pymod/pacparser/__init__.py +++ b/src/pymod/pacparser/__init__.py @@ -79,7 +79,7 @@ def find_proxy(url, host=None): m = _URL_REGEX.match(url) if not m: raise URLError(url) - if len(m.groups()) is 1: + if len(m.groups()) == 1: host = m.groups()[0] else: raise URLError(url) diff --git a/src/pymod/setup.py b/src/pymod/setup.py index 0747d8a9..994dc6e7 100644 --- a/src/pymod/setup.py +++ b/src/pymod/setup.py @@ -1,4 +1,4 @@ -# Copyright (C) 2007 Manu Garg. +# Copyright (C) 2007-2022 Manu Garg. # Author: Manu Garg # # pacparser is a library that provides methods to parse proxy auto-config @@ -28,7 +28,6 @@ import sys import os -from distutils import sysconfig from setuptools import setup from distutils.core import Extension @@ -39,7 +38,7 @@ def main(): libraries = [] extra_link_args = [] if sys.platform == 'win32': - extra_objects = ['pacparser.o', 'js.lib'] + extra_objects = ['../pacparser.o', '../spidermonkey/js.lib'] libraries = ['ws2_32'] if 'mingw32' in sys.argv or '--compiler=mingw32' in sys.argv: extra_link_args = ['-static-libgcc'] diff --git a/src/spidermonkey/Makefile.win32 b/src/spidermonkey/Makefile.win32 index 06dcb75b..5d57b2c0 100644 --- a/src/spidermonkey/Makefile.win32 +++ b/src/spidermonkey/Makefile.win32 @@ -1,8 +1,23 @@ # Project: fdlibm +ifeq ($(OS),Windows_NT) +RM = del /Q /F +CP = copy /Y +ifdef ComSpec +SHELL := $(ComSpec) +endif +ifdef COMSPEC +SHELL := $(COMSPEC) +endif +else +RM = rm -rf +CP = cp -f +endif + CC = gcc.exe JS_SRCDIR = js/src + JS_OBJECTS = \ $(JS_SRCDIR)/jsapi.o \ $(JS_SRCDIR)/jsarena.o \ @@ -44,21 +59,22 @@ CFLAGS = -D_IEEE_LIBM -DEXPORT_JS_API -DWIN32 -D_MINGW -D_WINDOWS -DXP_WIN -s all: js.lib -.c.o: $(CC) -c $(CFLAGS) -o $@ $(JS_SRCDIR)/$*.c +%.o: %.c js/src/jsautokw.h + $(CC) -c $(CFLAGS) -o $@ $< -js\src\jsautokw.h: +js/src/jsautokw.h: ifeq ($(wildcard js),) $(error JS source directory not found. Extract $(wildcard js-*.tar.gz) tarball using tool of your choice. Possible options are 7z, WinRAR, WinZip.) endif $(CC) -o jskwgen js/src/jskwgen.c jskwgen > js/src/jsautokw.h - rm jskwgen.exe + $(RM) jskwgen.exe -js.lib: js\src\jsautokw.h $(JS_OBJECTS) +js.lib: $(JS_OBJECTS) ar r js.lib $(JS_OBJECTS) ranlib js.lib clean: - rm js\src\*.o - rm js\src\jsautokw.h - rm *.lib + $(RM) js\src\*.o + $(RM) js\src\jsautokw.h + $(RM) *.lib diff --git a/tests/runtests.py b/tests/runtests.py index eb59b8c2..97603006 100644 --- a/tests/runtests.py +++ b/tests/runtests.py @@ -24,23 +24,14 @@ import glob import os import sys -from distutils import sysconfig - def runtests(pacfile, testdata, tests_dir): py_ver = '.'.join([str(x) for x in sys.version_info[0:2]]) - if sys.platform == 'win32': - pacparser_module_path = os.path.join( - tests_dir, '..', 'src', 'pymod', - 'pacparser-python%s' % sysconfig.get_config_vars('VERSION')[0]) - if os.path.exists(os.path.join(pacparser_module_path, '_pacparser.pyd')): - raise Exception('Tests failed. Could not determine pacparser path.') - else: - try: - pacparser_module_path = glob.glob(os.path.join( - tests_dir, '..', 'src', 'pymod', 'build', 'lib*%s' % py_ver))[0] - except Exception: - raise Exception('Tests failed. Could not determine pacparser path.') + try: + pacparser_module_path = glob.glob(os.path.join( + tests_dir, '..', 'src', 'pymod', 'build', 'lib*%s' % py_ver))[0] + except Exception: + raise Exception('Tests failed. Could not determine pacparser path.') if 'DEBUG' in os.environ: print('Pacparser module path: %s' % pacparser_module_path) sys.path.insert(0, pacparser_module_path)