[build] Use Python-bi-lingual header for POSIX executable (#33308)

Thanks: Mozilla Foundation

To build with the plain shebang, invoke the `Makefile` with `PYTHON=python` or `PYTHON=python3`.
This commit is contained in:
dirkf 2026-11-04 16:24:39 +00:00 committed by GitHub
parent a0379b9e51
commit 237f968e32
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -9,7 +9,7 @@ PREFIX ?= /usr/local
BINDIR ?= $(PREFIX)/bin
MANDIR ?= $(PREFIX)/man
SHAREDIR ?= $(PREFIX)/share
PYTHON ?= /usr/bin/env python
PYTHON ?=
# 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)
@ -65,12 +65,17 @@ 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
cd zip && zip -q "../$@" youtube_dl/*.py youtube_dl/*/*.py __main__.py
rm -rf zip
echo '#!$(PYTHON)' > youtube-dl
cat youtube-dl.zip >> youtube-dl
rm youtube-dl.zip
chmod a+x youtube-dl
[ -n "$(PYTHON)" ] && > "$@" echo "#!$(PYTHON)" || > "$@" echo "#!/bin/sh\\n\
''':'\\n\
python=python3\\n\
command -v \"\$$python\" > /dev/null || python=python\\n\
exec /usr/bin/env \"\$$python\" \"\$$0\" \"\$$@\"\\n\
'''"
cat "$@.zip" >> "$@"
rm "$@.zip"
chmod a+x "$@"
README.md: youtube_dl/*.py youtube_dl/*/*.py
COLUMNS=80 $(PYTHON) youtube_dl/__main__.py --help | $(PYTHON) devscripts/make_readme.py