annotate Makefile.freebsd @ 31:baeb8bdeff3a

Fortify sources using _FORTIFY_SOURCE=3 and also apply -fno-delete-null-pointer-checks. See: https://github.com/ossf/wg-best-practices-os-developers/issues/659.
author Franz Glasner <fzglas.hg@dom66.de>
date Sun, 21 Sep 2025 13:11:30 +0200
parents 2f43e400f144
children 72c1b70d4f5c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6
b5f06508363a PyMuPDF builds on FreeBSD now with "gmake -f Makefile.freebsd".
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1 # -*- mode: makefile; coding: utf-8 -*-
b5f06508363a PyMuPDF builds on FreeBSD now with "gmake -f Makefile.freebsd".
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2 #
10
76e05e28f6a8 Also use the LLVM linker by symlinking and use LLVM's ar now
Franz Glasner <fzglas.hg@dom66.de>
parents: 9
diff changeset
3 # Needs GNU make (aka gmake) and binutils/ar or LLVM/ar
76e05e28f6a8 Also use the LLVM linker by symlinking and use LLVM's ar now
Franz Glasner <fzglas.hg@dom66.de>
parents: 9
diff changeset
4 # (instead of FreeBSD /usr/bin/ar).
8
bf1744083a54 Some documentation notes into Makefile.freebsd
Franz Glasner <fzglas.hg@dom66.de>
parents: 6
diff changeset
5 #
bf1744083a54 Some documentation notes into Makefile.freebsd
Franz Glasner <fzglas.hg@dom66.de>
parents: 6
diff changeset
6 # Building against an installed mupdf package fails because the libmupdfcpp.so
bf1744083a54 Some documentation notes into Makefile.freebsd
Franz Glasner <fzglas.hg@dom66.de>
parents: 6
diff changeset
7 # is missing.
bf1744083a54 Some documentation notes into Makefile.freebsd
Franz Glasner <fzglas.hg@dom66.de>
parents: 6
diff changeset
8 #
bf1744083a54 Some documentation notes into Makefile.freebsd
Franz Glasner <fzglas.hg@dom66.de>
parents: 6
diff changeset
9 # Prepare:
bf1744083a54 Some documentation notes into Makefile.freebsd
Franz Glasner <fzglas.hg@dom66.de>
parents: 6
diff changeset
10 #
bf1744083a54 Some documentation notes into Makefile.freebsd
Franz Glasner <fzglas.hg@dom66.de>
parents: 6
diff changeset
11 # - Create a Python venv and activate it
bf1744083a54 Some documentation notes into Makefile.freebsd
Franz Glasner <fzglas.hg@dom66.de>
parents: 6
diff changeset
12 #
10
76e05e28f6a8 Also use the LLVM linker by symlinking and use LLVM's ar now
Franz Glasner <fzglas.hg@dom66.de>
parents: 9
diff changeset
13 # - Install a LLVM package that has the same version as the libclang
76e05e28f6a8 Also use the LLVM linker by symlinking and use LLVM's ar now
Franz Glasner <fzglas.hg@dom66.de>
parents: 9
diff changeset
14 # Python package that will be used/installed
76e05e28f6a8 Also use the LLVM linker by symlinking and use LLVM's ar now
Franz Glasner <fzglas.hg@dom66.de>
parents: 9
diff changeset
15 # (e.g. pkg install llvm18 because of libclang>=18,<19)
76e05e28f6a8 Also use the LLVM linker by symlinking and use LLVM's ar now
Franz Glasner <fzglas.hg@dom66.de>
parents: 9
diff changeset
16 #
76e05e28f6a8 Also use the LLVM linker by symlinking and use LLVM's ar now
Franz Glasner <fzglas.hg@dom66.de>
parents: 9
diff changeset
17 # - In the "bin"-directory of the venv symlink "make" to /usr/local/bin/gmake
76e05e28f6a8 Also use the LLVM linker by symlinking and use LLVM's ar now
Franz Glasner <fzglas.hg@dom66.de>
parents: 9
diff changeset
18 # and "ar" to /usr/local/llvm18/bin/llvm-ar
8
bf1744083a54 Some documentation notes into Makefile.freebsd
Franz Glasner <fzglas.hg@dom66.de>
parents: 6
diff changeset
19 #
bf1744083a54 Some documentation notes into Makefile.freebsd
Franz Glasner <fzglas.hg@dom66.de>
parents: 6
diff changeset
20 # * Makefiles have GNU syntax
10
76e05e28f6a8 Also use the LLVM linker by symlinking and use LLVM's ar now
Franz Glasner <fzglas.hg@dom66.de>
parents: 9
diff changeset
21 # * ar is called with @-response-files -- which are a GNU feature (also
76e05e28f6a8 Also use the LLVM linker by symlinking and use LLVM's ar now
Franz Glasner <fzglas.hg@dom66.de>
parents: 9
diff changeset
22 # implemented by LLVM's ar)
8
bf1744083a54 Some documentation notes into Makefile.freebsd
Franz Glasner <fzglas.hg@dom66.de>
parents: 6
diff changeset
23 #
bf1744083a54 Some documentation notes into Makefile.freebsd
Franz Glasner <fzglas.hg@dom66.de>
parents: 6
diff changeset
24 # - At first to not build with tesseract (OCR)
bf1744083a54 Some documentation notes into Makefile.freebsd
Franz Glasner <fzglas.hg@dom66.de>
parents: 6
diff changeset
25 #
bf1744083a54 Some documentation notes into Makefile.freebsd
Franz Glasner <fzglas.hg@dom66.de>
parents: 6
diff changeset
26 # export PYMUPDF_SETUP_MUPDF_TESSERACT=0
bf1744083a54 Some documentation notes into Makefile.freebsd
Franz Glasner <fzglas.hg@dom66.de>
parents: 6
diff changeset
27 #
6
b5f06508363a PyMuPDF builds on FreeBSD now with "gmake -f Makefile.freebsd".
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
28
21
2f43e400f144 Provide an "all" target to build both the sdist and the wheel
Franz Glasner <fzglas.hg@dom66.de>
parents: 20
diff changeset
29 .PHONY: all wheel sdist populate-venv check
16
bd5bb0742cc3 A "check" target that checks for all venv and host prerequisites
Franz Glasner <fzglas.hg@dom66.de>
parents: 15
diff changeset
30
bd5bb0742cc3 A "check" target that checks for all venv and host prerequisites
Franz Glasner <fzglas.hg@dom66.de>
parents: 15
diff changeset
31 .SILENT: check
6
b5f06508363a PyMuPDF builds on FreeBSD now with "gmake -f Makefile.freebsd".
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
32
b5f06508363a PyMuPDF builds on FreeBSD now with "gmake -f Makefile.freebsd".
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
33 THIS_MAKEFILE_JUSTNAME:= $(firstword $(MAKEFILE_LIST))
b5f06508363a PyMuPDF builds on FreeBSD now with "gmake -f Makefile.freebsd".
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
34 THIS_MAKEFILE_DIR:= $(abspath $(dir $(THIS_MAKEFILE_JUSTNAME)))
b5f06508363a PyMuPDF builds on FreeBSD now with "gmake -f Makefile.freebsd".
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
35
b5f06508363a PyMuPDF builds on FreeBSD now with "gmake -f Makefile.freebsd".
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
36 PYMUPDF_SETUP_MUPDF_BUILD?= $(THIS_MAKEFILE_DIR)/mupdf-source
b5f06508363a PyMuPDF builds on FreeBSD now with "gmake -f Makefile.freebsd".
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
37 PYMUPDF_SETUP_MUPDF_TESSERACT?= 0
b5f06508363a PyMuPDF builds on FreeBSD now with "gmake -f Makefile.freebsd".
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
38 LIBCLANG_LIBRARY_PATH?= $(CLANG_DIR)/lib
b5f06508363a PyMuPDF builds on FreeBSD now with "gmake -f Makefile.freebsd".
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
39
b5f06508363a PyMuPDF builds on FreeBSD now with "gmake -f Makefile.freebsd".
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
40 TEST= /bin/test
b5f06508363a PyMuPDF builds on FreeBSD now with "gmake -f Makefile.freebsd".
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
41 LOCALBASE?= /usr/local
b5f06508363a PyMuPDF builds on FreeBSD now with "gmake -f Makefile.freebsd".
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
42 SYMLINK?= /bin/ln -s
15
393e55ef9200 Explicitely use python3 instead of python
Franz Glasner <fzglas.hg@dom66.de>
parents: 13
diff changeset
43 PYTHON?= python3
6
b5f06508363a PyMuPDF builds on FreeBSD now with "gmake -f Makefile.freebsd".
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
44 PYTHON_PREFIXES!= $(PYTHON) -c 'import sys; print(sys.prefix); print(sys.base_prefix)'
b5f06508363a PyMuPDF builds on FreeBSD now with "gmake -f Makefile.freebsd".
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
45 CLANG_DIR?= /usr/local/llvm18
b5f06508363a PyMuPDF builds on FreeBSD now with "gmake -f Makefile.freebsd".
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
46
10
76e05e28f6a8 Also use the LLVM linker by symlinking and use LLVM's ar now
Franz Glasner <fzglas.hg@dom66.de>
parents: 9
diff changeset
47 #
76e05e28f6a8 Also use the LLVM linker by symlinking and use LLVM's ar now
Franz Glasner <fzglas.hg@dom66.de>
parents: 9
diff changeset
48 # Setting these does not work for some parts built by sub-makes.
76e05e28f6a8 Also use the LLVM linker by symlinking and use LLVM's ar now
Franz Glasner <fzglas.hg@dom66.de>
parents: 9
diff changeset
49 # Symlink in the venv instead.
76e05e28f6a8 Also use the LLVM linker by symlinking and use LLVM's ar now
Franz Glasner <fzglas.hg@dom66.de>
parents: 9
diff changeset
50 #
6
b5f06508363a PyMuPDF builds on FreeBSD now with "gmake -f Makefile.freebsd".
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
51 #CC= $(CLANG_DIR)/bin/clang
b5f06508363a PyMuPDF builds on FreeBSD now with "gmake -f Makefile.freebsd".
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
52 #CXX= $(CLANG_DIR)/bin/clang++
b5f06508363a PyMuPDF builds on FreeBSD now with "gmake -f Makefile.freebsd".
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
53
31
baeb8bdeff3a Fortify sources using _FORTIFY_SOURCE=3 and also apply -fno-delete-null-pointer-checks.
Franz Glasner <fzglas.hg@dom66.de>
parents: 21
diff changeset
54 # Define _FORTIFY_SOURCE=$(FORTIFY) (if != 0, default 0)
baeb8bdeff3a Fortify sources using _FORTIFY_SOURCE=3 and also apply -fno-delete-null-pointer-checks.
Franz Glasner <fzglas.hg@dom66.de>
parents: 21
diff changeset
55 FORTIFY?= 3
baeb8bdeff3a Fortify sources using _FORTIFY_SOURCE=3 and also apply -fno-delete-null-pointer-checks.
Franz Glasner <fzglas.hg@dom66.de>
parents: 21
diff changeset
56 #
baeb8bdeff3a Fortify sources using _FORTIFY_SOURCE=3 and also apply -fno-delete-null-pointer-checks.
Franz Glasner <fzglas.hg@dom66.de>
parents: 21
diff changeset
57 # If != 0 (default 1):
baeb8bdeff3a Fortify sources using _FORTIFY_SOURCE=3 and also apply -fno-delete-null-pointer-checks.
Franz Glasner <fzglas.hg@dom66.de>
parents: 21
diff changeset
58 # -fno-delete-null-pointer-checks
baeb8bdeff3a Fortify sources using _FORTIFY_SOURCE=3 and also apply -fno-delete-null-pointer-checks.
Franz Glasner <fzglas.hg@dom66.de>
parents: 21
diff changeset
59 #
baeb8bdeff3a Fortify sources using _FORTIFY_SOURCE=3 and also apply -fno-delete-null-pointer-checks.
Franz Glasner <fzglas.hg@dom66.de>
parents: 21
diff changeset
60 # Should always be done when fortifying:
baeb8bdeff3a Fortify sources using _FORTIFY_SOURCE=3 and also apply -fno-delete-null-pointer-checks.
Franz Glasner <fzglas.hg@dom66.de>
parents: 21
diff changeset
61 # https://github.com/ossf/wg-best-practices-os-developers/issues/659
baeb8bdeff3a Fortify sources using _FORTIFY_SOURCE=3 and also apply -fno-delete-null-pointer-checks.
Franz Glasner <fzglas.hg@dom66.de>
parents: 21
diff changeset
62 #
baeb8bdeff3a Fortify sources using _FORTIFY_SOURCE=3 and also apply -fno-delete-null-pointer-checks.
Franz Glasner <fzglas.hg@dom66.de>
parents: 21
diff changeset
63 EXTRA_CHECKS?= 1
baeb8bdeff3a Fortify sources using _FORTIFY_SOURCE=3 and also apply -fno-delete-null-pointer-checks.
Franz Glasner <fzglas.hg@dom66.de>
parents: 21
diff changeset
64
21
2f43e400f144 Provide an "all" target to build both the sdist and the wheel
Franz Glasner <fzglas.hg@dom66.de>
parents: 20
diff changeset
65
2f43e400f144 Provide an "all" target to build both the sdist and the wheel
Franz Glasner <fzglas.hg@dom66.de>
parents: 20
diff changeset
66 all: sdist wheel
2f43e400f144 Provide an "all" target to build both the sdist and the wheel
Franz Glasner <fzglas.hg@dom66.de>
parents: 20
diff changeset
67
2f43e400f144 Provide an "all" target to build both the sdist and the wheel
Franz Glasner <fzglas.hg@dom66.de>
parents: 20
diff changeset
68
19
c3ef899c5e56 Rename the "build" target to "wheel"
Franz Glasner <fzglas.hg@dom66.de>
parents: 18
diff changeset
69 wheel: check
6
b5f06508363a PyMuPDF builds on FreeBSD now with "gmake -f Makefile.freebsd".
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
70 $(TEST) -e $(firstword $(PYTHON_PREFIXES))/bin/make || $(SYMLINK) $(LOCALBASE)/bin/gmake $(firstword $(PYTHON_PREFIXES))/bin/make
10
76e05e28f6a8 Also use the LLVM linker by symlinking and use LLVM's ar now
Franz Glasner <fzglas.hg@dom66.de>
parents: 9
diff changeset
71 $(TEST) -e $(firstword $(PYTHON_PREFIXES))/bin/ar || $(SYMLINK) $(CLANG_DIR)/bin/llvm-ar $(firstword $(PYTHON_PREFIXES))/bin/ar
9
b2d41d02518f Use the LLVM compilers by symlinking them in the venv.
Franz Glasner <fzglas.hg@dom66.de>
parents: 8
diff changeset
72 $(TEST) -e $(firstword $(PYTHON_PREFIXES))/bin/cc || $(SYMLINK) $(CLANG_DIR)/bin/clang $(firstword $(PYTHON_PREFIXES))/bin/cc
b2d41d02518f Use the LLVM compilers by symlinking them in the venv.
Franz Glasner <fzglas.hg@dom66.de>
parents: 8
diff changeset
73 $(TEST) -e $(firstword $(PYTHON_PREFIXES))/bin/c++ || $(SYMLINK) $(CLANG_DIR)/bin/clang++ $(firstword $(PYTHON_PREFIXES))/bin/c++
10
76e05e28f6a8 Also use the LLVM linker by symlinking and use LLVM's ar now
Franz Glasner <fzglas.hg@dom66.de>
parents: 9
diff changeset
74 $(TEST) -e $(firstword $(PYTHON_PREFIXES))/bin/ld || $(SYMLINK) $(CLANG_DIR)/bin/ld.lld $(firstword $(PYTHON_PREFIXES))/bin/ld
31
baeb8bdeff3a Fortify sources using _FORTIFY_SOURCE=3 and also apply -fno-delete-null-pointer-checks.
Franz Glasner <fzglas.hg@dom66.de>
parents: 21
diff changeset
75 FORTIFY=$(FORTIFY) EXTRA_CHECKS=$(EXTRA_CHECKS) PIPCL_VERBOSE=2 LIBCLANG_LIBRARY_PATH=$(LIBCLANG_LIBRARY_PATH) PYMUPDF_SETUP_MUPDF_BUILD=$(PYMUPDF_SETUP_MUPDF_BUILD) PYMUPDF_SETUP_MUPDF_TESSERACT=$(PYMUPDF_SETUP_MUPDF_TESSERACT) $(PYTHON) -m build --wheel --verbose --no-isolation
11
f704f0a78213 A make target to populate the Python virtual environment
Franz Glasner <fzglas.hg@dom66.de>
parents: 10
diff changeset
76
f704f0a78213 A make target to populate the Python virtual environment
Franz Glasner <fzglas.hg@dom66.de>
parents: 10
diff changeset
77
18
dd663470c57c Make building an sdist work on FreeBSD and with Mercurial as SCM.
Franz Glasner <fzglas.hg@dom66.de>
parents: 16
diff changeset
78 sdist: check
dd663470c57c Make building an sdist work on FreeBSD and with Mercurial as SCM.
Franz Glasner <fzglas.hg@dom66.de>
parents: 16
diff changeset
79 PIPCL_VERBOSE=2 LIBCLANG_LIBRARY_PATH=$(LIBCLANG_LIBRARY_PATH) PYMUPDF_SETUP_MUPDF_BUILD=$(PYMUPDF_SETUP_MUPDF_BUILD) PYMUPDF_SETUP_MUPDF_TESSERACT=$(PYMUPDF_SETUP_MUPDF_TESSERACT) $(PYTHON) -m build --sdist --verbose --no-isolation
dd663470c57c Make building an sdist work on FreeBSD and with Mercurial as SCM.
Franz Glasner <fzglas.hg@dom66.de>
parents: 16
diff changeset
80
dd663470c57c Make building an sdist work on FreeBSD and with Mercurial as SCM.
Franz Glasner <fzglas.hg@dom66.de>
parents: 16
diff changeset
81
11
f704f0a78213 A make target to populate the Python virtual environment
Franz Glasner <fzglas.hg@dom66.de>
parents: 10
diff changeset
82 populate-venv:
f704f0a78213 A make target to populate the Python virtual environment
Franz Glasner <fzglas.hg@dom66.de>
parents: 10
diff changeset
83 ifneq ($(firstword $(PYTHON_PREFIXES)),$(lastword $(PYTHON_PREFIXES)))
f704f0a78213 A make target to populate the Python virtual environment
Franz Glasner <fzglas.hg@dom66.de>
parents: 10
diff changeset
84 $(PYTHON) -m pip install -U -r requirements-build.txt
f704f0a78213 A make target to populate the Python virtual environment
Franz Glasner <fzglas.hg@dom66.de>
parents: 10
diff changeset
85 else
f704f0a78213 A make target to populate the Python virtual environment
Franz Glasner <fzglas.hg@dom66.de>
parents: 10
diff changeset
86 $(error Not in a Python virtual environment)
f704f0a78213 A make target to populate the Python virtual environment
Franz Glasner <fzglas.hg@dom66.de>
parents: 10
diff changeset
87 endif
16
bd5bb0742cc3 A "check" target that checks for all venv and host prerequisites
Franz Glasner <fzglas.hg@dom66.de>
parents: 15
diff changeset
88
bd5bb0742cc3 A "check" target that checks for all venv and host prerequisites
Franz Glasner <fzglas.hg@dom66.de>
parents: 15
diff changeset
89
bd5bb0742cc3 A "check" target that checks for all venv and host prerequisites
Franz Glasner <fzglas.hg@dom66.de>
parents: 15
diff changeset
90 check:
bd5bb0742cc3 A "check" target that checks for all venv and host prerequisites
Franz Glasner <fzglas.hg@dom66.de>
parents: 15
diff changeset
91 ifneq ($(firstword $(PYTHON_PREFIXES)),$(lastword $(PYTHON_PREFIXES)))
bd5bb0742cc3 A "check" target that checks for all venv and host prerequisites
Franz Glasner <fzglas.hg@dom66.de>
parents: 15
diff changeset
92 $(PYTHON) -m pip freeze | grep -E '^\s*setuptools-scm==' >/dev/null
bd5bb0742cc3 A "check" target that checks for all venv and host prerequisites
Franz Glasner <fzglas.hg@dom66.de>
parents: 15
diff changeset
93 $(PYTHON) -m pip freeze | grep -E '^\s*build==' >/dev/null
bd5bb0742cc3 A "check" target that checks for all venv and host prerequisites
Franz Glasner <fzglas.hg@dom66.de>
parents: 15
diff changeset
94 $(PYTHON) -m pip freeze | grep -E '^\s*swig==' >/dev/null
bd5bb0742cc3 A "check" target that checks for all venv and host prerequisites
Franz Glasner <fzglas.hg@dom66.de>
parents: 15
diff changeset
95 $(PYTHON) -m pip freeze | grep -E '^\s*libclang==18\.' >/dev/null
bd5bb0742cc3 A "check" target that checks for all venv and host prerequisites
Franz Glasner <fzglas.hg@dom66.de>
parents: 15
diff changeset
96 $(TEST) -x $(LOCALBASE)/bin/gmake
bd5bb0742cc3 A "check" target that checks for all venv and host prerequisites
Franz Glasner <fzglas.hg@dom66.de>
parents: 15
diff changeset
97 $(TEST) -x $(LOCALBASE)/bin/cmake
bd5bb0742cc3 A "check" target that checks for all venv and host prerequisites
Franz Glasner <fzglas.hg@dom66.de>
parents: 15
diff changeset
98 $(TEST) -x $(CLANG_DIR)/bin/llvm-ar
bd5bb0742cc3 A "check" target that checks for all venv and host prerequisites
Franz Glasner <fzglas.hg@dom66.de>
parents: 15
diff changeset
99 $(TEST) -x $(CLANG_DIR)/bin/clang
bd5bb0742cc3 A "check" target that checks for all venv and host prerequisites
Franz Glasner <fzglas.hg@dom66.de>
parents: 15
diff changeset
100 $(TEST) -x $(CLANG_DIR)/bin/clang++
bd5bb0742cc3 A "check" target that checks for all venv and host prerequisites
Franz Glasner <fzglas.hg@dom66.de>
parents: 15
diff changeset
101 $(TEST) -x $(CLANG_DIR)/bin/ld.lld
bd5bb0742cc3 A "check" target that checks for all venv and host prerequisites
Franz Glasner <fzglas.hg@dom66.de>
parents: 15
diff changeset
102 else
bd5bb0742cc3 A "check" target that checks for all venv and host prerequisites
Franz Glasner <fzglas.hg@dom66.de>
parents: 15
diff changeset
103 $(error Not in a Python virtual environment)
bd5bb0742cc3 A "check" target that checks for all venv and host prerequisites
Franz Glasner <fzglas.hg@dom66.de>
parents: 15
diff changeset
104 endif