devicetree-compiler.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Allow static building with meson
@ 2022-06-29 16:35 Tero Tervala
       [not found] ` <20220629163557.932298-1-tero.tervala-ddXEi6N5mqbQT0dZR+AlfA@public.gmane.org>
  0 siblings, 1 reply; 2+ messages in thread
From: Tero Tervala @ 2022-06-29 16:35 UTC (permalink / raw)
  To: devicetree-compiler-u79uwXL29TY76Z2rM5mHXA; +Cc: Tero Tervala

Added "static-build" option in the meson_options.txt.
Setting it to "true" allows static building.

Signed-off-by: Tero Tervala <tero.tervala-ddXEi6N5mqbQT0dZR+AlfA@public.gmane.org>
---
 libfdt/meson.build |  8 +++++++-
 meson.build        | 14 ++++++++++++--
 meson_options.txt  |  2 ++
 tests/meson.build  |  9 +++++++--
 4 files changed, 28 insertions(+), 5 deletions(-)

diff --git a/libfdt/meson.build b/libfdt/meson.build
index 71f29b6..240bdf4 100644
--- a/libfdt/meson.build
+++ b/libfdt/meson.build
@@ -31,9 +31,15 @@ libfdt_a = static_library(
 
 libfdt_inc = include_directories('.')
 
+if static_build
+  link_with = libfdt_a
+else
+  link_with = libfdt
+endif
+
 libfdt_dep = declare_dependency(
   include_directories: libfdt_inc,
-  link_with: libfdt,
+  link_with: link_with,
 )
 
 install_headers(
diff --git a/meson.build b/meson.build
index b23ea1b..78251eb 100644
--- a/meson.build
+++ b/meson.build
@@ -31,8 +31,16 @@ add_project_arguments(
   language: 'c'
 )
 
+if get_option('static-build')
+  static_build = true
+  extra_link_args = ['-static']
+else
+  static_build = false
+  extra_link_args = []
+endif
+
 yamltree = 'yamltree.c'
-yaml = dependency('yaml-0.1', required: get_option('yaml'))
+yaml = dependency('yaml-0.1', required: get_option('yaml'), static: static_build)
 if not yaml.found()
   add_project_arguments('-DNO_YAML', language: 'c')
   yamltree = []
@@ -85,6 +93,7 @@ if get_option('tools')
       ],
       dependencies: util_dep,
       install: true,
+      link_args: extra_link_args,
     )
   endif
 
@@ -105,10 +114,11 @@ if get_option('tools')
     ],
     dependencies: [util_dep, yaml],
     install: true,
+    link_args: extra_link_args,
   )
 
   foreach e: ['fdtdump', 'fdtget', 'fdtput', 'fdtoverlay']
-    executable(e, files(e + '.c'), dependencies: util_dep, install: true)
+    executable(e, files(e + '.c'), dependencies: util_dep, install: true, link_args: extra_link_args)
   endforeach
 
   install_data(
diff --git a/meson_options.txt b/meson_options.txt
index ea59c28..82621c3 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -8,3 +8,5 @@ option('valgrind', type: 'feature', value: 'auto',
        description: 'Valgrind support')
 option('python', type: 'feature', value: 'auto',
        description: 'Build pylibfdt Python library')
+option('static-build', type: 'boolean', value: false,
+       description: 'Build static binaries')
diff --git a/tests/meson.build b/tests/meson.build
index 3776fef..4ac154a 100644
--- a/tests/meson.build
+++ b/tests/meson.build
@@ -96,15 +96,20 @@ tests += [
 ]
 
 dl = cc.find_library('dl', required: false)
-if dl.found()
+if dl.found() and not static_build
   tests += [
     'asm_tree_dump',
     'value-labels',
   ]
 endif
 
+test_deps = [testutil_dep, util_dep, libfdt_dep]
+if not static_build
+  test_deps += [dl]
+endif
+
 foreach t: tests
-  executable(t, files(t + '.c'), dependencies: [testutil_dep, util_dep, libfdt_dep, dl])
+  executable(t, files(t + '.c'), dependencies: test_deps, link_args: extra_link_args)
 endforeach
 
 run_tests = find_program('run_tests.sh')
-- 
2.33.3


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] Allow static building with meson
       [not found] ` <20220629163557.932298-1-tero.tervala-ddXEi6N5mqbQT0dZR+AlfA@public.gmane.org>
@ 2022-07-27  6:50   ` David Gibson
  0 siblings, 0 replies; 2+ messages in thread
From: David Gibson @ 2022-07-27  6:50 UTC (permalink / raw)
  To: Tero Tervala; +Cc: devicetree-compiler-u79uwXL29TY76Z2rM5mHXA

[-- Attachment #1: Type: text/plain, Size: 4013 bytes --]

On Wed, Jun 29, 2022 at 07:35:57PM +0300, Tero Tervala wrote:
> Added "static-build" option in the meson_options.txt.
> Setting it to "true" allows static building.
> 
> Signed-off-by: Tero Tervala <tero.tervala-ddXEi6N5mqbQT0dZR+AlfA@public.gmane.org>

Thanks for adding the meson support, I've merged this as well.

It took me way too long to figure out how you actually *set* these
options with meson :(.  Neither meson --help nor the online meson
documentation are as helpful as onw would hope.

We really need instructions for invoking meson in the README.

> ---
>  libfdt/meson.build |  8 +++++++-
>  meson.build        | 14 ++++++++++++--
>  meson_options.txt  |  2 ++
>  tests/meson.build  |  9 +++++++--
>  4 files changed, 28 insertions(+), 5 deletions(-)
> 
> diff --git a/libfdt/meson.build b/libfdt/meson.build
> index 71f29b6..240bdf4 100644
> --- a/libfdt/meson.build
> +++ b/libfdt/meson.build
> @@ -31,9 +31,15 @@ libfdt_a = static_library(
>  
>  libfdt_inc = include_directories('.')
>  
> +if static_build
> +  link_with = libfdt_a
> +else
> +  link_with = libfdt
> +endif
> +
>  libfdt_dep = declare_dependency(
>    include_directories: libfdt_inc,
> -  link_with: libfdt,
> +  link_with: link_with,
>  )
>  
>  install_headers(
> diff --git a/meson.build b/meson.build
> index b23ea1b..78251eb 100644
> --- a/meson.build
> +++ b/meson.build
> @@ -31,8 +31,16 @@ add_project_arguments(
>    language: 'c'
>  )
>  
> +if get_option('static-build')
> +  static_build = true
> +  extra_link_args = ['-static']
> +else
> +  static_build = false
> +  extra_link_args = []
> +endif
> +
>  yamltree = 'yamltree.c'
> -yaml = dependency('yaml-0.1', required: get_option('yaml'))
> +yaml = dependency('yaml-0.1', required: get_option('yaml'), static: static_build)
>  if not yaml.found()
>    add_project_arguments('-DNO_YAML', language: 'c')
>    yamltree = []
> @@ -85,6 +93,7 @@ if get_option('tools')
>        ],
>        dependencies: util_dep,
>        install: true,
> +      link_args: extra_link_args,
>      )
>    endif
>  
> @@ -105,10 +114,11 @@ if get_option('tools')
>      ],
>      dependencies: [util_dep, yaml],
>      install: true,
> +    link_args: extra_link_args,
>    )
>  
>    foreach e: ['fdtdump', 'fdtget', 'fdtput', 'fdtoverlay']
> -    executable(e, files(e + '.c'), dependencies: util_dep, install: true)
> +    executable(e, files(e + '.c'), dependencies: util_dep, install: true, link_args: extra_link_args)
>    endforeach
>  
>    install_data(
> diff --git a/meson_options.txt b/meson_options.txt
> index ea59c28..82621c3 100644
> --- a/meson_options.txt
> +++ b/meson_options.txt
> @@ -8,3 +8,5 @@ option('valgrind', type: 'feature', value: 'auto',
>         description: 'Valgrind support')
>  option('python', type: 'feature', value: 'auto',
>         description: 'Build pylibfdt Python library')
> +option('static-build', type: 'boolean', value: false,
> +       description: 'Build static binaries')
> diff --git a/tests/meson.build b/tests/meson.build
> index 3776fef..4ac154a 100644
> --- a/tests/meson.build
> +++ b/tests/meson.build
> @@ -96,15 +96,20 @@ tests += [
>  ]
>  
>  dl = cc.find_library('dl', required: false)
> -if dl.found()
> +if dl.found() and not static_build
>    tests += [
>      'asm_tree_dump',
>      'value-labels',
>    ]
>  endif
>  
> +test_deps = [testutil_dep, util_dep, libfdt_dep]
> +if not static_build
> +  test_deps += [dl]
> +endif
> +
>  foreach t: tests
> -  executable(t, files(t + '.c'), dependencies: [testutil_dep, util_dep, libfdt_dep, dl])
> +  executable(t, files(t + '.c'), dependencies: test_deps, link_args: extra_link_args)
>  endforeach
>  
>  run_tests = find_program('run_tests.sh')

-- 
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-07-27  6:50 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-06-29 16:35 [PATCH] Allow static building with meson Tero Tervala
     [not found] ` <20220629163557.932298-1-tero.tervala-ddXEi6N5mqbQT0dZR+AlfA@public.gmane.org>
2022-07-27  6:50   ` David Gibson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).