From 64275cdb51b2653f129c20e62f26910f57c2a8ab Mon Sep 17 00:00:00 2001 From: Trent Mick Date: Mon, 27 Aug 2012 12:13:39 -0700 Subject: [PATCH 1/8] Fix build out of the box on Mountain Lion (10.8). - Stop hardcoding python2.6. - Build with the arch reported by `uname -m` instead of the first arch listed in `file .../python`. This is my best guess as to the arch used by the system when launching a universal binary. - Fix shebang lines in installed binaries to explicitly point to the Python for which we built. work around broken pkg_alternatives in pkgsrc (internal DATASET-277) fix build to work against 64-bit python on smartos (at least) Fix build for when python runs in different bit-ness than `uname -m` on Mac. Also clean up some whitespace. use CFLAGS instead of CC for '-mNN' --- Makefile | 31 ++++++++++++++++++------------- javascriptlint/jsl | 2 +- javascriptlint/jsl.py | 2 +- javascriptlint/jsparse.py | 2 +- javascriptlint/lint.py | 2 +- spidermonkey/src/Makefile | 6 +++--- 6 files changed, 25 insertions(+), 20 deletions(-) diff --git a/Makefile b/Makefile index b23da6a..864262b 100644 --- a/Makefile +++ b/Makefile @@ -17,19 +17,18 @@ CPPFLAGS += -DNDEBUG -D_REENTRANT \ -I/usr/include \ +PY_PYTHON=$(shell python -c "import sys; print(sys.executable)") +PY_PREFIX=$(shell $(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 + PY_ARCH=$(shell $(PY_PYTHON) -c 'import sys; print (sys.maxint > 2**32 and "x86_64" or "i386")') + CPPFLAGS += -I$(PY_PREFIX)/include/python$(PY_VERSION) SOLDFLAGS += $(PY_PREFIX)/Python - LD=gcc -arch $(PY_FIRST_ARCH) - CC=gcc -arch $(PY_FIRST_ARCH) + 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")') + CPPFLAGS += -I$(PY_PREFIX)/include/python$(PY_VERSION) + CFLAGS += -m$(PY_BIT) endif SOFILE = $(BUILDDIR)/pyspidermonkey.so @@ -42,13 +41,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) -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 +57,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/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 > $@ From 8377c73dee9431299427600e09a2497c1256af56 Mon Sep 17 00:00:00 2001 From: Dave Pacheco Date: Tue, 28 Aug 2012 12:24:45 -0700 Subject: [PATCH 2/8] commonize CPPFLAGS definition --- Makefile | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 864262b..398c106 100644 --- a/Makefile +++ b/Makefile @@ -22,15 +22,14 @@ PY_PREFIX=$(shell $(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_ARCH=$(shell $(PY_PYTHON) -c 'import sys; print (sys.maxint > 2**32 and "x86_64" or "i386")') - CPPFLAGS += -I$(PY_PREFIX)/include/python$(PY_VERSION) SOLDFLAGS += $(PY_PREFIX)/Python CC=gcc -arch $(PY_ARCH) else PY_BIT=$(shell $(PY_PYTHON) -c 'import sys; print (sys.maxint > 2**32 and "64" or "32")') - CPPFLAGS += -I$(PY_PREFIX)/include/python$(PY_VERSION) CFLAGS += -m$(PY_BIT) endif +CPPFLAGS += -I$(PY_PREFIX)/include/python$(PY_VERSION) SOFILE = $(BUILDDIR)/pyspidermonkey.so all: $(SOFILE) From e1bd0abfd424811af469d1ece3af131d95443924 Mon Sep 17 00:00:00 2001 From: David Pacheco Date: Tue, 28 Aug 2012 13:48:09 -0700 Subject: [PATCH 3/8] Update README.md --- README.md | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) 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. From 040bf5e429969ae42d976b570fd64c9e17fab20f Mon Sep 17 00:00:00 2001 From: Mark Cavage Date: Tue, 28 Jul 2015 11:08:18 -0700 Subject: [PATCH 4/8] Build doesn't work inside a python "venv" --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 398c106..521952e 100644 --- a/Makefile +++ b/Makefile @@ -18,7 +18,7 @@ CPPFLAGS += -DNDEBUG -D_REENTRANT \ PY_PYTHON=$(shell python -c "import sys; print(sys.executable)") -PY_PREFIX=$(shell $(PY_PYTHON) -c "import sys; print(sys.prefix)") +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_ARCH=$(shell $(PY_PYTHON) -c 'import sys; print (sys.maxint > 2**32 and "x86_64" or "i386")') From ad52812e77bdfb1e90fb71a1201adb2b665a27e6 Mon Sep 17 00:00:00 2001 From: Cody Peter Mello Date: Wed, 7 Dec 2016 11:30:31 -0800 Subject: [PATCH 5/8] davepacheco/javascriptlint#20 does not build on OS X El Capitan with pkgsrc python 2.7 --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 521952e..e734698 100644 --- a/Makefile +++ b/Makefile @@ -22,7 +22,7 @@ PY_PREFIX=$(shell $(PY_PYTHON) -c "import sys; print(sys.real_prefix)" || $(PY_P PY_VERSION=$(shell $(PY_PYTHON) -c "import sys; print('.'.join(map(str, sys.version_info[:2])))") ifeq ($(BUILDOS),Darwin) PY_ARCH=$(shell $(PY_PYTHON) -c 'import sys; print (sys.maxint > 2**32 and "x86_64" or "i386")') - SOLDFLAGS += $(PY_PREFIX)/Python + SOLDFLAGS += -lpython$(PY_VERSION) CC=gcc -arch $(PY_ARCH) else PY_BIT=$(shell $(PY_PYTHON) -c 'import sys; print (sys.maxint > 2**32 and "64" or "32")') @@ -40,7 +40,7 @@ $(BUILDDIR) $(INSTALLDIRS): $(OBJECTS): spidermonkey/src/build/libjs.a spidermonkey/src/build/js_operating_system.h $(SOFILE): $(OBJECTS) - $(CC) $(CFLAGS) $(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) $< From ccd43750f72a64edb2ffc6c4c204b8fd3b07cac7 Mon Sep 17 00:00:00 2001 From: Trent Mick Date: Tue, 29 Oct 2019 11:58:52 -0700 Subject: [PATCH 6/8] TOOLS-2359 javascriptlint breaks on 19.2 images because it is incompatible with python3 (#24) This attempts to only use Python 2 -- looking for `which python2` first in case `which python` is actually a Python 3. --- Makefile | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index e734698..b9ba778 100644 --- a/Makefile +++ b/Makefile @@ -16,8 +16,16 @@ CPPFLAGS += -DNDEBUG -D_REENTRANT \ -Ispidermonkey/src -Ispidermonkey/src/build \ -I/usr/include \ - -PY_PYTHON=$(shell python -c "import sys; print(sys.executable)") +# Try to get a Python 2. On macOS there isn't a "python2". On +# SmartOS pkgsrc 2019Q2 minimal "python" is v3. +PY_EXEC=$(shell which python2.7) +ifndef PY_EXEC + PY_EXEC=$(shell which python2) +endif +ifndef 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) From a365abebde31d1f7cc57741f365a3025dc4527ca Mon Sep 17 00:00:00 2001 From: Brian Bennett Date: Thu, 6 Jan 2022 11:38:02 -0800 Subject: [PATCH 7/8] Fix compiling on macOS 12 and M1 processors. (#28) Reviewed by: Dan McDonald --- Makefile | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index b9ba778..4a645a9 100644 --- a/Makefile +++ b/Makefile @@ -18,8 +18,25 @@ CPPFLAGS += -DNDEBUG -D_REENTRANT \ # Try to get a Python 2. On macOS there isn't a "python2". On # SmartOS pkgsrc 2019Q2 minimal "python" is v3. -PY_EXEC=$(shell which python2.7) +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 which -a python2.7 | grep -v /usr/bin/python | head -1) +else + PY_EXEC=$(shell which python2.7) +endif ifndef 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 which python2) endif ifndef PY_EXEC @@ -29,7 +46,7 @@ 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_ARCH=$(shell $(PY_PYTHON) -c 'import sys; print (sys.maxint > 2**32 and "x86_64" or "i386")') + PY_ARCH=$(shell $(PY_PYTHON) -c 'import platform; print platform.machine()') SOLDFLAGS += -lpython$(PY_VERSION) CC=gcc -arch $(PY_ARCH) else From aff7fdd4e07e6f6a7806cb9dc57a65ecb07c0073 Mon Sep 17 00:00:00 2001 From: Brian Bennett Date: Fri, 8 Apr 2022 12:28:01 -0700 Subject: [PATCH 8/8] javascriptlint#29 "which" is useless for finding command paths (#30) Reviewed by: Dan McDonald --- Makefile | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index 4a645a9..9d6d59c 100644 --- a/Makefile +++ b/Makefile @@ -21,11 +21,11 @@ CPPFLAGS += -DNDEBUG -D_REENTRANT \ 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 which -a python2.7 | grep -v /usr/bin/python | head -1) + PY_EXEC=$(shell type -a --path python2.7 | grep -v /usr/bin/python | head -1) else - PY_EXEC=$(shell which python2.7) + PY_EXEC=$(shell /usr/bin/command -v python2.7) endif -ifndef PY_EXEC +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 @@ -37,9 +37,9 @@ ifndef PY_EXEC # 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 which python2) + PY_EXEC=$(shell /usr/bin/command -v python2) endif -ifndef PY_EXEC +ifeq ($(PY_EXEC),) PY_EXEC=python endif PY_PYTHON=$(shell $(PY_EXEC) -c "import sys; print(sys.executable)")