Skip to content

Commit f7b3a76

Browse files
authored
[make] Recompile library when source files change (#89)
* [make] Recompile library when source files change The build has been split up into separate object files, and each object file is recompiled if the relevant source/header file changes. Previously, it would never recompile the library, regardless of whether any files had changed, so running `make clean` was necessary every time.
1 parent 660472b commit f7b3a76

2 files changed

Lines changed: 17 additions & 8 deletions

File tree

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
test/
22
*.so
33
*.dll
4+
*.o
5+
*.d

Makefile

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
SRC = src/luasimdjson.cpp src/simdjson.cpp
2-
INCLUDE = -I$(LUA_INCDIR)
3-
LIBS = -lpthread
4-
FLAGS = -std=c++11 -Wall $(LIBFLAG) $(CFLAGS)
1+
OBJ = src/luasimdjson.o src/simdjson.o
2+
CPPFLAGS = -I$(LUA_INCDIR)
3+
CXXFLAGS = -std=c++11 -Wall $(CFLAGS)
4+
LDFLAGS = $(LIBFLAG)
5+
LDLIBS = -lpthread
56

67
ifdef LUA_LIBDIR
7-
FLAGS += $(LUA_LIBDIR)/$(LUALIB)
8+
LDLIBS += $(LUA_LIBDIR)/$(LUALIB)
89
endif
910

1011
ifeq ($(OS),Windows_NT)
@@ -24,11 +25,17 @@ TARGET = simdjson.$(LIBEXT)
2425

2526
all: $(TARGET)
2627

27-
$(TARGET):
28-
$(CXX) $(SRC) $(FLAGS) $(INCLUDE) $(LIBS) -o $@
28+
DEP_FILES = $(OBJ:.o=.d)
29+
-include $(DEP_FILES)
30+
31+
%.o: %.cpp
32+
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -MMD -MP -c $< -o $@
33+
34+
$(TARGET): $(OBJ)
35+
$(CXX) $(LDFLAGS) $^ -o $@ $(LDLIBS)
2936

3037
clean:
31-
rm *.$(LIBEXT)
38+
rm -f *.$(LIBEXT) src/*.{o,d}
3239

3340
install: $(TARGET)
3441
cp $(TARGET) $(INST_LIBDIR)

0 commit comments

Comments
 (0)