Last active
May 8, 2017 09:41
-
-
Save etam/3d19fcc6ce389390be77a763f60a3c96 to your computer and use it in GitHub Desktop.
Makefile for a single binary with mixed C and C++ sources
This file contains 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
CC := gcc | |
CXX := g++ | |
CPPFLAGS := | |
CFLAGS := -std=c11 -O2 -Wall -Wextra | |
CXXFLAGS := -std=c++14 -O2 -Wall -Wextra | |
LDFLAGS := | |
LDLIBS := -lstdc++ | |
COBJS := | |
CXXOBJS := main.o | |
OBJS := $(COBJS) $(CXXOBJS) | |
EXE := main | |
all: $(EXE) | |
$(EXE): $(OBJS) | |
CDEPS := $(COBJS:.o=.d) | |
CXXDEPS := $(CXXOBJS:.o=.d) | |
DEPS := $(CDEPS) $(CXXDEPS) | |
$(CDEPS): %.d: %.c | |
@set -e; rm -f $@; \ | |
DIR=`dirname $<`; \ | |
$(CC) -MM $(CFLAGS) $(CPPFLAGS) $< | \ | |
sed "s,^\(.*\)\.o:,$$DIR/\1.d $$DIR/\1.o:," > $@ | |
$(CXXDEPS): %.d: %.cpp | |
@set -e; rm -f $@; \ | |
DIR=`dirname $<`; \ | |
$(CXX) -MM $(CXXFLAGS) $(CPPFLAGS) $< | \ | |
sed "s,^\(.*\)\.o:,$$DIR/\1.d $$DIR/\1.o:," > $@ | |
ifneq ($(MAKECMDGOALS),clean) | |
-include $(DEPS) | |
endif | |
clean: | |
$(RM) $(EXE) $(OBJS) $(DEPS) | |
.PHONY: all clean |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment