From dc80281ba0d325e71ff6cd2c1d7d525c889b3996 Mon Sep 17 00:00:00 2001
From: Rosen Penev <rosenp@gmail.com>
Date: Sat, 2 Jan 2021 21:05:53 -0800
Subject: [PATCH] add meson build

meson compiles faster and is simpler than autotools.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
 addshare/meson.build | 11 +++++++++++
 adduser/meson.build  | 13 +++++++++++++
 control/meson.build  |  9 +++++++++
 lib/meson.build      | 18 ++++++++++++++++++
 meson.build          | 33 +++++++++++++++++++++++++++++++++
 meson_options.txt    |  4 ++++
 mountd/meson.build   | 17 +++++++++++++++++
 7 files changed, 105 insertions(+)
 create mode 100644 addshare/meson.build
 create mode 100644 adduser/meson.build
 create mode 100644 control/meson.build
 create mode 100644 lib/meson.build
 create mode 100644 meson.build
 create mode 100644 meson_options.txt
 create mode 100644 mountd/meson.build

--- /dev/null
+++ b/addshare/meson.build
@@ -0,0 +1,11 @@
+addshare = executable(
+  'ksmbd.addshare',
+  'share_admin.c',
+  'addshare.c',
+  'share_admin.h',
+  dependencies: [glib_dep, netlink_dep],
+  include_directories: tools_incdir,
+  link_with: libksmbdtools,
+  install: true,
+  install_dir: get_option('sbindir'),
+)
--- /dev/null
+++ b/adduser/meson.build
@@ -0,0 +1,13 @@
+adduser = executable(
+  'ksmbd.adduser',
+  'md4_hash.c',
+  'user_admin.c',
+  'adduser.c',
+  'md4_hash.h',
+  'user_admin.h',
+  dependencies: [glib_dep, netlink_dep],
+  include_directories: tools_incdir,
+  link_with: libksmbdtools,
+  install: true,
+  install_dir: get_option('sbindir'),
+)
--- /dev/null
+++ b/control/meson.build
@@ -0,0 +1,9 @@
+control = executable(
+  'ksmbd.control',
+  'control.c',
+  dependencies: [glib_dep, netlink_dep],
+  include_directories: tools_incdir,
+  link_with: libksmbdtools,
+  install: true,
+  install_dir: get_option('sbindir'),
+)
--- /dev/null
+++ b/lib/meson.build
@@ -0,0 +1,18 @@
+core_files = [
+  'management/tree_conn.c',
+  'management/user.c',
+  'management/share.c',
+  'management/session.c',
+  'config_parser.c',
+  'ksmbdtools.c',
+]
+
+if krb5_dep.found()
+  core_files += [
+    'management/spnego.c',
+    'asn1.c',
+    'management/spnego_krb5.c',
+  ]
+endif
+
+libksmbdtools = static_library('ksmbdtools', core_files, include_directories: tools_incdir, dependencies: [glib_dep, krb5_dep])
--- /dev/null
+++ b/meson.build
@@ -0,0 +1,33 @@
+project('ksmbsd-tools', 'c',
+  version: run_command(find_program('awk'), '''/define KSMBD_TOOLS_VERSION / \
+    { gsub(/"/,"",$3); printf "%s", $3 }''', 'include/version.h', check: true).stdout(),
+  default_options: 'c_std=gnu99')
+
+tools_incdir = include_directories(['include', '.'])
+
+glib_dep = dependency('glib-2.0', static: true)
+netlink_dep = dependency('libnl-genl-3.0')
+krb5_dep = dependency('krb5', required: get_option('krb5'))
+
+cc = meson.get_compiler('c')
+
+cdata = configuration_data()
+add_project_arguments('-DHAVE_CONFIG_H', language: 'c')
+if krb5_dep.found()
+  cdata.set('CONFIG_KRB5', krb5_dep.found())
+  cdata.set('HAVE_KRB5_KEYBLOCK_KEYVALUE', cc.has_member('krb5_keyblock', 'keyvalue', prefix: '#include <krb5.h>'))
+  cdata.set('HAVE_KRB5_AUTHENTICATOR_CLIENT', cc.has_member('krb5_authenticator', 'client', prefix: '#include <krb5.h>'))
+  cdata.set('HAVE_KRB5_AUTH_CON_GETRECVSUBKEY', cc.has_function('krb5_auth_con_getrecvsubkey', dependencies: krb5_dep))
+  cdata.set('HAVE_KRB5_AUTH_CON_GETAUTHENTICATOR_DOUBLE_POINTER', cc.compiles('''#include <krb5.h>
+    krb5_error_code krb5_auth_con_getauthenticator(krb5_context, krb5_auth_context, krb5_authenticator**);''', dependencies: krb5_dep))
+endif
+cfile = configure_file(
+  output: 'config.h',
+  configuration: cdata,
+)
+
+subdir('lib')
+subdir('addshare')
+subdir('adduser')
+subdir('control')
+subdir('mountd')
--- /dev/null
+++ b/meson_options.txt
@@ -0,0 +1,4 @@
+option('krb5', type : 'feature',
+  description : 'Build with Kerberos support',
+  value : 'disabled',
+)
--- /dev/null
+++ b/mountd/meson.build
@@ -0,0 +1,17 @@
+mountd = executable(
+  'ksmbd.mountd',
+  'worker.c',
+  'ipc.c',
+  'rpc.c',
+  'rpc_srvsvc.c',
+  'rpc_wkssvc.c',
+  'mountd.c',
+  'smbacl.c',
+  'rpc_samr.c',
+  'rpc_lsarpc.c',
+  dependencies: [glib_dep, netlink_dep],
+  include_directories: tools_incdir,
+  link_with: libksmbdtools,
+  install: true,
+  install_dir: get_option('sbindir'),
+)