Created
March 25, 2014 16:52
-
-
Save FlorianLudwig/9766208 to your computer and use it in GitHub Desktop.
compile ngspice with emscripten (WIP)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# this is WIP and does NOT produce a working result. | |
import os | |
import shutil | |
import subprocess as sp | |
NG_SPICE_25 = 'http://netcologne.dl.sourceforge.net/project/ngspice/ng-spice-rework/25/ngspice-25.tar.gz' | |
NG_SPICE_26 = 'http://optimate.dl.sourceforge.net/project/ngspice/ng-spice-rework/26/ngspice-26.tar.gz' | |
# build own llvm | |
""" | |
cd ~ | |
svn co http://llvm.org/svn/llvm-project/llvm/tags/RELEASE_32/final llvm32 | |
cd llvm32/tools | |
svn co http://llvm.org/svn/llvm-project/cfe/tags/RELEASE_32/final clang | |
cd ../projects | |
svn co http://llvm.org/svn/llvm-project/compiler-rt/tags/RELEASE_32/final compiler-rt | |
cd ../.. | |
mkdir llvm32build | |
cd llvm32build | |
cmake -DCMAKE_BUILD_TYPE=Release -G "Unix Makefiles" -DLLVM_BUILD_EXAMPLES=OFF -DLLVM_INCLUDE_EXAMPLES=OFF -DLLVM_BUILD_TESTS=OFF -DLLVM_INCLUDE_TESTS=OFF ../llvm32 | |
make | |
""" | |
def bold(message): | |
print '\033[1m' + message + '\033[0m' | |
def call(cmd): | |
bold(cmd[0] + ' ' + ' '.join(repr(part) for part in cmd[1:])) | |
return sp.call(cmd) | |
def main(): | |
base_dir = os.path.abspath('.') | |
assert sp.Popen(['ngmakeidx']).wait() == 0, 'ngspice must be installed' | |
# download emscript, if needed | |
if not os.path.exists('emscripten'): | |
call(['git', 'clone', 'https://github.com/kripken/emscripten.git']) | |
# lets check if it got installed ok | |
os.chdir('emscripten') | |
call(['./emcc']) # first call initializes emscripten | |
call(['./em++', 'tests/hello_world.cpp']) | |
assert call(['node', 'a.out.js']) == 0 | |
os.chdir(base_dir) | |
# download ngspice | |
version = NG_SPICE_25 | |
src_tar = version.split('/')[-1] | |
src = src_tar.replace('.tar.gz', '') | |
if not os.path.exists(src_tar): | |
call(['wget', version]) | |
if os.path.exists(src): | |
shutil.rmtree(src) | |
call(['tar', '-xzf', src_tar]) | |
# actual build | |
os.chdir(src) | |
call([base_dir + '/emscripten/emconfigure', './configure', '--without-x']) | |
# the build process runs ngmakeidx which is compiled during the process | |
# since it is not available at the time | |
bold('patch src/Makefile: use system ngmakeidx') | |
makefile = open('src/Makefile').read() | |
makefile = makefile.replace('./ngmakeidx', 'ngmakeidx') | |
out = open('src/Makefile', 'w') | |
out.write(makefile) | |
out.close() | |
call([base_dir + '/emscripten/emmake', 'make']) | |
os.rename('src/ngspice', 'ngspice.bc') | |
# | |
call([base_dir + '/emscripten/emcc', | |
'-s', 'ALLOW_MEMORY_GROWTH=1', | |
'-s', 'TOTAL_MEMORY=52428800', | |
'ngspice.bc', '-o', 'ngspice.js']) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment