NAME = perf
COMPILER= g++
BIN= ../../bin
ifeq ($(OS),WIN32)
BIN=../../bin-x86
endif
ifeq ($(OS),WIN64)
BIN=../../bin-amd64
endif
LIB_DIR = -L$(BIN)
OBJECTS= $(BIN)/perf.o 
OBJECTSLIB= $(BIN)/fis.o $(BIN)/out.o $(BIN)/in.o $(BIN)/mf.o $(BIN)/rule.o $(BIN)/defuz.o $(BIN)/common.o $(BIN)/aggreg.o $(BIN)/mfdposs.o $(BIN)/point.o
INCLUDE = -I.

# OS-default=LINUX
# for win32 run OS=WIN32;make
ifndef OS
OS=LINUX
endif

# the arch command is only valid under Linux/UNIX
#ARCH=$(shell arch)
ARCH=$(shell uname -m)
export ARCH

# flag -DDEBUG
ifdef DEBUG
OPT=-g -DDEBUG
else
OPT=-O3 -DNDEBUG
endif

# win32
ifeq ($(OS),WIN32)
OPT+= -m32
endif
# win64
ifeq ($(OS),WIN64)
OPT+= -m64
endif

ifeq ($(OS),LINUX)
ifeq ($(ARCH),x86_64)
OPT+=-fPIC
endif
endif

ifdef _OPENMP
ifeq ($(CXX),g++)
OPT+=-fopenmp
endif
endif

ifeq ($(OS),$(filter $(OS),WIN32 WIN64))
LIB_DIR+=-static
endif
  

CCFLAGS=$(INCLUDE) -Wall $(OPT)

$(BIN)/$(NAME) : $(OBJECTS)  $(OBJECTSLIB)
	$(COMPILER) -o $(BIN)/$(NAME)  $(LIB_DIR) $(OPT) $(OBJECTS) $(OBJECTSLIB) -lm 

$(BIN)/perf.o : perf.cpp 
	$(COMPILER) -c $(CCFLAGS) -o $(BIN)/perf.o perf.cpp

$(BIN)/fis.o : fis.cpp fis.h mf.h rule.h defuz.h common.h 
	$(COMPILER) -c $(CCFLAGS) -o $(BIN)/fis.o fis.cpp

$(BIN)/in.o : in.cpp fis.h mf.h common.h 
	$(COMPILER) -c $(CCFLAGS) -o $(BIN)/in.o in.cpp

$(BIN)/out.o : out.cpp fis.h mf.h common.h 
	$(COMPILER) -c $(CCFLAGS) -o $(BIN)/out.o out.cpp

$(BIN)/mf.o : mf.cpp fis.h mf.h common.h 
	$(COMPILER) -c $(CCFLAGS) -o $(BIN)/mf.o mf.cpp

$(BIN)/rule.o : rule.cpp fis.h mf.h rule.h common.h 
	$(COMPILER) -c $(CCFLAGS) -o $(BIN)/rule.o rule.cpp

$(BIN)/defuz.o : defuz.cpp fis.h mf.h rule.h defuz.h common.h 
	$(COMPILER) -c $(CCFLAGS) -o $(BIN)/defuz.o defuz.cpp

$(BIN)/common.o : common.cpp common.h
	$(COMPILER) -c $(CCFLAGS) -o $(BIN)/common.o common.cpp

$(BIN)/aggreg.o : aggreg.cpp fis.h mf.h rule.h defuz.h common.h 
	$(COMPILER) -c $(CCFLAGS) -o $(BIN)/aggreg.o aggreg.cpp

$(BIN)/mfdposs.o : mfdposs.cpp fis.h mf.h rule.h defuz.h common.h 
	$(COMPILER) -c $(CCFLAGS) -o $(BIN)/mfdposs.o mfdposs.cpp

$(BIN)/pt.o : pt.cpp fis.h mf.h rule.h defuz.h common.h 
	$(COMPILER) -c $(CCFLAGS) -o $(BIN)/pt.o pt.cpp

clean : 
	rm  *~ $(BIN)/perf.o $(BIN)/$(NAME) 

