filter_filter_dir = ../filter/filter
filter_backend_dir = ../filter/backend
filter_frontend_dir = ../filter/frontend
caml_link_dirs = -cclib -lpthread -cclib -lcamlidl -cclib -L$(bindings_dir)
bindings_dir =  ../bindings-pkcs11
rpc-pkcs11_dir =  ../rpc-pkcs11
mem_prot_opt_caml=-ccopt -O2 -ccopt -fPIC -ccopt -fPIE -ccopt -Wl,-z,relro,-z,now -ccopt -fstack-protector -ccopt -DFORTIFY_SOURCE=2
server_name = pkcs11proxyd
prefix=${DESTDIR}@prefix@
sysconf=${DESTDIR}@sysconfdir@

all:
	#Compile Server
	ocamlfind ocamlopt @ocaml_options@ -pp "camlp4o pa_macro.cmo @ocaml_bytes_module_define@ -I @srcdir@ @caml_server_daemonize_define@ @caml_server_ssl_define@ @filter_define@" -package "netplex" @filter_include@ @caml_server_ssl_package@ -I $(bindings_dir) -I $(rpc-pkcs11_dir) -o server -c @srcdir@/server.ml
	ocamlfind ocamlopt @ocaml_options@ @filter_include@ -package "str,netplex,config-file" @caml_server_ssl_package@ -linkpkg $(bindings_dir)/pkcs11.cmxa @filter_files@ $(rpc-pkcs11_dir)/pkcs11_rpclib.cmxa server.cmx $(caml_link_dirs) $(mem_prot_opt_caml) -o $(server_name)

install:
	echo "Installing $(server_name) to ${prefix}/bin/$(server_name)"
	install -D $(server_name) ${prefix}/bin/$(server_name)
	echo "Installing @srcdir@/$(server_name).conf to ${sysconf}/$(server_name)/$(server_name).conf"
	install -m 640 -D @srcdir@/$(server_name).conf ${sysconf}/$(server_name)/$(server_name).conf
	install -m 640 -D @srcdir@/filter.conf ${sysconf}/$(server_name)/filter.conf

uninstall:
	echo "Removing $(server_name) from ${prefix}/bin/$(server_name)"
	rm ${prefix}/bin/$(server_name)
	echo "Removing $(server_name).conf from ${sysconf}/$(server_name)/$(server_name).conf"
	rm ${sysconf}/$(server_name)/$(server_name).conf
	rm ${sysconf}/$(server_name)/filter.conf

clean:
	@rm -f @srcdir@/*.cmi @srcdir@/*.cmo @srcdir@/*.cma @srcdir@/*.cmx @srcdir@/*.o @srcdir@/*.a @srcdir@/*.cmxa @srcdir@/dll* @srcdir@/packlist-* @srcdir@/ocamldoc.dump @srcdir@/META @srcdir@/depend @srcdir@/$(server_name) @srcdir@/*.astamp @srcdir@/*.cstamp @srcdir@/*.s2stamp
