# Makefile for OpenCV libraries

############################################################################

# this library name
LIBNAME	    = utils

# files in the library (.o files will be compiled implicitly from .cpp)
LIBOBJS     = utils.o

# target executables in library (ending in .bin)
LIBBIN      = 

# target executable dependencies w/ VISAL libraries (-l<libname> -l<libname> ...)
LIBDEP      = 

############################################################################


### COMMON MAKEFILE ###
### VERSION 1.0     ###

UNAME := $(shell uname)

# Path to OpenCV installation: default Linux
LIBPATH = /usr/local/lib
INCPATH = /usr/local/include

# Path to OpenCV installation: Mac OS X
ifeq ($(UNAME), Darwin)
  LIBPATH = /opt/local/lib
  INCPATH = /opt/local/include
endif

# where to put the compiled libraries and binaries
VLIBDIR = ../../linux/lib/
VBINDIR = ../../linux/bin/

# OpenCV options, includes, and libraries
OPENCV_FLAGS = -O3
OPENCV_INC   = -I$(INCPATH)/opencv -I$(INCPATH) -I../
OPENCV_LIB   = -lopencv_core -lopencv_imgproc -lopencv_highgui -lopencv_ml -lopencv_features2d -lopencv_video -lopencv_objdetect -lopencv_calib3d -lopencv_flann

# unused OpenCV libraries
OPENCV_LIBX  = -lopencv_contrib -lopencv_legacy -lopencv_gpu

# Compile and link flags
CXX          =  g++
CFLAGS       = -Wall -g $(OPENCV_INC) $(OPENCV_FLAGS)

# Compilation (add flags as needed)
#CXXFLAGS    += `pkg-config opencv --cflags`
CXXFLAGS     = -Wall -g $(OPENCV_INC) $(OPENCV_FLAGS)

# Linking (add flags as needed)
#LDFLAGS     += `pkg-config opencv --libs`

# stdc++ explicitly added for Mac Makefile
ifeq ($(UNAME), Darwin)
  LDFLAGS     += -L/usr/lib -lstdc++
endif

# opencv libraries
LDFLAGS     += -L$(LIBPATH) $(OPENCV_LIB)


############################################################################

# Default target is the first one - so we will have it make everything :-)
# first compile the library, then compile the executables
all: lib$(LIBNAME).a $(LIBBIN) 

clean: 
	rm -f lib$(LIBNAME).a $(LIBBIN) *.o
	rm -f $(VLIBDIR)lib$(LIBNAME).a
	for i in $(LIBBIN); do \
	rm -f $(VBINDIR)$$i; \
	done


# build the static library for this directory, and copy to lib dir
lib$(LIBNAME).a: $(LIBOBJS)
	echo --- Building library $(LIBNAME) ---
	rm -f $@
	ar rcs $@ $(LIBOBJS)
	cp $@ $(VLIBDIR)$@

# compile binary, and copy to bin dir
%.bin : %.cpp
	echo --- Compiling binary $@ ---
	$(CC) $(CXXFLAGS) $< -o $@ $(LDFLAGS) -L$(VLIBDIR) -l$(LIBNAME) $(LIBDEP)
	cp $@ $(VBINDIR)$@





