# igraph/src

## Updating the C sources

1. Clean the `src/` directory:

    ```sh
    make -f Makefile-cigraph clean
    ```

2. Update the `src/` directory:

    ```sh
    make -f Makefile-cigraph
    ```

    Note that this may change files generated by `flex` and `bison`, and configure scripts, depending on the version of those tools.
    For stability, the `Makefile` uses Docker with pinned versions of those tools.

3. Review the changes, especially in `src/` and `configure`:

    ```sh
    git diff src/ configure
    ```

4. Commit and push

## Dependency Tracking System

The build system uses an automated dependency tracking mechanism to enable efficient incremental compilation.

### How It Works

1. **Dependency Generation**: When compiling C/C++ files, the compiler generates `.d` files containing all dependencies (headers) for each source file.

2. **Filtering**: The `deps.mk` makefile processes these `.d` files to create `.dd` files that:
   - Include only local project headers (not system headers)
   - Format dependencies in a Makefile-compatible format with proper line continuations
   - Add a header comment indicating they are auto-generated

3. **Integration**: The generated `.dd` files are included by the main Makefile, allowing Make to automatically recompile sources when their dependencies change.

### File Types

- **`.d` files**: Raw dependency files generated by the compiler (ignored by git via `.gitignore`)
- **`.dd` files**: Processed dependency files with only local headers (committed but need to be kept clean of system headers)

### Important Notes

- **Never commit `.d` files**: They contain machine-specific paths and are regenerated on each build
- **Never add system headers to `.dd` files**: They are for review only
- **Never edit `.dd` files**: They are automatically generated; manual edits will be overwritten
- The system is implemented in `deps.mk` and works transparently during normal builds
- For clean builds or troubleshooting, remove all `.d` files: `rm -f src/*.d`

### Implementation Details

See `src/deps.mk` for the implementation. The key steps are:

1. The compiler's `-MMD -MP` flags generate `.d` files during compilation
2. A sed-based pipeline filters and formats the dependencies
3. System headers and vendored dependencies are excluded to reduce file size
4. Dependencies are sorted for consistency
