Remove Includes Transformation
The Remove Includes Transformation removes all non-standard include directives from a C source file and replaces them with the corresponding declarations directly within the file. The result is a self-contained .c
file that can be compiled independently of external headers.
This transformation effectively performs a header-flattening step that normally occurs during preprocessing in a compiler’s build pipeline. However, instead of producing a preprocessed file, it inserts only the relevant declarations (e.g., function prototypes, structs, macros) in a clean and readable format.
Remove Includes Transformation in emmtrix Studio
The RemoveIncludes transformation in emmtrix Studio resolves and eliminates all non-standard includes from a source file. It can be invoked via #pragma EMX_TRANSFORMATION_GLOBAL RemoveIncludes
or through the graphical user interface.
The transformation extracts all declarations from the included header files and inserts them directly into the C source file, replacing the corresponding #include
directives. System includes such as <stdio.h>
or <stdlib.h>
are left untouched.
After applying this transformation, the resulting .c
file is fully self-contained and can be compiled without any external include files.
Purpose
This transformation is useful when:
- creating standalone compilable files, e.g., for testing, simulation, or external distribution
- analyzing or debugging code where include chains introduce complexity
- preparing code for environments without access to full header hierarchies
- exporting generated code for toolchain-agnostic or embedded workflows
Example
#include "my_driver.h"
#include "board_cfg.h"
int main(void) {
init_driver();
return 0;
}
|
/* auto-generated by RemoveIncludes Transformation */
void init_driver(void);
int main(void) {
init_driver();
return 0;
}
|
Parameters
Parameter | Default | Description | |
---|---|---|---|
Currently, no parameters |
Limitations
- The transformation does not take system includes (e.g.,
<stdio.h>
,<math.h>
) into account, although that might be changed in the future. - Static functions or internal declarations that are not exposed in headers will not be visible
- Header guards, conditional compilation logic or complex macro definitions are not always fully preserved