Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix cross-compiling #10

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 70 additions & 0 deletions config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#
# ICRAR - International Centre for Radio Astronomy Research
# (c) UWA - The University of Western Australia, 2014
# Copyright by UWA (in the framework of the ICRAR)
# All rights reserved
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library 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
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston,
# MA 02111-1307 USA
#

try:
import configparser
except ImportError:
# Python 2 compatibility
import ConfigParser as configparser

class setup_config(object):
"""
Class to obtain configuration provided by the setup.cfg file used by
setuptools.
"""

# Setuptools configuration file
SETUPTOOLS_CONFIG_FILE = 'setup.cfg'

# Cross-compiling section
BUILD_SECTION_NAME = 'build_info'

# Key name for specifying the target machine
MACHINE_KEY = 'machine'

def __init__(self):
"""Initialize the configuration object"""
self._metadata = self._metadata_from_setupcfg(self.BUILD_SECTION_NAME)

def machine(self):
"""Return the target machine name, or None if unknown"""
return self._get_cfg_value(self.MACHINE_KEY)

def _get_cfg_value(self, key):
"""
Get a value associated with a key in the build section. Returns the
value, or None if unknown.
"""
return self._metadata.get(key, None)

@classmethod
def _metadata_from_setupcfg(cls, section_name):
"""Read the section of setup.cfg and return it as a dict"""
cfgparser = configparser.ConfigParser()
cfgparser.read(cls._get_cfg_filename())

return dict(cfgparser.items(section_name))

@classmethod
def _get_cfg_filename(cls):
"""Get the file name of the setuptools cfg file"""
return cls.SETUPTOOLS_CONFIG_FILE
6 changes: 6 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Cross-compiling configuration interface
[build_info]

# If cross-compiling, uncomment this and set it to the target machine name
# (e.g. output of uname -m). If unset, the host machine type will be detected.
#machine = x86_64
11 changes: 10 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
# Foundation, Inc., 59 Temple Place, Suite 330, Boston,
# MA 02111-1307 USA
#
from config import setup_config

import glob
import platform

Expand All @@ -33,7 +35,14 @@
language='c',
sources=['_crc32c.c', 'crc32c_sw.c'],
include_dirs=['.'])
is_intel = platform.machine() in ['x86_64', 'AMD64']

config = setup_config()

machine = config.machine()
if not machine:
machine = platform.machine()

is_intel = machine in ['x86_64', 'AMD64']

def get_extra_compile_args():
# msvc is treated specially; otherwise we assume it's a unix compiler
Expand Down