Advanced usage
==============

You can specify preprocessor macros with ``-D`` and search paths with ``-I``:

.. code-block:: bash

    fortdepend -DMACRO=42 -Isome/include/dir -o Makefile.dep

will replace instances of ``MACRO`` with ``42`` according to the usual
C99 preprocessor rules. This can be used to conditionally ``use`` some
modules or change which module is used at compile time.

Full command line arguments:

.. argparse::
   :module: fortdepend.__main__
   :func: create_argument_parser
   :prog: fortdepend

Here's a slightly more advanced example of how to use
:py:mod:`fortdepend` in your makefiles:

.. code-block:: make

    # Script to generate the dependencies
    MAKEDEPEND=/path/to/fortdepend

    # $(DEP_FILE) is a .dep file generated by fortdepend
    DEP_FILE = my_project.dep

    # Preprocessor flags
    CPPFLAGS = -DFEATURE -Iinclude/dir

    # Source files to compile
    OBJECTS = mod_file1.f90 \
              mod_file2.f90

    # Make sure everything depends on the .dep file
    all: $(actual_executable) $(DEP_FILE)

    # Make dependencies
    .PHONY: depend
    depend: $(DEP_FILE)

    # The .dep file depends on the source files, so it automatically gets updated
    # when you change your source
    $(DEP_FILE): $(OBJECTS)
        @echo "Making dependencies!"
        cd $(SRCPATH) && $(MAKEDEPEND) -w -o /path/to/$(DEP_FILE) $(CPPFLAGS) -f $(OBJECTS)

    include $(DEP_FILE)

This will automatically rebuild the dependency file if any of the
source files change. You might not like to do this if you have a lot
of files and need to preprocess them!
