+ 21.6 Strings library, Null-terminated sequence utilities: <cctype>, <cwctype>,...
[lightlibc++.git] / Makefile
blob8e244df799a69561969a44ab81928b1f56f54d93
1 default: all
3 .PHONY: doc todo clean
5 # The shell used to execute the commands
6 SHELL:= /bin/bash
8 # Environment:
9 ifeq ($(CXX),)
10 CXX:= g++
11 endif
12 ifeq ($(AR),)
13 AR:= ar
14 endif
15 ifeq ($(STATIC_LIB),)
16 STATIC_LIB:= libc++.a
17 endif
18 ifeq ($(SHARED_LIB),)
19 SHARED_LIB:= libc++.so
20 endif
21 ifneq ($(SHARED_LIB_NAME),)
22 SHARED_LIB_NAME:= -Xlinker -h$(SHARED_LIB_NAME)
23 endif
24 # CXXFLAGS
25 ifeq ($(CXXFLAGS_SHARED),)
26 CXXFLAGS_SHARED:= -fpic
27 endif
29 # Files from the host environment
30 LIBC:= $(shell $(CXX) -print-file-name=libc.so)
31 LIBGCC:= $(shell $(CXX) -print-libgcc-file-name)
33 SRC:= $(shell [ -d source ] && find source -name "*.cpp")
34 OBJ:= $(SRC:%.cpp=%.o)
35 OBJ_SHARED:= $(SRC:%.cpp=%-shared.o)
36 DEP:= $(SRC:%.cpp=%.dep)
37 DEP_SHARED:= $(SRC:%.cpp=%-shared.dep)
38 TESTCASE_SRC:= $(shell [ -d testcase ] && find testcase -name "*.cpp")
39 TESTCASE:= $(TESTCASE_SRC:%.cpp=%)
40 TESTCASE_DEP:= $(TESTCASE_SRC:%.cpp=%.dep)
41 TESTCASE_HOST:= $(TESTCASE_SRC:%.cpp=%-host)
42 TESTCASE_HOST_DEP:= $(TESTCASE_SRC:%.cpp=%-host.dep)
43 INCLUDE:= -I include/
44 CXXFLAGS_COMMON_HOST:= -std=c++0x -Wall -Werror -Wextra -pedantic-errors
45 CXXFLAGS_COMMON:= $(CXXFLAGS_COMMON_HOST) -fno-exceptions -nostdinc++
46 CXXFLAGS:= $(CXXFLAGS) $(CXXFLAGS_COMMON) $(INCLUDE)
47 CXXFLAGS_SHARED:= $(CXXFLAGS_SHARED) $(CXXFLAGS_COMMON) $(INCLUDE)
48 CXXFLAGS_TESTCASE:= $(CXXFLAGS_COMMON) $(INCLUDE) -nodefaultlibs
49 LIBS_TESTCASE:= -Xlinker --start-group -Xlinker $(STATIC_LIB) -Xlinker $(LIBGCC) -Xlinker $(LIBC) -Xlinker --end-group
51 -include $(DEP)
52 -include $(TESTCASE_DEP) $(TESTCASE_HOST_DEP)
54 all: $(STATIC_LIB) $(SHARED_LIB)
56 testcases: $(STATIC_LIB) $(TESTCASE)
58 testcases-host: $(TESTCASE_HOST)
60 clean:
61 @rm -f $(DEP) $(DEP_SHARED) $(OBJ) $(OBJ_SHARED) $(STATIC_LIB) $(SHARED_LIB) $(TESTCASE_DEP) $(TESTCASE_HOST_DEP) $(TESTCASE) $(TESTCASE_HOST) $(TESTCASE:%=%.gcc) $(TESTCASE:%=%.out) $(TESTCASE_HOST:%=%.gcc) $(TESTCASE_HOST:%=%.out)
63 doc:
64 @rm -rf doc
65 @mkdir doc
66 @doxygen
68 todo:
69 @grep -r -H -n --exclude=Doxyfile --exclude=Makefile --exclude-dir=doc -e TODO *
71 kloc:
72 @sloccount include source testcase
74 $(OBJ): Makefile
75 @echo " C++ lightlibc++/$(@:%.o=%.cpp)"
76 @$(CXX) $(CXXFLAGS) -MMD -MF $(@:%.o=%.dep) -MT $@ -c $(@:%.o=%.cpp) -o $@
78 $(OBJ_SHARED): Makefile
79 @echo " C++ lightlibc++/$(@:%-shared.o=%.cpp)"
80 @$(CXX) $(CXXFLAGS_SHARED) -MMD -MF $(@:%.o=%.dep) -MT $@ -c $(@:%-shared.o=%.cpp) -o $@
82 $(STATIC_LIB): $(OBJ)
83 @echo " AR $@"
84 @$(AR) rc $(STATIC_LIB) $(OBJ)
86 $(SHARED_LIB): $(OBJ_SHARED)
87 @echo " C++ $@"
88 @$(CXX) -nostdlib -shared $(OBJ_SHARED) -o $@ $(SHARED_LIB_NAME) $(LIBGCC) $(LIBC)
90 $(TESTCASE): $(STATIC_LIB) Makefile
91 @( $(CXX) $(CXXFLAGS_TESTCASE) -MMD -MF $(@:%=%.dep) -MT $@ $(@:%=%.cpp) $(LIBS_TESTCASE) -o $@ 2> $(@:%=%.gcc) && ./testcase.sh $@ $@ ) || echo -e "\033[01;31mfailed to compile\033[m: $@"
93 $(TESTCASE_HOST): Makefile
94 @( $(CXX) $(CXXFLAGS_COMMON_HOST) -MMD -MF $(@:%=%.dep) -MT $@ $(@:%-host=%.cpp) -o $@ 2> $(@:%=%.gcc) && ./testcase.sh $@ $(@:%-host=%) ) || echo -e "\033[01;31mfailed to compile\033[m: $(@:%-host=%)"