Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 0 additions & 60 deletions _a_compile_dynamic.py

This file was deleted.

115 changes: 84 additions & 31 deletions a_compile.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import os
import argparse
import stat
import shutil
import subprocess
import platform
import zipfile
from distutils.dir_util import copy_tree

parser = argparse.ArgumentParser(description='Pigz script')
parser.add_argument('--rebuild', help='Rebuild', action='store_const', const=True, default=None)
args, unknown = parser.parse_known_args()


def rmtree(top):
"""Delete folder and contents: shutil.rmtree has issues with read-only files on Windows"""

Expand All @@ -20,6 +26,7 @@ def rmtree(top):
os.rmdir(os.path.join(root, name))
os.rmdir(top)


def install_silesia_corpus():
"""Install popular Silesia corpus"""

Expand All @@ -30,9 +37,9 @@ def install_silesia_corpus():
try:
os.mkdir(corpusdir)
except OSError:
print('Creation of the directory {} failed' .format(corpusdir) )
print('Creation of the directory {} failed' .format(corpusdir))
cmd = 'git clone https://github.com/MiloszKrajewski/SilesiaCorpus silesia'
print("Installing "+corpusdir);
print("Installing "+corpusdir)
subprocess.call(cmd, shell=True)
os.chdir(corpusdir)
fnm = 'README.md'
Expand All @@ -50,6 +57,7 @@ def install_silesia_corpus():
os.remove(file_name) # delete zipped file
os.chdir(basedir)


def install_neuro_corpus():
"""Install neuroimaging corpus"""

Expand All @@ -60,7 +68,7 @@ def install_neuro_corpus():
try:
os.mkdir(corpusdir)
except OSError:
print('Creation of the directory {} failed' .format(exedir) )
print('Creation of the directory {} failed' .format(exedir))
cmd = 'git clone https://github.com/neurolabusc/zlib-bench.git'
subprocess.call(cmd, shell=True)
indir = os.path.join(basedir, 'zlib-bench', 'corpus')
Expand All @@ -71,51 +79,96 @@ def install_neuro_corpus():
indir = os.path.join(basedir, 'zlib-bench')
rmtree(indir)

def compile_pigz():

def compile_pigz(rebuild=True):
"""compile variants of pigz"""

methods = ['ng']
if platform.system() == 'Windows':
methods = ['Cloudflare', 'ng']
methods = [
{'name': 'madler',
'repository': 'https://github.com/madler/zlib',
'branch': None},
{'name': 'cloudflare',
'repository': 'https://github.com/cloudflare/zlib', # Only supports 64-bit builds
'branch': None},
{'name': 'ng',
'repository': 'https://github.com/zlib-ng/zlib-ng',
'branch': 'develop'}
]
basedir = os.getcwd()
exedir = os.path.join(basedir, 'exe')

if os.path.isdir(exedir):
rmtree(exedir)
try:
if not os.path.isdir(exedir):
os.mkdir(exedir)
except OSError:
print ("Creation of the directory {} failed" .format(exedir) )
pigzdir = './pigz'
if os.path.isdir(pigzdir):
rmtree(pigzdir)
cmd = 'git clone https://github.com/neurolabusc/pigz'
subprocess.call(cmd, shell=True)
pigzdir = os.path.join(basedir, 'pigz', 'build')
pigzexe = os.path.join(pigzdir, 'bin', 'pigz')

ext = ''
if platform.system() == 'Windows':
ext = '.exe'
pigzexe = pigzexe + ext

for method in methods:
os.chdir(basedir)
if os.path.isdir(pigzdir):
rmtree(pigzdir)
os.mkdir(pigzdir)
os.chdir(pigzdir)
cmd = 'cmake -DZLIB_IMPLEMENTATION=' + method + ' ..'
subprocess.call(cmd, shell=True)
cmd = 'make'

pthreads4wdir = os.path.join(basedir, 'pthreads4w')
if rebuild or not os.path.exists('pthreads4w') and platform.system() == 'Windows':
cmd = 'git clone https://github.com/jwinarske/pthreads4w'
subprocess.call(cmd, shell=True)

zlibname = 'zlib-{0}'.format(method['name'])
if rebuild or not os.path.exists(zlibname):
if os.path.isdir(zlibname):
rmtree(zlibname)
print("Checking out zlib source code for {0}".format(method['name']))
cmd = 'git clone {0} {1}'.format(method['repository'], zlibname)
subprocess.call(cmd, shell=True)

pigzname = 'pigz-{0}'.format(method['name'])
if rebuild or not os.path.exists(pigzname):
if os.path.isdir(pigzname):
rmtree(pigzname)
print("Checking out pigz source code for {0}".format(method['name']))
cmd = 'git clone https://github.com/madler/pigz {0}'.format(pigzname)
subprocess.call(cmd, shell=True)

os.chdir(zlibname)
if method['branch']:
cmd = 'git checkout {0}'.format(method['branch'])
subprocess.call(cmd, shell=True)

pigzdir = os.path.join(basedir, pigzname)
copy_tree(os.path.join(basedir, 'pigz'), pigzdir)
builddir = os.path.join(pigzdir, 'build')
if rebuild or not os.path.exists(builddir):
if os.path.isdir(builddir):
rmtree(builddir)
os.mkdir(builddir)

os.chdir(builddir)

cmd = 'cmake .. -DZLIB_ROOT:PATH=../{0} -DZLIB_COMPAT=ON -DBUILD_SHARED_LIBS=OFF'.format(zlibname)
if platform.system() == 'Windows':
cmd = 'cmake --build . --config Release'
cmd += ' -DPTHREADS4W_ROOT:PATH=../pthreads4w'
subprocess.call(cmd, shell=True)

cmd = 'cmake --build . --config Release'
subprocess.call(cmd, shell=True)
outnm = os.path.join(exedir, 'pigz' + method + ext)
print (pigzexe + '->' + outnm)

pigzexe = os.path.join(builddir, 'bin', 'pigz' + ext)
if not os.path.exists(pigzexe):
pigzexe = os.path.join(builddir, 'pigz' + ext)
if not os.path.exists(pigzexe):
pigzexe = os.path.join(builddir, 'Release', 'pigz' + ext)

outnm = os.path.join(exedir, pigzname + ext)
shutil.move(pigzexe, outnm)
print(pigzexe + '->' + outnm)


if __name__ == '__main__':
"""compile variants of pigz and sample compression corpus"""

install_neuro_corpus()
install_silesia_corpus()
compile_pigz()
if args.rebuild:
install_neuro_corpus()
install_silesia_corpus()

compile_pigz(args.rebuild)
67 changes: 67 additions & 0 deletions pigz/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
cmake_minimum_required(VERSION 3.0.2)

project(pigz C)

if(${CMAKE_C_COMPILER_ID} STREQUAL "Clang")
# using Clang
add_definitions(-fno-caret-diagnostics)
elseif(${CMAKE_C_COMPILER_ID} STREQUAL "GNU")
# using GCC
if(NOT ${CMAKE_C_COMPILER_VERSION} VERSION_LESS 4.5.0)
add_definitions(-Wno-unused-result)
endif()
if(NOT ${CMAKE_C_COMPILER_VERSION} VERSION_LESS 4.8.0)
add_definitions(-fno-diagnostics-show-caret)
endif()
elseif(MSVC)
# using Visual Studio
add_definitions(-D_CRT_SECURE_NO_DEPRECATE)
endif()

set(PIGZ_SRCS
pigz.c
yarn.c
try.c)

add_executable(${PROJECT_NAME} ${PIGZ_SRCS})
add_definitions(-DNOZOPFLI)

if(WIN32)
add_definitions(-D_TIMESPEC_DEFINED)

if(NOT DEFINED PTHREADS4W_ROOT)
message(FATAL "Missing pthreads4w root directory")
endif()

set(CLEANUP_STYLE VC)
set(PTHREADS4W_VERSION 3)

add_subdirectory(${PTHREADS4W_ROOT} ${PTHREADS4W_ROOT} EXCLUDE_FROM_ALL)
target_link_libraries(${PROJECT_NAME} pthreadVC3)
target_include_directories(${PROJECT_NAME} PRIVATE win ${PTHREADS4W_ROOT})
else()
find_package(Threads REQUIRED)
target_link_libraries(${PROJECT_NAME} Threads::Threads)
if(NOT APPLE)
target_link_libraries(${PROJECT_NAME} m)
endif()
endif()

if(NOT DEFINED ZLIB_ROOT)
find_package(Zlib REQUIRED)
endif()

add_subdirectory(${ZLIB_ROOT} ${CMAKE_CURRENT_BINARY_DIR}/zlib EXCLUDE_FROM_ALL)

if(TARGET zlibstatic)
set(ZLIB_TARGET zlibstatic)
else()
set(ZLIB_TARGET zlib)
endif()

target_include_directories(${PROJECT_NAME} PRIVATE ${ZLIB_ROOT} ${CMAKE_CURRENT_BINARY_DIR}/zlib)
target_link_libraries(${PROJECT_NAME} ${ZLIB_TARGET})

if(NOT SKIP_INSTALL_BINARIES AND NOT SKIP_INSTALL_ALL)
install(TARGETS ${PROJECT_NAME} DESTINATION "bin")
endif()
Loading