Skip to content

Instantly share code, notes, and snippets.

@stevestock
Last active April 6, 2018 20:26
Show Gist options
  • Save stevestock/2b0192783d34b05e7b9fcda42a607dc8 to your computer and use it in GitHub Desktop.
Save stevestock/2b0192783d34b05e7b9fcda42a607dc8 to your computer and use it in GitHub Desktop.
Makefile Example
# from: https://pastebin.com/raw/g8QqfMTT
# discussion: https://www.reddit.com/r/programming/comments/7lqw9b/a_simple_makefile_is_a_unicorn/
# http://www.evanjones.ca/makefile-dependencies.html
# https://www.reddit.com/r/programming/comments/4nfade/easymake_a_generic_makefile_for_those_who_hate_to/
# http://make.mad-scientist.net/papers/advanced-auto-dependency-generation/#tldr
# http://nuclear.mutantstargoat.com/articles/make/
# https://spin.atomicobject.com/2016/08/26/makefile-c-projects/
SOURCES_CPP := file1cpp.cpp \
file2cpp.cpp \
SOURCES_CC := file1.c \
file2.c \
OBJDIR_CPP := $(SOURCES_CPP:%.cpp=obj/%.o)
OBJDIR_C := $(SOURCES_CC:%.c=obj/%.o)
obj/%.o: src/%.cpp
$(CPP) $(CFLAGS) -c $(INCLUDES) -o $@ $<
obj/%.o: src/%.c
$(CC) $(CFLAGS) -c $(INCLUDES) -o $@ $<
INCLUDES = -I./include/
#CPP := g++
#CC := gcc
CPP := clang++
CC := clang
CFLAGS := -MMD -MP -Wall -O3 -march=native -fno-exceptions -fno-rtti
LFLAGS := -lrt -lpthread
LIBS := -L/usr/local/lib
all: myProject
myProject: $(OBJDIR_CPP) $(OBJDIR_C)
$(CPP) $(CFLAGS) -o myProject $(OBJDIR_CPP) $(OBJDIR_C) $(LIBS) $(LFLAGS)
clean:
rm -f ./obj/*.o
rm -f ./myProject
-include $(SOURCES_CPP:%.cpp=obj/%.d)
-include $(SOURCES_CC:%.c=obj/%.d)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment