change simple-build

This commit is contained in:
PyYoshi 2012-06-26 09:44:17 +09:00
parent aeaf25b556
commit b68dbdaf9d

140
setup.py
View file

@ -1,118 +1,68 @@
#!/usr/bin/env python #!/usr/bin/env python
# coding: utf-8 # coding: utf-8
# TODO: WinはMSVC9で行うようにする
import ez_setup import ez_setup
ez_setup.use_setuptools() ez_setup.use_setuptools()
import os,sys,platform,shutil import os,platform
import subprocess
from setuptools import setup, Extension from setuptools import setup, Extension
import distutils.spawn as ds
from Cython.Distutils import build_ext from Cython.Distutils import build_ext
root = os.getcwd() root = os.getcwd()
ext_dir = os.path.join(root,'ext_') ext_dir = os.path.join(root,'ext')
src_dir = os.path.join(root,'src') src_dir = os.path.join(root,'src')
build_dir = os.path.join(root,'build') build_dir = os.path.join(root,'build')
cchardet_dir = os.path.join(src_dir,'cchardet') cchardet_dir = os.path.join(src_dir,'cchardet')
cchardet_source = os.path.join(cchardet_dir,"cchardet.pyx") cchardet_source = os.path.join(cchardet_dir,"cchardet.pyx")
charsetdetect_dir = os.path.join(ext_dir, 'libcharsetdetect') charsetdetect_dir = os.path.join(ext_dir, 'libcharsetdetect')
charsetdetect_build_dir = os.path.join(charsetdetect_dir,'build') nspr_emu_dir = os.path.join(charsetdetect_dir,"nspr-emu")
uchardet_dir = os.path.join(charsetdetect_dir,"mozilla/extensions/universalchardet/src/base")
platform_os = platform.system() uchardet_sources = [
cmake_cmd = "cmake" "ext/libcharsetdetect/charsetdetect.cpp",
if platform_os == "Windows": "ext/libcharsetdetect/mozilla/extensions/universalchardet/src/base/CharDistribution.cpp",
cmake_args = " -DBUILD_SHARED_LIBS=NO -DCMAKE_BUILD_TYPE:STRING=Release -G \"NMake Makefiles\"" "ext/libcharsetdetect/mozilla/extensions/universalchardet/src/base/JpCntx.cpp",
else: "ext/libcharsetdetect/mozilla/extensions/universalchardet/src/base/LangBulgarianModel.cpp",
cmake_args = " -DBUILD_SHARED_LIBS=YES -DCMAKE_BUILD_TYPE:STRING=Release".split() "ext/libcharsetdetect/mozilla/extensions/universalchardet/src/base/LangCyrillicModel.cpp",
"ext/libcharsetdetect/mozilla/extensions/universalchardet/src/base/LangCzechModel.cpp",
def build_charsetdetect(): "ext/libcharsetdetect/mozilla/extensions/universalchardet/src/base/LangFinnishModel.cpp",
if ds.find_executable(cmake_cmd) is None: "ext/libcharsetdetect/mozilla/extensions/universalchardet/src/base/LangFrenchModel.cpp",
print("Error: unable to configure libcharsetdetect!") "ext/libcharsetdetect/mozilla/extensions/universalchardet/src/base/LangGermanModel.cpp",
print() "ext/libcharsetdetect/mozilla/extensions/universalchardet/src/base/LangGreekModel.cpp",
print("CMake build tool (http://www.cmake.org/) to configure.") "ext/libcharsetdetect/mozilla/extensions/universalchardet/src/base/LangHebrewModel.cpp",
print("However, CMake is not found in your system.") "ext/libcharsetdetect/mozilla/extensions/universalchardet/src/base/LangHungarianModel.cpp",
print("Please install CMake before running the setup file.") "ext/libcharsetdetect/mozilla/extensions/universalchardet/src/base/LangPolishModel.cpp",
sys.exit(-1) "ext/libcharsetdetect/mozilla/extensions/universalchardet/src/base/LangSpanishModel.cpp",
"ext/libcharsetdetect/mozilla/extensions/universalchardet/src/base/LangSwedishModel.cpp",
print("Configuring libcharsetdetect via CMake...") "ext/libcharsetdetect/mozilla/extensions/universalchardet/src/base/LangThaiModel.cpp",
os.chdir(charsetdetect_dir) "ext/libcharsetdetect/mozilla/extensions/universalchardet/src/base/LangTurkishModel.cpp",
if platform_os == "Windows": "ext/libcharsetdetect/mozilla/extensions/universalchardet/src/base/nsBig5Prober.cpp",
import distutils.msvc9compiler as dm "ext/libcharsetdetect/mozilla/extensions/universalchardet/src/base/nsCharSetProber.cpp",
msvc_version = dm.get_build_version() "ext/libcharsetdetect/mozilla/extensions/universalchardet/src/base/nsEscCharsetProber.cpp",
vcvarsall_cmd = dm.find_vcvarsall(msvc_version) "ext/libcharsetdetect/mozilla/extensions/universalchardet/src/base/nsEscSM.cpp",
if os.path.exists(vcvarsall_cmd) is None: "ext/libcharsetdetect/mozilla/extensions/universalchardet/src/base/nsEUCJPProber.cpp",
print("Error: Could not execute vcvarsall.bat!") "ext/libcharsetdetect/mozilla/extensions/universalchardet/src/base/nsEUCKRProber.cpp",
print("Require Microsoft Visual Studio 2008.") "ext/libcharsetdetect/mozilla/extensions/universalchardet/src/base/nsEUCTWProber.cpp",
sys.exit(-1) "ext/libcharsetdetect/mozilla/extensions/universalchardet/src/base/nsGB2312Prober.cpp",
configure_file = "configure.bat" "ext/libcharsetdetect/mozilla/extensions/universalchardet/src/base/nsHebrewProber.cpp",
print("Create: %s" % configure_file) "ext/libcharsetdetect/mozilla/extensions/universalchardet/src/base/nsLatin1Prober.cpp",
fp = file(configure_file,"w") "ext/libcharsetdetect/mozilla/extensions/universalchardet/src/base/nsMBCSGroupProber.cpp",
fp_code_lines = [ "ext/libcharsetdetect/mozilla/extensions/universalchardet/src/base/nsMBCSSM.cpp",
'call "%s"' % vcvarsall_cmd, "ext/libcharsetdetect/mozilla/extensions/universalchardet/src/base/nsSBCharSetProber.cpp",
'\n', "ext/libcharsetdetect/mozilla/extensions/universalchardet/src/base/nsSBCSGroupProber.cpp",
'cmake %s'% cmake_args, "ext/libcharsetdetect/mozilla/extensions/universalchardet/src/base/nsSJISProber.cpp",
'\n', "ext/libcharsetdetect/mozilla/extensions/universalchardet/src/base/nsUniversalDetector.cpp",
"ext/libcharsetdetect/mozilla/extensions/universalchardet/src/base/nsUTF8Prober.cpp",
] ]
fp.writelines(fp_code_lines)
fp.close()
print("Excec: %s"% configure_file)
configure_file = os.path.join(charsetdetect_dir,configure_file)
popen = subprocess.Popen(configure_file,stdout=subprocess.PIPE,stderr=subprocess.PIPE)
print("===========================================")
print(popen.stdout.read())
print(popen.stderr.read())
print("===========================================")
else:
try:
ds.spawn(cmd=[cmake_cmd]+cmake_args,)
except ds.DistutilsExecError:
print("Error: error occurred while running CMake to configure libcharsetdetect!")
print("You may want to manually configure libcharsetdetect by running cmake's tools:")
print('cd %s' % charsetdetect_dir)
print("cmake-gui or cmake")
sys.exit(-1)
print("Building libcharsetdetect ...") macros = []
if platform.system() == "Windows":
try: macros.append(("WIN32","1"))
if platform_os == "Windows":
execute_make_file = "exec_make.bat"
print("Create: %s" % execute_make_file)
fp = file(execute_make_file,"w")
fp_code_lines = [
'call "%s"' % vcvarsall_cmd,
'\n',
'nmake',
'\n',
]
fp.writelines(fp_code_lines)
fp.close()
execute_make_file = os.path.join(charsetdetect_dir,execute_make_file)
popen = subprocess.Popen(execute_make_file,stdout=subprocess.PIPE,stderr=subprocess.PIPE)
print("===========================================")
print(popen.stdout.read())
print(popen.stderr.read())
print("===========================================")
else:
ds.spawn(cmd=["make"])
if not os.path.exists(build_dir):
os.makedirs(build_dir)
except ds.DistutilsExecError as e:
print("Error: Could not build libchardet!")
print(e)
sys.exit(-1)
os.chdir(root)
build_charsetdetect()
cchardet_module = Extension("_cchardet", cchardet_module = Extension("_cchardet",
sources = [cchardet_source], sources = uchardet_sources+[cchardet_source],
libraries = ['charsetdetect'], include_dirs = [uchardet_dir,nspr_emu_dir,charsetdetect_dir],
include_dirs = [charsetdetect_dir],
library_dirs = [charsetdetect_build_dir],
language = "c++", language = "c++",
define_macros=macros
) )
setup( setup(