#
# Makefile - Makefile of solidify
#
# Written 2010, 2014 by Werner Almesberger
# Copyright 2010, 2014 by Werner Almesberger
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#

SHELL = /bin/bash

OBJS = array.o face.o gui_util.o histo.o level.o matrix.o overlap.o povray.o \
       project.o solidify.o style.o

CFLAGS_WARN = -Wall -Wshadow -Wmissing-prototypes \
	      -Wmissing-declarations -Wno-format-zero-length

CFLAGS = $(CFLAGS_WARN) -g -O9 `pkg-config --cflags gtk+-2.0`
LDFLAGS =
LDLIBS = -lm `pkg-config --libs gtk+-2.0`

# ----- Verbosity control -----------------------------------------------------

CC_normal	:= $(CC)
DEPEND_normal	:= $(CPP) $(CFLAGS) -MM -MG

CC_quiet	= @echo "  CC       " $@ && $(CC_normal)
DEPEND_quiet	= @$(DEPEND_normal)

ifeq ($(V),1)
    CC		= $(CC_normal)
    DEPEND	= $(DEPEND_normal)
else
    CC		= $(CC_quiet)
    DEPEND	= $(DEPEND_quiet)
endif

# ----- Rules -----------------------------------------------------------------

.PHONY:		all clean spotless

all:		solidify

solidify:	$(OBJS)

clean:
		rm -f $(OBJS) $(OBJS:.o=.d)

spotless:	clean
		rm -f solidify

# ----- Experimental execution ------------------------------------------------

NAME=baseframe
TOP=top
BOTTOM=bottom
D=0.86

PRJ=http://projects.qi-hardware.com/index.php/p/ben-scans/source/tree/master
DIR=$(PRJ)/data/csv
FACE_A=$(DIR)/ben-$(NAME)-$(TOP)-100um.txt.bz2
FACE_B=$(DIR)/ben-$(NAME)-$(BOTTOM)-100um.txt.bz2


.PHONY:		new run pov disp

new:		solidify
		rm -f $(NAME).sfy
		./solidify $(NAME).sfy $(FACE_A) $(FACE_B) $(D)

run:		solidify
		./solidify $(NAME).sfy

pov:		$(NAME).pov $(NAME).inc
		povray +A +P -W1280 -H900 $(NAME).pov

disp:
		display $(NAME).png

$(NAME).pov:	template.pov
		sed 's/NAME/$(NAME)/' template.pov >$@ || { rm -f $@; exit 1; }

$(NAME).inc:	$(NAME).sfy
		./solidify -p $<

# ----- 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; }

-include $(OBJS:.o=.d)