# Basic compilation rules for libdarwintest using tests # # Makefile.common should be included before including this file. # # This will automatically compile all *.c and *.m files. Tests that are # multi-file should be placed in their own directory so that they are ignored # by the default rules. # # Custom rules can then be written and the target defined in OTHER_TARGETS # before this file is included to avoid them being compiled by the default # rules. # # If TARGETS is defined prior to this file being included, only the # targets listed there will be compiled. # # The values of OTHER_CFLAGS and OTHER_LDFLAGS will be used when building the # tests. VPATH = $(SRCROOT):$(OBJROOT):$(SYMROOT):$(DSTROOT) SOURCES_c := $(notdir $(wildcard $(SRCROOT)/*.c)) SOURCES_m := $(notdir $(wildcard $(SRCROOT)/*.m)) ifndef TARGETS TARGETS_c := $(filter-out $(OTHER_TARGETS),$(patsubst %.c,%,$(SOURCES_c))) TARGETS_m := $(filter-out $(OTHER_TARGETS),$(patsubst %.m,%,$(SOURCES_m))) TARGETS := $(TARGETS_c) $(TARGETS_m) $(OTHER_TARGETS) else TARGETS_c := $(filter-out $(OTHER_TARGETS),$(filter $(TARGETS),$(patsubst %.c,%,$(SOURCES_c)))) TARGETS_m := $(filter-out $(OTHER_TARGETS),$(filter $(TARGETS),$(patsubst %.m,%,$(SOURCES_m)))) endif TESTS := $(patsubst %,test-%,$(TARGETS)) # We currently don't support libdarwintest in the simulator ifeq ($(Simulator),YES) TARGETS := TESTS := endif all: $(TARGETS) % :: %.c $(CC) $(OTHER_CFLAGS) $(CFLAGS) $(OTHER_LDFLAGS) $(LDFLAGS) $< -o $(SYMROOT)/$@ % :: %.m $(CC) $(OTHER_CFLAGS) $(CFLAGS) $(OTHER_LDFLAGS) $(LDFLAGS) $(OBJCFLAGS) $< -o $(SYMROOT)/$@ $(TARGETS_c): % : %.c $(CC) $(DT_CFLAGS) $(OTHER_CFLAGS) $(CFLAGS) $(DT_LDFLAGS) $(OTHER_LDFLAGS) $(LDFLAGS) $< -o $(SYMROOT)/$@ $(TARGETS_m): % : %.m $(CC) $(DT_CFLAGS) $(OTHER_CFLAGS) $(CFLAGS) $(DT_LDFLAGS) $(OTHER_LDFLAGS) $(LDFLAGS) $(OBJCFLAGS) $< -o $(SYMROOT)/$@ installhdrs: install: all bats.plist ifneq ($(TARGETS),) mkdir -p $(INSTALLDIR) cp $(patsubst %,$(SYMROOT)/%,$(TARGETS)) $(INSTALLDIR)/ mkdir -p $(DSTROOT)/AppleInternal/CoreOS/BATS/unit_tests cp $(SYMROOT)/bats.plist $(DSTROOT)/AppleInternal/CoreOS/BATS/unit_tests/$(PROJECT).plist endif clean: rm -rf $(wildcard $(OBJROOT)/*) $(wildcard $(SYMROOT)/*) define _bats_plist_generation_script BEGIN { print "" print "" print "" print "" print " BATSConfigVersion" print " 0.1.0" print " Project" print " $(PROJECT)" print " Timeout" print " 300 " print " Tests" print " " } { print " " print " TestName" print " " $$1 "" print " WorkingDirectory" print " $(INSTALLPATH)" print " Arch" print " platform-native" print " AsRoot" print " " print " Command" print " " print " ./" $$1 "" print " " print " Timeout" print " 60" print " " } END { print " " print "" print "" } endef export bats_plist_generation_script=$(_bats_plist_generation_script) bats.plist: ifneq ($(TARGETS),) @echo $(TARGETS) | tr ' ' '\n' | awk "$$bats_plist_generation_script" > $(SYMROOT)/$@ endif $(TESTS): test-%: % @$(TEST_ENV) $< @echo test: $(TESTS) .PHONY: all test clean install bats.plist $(TESTS)