CC= gcc
IROOT=/usr/local/include/Sapera

INC_PATH = -I$(IROOT)/include -I$(IROOT)/examples/common -I$(IROOT)/classes/basic

DEBUGFLAGS = -g 
CXX_COMPILE_OPTIONS = -c $(DEBUGFLAGS) -DPOSIX_HOSTPC -D_REENTRANT -fno-for-scope \
			-Wall -Wno-parentheses -Wno-missing-braces \
			-Wno-unknown-pragmas -Wno-cast-qual -Wno-unused-function -Wno-unused-label

C_COMPILE_OPTIONS= $(DEBUGFLAGS) -fhosted -Wall -Wno-parentheses -Wno-missing-braces \
		   	-Wno-unknown-pragmas -Wno-cast-qual -Wno-unused-function -Wno-unused-label


# gcc 4.8 is broken - handles symbols in libraries differently than previous versions.
# So change :
# LCLLIBS=  -lpthread -lstdc++ -L/usr/X11R6/lib -lXext -lX11 -L/usr/local/lib -lSapera++ -lSaperaLT 
# to ...
LCLLIBS=  -lpthread -lstdc++ -L/usr/X11R6/lib -lXext -lX11 -L/usr/local/lib -lSapera++ -lSaperaLT -lCorW32 -L. -lCameraLinkCmd

VPATH= . : ../common

ifndef ARCH
  ARCH := $(shell uname -m | sed -e s/i.86/i386/ -e s/x86_64/x86_64/ -e s/aarch64/aarch64/ )
endif

ifeq  ($(ARCH), x86_64)
	ARCH_OPTIONS= -Dx86_64
else ifeq  ($(ARCH), i386)
	ARCH_OPTIONS= -D__i386__ 
else ifeq  ($(ARCH), aarch64)
	ARCH_OPTIONS= -Daarch64 -Darm_family 
else
# Force an error
$(error	Unknown architecture ***)
endif

%.o : %.cpp
	$(CC) -I. $(INC_PATH) $(CXX_COMPILE_OPTIONS) $(ARCH_OPTIONS) -c $< -o $@

%.o : %.c
	$(CC) -I. $(INC_PATH) $(C_COMPILE_OPTIONS) $(ARCH_OPTIONS) -c $< -o $@

OBJS= consoledemo.o \
      SapExUtil.o \
      X_Display_utils.o

consoledemo : $(OBJS)
	$(CC) -g -o consoledemo -Wl,-rpath -Wl,'$$ORIGIN' $(OBJS) $(LCLLIBS)

clean:
	rm -f *.o consoledemo 


