#
# NrrdIO: stand-alone code for basic nrrd functionality
# Copyright (C) 2013, 2012, 2011, 2010, 2009  University of Chicago
# Copyright (C) 2008, 2007, 2006, 2005  Gordon Kindlmann
# Copyright (C) 2004, 2003, 2002, 2001, 2000, 1999, 1998  University of Utah
#
# This software is provided 'as-is', without any express or implied
# warranty.  In no event will the authors be held liable for any
# damages arising from the use of this software.
#
# Permission is granted to anyone to use this software for any
# purpose, including commercial applications, and to alter it and
# redistribute it freely, subject to the following restrictions:
#
# 1. The origin of this software must not be misrepresented; you must
#    not claim that you wrote the original software. If you use this
#    software in a product, an acknowledgment in the product
#    documentation would be appreciated but is not required.
#
# 2. Altered source versions must be plainly marked as such, and must
#    not be misrepresented as being the original software.
#
# 3. This notice may not be removed or altered from any source distribution.
#

### For the time being, this will have to do as a makefile for NrrdIO

### These have to be set to reflect the current platform:
###
### -DTEEM_DIO=0, -DTEEM_DIO=1: This platform can (1) or cannot (0) do
### DirectIO, which is the fast way to do multi-gigabyte I/O.
### Currently, only available on SGIs.
###
### -DTEEM_QNANHIBIT=1, -DTEEM_QNANHIBIT=0: The 23nd bit of a 32-bit
### quiet-NaN is either 1 (1) or 0 (0).  This is needed as part of
### handling IEEE floating point special values.  This quantity is
### independent of endianness.
###
###
PLATFORM_DEFS = \
  -DTEEM_DIO=0 \
  -DTEEM_QNANHIBIT=1

CC = gcc

### Flags to cc. These now include all the various warnings that proved
### useful when cleaning up NrrdIO
###
CCFLAGS = -O2 -std=c89 -pedantic \
   -W -Wall -Wextra -Wno-long-long -Wno-overlength-strings \
   -fstrict-aliasing -Wstrict-aliasing=2 -fstrict-overflow -Wstrict-overflow=5 \
   -ftrapv -fshort-enums -fno-common \
   -Wpointer-arith -Wcast-qual -Wcast-align \
   -Wstrict-prototypes -Wshadow -Wwrite-strings -Wnested-externs \
   -Wmissing-field-initializers

### This also has to be set per-architecture- whether or not we need to
### run ranlib on libraries created via ar
###
RANLIB = ranlib

### Assuming NrrdIO will be built with zlib enabled (due to "-DTEEM_ZLIB=1"
### on the source compilation, below), these (may) need to be set to help
### find the zlib includes and libraries
###
ZLIB_IPATH =
ZLIB_LPATH =

### We'll build the static libNrrdIO library, and one test program
###
ALL = libNrrdIO.a sampleIO
all: $(ALL)

### The libNrrdIO library is built from the objects from the source files
### named in NrrdIO_Srcs.txt
###
libNrrdIO.a : $(patsubst %.c,%.o,$(shell cat NrrdIO_Srcs.txt))
	ar ru $@ $^
	$(if $(RANLIB),$(RANLIB) $@,)

### Compiling the source files will also have some platform-specific stuff
###
%.o : %.c
	$(CC) $(CCFLAGS) $(PLATFORM_DEFS) \
          -DTEEM_ZLIB=1 $(ZLIB_IPATH) -c $^ -o $@

### this creates the sampleIO program
###
sampleIO : sampleIO.c
	$(CC) $(CCFLAGS) $(PLATFORM_DEFS) -DTEEM_ZLIB=1 $(ZLIB_IPATH) \
	$^ -o $@ -L. -lNrrdIO $(ZLIB_LPATH) -lz -lm

### how to clean up
###
clean :
	rm -f *.o $(ALL)
