CURDIR1 = $(CURDIR)/..

ifndef PCOREC
	PCOREC = /opt/pco/pco.recorder
endif

ifeq "$(strip $(filter debug,$(MAKECMDGOALS)))" "debug"
  PREDEFS := -g -O0 -fno-inline -D_DEBUG
  OUTDIR   = $(CURDIR1)/bin64_debug
  DEB = debug
else
  PREDEFS := -O2
  OUTDIR   = $(CURDIR1)/bin64
  DEB = 
endif

OUTDIRD  = $(CURDIR1)/bin64_debug

PREDEFS += -DPCO_LINUX
PCOINCDIR  = $(PCOREC)/include
PCOLIBDIR  = $(PCOREC)/bin64

INCLUDES = -I$(PCOINCDIR)

CXXFLAGS += -std=c++17 -Wall $(PREDEFS) 

HEADERS = # local headers
PCOLIB  = -lpco_sc2cam -lpco_recorder -lpco_convert
LIBADD = -lpthread -lstdc++fs

LFLAGS +=  -L$(PCOLIBDIR)
LIBADD_START = -Wl,--start-group 
LIBADD_END   = -Wl,--end-group
LINKRPATH += -Wl,-rpath,'$$ORIGIN'
LINKRPATH += -Wl,-z,origin
LINKRPATH += -Wl,-rpath,$(PCOLIBDIR)

TARGET  = SimpleExample
TARGETS = $(addprefix $(OUTDIR)/,$(TARGET))

all: dirs $(TARGETS)

debug: dirs $(TARGETS)

clean:
		$(RM) *.o *~ $(TARGETS) $(addprefix $(OUTDIRD)/,$(TARGET))

dirs:
		@if [ ! -d $(OUTDIR) ]; then \
		echo create directory $(OUTDIR); \
		mkdir $(OUTDIR); \
		fi

$(OUTDIR)/%: $(CURDIR)/%.cpp $(HEADERS) Makefile
		$(CXX) $(CXXFLAGS) $< -o $@ $(INCLUDES) $(LFLAGS) $(LINKRPATH) $(LIBADD_START) $(PCOLIB) $(LIBADD) $(LIBADD_END)
