From 6a0e05153c34a9dbb0793b1149725595cb0e0039 Mon Sep 17 00:00:00 2001 From: Leonardo de Moura Date: Tue, 23 Oct 2012 15:10:46 -0700 Subject: [PATCH] improving mk_make.py Signed-off-by: Leonardo de Moura --- scripts/mk_make.py | 2 ++ scripts/mk_util.py | 69 +++++++++++++++++++++++++++++++++++++++------- 2 files changed, 61 insertions(+), 10 deletions(-) diff --git a/scripts/mk_make.py b/scripts/mk_make.py index 995d0df26..590e8a50b 100644 --- a/scripts/mk_make.py +++ b/scripts/mk_make.py @@ -8,6 +8,8 @@ ############################################ from mk_util import * +parse_options() + # set_build_dir('build') # set_src_dir('src') # set_modes(['Debug', 'Release']) diff --git a/scripts/mk_util.py b/scripts/mk_util.py index 8f24fccef..7209182a0 100644 --- a/scripts/mk_util.py +++ b/scripts/mk_util.py @@ -10,23 +10,64 @@ import os import glob import sets import re +import getopt +import sys from mk_exception import * BUILD_DIR='build' REV_BUILD_DIR='..' SRC_DIR='src' IS_WINDOW=False -CXX='g++' -MAKE='make' -if os.name == 'nt': - IS_WINDOW=True - CXX='cl' - MAKE='nmake' +VERBOSE=False +DEBUG_MODE=False SHOW_CPPS = True +VS_X64 = False LIB_KIND = 0 EXE_KIND = 1 +if os.name == 'nt': + IS_WINDOW=True + +def display_help(): + print "mk_make.py: Z3 Makefile generator\n" + print "This script generates the Makefile for the Z3 theorem prover." + print "It must be executed from the Z3 root directory." + print "\nOptions:" + print " -h, --help display this message" + print " -v, --verbose be verbose" + print " -b , --build= subdirectory where Z3 will be built (default: build)." + print " -d, --debug compile Z3 in debug mode." + print " -x, --x64 create 64 binary when using Visual Studio." + exit(0) + +# Parse configuration option for mk_make script +def parse_options(): + global VERBOSE, DEBUG_MODE, IS_WINDOW, VS_X64 + options, remainder = getopt.gnu_getopt(sys.argv[1:], 'b:dvxh', ['build=', + 'debug', + 'verbose', + 'x64', + 'help' + ]) + for opt, arg in options: + if opt in ('-b', '--build'): + if arg == 'src': + raise MKException('The src directory should not be used to host the Makefile') + set_build_dir(arg) + elif opt in ('-v', '--verbose'): + VERBOSE = True + elif opt in ('-d', '--debug'): + DEBUG_MODE = True + elif opt in ('-x', '--x64'): + if not IS_WINDOW: + raise MKException('x64 compilation mode can only be specified when using Visual Studio') + VS_X64 = True + elif opt in ('-h', '--help'): + display_help() + else: + raise MKException("Invalid command line option '%s'" % opt) + # Return a list containing a file names included using '#include' in # the given C/C++ file named fname. def extract_c_includes(fname): @@ -261,6 +302,8 @@ def reg_component(name, c): _Components.append(c) _ComponentNames.add(name) _Name2Component[name] = c + if VERBOSE: + print "Processed '%s'" % name def add_lib(name, deps=[], path=None): c = LibComponent(name, path, deps) @@ -272,13 +315,19 @@ def add_exe(name, deps=[], path=None, exe_name=None): def mk_makefile(): mk_dir(BUILD_DIR) + if VERBOSE: + print "Writing %s/Makefile" % BUILD_DIR out = open('%s/Makefile' % BUILD_DIR, 'w') out.write('# Automatically generated file. Generator: scripts/mk_make.py\n') out.write('include config.mk\n') for c in _Components: c.mk_makefile(out) + if VERBOSE: + print "Makefile was successfully generated." + if DEBUG_MODE: + print " compilation mode: Debug" + else: + print " compilation mode: Release" + print "Type 'cd %s; make' to build Z3" % BUILD_DIR + -# add_lib('util') -# add_lib('polynomial', ['util']) -# add_lib('ast', ['util', 'polynomial']) -# mk_makefile()