mailarchive of the pengutronix oss-tools mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: oss-tools@pengutronix.de
Subject: [OSS-Tools] [PATCH 1/5] Add meson as build system
Date: Wed, 31 May 2023 17:31:21 +0200	[thread overview]
Message-ID: <20230531153125.1408092-2-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20230531153125.1408092-1-a.fatoum@pengutronix.de>

This adds experimental support for building dt-utils with meson. The
hope is that the alternative meson.build will be easier to maintain.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 .gitignore        |   1 +
 README            |  20 ++++++
 check-news.sh     |  82 ++++++++++++++++++++++++
 meson.build       | 159 ++++++++++++++++++++++++++++++++++++++++++++++
 meson_options.txt |  25 ++++++++
 version-gen       |   3 +
 version.h.in      |   3 +
 7 files changed, 293 insertions(+)
 create mode 100755 check-news.sh
 create mode 100644 meson.build
 create mode 100644 meson_options.txt
 create mode 100755 version-gen
 create mode 100644 version.h.in

diff --git a/.gitignore b/.gitignore
index 5ee5535f544f..34df220d8723 100644
--- a/.gitignore
+++ b/.gitignore
@@ -15,6 +15,7 @@ Makefile.in
 /stamp-h1
 /tags
 /TAGS
+/build/
 
 /fdtdump
 /src/libdt-utils.pc
diff --git a/README b/README
index 46b4ea9c1508..0b4e96d6002e 100644
--- a/README
+++ b/README
@@ -13,6 +13,26 @@ For questions, feedback, patches, please send a mail to
 Note: you must be subscribed to post to this mailing list. You can do so by
 sending an empty mail to <oss-tools-subscribe@pengutronix.de>.
 
+Building from Sources
+---------------------
+
+Check out the latest git state:
+
+    git clone https://github.com/barebox/dt-utils
+    cd dt-utils
+
+And then build using autotools:
+
+    ./autogen.sh
+    ./configure
+    make
+
+There's also experimental support for building with meson.
+The intention is to deprecate autotools eventually in its favor. To build:
+
+    meson setup build
+    meson compile -C build
+
 Contributing
 ------------
 
diff --git a/check-news.sh b/check-news.sh
new file mode 100755
index 000000000000..e7e8fa6bb95d
--- /dev/null
+++ b/check-news.sh
@@ -0,0 +1,82 @@
+#!/bin/sh
+
+# Copyright (C) 2019 Red Hat, Inc.
+# Author: Bastien Nocera <hadess@hadess.net>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA.
+
+
+# Add to your top-level meson.build to check for an updated NEWS file
+# when doing a "dist" release, similarly to automake's check-news:
+# https://www.gnu.org/software/automake/manual/html_node/List-of-Automake-options.html
+#
+# Checks NEWS for the version number:
+# meson.add_dist_script(
+#   find_program('check-news.sh').path(),
+#   '@0@'.format(meson.project_version())
+# )
+#
+# Checks NEWS and data/foo.appdata.xml for the version number:
+# meson.add_dist_script(
+#   find_program('check-news.sh').path(),
+#   '@0@'.format(meson.project_version()),
+#   'NEWS',
+#   'data/foo.appdata.xml'
+# )
+
+usage()
+{
+	echo "$0 VERSION [FILES...]"
+	exit 1
+}
+
+check_version()
+{
+	VERSION=$1
+	# Look in the first 15 lines for NEWS files, but look
+	# everywhere for other types of files
+	if [ "$2" = "NEWS" ]; then
+		DATA=`sed 15q $SRC_ROOT/"$2"`
+	else
+		DATA=`cat $SRC_ROOT/"$2"`
+	fi
+	case "$DATA" in
+	*"$VERSION"*)
+		:
+		;;
+	*)
+		echo "$2 not updated; not releasing" 1>&2;
+		exit 1
+		;;
+	esac
+}
+
+SRC_ROOT=${MESON_DIST_ROOT:-"./"}
+
+if [ $# -lt 1 ] ; then usage ; fi
+
+VERSION=$1
+shift
+
+if [ $# -eq 0 ] ; then
+	check_version $VERSION 'NEWS'
+	exit 0
+fi
+
+for i in $@ ; do
+	check_version $VERSION "$i"
+done
+
+exit 0
diff --git a/meson.build b/meson.build
new file mode 100644
index 000000000000..22b522ea4d0e
--- /dev/null
+++ b/meson.build
@@ -0,0 +1,159 @@
+# Copyright 2013-2023 The DT-Utils Authors <oss-tools@pengutronix.de>
+# Homepage: https://git.pengutronix.de/cgit/tools/dt-utils
+
+project(
+  'dt-utils',
+  'c',
+  version : '2021.03.0',
+  meson_version : '>=0.51',
+  default_options: [
+    'c_std=gnu11',
+    'warning_level=2',
+  ],
+  license : 'GPL-2.0-only',
+)
+
+cc = meson.get_compiler('c')
+
+conf = configuration_data()
+# Statically define to be enabled to harmonize barebox' & dt-utils' code base.
+conf.set10('CONFIG_MTD', true)
+conf.set10('CONFIG_STATE', true)
+conf.set10('CONFIG_STATE_BACKWARD_COMPATIBLE', get_option('state-backward-compatibility'))
+
+meson.add_dist_script(
+  find_program('check-news.sh').path(),
+  '@0@'.format(meson.project_version())
+)
+
+prefixdir = get_option('prefix')
+if not prefixdir.startswith('/')
+        error('Prefix is not absolute: "@0@"'.format(prefixdir))
+endif
+sysconfdir = join_paths(prefixdir, get_option('sysconfdir'))
+conf.set('SYSCONFDIR', sysconfdir)
+libexecdir = join_paths(prefixdir, get_option('libexecdir'))
+conf.set('LIBEXECDIR', libexecdir)
+
+udevdep = dependency('libudev')
+
+c_flags = '''
+  -fno-strict-aliasing
+  -ffunction-sections
+  -fdata-sections
+'''.split()
+
+c_warn_flags = '''
+  -Wmissing-declarations
+  -Wmissing-prototypes
+  -Wnested-externs
+  -Wno-sign-compare
+  -Wno-unused-parameter
+  -Wchar-subscripts
+  -Wstrict-prototypes
+  -Wshadow
+  -Wformat-security
+  -Wtype-limits
+  -Wno-pointer-sign
+  -Wno-shadow
+'''.split()
+c_flags += cc.get_supported_arguments(c_warn_flags)
+add_project_arguments(c_flags, language : 'c')
+# enable GNU extensions (required!)
+add_project_arguments('-D_GNU_SOURCE', language : 'c')
+
+ld_flags = '''
+  -Wl,--gc-sections
+  -Wl,--as-needed
+'''.split()
+
+incdir = include_directories(['src/dt', 'src'])
+
+sources_libdt = files('''
+  src/crc32.c
+  src/libdt.c
+  src/fdt.c
+'''.split())
+
+if get_option('barebox-state')
+  sources_barebox_state = files('''
+    src/crypto/digest.c
+    src/crypto/hmac.c
+    src/crypto/sha1.c
+    src/crypto/sha2.c
+    src/keystore-blob.c
+    src/base64.c
+    src/barebox-state/backend_bucket_circular.c
+    src/barebox-state/backend_bucket_direct.c
+    src/barebox-state/backend_format_dtb.c
+    src/barebox-state/backend_format_raw.c
+    src/barebox-state/backend_storage.c
+    src/barebox-state/state.c
+    src/barebox-state/state_variables.c
+    src/barebox-state.c
+  '''.split())
+endif
+
+sources_dtblint = files('''
+  src/dtblint.c
+  src/dtblint-imx-pinmux.c
+  src/dtblint.h
+'''.split())
+
+sources_fdtdump = files('''
+src/fdtdump.c
+'''.split())
+
+config_h = configure_file(
+  output : 'config.h',
+  configuration : conf
+)
+add_project_arguments('-include', meson.current_build_dir() / 'config.h', language : 'c')
+
+version_h = vcs_tag(
+  input : 'version.h.in',
+  output : 'version.h',
+)
+versiondep = declare_dependency(sources: version_h)
+
+meson.add_dist_script('version-gen', meson.project_version())
+
+mapfile = 'src/libdt-utils.sym'
+libdt_ld_flags = '-Wl,--version-script,@0@/@1@'.format(meson.current_source_dir(), mapfile)
+
+libdt = shared_library('dt-utils',
+  sources_libdt,
+  include_directories : incdir,
+  link_args : ld_flags + ['-Wl,--no-undefined', libdt_ld_flags],
+  link_depends : mapfile,
+  c_args : ['-include', meson.current_build_dir() / 'version.h'],
+  dependencies : [udevdep, versiondep],
+  gnu_symbol_visibility : 'default',
+  install : true)
+
+executable('barebox-state',
+  sources_barebox_state,
+  include_directories : incdir,
+  link_args : ld_flags,
+  c_args : ['-include', meson.current_build_dir() / 'version.h'],
+  dependencies : [versiondep],
+  link_with : libdt,
+  install : true)
+
+executable('fdtdump',
+  sources_fdtdump,
+  include_directories : incdir,
+  link_args : ld_flags,
+  c_args : ['-include', meson.current_build_dir() / 'version.h'],
+  dependencies : [versiondep],
+  link_with : libdt,
+  install : true)
+
+executable('dtblint',
+  sources_dtblint,
+  include_directories : incdir,
+  link_args : ld_flags,
+  c_args : ['-include', meson.current_build_dir() / 'version.h'],
+  dependencies : [versiondep],
+  link_with : libdt,
+  install : true)
diff --git a/meson_options.txt b/meson_options.txt
new file mode 100644
index 000000000000..f80643aa6c73
--- /dev/null
+++ b/meson_options.txt
@@ -0,0 +1,25 @@
+# feature options
+option(
+  'state-backward-compatibility',
+  type : 'boolean',
+  value : 'false',
+  description : 'barebox-state: when using the "direct" storage backend, keep the on-disk format readable by barebox <= v2016.08.0')
+
+option(
+  'lock-device',
+  type : 'boolean',
+  value : 'false',
+  description : 'lock device node instead of creating lockfile in /run')
+
+# build options
+option(
+  'barebox-state',
+  type : 'boolean',
+  value : 'true',
+  description : 'Build barebox-state utility')
+
+option(
+  'tests',
+  type : 'boolean',
+  value : 'true',
+  description : 'Enable/Disable test suite')
diff --git a/version-gen b/version-gen
new file mode 100755
index 000000000000..bf77f50bc1e7
--- /dev/null
+++ b/version-gen
@@ -0,0 +1,3 @@
+#!/bin/sh
+
+echo "$1" > "$MESON_DIST_ROOT/.tarball-version"
diff --git a/version.h.in b/version.h.in
new file mode 100644
index 000000000000..a0c0ce367ab7
--- /dev/null
+++ b/version.h.in
@@ -0,0 +1,3 @@
+#define PACKAGE_STRING "dt-utils @VCS_TAG@"
+
+#define PACKAGE_VERSION "@VCS_TAG@"
-- 
2.39.2




  reply	other threads:[~2023-05-31 15:31 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-31 15:31 [OSS-Tools] [PATCH 0/5] Add meson support and first test suite Ahmad Fatoum
2023-05-31 15:31 ` Ahmad Fatoum [this message]
2023-05-31 15:31 ` [OSS-Tools] [PATCH 2/5] state: add option to lock device node Ahmad Fatoum
2023-05-31 15:31 ` [OSS-Tools] [PATCH 3/5] meson: add simple integration test Ahmad Fatoum
2023-05-31 15:31 ` [OSS-Tools] [PATCH 4/5] libdt: add CONFIG_TEST_LOOPBACK Ahmad Fatoum
2023-06-12 11:56   ` Ahmad Fatoum
2023-05-31 15:31 ` [OSS-Tools] [PATCH 5/5] test: add barebox-state loop block device tests Ahmad Fatoum
2023-06-05 10:17 ` [OSS-Tools] [PATCH 0/5] Add meson support and first test suite Roland Hieber
2023-06-12 11:57   ` Ahmad Fatoum

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230531153125.1408092-2-a.fatoum@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --cc=oss-tools@pengutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox