Skip to content

Instantly share code, notes, and snippets.

@yzhong52
Forked from wenchy/Makefile
Last active June 25, 2017 15:12
Show Gist options
  • Save yzhong52/8c263f6ffe7b4d7498c31ca2f6df9a7d to your computer and use it in GitHub Desktop.
Save yzhong52/8c263f6ffe7b4d7498c31ca2f6df9a7d to your computer and use it in GitHub Desktop.
Compile all .cpp files into one target under the current directory.
CC := g++
CFLAGS := -Wall -g
TARGET := example
# $(wildcard *.cpp /xxx/xxx/*.cpp): get all .cpp files from the current directory and dir "/xxx/xxx/"
SRCS := $(wildcard *.cpp)
# $(patsubst %.cpp,%.o,$(SRCS)): substitute all ".cpp" file name strings to ".o" file name strings
OBJS := $(patsubst %.cpp,%.o,$(SRCS))
all: $(TARGET)
$(TARGET): $(OBJS)
$(CC) -o $@ $^
%.o: %.cpp
$(CC) $(CFLAGS) -c $<
run: all
./$(TARGET)
clean:
rm -rf $(TARGET) *.o
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment