Skip to content

Instantly share code, notes, and snippets.

@CarloCattano
Last active January 21, 2024 15:59
Show Gist options
  • Save CarloCattano/1f1db247c4eb8477a365e29eaf12aaf1 to your computer and use it in GitHub Desktop.
Save CarloCattano/1f1db247c4eb8477a365e29eaf12aaf1 to your computer and use it in GitHub Desktop.
Easy way to generate documentation and call graphs that you can click to go to the definitions real quick. Useful for big projects to have a visual help

A script to generate a Doxyfile with call graphs , it needs to have installed doxygen and graphviz

Installation

Ensure you have the required dependencies installed:

# Example installation on Debian-based systems
sudo apt-get install graphviz

Usage

./makeDoxy.sh -i "main.c src" -e "libft"

Explanation

-i or --input: Specify input directories/files for Doxygen.
-e or --exclude: Specify directories/files to be excluded from Doxygen.

Generated Output

The script generates Doxygen documentation with configured settings. View the generated documentation for details on your project's structure and relationships.

#!/bin/bash

# Generate Doxygen configuration file
doxygen -g

# Replace specific lines in the Doxygen configuration file to create the call graphs
sed -i 's/HAVE_DOT\s*=\s*NO/HAVE_DOT = YES/' Doxyfile
sed -i 's/EXTRACT_ALL\s*=\s*NO/EXTRACT_ALL = YES/' Doxyfile
sed -i 's/EXTRACT_PRIVATE\s*=\s*NO/EXTRACT_PRIVATE = YES/' Doxyfile
sed -i 's/EXTRACT_STATIC\s*=\s*NO/EXTRACT_STATIC = YES/' Doxyfile
sed -i 's/CALL_GRAPH\s*=\s*NO/CALL_GRAPH = YES/' Doxyfile
sed -i 's/CALLER_GRAPH\s*=\s*NO/CALLER_GRAPH = YES/' Doxyfile
sed -i 's/DISABLE_INDEX\s*=\s*NO/DISABLE_INDEX = YES/' Doxyfile
sed -i 's/GENERATE_TREEVIEW\s*=\s*NO/GENERATE_TREEVIEW = YES/' Doxyfile
sed -i 's/RECURSIVE\s*=\s*NO/RECURSIVE = YES/' Doxyfile
sed -i 's/INLINE_SOURCES\s*=\s*NO/INLINE_SOURCES = YES/' Doxyfile

while [[ $# -gt 0 ]]
do
    case "$1" in
        -i|--input)
        INPUT="$2"
        shift 2
        ;;
        -e|--exclude)
        EXCLUDE="$2"
        shift 2
        ;;
        *)
        shift
        ;;
    esac
done

sed -i "s/INPUT\s*=\s*/INPUT = $INPUT/" Doxyfile
sed -i "s/EXCLUDE\s*=\s*/EXCLUDE = $EXCLUDE/" Doxyfile

echo " INPUT = $INPUT "
echo " EXCLUDE = $EXCLUDE "
doxygen Doxyfile

Make it executable with :

chmod +x ./doxyGraph.sh 

And thats it, after you can open the file with a browser

brave html/main_foo.html

Original idea from https://stackoverflow.com/a/68342053

20230415_13h33m53s_grim

if you write your comments in this format , Doxygen will generate a nice documentation for every function. There are more attributes that you can set and looks really good in the docs

/**
 * @brief      Description that tells what the function after this comment does
 *
 * @param[in]  ac    The argument count
 * @param      av    The argument vector (array of strings)
 *
 * @return     what does it return 
 */

20230415_13h38m44s_grim

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment