-
-
Save yzhong52/8c263f6ffe7b4d7498c31ca2f6df9a7d to your computer and use it in GitHub Desktop.
Compile all .cpp files into one target under the current directory.
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 := 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