# Makefile for database package for Octave
#
# Copyright (C) 2016 Olaf Till <i7tiol@t-online.de>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, see <http://www.gnu.org/licenses/>.

# We rely on g++ features, configure assures CXX=g++.
CXX := @CXX@

EXTRALIBS = 
ifeq ($(OS),Windows_NT)
  EXTRALIBS = -lws2_32
endif

ifndef CXXFLAGS
CXXFLAGS_NSA := "-g -O2 -fno-strict-aliasing"
CXXFLAGS := "-g -O2"
else
CXXFLAGS_NSA := "$(CXXFLAGS) -fno-strict-aliasing"
endif

OBJECTS := __pq_connect__.o pq_close.o pq_exec.o converters.o \
           converters_arr_comp.o pq_connection.o command.o \
           pq_update_types.o pq_lo.o pq_conninfo.o __pq_internal_exit__.o \
           error-helpers.o

pq_interface.oct: $(OBJECTS)
	@MKOCTFILE@ -o pq_interface.oct -L`@PG_CONFIG@ --libdir` -lpq $(OBJECTS) $(EXTRALIBS)

converters.o: converters.cc converters.h wrap_endian.h config.h error-helpers.h
	CXX=$(CXX) CXXFLAGS=$(CXXFLAGS_NSA) @MKOCTFILE@ -I`@PG_CONFIG@ --includedir` -c converters.cc

converters_arr_comp.o: converters_arr_comp.cc converters.h wrap_endian.h \
                       pq_connection.h command.h config.h error-helpers.h
	CXX=$(CXX) CXXFLAGS=$(CXXFLAGS_NSA) @MKOCTFILE@ -I`@PG_CONFIG@ --includedir` -c converters_arr_comp.cc

# be on the safe side with respect to include files
%.o: %.cc converters.h pq_connection.h command.h config.h error-helpers.h
	CXX=$(CXX) CXXFLAGS=$(CXXFLAGS) @MKOCTFILE@ -I`@PG_CONFIG@ --includedir` -c $<

.PHONY: clean
clean: ; rm -f *.o *.oct
