-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
149 lines (135 loc) · 5.5 KB
/
setup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
# unvivtool Copyright (C) 2020-2024 Benjamin Futasz <https://github.com/bfut>
#
# Portions copyright, see each source file for more information.
#
# You may not redistribute this program without its source code.
# README.md may not be removed or altered from any unvivtool redistribution.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
"""
setup.py - adapted from https://github.com/pybind/python_example/blob/master/setup.py
"""
import os
import platform
import pathlib
import re
import setuptools
import sys
import sysconfig
if "UVTVERBOSE" in os.environ:
print(f'UVTVERBOSE={os.environ["UVTVERBOSE"]}')
SCRIPT_PATH = pathlib.Path(__file__).parent.resolve()
os.chdir(SCRIPT_PATH)
__version__ = re.findall(
r"#define UVTVERS \"(.*)\"",
(SCRIPT_PATH / "./libnfsviv.h").read_text("utf-8")
)[0]
print(f"VERSION_INFO={__version__}")
long_description = (SCRIPT_PATH / "./python/README.md").read_text(encoding="utf-8")
if sys.version_info.minor < 13 or sysconfig.get_config_var("Py_GIL_DISABLED") != 1 or sys._is_gil_enabled() == True:
os.environ["PYMEM_MALLOC"] = ""
if sys.version_info.minor >= 13:
if sysconfig.get_config_var("Py_GIL_DISABLED") == 1 and sys._is_gil_enabled() == False:
print(f'sysconfig.get_config_var("Py_GIL_DISABLED") = {sysconfig.get_config_var("Py_GIL_DISABLED")}')
print(f'sys._is_gil_enabled() = {sys._is_gil_enabled()}')
extra_compile_args = []
if "PYMEM_MALLOC" in os.environ:
print(f'PYMEM_MALLOC={os.environ["PYMEM_MALLOC"]}')
extra_compile_args += [ "-DPYMEM_MALLOC" ]
if platform.system() == "Windows":
extra_compile_args += [
("/wd4267"), # prevents warnings on conversion from size_t to int
("/wd4996"), # prevents warnings on fopen() and other POSIX functions
("/std:c++latest"), ("/Zc:__cplusplus"), # sets __cplusplus
]
else:
extra_compile_args += [
# debug
# ("-std=c23"),
# ("-g"),
# ("-Og"),
# ("-pedantic-errors"), # multi-phase extension gives error
("-fvisibility=hidden"), # sets the default symbol visibility to hidden
("-Wformat-security"),
("-Wdeprecated-declarations"),
]
if "gcc" in platform.python_compiler().lower():
extra_compile_args += [
# ("-Wno-sign-compare"), # prevents warnings on conversion from size_t to int
("-Wno-unused-parameter"), # self in PyObject *unviv(PyObject *self, ...)
("-Wno-missing-field-initializers"), # {NULL, NULL} in struct PyMethodDef{}
("-fasynchronous-unwind-tables"),
("-Wall"),
("-Wextra"),
("-Wstack-protector"),
("-Woverlength-strings"),
("-Wpointer-arith"),
("-Wunused-local-typedefs"),
("-Wunused-result"),
("-Wvarargs"),
("-Wvla"),
("-Wwrite-strings"), # ("-Wno-discarded-qualifiers"),
# # https://developers.redhat.com/blog/2018/03/21/compiler-and-linker-flags-gcc
("-D_GNU_SOURCE"), # realpath()
("-D_FORTIFY_SOURCE=2"),
# ("-D_GLIBCXX_ASSERTIONS"),
# ("-fexceptions"), # C++ exceptions
# ("-fplugin=annobin"),
("-fstack-clash-protection"),
("-fstack-protector-strong"),
# ("-mcet"), ("-fcf-protection"), # (x86 only)
("-Werror=format-security"),
("-Werror=implicit-function-declaration"),
# ("-Wl,-z,defs"),
# ("-Wl,-z,now"),
# ("-Wl,-z,relro"),
]
elif "clang" in platform.python_compiler().lower():
extra_compile_args += [
# ("-Weverything"),
("-Wno-braced-scalar-init"),
("-Wno-embedded-directive"),
# ("-Wno-newline-eof"),
("-D_GNU_SOURCE"),
]
ext_modules = [
setuptools.Extension(
name="unvivtool",
sources=sorted(["./python/unvivtoolmodule.c"]),
define_macros=[
("VERSION_INFO", __version__),
# ("SCL_DEVMODE", os.environ.get("SCL_DEVMODE", 0)), # 0 if key not set
# ("SCL_DEBUG", os.environ.get("SCL_DEBUG", 0)), # 0 if key not set
# defined in unvivtoolmodule.c # ("UVTUTF8", os.environ.get("UVTUTF8", 0)), # branch: unviv() detects utf8
],
extra_compile_args=extra_compile_args,
)
]
setuptools.setup(
name="unvivtool",
version=__version__,
author="Benjamin Futasz",
url="https://github.com/bfut/unvivtool",
license="GPLv3+",
description="simple BIGF BIGH BIG4 decoder/encoder (commonly known as VIV/BIG)",
long_description=long_description,
long_description_content_type="text/markdown",
ext_modules=ext_modules,
python_requires=">=3.10",
# extras_require={"test": "pytest"},
# Currently, build_ext only provides an optional "highest supported C++
# level" feature, but in the future it may provide more features.
# cmdclass={"build_ext": build_ext},
zip_safe=False,
)