#*********************************************
#**** Makefile for Zhiqiang Lao's C code *****
#*********************************************

#########################################################################
## Macro Definitions ####################################################
#########################################################################

#########################################################################
###### Root Directories #################################################
#########################################################################

MYROOT = ./
INCROOT=$(MYROOT)/../include
LIBROOT=$(MYROOT)/lib
TOOLSROOT=$(MYROOT)/mvctdtools

#########################################################################
###### Library link options #############################################
#########################################################################

CLIBS1=-lmvcd -lm
CLIBS2=-lmatrixSHEN $(CLIBS1)
CLIBS4=-lmvvt $(CLIBS2)

#########################################################################
###### Flags ############################################################
#########################################################################

OPTFLAG=
LIBFLAG=-L$(LIBROOT)
INCFLAG=-I$(INCROOT)

#########################################################################
## Targets and Dependencies #############################################
#########################################################################

all: mvcd cres matrixSHEN affine getopts make_hdr pgstd InhomoCorrection_improve_again OpeningCloseingRegiongrowing3DBinaryImg MaskOutImg MatchHistogramsOfImgA2ImgB_special WMLRemoveEyeInFlair_improve_again WMLTestSingleImageKeepAllFunctionValue_NoSmooth InvertImgFloat OneImgOp anslice4volrot WMLGetSelectedFeature WMLGetAutoManualMaskDiff OpeningCloseingRegiongrowing3DBinaryImg_special GetWholeImageVolume extractVentricle4perl

mvcd: 
	gcc -c -I../include mvcd.c; ar cr ../lib/libmvcd.a mvcd.o; rm mvcd.o;
cres: 
	cd $(TOOLSROOT); gcc -c -I ../../include cres.c; ar cr ../lib/libcres.a cres.o; rm cres.o;
matrixSHEN: 
	gcc -c -I../include matrixSHEN.c; ar cr ../lib/libmatrixSHEN.a matrixSHEN.o; rm matrixSHEN.o;
affine: 
	gcc -c -I../include affine.c; 
getopts: 
	gcc -c -I../include getopts.c; 
make_hdr: 
	gcc -c -I../include make_hdr.c; 
pgstd: 
	gcc -c -I../include pgstd.c; 

#########################################################################
###### Clean up #########################################################
#########################################################################

clean: 
	ls *.o
	rm -f *.o
purge:
	ls *~*
	rm -r *~*

#########################################################################
##########                    ROI Label Correction            ###########
#########################################################################

InhomoCorrection_improve_again: InhomoCorrection_improve_again.o
	gcc -o $(MYROOT)/../bin/$@ $? $(CLIBS1) $(LIBFLAG)

InhomoCorrection_improve_again.o: InhomoCorrection_improve_again.c
	gcc $(OPTFLAG) -c $(MYROOT)/$? $(INCFLAG)

#########################################################################
##########      basic morphological operations     ###########
#########################################################################

OpeningCloseingRegiongrowing3DBinaryImg: OpeningCloseingRegiongrowing3DBinaryImg.o
	gcc -o $(MYROOT)/../bin/$@ $? $(CLIBS1) $(LIBFLAG)

OpeningCloseingRegiongrowing3DBinaryImg.o: OpeningCloseingRegiongrowing3DBinaryImg.c
	gcc $(OPTFLAG) -c $(MYROOT)/$? $(INCFLAG)

#########################################################################
##########                 masking operation                  ###########
#########################################################################

MaskOutImg: MaskOutImg.o
	gcc -o $(MYROOT)/../bin/$@ $? $(CLIBS1) $(LIBFLAG)

MaskOutImg.o: MaskOutImg.c
	gcc $(OPTFLAG) -c $(MYROOT)/$? $(INCFLAG)

############################################################################
##########      histogram matching based intensity normalization ###########
############################################################################

MatchHistogramsOfImgA2ImgB_special: MatchHistogramsOfImgA2ImgB_special.o
	gcc -o $(MYROOT)/../bin/$@ $? $(CLIBS1) $(LIBFLAG)

MatchHistogramsOfImgA2ImgB_special.o: MatchHistogramsOfImgA2ImgB_special.c
	gcc $(OPTFLAG) -c $(MYROOT)/$? $(INCFLAG)

#####################################################################################
##########      remove eye tissue in FLAIR image for skull-stripped brain ###########
#####################################################################################

WMLRemoveEyeInFlair_improve_again: WMLRemoveEyeInFlair_improve_again.o
	gcc -o $(MYROOT)/../bin/$@ $? $(CLIBS1) $(LIBFLAG)

WMLRemoveEyeInFlair_improve_again.o: WMLRemoveEyeInFlair_improve_again.c
	gcc $(OPTFLAG) -c $(MYROOT)/$? $(INCFLAG)

#####################################################################################
##########            test new images according to SVM model              ###########
#####################################################################################

WMLTestSingleImageKeepAllFunctionValue_NoSmooth: WMLTestSingleImageKeepAllFunctionValue_NoSmooth.o
	gcc -o $(MYROOT)/../bin/$@ $? $(CLIBS1) $(LIBFLAG)

WMLTestSingleImageKeepAllFunctionValue_NoSmooth.o: WMLTestSingleImageKeepAllFunctionValue_NoSmooth.c
	gcc $(OPTFLAG) -c $(MYROOT)/$? $(INCFLAG)

#####################################################################################
##########            invert intensity values in a float image              #########
#####################################################################################

InvertImgFloat: InvertImgFloat.o
	gcc -o $(MYROOT)/../bin/$@ $? $(CLIBS1) $(LIBFLAG)

InvertImgFloat.o: InvertImgFloat.c
	gcc $(OPTFLAG) -c $(MYROOT)/$? $(INCFLAG)

#####################################################################################
##########            some simple image operations                        ###########
#####################################################################################

OneImgOp: OneImgOp.o
	gcc -o $(MYROOT)/../bin/$@ $? $(CLIBS1) $(LIBFLAG)

OneImgOp.o: OneImgOp.c
	gcc $(OPTFLAG) -c $(MYROOT)/$? $(INCFLAG)

#####################################################################################
##########            b-spline interpolation program for rotation         ###########
#####################################################################################

anslice4volrot: anslice4volrot.o affine.o getopts.o make_hdr.o pgstd.o 
	gcc -o $(MYROOT)/../bin/$@ $? -lm $(LIBFLAG)

anslice4volrot.o: anslice4volrot.c
	gcc $(OPTFLAG) -c $(MYROOT)/$? $(INCFLAG)

#####################################################################################
##########            test new images according to SVM model              ###########
#####################################################################################

WMLGetSelectedFeature: WMLGetSelectedFeature.o
	gcc -o $(MYROOT)/../bin/$@ $? $(CLIBS1) $(LIBFLAG)

WMLGetSelectedFeature.o: WMLGetSelectedFeature.c
	gcc $(OPTFLAG) -c $(MYROOT)/$? $(INCFLAG)

#####################################################################################
##########            test new images according to SVM model              ###########
#####################################################################################

WMLGetAutoManualMaskDiff: WMLGetAutoManualMaskDiff.o
	gcc -o $(MYROOT)/../bin/$@ $? $(CLIBS1) $(LIBFLAG)

WMLGetAutoManualMaskDiff.o: WMLGetAutoManualMaskDiff.c
	gcc $(OPTFLAG) -c $(MYROOT)/$? $(INCFLAG)

#########################################################################
##########      basic morphological operations     ###########
#########################################################################

OpeningCloseingRegiongrowing3DBinaryImg_special: OpeningCloseingRegiongrowing3DBinaryImg_special.o
	gcc -o $(MYROOT)/../bin/$@ $? $(CLIBS1) $(LIBFLAG)

OpeningCloseingRegiongrowing3DBinaryImg_special.o: OpeningCloseingRegiongrowing3DBinaryImg_special.c
	gcc $(OPTFLAG) -c $(MYROOT)/$? $(INCFLAG)

#########################################################################
##########      basic morphological operations     ###########
#########################################################################

GetWholeImageVolume: GetWholeImageVolume.o
	gcc -o $(MYROOT)/../bin/$@ $? $(CLIBS1) $(LIBFLAG)

GetWholeImageVolume.o: GetWholeImageVolume.c
	gcc $(OPTFLAG) -c $(MYROOT)/$? $(INCFLAG)

#########################################################################
##########      basic image operations     ###########
#########################################################################

extractVentricle4perl: extractVentricle4perl.o
	gcc -o $(MYROOT)/../bin/$@ $? $(CLIBS2) $(LIBFLAG)

extractVentricle4perl.o: extractVentricle4perl.c
	gcc $(OPTFLAG) -c $(MYROOT)/$? $(INCFLAG)

