#
# Makefile for the VolPack library.  If it has the name "Makefile.in"
# then it is a template for a Makefile; to generate the actual Makefile,
# run "./configure", which is a configuration script generated by the
# "autoconf" program (constructs like "@foo@" will get replaced in the
# actual Makefile).
#
# Copyright (c) 1994 The Board of Trustees of The Leland Stanford
# Junior University.  All rights reserved.
# 
# Permission to use, copy, modify and distribute this software and its
# documentation for any purpose is hereby granted without fee, provided
# that the above copyright notice and this permission notice appear in
# all copies of this software and that you do not sell the software.
# Commercial licensing is available by contacting the author.
# 
# THE SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTY OF ANY KIND,
# EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
# WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
# 
# Author:
#    Phil Lacroute
#    Computer Systems Laboratory
#    Electrical Engineering Dept.
#    Stanford University
#

# shell to use for executing make commands
SHELL =		/bin/sh

###########################################################################
# Options that can be changed by the user.
###########################################################################

# default top-level directory for installing architecture-independent files
# (include files, documentation)
prefix = 	@prefix@

# default top-level directory for installing architecture-specific files
# (binaries)
exec_prefix = 	@exec_prefix@

# directory in which to install the VolPack library
LIB_DIR = 	$(exec_prefix)/lib

# directory for include files
INCLUDE_DIR = 	$(prefix)/include

# top-level directory for manual entries
MAN_DIR = 	$(prefix)/man

# directory in which to install manual entries for library functions
MAN3_DIR = 	$(MAN_DIR)/man3

# ANSI-C prototypes: use the first line to let the #ifdef's in
# volpack.h guess if your compiler supports prototypes, use the
# second line to disable prototypes, or use the third line to
# enable prototypes
PROTO_FLAG =
#PROTO_FLAG =	-DNO_PROTOTYPE
#PROTO_FLAG =	-DANSI_C

# loop unrolling optimization: if the following line is not commented
# out then the library will be built with a special version of the
# rendering code that has been hand-optimized; use this unless your
# compiler's optimizer has trouble with procedures that have a large
# number of basic blocks
#UNROLL_FLAG = -DUNROLL_RUN_LOOP

# optional compiler flags:
#    use the first line for full optimization
#    use the second line for no optimization
# the other lines are for various levels of debugging
CCOPT_FLAGS = $(OFLAGS)
#CCOPT_FLAGS =
#CCOPT_FLAGS = -DASSERTIONS -fullwarn -g
#CCOPT_FLAGS = -DDEBUG -DASSERTIONS -fullwarn -g

# list of optional C source files to build with code specialized
# for particular shaders and resampling filters
OPT_SRCS =	vp_compAC11B.c vp_compAC31B.c vp_compAC32B.c \
		vp_compAR11B.c vp_compAR31B.c vp_compAR32B.c

# object files corresponding to COMP_SRCS
OPT_OBJS =	vp_compAC11B.o vp_compAC31B.o vp_compAC32B.o \
		vp_compAR11B.o vp_compAR31B.o vp_compAR32B.o

# C define flags corresponding to COMP_SRCS; these tell the dispatch
# routines in the library which object files are available
OPT_FLAGS =	-DCOMP_AC11B   -DCOMP_AC31B   -DCOMP_AC32B \
		-DCOMP_AR11B   -DCOMP_AR31B   -DCOMP_AR32B

###########################################################################
# Options that are changed by the configure script.  These should
# probably not be editted by hand.
###########################################################################

# pathname for the C compiler
CC = 		@CC@

# pathname for the m4 macro preprocessor; it must understand the -D flag
# (some BSD versions do not; GNU m4 works)
M4 = 		@M4@

# pathname for ranlib if you need it
RANLIB = 	@RANLIB@

# commands to use to install files
INSTALL = 	@INSTALL@
INSTALL_DATA =	@INSTALL_DATA@

# directory containing source code
SRC_DIR = 	@srcdir@
VPATH = 	@srcdir@

# compiler options
AC_FLAGS = 	@DEFS@

# system-dependent options based on system name passed to configure;
# this macro is for options that should always be included (even for
# compiles with optimization turned off); configure can fill
# this in automatically if you supply a recognized system name
MFLAGS =	@MFLAGS@

# system-dependent options based on system name passed to configure;
# this macro is for optimization options only; configure can fill
# this in automatically if you supply a recognized system name
OFLAGS =	@OFLAGS@

###########################################################################
# Nothing beyond this point should need to be changed by the user.
###########################################################################

CFLAGS = -I. -I$(SRC_DIR) $(AC_FLAGS) $(CCOPT_FLAGS) $(MFLAGS) \
	 $(PROTO_FLAG) $(UNROLL_FLAG) $(OPT_FLAGS)

CSRC = vp_check.c vp_context.c vp_extract.c vp_file.c vp_linalg.c vp_octree.c \
       vp_renderA.c vp_renderB.c vp_renderC.c vp_renderR.c vp_resample.c \
       vp_rle.c vp_shade.c vp_transpose.c vp_util.c vp_view.c vp_warp.c
HSRC = volpack.h vp_global.h patchlevel.h
MSRC = vp_compA.m4 vp_warpA.m4
SUPPORT = Makefile.in configure.in no_edit_header makeopts.c
COMP_SRCS = vp_compAC1NB.c vp_compAC3NB.c vp_compAR1NB.c vp_compAR3NB.c \
       vp_compAC1PB.c vp_compAC3PB.c vp_compAR1PB.c vp_compAR3PB.c \
       vp_compAC00G.c vp_compAR00G.c vp_compAC1NS.c vp_compAC3NS.c \
       vp_compAR1NS.c vp_compAR3NS.c $(OPT_SRCS)
COMP_OBJS = vp_compAC1NB.o vp_compAC3NB.o vp_compAR1NB.o vp_compAR3NB.o \
       vp_compAC1PB.o vp_compAC3PB.o vp_compAR1PB.o vp_compAR3PB.o \
       vp_compAC00G.o vp_compAR00G.o vp_compAC1NS.o vp_compAC3NS.o \
       vp_compAR1NS.o vp_compAR3NS.o $(OPT_OBJS)
WARP_SRCS = vp_warpA101N.c vp_warpA301N.c vp_warpA110N.c vp_warpA111N.c \
       vp_warpA330N.c vp_warpA331N.c vp_warpA330R.c vp_warpA331R.c
WARP_OBJS = vp_warpA101N.o vp_warpA301N.o vp_warpA110N.o vp_warpA111N.o \
       vp_warpA330N.o vp_warpA331N.o vp_warpA330R.o vp_warpA331R.o
CGEN = vp_opts.c $(COMP_SRCS) $(WARP_SRCS)
OBJS = vp_check.o vp_context.o vp_extract.o vp_file.o vp_linalg.o vp_octree.o \
       vp_renderA.o vp_renderB.o vp_renderC.o vp_renderR.o vp_resample.o \
       vp_rle.o vp_shade.o vp_transpose.o vp_util.o vp_view.o vp_warp.o \
       vp_opts.o $(COMP_OBJS) $(WARP_OBJS)
COMP_IN = $(SRC_DIR)/no_edit_header $(SRC_DIR)/vp_compA.m4
WARP_IN = $(SRC_DIR)/no_edit_header $(SRC_DIR)/vp_warpA.m4
ESRC = vp_raycast.c
EOBJ = vp_raycast.o

all: libvolpack.a

libvolpack.a: $(OBJS)
	rm -f libvolpack.a
	ar cr libvolpack.a $(OBJS)
	$(RANLIB) libvolpack.a

$(OBJS): volpack.h vp_global.h config.h

makeopts: makeopts.c
	cc -o makeopts makeopts.c

vp_opts.c: makeopts Makefile
	makeopts vp_opts.c $(CFLAGS)

$(COMP_SRCS): $(COMP_IN)
	@for i in $(COMP_SRCS) ; \
	    do \
		rm -f $$i ;\
		echo "$(M4) -DSourceFile=$$i $(COMP_IN) > $$i" ;\
		$(M4) -DSourceFile=$$i $(COMP_IN) > $$i; \
		chmod -w $$i; \
	    done

$(WARP_SRCS): $(WARP_IN)
	@for i in $(WARP_SRCS) ; \
	    do \
		rm -f $$i ;\
		echo "$(M4) -DSourceFile=$$i $(WARP_IN) > $$i" ;\
		$(M4) -DSourceFile=$$i $(WARP_IN) > $$i; \
		chmod -w $$i; \
	    done

examples: libvolpack.a
	cd examples; make

install: install-binaries install-include install-man

install-binaries: libvolpack.a
	@for i in $(LIB_DIR) ; \
	    do \
	    if [ ! -d $$i ] ; then \
		echo "Making directory $$i"; \
		mkdir $$i ; \
		chmod 755 $$i; \
		else true; \
		fi; \
	    done;
	@echo "Installing libvolpack.a"
	@$(INSTALL_DATA) libvolpack.a $(LIB_DIR)
	@$(RANLIB) $(LIB_DIR)/libvolpack.a

install-include:
	@for i in $(INCLUDE_DIR) ; \
	    do \
	    if [ ! -d $$i ] ; then \
		echo "Making directory $$i"; \
		mkdir $$i ; \
		chmod 755 $$i; \
		else true; \
		fi; \
	    done;
	@echo "Installing volpack.h"
	@$(INSTALL_DATA) volpack.h $(INCLUDE_DIR)

install-man:
	@for i in $(MAN_DIR) $(MAN3_DIR) ; \
	    do \
	    if [ ! -d $$i ] ; then \
		echo "Making directory $$i"; \
		mkdir $$i ; \
		chmod 755 $$i; \
		else true; \
		fi; \
	    done;
	@cd $(SRC_DIR)/man/src; for i in *.3; \
	    do \
	    echo "Installing man/src/$$i"; \
	    rm -f $(MAN3_DIR)/$$i; \
	    cp $$i $(MAN3_DIR); \
	    chmod 444 $(MAN3_DIR)/$$i; \
	    done;

Makefile: $(SRC_DIR)/Makefile.in
	./config.status

mostlyclean:
	rm -f $(OBJS) $(CGEN) makeopts

clean: mostlyclean
	rm -f libvolpack.a

distclean: clean
	rm -f config.status config.log config.cache config.h Makefile

checkin:
	ci -l -f $(CSRC) $(HSRC) $(MSRC) $(ESRC) $(SUPPORT)
