Skip to content
Snippets Groups Projects
Commit f32bc908 authored by David Hendriks's avatar David Hendriks
Browse files

Modified makefile s.t. setup actually builds the libraries

parent 07f0c5a4
No related branches found
No related tags found
No related merge requests found
......@@ -22,6 +22,7 @@ TARGET_LIB_DIR := lib
CC := gcc
LD := gcc
MAKE := /usr/bin/make
MKDIR_P := mkdir -p
# Libraries
LIBS := -lbinary_c $(shell $(BINARY_C)/binary_c-config --libs)
......@@ -38,27 +39,30 @@ OBJECTS := $(C_SRC:$(SRC_DIR)/%.c=$(OBJ_DIR)/%.o)
OBJ_FLAGS := -c
# Shared lib files and flags
SO_NAME := $(TARGET_LIB_DIR)/libbinary_c_api.so
SO_NAME := $(TARGET_LIB_DIR)/libbinary_c_python_api.so
SO_FLAGS := -shared
# To create python shared library
PY_EXEC := python3
PY_SETUP := setup.py
#PY_OPTIONS := build_ext --build-lib $(TARGET_LIB_DIR)
PY_OPTIONS := build_ext --inplace
all: create_directories create_objects create_library
all:
debug: create_directories create_objects_debug create_library_debug
create_directories:
${MKDIR_P} ${TARGET_LIB_DIR}
${MKDIR_P} ${OBJ_DIR}
create_objects:
$(CC) -DBINARY_C=$(BINARY_C) $(CFLAGS) $(INCDIRS) $(C_SRC) -o $(OBJECTS) $(OBJ_FLAGS) $(LIBS)
$(CC) -DBINARY_C=$(BINARY_C) $(SO_FLAGS) -o $(SO_NAME) $(OBJECTS)
$(PY_EXEC) $(PY_SETUP) $(PY_OPTIONS)
debug:
create_objects_debug:
$(CC) -DBINARY_C=$(BINARY_C) -DBINARY_C_PYTHON_DEBUG $(CFLAGS) $(INCDIRS) $(C_SRC) -o $(OBJECTS) $(OBJ_FLAGS) $(LIBS)
$(CC) -DBINARY_C=$(BINARY_C) -DBINARY_C_PYTHON_DEBUG $(SO_FLAGS) -o $(SO_NAME) $(OBJECTS)
$(PY_EXEC) $(PY_SETUP) $(PY_OPTIONS)
create_library:
$(CC) -DBINARY_C=$(BINARY_C) $(SO_FLAGS) -o $(SO_NAME) $(OBJECTS)
create_library_debug:
$(CC) -DBINARY_C=$(BINARY_C) -DBINARY_C_PYTHON_DEBUG $(SO_FLAGS) -o $(SO_NAME) $(OBJECTS)
test:
echo_vars:
@echo OBJECTS: $(OBJECTS)
@echo LIBS: $(LIBS)
@echo C_SRC: $(C_SRC)
......
"""
Setup script for binarycpython
"""
import setuptools
from distutils.core import setup, Extension
import os
import subprocess
import re
import sys
import setuptools
from distutils.core import setup, Extension
import distutils.command.build
# TODO: replace the tasks that call binary_c-config with a single function that handles the return status a bit better.
# Functions
def readme():
......@@ -24,13 +29,39 @@ def license():
def check_version(installed_binary_c_version, required_binary_c_versions):
"""Function to check the installed version and compare it to the required version"""
message = """
The binary_c version that is installed ({}) does not match the binary_c versions ({})
Something went wrong. Make sure that binary_c config exists.
Possibly the binary_c version that is installed ({}) does not match the binary_c versions ({})
that this release of the binary_c python module requires.
""".format(
installed_binary_c_version, required_binary_c_versions
)
assert installed_binary_c_version in required_binary_c_versions, message
def execute_make():
"""
Function to execute the makefile.
This makefile builds the binary_c_python_api library that python will use to interface wth
"""
# Custom extra command:
make_command = ["make"]
p = subprocess.run(make_command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stdout = p.stdout # stdout = normal output
stderr = p.stderr # stderr = error output
if p.returncode != 0:
print("Something went wrong when executing the makefile:")
print(stderr.decode('utf-8'))
print("Aborting")
sys.exit(-1)
else:
print(stdout.decode("utf-8"))
print("Successfully built the libbinary_c_api.so")
###
REQUIRED_BINARY_C_VERSIONS = ["2.1.7"]
......@@ -129,7 +160,7 @@ INCLUDE_DIRS = (
else []
)
LIBRARIES = ["binary_c"] + BINARY_C_LIBS + ["binary_c_api"]
LIBRARIES = ["binary_c"] + BINARY_C_LIBS + ["binary_c_python_api"]
LIBRARY_DIRS = [
os.path.join(BINARY_C_DIR, "src"),
......@@ -163,7 +194,6 @@ RUNTIME_LIBRARY_DIRS = list(dict.fromkeys(RUNTIME_LIBRARY_DIRS))
# print("macros: ", str(BINARY_C_DEFINE_MACROS) + "\n")
# print('\n')
#quit()
############################################################
# Making the extension function
############################################################
......@@ -171,7 +201,7 @@ RUNTIME_LIBRARY_DIRS = list(dict.fromkeys(RUNTIME_LIBRARY_DIRS))
BINARY_C_PYTHON_API_MODULE = Extension(
# name="binarycpython.core.binary_c",
name="binary_c_python_api",
name="binarycpython._binary_c_bindings",
sources=["src/binary_c_python.c"],
include_dirs=INCLUDE_DIRS,
libraries=LIBRARIES,
......@@ -187,6 +217,16 @@ BINARY_C_PYTHON_API_MODULE = Extension(
# Making the extension function
############################################################
# Override build command
class CustomBuildCommand(distutils.command.build.build):
def run(self):
execute_make()
# Run the original build command
# print(super().run())
distutils.command.build.build.run(self)
setup(
name="binarycpython",
version="0.2",
......@@ -201,22 +241,20 @@ setup(
),
author="David Hendriks",
author_email="davidhendriks93@gmail.com",
long_description_content_type='text/markdown',
long_description=readme(),
url="https://gitlab.eps.surrey.ac.uk/ri0005/binary_c-python",
license="gpl",
package_dir={
"binarycpython": "binarycpython",
"binarycpython.utils": "binarycpython/utils",
# 'binarycpython.core': 'lib',
},
keywords = ['binary_c', 'astrophysics', 'stellar evolution', 'population synthesis'], # Keywords that define your package best
packages=[
"binarycpython",
"binarycpython.utils",
# 'binarycpython.core',
"binarycpython.core",
"binarycpython.tests",
"binarycpython.tests.core",
],
# package_data={
# 'binarycpython.core': ['libbinary_c_api.so'],
# },
install_requires=["numpy", "pytest", "h5py"],
include_package_data=True,
ext_modules=[BINARY_C_PYTHON_API_MODULE], # binary_c must be loaded
classifiers=[
......@@ -231,4 +269,7 @@ setup(
"Topic :: Scientific/Engineering :: Physics",
"Topic :: Software Development :: Libraries :: Python Modules",
],
cmdclass={'build': CustomBuildCommand},
)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment