3434 - extra option 'runtime_library_dirs'
3535 - extra option 'extra_preargs'
3636 - extra option 'extra_link_postargs'
37+ - extra option 'force_build'
3738 - extra option 'language'
38-
39+ - a check if source needs to be rebuilt based on time stamp
40+ - a check if librayr needs to be rebuilt based on time stamp
3941"""
4042
41-
4243import os
44+
4345from setuptools .command import build_clib
4446from distutils import log
47+ from distutils .dep_util import newer_group
4548from distutils .file_util import copy_file
4649
4750
@@ -51,7 +54,12 @@ def build_libraries(self, libraries):
5154 """
5255 This function is overloaded to the original function in build_clib.py file
5356 """
57+
5458 for (lib_name , build_info ) in libraries :
59+ c_library_name = self .compiler .library_filename (lib_name , lib_type = 'shared' )
60+ c_library_filename = os .path .join (self .build_clib , c_library_name )
61+ dest_filename = "dpnp" # TODO need to fix destination directory
62+
5563 sources = build_info .get ('sources' )
5664 if sources is None or not isinstance (sources , (list , tuple )):
5765 err_msg = f"in 'libraries' option (library '{ lib_name } '),"
@@ -60,7 +68,11 @@ def build_libraries(self, libraries):
6068
6169 sources = list (sources )
6270
63- log .info ("building '%s' library" , lib_name )
71+ log .info ("DPNP: building '%s' library" , lib_name )
72+
73+ # set compiler and options
74+ # -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC
75+ # self.compiler.compiler_so = ["clang++", "-fPIC"]
6476
6577 macros = build_info .get ('macros' )
6678 include_dirs = build_info .get ('include_dirs' )
@@ -69,29 +81,49 @@ def build_libraries(self, libraries):
6981 runtime_library_dirs = build_info .get ("runtime_library_dirs" )
7082 extra_preargs = build_info .get ("extra_preargs" )
7183 extra_link_postargs = build_info .get ("extra_link_postargs" )
84+ force_build = build_info .get ("force_build" )
7285 language = build_info .get ("language" )
7386
74- objects = self .compiler .compile (sources ,
75- output_dir = self .build_temp ,
76- macros = macros ,
77- include_dirs = include_dirs ,
78- extra_preargs = extra_preargs ,
79- debug = self .debug )
80-
81- self .compiler .link_shared_lib (objects ,
82- lib_name ,
83- output_dir = self .build_clib ,
84- libraries = libraries ,
85- library_dirs = library_dirs ,
86- runtime_library_dirs = runtime_library_dirs ,
87- extra_preargs = extra_preargs ,
88- extra_postargs = extra_link_postargs ,
89- debug = self .debug ,
90- build_temp = self .build_temp ,
91- target_lang = language )
87+ objects = []
88+ """
89+ Build object files from sources
90+ """
91+ for source_it in sources :
92+ obj_file_list = self .compiler .object_filenames ([source_it ], strip_dir = 0 , output_dir = self .build_temp )
93+ obj_file = "" .join (obj_file_list ) # convert from list to file name
9294
93- dest_filename = "dpnp" # TODO need to fix destination directory
94- c_library_name = self .compiler .library_filename (lib_name , lib_type = 'shared' )
95- c_library_filename = os .path .join (self .build_clib , c_library_name )
95+ newer_than_obj = newer_group ([source_it ], obj_file , missing = "newer" )
96+ if force_build or newer_than_obj :
97+ obj_file_list = self .compiler .compile ([source_it ],
98+ output_dir = self .build_temp ,
99+ macros = macros ,
100+ include_dirs = include_dirs ,
101+ extra_preargs = extra_preargs ,
102+ debug = self .debug )
103+ objects .extend (obj_file_list )
104+ else :
105+ objects .append (obj_file )
106+
107+ """
108+ Build library file from objects
109+ """
110+ newer_than_lib = newer_group (objects , c_library_filename , missing = "newer" )
111+ if force_build or newer_than_lib :
112+ self .compiler .link_shared_lib (objects ,
113+ lib_name ,
114+ output_dir = self .build_clib ,
115+ libraries = libraries ,
116+ library_dirs = library_dirs ,
117+ runtime_library_dirs = runtime_library_dirs ,
118+ extra_preargs = extra_preargs ,
119+ extra_postargs = extra_link_postargs ,
120+ debug = self .debug ,
121+ build_temp = self .build_temp ,
122+ target_lang = language )
96123
124+ """
125+ Copy library to the destination path
126+ """
97127 copy_file (c_library_filename , dest_filename , verbose = self .verbose , dry_run = self .dry_run )
128+
129+ log .info ("DPNP: building '%s' library finished" , lib_name )
0 commit comments