Amalgamation¶
Lexbor can be built as a single-header/single-source amalgamation for easy integration into your project without managing multiple files or dependencies.
The amalgamation combines all selected modules and their dependencies into one .h file, making it simple to drop into any C/C++ project.
Generate Amalgamation¶
Use the single.pl script from the repository root to generate an amalgamated version:
# Generate amalgamation with all modules
perl single.pl --all > lexbor_single.h
# Generate amalgamation for specific modules (dependencies are included automatically)
perl single.pl html css > lexbor_html_css_single.h
# Generate with exported symbols (for dynamic linking)
perl single.pl --with-export-symbols html > lexbor_html_single.h
# Use a specific port only
perl single.pl --port=posix html > lexbor_html_single.h
# Use multiple specific ports (comma-separated)
perl single.pl --port=windows_nt,posix html > lexbor_html_single.h
Available Options¶
Basic Options¶
Option |
Description |
|---|---|
|
Show help message |
|
Include all modules if no modules specified |
|
Specify platform port to use (default: |
|
Export symbols (for building shared libraries) |
Information Options¶
Option |
Description |
|---|---|
|
Print all available modules |
|
Print detailed dependencies of specified modules |
|
Print dependency graph as a tree |
|
Print statistics about module dependencies |
|
Print reverse dependencies (which modules depend on specified ones) |
|
Print size information (lines of code, file counts) |
|
Show minimal set of dependencies |
|
Print dependencies for specified modules (space-separated, sorted) |
|
With |
|
Print version information for modules |
|
Print Lexbor version |
Validation Options¶
Option |
Description |
|---|---|
|
Check for cyclic dependencies |
|
Validate that all dependencies exist |
|
Compare dependencies between two modules |
Export Options¶
Option |
Description |
|---|---|
|
Export dependency graph in DOT format (Graphviz) |
|
Export dependency structure to JSON |
|
Export dependency structure to YAML |
Ports¶
Ports contain platform-specific code (e.g., posix, windows_nt). By default (--port=all), the script automatically discovers all available ports from source/lexbor/ports/ and includes them all in the amalgamation.
When multiple ports are included, their platform-specific code is wrapped in preprocessor conditionals (#if/#elif/#else), so the correct implementation is selected at compile time based on the target platform. For example:
#if defined(_WIN32) /* Port: windows_nt */
// ... Windows-specific code ...
#else /* Port: posix (fallback) */
// ... POSIX-specific code ...
#endif
Each port has a port.conf file that defines its preprocessor condition. Ports without a condition (or with fallback = true) serve as the default fallback in the #else branch.
This means you do not need to worry about selecting the right port — by default the generated file will work on all supported platforms. If you want to generate a file for a specific platform only, use the --port option:
# Only POSIX (no preprocessor conditionals for ports)
perl single.pl --port=posix html > lexbor_html_single.h
# Only Windows
perl single.pl --port=windows_nt html > lexbor_html_single.h
# Explicit multi-port (same as default --port=all)
perl single.pl --port=windows_nt,posix html > lexbor_html_single.h
Usage Example¶
Generate the amalgamation file with the HTML module:
perl single.pl html > lexbor_html_single.h
Then include the generated file in your project:
#include "lexbor_html_single.h"
int
main(void)
{
lxb_html_document_t *document;
lxb_status_t status;
const lxb_char_t html[] = "<div>Hello!</div>";
document = lxb_html_document_create();
if (document == NULL) {
return EXIT_FAILURE;
}
status = lxb_html_document_parse(document, (const lxb_char_t *) html,
sizeof(html) - 1);
if (status != LXB_STATUS_OK) {
return EXIT_FAILURE;
}
lxb_html_document_destroy(document);
return EXIT_SUCCESS;
}
Compile without any additional dependencies:
gcc -o myapp myapp.c