1# 2# Makefile for OpenzWave Mac OS X applications 3# Greg Satz 4 5# GNU make only 6 7# requires libudev-dev 8 9.SUFFIXES: .d .cpp .o .a 10.PHONY: default clean 11 12# 2019-10 added this test because there are path issues, hings go wrong when you try to run 13# "make" in the cpp/test subdirectory. One of the offending statements is "top_builddir ?= $(CURDIR)" 14# Needs some work to get a proper fix. 15 16ifeq ($(top_builddir),) 17 $(error Variable top_builddir is undefined, please run "make" from root of OpenzWave repository only.) 18endif 19 20COMMON_FLAGS := -std=c++11 -Wall -Wno-unknown-pragmas -Wsign-compare 21DEBUG_CFLAGS := -ggdb -DDEBUG $(CPPFLAGS) $(COMMON_FLAGS) 22RELEASE_CFLAGS := -O3 $(CPPFLAGS) $(COMMON_FLAGS) 23 24DEBUG_LDFLAGS := -g 25 26top_srcdir := $(abspath $(dir $(lastword $(MAKEFILE_LIST)))../../) 27 28#where is put the temporary library 29LIBDIR ?= $(top_builddir) 30 31INCLUDES := -I $(top_srcdir)/cpp/test/ -I $(top_srcdir)/cpp/test/include/ -I $(top_srcdir)/cpp/src -I $(top_srcdir)/cpp/tinyxml/ -I $(top_srcdir)/cpp/hidapi/hidapi/ 32OZW_LIB = $(wildcard $(LIBDIR)/*.a ) 33LIBS = $(OZW_LIB) 34 35ifneq ($(UNAME),FreeBSD) 36LIBS += -lresolv 37endif 38 39#LIBSDIR = $(abspath $(dir $(firstword $(LIBS)))) 40SOURCES := $(top_srcdir)/cpp/test/src/ $(top_srcdir)/cpp/test/ 41gtestsrc := $(notdir $(wildcard $(top_srcdir)/cpp/test/src/*.cc)) 42testsrc := $(notdir $(wildcard $(top_srcdir)/cpp/test/*.cpp)) 43VPATH := $(top_srcdir)/cpp/test/:$(top_srcdir)/cpp/test/src/ 44 45top_builddir ?= $(CURDIR) 46 47default: $(top_builddir)/gtest-main 48 49include $(top_srcdir)/cpp/build/support.mk 50 51-include $(patsubst %.cc,$(DEPDIR)/%.d,$(gtestsrc)) 52-include $(patsubst %.cpp,$(DEPDIR)/%.d,$(testsrc)) 53 54#if we are on a Mac, add these flags and libs to the compile and link phases 55ifeq ($(UNAME),Darwin) 56CFLAGS += -DDARWIN 57TARCH += -arch x86_64 58endif 59 60# Dup from main makefile, but that is not included when building here.. 61ifeq ($(UNAME),FreeBSD) 62LDFLAGS+= -lusb 63 64ifeq ($(shell test $$(uname -U) -ge 1002000; echo $$?),1) 65ifeq (,$(wildcard /usr/local/include/iconv.h)) 66$(error FreeBSD pre 10.2: Please install libiconv from ports) 67else 68CFLAGS += -I/usr/local/include 69LDFLAGS+= -L/usr/local/lib -liconv 70endif 71endif 72 73endif 74 75$(OBJDIR)/%.o : %.cc 76 @echo "Building $(notdir $@)" 77 @$(CXX) -MM $(CFLAGS) $(INCLUDES) $< > $(DEPDIR)/$*.d 78 @mv -f $(DEPDIR)/$*.d $(DEPDIR)/$*.d.tmp 79 @$(SED) -e 's|.*:|$(OBJDIR)/$*.o: $(DEPDIR)/$*.d|' < $(DEPDIR)/$*.d.tmp > $(DEPDIR)/$*.d; 80 @$(SED) -e 's/.*://' -e 's/\\$$//' < $(DEPDIR)/$*.d.tmp | fmt -1 | \ 81 $(SED) -e 's/^ *//' -e 's/$$/:/' >> $(DEPDIR)/.$*.d; 82 @rm -f $(DEPDIR)/$*.d.tmp 83 @$(CXX) $(CFLAGS) $(TARCH) $(INCLUDES) -o $@ $< 84 85$(top_builddir)/gtest-main: $(patsubst %.cc,$(OBJDIR)/%.o,$(gtestsrc)) \ 86 $(patsubst %.cpp,$(OBJDIR)/%.o,$(testsrc)) $(OZW_LIB) 87 @echo "Linking $@" 88 @$(LD) $(LDFLAGS) $(TARCH) -o $@ $+ $(LIBS) -pthread 89 90test: $(top_builddir)/gtest-main 91 $(top_builddir)/gtest-main 92 93clean: 94 @rm -rf $(DEPDIR) $(OBJDIR) $(top_builddir)/gtest-main 95 96.SUFFIXES: .d .cpp .cc .o .a 97