import sys

if len(sys.argv) != 4:
    print """Usage:
    generate_doc_inputspec.py <package-dir> <build-dir> <output-spec-file>"""
    sys.exit()

packageDir=sys.argv[1]
buildDir=sys.argv[2]
outputFileName=sys.argv[3]

xmlFileContents="""<?xml version="1.0" ?>
<!DOCTYPE INPUTSPEC SYSTEM "inputspec.dtd">

<!-- This file is automatically generated by generate_doc_inputspec.py.  Please do not directly modify this xml file. -->

<INPUTSPEC>

	<GLOBALDIR RECURSIVE="YES">
		<FILEPATTERN>*.h</FILEPATTERN>
		<FILEPATTERN>*.cpp</FILEPATTERN>
	</GLOBALDIR>

	<FILE SOURCE="%(PACKAGE_DIR)s/src/doc/prose/mainpage.dox" />
   	
	<GROUP TITLE="Prerequisite Knowledge" NAME="g_prerequisite_knowledge">
	    <FILE SOURCE="%(PACKAGE_DIR)s/src/doc/prose/prerequisite_knowledge.dox" />
		<FILE SOURCE="%(PACKAGE_DIR)s/src/doc/prose/prerequisite_knowledge/vectorization.dox" />
		<FILE SOURCE="%(PACKAGE_DIR)s/src/doc/prose/prerequisite_knowledge/scalar_access.dox" />
		<FILE SOURCE="%(PACKAGE_DIR)s/src/doc/prose/prerequisite_knowledge/load_hit_store.dox" />
		<FILE SOURCE="%(PACKAGE_DIR)s/src/doc/prose/prerequisite_knowledge/branching.dox" />
	</GROUP>
	
	<GROUP TITLE="Overview" NAME="g_overview">
		<FILE SOURCE="%(PACKAGE_DIR)s/src/doc/prose/overview.dox" />
		<FILE SOURCE="%(PACKAGE_DIR)s/src/doc/prose/overview/platform_support.dox" />
		<FILE SOURCE="%(PACKAGE_DIR)s/src/doc/prose/overview/vpu_library.dox" />
		<FILE SOURCE="%(PACKAGE_DIR)s/src/doc/prose/overview/fpu_library.dox" />
		<FILE SOURCE="%(PACKAGE_DIR)s/src/doc/prose/overview/vpl_library.dox" />
		<FILE SOURCE="%(PACKAGE_DIR)s/src/doc/prose/overview/fpu_versus_vpu.dox" />		
		<FILE SOURCE="%(PACKAGE_DIR)s/src/doc/prose/overview/defines.dox" />
		<FILE SOURCE="%(PACKAGE_DIR)s/src/doc/prose/overview/when_not_to_use.dox" />
		<FILE SOURCE="%(PACKAGE_DIR)s/src/doc/prose/overview/deprecation.dox" />
		<FILE SOURCE="%(PACKAGE_DIR)s/src/doc/prose/overview/known_issues.dox" />
		<GROUP TITLE="Types" NAME="g_types">
		    <FILE SOURCE="%(PACKAGE_DIR)s/src/doc/prose/overview/types/vec_float.dox" />
		    <FILE SOURCE="%(PACKAGE_DIR)s/src/doc/prose/overview/types/vector3plus.dox" />
		    <FILE SOURCE="%(PACKAGE_DIR)s/src/doc/prose/overview/types/quatpos.dox" />
		    <FILE SOURCE="%(PACKAGE_DIR)s/src/doc/prose/overview/types/matrix44affine.dox" />
		    <FILE SOURCE="%(PACKAGE_DIR)s/src/doc/prose/overview/types/matrix44affinepacked.dox" />
            <GROUP TITLE="Mask Types" NAME="g_mask_types">
                <FILE SOURCE="%(PACKAGE_DIR)s/src/doc/prose/overview/types/mask_types.dox" />
                <FILE SOURCE="%(PACKAGE_DIR)s/src/doc/prose/overview/types/mask_types/maskscalar.dox" />
                <FILE SOURCE="%(PACKAGE_DIR)s/src/doc/prose/overview/types/mask_types/mask2.dox" />
                <FILE SOURCE="%(PACKAGE_DIR)s/src/doc/prose/overview/types/mask_types/mask3.dox" />
                <FILE SOURCE="%(PACKAGE_DIR)s/src/doc/prose/overview/types/mask_types/mask4.dox" />
            </GROUP>
        </GROUP>
	</GROUP>
	
	<GROUP TITLE="Gotchas" NAME="g_gotchas">
	    <FILE SOURCE="%(PACKAGE_DIR)s/src/doc/prose/gotchas.dox" />
	    <FILE SOURCE="%(PACKAGE_DIR)s/src/doc/prose/gotchas/address_of_accessors.dox" />	       
	    <FILE SOURCE="%(PACKAGE_DIR)s/src/doc/prose/gotchas/printf.dox" />
	    <FILE SOURCE="%(PACKAGE_DIR)s/src/doc/prose/gotchas/aliasing.dox" />	    
	    <FILE SOURCE="%(PACKAGE_DIR)s/src/doc/prose/gotchas/alignment.dox" />	    
	    <FILE SOURCE="%(PACKAGE_DIR)s/src/doc/prose/gotchas/potentially_spurious_warnings.dox" />	    
	    <FILE SOURCE="%(PACKAGE_DIR)s/src/doc/prose/gotchas/endian_swapping.dox" />	    
	    <FILE SOURCE="%(PACKAGE_DIR)s/src/doc/prose/gotchas/ambiguous_function_calls.dox" />	    
	    <FILE SOURCE="%(PACKAGE_DIR)s/src/doc/prose/gotchas/gotchas_for_branch_free_code.dox" />	    
        <FILE SOURCE="%(PACKAGE_DIR)s/src/doc/prose/gotchas/constistency_of_results.dox" />
        <FILE SOURCE="%(PACKAGE_DIR)s/src/doc/prose/gotchas/static_initialization_order.dox" />
        <FILE SOURCE="%(PACKAGE_DIR)s/src/doc/prose/gotchas/matrix_lookat_functions.dox" />
	</GROUP>
	
	<GROUP TITLE="Best Practices" NAME="g_best_practices">
	    <FILE SOURCE="%(PACKAGE_DIR)s/src/doc/prose/best_practices.dox" />
	    <FILE SOURCE="%(PACKAGE_DIR)s/src/doc/prose/best_practices/porting_legacy.dox" />
	    <FILE SOURCE="%(PACKAGE_DIR)s/src/doc/prose/best_practices/forward_declaring.dox" />
	    <FILE SOURCE="%(PACKAGE_DIR)s/src/doc/prose/best_practices/casting_between_math_types.dox" />
	    <FILE SOURCE="%(PACKAGE_DIR)s/src/doc/prose/best_practices/constants.dox" />
	    <FILE SOURCE="%(PACKAGE_DIR)s/src/doc/prose/best_practices/write_your_own.dox" />	    
	    <FILE SOURCE="%(PACKAGE_DIR)s/src/doc/prose/best_practices/private_vs_public_functionality.dox" />	    
	    <FILE SOURCE="%(PACKAGE_DIR)s/src/doc/prose/best_practices/hijacking_namespaces.dox" />
	    <FILE SOURCE="%(PACKAGE_DIR)s/src/doc/prose/best_practices/choosing_fpu_or_vpu.dox" />
	</GROUP>
		
	<GROUP TITLE="Optimization" NAME="g_optimization">
	    <FILE SOURCE="%(PACKAGE_DIR)s/src/doc/prose/optimization.dox" />
        <FILE SOURCE="%(PACKAGE_DIR)s/src/doc/prose/optimization/optimization_guidelines.dox" />
        <FILE SOURCE="%(PACKAGE_DIR)s/src/doc/prose/optimization/data_dependencies.dox" />
        <FILE SOURCE="%(PACKAGE_DIR)s/src/doc/prose/optimization/estimates_and_approximations.dox" />
        <FILE SOURCE="%(PACKAGE_DIR)s/src/doc/prose/optimization/literal_constants.dox" />
        <GROUP TITLE="Branch Free Coding" NAME="g_branch_free_coding">
            <FILE SOURCE="%(PACKAGE_DIR)s/src/doc/prose/optimization/branch_free_coding.dox" />
            <FILE SOURCE="%(PACKAGE_DIR)s/src/doc/prose/optimization/branch_free_coding/mask_operations.dox" />
            <FILE SOURCE="%(PACKAGE_DIR)s/src/doc/prose/optimization/branch_free_coding/comparison_operations.dox" />
            <FILE SOURCE="%(PACKAGE_DIR)s/src/doc/prose/optimization/branch_free_coding/select_operations.dox" />
            <FILE SOURCE="%(PACKAGE_DIR)s/src/doc/prose/optimization/branch_free_coding/boolean_vs_bitwise_semantics.dox" />
            <FILE SOURCE="%(PACKAGE_DIR)s/src/doc/prose/optimization/branch_free_coding/implementation_details.dox" />
        </GROUP>
        <GROUP TITLE="Coding Dos and Donts " NAME="g_coding_dos_and_donts">
            <FILE SOURCE="%(PACKAGE_DIR)s/src/doc/prose/optimization/coding_dos_and_donts.dox" />
            <FILE SOURCE="%(PACKAGE_DIR)s/src/doc/prose/optimization/coding_dos_and_donts/min_and_max.dox" />
            <FILE SOURCE="%(PACKAGE_DIR)s/src/doc/prose/optimization/coding_dos_and_donts/matrix_column_access.dox" />
        </GROUP>
    </GROUP>
    
	<GROUP TITLE="Vectorization Portability Library" NAME="g_vpl">
        <FILE SOURCE="%(PACKAGE_DIR)s/src/doc/prose/vpl/vpl.dox" />
        <FILE SOURCE="%(PACKAGE_DIR)s/src/doc/prose/vpl/vpl_header_structure.dox" />
        <FILE SOURCE="%(PACKAGE_DIR)s/src/doc/prose/vpl/endian_issues.dox" />
        <FILE SOURCE="%(PACKAGE_DIR)s/src/doc/prose/vpl/vpl_platform_information.dox" />
        <FILE SOURCE="%(PACKAGE_DIR)s/src/doc/prose/vpl/vpl_simulated_operations.dox" />
        <FILE SOURCE="%(PACKAGE_DIR)s/src/doc/prose/vpl/vpl_migration_from_internal_macros.dox" />
        <FILE SOURCE="%(PACKAGE_DIR)s/src/doc/prose/vpl/vpl_sse2_support.dox" />
    </GROUP>

	<GROUP TITLE="Structure of Array 4 (SoA4) Math" NAME="g_soa4">
        <FILE SOURCE="%(PACKAGE_DIR)s/src/doc/prose/soa4/soa4.dox" />
        <FILE SOURCE="%(PACKAGE_DIR)s/src/doc/prose/soa4/mandelbrot_example.dox" />
        <FILE SOURCE="%(PACKAGE_DIR)s/src/doc/prose/soa4/writing_soa4_code.dox" />
    </GROUP>

	<GROUP TITLE="Rationales" NAME="g_rationales">
	    <FILE SOURCE="%(PACKAGE_DIR)s/src/doc/prose/rationales.dox" />
	    <FILE SOURCE="%(PACKAGE_DIR)s/src/doc/prose/rationales/design_principles.dox" />
	    <FILE SOURCE="%(PACKAGE_DIR)s/src/doc/prose/rationales/history.dox" />
	    <FILE SOURCE="%(PACKAGE_DIR)s/src/doc/prose/rationales/unions.dox" />
		<FILE SOURCE="%(PACKAGE_DIR)s/src/doc/prose/rationales/accessors.dox" />
		<FILE SOURCE="%(PACKAGE_DIR)s/src/doc/prose/rationales/mixed_mode_math.dox" />
	</GROUP>
	
	<GROUP TITLE="Change Log" NAME="g_change_log">
		<FILE SOURCE="%(PACKAGE_DIR)s/changes.dox" />
	</GROUP>	
	
	<GROUP TITLE="Miscellaneous" NAME="g_miscellaneous">
		<FILE SOURCE="%(PACKAGE_DIR)s/src/doc/prose/miscellaneous.dox" />
		<FILE SOURCE="%(PACKAGE_DIR)s/src/doc/prose/miscellaneous/member_initializer.dox" />
		<FILE SOURCE="%(PACKAGE_DIR)s/src/doc/prose/miscellaneous/passinreg_xenon.dox" />
	</GROUP>
	

    <GROUP TITLE="Reference" NAME="g_reference">
        <FILE SOURCE="%(PACKAGE_DIR)s/src/doc/prose/reference.dox" />
        <GROUP TITLE="Miscellaneous" NAME="g_api_miscellaneous">
            <DIR SOURCE="%(PACKAGE_DIR)s/include/rw/math" >
                <FILEPATTERN>version.h</FILEPATTERN>
            </DIR>
        </GROUP>
        <GROUP TITLE="Constants" NAME="g_api_constants">
            <DIR SOURCE="%(PACKAGE_DIR)s/include/rw/math/fpu" >
                <FILEPATTERN>constants*.h</FILEPATTERN>
            </DIR>
            <DIR SOURCE="%(PACKAGE_DIR)s/include/rw/math/vpu" >
                <FILEPATTERN>constants*.h</FILEPATTERN>
            </DIR>
        </GROUP>
        <GROUP TITLE="Scalar/Trig" NAME="g_api_scalar_trig">
            <DIR SOURCE="%(PACKAGE_DIR)s/include/rw/math/fpu" >
                <FILEPATTERN>scalar*.h</FILEPATTERN>
                <FILEPATTERN>trig*.h</FILEPATTERN>
            </DIR>
            <DIR SOURCE="%(PACKAGE_DIR)s/include/rw/math/vpu" >
                <FILEPATTERN>scalar*.h</FILEPATTERN>
                <FILEPATTERN>trig*.h</FILEPATTERN>
                <FILEPATTERN>vec_float*.h</FILEPATTERN>
            </DIR>
        </GROUP>
        <GROUP TITLE="Matrices" NAME="g_api_matrices">
            <FILE SOURCE="%(PACKAGE_DIR)s/src/doc/prose/reference/matrices/projection_matrix_functions.dox" />
            <GROUP TITLE="Matrix33" NAME="g_api_matrix33">
                <DIR SOURCE="%(PACKAGE_DIR)s/include/rw/math/fpu" >
                    <FILEPATTERN>matrix33*.h</FILEPATTERN>
                </DIR>
                <DIR SOURCE="%(PACKAGE_DIR)s/include/rw/math/vpu" >
                    <FILEPATTERN>matrix33*.h</FILEPATTERN>
                </DIR>
            </GROUP>
            <GROUP TITLE="Matrix44Affine/Matrix44AffinePacked" NAME="g_api_matrix44affine">
                <DIR SOURCE="%(PACKAGE_DIR)s/include/rw/math/fpu" >
                    <FILEPATTERN>matrix44affine*.h</FILEPATTERN>
                </DIR>
                <DIR SOURCE="%(PACKAGE_DIR)s/include/rw/math/vpu" >
                    <FILEPATTERN>matrix44affine*.h</FILEPATTERN>
                </DIR>
            </GROUP>
            <GROUP TITLE="Matrix44" NAME="g_api_matrix44">
                <DIR SOURCE="%(PACKAGE_DIR)s/include/rw/math/fpu" >
                    <FILEPATTERN>matrix44*.h</FILEPATTERN>
                </DIR>
                <DIR SOURCE="%(PACKAGE_DIR)s/include/rw/math/vpu" >
                    <FILEPATTERN>matrix44*.h</FILEPATTERN>
                </DIR>
            </GROUP>
        </GROUP>
        <GROUP TITLE="Vectors" NAME="g_api_vectors">
            <GROUP TITLE="Vector2" NAME="g_api_vector2">
                <DIR SOURCE="%(PACKAGE_DIR)s/include/rw/math/fpu" >
                    <FILEPATTERN>vector2*.h</FILEPATTERN>
                </DIR>
                <DIR SOURCE="%(PACKAGE_DIR)s/include/rw/math/vpu" >
                    <FILEPATTERN>vector2*.h</FILEPATTERN>
                </DIR>
            </GROUP>
            <GROUP TITLE="Vector3/Vector3Plus" NAME="g_api_vector3">
                <DIR SOURCE="%(PACKAGE_DIR)s/include/rw/math/fpu" >
                    <FILEPATTERN>vector3*.h</FILEPATTERN>
                </DIR>
                <DIR SOURCE="%(PACKAGE_DIR)s/include/rw/math/vpu" >
                    <FILEPATTERN>vector3*.h</FILEPATTERN>
                </DIR>
            </GROUP>
            <GROUP TITLE="Vector4" NAME="g_api_vector4">
                <DIR SOURCE="%(PACKAGE_DIR)s/include/rw/math/fpu" >
                    <FILEPATTERN>vector4*.h</FILEPATTERN>
                </DIR>
                <DIR SOURCE="%(PACKAGE_DIR)s/include/rw/math/vpu" >
                    <FILEPATTERN>vector4*.h</FILEPATTERN>
                </DIR>
            </GROUP>
        </GROUP>
        <GROUP TITLE="Plane" NAME="g_api_plane">
            <DIR SOURCE="%(PACKAGE_DIR)s/include/rw/math/fpu" >
                <FILEPATTERN>plane*.h</FILEPATTERN>
            </DIR>
            <DIR SOURCE="%(PACKAGE_DIR)s/include/rw/math/vpu" >
                <FILEPATTERN>plane*.h</FILEPATTERN>
            </DIR>
        </GROUP>
        <GROUP TITLE="Mask" NAME="g_api_mask">
            <FILE SOURCE="%(PACKAGE_DIR)s/src/doc/prose/reference/masks/mask_api.dox" />
            <GROUP TITLE="MaskScalar" NAME="g_api_maskscalar">
                <DIR SOURCE="%(PACKAGE_DIR)s/include/rw/math/fpu" >
                    <FILEPATTERN>maskscalar*.h</FILEPATTERN>
                </DIR>
                <DIR SOURCE="%(PACKAGE_DIR)s/include/rw/math/vpu" >
                    <FILEPATTERN>maskscalar*.h</FILEPATTERN>
                </DIR>
            </GROUP>
            <GROUP TITLE="Mask2" NAME="g_api_mask2">
                <DIR SOURCE="%(PACKAGE_DIR)s/include/rw/math/fpu" >
                    <FILEPATTERN>mask2*.h</FILEPATTERN>
                </DIR>
                <DIR SOURCE="%(PACKAGE_DIR)s/include/rw/math/vpu" >
                    <FILEPATTERN>mask2*.h</FILEPATTERN>
                </DIR>
            </GROUP>
            <GROUP TITLE="Mask3" NAME="g_api_mask3">
                <DIR SOURCE="%(PACKAGE_DIR)s/include/rw/math/fpu" >
                    <FILEPATTERN>mask3*.h</FILEPATTERN>
                </DIR>
                <DIR SOURCE="%(PACKAGE_DIR)s/include/rw/math/vpu" >
                    <FILEPATTERN>mask3*.h</FILEPATTERN>
                </DIR>
            </GROUP>
            <GROUP TITLE="Mask4" NAME="g_api_mask4">
                <DIR SOURCE="%(PACKAGE_DIR)s/include/rw/math/fpu" >
                    <FILEPATTERN>mask4*.h</FILEPATTERN>
                </DIR>
                <DIR SOURCE="%(PACKAGE_DIR)s/include/rw/math/vpu" >
                    <FILEPATTERN>mask4*.h</FILEPATTERN>
                </DIR>
            </GROUP>
        </GROUP>
        <GROUP TITLE="Quaternions" NAME="g_api_quaternion_types">
            <GROUP TITLE="Quaternion" NAME="g_api_quaternion">
                <DIR SOURCE="%(PACKAGE_DIR)s/include/rw/math/fpu" >
                    <FILEPATTERN>quaternion*.h</FILEPATTERN>
                </DIR>
                <DIR SOURCE="%(PACKAGE_DIR)s/include/rw/math/vpu" >
                    <FILEPATTERN>quaternion*.h</FILEPATTERN>
                </DIR>
            </GROUP>
            <GROUP TITLE="QuatPos" NAME="g_api_quatpos">
                <DIR SOURCE="%(PACKAGE_DIR)s/include/rw/math/fpu" >
                    <FILEPATTERN>quatpos*.h</FILEPATTERN>
                </DIR>
                <DIR SOURCE="%(PACKAGE_DIR)s/include/rw/math/vpu" >
                    <FILEPATTERN>quatpos*.h</FILEPATTERN>
                </DIR>
            </GROUP>
            <GROUP TITLE="Sqt" NAME="g_api_sqt">
                <DIR SOURCE="%(PACKAGE_DIR)s/include/rw/math/fpu" >
                    <FILEPATTERN>sqt*.h</FILEPATTERN>
                </DIR>
                <DIR SOURCE="%(PACKAGE_DIR)s/include/rw/math/vpu" >
                    <FILEPATTERN>sqt*.h</FILEPATTERN>
                </DIR>
            </GROUP>
        </GROUP>
        <GROUP TITLE="Random Numbers" NAME="g_api_random_numbers">
            <DIR SOURCE="%(PACKAGE_DIR)s/include/rw/math/" >
                <FILEPATTERN>random.h</FILEPATTERN>
            </DIR>
        </GROUP>
        <GROUP TITLE="Structure of Arrays" NAME="g_api_soa4">
            <DIR SOURCE="%(PACKAGE_DIR)s/include/rw/math/vpu">
                <FILEPATTERN>soa4*.h</FILEPATTERN>
            </DIR>
        </GROUP>
        <GROUP TITLE="VPL" NAME="g_api_vpl">
            <!-- Hard code the path to the VPL docs for now.  It would be nice
                 if this could be provided by the build system. -->
            <DIR SOURCE="%(BUILD_DIR)s/preprocessed_docs/">
                <FILEPATTERN>*.h</FILEPATTERN>
                <FILEPATTERN>*.dox</FILEPATTERN>
            </DIR>
        </GROUP>
        <GROUP TITLE="Half Vectors" NAME="g_api_half_vectors">
            <DIR SOURCE="%(PACKAGE_DIR)s/include/rw/math/half" >
                <FILEPATTERN>half*.h</FILEPATTERN>
            </DIR>
        </GROUP>

    </GROUP>
    
</INPUTSPEC>
""" % { 'PACKAGE_DIR' : packageDir, 'BUILD_DIR' : buildDir }

outputFile=open( outputFileName, 'w' )
outputFile.write( xmlFileContents )
outputFile.close()
