Skip to content

Instantly share code, notes, and snippets.

@StefanoBelli
Last active February 19, 2020 20:17
Show Gist options
  • Save StefanoBelli/c94a24c65e52dfbb18255b2443da1318 to your computer and use it in GitHub Desktop.
Save StefanoBelli/c94a24c65e52dfbb18255b2443da1318 to your computer and use it in GitHub Desktop.
Makefile C template
SHELL = /bin/bash
CC = gcc
OBJECT_FLAG = -c
CFLAGS = -O2 -pedantic -std=c99 -Wall -Wextra -Wshadow -W
LIBS = -lexample
OBJS = example.o
OUT = example
SUPPRESS_OUTPUT = > /dev/null 2>&1
all:$(OBJS)
@for OBJ in $(OBJS); do echo -e "\tLD $$OBJ"; done
@$(CC) $(OBJS) $(LIBS) -o $(OUT) && echo -e '\tELF $(OUT)'
$(OBJS): %.o: %.c
@echo -e '\tCC $<'
@$(CC) $(CFLAGS) $< $(OBJECT_FLAG) -o $@
clean:
@for OBJ in $(OBJS); do echo -e "\tRM $$OBJ"; done
@rm $(OBJS) $(SUPPRESS_OUTPUT) || echo -e "\tRM no object files"
cleanall: clean
@echo -e "\tRM $(OUT)"
@rm $(OUT) $(SUPPRESS_OUTPUT) || echo -e "\tRM no executable files"
.PHONY: all, clean, cleanall
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment