include ZOOMakefile.opts

all: version.h zoo_loader.cgi ${YAML_FILE1}

version.h:
	echo "#define ZOO_VERSION \"`svnversion`\"" > version.h

service.o: service.c service.h
	gcc ${YAML_CFLAGS} ${XML2CFLAGS} ${CFLAGS} -fPIC -c service.c

main_conf_read.tab.c: main_conf_read.y service.h
	bison -p cr -d main_conf_read.y

main_conf_read.tab.o: main_conf_read.tab.c service.h
	g++ ${CFLAGS} -c main_conf_read.tab.c

lex.cr.c: main_conf_read.y main_conf_read.l main_conf_read.tab.c service.h
	flex -P cr --header-file main_conf_read.l

lex.cr.o: lex.cr.c service.h
	g++ ${CFLAGS} -c lex.cr.c

service_conf.tab.c: service_conf.y service.h
	bison -p sr -d service_conf.y

service_conf.tab.o: service_conf.tab.c service.h
	g++ ${CFLAGS} -c service_conf.tab.c

lex.sr.c: service_conf.y service_conf.l service_conf.tab.c service.h
	flex -P sr --header-file service_conf.l

lex.sr.o: lex.sr.c service.h
	g++ ${CFLAGS} -c lex.sr.c

ulinet.o: ulinet.c
	gcc -fPIC ${XML2CFLAGS} ${CFLAGS} ${JSCFLAGS} ${JS_ENABLED} -c ulinet.c

zoo_zcfg.o: zoo_zcfg.c service.h
	g++ ${GLIB_CPPFLAGS} ${XML2CFLAGS} -c zoo_zcfg.c

logger.o: logger.c
	gcc -c logger.c

zoo_json.o: zoo_json.c service.h
	g++ ${JSON_CPPFLAGS} ${XML2CFLAGS} -c zoo_json.c

zoo_amqp.o: zoo_amqp.c
	g++ ${CFLAGS} -c zoo_amqp.c

request_parser.o: request_parser.c request_parser.h
	g++ -fPIC ${XML2CFLAGS} ${CFLAGS} ${JSCFLAGS} ${JS_ENABLED} -c request_parser.c

sqlapi.o: sqlapi.c sqlapi.h
	g++ -fPIC ${XML2CFLAGS} ${CFLAGS} ${JSCFLAGS} ${JS_ENABLED} -c sqlapi.c

caching.o: caching.c
	g++ -fPIC ${XML2CFLAGS} ${CFLAGS} ${JSCFLAGS} ${JS_ENABLED} -c caching.c

response_print.o: response_print.c response_print.h
	g++ -fPIC ${GDAL_CFLAGS} ${XML2CFLAGS} ${CFLAGS} ${JSCFLAGS} ${JS_ENABLED} -c response_print.c

server_internal.o: server_internal.c server_internal.h service.h mimetypes.h
	g++ ${GDAL_CFLAGS} ${JS_ENABLED} ${JSCFLAGS} ${XML2CFLAGS} ${CFLAGS} -fPIC -c server_internal.c

service_internal.o: service_internal.c service_internal.h service.h
	gcc ${GDAL_CFLAGS} ${JS_ENABLED} ${JSCFLAGS} ${XML2CFLAGS} ${CFLAGS} -fPIC -c service_internal.c

service_yaml.o: service_yaml.c service.h
	gcc ${YAML_CFLAGS} ${XML2CFLAGS} ${CFLAGS} -fPIC -c service_yaml.c

service_internal_ms.o: service_internal_ms.c
	gcc ${JS_ENABLED} ${JSCFLAGS} ${XML2CFLAGS} ${CFLAGS} -fPIC -c service_internal_ms.c

service_internal_python.o: service_internal_python.c service.h
	g++ ${XML2CFLAGS} ${PYTHONCFLAGS} ${CFLAGS} -c service_internal_python.c

service_internal_otb.o: service_internal_otb.c service_internal_otb.h service.h
	g++ ${XML2CFLAGS} ${OTBCFLAGS} ${CFLAGS} -c service_internal_otb.c

service_internal_saga.o: service_internal_saga.c service_internal_saga.h service.h
	g++ ${XML2CFLAGS} ${SAGA_CFLAGS} ${CFLAGS} -c service_internal_saga.c

otbZooWatcher.o: otbZooWatcher.cxx otbZooWatcher.h  service.h
	g++ ${OTBCFLAGS} ${CFLAGS} -c otbZooWatcher.cxx

service_internal_php.o: service_internal_php.c service.h
	g++ -c ${XML2CFLAGS} ${PHPCFLAGS} ${CFLAGS}  ${PHP_ENABLED} service_internal_php.c

service_internal_perl.o: service_internal_perl.c service.h
	gcc -c ${XML2CFLAGS} ${PERLCFLAGS} ${CFLAGS}  ${PERL_ENABLED} service_internal_perl.c

service_internal_java.o: service_internal_java.c service.h
	gcc -c ${XML2CFLAGS} ${JAVACFLAGS} ${CFLAGS} ${JAVA_ENABLED} service_internal_java.c

service_internal_js.o: service_internal_js.c service_internal_js.h
	gcc -fPIC ${XML2CFLAGS} ${JSCFLAGS} ${CFLAGS} ${JS_ENABLED} -c service_internal_js.c

service_internal_ruby.o: service_internal_ruby.c service_internal_ruby.h
	g++ ${XML2CFLAGS} ${RUBYCFLAGS} ${CFLAGS} ${JSCFLAGS} ${JS_ENABLED} -c service_internal_ruby.c

service_loader.o: service_loader.c service.h
	g++ -c ${XML2CFLAGS} ${PYTHONCFLAGS} ${CFLAGS} service_loader.c

zoo_service_loader.o: zoo_service_loader.c service.h
	g++ -g -O2 ${XML2CFLAGS} ${CFLAGS} ${SAGA_CFLAGS} ${OTBCFLAGS} ${PYTHONCFLAGS} ${JAVACFLAGS} ${JSCFLAGS} ${PERLCFLAGS} ${PHPCFLAGS} ${JSON_CPPFLAGS} ${SAGA_ENABLED} ${OTB_ENABLED} ${PYTHON_ENABLED} ${JS_ENABLED} ${PHP_ENABLED} ${PERL_ENABLED} ${JAVA_ENABLED}  -c zoo_service_loader.c  -fno-common -DPIC -o zoo_service_loader.o

libzoo_service.${EXT}: version.h service_internal.o service.o sqlapi.o
	gcc -shared  ${GDAL_CFLAGS} ${DEFAULT_OPTS} -fpic -o libzoo_service.${EXT} ${CFLAGS}  service_internal.o service.o sqlapi.o -lfcgi ${GDAL_LIBS}

zoo_loader.cgi: version.h libzoo_service.${EXT} zoo_json.o zoo_amqp.o zoo_loader.c zoo_service_loader.o  ulinet.o zoo_zcfg.o service.h lex.sr.o service_conf.tab.o service_conf.y ulinet.o main_conf_read.tab.o lex.cr.o request_parser.o response_print.o server_internal.o caching.o ${MS_FILE} ${PYTHON_FILE} ${PHP_FILE} ${JAVA_FILE} ${JS_FILE} ${PERL_FILE} ${RUBY_FILE} ${RABBITMQ_FILE} ${YAML_FILE} ${OTB_FILE} ${SAGA_FILE}
	g++ -g -O2 ${JSCFLAGS} ${PHPCFLAGS}  ${PERLCFLAGS} ${RUBYCFLAGS}  ${JAVACFLAGS} ${XML2CFLAGS} ${PYTHONCFLAGS} ${JSON_CPPFLAGS} ${CFLAGS} -c zoo_loader.c  -fno-common -DPIC -o zoo_loader.o
	g++  ${JSCFLAGS} ${SAGA_CFLAGS} ${OTBCFLAGS} ${GDAL_CFLAGS} ${XML2CFLAGS} ${PHPCFLAGS} ${PERLCFLAGS} ${JAVACFLAGS} ${PYTHONCFLAGS} ${CFLAGS} zoo_loader.o zoo_service_loader.o ${RABBITMQ_FILE}  ${MS_FILE} ${PYTHON_FILE}  ${PERL_FILE} ${PHP_FILE}  ${JS_FILE} ${JAVA_FILE} ${YAML_FILE} ${OTB_FILE} ${SAGA_FILE} response_print.o server_internal.o caching.o request_parser.o ulinet.o zoo_json.o zoo_zcfg.o lex.cr.o lex.sr.o service_conf.tab.o main_conf_read.tab.o -o zoo_loader.cgi -L. ${LDFLAGS}

zoo_fpm: version.h libzoo_service.${EXT} logger.o zoo_json.o zoo_amqp.o zoo_fpm.c zoo_service_loader.o  ulinet.o zoo_zcfg.o service.h lex.sr.o service_conf.tab.o service_conf.y ulinet.o main_conf_read.tab.o lex.cr.o request_parser.o response_print.o server_internal.o caching.o ${MS_FILE} ${PYTHON_FILE} ${PHP_FILE} ${JAVA_FILE} ${JS_FILE} ${PERL_FILE} ${RUBY_FILE} ${RABBITMQ_FILE} ${YAML_FILE} ${OTB_FILE} ${SAGA_FILE}
	g++ -g -O2 ${JSCFLAGS} ${PHPCFLAGS}  ${PERLCFLAGS} ${RUBYCFLAGS}  ${JAVACFLAGS} ${XML2CFLAGS} ${PYTHONCFLAGS} ${JSON_CPPFLAGS} ${CFLAGS} -c zoo_fpm.c  -fno-common -DPIC -o zoo_fpm.o
	g++  ${JSCFLAGS} ${SAGA_CFLAGS} ${OTBCFLAGS} ${GDAL_CFLAGS} ${XML2CFLAGS} ${PHPCFLAGS} ${PERLCFLAGS} ${JAVACFLAGS} ${PYTHONCFLAGS} ${CFLAGS} logger.o zoo_fpm.o zoo_service_loader.o ${RABBITMQ_FILE}  ${MS_FILE} ${PYTHON_FILE}  ${PERL_FILE} ${PHP_FILE}  ${JS_FILE} ${JAVA_FILE} ${YAML_FILE} ${OTB_FILE} ${SAGA_FILE} response_print.o server_internal.o caching.o request_parser.o ulinet.o zoo_json.o zoo_zcfg.o lex.cr.o lex.sr.o service_conf.tab.o main_conf_read.tab.o -o zoo_fpm -L. ${LDFLAGS}


zcfg2yaml: zcfg2yaml.c service.h lex.sr.o service_conf.tab.o service_conf.y main_conf_read.tab.o lex.cr.o response_print.o server_internal.o service_internal.o ${MS_FILE} ${YAML_FILE}
	g++ -g -O2 ${JSCFLAGS} ${RUBYCFLAGS} ${XML2CFLAGS} ${CFLAGS} -c zcfg2yaml.c  -fno-common -DPIC -o zcfg2yaml.o
	g++  ${XML2CFLAGS} ${CFLAGS} zcfg2yaml.o server_internal.o service_internal.o ${MS_FILE} response_print.o lex.cr.o lex.sr.o service_conf.tab.o main_conf_read.tab.o  ${YAML_FILE} -o zcfg2yaml -L. ${LDFLAGS}

install:
	install -d ${CGI_DIR}
	install zoo_loader.cgi ${CGI_DIR}/
	install libzoo_service.${EXT} ${DESTDIR}${INST_LIB}/${LIBZOO_SERVICE}
	(cd ${DESTDIR}${INST_LIB} ; \
	 if [ -e "libzoo_service.${EXT}" ]; then rm  libzoo_service.${EXT}; fi ; \
	 ln -s ${LIBZOO_SERVICE} libzoo_service.${EXT})
	install -d ${DESTDIR}${INST_INCLUDE}/zoo
	install service.h service_internal.h ${DESTDIR}${INST_INCLUDE}/zoo

clean:
	rm -f version.h *.o *.zo *.eo *.tab.c *.tab.h *.sr.c* service_loader lex.* *.lreg *.sibling service_loader.dSYM *${EXT}
