-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
69 lines (57 loc) · 2.05 KB
/
Copy pathMakefile
File metadata and controls
69 lines (57 loc) · 2.05 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
CXX=c++
CXXFLAGS=-Wall -Wextra -Werror
INC=-I/mnt/c/Users/dylan/Shared/picine_cpp/libcpp
LDFLAGS=
LIB_DIR=/mnt/c/Users/dylan/Shared/picine_cpp/libcpp
LIBS=-lcpp
SRC=
OBJ=$(SRC:.cpp=.o)
OBJ := $(OBJ:.c=.o)
TARGET=picine_cpp
# If INC wasn't provided by env, add common candidate include dirs inside $(LIB_DIR)
ifeq ($(strip $(INC)),)
INC := -I$(LIB_DIR) -I$(LIB_DIR)/include -I$(LIB_DIR)/inc
endif
# If libcpp provides a single top-level header, pre-include it so declarations are available
ifeq ($(wildcard $(LIB_DIR)/libcpp.h),)
CPPFLAGS :=
else
CPPFLAGS := -include $(LIB_DIR)/libcpp.h
endif
all: $(TARGET)
$(TARGET): $(OBJ)
$(MAKE) -C $(LIB_DIR)
@# prefer linking lib object files if present, else prefer direct lib file, else fallback to -L/-l
@libobjs="$$(ls $(LIB_DIR)/*.o 2>/dev/null || true)"; \
libfile=""; \
if [ -f "$(LIB_DIR)/libcpp.a" ]; then \
libfile="$(LIB_DIR)/libcpp.a"; \
elif [ -f "$(LIB_DIR)/libcpp.so" ]; then \
libfile="$(LIB_DIR)/libcpp.so"; \
fi; \
if [ -n "$$libobjs" ]; then \
$(CXX) $(CXXFLAGS) $(CPPFLAGS) $(INC) $(OBJ) $$libobjs -o $(TARGET) $(LDFLAGS) $$libfile; \
elif [ -n "$$libfile" ]; then \
$(CXX) $(CXXFLAGS) $(CPPFLAGS) $(INC) $(OBJ) -o $(TARGET) $(LDFLAGS) $$libfile; \
else \
$(CXX) $(CXXFLAGS) $(CPPFLAGS) $(INC) $(OBJ) -o $(TARGET) -L$(LIB_DIR) $(LDFLAGS) $(LIBS); \
fi
%.o: %.cpp
$(CXX) $(CXXFLAGS) $(CPPFLAGS) $(INC) -c $< -o $@
# compile .c as C++ (project uses C sources compiled with C++ toolchain)
%.o: %.c
$(CXX) $(CXXFLAGS) $(CPPFLAGS) $(INC) -x c++ -c $< -o $@
clean:
rm -f $(OBJ)
fclean: clean
rm -f $(TARGET)
re: fclean all
genmake:
@if [ -z "$(path)" ]; then \
echo "Usage: make genmake path=your/target/dir"; \
exit 1; \
fi; \
sh "$(CURDIR)/autotools/env.sh" autotools "$(path)"
update_makefile:
find . -path './cpp_module*/ex*' -type d -not -name 'build' -not -name 'tests' -not -path '*/build/*' -not -path '*/tests/*' | sort | while read dir; do if ls "$dir"/*.cpp "$dir"/*.c 2>/dev/null | head -1 > /dev/null 2>&1; then echo "$dir"; fi; done
.PHONY: all clean fclean re genmake update_makefile