@@ -55,7 +55,7 @@ def __init__(self, library_folder, packages_folder, distro, python_env):
5555 self .env = {}
5656
5757 def run (self , meta , toolchain , user_meta = "" ):
58- if os .path .exists (self .library_path ):
58+ if os .path .exists (self .library ):
5959 print ("micro-ROS already built" )
6060 return
6161
@@ -183,6 +183,7 @@ def build_mcu_environment(self, meta_file, toolchain_file, user_meta = ""):
183183 sys .exit (1 )
184184
185185 def package_mcu_library (self ):
186+ binutils_path = self .resolve_binutils_path ()
186187 aux_folder = self .build_folder + "/aux"
187188
188189 shutil .rmtree (aux_folder , ignore_errors = True )
@@ -194,12 +195,12 @@ def package_mcu_library(self):
194195 if f .endswith ('.a' ):
195196 os .makedirs (aux_folder + "/naming" , exist_ok = True )
196197 os .chdir (aux_folder + "/naming" )
197- os .system ("ar x {}" .format (root + "/" + f ))
198+ os .system ("{} ar x {}" .format (binutils_path , root + "/" + f ))
198199 for obj in [x for x in os .listdir () if x .endswith ('obj' )]:
199200 os .rename (obj , '../' + f .split ('.' )[0 ] + "__" + obj )
200201
201202 os .chdir (aux_folder )
202- command = "ar rc libmicroros.a $(ls *.o *.obj 2> /dev/null); rm *.o *.obj 2> /dev/null; ranlib libmicroros.a"
203+ command = "{binutils} ar rc libmicroros.a $(ls *.o *.obj 2> /dev/null); rm *.o *.obj 2> /dev/null; {binutils} ranlib libmicroros.a" . format ( binutils = binutils_path )
203204 result = run_cmd (command )
204205
205206 if 0 != result .returncode :
@@ -221,3 +222,15 @@ def package_mcu_library(self):
221222 if os .path .exists (repeated_path ):
222223 shutil .copytree (repeated_path , folder_path , copy_function = shutil .move , dirs_exist_ok = True )
223224 shutil .rmtree (repeated_path )
225+
226+ def resolve_binutils_path (self ):
227+ if sys .platform == "darwin" :
228+ homebrew_binutils_path = "/opt/homebrew/opt/binutils/bin/"
229+ if os .path .exists (homebrew_binutils_path ):
230+ return homebrew_binutils_path
231+
232+ print ("ERROR: GNU binutils not found. ({}) Please install binutils with homebrew: brew install binutils"
233+ .format (homebrew_binutils_path ))
234+ sys .exit (1 )
235+
236+ return ""
0 commit comments