project(
	'c8-files',
	'c',
	version: '0.1.0',
	license: 'CC0-1.0',
	meson_version: '>=1.3.0',
	default_options: ['c_std=c11', 'warning_level=2', 'buildtype=debugoptimized', 'werror=false'],
)

add_project_arguments(
	'-D_POSIX_C_SOURCE=200809L',
	'-Wno-unused-parameter',
	'-Wno-missing-field-initializers',
	language: 'c',
)

c8ui = dependency('c8ui')
# stealth.h: stand-ins for the login and the PC's name (stealth mode)
c8base = dependency('c8-base')
gio = dependency('gio-2.0')
xkbcommon = dependency('xkbcommon')
# Extracting and making archives
libarchive = dependency('libarchive', version: '>=3.6')

libexecdir = get_option('prefix') / get_option('libexecdir')

# Reads archives for Extract, inside bubblewrap: only libarchive, so the
# sandbox needs nothing of ours but this
executable(
	'c8-files-unpack',
	files('src/unpack.c'),
	dependencies: [libarchive],
	install: true,
	install_dir: get_option('libexecdir'),
)

executable(
	'c8-files',
	files('src/main.c', 'src/folder.c', 'src/places.c', 'src/view.c',
		'src/ops.c', 'src/portal.c', 'src/prefs.c',
		'src/openwith.c', 'src/props.c', 'src/mount.c',
		'src/filemanager.c', 'src/archive.c'),
	dependencies: [c8ui, c8base, gio, xkbcommon, libarchive],
	c_args: ['-DUNPACK_PATH="' + libexecdir / 'c8-files-unpack' + '"'],
	install: true,
)

bindir = get_option('prefix') / get_option('bindir')
conf = {'bindir': bindir}

# In Start, and the app for folders and archives (MimeType): the archives
# it looks into (archive.c), less disk images and packages, which other
# apps are usually for
desktop = configure_file(input: 'data/org.cont8nuum.Files.desktop.in',
	output: 'org.cont8nuum.Files.desktop', configuration: conf)
install_data(desktop, install_dir: get_option('datadir') / 'applications')
# and the default for them in cont8nuum sessions, even beside another
# app that claims them (Ark, File Roller): GIO and xdg-open read
# DESKTOP-mimeapps.list from the data dirs, after the user's own
install_data('data/cont8nuum-mimeapps.list',
	install_dir: get_option('datadir') / 'applications')

# The file picker: D-Bus starts us for the portal's calls
service = configure_file(
	input: 'data/org.freedesktop.impl.portal.desktop.c8.service.in',
	output: 'org.freedesktop.impl.portal.desktop.c8.service',
	configuration: conf)
install_data(service, install_dir: get_option('datadir') / 'dbus-1/services')

# "Open containing folder" in browsers and the like: D-Bus starts us
fm_service = configure_file(
	input: 'data/org.freedesktop.FileManager1.service.in',
	output: 'org.freedesktop.FileManager1.service',
	configuration: conf)
install_data(fm_service, install_dir: get_option('datadir') / 'dbus-1/services')

# xdg-desktop-portal reads .portal files from its own data dir only
portal_dir = get_option('portal_dir')
if portal_dir == '' and get_option('prefix').startswith('/usr')
	portal_dir = '/usr/share/xdg-desktop-portal/portals'
endif
if portal_dir != ''
	install_data('data/c8.portal', install_dir: portal_dir)
endif

gnome = import('gnome')
gnome.post_install(update_desktop_database: true)
