From de6369c976cd95c71ff7ed92c9e2b9b9f3ffbe8d Mon Sep 17 00:00:00 2001 From: dmerge <25472575+dmerge@users.noreply.github.com> Date: Thu, 8 Mar 2018 23:14:03 -0800 Subject: [PATCH] [Makefile] Add option to compile to bytecode when building youtube-dl --- Makefile | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index fe247810f..aa2c065b6 100644 --- a/Makefile +++ b/Makefile @@ -11,6 +11,13 @@ MANDIR ?= $(PREFIX)/man SHAREDIR ?= $(PREFIX)/share PYTHON ?= /usr/bin/env python +COMPILE ?= no +COMPILEFLAGS := -q +# Write to legacy location for python >=3.2, instead of __pycache__ +ifneq ($(shell $(PYTHON) --version 2>&1 | grep '^Python 3\.[2-9]'),) +COMPILEFLAGS += -b +endif + # set SYSCONFDIR to /etc if PREFIX=/usr or PREFIX=/usr/local SYSCONFDIR = $(shell if [ $(PREFIX) = /usr -o $(PREFIX) = /usr/local ]; then echo /etc; else echo $(PREFIX)/etc; fi) @@ -62,7 +69,10 @@ youtube-dl: youtube_dl/*.py youtube_dl/*/*.py done touch -t 200001010101 zip/youtube_dl/*.py zip/youtube_dl/*/*.py mv zip/youtube_dl/__main__.py zip/ - cd zip ; zip -q ../youtube-dl youtube_dl/*.py youtube_dl/*/*.py __main__.py + if [ "$(COMPILE)" = yes ] ; then \ + $(PYTHON) -m compileall $(COMPILEFLAGS) zip/ ;\ + fi + cd zip ; zip -q ../youtube-dl youtube_dl/*.py* youtube_dl/*/*.py* __main__.py* rm -rf zip echo '#!$(PYTHON)' > youtube-dl cat youtube-dl.zip >> youtube-dl