diff options
author | Alexander Golubev <fatzer2@gmail.com> | 2025-07-26 15:14:39 +0300 |
---|---|---|
committer | Alexander Golubev <fatzer2@gmail.com> | 2025-07-28 16:21:55 +0300 |
commit | 5e40676b8b687a896b5365f8f77ea7efc51ba165 (patch) | |
tree | 46cc5195ce7f5c6a99a1932df42e13f5e614a069 /setup.py | |
parent | 3c4462cd16585d66502087578fd868d8ba0a2a84 (diff) | |
download | pytdeextensions-5e40676b8b687a896b5365f8f77ea7efc51ba165.tar.gz pytdeextensions-5e40676b8b687a896b5365f8f77ea7efc51ba165.zip |
A more consistent compiler and flags config
For compiler:
* use the same one that was used to build python
* [if none] use the one from CXX env var
* [if none] fallback to c++
For CXXFLAGS:
* use python's recommended CFLAGS
* append our own -fno-strict-aliasing
* append user-provided CXXFLAGS
Signed-off-by: Alexander Golubev <fatzer2@gmail.com>
Diffstat (limited to 'setup.py')
-rwxr-xr-x | setup.py | 43 |
1 files changed, 17 insertions, 26 deletions
@@ -160,34 +160,25 @@ class BuildLibpythonize(Command): cmdlist.append("--mode=compile") cmdlist.append("--tag=CXX") - # Find the compiler flags and options - # CXX is empty on some Systems, let's do it 'the hard way'. - # FIXME :: get CXX from make.conf for Gentoo. - if len(sysconfig.get_config_var("CXX").split()) >= 2: - cmdlist.extend(sysconfig.get_config_var("CXX").split()) - else: - cmdlist.extend(['g++', '-pthread']) - + # Find the compiler and flags + cxx = sysconfig.get_config_var("CXX") or os.environ.get("CXX") or "c++" + cxxflags = [] + # Use python's CFLAGS + cflags = (sysconfig.get_config_var("CFLAGS")) + if cflags: + cxxflags.extend(cflags.split()) + # Append our own flags + cxxflags.append ('-fno-strict-aliasing') + # Get user-provided flags + if os.environ.get("CXXFLAGS"): + cxxflags.extend(os.environ["CXXFLAGS"].split()) + + cmdlist.append(cxx) # cc_flags cmdlist.append("-c") - cmdlist.append("-g") + + cmdlist.extend(cxxflags) - # The 4 is randomly chosen! - # FIXME :: get CFLAGS from make.conf for Gentoo. - if len(sysconfig.get_config_var("CFLAGS").split()) >=4: - cmdlist.extend(sysconfig.get_config_var("CFLAGS").split()) - else: - # On Gentoo systems, CFLAGS are not in the environment. - raw = os.popen('emerge info 2> /dev/null|grep CFLAGS') - lines = raw.readlines() - if len(lines): - cflags = lines[0].split('"')[1].split() - print("Got CFLAGS from emerge info.") - cmdlist.extend(cflags) - else: - # Still no CFLAGS found, use these ... - cmdlist.extend(['-fno-strict-aliasing', '-DNDEBUG', '-g', '-O3', '-Wall', '-Wstrict-prototypes']) - # includes cmdlist.append("-I" + sysconfig.get_config_var("INCLUDEDIR")) cmdlist.append("-I" + sysconfig.get_config_var("INCLUDEPY")) @@ -205,7 +196,7 @@ class BuildLibpythonize(Command): # Link the resulting object file to create a shared library. cmdlist = ['libtool'] cmdlist.append("--mode=link") - cmdlist.append("--tag=LD") + cmdlist.append("--tag=CXX") # Grab the linker command name cmdlist.append(sysconfig.get_config_var("LDSHARED").split()[0]) |