forked from AlloSphere-Research-Group/AlloSystem
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile.buildandrun
48 lines (39 loc) · 1.76 KB
/
Makefile.buildandrun
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#RUN_INC_DIRS ?=
#RUN_SRC_DIRS ?=
RUN_DIRS += examples/ work/
VPATH += $(RUN_SRC_DIRS)
CPPFLAGS := -I$(BUILD_DIR)/include/ $(CPPFLAGS)
CPPFLAGS := $(addprefix -I, $(RUN_SRC_DIRS)) $(CPPFLAGS)
RUN_SRCS = $(wildcard $(addsuffix /*.cpp, $(RUN_SRC_DIRS)))
RUN_SRCS += $(wildcard $(addsuffix /*.cc, $(RUN_SRC_DIRS)))
RUN_SRCS += $(wildcard $(addsuffix /*.c, $(RUN_SRC_DIRS)))
# Add Objective-C++ support if using OSX
ifeq ($(PLATFORM), macosx)
RUN_SRCS += $(wildcard $(addsuffix /*.mm, $(RUN_SRC_DIRS)))
endif
RUN_OBJS = $(addsuffix .o, $(basename $(notdir $(RUN_SRCS)) ))
#RUN_OBJS := $(addsuffix .o, $(basename $(subst /,_,$(RUN_OBJS)) ))
RUN_OBJS := $(addprefix $(OBJ_DIR), $(RUN_OBJS))
# These variables are used to link to all libraries found in build/lib/
LINK_LIBS_PATH = $(wildcard $(BUILD_DIR)lib/*.$(SLIB_EXT))
LINK_LIBS_PATH += $(wildcard $(BUILD_DIR)lib/*.$(DLIB_EXT))
LINK_LIBS_FLAGS =
# Compile and run source files in examples/ folder
# For whatever reason, we need this rule so the objects don't get rm'ed by make
runobjs: $(RUN_OBJS)
# Hack to prevent circular dependencies with compile-and-run rule
.PHONY: %.hpp
%.hpp:
# FIXME: this rule should only work for .cpp and .c
EXEC_TARGETS = $(addsuffix %.cpp, $(RUN_DIRS)) $(addsuffix %.c, $(RUN_DIRS))
ifeq ($(PLATFORM), linux)
LINK_LIBS_FLAGS += $(addprefix -l :, $(notdir $(LINK_LIBS_PATH)))
endif
.PRECIOUS: $(EXEC_TARGETS)
$(EXEC_TARGETS): MY_FLAGS = $(shell test -e $(@D)/flags.txt && cat $(@D)/flags.txt)
#$(EXEC_TARGETS): MY_FLAGS += -l$(LIB_NAME)
$(EXEC_TARGETS): FORCE $(BIN_DIR) $(ALL_BUILD_DIRS) $(LIB_PATH) runobjs
$(CXX) $(CXXFLAGS) -o $(BIN_DIR)$(*F) $@ $(RUN_OBJS) $(LINK_LIBS_FLAGS) $(LINK_LIBS_PATH) $(LDFLAGS) $(subst $$(PROJECT_DIR),$(@D)/,$(MY_FLAGS))
ifneq ($(AUTORUN), 0)
@cd $(BIN_DIR) && ./$(*F)
endif