diff --git a/doc/mk_api_doc.py b/doc/mk_api_doc.py index 476f2c8c7..b93654288 100644 --- a/doc/mk_api_doc.py +++ b/doc/mk_api_doc.py @@ -1,11 +1,52 @@ import os import shutil import re +import getopt import pydoc import sys import subprocess import shutil +ML_ENABLED=False +BUILD_DIR='../build' + +def norm_path(p): + # We use '/' on mk_project for convenience + return os.path.join(*(p.split('/'))) + +def display_help(exit_code): + print("mk_api_doc.py: Z3 documentation generator\n") + print("\nOptions:") + print(" -h, --help display this message.") + print(" -b , --build= subdirectory where Z3 is built (default: ../build).") + print(" --ml include ML/OCaml API documentation.") + +def parse_options(): + global ML_ENABLED, BUILD_DIR + + try: + options, remainder = getopt.gnu_getopt(sys.argv[1:], + 'b:h', + ['build=', 'help', 'ml']) + except: + print("ERROR: Invalid command line option") + display_help(1) + + for opt, arg in options: + if opt in ('-b', '--build'): + BUILD_DIR = norm_path(arg) + elif opt in ('h', '--help'): + display_help() + exit(1) + elif opt in ('--ml'): + ML_ENABLED=True + else: + print("ERROR: Invalid command line option: %s" % opt) + display_help(1) + + + + def mk_dir(d): if not os.path.exists(d): os.makedirs(d) @@ -22,9 +63,23 @@ def cleanup_API(inf, outf): _outf.write(line) try: + parse_options() + + fi = open('website.dox', 'r') + fo = open('website-adj.dox', 'w') + + for line in fi: + if (line != '[ML]\n'): + fo.write(line) + elif (ML_ENABLED): + fo.write(' - ML/OCaml API\n') + fi.close() + fo.close() + mk_dir('api/html') mk_dir('tmp') - shutil.copyfile('website.dox', 'tmp/website.dox') + shutil.copyfile('website-adj.dox', 'tmp/website.dox') + os.remove('website-adj.dox') shutil.copyfile('../src/api/python/z3.py', 'tmp/z3py.py') cleanup_API('../src/api/z3_api.h', 'tmp/z3_api.h') cleanup_API('../src/api/z3_algebraic.h', 'tmp/z3_algebraic.h') @@ -59,6 +114,14 @@ try: pydoc.writedoc('z3') shutil.move('z3.html', 'api/html/z3.html') print "Generated Python documentation." + + if ML_ENABLED: + mk_dir('api/html/ml') + if subprocess.call(['ocamldoc', '-html', '-d', 'api\html\ml', '-sort', '-hide', 'Z3', '-I', '%s/api/ml' % BUILD_DIR, '../src/api/ml/z3enums.mli', '../src/api/ml/z3.mli']) != 0: + print "ERROR: ocamldoc failed." + exit(1) + print "Generated ML/OCaml documentation." + print "Documentation was successfully generated at subdirectory './api/html'." except: print "ERROR: failed to generate documentation" diff --git a/doc/website.dox b/doc/website.dox index d048dab0c..5b77c46c6 100644 --- a/doc/website.dox +++ b/doc/website.dox @@ -14,6 +14,7 @@ - \ref cppapi - .NET API - Java API - - Python API (also available in pydoc format). + - Python API (also available in pydoc format) +[ML] - Try Z3 online at RiSE4Fun. */