# vim:noexpandtab:softtabstop=2:tabstop=2:shiftwidth=2:nowrap
# 
# Copyright (c) 2015, iwrite authors
# All rights reserved.
# 
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 
# 1. Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
# 
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# 
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
# TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

UNAME:= $(shell uname)

ifeq ($(UNAME), Linux)
LDFLAGS+= -ldl -lX11
PNG_LIB= -l png
else
PNG_LIB= -l png16
endif

# use icu-config?
ICU4=`pkg-config --cflags icu-uc icu-io`
ICU4_LIB=`pkg-config --libs icu-uc icu-io`

GTK=`pkg-config gtk+-3.0 --cflags`
GTK_LIB=`pkg-config gtk+-3.0 --libs`

GMODULE=`pkg-config gmodule-export-2.0 --cflags`
GMODULE_LIB=`pkg-config gmodule-export-2.0 --libs`

ICU=-I icu/
ICU_LIB=-L icu/ -licu

BSON=-I bson/
BSON_LIB=-L bson/ -lbson

DECN=-I decNumber/
DECN_LIB=-L decNumber/ -ldecnumber

IWSQL_DRIVER=-I../drivers/include

GEOM=-I geometry/
GEOM_LIB=-L geometry/ -lgeometry

ZINT=-I zint/
ZINT_LIB=zint/libzint.a ${PNG_LIB}

CFLAGS=\
	${IWSQL_DRIVER}\
	${GTK}\
	${BSON}\
	${ICU}\
	${DECN}\
	${RULER}\
	${GEOM}\
	${GMODULE}\
	${ZINT}\
	-pthread\
	-Wall\
	-std=c99\
	-pedantic\
	-ggdb

CXXFLAGS:=${CFLAGS}

ALL_LIB=\
	${GTK_LIB}\
	${BSON_LIB}\
	${ICU4_LIB}\
	${ICU_LIB}\
	${DECN_LIB}\
	${RULER_LIB}\
	${GEOM_LIB}\
	${GMODULE_LIB}\
	${ZINT_LIB}\
	${LDFLAGS}\
	-lstdc++\
	-lm\

IWRITE_OBJECTS=\
	config.o\
	csv.o\
	database_aspect.o\
	database_aspect_property.o\
	database_config.o\
	database_field.o\
	database_field_property.o\
	database_session.o\
	division.o\
	driver_config.o\
	error.o\
	export_config.o\
	export.o\
	export_page_setup_property.o\
	global_common.o\
	item_circle.o\
	item_circle_property.o\
	item_common_base.o\
	item_common_box.o\
	item_common_circle.o\
	item_common_line.o\
	item_common_lookup.o\
	item_common_rectvect.o\
	item_date.o\
	item_date_property.o\
	item_fbarcode.o\
	item_fbarcode_property.o\
	item_fimage.o\
	item_fimage_property.o\
	item_fnumber.o\
	item_fnumber_property.o\
	item_frame.o\
	item_frame_property.o\
	item_fsum.o\
	item_fsum_property.o\
	item_ftext.o\
	item_ftext_property.o\
	item_image.o\
	item_image_property.o\
	item_line.o\
	item_line_property.o\
	item.o\
	item_page_number.o\
	item_page_number_property.o\
	item_text.o\
	item_text_property.o\
	iwr_page_menu.o\
	iwr_page.o\
	iwsql_dll.o\
	label.o\
	label_config.o\
	label_paper.o\
	label_page_setup_property.o\
	label_pdf.o\
	layout_break_property.o\
	layout.o\
	main.o\
	mainw.o\
	menu.o\
	option.o\
	page_setup.o\
	page_setup_property.o\
	paper.o\
	pdf.o\
	pixbuf.o\
	query_exec.o\
	query.o\
	query_property.o\
	report.o\
	rw.o\
	sql.o\
	symbology.o\
	version.o

includes = ${wildcard *.h}

.PHONY: all
all: bson/libbson.a icu/libicu.a decNumber/libdecnumber.a\
	geometry/libgeometry.a zint/libzint.a iwrite

iwrite : ${IWRITE_OBJECTS}
	${CC} -o $@ ${IWRITE_OBJECTS} ${ALL_LIB} 

%.o : %.c ${includes}
	${CC} -c ${CFLAGS} -o $@ $< 2> $@.err

item_common_lookup.o: item_common_lookup_gp.c

item_common_lookup_gp.c: item_common_lookup.gperf
	gperf -7 -D -t -L 'ANSI-C' item_common_lookup.gperf --output-file=item_common_lookup_gp.c

bson/libbson.a:
	@cd bson && ${MAKE}

icu/libicu.a:
	@cd icu && ${MAKE}

decNumber/libdecnumber.a:
	@cd decNumber && ${MAKE}

geometry/libgeometry.a:
	@cd geometry && ${MAKE}

zint/libzint.a:
	@cd zint && ${MAKE}

clean:
	rm -f *.o
	rm -f *.o.err
	rm -f *.a
	rm -f *.so
	rm -f iwrite
