Skip to content

Instantly share code, notes, and snippets.

@loadletter
Created November 28, 2014 23:48
Show Gist options
  • Save loadletter/626215517424fcf54939 to your computer and use it in GitHub Desktop.
Save loadletter/626215517424fcf54939 to your computer and use it in GitHub Desktop.
Generic makefile for small c programs
# ?= declare if not already defined
CC ?= gcc
CFLAGS ?= -Wall -O2 -march=native
#LDLIBS = -lcrypt -lssl
# output executable name and file extensions
EXEC = run
SOURCES = $(wildcard *.c)
OBJECTS = $(SOURCES:.c=.o)
all: $(EXEC)
debug: CFLAGS = -Wall -g
debug: clean
debug: $(EXEC)
# Main target
$(EXEC): $(OBJECTS)
$(CC) $(LDLIBS) $(OBJECTS) -o $(EXEC)
# Object files
%.o: %.cpp
$(CC) -c $(CFLAGS) $< -o $@
clean:
rm -f $(EXEC) $(OBJECTS)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment