3 .PHONY: build all install installsrc installhdrs test check Makefile testexcldebug
8 HFILES := $(shell find $(TESTDIRS) -type f -name \*.h -print)
9 ALL_CFILES := $(shell find $(TESTDIRS) -type f -name \*.c -print)
10 ALL_CXXFILES := $(shell find $(TESTDIRS) -type f -name \*.cpp -print)
11 ALL_MFILES := $(shell find $(TESTDIRS) -type f -name \*.m -print)
12 SHFILES := $(shell find $(TESTDIRS) -type f -name \*.sh -print)
13 TFILES := $(shell find $(TESTDIRS) -type f -name \*.t -print)
16 CTESTS := $(shell grep -l 'main[ \t]*$(PAREN)' $(ALL_CFILES) /dev/null)
17 CXXTESTS := $(shell grep -l 'main[ \t]*$(PAREN)' $(ALL_CXXFILES) /dev/null)
18 MTESTS := $(shell grep -l 'main[ \t]*$(PAREN)' $(ALL_MFILES) /dev/null)
21 EXCLSTR := NO_AUTOMATED_TESTING
22 EXCL_CTESTS := $(shell grep -l $(EXCLSTR) $(CTESTS) /dev/null)
23 EXCL_CXXTESTS := $(shell grep -l $(EXCLSTR) $(CXXTESTS) /dev/null)
24 EXCL_MTESTS := $(shell grep -l $(EXCLSTR) $(MTESTS) /dev/null)
25 EXCL_SHTESTS := $(shell grep -l $(EXCLSTR) $(SHTESTS) /dev/null)
26 EXCL_TESTS := $(EXCL_CTESTS) $(EXCL_CXXTESTS) $(EXCL_MTESTS) $(EXCL_SHTESTS)
28 CFILES = $(filter-out $(CTESTS),$(ALL_CFILES))
29 CXXFILES = $(filter-out $(CXXTESTS),$(ALL_CXXFILES))
30 MFILES = $(filter-out $(MTESTS),$(ALL_MFILES))
32 BUILT_PRODUCTS_DIR ?= $(shell echo $(LOCAL_BUILD_DIR))
33 ifeq "" "$(BUILT_PRODUCTS_DIR)"
34 BUILT_PRODUCTS_DIR = $(SYMROOT)
35 ifeq "" "$(BUILT_PRODUCTS_DIR)"
36 BUILT_PRODUCTS_DIR = build
39 SYMROOT ?= $(BUILT_PRODUCTS_DIR)
40 OBJROOT ?= $(BUILT_PRODUCTS_DIR)/intermediates/$(PRODUCT).build
41 SRCROOT ?= $(shell /bin/pwd)
44 INSTALLDIR := $(DSTROOT)/usr/local/bin
46 SRCFILES := Makefile $(HFILES) $(CTESTS) $(CFILES) $(CXXTESTS) $(CXXFILES) $(MTESTS) $(MFILES)
48 BUILT_CTARGETS := $(addprefix $(BUILT_PRODUCTS_DIR)/,$(notdir $(basename $(CTESTS))))
49 BUILT_CXXTARGETS := $(addprefix $(BUILT_PRODUCTS_DIR)/,$(notdir $(basename $(CXXTESTS))))
50 BUILT_MTARGETS := $(addprefix $(BUILT_PRODUCTS_DIR)/,$(notdir $(basename $(MTESTS))))
51 BUILT_TARGETS := $(BUILT_CTARGETS) $(BUILT_CXXTARGETS) $(BUILT_MTARGETS)
52 EXCL_TARGETS := $(addprefix $(BUILT_PRODUCTS_DIR)/, $(notdir $(basename $(EXCL_TESTS))))
53 TEST_TARGETS := $(filter-out $(EXCL_TARGETS),$(BUILT_TARGETS))
55 COFILES := $(addprefix $(OBJROOT)/,$(addsuffix .o, $(basename $(CFILES))))
56 CXXOFILES := $(addprefix $(OBJROOT)/,$(addsuffix .o, $(basename $(CXXFILES))))
57 MOFILES := $(addprefix $(OBJROOT)/,$(addsuffix .o, $(basename $(MFILES))))
58 OFILES := $(COFILES) $(CXXOFILES) $(MOFILES)
60 TEST_COFILES := $(addprefix $(OBJROOT)/,$(addsuffix .o, $(basename $(CTESTS))))
61 TEST_CXXOFILES := $(addprefix $(OBJROOT)/,$(addsuffix .o, $(basename $(CXXTESTS))))
62 TEST_MOFILES := $(addprefix $(OBJROOT)/,$(addsuffix .o, $(basename $(MTESTS))))
63 TEST_OFILES := $(TEST_COFILES) $(TEST_CXXOFILES) $(TEST_MOFILES)
65 OBJDIRS := $(sort $(OBJROOT) $(dir $(OFILES) $(TEST_OFILES)))
68 # Assume final load with cc, not ld
71 C_FRAMEWORK_SEARCH_PATHS = $(BUILT_PRODUCTS_DIR)
72 CPP_FRAMEWORK_SEARCH_PATHS = $(BUILT_PRODUCTS_DIR) \
73 /System/Library/PrivateFrameworks /usr/local/SecurityPieces/Frameworks
74 M_FRAMEWORK_SEARCH_PATHS = $(BUILT_PRODUCTS_DIR) \
75 /System/Library/PrivateFrameworks
76 STD_HEADER_SEARCH_PATHS = $(SRCROOT)/test
77 STD_LIBARY_SEARCH_PATHS = $(BUILT_PRODUCTS_DIR)
79 ALL_HEADER_SEARCH_PATHS = $(HEADER_SEARCH_PATHS) $(STD_HEADER_SEARCH_PATHS)
80 ALL_LIBARY_SEARCH_PATHS = $(LIBARY_SEARCH_PATHS) $(STD_LIBARY_SEARCH_PATHS)
83 ALL_LIBRARIES = $(STD_LIBRARIES) $(LIBRARIES:lib%.a=%)
85 C_FRAMEWORKS = Security CoreFoundation
86 CPP_FRAMEWORKS = $(C_FRAMEWORKS) #security_utilities
87 M_FRAMEWORKS = $(C_FRAMEWORKS) SecurityFoundation Foundation
89 C_FINCLUDES = $(addprefix -F,$(C_FRAMEWORK_SEARCH_PATHS) \
90 $(FRAMEWORK_SEARCH_PATHS))
91 CPP_FINCLUDES = $(addprefix -F,$(CPP_FRAMEWORK_SEARCH_PATHS) \
92 $(FRAMEWORK_SEARCH_PATHS))
93 M_FINCLUDES = $(addprefix -F,$(M_FRAMEWORK_SEARCH_PATHS) \
94 $(FRAMEWORK_SEARCH_PATHS))
95 ALL_INCLUDES = $(addprefix -I,$(ALL_HEADER_SEARCH_PATHS))
98 # Override this from the make command line to add e.g. -lMallocDebug
103 C_LDFLAGS = $(CMDLINE_LDFLAGS) \
105 $(addprefix -framework ,$(C_FRAMEWORKS) $(FRAMEWORKS)) \
106 $(addprefix -L,$(ALL_LIBARY_SEARCH_PATHS)) \
107 $(addprefix -l,$(ALL_LIBARIES)) \
109 CPP_LDFLAGS = $(CMDLINE_LDFLAGS) \
111 $(addprefix -framework ,$(CPP_FRAMEWORKS) $(FRAMEWORKS)) \
112 $(addprefix -L,$(ALL_LIBARY_SEARCH_PATHS)) \
113 $(addprefix -l,$(ALL_LIBARIES)) \
114 $(OTHER_LDFLAGS) /usr/local/lib/libsecurity_utilities.a
115 M_LDFLAGS = $(CMDLINE_LDFLAGS) \
117 $(addprefix -framework ,$(M_FRAMEWORKS) $(FRAMEWORKS)) \
118 $(addprefix -L,$(ALL_LIBARY_SEARCH_PATHS)) \
119 $(addprefix -l,$(ALL_LIBARIES)) \
122 ###WARNING_CFLAGS = -Wno-four-char-constants -Wall -Werror
123 WARNING_CFLAGS = -Wno-four-char-constants -Wall -Wno-deprecated-declarations
127 ALL_CFLAGS = $(C_FINCLUDES) $(ALL_INCLUDES) $(STD_CFLAGS) \
128 $(WARNING_CFLAGS) $(OTHER_CFLAGS) $(DEBUG_CFLAGS)
129 ALL_CXXFLAGS = $(CPP_FINCLUDES) $(ALL_INCLUDES) $(STD_CFLAGS) \
130 $(WARNING_CFLAGS) $(OTHER_CXXFLAGS) $(DEBUG_CFLAGS)
131 ALL_MFLAGS = $(M_FINCLUDES) $(ALL_INCLUDES) $(STD_CFLAGS) \
132 $(WARNING_CFLAGS) $(OTHER_CFLAGS) $(DEBUG_CFLAGS)
134 build: $(OTHER_DEPENDENCIES) $(OBJDIRS) $(BUILT_TARGETS)
139 make CMDLINE_LDFLAGS="-arch ppc64" DEBUG_CFLAGS="-arch ppc64"
142 install -d -m 0755 $(INSTALLDIR)
143 install -p -m 0755 $(BUILT_TARGETS) $(INSTALLDIR)
151 rm -f $(BUILT_TARGETS) $(OFILES) $(TEST_OFILES) $(OTHER_TO_CLEAN)
152 # echo rm -rf $(OBJDIRS)
155 @perl -Iinc -e 'use MyHarness; Test::Harness::runtests @ARGV;' $(sort $(TEST_TARGETS)) $(sort $(TFILES))
158 @echo EXCL_CTESTS: $(EXCL_CTESTS)
159 @echo EXCL_CXXTESTS: $(EXCL_CXXTESTS)
160 @echo EXCL_MTESTS: $(EXCL_MTESTS)
161 @echo EXCL_SHTESTS: $(EXCL_SHTESTS)
162 @echo EXCL_TESTS: $(EXCL_TESTS)
163 @echo BUILT_TARGETS: $(BUILT_TARGETS)
164 @echo TEST_TARGETS: $(TEST_TARGETS)
166 LOCAL_OFILES := $(addsuffix .o, $(basename $(CFILES) $(CXXFILES) $(MFILES)))
167 OFILES := $(LOCAL_OFILES:%=$(OBJROOT)/%)
169 $(BUILT_CTARGETS): $(COFILES) $(TEST_COFILES)
170 $(CC) -o $@ $(filter %/$(notdir $@).o,$(TEST_COFILES)) $(OFILES) $(C_LDFLAGS)
172 $(BUILT_CXXTARGETS): $(COFILES) $(CXXOFILES) $(TEST_CXXOFILES)
173 $(CXX) -o $@ $(filter %/$(notdir $@).o,$(TEST_CXXOFILES)) $(OFILES) $(CPP_LDFLAGS)
175 $(BUILT_MTARGETS): $(COFILES) $(MOFILES) $(TEST_MOFILES)
176 $(CC) -o $@ $(filter %/$(notdir $@).o,$(TEST_MOFILES)) $(OFILES) $(M_LDFLAGS)
182 $(CC) $(ALL_CFLAGS) -c -o $(OBJROOT)/$*.o $<
184 $(OBJROOT)/%.o: %.cpp
185 $(CXX) $(ALL_CXXFLAGS) -c -o $(OBJROOT)/$*.o $<
188 $(CC) $(ALL_MFLAGS) -c -o $(OBJROOT)/$*.o $<
190 $(OFILES) $(TEST_OFILES): $(HFILES)