For the common case of a C project with no parser or scanner generation, the framework requires only a few declarations: the program name, its source directory, and the closingDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/fernandodanielmaqueda/gcc-bison-flex-GNUmakefile/llms.txt
Use this file to discover all available pages before exploring further.
MKFWK_FOOTER expansion. Everything else — object files, dependency tracking, the bin/ and obj/ output directories — is handled automatically.
When to use this approach
Use a pure-C setup when your project contains only.c and .h files. There is no need to involve Bison or Flex variables unless .y or .l source files are present. The framework will discover your .c files, compile each to obj/, and link the final binary into bin/.
Project layout
After runningmake all for the first time, the framework creates the directories it needs. A typical project looks like this:
The
bin/ and obj/ directories are set by BINDIR and OBJDIR in main.mk. You can override them before the MKFWK_FOOTER expansion if you need a different layout.Setting up the GNUmakefile
Copy the framework into your project
Place the
mkframework/ directory at the root of your project, next to your GNUmakefile:Include main.mk
The first line of your This line must come before any program declarations.
GNUmakefile includes the framework header. The conditional handles the case where the framework path is overridden via the MKFWK_MAIN_MAKEFILE environment variable:Declare your program
Use a local variable to hold the program basename, then add it to
BIN_PROGRAMS:BIN_PROGRAMS is a space-separated list. You can add more programs later by appending additional basenames.Set the source directory and discover sources
Point the program’s
_SRCDIR to the directory containing your .c files, then use the framework’s FIND command to discover them:_SOURCES is the list of source files to compile. _LDADD controls the linking order — for a simple program it mirrors _SOURCES, but you can reorder or add library flags here.Configure include and library paths
The framework can auto-discover This produces
-I and -L flags from your source tree. For a pure-C project the header search usually points at the same directory as your sources:-I'src/' (or whichever subdirectories contain .h files) and appends them to the per-program _CPPFLAGS.Set per-program flags (optional)
You can set preprocessor, compiler, assembler, and linker flags per program. These are merged with the global
CPPFLAGS, CFLAGS, ASFLAGS, and LDFLAGS when the binary is built:Set run arguments and working directory (optional)
The
_ARGS variable passes command-line arguments when you use make run-myprogram. _CWD sets the working directory the program is launched from:Complete annotated GNUmakefile
Here is the full template for a single-program pure-C project, based directly on the upstreamGNUmakefile:
Minimal src/main.c example
Building and running
What VERBOSE output looks like
WithVERBOSE=X (the default), each build step is surrounded by angle-bracket markers:
VERBOSE on the command line:
Common build adjustments
Disable debug symbols, enable optimization
CC_DEBUG=X is on by default, which passes -g3 and -DDEBUG=1 to the compiler. Turn it off and add -O2:
CFLAGS permanently in your GNUmakefile after the include line:
Preview what would be rebuilt
SetMUST_MAKE=X to print which targets are out of date without actually building them:
Adding -I include paths manually
The_FIND_-I_FLAGS mechanism auto-generates paths from header locations, but you can also add paths directly:
_FIND_-I_FLAGS assignment so it is appended rather than overwriting the auto-discovered flags.
Next steps
Bison and Flex project
Add a parser and scanner to your project.
Libraries
Build and link static or shared libraries.
Multi-program project
Declare multiple programs in a single GNUmakefile.
Build targets reference
All available make targets for building.