def build_libzip(): global DEPS_PATH global MAKE_THREAD_COUNT global INSTALL_PATH url = "https://github.com/kuba--/zip/archive/v0.1.19.zip" src_dir = "zip-0.1.19" filename = "zip-0.1.19.zip" output = get_lib_filename("zip") old_path = os.path.realpath(os.getcwd()) os.chdir(DEPS_PATH) fetch_dep("libzip", url, src_dir, filename) if os.path.exists( os.path.join(os.path.realpath(INSTALL_PATH), "Lib", output)): infoMsg("libzip is already built and installed.") successMsg("Building libzip.") return os.chdir(src_dir) try: if is_windows(): # TODO: Build libzip for windows. raise NotImplementedError( "Building libzip for Windows OS is not implemented yet!") else: build_dir = os.path.join(DEPS_PATH, src_dir, "build") if not os.path.exists(build_dir): try: os.mkdir(build_dir) except: failMsg(f'Cannot make "{build_dir}" directory.') exit(1) os.chdir("build") ret = subprocess.call(["cmake", "-DBUILD_SHARED_LIBS=true", ".."]) if ret != 0: failMsg("Building libzip.") exit(1) ret = subprocess.call( "make -j{}".format(MAKE_THREAD_COUNT).split()) if ret != 0: failMsg("Building libzip.") exit(1) shutil.copy2( os.path.join(DEPS_PATH, build_dir, output), os.path.join(os.path.realpath(INSTALL_PATH), "Lib", output)) if ret != 0: failMsg("Building libzip.") exit(1) except (OSError, subprocess.CalledProcessError): failMsg("Building libzip.") exit(1) successMsg("Building libzip.") os.chdir(old_path)
def copy_other_installation_files(): global ALUSUS_ROOT global INSTALL_PATH infoMsg("Copying other installation files...") shutil.rmtree(os.path.join(INSTALL_PATH, "Doc"), ignore_errors=True) shutil.copytree(os.path.join(ALUSUS_ROOT, "Doc"), os.path.join(INSTALL_PATH, "Doc")) shutil.rmtree(os.path.join(INSTALL_PATH, "Notices_L18n"), ignore_errors=True) shutil.copytree(os.path.join(ALUSUS_ROOT, "Notices_L18n"), os.path.join(INSTALL_PATH, "Notices_L18n")) try: os.makedirs( os.path.join(INSTALL_PATH, "Tools", "Gtk_Syntax_Highlighting")) except OSError: pass shutil.copy2( os.path.join(ALUSUS_ROOT, "Tools", "Gtk_Syntax_Highlighting", "alusus.lang"), os.path.join(INSTALL_PATH, "Tools", "Gtk_Syntax_Highlighting", "alusus.lang")) shutil.copy2(os.path.join(ALUSUS_ROOT, "changelog.en.md"), os.path.join(INSTALL_PATH, "changelog.en.md")) shutil.copy2(os.path.join(ALUSUS_ROOT, "changelog.ar.md"), os.path.join(INSTALL_PATH, "changelog.ar.md")) shutil.copy2(os.path.join(ALUSUS_ROOT, "license.pdf"), os.path.join(INSTALL_PATH, "license.pdf")) shutil.copy2(os.path.join(ALUSUS_ROOT, "license.txt"), os.path.join(INSTALL_PATH, "license.txt")) successMsg("Copying other installation files.")
def build_libcurl(): global DEPS_PATH global MAKE_THREAD_COUNT global INSTALL_PATH url = "https://github.com/curl/curl/releases/download/curl-7_70_0/curl-7.70.0.tar.xz" src_dir = "curl-7.70.0" filename = "curl-7.70.0.tar.xz" output = get_lib_filename("curl") old_path = os.path.realpath(os.getcwd()) os.chdir(DEPS_PATH) fetch_dep("libcurl", url, src_dir, filename) if os.path.exists( os.path.join(os.path.realpath(INSTALL_PATH), "Lib", output)): infoMsg("libcurl is already built and installed.") successMsg("Building libcurl.") return os.chdir(src_dir) try: if is_windows(): # TODO: Build libcurl for windows. raise NotImplementedError( "Building libcurl for Windows OS is not implemented yet!") else: if is_macos(): ret = subprocess.call(["./configure", "--with-darwinssl"]) else: ret = subprocess.call("./configure") if ret != 0: failMsg("Building libcurl (./configure).") exit(1) ret = subprocess.call( "make -j{}".format(MAKE_THREAD_COUNT).split()) if ret != 0: failMsg("Building libcurl (make).") exit(1) shutil.copy2( os.path.join(DEPS_PATH, src_dir, "lib", ".libs", output), os.path.join(os.path.realpath(INSTALL_PATH), "Lib", output)) if ret != 0: failMsg(f"Building libcurl. Couldn't copy {output}.") exit(1) except (OSError, subprocess.CalledProcessError) as e: failMsg(f"Building libcurl. Exception: {e}") exit(1) successMsg("Building libcurl.") os.chdir(old_path)
def build_alusus(llvm_path): global BUILD_PATH global ALUSUS_ROOT global BUILD_TYPE global INSTALL_PATH global DEPS_PATH global MAKE_THREAD_COUNT global CREATE_PACKAGES global DLFCN_WIN32_NAME infoMsg("Building Alusus...") old_path = os.path.realpath(os.getcwd()) os.chdir(BUILD_PATH) try: # Determine fpic flag based on architecture type. For arm64 we'll use -fPIC to avoid the `too many GOT entries` # error. For everything else we'll use -fpic to maintain higher performance. arch = subprocess.check_output(['uname', '-m']).decode('utf-8').strip() fpic = '-fPIC' if arch == 'arm64' or arch == 'aarch64' else '-fpic' cmake_cmd = [ "cmake", os.path.join(ALUSUS_ROOT, "Sources"), f"-DCMAKE_BUILD_TYPE={BUILD_TYPE}".format(), f"-DCMAKE_INSTALL_PREFIX={INSTALL_PATH}".format(), f"-DLLVM_PATH={llvm_path}".format(), f"-DFPIC={fpic}".format() ] ret = subprocess.call(cmake_cmd) if ret != 0: failMsg("Building Alusus.") exit(1) if is_windows(): ret = subprocess.call("msbuild INSTALL.vcxproj /m".split()) if ret != 0: failMsg("Building Alusus.") exit(1) else: ret = subprocess.call( "make install -j{}".format(MAKE_THREAD_COUNT).split()) if ret != 0: failMsg("Building Alusus.") exit(1) except (OSError, subprocess.CalledProcessError): failMsg("Building Alusus.") exit(1) os.chdir(old_path) successMsg("Building Alusus.")
def build_alusus(): global BUILD_PATH global ALUSUS_ROOT global BUILD_TYPE global INSTALL_PATH global DEPS_PATH global LLVM_NAME global MAKE_THREAD_COUNT global CREATE_PACKAGES global DLFCN_WIN32_NAME global THIS_SYSTEM infoMsg("Building Alusus...") if not os.path.isdir(BUILD_PATH): os.makedirs(BUILD_PATH) old_path = os.path.realpath(os.getcwd()) os.chdir(BUILD_PATH) try: cmake_cmd = [ "cmake", "{}".format(os.path.join(ALUSUS_ROOT, "Sources")), "-DCMAKE_BUILD_TYPE={}".format(BUILD_TYPE), "-DCMAKE_INSTALL_PREFIX={}".format(INSTALL_PATH), "-DLLVM_PATH={}".format( os.path.join(DEPS_PATH, LLVM_NAME + ".install")) ] ret = subprocess.call(cmake_cmd) if ret != 0: failMsg("Building Alusus.") exit(1) if THIS_SYSTEM == "Windows": ret = subprocess.call("msbuild INSTALL.vcxproj /m".split()) if ret != 0: failMsg("Building Alusus.") exit(1) else: ret = subprocess.call( "make install -j{}".format(MAKE_THREAD_COUNT).split()) if ret != 0: failMsg("Building Alusus.") exit(1) except (OSError, subprocess.CalledProcessError): failMsg("Building Alusus.") exit(1) os.chdir(old_path) successMsg("Building Alusus.")
def create_packages(): global PACKAGES_PATH global THIS_SYSTEM infoMsg("Creating installation packages...") shutil.rmtree(PACKAGES_PATH, ignore_errors=True) os.makedirs(PACKAGES_PATH) copy_other_installation_files() if is_windows(): create_packages_windows() elif is_linux() or is_macos(): create_packages_unix() else: raise NotImplementedError( "Packaging is not supported on \"{}\"!".format(THIS_SYSTEM)) successMsg("Creating installation packages.")
def build_alusus(llvm_path): global BUILD_PATH global ALUSUS_ROOT global BUILD_TYPE global INSTALL_PATH global DEPS_PATH global MAKE_THREAD_COUNT global CREATE_PACKAGES global DLFCN_WIN32_NAME infoMsg("Building Alusus...") old_path = os.path.realpath(os.getcwd()) os.chdir(BUILD_PATH) try: cmake_cmd = [ "cmake", os.path.join(ALUSUS_ROOT, "Sources"), f"-DCMAKE_BUILD_TYPE={BUILD_TYPE}".format(), f"-DCMAKE_INSTALL_PREFIX={INSTALL_PATH}".format(), f"-DLLVM_PATH={llvm_path}".format() ] ret = subprocess.call(cmake_cmd) if ret != 0: failMsg("Building Alusus.") exit(1) if is_windows(): ret = subprocess.call("msbuild INSTALL.vcxproj /m".split()) if ret != 0: failMsg("Building Alusus.") exit(1) else: ret = subprocess.call( "make install -j{}".format(MAKE_THREAD_COUNT).split()) if ret != 0: failMsg("Building Alusus.") exit(1) except (OSError, subprocess.CalledProcessError): failMsg("Building Alusus.") exit(1) os.chdir(old_path) successMsg("Building Alusus.")
def build_llvm(): global DEPS_PATH global MAKE_THREAD_COUNT url = "https://github.com/llvm/llvm-project/releases/download/llvmorg-10.0.0/llvm-10.0.0.src.tar.xz" filename = "llvm-10.0.0.src.tar.xz" src_dir, build_dir, install_dir = "llvm-10.0.0.src", "llvm-10.0.0.build", "llvm-10.0.0.install" old_path = os.path.realpath(os.getcwd()) os.chdir(DEPS_PATH) fetch_dep("LLVM", url, src_dir, filename) if os.path.exists(os.path.join(install_dir, "INSTALLED")): infoMsg("LLVM is already built and installed.") successMsg("Building LLVM.") return os.path.realpath(install_dir) try: os.makedirs(install_dir) except OSError: pass if not os.path.exists(build_dir): try: os.makedirs(build_dir) except OSError: pass os.chdir(build_dir) try: ret = subprocess.call([ "cmake", os.path.join("..", src_dir), f"-DCMAKE_INSTALL_PREFIX={os.path.join(DEPS_PATH, install_dir)}", "-DCMAKE_BUILD_TYPE=Release", "-DLLVM_TARGETS_TO_BUILD=X86;WebAssembly" ]) if ret != 0: failMsg("Building LLVM.") exit(1) if is_windows(): ret = subprocess.call( "msbuild INSTALL.vcxproj /p:Configuration=Release /m".split()) if ret != 0: failMsg("Building LLVM.") exit(1) else: ret = subprocess.call( "make install -j{}".format(MAKE_THREAD_COUNT).split()) if ret != 0: failMsg("Building LLVM.") exit(1) os.chdir(DEPS_PATH) with open(os.path.join(install_dir, "INSTALLED"), "w") as fd: fd.write("LLVM INSTALLED CHECKER") except (OSError, subprocess.CalledProcessError): failMsg("Building LLVM.") exit(1) successMsg("Building LLVM.") os.chdir(DEPS_PATH) return os.path.realpath(install_dir)
global PACKAGES_PATH global THIS_SYSTEM infoMsg("Creating installation packages...") shutil.rmtree(PACKAGES_PATH, ignore_errors=True) os.makedirs(PACKAGES_PATH) copy_other_installation_files() if is_windows(): create_packages_windows() elif is_linux() or is_macos(): create_packages_unix() else: raise NotImplementedError( "Packaging is not supported on \"{}\"!".format(THIS_SYSTEM)) successMsg("Creating installation packages.") if __name__ == "__main__": colorama.init() process_args() infoMsg("Building dependencies...") create_dirs() llvm_path = build_llvm() build_libcurl() build_libzip() successMsg("Building dependencies.") build_alusus(llvm_path) if CREATE_PACKAGES == "yes": create_packages()
def prep_debs(): infoMsg("Preparing dependencies...") build_llvm() build_libcurl() build_libzip() successMsg("Building dependencies.")
def build_libzip(): global BUILD_PATH global DEPS_PATH global LIBZIP_NAME global LIBZIP_SRC_URL global MAKE_THREAD_COUNT global INSTALL_PATH try: os.makedirs(BUILD_PATH) except OSError: pass try: os.makedirs(DEPS_PATH) except OSError: pass old_path = os.path.realpath(os.getcwd()) os.chdir(DEPS_PATH) if not os.path.exists(os.path.join(LIBZIP_NAME, "EXTRACTED")): if not os.path.exists(LIBZIP_NAME + ".zip"): wget.download(LIBZIP_SRC_URL) with ZipFile(file=LIBZIP_NAME + ".zip", mode="r") as zip: infoMsg("Extracting libzip sources...") zip.extractall() os.remove(LIBZIP_NAME + ".zip") with open(os.path.join(LIBZIP_NAME, "EXTRACTED"), "w") as fd: fd.write("LIBZIP EXTRACTED CHECKER") infoMsg("Finished extracting libzip sources.") else: infoMsg("libzip sources are already available.") if os.path.exists( os.path.join(os.path.realpath(INSTALL_PATH), "Lib", "libzip.so")): infoMsg("libzip is already built and installed.") successMsg("Building libzip.") return os.chdir(LIBZIP_NAME) try: if THIS_SYSTEM == "Windows": # TODO: Build libzip for windows. raise NotImplementedError( "Building libzip for Windows OS is not implemented yet!") else: if not os.path.exists(os.path.join(DEPS_PATH, LIBZIP_NAME, "build")): try: os.mkdir(os.path.join(DEPS_PATH, LIBZIP_NAME, "build")) except: failMsg("Cannot make \"" + os.path.join(DEPS_PATH, LIBZIP_NAME, "build") + "\" directory.") exit(1) os.chdir("build") ret = subprocess.call(["cmake", "-DBUILD_SHARED_LIBS=true", ".."]) if ret != 0: failMsg("Building libzip.") exit(1) ret = subprocess.call( "make -j{}".format(MAKE_THREAD_COUNT).split()) if ret != 0: failMsg("Building libzip.") exit(1) if not os.path.exists( os.path.join(os.path.realpath(INSTALL_PATH), "Lib")): try: os.mkdir( os.path.join(os.path.realpath(INSTALL_PATH), "Lib")) except: failMsg( "Cannot make \"" + os.path.join(os.path.realpath(INSTALL_PATH), "Lib") + "\" directory.") exit(1) shutil.copy2( os.path.join(DEPS_PATH, LIBZIP_NAME, "build", "libzip.so"), os.path.join(os.path.realpath(INSTALL_PATH), "Lib", "libzip.so")) if ret != 0: failMsg("Building libzip.") exit(1) except (OSError, subprocess.CalledProcessError): failMsg("Building libzip.") exit(1) successMsg("Building libzip.") os.chdir(old_path)
def build_libcurl(): global BUILD_PATH global DEPS_PATH global LIBCURL_NAME global LIBCURL_SRC_URL global MAKE_THREAD_COUNT global INSTALL_PATH try: os.makedirs(BUILD_PATH) except OSError: pass try: os.makedirs(DEPS_PATH) except OSError: pass old_path = os.path.realpath(os.getcwd()) os.chdir(DEPS_PATH) if not os.path.exists(os.path.join(LIBCURL_NAME, "EXTRACTED")): if not os.path.exists(LIBCURL_NAME + ".tar.xz"): wget.download(LIBCURL_SRC_URL) with lzma.open(LIBCURL_NAME + ".tar.xz") as fd: with tarfile.open(fileobj=fd) as tar: infoMsg("Extracting libcurl sources...") tar.extractall() os.remove(LIBCURL_NAME + ".tar.xz") with open(os.path.join(LIBCURL_NAME, "EXTRACTED"), "w") as fd: fd.write("LIBCURL EXTRACTED CHECKER") infoMsg("Finished extracting libcurl sources.") else: infoMsg("libcurl sources are already available.") if os.path.exists( os.path.join(os.path.realpath(INSTALL_PATH), "Lib", "libcurl.so")): infoMsg("libcurl is already built and installed.") successMsg("Building libcurl.") return os.chdir(LIBCURL_NAME) try: if THIS_SYSTEM == "Windows": # TODO: Build libcurl for windows. raise NotImplementedError( "Building libcurl for Windows OS is not implemented yet!") else: ret = subprocess.call("./configure") if ret != 0: failMsg("Building libcurl.") exit(1) ret = subprocess.call( "make -j{}".format(MAKE_THREAD_COUNT).split()) if ret != 0: failMsg("Building libcurl.") exit(1) if not os.path.exists( os.path.join(os.path.realpath(INSTALL_PATH), "Lib")): try: os.mkdir( os.path.join(os.path.realpath(INSTALL_PATH), "Lib")) except: failMsg( "Cannot make \"" + os.path.join(os.path.realpath(INSTALL_PATH), "Lib") + "\" directory.") shutil.copy2( os.path.join(DEPS_PATH, LIBCURL_NAME, "lib", ".libs", "libcurl.so"), os.path.join(os.path.realpath(INSTALL_PATH), "Lib", "libcurl.so")) if ret != 0: failMsg("Building libcurl.") exit(1) except (OSError, subprocess.CalledProcessError): failMsg("Building libcurl.") exit(1) successMsg("Building libcurl.") os.chdir(old_path)
def build_llvm(): global BUILD_PATH global DEPS_PATH global LLVM_NAME global LLVM_SRC_URL global MAKE_THREAD_COUNT try: os.makedirs(BUILD_PATH) except OSError: pass try: os.makedirs(DEPS_PATH) except OSError: pass old_path = os.path.realpath(os.getcwd()) os.chdir(DEPS_PATH) if not os.path.exists(os.path.join(LLVM_NAME + ".src", "EXTRACTED")): if not os.path.exists(LLVM_NAME + ".src.tar.xz"): wget.download(LLVM_SRC_URL) with lzma.open(LLVM_NAME + ".src.tar.xz") as fd: with tarfile.open(fileobj=fd) as tar: infoMsg("Extracting LLVM sources...") tar.extractall() os.remove(LLVM_NAME + ".src.tar.xz") with open(os.path.join(LLVM_NAME + ".src", "EXTRACTED"), "w") as fd: fd.write("LLVM EXTRACTED CHECKER") infoMsg("Finished extracting LLVM sources.") else: infoMsg("LLVM sources are already available.") if os.path.exists(os.path.join(LLVM_NAME + ".install", "INSTALLED")): infoMsg("LLVM is already built and installed.") successMsg("Building LLVM.") return try: os.makedirs(LLVM_NAME + ".install") except OSError: pass if not os.path.exists(LLVM_NAME + ".build"): try: os.makedirs(LLVM_NAME + ".build") except OSError: pass os.chdir(LLVM_NAME + ".build") try: cmake_cmd = [ "cmake", os.path.join("..", LLVM_NAME + ".src"), "-DCMAKE_INSTALL_PREFIX={}".format( os.path.join(DEPS_PATH, LLVM_NAME + ".install")), "-DCMAKE_BUILD_TYPE=MinSizeRel" ] ret = subprocess.call(cmake_cmd) if ret != 0: failMsg("Building LLVM.") exit(1) if THIS_SYSTEM == "Windows": ret = subprocess.call( "msbuild INSTALL.vcxproj /p:Configuration=MinSizeRel /m".split( )) if ret != 0: failMsg("Building LLVM.") exit(1) else: ret = subprocess.call( "make install -j{}".format(MAKE_THREAD_COUNT).split()) if ret != 0: failMsg("Building LLVM.") exit(1) os.chdir(DEPS_PATH) with open(os.path.join(LLVM_NAME + ".install", "INSTALLED"), "w") as fd: fd.write("LLVM INSTALLED CHECKER") except (OSError, subprocess.CalledProcessError): failMsg("Building LLVM.") exit(1) successMsg("Building LLVM.") os.chdir(old_path)