# # Makefile - Makefile of libpoly2d # # Written 2012, 2013 by Werner Almesberger # Copyright 2012, 2013 by Werner Almesberger # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public # License as published by the Free Software Foundation; either # version 2.1 of the License, or (at your option) any later version. # PREFIX ?= /usr/local SHELL = /bin/bash LIB = libpoly2d.a OBJS = v2d_intersect.o v2d_line_distance.o \ p2d_area.o p2d_area_holes.o \ p2d_attrib.o p2d_contains_point.o p2d_contains_poly.o \ p2d_copy.o p2d_free.o p2d_gnuplot.o p2d_make.o p2d_offset.o \ p2d_hsort.o f2d_tri_holes.o f2d_tri.o CFLAGS_WARN = -Wall -Wshadow -Wmissing-prototypes \ -Wmissing-declarations -Wno-format-zero-length CFLAGS = $(CFLAGS_WARN) -g -std=gnu99 CXXFLAGS = -Wall -frounding-math LDFLAGS = LDLIBS = -lm # ----- Verbosity control ----------------------------------------------------- CC_normal := $(CC) CXX_normal := $(CXX) AR_normal := $(AR) DEPEND_normal := $(CPP) $(CFLAGS) -MM -MG DEPENDXX_normal := $(CPP) $(CXXFLAGS) -MM -MG CC_quiet = @echo " CC " $@ && $(CC_normal) CXX_quiet = @echo " CXX " $@ && $(CXX_normal) AR_quiet = @echo " AR " $@ && $(AR_normal) DEPEND_quiet = @$(DEPEND_normal) DEPENDXX_quiet = @$(DEPENDXX_normal) ifeq ($(V),1) CC = $(CC_normal) CXX = $(CXX_normal) AR = $(AR_normal) DEPEND = $(DEPEND_normal) DEPENDXX = $(DEPENDXX_normal) else CC = $(CC_quiet) CXX = $(CXX_quiet) AR = $(AR_quiet) DEPEND = $(DEPEND_quiet) DEPENDXX = $(DEPENDXX_quiet) endif # ----- Rules ----------------------------------------------------------------- .PHONY: all clean spotless .PHONY: test tests valgrind all: $(LIB) $(LIB): $(OBJS) $(AR) cr $@ $^ clean: rm -f $(OBJS) $(OBJS:.o=.d) spotless: clean rm -f $(LIB) # ----- Install / uninstall --------------------------------------------------- install: all mkdir -p $(DESTDIR)/$(PREFIX)/bin/ install -m 755 $(MAIN) $(DESTDIR)/$(PREFIX)/bin/ uninstall: rm -f $(DESTDIR)/$(PREFIX)/bin/$(MAIN) # ----- Dependencies ---------------------------------------------------------- # compile and generate dependencies, from fped, based on # http://scottmcpeak.com/autodepend/autodepend.html %.o: %.c $(CC) -c $(CFLAGS) $*.c -o $*.o $(DEPEND) $*.c | \ sed -e \ '/^\(.*:\)\? */{p;s///;s/ *\\\?$$/ /;s/ */:\n/g;H;}' \ -e '$${g;p;}' -e d >$*.d; \ [ "$${PIPESTATUS[*]}" = "0 0" ] || { rm -f $*.d; exit 1; } %.o: %.cpp $(CXX) -c $(CXXFLAGS) $*.cpp -o $*.o $(DEPENDXX) $*.cpp | \ sed -e \ '/^\(.*:\)\? */{p;s///;s/ *\\\?$$/ /;s/ */:\n/g;H;}' \ -e '$${g;p;}' -e d >$*.d; \ [ "$${PIPESTATUS[*]}" = "0 0" ] || { rm -f $*.d; exit 1; } -include $(OBJS:.o=.d) # ----- Tests ----------------------------------------------------------------- test tests: all LANG= sh -c \ 'passed=0 && cd test && \ for n in [a-z]*; do \ [ $$n != core ] && SCRIPT=$$n . ./$$n; done; \ echo "Passed all $$passed tests"' valgrind: VALGRIND="valgrind -q" $(MAKE) tests