Skip to content

Instantly share code, notes, and snippets.

@collinprice
Created July 26, 2013 20:51
Show Gist options
  • Save collinprice/6092141 to your computer and use it in GitHub Desktop.
Save collinprice/6092141 to your computer and use it in GitHub Desktop.
Generic C++ Makefile that needs to include C sources.
CC = gcc
CXX = g++
CXXFLAGS = -c -Wall -Wextra -pedantic
CCFLAGS = -c
LDFLAGS = -lpthread
CPP_SRC = main.cpp
CPP_SRC_OBJS = $(CPP_SRC:.cpp=.o)
CC_SRC = lib.c
CC_SRC_OBJS = $(CC_SRC:.c=.o)
EXECUTABLE = main
all: $(SOURCES) $(EXECUTABLE)
$(EXECUTABLE): $(CPP_SRC_OBJS) $(CC_SRC_OBJS)
$(CXX) $(CPP_SRC_OBJS) $(CC_SRC_OBJS) -o $@ $(LDFLAGS)
.cpp.o:
$(CXX) $(CXXFLAGS) $< -o $@
.c.o:
$(CC) $(CCFLAGS) $< -o $@
clean:
rm -rf $(CPP_SRC_OBJS) $(CC_SRC_OBJS) $(EXECUTABLE)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment