MinGW Basic Makefile

Basic Makefile for MinGW

I’ve been working with the MinGW compiler and needed a basic makefile to understand how to build my C programs. Here’s a simple makefile that demonstrates how to compile and link a basic C project:

CC = gcc
CFLAGS = -Wall -g
TARGET = myprogram
SOURCES = main.c util.c

$(TARGET): $(SOURCES)
	$(CC) $(CFLAGS) -o $(TARGET) $(SOURCES)

clean:
	rm -f $(TARGET)

This makefile uses the GCC compiler (which is part of MinGW) to compile C source files and create an executable. The -Wall flag enables all warnings, and -g includes debugging information.

In practice, it’s better to have separate object files and use a more complex makefile, but this is sufficient to get started with basic projects.