# builds fispro basic library (shared library to be used by standalone C++ programs

# uncomment next line for debug mode
#DEBUG=true

# 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 DEBUG
ifdef DEBUG
OPT=-g -DDEBUG -O0
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
LIBOMP=-lgomp
endif
endif

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

COMPILER= g++

ifeq ($(OS),$(filter $(OS),WIN32 WIN64))
NAME = libfispro.a
ARCHIVER= ar -r -o
endif

ifeq ($(OS),LINUX)
NAME = libfispro.so
ARCHIVER= g++ -shared -o
endif

BIN= ../../bin
ifeq ($(OS),WIN32)
BIN=../../bin-x86
endif
ifeq ($(OS),WIN64)
BIN=../../bin-amd64
endif
OBJECTS= $(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)/pt.o

$(BIN)/$(NAME) : $(OBJECTS)  
	$(ARCHIVER) $(BIN)/$(NAME) $(OBJECTS) 

$(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   $(OBJECTS) $(BIN)/$(NAME)

cleanall :
	rm   $(OBJECTS) $(BIN)/$(NAME)

