filter_filter_dir = @top_srcdir@/src/filter/filter
filter_backend_dir = @top_srcdir@/src/filter/backend
filter_frontend_dir = @top_srcdir@/src/filter/frontend
caml_link_dirs = -cclib -lcamlidl -cclib -L$(bindings_dir)
bindings_dir =  ../bindings-pkcs11
mem_prot_opt_caml=-ccopt -fPIC -ccopt -fPIE -ccopt -Wl,-z,relro,-z,now -ccopt -fstack-protector

all:	@caml_rpc_gen@
	#Compile RPC files
	ocamlfind ocamlopt @ocaml_options@ -package "rpc" -o pkcs11_rpc_aux -c @srcdir@/pkcs11_rpc_aux.mli
	ocamlfind ocamlopt @ocaml_options@ -package "rpc" -o pkcs11_rpc_aux -c @srcdir@/pkcs11_rpc_aux.ml
	ocamlfind ocamlopt @ocaml_options@ -package "rpc" -o pkcs11_rpc_clnt -c @srcdir@/pkcs11_rpc_clnt.mli
	ocamlfind ocamlopt @ocaml_options@ -package "rpc" -o pkcs11_rpc_clnt -c @srcdir@/pkcs11_rpc_clnt.ml
	ocamlfind ocamlopt @ocaml_options@ -package "rpc" -o pkcs11_rpc_srv -c @srcdir@/pkcs11_rpc_srv.mli
	ocamlfind ocamlopt @ocaml_options@ -package "rpc" -o pkcs11_rpc_srv -c @srcdir@/pkcs11_rpc_srv.ml
	#Build RPC helpers
	ocamlopt @ocaml_options@ -I $(bindings_dir) -o rpc_helpers -c @srcdir@/rpc_helpers.ml
	#Build a library from RPC files
	ocamlopt @ocaml_options@ -o pkcs11_rpclib.cmxa -a pkcs11_rpc_aux.cmx pkcs11_rpc_clnt.cmx pkcs11_rpc_srv.cmx rpc_helpers.cmx

rpc:
	#Ocaml RPC Generation
	ocamlrpcgen -aux -int unboxed -hyper int64 @srcdir@/pkcs11_rpc.x
	ocamlrpcgen -clnt -int unboxed -hyper int64 @srcdir@/pkcs11_rpc.x
	ocamlrpcgen -srv2 -int unboxed -hyper int64 @srcdir@/pkcs11_rpc.x

#test:
#	#Compile Test file
#	ocamlopt $(include_dirs) -c test_pkcs11.ml
#	ocamlfind ocamlopt -package "rpc" -linkpkg $(bindings_dir)/pkcs11.cmxa pkcs11_rpclib.cmxa client.cmx test_pkcs11.cmx $(caml_link_dirs) -o test_pkcs11_rpc

clean_rpc:
	# Rmove old RPC generated files
	@rm -f @caml_rpc_clean@

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@/*.astamp @srcdir@/*.cstamp @srcdir@/*.s2stamp @srcdir@/test_pkcs11_rpc
