#
# NrrdIO: C library for NRRD file IO (with optional compressions)
# Copyright (C) 2009--2026  University of Chicago
# Copyright (C) 2005--2008  Gordon Kindlmann
# Copyright (C) 1998--2004  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

CC = cc

### 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 \
   -Wstrict-aliasing=2 -Wstrict-overflow=5 \
   -Wpointer-arith -Wcast-qual -Wcast-align \
   -Wstrict-prototypes -Wshadow -Wwrite-strings -Wnested-externs \
   -Wformat -Wformat-signedness -Wformat-pedantic -Wmissing-field-initializers \
   -Wunused-parameter -Wconversion \
   -fstrict-overflow -fstrict-aliasing -ftrapv -fshort-enums -fno-common

### 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) \
          -DTEEM_ZLIB=1 -DTEEM_BZIP2=1 $(ZLIB_IPATH) -c $^ -o $@

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

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