Created
November 26, 2023 09:07
-
-
Save keksipurkki/c42318f7850832de43d582914c19e680 to your computer and use it in GitHub Desktop.
Makefile template
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Generic GNUMakefile | |
# Just a snippet to stop executing under other make(1) commands | |
# that won't understand these lines | |
ifneq (,) | |
This makefile requires GNU Make. | |
endif | |
PROGRAM = foo | |
C_FILES := $(wildcard *.c) | |
OBJS := $(patsubst %.c, %.o, $(C_FILES)) | |
CC = cc | |
CFLAGS = -std=c11 -Wall -pedantic | |
LDFLAGS = | |
all: $(PROGRAM) | |
$(PROGRAM): .depend $(OBJS) | |
$(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) -o $(PROGRAM) | |
depend: .depend | |
.depend: cmd = gcc -MM -MF depend $(var); cat depend >> .depend; | |
.depend: | |
@echo "Generating dependencies..." | |
@$(foreach var, $(C_FILES), $(cmd)) | |
@rm -f depend | |
-include .depend | |
# These are the pattern matching rules. In addition to the automatic | |
# variables used here, the variable $* that matches whatever % stands for | |
# can be useful in special cases. | |
%.o: %.c | |
$(CC) $(CFLAGS) -c $< -o $@ | |
%: %.c | |
$(CC) $(CFLAGS) -o $@ $< | |
clean: | |
rm -f .depend *.o | |
.PHONY: clean depend |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment