diff --git a/Makefile b/Makefile index b23da6a..9d6d59c 100644 --- a/Makefile +++ b/Makefile @@ -16,22 +16,45 @@ CPPFLAGS += -DNDEBUG -D_REENTRANT \ -Ispidermonkey/src -Ispidermonkey/src/build \ -I/usr/include \ - +# Try to get a Python 2. On macOS there isn't a "python2". On +# SmartOS pkgsrc 2019Q2 minimal "python" is v3. +ifeq ($(BUILDOS),Darwin) +# As of macOS 12, we can't use the system python anymore, so take the +# first one that's not in /usr/bin. + PY_EXEC=$(shell type -a --path python2.7 | grep -v /usr/bin/python | head -1) +else + PY_EXEC=$(shell /usr/bin/command -v python2.7) +endif +ifeq ($(PY_EXEC),) +# If we get here, there wasn't a python2.7 binary. It's getting pretty +# untennable at this point, because even as it is, python2.7 isn't +# supported anymore, and anything older than that is even worse off, but +# at least we won't break anybody who was previously working. +# +# For macOS 12 that gets here, this will pick up the system python which +# will refuse to link later because linking against system python is +# no longer allowed. That means that while it's still broken, there's +# nothing we can do about it and we're no worse off than before. If you're +# reading this trying to figure out how to compile this on macOS 12+, +# you need to install your own python2.7 and have that in your PATH. + PY_EXEC=$(shell /usr/bin/command -v python2) +endif +ifeq ($(PY_EXEC),) + PY_EXEC=python +endif +PY_PYTHON=$(shell $(PY_EXEC) -c "import sys; print(sys.executable)") +PY_PREFIX=$(shell $(PY_PYTHON) -c "import sys; print(sys.real_prefix)" || $(PY_PYTHON) -c "import sys; print(sys.prefix)") +PY_VERSION=$(shell $(PY_PYTHON) -c "import sys; print('.'.join(map(str, sys.version_info[:2])))") ifeq ($(BUILDOS),Darwin) - PY_PREFIX=$(shell python2.6 -c "import sys; sys.stdout.write(sys.prefix)") - PY_FIRST_ARCH=$(shell set -x; file `which python2.6` | grep "for architecture" | head -1 | awk '{print $$NF}') - CPPFLAGS += -I$(PY_PREFIX)/include/python2.6 - SOLDFLAGS += $(PY_PREFIX)/Python - LD=gcc -arch $(PY_FIRST_ARCH) - CC=gcc -arch $(PY_FIRST_ARCH) + PY_ARCH=$(shell $(PY_PYTHON) -c 'import platform; print platform.machine()') + SOLDFLAGS += -lpython$(PY_VERSION) + CC=gcc -arch $(PY_ARCH) else -# This is known to work on 2.6 and 2.7. - PY_PREFIX=$(shell python -c "import sys; sys.stdout.write(sys.prefix)") - PY_VERSION=$(shell python -c "import sys; import platform; sys.stdout.write(platform.python_version()[0:3])") - CPPFLAGS += \ - -I$(PY_PREFIX)/include/python$(PY_VERSION) + PY_BIT=$(shell $(PY_PYTHON) -c 'import sys; print (sys.maxint > 2**32 and "64" or "32")') + CFLAGS += -m$(PY_BIT) endif +CPPFLAGS += -I$(PY_PREFIX)/include/python$(PY_VERSION) SOFILE = $(BUILDDIR)/pyspidermonkey.so all: $(SOFILE) @@ -42,13 +65,13 @@ $(BUILDDIR) $(INSTALLDIRS): $(OBJECTS): spidermonkey/src/build/libjs.a spidermonkey/src/build/js_operating_system.h $(SOFILE): $(OBJECTS) - $(LD) $(SOLDFLAGS) $(LDFLAGS) $(OBJECTS) -Lspidermonkey/src/build -ljs -o $@ + $(CC) $(CFLAGS) $(SOLDFLAGS) $(LDFLAGS) $(OBJECTS) -L$(PY_PREFIX)/lib -Lspidermonkey/src/build -ljs -o $@ $(BUILDDIR)/%.o: javascriptlint/pyspidermonkey/%.c | $(BUILDDIR) $(CC) -o $@ -c $(CFLAGS) $(CPPFLAGS) $< spidermonkey/src/build/libjs.a: - (cd spidermonkey/src && CC="$(CC)" $(MAKE)) + (cd spidermonkey/src && CC="$(CC)" CFLAGS="$(CFLAGS)" $(MAKE)) spidermonkey/src/build/js_operating_system.h: echo "#define XP_UNIX" > $@ @@ -58,7 +81,13 @@ clean: -(cd spidermonkey/src && $(MAKE) clean) install: $(SOFILE) javascriptlint/jsl javascriptlint/jsl | $(INSTALLDIRS) - cp javascriptlint/jsl $(SOFILE) build/install + cp $(SOFILE) build/install cp javascriptlint/*.py build/install/javascriptlint + sed -e "1s:#\!/usr/bin/env python:#\!$(PY_PYTHON):" javascriptlint/jsl >build/install/jsl + chmod +x build/install/jsl + sed -e "1s:#\!/usr/bin/env python:#\!$(PY_PYTHON):" javascriptlint/jsl.py >build/install/javascriptlint/jsl.py + chmod +x build/install/javascriptlint/jsl.py + sed -e "1s:#\!/usr/bin/env python:#\!$(PY_PYTHON):" javascriptlint/jsparse.py >build/install/javascriptlint/jsparse.py + sed -e "1s:#\!/usr/bin/env python:#\!$(PY_PYTHON):" javascriptlint/lint.py >build/install/javascriptlint/lint.py .PHONY: install diff --git a/README.md b/README.md index 5db244b..1e281bc 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ tools: for cases where potentially dangerous behavior is being deliberately used carefully. -If you want style, see http://github.com/davepacheco/jsstyle. +If you want a style checker, see http://github.com/davepacheco/jsstyle. Synopsis @@ -55,9 +55,11 @@ Supported Platforms This branch of JSL has been tested on: -- SmartOS (Illumos-based) with Python 2.6. -- Mac OS X >=10.6 with Python 2.6. I.e. does `which python2.6` return something? +- SmartOS (illumos-based), both 32-bit and 64-bit. +- Mac OS X Snow Leopard, Lion, and Mountain Lion. +- Debian Squeeze (6.0.5). +All of these use Python 2.6 or later. History ------- @@ -66,8 +68,7 @@ This version forked from the Subversion repo at revision 302 (2011-04-06). I'll happily look at incorporating new patches from upstream, though the project has been pretty quiet for the last many months. -The main purpose of this fork is to fix building on Illumos-based systems. -Rather than fix the complex spidermonkey build system to work on Illumos, I +The main purpose of this fork is to fix building on illumos-based systems. +Rather than fix the complex spidermonkey build system to work on illumos, I stripped out a bunch of unnecessary pieces and Makefiles and wrote a new set of -Makefiles. The result now builds on Mac OSX as well, and should build on Linux -with minimal changes to the Makefile. +Makefiles. The result now builds on Mac OS X and Linux as well. diff --git a/javascriptlint/jsl b/javascriptlint/jsl index 1d8cd75..a18794b 100755 --- a/javascriptlint/jsl +++ b/javascriptlint/jsl @@ -1,4 +1,4 @@ -#!/usr/bin/env python2.6 +#!/usr/bin/env python import os import sys diff --git a/javascriptlint/jsl.py b/javascriptlint/jsl.py index f586d01..4eee0b6 100755 --- a/javascriptlint/jsl.py +++ b/javascriptlint/jsl.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python2.6 +#!/usr/bin/env python # vim: ts=4 sw=4 expandtab import codecs import fnmatch diff --git a/javascriptlint/jsparse.py b/javascriptlint/jsparse.py index 7dad7dc..eec82a4 100644 --- a/javascriptlint/jsparse.py +++ b/javascriptlint/jsparse.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python2.6 +#!/usr/bin/env python # vim: ts=4 sw=4 expandtab """ Parses a script into nodes. """ import bisect diff --git a/javascriptlint/lint.py b/javascriptlint/lint.py index 14d2849..f2967a4 100644 --- a/javascriptlint/lint.py +++ b/javascriptlint/lint.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python2.6 +#!/usr/bin/env python # vim: ts=4 sw=4 expandtab import os.path import re diff --git a/spidermonkey/src/Makefile b/spidermonkey/src/Makefile index b809650..844d62c 100644 --- a/spidermonkey/src/Makefile +++ b/spidermonkey/src/Makefile @@ -52,19 +52,19 @@ $(BUILDDIR)/libjs.a: $(BUILDDIR)/jsautocfg.h $(BUILDDIR)/jsautokw.h $(OBJECTS) $(AR) rv $@ $(OBJECTS) $(BUILDDIR)/%.o: %.c | $(BUILDDIR) - $(CC) -o $@ -c $(CFLAGS) $(CPPFLAGS) $^ + $(CC) $(CFLAGS) $(CPPFLAGS) -o $@ -c $^ clean: -rm -rf $(BUILDDIR) $(BUILDDIR)/jscpucfg: $(BUILDDIR)/jscpucfg.o - $(CC) -o $@ $^ + $(CC) $(CFLAGS) -o $@ $^ $(BUILDDIR)/jsautocfg.h: $(BUILDDIR)/jscpucfg $(BUILDDIR)/jscpucfg > $@ $(BUILDDIR)/jskwgen: $(BUILDDIR)/jskwgen.o - $(CC) -o $@ $^ + $(CC) $(CFLAGS) -o $@ $^ $(BUILDDIR)/jsautokw.h: $(BUILDDIR)/jskwgen $(BUILDDIR)/jskwgen > $@