Created
October 20, 2018 01:33
-
-
Save udnaan/d549950a33fd82d13f9e6ba4aae82964 to your computer and use it in GitHub Desktop.
Use distutils to create a static library (for external usage)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from distutils.ccompiler import new_compiler | |
from sysconfig import get_paths | |
import os | |
project_name = "slimey_project" | |
source = ['source1.c'] | |
include_dirs = ['include'] | |
build_dir = os.path.join(os.path.dirname(__file__), 'build') | |
class StaticLib(Command): | |
description = 'build static lib' | |
user_options = [] # do not remove, needs to be stubbed out! | |
python_info = get_paths() | |
def initialize_options(self): | |
pass | |
def finalize_options(self): | |
pass | |
def run(self): | |
# Create compiler with default options | |
c = new_compiler() | |
# Optionally add include directories etc. | |
for d in include_dirs: | |
c.add_include_dir(d) | |
c.add_include_dir(self.python_info['include']) | |
# Compile into .o files | |
objects = c.compile(sources) | |
# Create static or shared library | |
c.create_static_lib(objects, project_name, output_dir=build_dir) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How should this actually be invoked? IE how does this fit into an existing setup.py?