34
34
- extra option 'runtime_library_dirs'
35
35
- extra option 'extra_preargs'
36
36
- extra option 'extra_link_postargs'
37
+ - extra option 'force_build'
37
38
- 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
39
41
"""
40
42
41
-
42
43
import os
44
+
43
45
from setuptools .command import build_clib
44
46
from distutils import log
47
+ from distutils .dep_util import newer_group
45
48
from distutils .file_util import copy_file
46
49
47
50
@@ -51,7 +54,12 @@ def build_libraries(self, libraries):
51
54
"""
52
55
This function is overloaded to the original function in build_clib.py file
53
56
"""
57
+
54
58
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
+
55
63
sources = build_info .get ('sources' )
56
64
if sources is None or not isinstance (sources , (list , tuple )):
57
65
err_msg = f"in 'libraries' option (library '{ lib_name } '),"
@@ -60,7 +68,11 @@ def build_libraries(self, libraries):
60
68
61
69
sources = list (sources )
62
70
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"]
64
76
65
77
macros = build_info .get ('macros' )
66
78
include_dirs = build_info .get ('include_dirs' )
@@ -69,29 +81,49 @@ def build_libraries(self, libraries):
69
81
runtime_library_dirs = build_info .get ("runtime_library_dirs" )
70
82
extra_preargs = build_info .get ("extra_preargs" )
71
83
extra_link_postargs = build_info .get ("extra_link_postargs" )
84
+ force_build = build_info .get ("force_build" )
72
85
language = build_info .get ("language" )
73
86
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
92
94
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 )
96
123
124
+ """
125
+ Copy library to the destination path
126
+ """
97
127
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