import shutil from cerbero.build.build import modify_environment class Recipe(recipe.Recipe): name = 'winpthreads' version = 'v6.0.0' licenses = [License.LGPLv2_1Plus] configure_options = '--enable-shared --enable-static' add_host_build_target = False autoreconf = True allow_parallel_build = False stype = SourceType.CUSTOM deps = ['mingw-w64-headers'] files_all = [ 'bin/libwinpthread-1.dll', 'lib/libpthread.a', 'lib/libpthread.dll.a', 'lib/libwinpthread.a', 'lib/libwinpthread.dll.a', 'lib/libwinpthread.la', 'include/pthread.h', 'include/pthread_compat.h', 'include/pthread_time.h', 'include/pthread_unistd.h', 'include/sched.h', 'include/semaphore.h', ] def prepare(self): if self.config.target_arch == Architecture.X86: raise InvalidRecipeError(self) # Since we are cross-compiling we have to reset all the env # variables set by cerbero (eg: we don't want -m64 overriding # a i386 build or gcc being used instead of x86_64-mingw32-w64-gcc) for v in ['CC', 'LD', 'CPP', 'AS', 'RC', 'CXX','CFLAGS', 'LDFLAGS', 'CXXFLAGS', 'CCASFLAGS']: self.set_env(v) self.host = 'x86_64-w64-mingw32' self.sysroot = os.path.join(self.config.prefix, self.host, 'sysroot') self.configure_options += ' --with-sysroot=%s ' % self.sysroot self.make_install = ['make', 'install', 'DESTDIR=' + self.sysroot] self.build_dir = os.path.join(self.config.sources, 'mingw-w64-%s' % self.version) self.make_dir = os.path.join(self.config.sources, 'mingw-w64-%s/mingw-w64-libraries/winpthreads' % self.version) self.configure_tpl = "%%(config-sh)s --prefix /usr/%(host)s "\ "--libdir /usr/%(host)s %%(options)s" % {'host': self.host} self.build_dir_32 = os.path.join(self.make_dir, 'winpthread_build_32') self.build_dir_64 = os.path.join(self.make_dir, 'winpthread_build_64') @modify_environment def configure(self): # Since the toolchain is built with multilib support # this recipe builds winpthreads for both x86_64 and x86 try: os.mkdir(self.build_dir_32) except: pass flags = "CC=x86_64-w64-mingw32-gcc RC=x86_64-w64-mingw32-windres " \ "LD=x86_64-w64-mingw32-ld LDFLAGS=' -m32' CFLAGS=' -m32' CXXFLAGS=' -m32' " \ "RCFLAGS='-F pe-i386' DLLTOOLFLAGS='-m i386'" host = 'i386-w64-mingw32' libdir = "/usr/%s/lib32" % self.host shell.new_call('%s ../configure --bindir=%s --libdir=%s --prefix=/usr/%s --host=%s %s' %\ (flags, libdir, libdir, host, host, self.configure_options), self.build_dir_32) try: os.mkdir(self.build_dir_64) except: pass flags = "CC=x86_64-w64-mingw32-gcc RC=x86_64-w64-mingw32-windres " \ "LD=x86_64-w64-mingw32-ld LDFLAGS=' -m64' CFLAGS=' -m64' CXXFLAGS=' -m64' " host = 'x86_64-w64-mingw32' libdir = "/usr/%s/lib" % self.host shell.new_call('%s ../configure --bindir=%s --libdir=%s --prefix=/usr/%s --host=%s %s' %\ (flags, libdir, libdir, host, host, self.configure_options), self.build_dir_64) def compile(self): shell.new_call(self.make, self.build_dir_32) shell.new_call(self.make, self.build_dir_64) @modify_environment def install(self): src_winpthread_dll = "%s/usr/%s/bin/libwinpthread-1.dll" % \ (self.sysroot, self.host) libdir = "%s/usr/%s/lib32/" % (self.sysroot, self.host) dest_winpthread_dll = os.path.join(libdir, "libwinpthread-1.dll") shell.new_call(self.make_install, self.build_dir_32) if os.path.exists(dest_winpthread_dll): os.remove(dest_winpthread_dll) shutil.move(src_winpthread_dll, dest_winpthread_dll) shell.new_call(self.make_install, self.build_dir_64) libdir = "%s/usr/%s/lib/" % (self.sysroot, self.host) dest_winpthread_dll = os.path.join(libdir, "libwinpthread-1.dll") if os.path.exists(dest_winpthread_dll): os.remove(dest_winpthread_dll) shutil.move(src_winpthread_dll, libdir)