change makefile and ignore .o file
authorPeng Li <seudut@gmail.com>
Mon, 9 Jul 2018 16:01:00 +0000 (00:01 +0800)
committerPeng Li <seudut@gmail.com>
Mon, 9 Jul 2018 16:01:00 +0000 (00:01 +0800)
.gitignore [new file with mode: 0644]
Makefile

diff --git a/.gitignore b/.gitignore
new file mode 100644 (file)
index 0000000..4fc836e
--- /dev/null
@@ -0,0 +1,2 @@
+src/*.o
+*.o
index 47cf62e..cfc680f 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,7 +1,18 @@
-CC = g++
-CFLAGS += -Wall -std=c++11
+CC := g++
+CFLAGS := -Wall -std=c++11
+CPPLAGS += -Wall -std=c++11
+CXXLAGS += -Wall -std=c++11
 
-SRC = src/*.cpp main.cpp
+SRC := $(wildcard src/*.cpp *.cpp)
+OBJS := $(patsubst %.cpp,%.o, $(SRC))
 
-all:
-       $(CC) $(CFLAGS) -o main $(SRC) -llog4cpp
+.PHONY: all clean
+all:$(OBJS)
+       $(CC) $(CFLAGS) -o main $(OBJS) -llog4cpp
+
+$(OBJS):%.o:%.cpp
+       $(CC) -c $(CFLAGS) $< -o $@
+
+
+clean:
+       rm -rf $(OBJS) main