Skip to content

Instantly share code, notes, and snippets.

@vhanla
Created September 2, 2016 10:05
Show Gist options
  • Save vhanla/f4ae372d47d4ece6b2214e07d2492139 to your computer and use it in GitHub Desktop.
Save vhanla/f4ae372d47d4ece6b2214e07d2492139 to your computer and use it in GitHub Desktop.
Build CHMlib on Windows and also PyCHM setup fix
@echo off
rem author: vhanla
rem If you want to install PyChm on Python (2.7) in Windows (32bits), you might get stuck on errors by trying to build using
rem Microsoft Visual C++ Compiler Package for Python 2.7 because it won't be capable to build chmlib (chm.lib)
rem So to fix that you need to build it manually, but here is a batch that will built it and setup automatically:
set currentdir=%~dp0
if exist "%CD%\chmlib\" goto building
goto gitchmlib
:building
set /p ask=CHMLib directory exists. Restart from fresh? (y/n)
if %ask%==y (
goto cleanchmlibdir
) else (
goto buildnow
)
:cleanchmlibdir
@echo Cleaning CHMLib dir to start all over
rmdir /s /q chmlib
:gitchmlib
@echo Getting from Git
git clone https://github.com/jedwing/CHMLib.git chmlib
:buildnow
@echo Building...
if not exist "%VCINSTALLDIR%" (
goto missingvc4python
) else (
goto buildit
)
:missingvc4python
@echo Visual C++ for Python is not installed, please install it first
goto :finished
:buildit
cd chmlib
if not exist release\libchm.lib (
goto compileandlink
) else (
goto setuppychm
)
:compileandlink
@git clone https://github.com/chemeris/msinttypes.git
@rem cl /c /W3 /WX- /O2 /Oi /Oy- /D WIN32 /D NDEBUG /D _LIB /D _UNICODE /D UNICODE /Gm- /EHsc /MD /GS /Gy /fp:precise /Zc:wchar_t /Zc:forScope /Zc:inline /Fo"Release\\" /Fd"Release\libchm.pdb" /Gd /TC /analyze- /errorReport:prompt chm_lib.c enumdir_chmLib.c enum_chmLib.c extract_chmLib.c lzx.c -I"C:\Python27\demos\msinttypes-r26"
rmdir /s /q release
mkdir release
cl /c /W3 /WX- /O2 /Oi /Oy- /D WIN32 /D NDEBUG /D _LIB /D _UNICODE /D UNICODE /Gm- /EHsc /MD /GS /Gy /fp:precise /Zc:wchar_t /Zc:forScope /Fo"Release\\" /Fd"Release\libchm.pdb" /Gd /TC /analyze- /errorReport:prompt src\chm_lib.c src\enumdir_chmLib.c src\enum_chmLib.c src\extract_chmLib.c src\lzx.c -I\"%CD%\msinttypes\"
lib /OUT:"%CD%\Release\libchm.lib" /NOLOGO Release\chm_lib.obj Release\enumdir_chmLib.obj Release\enum_chmLib.obj Release\extract_chmLib.obj Release\lzx.obj
set chmlibbuild=CHMLib built in %currentdir%chmlib\release directory
:setuppychm
@git clone https://github.com/dottedmag/pychm.git
cd pychm
echo #define strcasecmp _stricmp > "%currentdir%\chmlib\msinttypes\strings.h"
echo #define strncasecmp _strnicmp >> "%currentdir%\chmlib\msinttypes\strings.h"
echo #define inline __inline >> "%currentdir%\chmlib\msinttypes\strings.h"
copy "%currentdir%\chmlib\release\libchm.lib" "%currentdir%\chmlib\release\chm.lib"
echo [build_ext] > setup.cfg
echo include_dirs=%currentdir%chmlib\msinttypes;%currentdir%\chmlib\src>> setup.cfg
echo library_dirs=%currentdir%chmlib\release>> setup.cfg
python setup.py install --record files.txt
set pychmbuild=PyCHM installed from %currentdir%chmlib\pychm directory, see files.txt
:finished
cd "%currentdir%"
echo === TASKS FINISHED ===
if "%chmlibbuild%" neq "" echo %chmlibbuild%
echo %pychmbuild%
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment