With newer versions of emscripten, linker errors surface eariler.
This makes it easier to find function pointer cast errors without
having to execute the bad code path -- the errors happen when the
wasm modules are linked (at load time in the browser)

Anyways, this fixes more linker errors. Mostly the problems have
to do with LAPACK functions that take string arguments. Most
LAPACK functions that take string arguments use them as enums and
only care about the first character of the string. Because of the
way that f2c works, we need to replace these strings with the ascii
code of the first character so we should replace:

sTRSV( 'UPPER', 'NOTRANS', 'NONUNIT', J, H, LDH, Y, 1 )
==>
CALL sTRSV( 85, 78, 78, J, H, LDH, Y, 1 )

where 85 and 78 are the ascii codes of U and N. Various character
variables are subbed into being integer variables. The two
functions `ilaenv` and `xerbla` expect actual C strings as an
argument, but it is very annoying to produce C strings so instead
I added wrapper functions ilaenvf2c and xerblaf2c to clapack and
instead of calling ilaenv and xerbla we call the f2c versions.

Fix scipy linking errors. With newer versions of emscripten, linker errors surface eariler.
This makes it easier to find function pointer cast errors without
having to execute the bad code path -- the errors happen when the
wasm modules are linked (at load time in the browser)

Anyways, this fixes more linker errors. Mostly the problems have
to do with LAPACK functions that take string arguments. Most
LAPACK functions that take string arguments use them as enums and
only care about the first character of the string. Because of the
way that f2c works, we need to replace these strings with the ascii
code of the first character so we should replace:

sTRSV( 'UPPER', 'NOTRANS', 'NONUNIT', J, H, LDH, Y, 1 )
==>
CALL sTRSV( 85, 78, 78, J, H, LDH, Y, 1 )

where 85 and 78 are the ascii codes of U and N. Various character
variables are subbed into being integer variables. The two
functions `ilaenv` and `xerbla` expect actual C strings as an
argument, but it is very annoying to produce C strings so instead
I added wrapper functions ilaenvf2c and xerblaf2c to clapack and
instead of calling ilaenv and xerbla we call the f2c versions.

This patch simplifies the compilation process for the pysolvers extension.
As a result, all the solvers are compiled by em++, which makes lingeling
difficult to compile. Solving this issue seems possible eventually but it
requires more effort to put, which might be not worth it at this point.

diff --git a/setup.py b/setup.py
index 82dac9c..3fe102f 100644
--- a/setup.py
+++ b/setup.py
@@ -69,8 +69,8 @@ Details can be found at `https://pysathq.github.io <https://pysathq.github.io>`_
 # solvers to install
 #==============================================================================
 to_install = ['cadical', 'gluecard30', 'gluecard41', 'glucose30', 'glucose41',
-        'lingeling', 'maplechrono', 'maplecm', 'maplesat', 'mergesat3',
-        'minicard', 'minisat22', 'minisatgh']
+        'maplechrono', 'maplecm', 'maplesat', 'mergesat3', 'minicard',
+        'minisat22', 'minisatgh']
 
 # example scripts to install as standalone executables
 #==============================================================================
@@ -78,47 +78,9 @@ scripts = ['fm', 'genhard', 'lbx', 'lsu', 'mcsls', 'models', 'musx', 'optux',
         'rc2']
 
 
-# we need to redefine the build command to
-# be able to download and compile solvers
-#==============================================================================
-class build(distutils.command.build.build):
-    """
-        Our custom builder class.
-    """
-
-    def run(self):
-        """
-            Download, patch and compile SAT solvers before building.
-        """
-        # download and compile solvers
-        if platform.system() != 'Windows':
-            prepare.do(to_install)
-
-        # now, do standard build
-        distutils.command.build.build.run(self)
-
-# same with build_ext
-#==============================================================================
-class build_ext(distutils.command.build_ext.build_ext):
-    """
-        Our custom builder class.
-    """
-
-    def run(self):
-        """
-            Download, patch and compile SAT solvers before building.
-        """
-        # download and compile solvers
-        if platform.system() != 'Windows':
-            prepare.do(to_install)
-
-        # now, do standard build
-        distutils.command.build_ext.build_ext.run(self)
-
-
 # compilation flags for C extensions
 #==============================================================================
-compile_flags, cpplib = ['-std=c++11', '-Wall', '-Wno-deprecated'],  ['stdc++']
+compile_flags, cpplib = ['-std=c++11', '-O3', '-Wall', '-Wno-deprecated', '-DQUIET'],  ['stdc++']
 if platform.system() == 'Darwin':
     compile_flags += ['--stdlib=libc++']
     cpplib = ['c++']
@@ -141,23 +103,19 @@ pycard_ext = Extension('pycard',
 
 pysolvers_sources = ['solvers/pysolvers.cc']
 
-if platform.system() == 'Windows':
-    prepare.do(to_install)
-    with chdir('solvers'):
-        for solver in to_install:
-            with chdir(solver):
-                for filename in glob.glob('*.c*'):
-                    pysolvers_sources += ['solvers/%s/%s' % (solver, filename)]
-                for filename in glob.glob('*/*.c*'):
-                    pysolvers_sources += ['solvers/%s/%s' % (solver, filename)]
-    libraries = []
-    library_dirs = []
-else:
-    libraries = to_install + cpplib
-    library_dirs = list(map(lambda x: os.path.join('solvers', x), to_install))
+prepare.do(to_install)
+with chdir('solvers'):
+    for solver in to_install:
+        with chdir(solver):
+            for filename in glob.glob('*.c*'):
+                pysolvers_sources += ['solvers/%s/%s' % (solver, filename)]
+            for filename in glob.glob('*/*.c*'):
+                pysolvers_sources += ['solvers/%s/%s' % (solver, filename)]
+libraries = []
+library_dirs = []
 
 pysolvers_ext = Extension('pysolvers',
-    sources=pysolvers_sources,
+    sources=sorted(pysolvers_sources),
     extra_compile_args=compile_flags + \
         list(map(lambda x: '-DWITH_{0}'.format(x.upper()), to_install)),
     include_dirs=['solvers'],
@@ -182,7 +140,6 @@ setup(name='python-sat',
     url='https://github.com/pysathq/pysat',
     ext_modules=[pycard_ext, pysolvers_ext],
     scripts=['examples/{0}.py'.format(s) for s in scripts],
-    cmdclass={'build': build, 'build_ext': build_ext},
     install_requires=['six'],
     extras_require = {
         'aiger': ['py-aiger-cnf>=2.0.0'],
diff --git a/solvers/prepare.py b/solvers/prepare.py
index a1b5e91..464e1d1 100644
--- a/solvers/prepare.py
+++ b/solvers/prepare.py
@@ -520,8 +520,6 @@ def do(to_install):
         adapt_files(solver)
         patch_solver(solver)
 
-        if platform.system() != 'Windows':
-            compile_solver(solver)
 
 #
 #==============================================================================

This patch simplifies the compilation process for the pysolvers extension.
As a result, all the solvers are compiled by em++, which makes lingeling
difficult to compile. Solving this issue seems possible eventually but it
requires more effort to put, which might be not worth it at this point.

diff --git a/setup.py b/setup.py
index 82dac9c..3fe102f 100644
--- a/setup.py
+++ b/setup.py
@@ -69,8 +69,8 @@ Details can be found at `https://pysathq.github.io <https://pysathq.github.io>`_
 # solvers to install
 #==============================================================================
 to_install = ['cadical', 'gluecard30', 'gluecard41', 'glucose30', 'glucose41',
-        'lingeling', 'maplechrono', 'maplecm', 'maplesat', 'mergesat3',
-        'minicard', 'minisat22', 'minisatgh']
+        'maplechrono', 'maplecm', 'maplesat', 'mergesat3', 'minicard',
+        'minisat22', 'minisatgh']
 
 # example scripts to install as standalone executables
 #==============================================================================
@@ -78,47 +78,9 @@ scripts = ['fm', 'genhard', 'lbx', 'lsu', 'mcsls', 'models', 'musx', 'optux',
         'rc2']
 
 
-# we need to redefine the build command to
-# be able to download and compile solvers
-#==============================================================================
-class build(distutils.command.build.build):
-    """
-        Our custom builder class.
-    """
-
-    def run(self):
-        """
-            Download, patch and compile SAT solvers before building.
-        """
-        # download and compile solvers
-        if platform.system() != 'Windows':
-            prepare.do(to_install)
-
-        # now, do standard build
-        distutils.command.build.build.run(self)
-
-# same with build_ext
-#==============================================================================
-class build_ext(distutils.command.build_ext.build_ext):
-    """
-        Our custom builder class.
-    """
-
-    def run(self):
-        """
-            Download, patch and compile SAT solvers before building.
-        """
-        # download and compile solvers
-        if platform.system() != 'Windows':
-            prepare.do(to_install)
-
-        # now, do standard build
-        distutils.command.build_ext.build_ext.run(self)
-
-
 # compilation flags for C extensions
 #==============================================================================
-compile_flags, cpplib = ['-std=c++11', '-Wall', '-Wno-deprecated'],  ['stdc++']
+compile_flags, cpplib = ['-std=c++11', '-O3', '-Wall', '-Wno-deprecated', '-DQUIET'],  ['stdc++']
 if platform.system() == 'Darwin':
     compile_flags += ['--stdlib=libc++']
     cpplib = ['c++']
@@ -141,23 +103,19 @@ pycard_ext = Extension('pycard',
 
 pysolvers_sources = ['solvers/pysolvers.cc']
 
-if platform.system() == 'Windows':
-    prepare.do(to_install)
-    with chdir('solvers'):
-        for solver in to_install:
-            with chdir(solver):
-                for filename in glob.glob('*.c*'):
-                    pysolvers_sources += ['solvers/%s/%s' % (solver, filename)]
-                for filename in glob.glob('*/*.c*'):
-                    pysolvers_sources += ['solvers/%s/%s' % (solver, filename)]
-    libraries = []
-    library_dirs = []
-else:
-    libraries = to_install + cpplib
-    library_dirs = list(map(lambda x: os.path.join('solvers', x), to_install))
+prepare.do(to_install)
+with chdir('solvers'):
+    for solver in to_install:
+        with chdir(solver):
+            for filename in glob.glob('*.c*'):
+                pysolvers_sources += ['solvers/%s/%s' % (solver, filename)]
+            for filename in glob.glob('*/*.c*'):
+                pysolvers_sources += ['solvers/%s/%s' % (solver, filename)]
+libraries = []
+library_dirs = []
 
 pysolvers_ext = Extension('pysolvers',
-    sources=pysolvers_sources,
+    sources=sorted(pysolvers_sources),
     extra_compile_args=compile_flags + \
         list(map(lambda x: '-DWITH_{0}'.format(x.upper()), to_install)),
     include_dirs=['solvers'],
@@ -182,7 +140,6 @@ setup(name='python-sat',
     url='https://github.com/pysathq/pysat',
     ext_modules=[pycard_ext, pysolvers_ext],
     scripts=['examples/{0}.py'.format(s) for s in scripts],
-    cmdclass={'build': build, 'build_ext': build_ext},
     install_requires=['six'],
     extras_require = {
         'aiger': ['py-aiger-cnf>=2.0.0'],
diff --git a/solvers/prepare.py b/solvers/prepare.py
index a1b5e91..464e1d1 100644
--- a/solvers/prepare.py
+++ b/solvers/prepare.py
@@ -520,8 +520,6 @@ def do(to_install):
         adapt_files(solver)
         patch_solver(solver)
 
-        if platform.system() != 'Windows':
-            compile_solver(solver)
 
 #
 #==============================================================================
