From 87c2e5bc3cafd6474facac7ce4c68881ba56e15b Mon Sep 17 00:00:00 2001 From: Leonardo de Moura Date: Wed, 24 Oct 2012 16:00:25 -0700 Subject: [PATCH] Enabled .so support Signed-off-by: Leonardo de Moura --- configure.ac | 14 ++++++--- scripts/config-debug.mk.in | 7 ++++- scripts/config-release.mk.in | 5 ++++ scripts/mk_make.py | 1 + scripts/mk_util.py | 56 ++++++++++++++++++++++++++++++------ 5 files changed, 70 insertions(+), 13 deletions(-) diff --git a/configure.ac b/configure.ac index 07ef64102..f4b659a41 100644 --- a/configure.ac +++ b/configure.ac @@ -103,21 +103,24 @@ host_os=`uname -s` AS_IF([test "$host_os" = "Darwin"], [ PLATFORM=osx - SO_EXT=dylib + SO_EXT=.dylib SLIBFLAGS="-dynamiclib -fopenmp" + SLIBEXTRAFLAGS="" COMP_VERSIONS="-compatibility_version \$(Z3_VERSION) -current_version \$(Z3_VERSION)" STATIC_FLAGS= ], [test "$host_os" = "Linux"], [ PLATFORM=linux - SO_EXT=so - SLIBFLAGS="-shared -fopenmp" + SO_EXT=.so + SLIBFLAGS="-shared -fopenmp -Wl,--whole-archive" + SLIBEXTRAFLAGS="-Wl,--no-whole-archive" COMP_VERSIONS= STATIC_FLAGS=-static ], [test "${host_os:0:6}" = "CYGWIN"], [ PLATFORM=win - SO_EXT=dll + SO_EXT=.dll LDFLAGS= SLIBFLAGS="-shared -fopenmp" + SLIBEXTRAFLAGS="" COMP_VERSIONS= STATIC_FLAGS=-static CXXFLAGS+=" -D_CYGWIN" @@ -125,6 +128,9 @@ AS_IF([test "$host_os" = "Darwin"], [ [ AC_MSG_ERROR([Unknown host platform: $host_os]) ]) +AC_SUBST(SLIBFLAGS) +AC_SUBST(SLIBEXTRAFLAGS) +AC_SUBST(SO_EXT) ################### # diff --git a/scripts/config-debug.mk.in b/scripts/config-debug.mk.in index 0c4d1b333..78109ea7a 100644 --- a/scripts/config-debug.mk.in +++ b/scripts/config-debug.mk.in @@ -11,4 +11,9 @@ AR_OUTFLAG= EXE_EXT= LINK=@CXX@ LINK_FLAGS=-lpthread -fopenmp -LINK_OUT_FLAG=-o \ No newline at end of file +LINK_OUT_FLAG=-o +SO_EXT=@SO_EXT@ +SLINK=@CXX@ +SLINK_FLAGS=@SLIBFLAGS@ +SLINK_EXTRA_FLAGS=@SLIBEXTRAFLAGS@ +SLINK_OUT_FLAG=-o \ No newline at end of file diff --git a/scripts/config-release.mk.in b/scripts/config-release.mk.in index 27c87b0e3..8e0f0f4c2 100644 --- a/scripts/config-release.mk.in +++ b/scripts/config-release.mk.in @@ -12,3 +12,8 @@ EXE_EXT= LINK=@CXX@ LINK_FLAGS=-lpthread -fopenmp LINK_OUT_FLAG=-o +SO_EXT=@SO_EXT@ +SLINK=@CXX@ +SLINK_FLAGS=@SLIBFLAGS@ +SLINK_EXTRA_FLAGS=@SLIBEXTRAFLAGS@ +SLINK_OUT_FLAG=-o \ No newline at end of file diff --git a/scripts/mk_make.py b/scripts/mk_make.py index a9d2e481d..f3ecdbdcd 100644 --- a/scripts/mk_make.py +++ b/scripts/mk_make.py @@ -62,5 +62,6 @@ add_lib('portfolio', ['smtlogic_tactics', 'ufbv_tactic', 'fpa', 'aig', 'muz_qe', add_lib('api', ['portfolio', 'user_plugin']) add_exe('shell', ['api', 'sat', 'extra_cmds'], exe_name='z3') add_exe('test', ['api', 'fuzzing'], exe_name='test-z3') +add_dll('api_dll', ['api', 'sat', 'extra_cmds'], 'api/dll', dll_name='libz3') mk_makefile() diff --git a/scripts/mk_util.py b/scripts/mk_util.py index 52571eb3d..cd49ee170 100644 --- a/scripts/mk_util.py +++ b/scripts/mk_util.py @@ -24,9 +24,6 @@ DEBUG_MODE=False SHOW_CPPS = True VS_X64 = False -LIB_KIND = 0 -EXE_KIND = 1 - if os.name == 'nt': IS_WINDOW=True # Visual Studio already displays the files being compiled @@ -142,13 +139,12 @@ def find_all_deps(name, deps): return new_deps class Component: - def __init__(self, name, kind, path, deps): + def __init__(self, name, path, deps): global BUILD_DIR, SRC_DIR, REV_BUILD_DIR if name in _ComponentNames: raise MKException("Component '%s' was already defined." % name) if path == None: path = name - self.kind = kind self.name = name self.path = path self.deps = find_all_deps(name, deps) @@ -232,7 +228,7 @@ class Component: class LibComponent(Component): def __init__(self, name, path, deps): - Component.__init__(self, name, LIB_KIND, path, deps) + Component.__init__(self, name, path, deps) def mk_makefile(self, out): Component.mk_makefile(self, out) @@ -267,7 +263,7 @@ def sort_components(cnames): class ExeComponent(Component): def __init__(self, name, exe_name, path, deps): - Component.__init__(self, name, EXE_KIND, path, deps) + Component.__init__(self, name, path, deps) if exe_name == None: exe_name = name self.exe_name = exe_name @@ -305,6 +301,46 @@ class ExeComponent(Component): def main_component(self): return True +class DLLComponent(Component): + def __init__(self, name, dll_name, path, deps): + Component.__init__(self, name, path, deps) + if dll_name == None: + dll_name = name + self.dll_name = dll_name + + def mk_makefile(self, out): + global _Name2Component + Component.mk_makefile(self, out) + # generate rule for (SO_EXT) + + dllfile = '%s$(SO_EXT)' % self.dll_name + out.write('%s:' % dllfile) + deps = sort_components(self.deps) + objs = [] + for cppfile in get_cpp_files(self.src_dir): + objfile = '%s/%s$(OBJ_EXT)' % (self.build_dir, os.path.splitext(cppfile)[0]) + objs.append(objfile) + for obj in objs: + out.write(' ') + out.write(obj) + for dep in deps: + c_dep = _Name2Component[dep] + out.write(' %s/%s$(LIB_EXT)' % (c_dep.build_dir, c_dep.name)) + out.write('\n') + out.write('\t$(LINK) $(SLINK_OUT_FLAG)%s $(SLINK_FLAGS)' % dllfile) + for obj in objs: + out.write(' ') + out.write(obj) + for dep in deps: + c_dep = _Name2Component[dep] + out.write(' %s/%s$(LIB_EXT)' % (c_dep.build_dir, c_dep.name)) + out.write(' $(SLINK_EXTRA_FLAGS)\n') + out.write('%s: %s\n\n' % (self.name, dllfile)) + + # All DLLs are included in the all: rule + def main_component(self): + return True + def reg_component(name, c): global _Id, _Components, _ComponentNames, _Name2Component c.id = _Id @@ -323,6 +359,10 @@ def add_exe(name, deps=[], path=None, exe_name=None): c = ExeComponent(name, exe_name, path, deps) reg_component(name, c) +def add_dll(name, deps=[], path=None, dll_name=None): + c = DLLComponent(name, dll_name, path, deps) + reg_component(name, c) + # Copy configuration correct file to BUILD_DIR def cp_config_mk(): if IS_WINDOW: @@ -352,7 +392,7 @@ def mk_makefile(): # Generate :all rule out.write('all:') for c in _Components: - if c.main_component: + if c.main_component(): out.write(' %s' % c.name) out.write('\n\n') # Generate components