#######################################################################
# File: Makefile
# 	(Extracted from
#	   "$$")
#
# Abstracts:
#  This make file generates the test program for "aggregate.c".
#
# Copyright (C) 2009 Maoyam Tokyo, Japan (mailto:maoyam@mail.goo.ne.jp)
#
#  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.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program; if not, write to the Free Software
#  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#
#
######################################################################

# Debugging Flag
DBGFLAGS=-DDEBUG

# Cygwin
## CC=g++
## CC=gcc -std=c99
## CFLAGS=$(DBGFLAGS) -mno-cygwin -Wall -pedantic -Wshadow -Wredundant-decls -Werror

# Linux
CC=gcc -std=c99
CFLAGS=$(DBGFLAGS) -Wall -pedantic -Wshadow -Wredundant-decls -Werror

# Solaris (fcc)
## CC=/opt/FSUNf90/bin/fcc
## CFLAGS=$(DBGFLAGS)

PROG=data
OBJS= data.o csv_converter.o
SRCS=$(OBJS:.o=.c)
PROG2=write_csv_columns_test
OBJS2= write_csv_columns_test.o csv_converter.o
SRCS2=$(OBJS2:.o=.c)

all: $(PROG) $(PROG2)

$(PROG): data.c csv_converter.c csv_converter.h
	$(CC) -g $(CFLAGS) -o $(PROG) $(SRCS)

$(PROG2): write_csv_columns_test.c csv_converter.c
	$(CC) -g $(CFLAGS) -o $(PROG2) $(SRCS2)

splint:
	-splint +posixlib -nullassign -initallelements		\
		-nullpass -mustfreefresh -exitarg +voidabstract	\
		-branchstate -usereleased -nullstate -nullret	\
		-temptrans -usedef -mustfreeonly -compmempass	\
		-compdef -unqualifiedtrans -casebreak			\
		-dependenttrans -exportlocal -compdestroy		\
													$(SRCS)
	-splint +posixlib -nullassign -initallelements		\
		-nullpass -mustfreefresh -exitarg +voidabstract	\
		-branchstate -usereleased -nullstate -nullret	\
		-temptrans -usedef -mustfreeonly -compmempass	\
		-compdef -unqualifiedtrans -casebreak			\
		-dependenttrans -exportlocal					\
									write_csv_columns_test.c

utest:
	./$(PROG)	> $(PROG).out`date +'%Y%m%d'`.txt
	./$(PROG2)	> $(PROG2).out`date +'%Y%m%d'`.txt

valgrind:
	make clean;
	make;
	(date; uname -a; $(CC) --version; echo; valgrind -v --read-var-info=yes --track-origins=yes --leak-check=full ./$(PROG) ) > valgrind.$(PROG).out`date +'%Y%m%d'`.txt 2>&1
	(date; uname -a; $(CC) --version; echo; valgrind -v --read-var-info=yes --track-origins=yes --leak-check=full ./$(PROG2) ) > valgrind.$(PROG2).out`date +'%Y%m%d'`.txt 2>&1

gprof:
	make clean;
	$(CC) -pg $(CFLAGS) -o $(PROG) $(SRCS)
	./$(PROG) -P > /dev/null 2>&1;
	(date; uname -a; $(CC) --version; echo; gprof --version; gprof $(PROG) gmon.out) > gprof.$(PROG).out`date +'%Y%m%d'`.txt 2>&1;
	$(CC) -pg $(CFLAGS) -o $(PROG2) $(SRCS2)
	./$(PROG2) -P > /dev/null 2>&1;
	(date; uname -a; $(CC) --version; echo; gprof --version; gprof $(PROG2) gmon.out) > gprof.$(PROG2).out`date +'%Y%m%d'`.txt 2>&1;
	rm gmon.out;
	make clean;

rcs:
	ci										\
		GPL.txt								\
		Makefile							\
		csv_converter.c						\
		csv_converter.h						\
		data.c								\
		index.html							\
		test_file_2.csv						\
		write_csv_columns_test.c
	co -l									\
		GPL.txt								\
		Makefile							\
		csv_converter.c						\
		csv_converter.h						\
		data.c								\
		index.html							\
		test_file_2.csv						\
		write_csv_columns_test.c
	rlog									\
		GPL.txt								\
		Makefile							\
		csv_converter.c						\
		csv_converter.h						\
		data.c								\
		index.html							\
		test_file_2.csv						\
		write_csv_columns_test.c		> CHANGE_LOGS.txt

clean:
	rm	-f $(OBJS) $(OBJS2)					\
		$(PROG) $(PROG).exe $(PROG2) $(PROG2).exe

