diff --git a/messenger/make.py b/messenger/make.py index fa686be..5ada5d8 100755 --- a/messenger/make.py +++ b/messenger/make.py @@ -14,7 +14,7 @@ messenger_dir = 'mexa64' elif platform.startswith('darwin'): messenger_dir = 'mexmaci64' -if platform.startswith('win32'): +elif platform.startswith('win32'): # We further need to differniate 32 from 64 bit: maxint = sys.maxint() if maxint == 9223372036854775807: @@ -23,45 +23,51 @@ messenger_dir = 'mexw32' # Open the configure file and start parsing -config = open(os.path.join(messenger_dir, 'local.cfg'), 'r') +with open(os.path.join(messenger_dir, 'local.cfg'), 'r') as config: + for line in config: + try: + line = line.decode('utf-8') -for line in config.decode('utf-8'): - path = line.split('=') + # python3 + except: + pass - if path[0] == "MATLAB_BIN": - print("Searching for Matlab bin folder in local.cfg ...") - matlab_bin = path[1].rstrip('\r\n') - if matlab_bin == "": - raise ValueError("Could not find Matlab bin folder. Please add it to local.cfg") - print("Matlab found in " + matlab_bin) + path = line.split('=') - elif path[0] == "HEADER_PATH": - print("Searching for zmq.h in local.cfg ...") - header_path = path[1].rstrip('\r\n') - if header_path == "": - raise ValueError("Could not find zmq.h. Please add its path to local.cfg") - print("zmq.h found in " + header_path) + if path[0] == "MATLAB_BIN": + print("Searching for Matlab bin folder in local.cfg ...") + matlab_bin = path[1].rstrip('\r\n') + if matlab_bin == "": + raise ValueError("Could not find Matlab bin folder. Please add it to local.cfg") + print("Matlab found in " + matlab_bin) - elif path[0] == "LIB_PATH": - print("Searching for zmq library in local.cfg ...") - lib_path = path[1].rstrip('\r\n') - if lib_path == "": - raise ValueError("Could not find zmq library. Please add its path to local.cfg") + elif path[0] == "HEADER_PATH": + print("Searching for zmq.h in local.cfg ...") + header_path = path[1].rstrip('\r\n') + if header_path == "": + raise ValueError("Could not find zmq.h. Please add its path to local.cfg") + print("zmq.h found in " + header_path) + + elif path[0] == "LIB_PATH": + print("Searching for zmq library in local.cfg ...") + lib_path = path[1].rstrip('\r\n') + if lib_path == "": + raise ValueError("Could not find zmq library. Please add its path to local.cfg") + + print("zmq library found in " + lib_path) - print("zmq library found in " + lib_path) -config.close() # Get the extension if platform == 'win32': extcmd = '"' + matlab_bin + "\\mexext.bat" + '"' - check_extension = subprocess.Popen(extcmd, stdout = subprocess.PIPE) - extension = check_extension.stdout.readline().rstrip('\r\n') else: extcmd = matlab_bin + "/mexext" - check_extension = subprocess.Popen(extcmd, stdout = subprocess.PIPE) - extension = check_extension.stdout.readline().rstrip('\r\n') +check_extension = subprocess.Popen(extcmd, stdout = subprocess.PIPE) +extension = check_extension.stdout.read() +extension = extension.decode('utf-8').rstrip('\r\n') + print("Building messenger." + extension + " ...") # Build the mex file @@ -70,7 +76,11 @@ else: mex = "/mex" make_cmd = '"' + matlab_bin + mex + '"' + " -O -I" + header_path + " -L" + lib_path + " -lzmq ./src/messenger.c" +print(make_cmd) os.system(make_cmd) -shutil.move('messenger.%s'%extension, messenger_dir) +messenger_exe = 'messenger.%s'%extension +messenger_loc = os.path.join(messenger_dir, messenger_exe) + +shutil.move(messenger_exe, messenger_loc)