.. _Writing Config: How to Write a Build Config *************************** This page walks through the process of writing a build script. Config File =========== Here's a simple config without any steps. .. code-block:: :linenos: :caption: build_it.py #!/usr/bin/env python3 from fab.build_config import BuildConfig with BuildConfig(project_label='') as state: pass If we want to run the build script from the command line, we give it executable permission with the command `chmod +x build_it.py`. We also add the `shebang `_ directive on line 1, telling our computer it's a Python script. Pick a project label. Fab creates a project workspace with this name (see :term:`Project Workspace`). Source Code =========== Let's tell Fab where our source code is. We use the :func:`~fab.steps.find_source_files.find_source_files` step for this. We can point this step to a source folder, which is a valid way to use this step. However, because Fab can sometimes create artefacts alongside the source [1]_, we usually copy the source into the project workspace first using a :mod:`~fab.steps.grab` step. A grab step will copy files from a folder or remote repo into a folder called "source" within the project workspace. .. code-block:: :linenos: :caption: build_it.py :emphasize-lines: 4,5,10,11 #!/usr/bin/env python3 from fab.build_config import BuildConfig from fab.steps.find_source_files import find_source_files from fab.steps.grab import GrabFolder if __name__ == '__main__': with BuildConfig(project_label='` environment variable to determine which tool to call. .. code-block:: :linenos: :caption: build_it.py :emphasize-lines: 6,13 #!/usr/bin/env python3 import logging from fab.build_config import BuildConfig from fab.steps.find_source_files import find_source_files from fab.steps.preprocess import preprocess_fortran logger = logging.getLogger('fab') if __name__ == '__main__': with BuildConfig(project_label='`. C Code ====== Fab comes with C processing steps. The :func:`~fab.steps.preprocess.preprocess_c` and :func:`~fab.steps.compile_c.compile_c` Steps behave like their Fortran equivalents. However, it currently requires a preceding step called the :func:`~fab.steps.c_pragma_injector.c_pragma_injector`. Fab needs to inject pragmas into C code before it is preprocessed in order to know which dependencies are for user code, and which are for system code to be ignored. See also :ref:`Advanced C Code` Further Reading =============== More advanced config topics are discussed in :ref:`Advanced Config`. You can see more complicated configs in Fab's `example run configs `_.