From 7e980225821aaa3073fc46d2dc248e9571d3c298 Mon Sep 17 00:00:00 2001 From: David Härdeman Date: Wed, 24 Jun 2020 10:32:54 +0200 Subject: Organise linker and cc flags a bit --- meson.build | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/meson.build b/meson.build index eb9ae1e..8160a0a 100644 --- a/meson.build +++ b/meson.build @@ -6,17 +6,35 @@ project('minecproxy', 'c_std=gnu18', 'sysconfdir=/etc', 'warning_level=2', + 'b_lto=true', ] ) cc = meson.get_compiler('c') -basic_disabled_warnings = [ - '-Wno-sign-compare', +cc_flags = [ + '-D_GNU_SOURCE', ] -add_project_arguments(cc.get_supported_arguments(basic_disabled_warnings), language : 'c') +cc_warning_flags = [ + '-Wno-sign-compare', # Lots of pointless warnings +] +cc_flags += cc.get_supported_arguments(cc_warning_flags) +cc_extra_flags = [ + '-ffunction-sections', # Generate each function in a separate section + '-fdata-sections', # Ditto for data +] +cc_flags += cc.get_supported_arguments(cc_extra_flags) +add_project_arguments(cc_flags, language: 'c') -add_project_arguments('-D_GNU_SOURCE', language: 'c') +ld_flags = [] +ld_extra_flags = [ + '-Wl,-z,defs', # Detect and reject underlinking + '-Wl,-z,now', # Disable lazy binding + '-Wl,-z,relro', # Read-only segments after relocation + '-Wl,--gc-sections', # Remove unused sections +] +ld_flags += cc.get_supported_link_arguments(ld_extra_flags) +add_project_link_arguments(ld_flags, language: 'c') sysconfdir = join_paths(get_option('prefix'), get_option('sysconfdir'), meson.project_name()) mainconfname = meson.project_name() + '.conf' -- cgit v1.2.3