From 6ec7928ad91bb4806aaeaecb7aed81cb1b0e66d3 Mon Sep 17 00:00:00 2001
From: Esben Haabendal <esben.haabendal@huawei.com>
Date: Thu, 16 Sep 2021 15:39:37 +0200
Subject: [PATCH] hc-gen: Add recipe for building OpenHarmony hc-gen tool

The hc-gen tool is used to convert HDF (Hardware Driver Foundation)
configuration source files (.hcs) to HDF configuration binary files (.hcb).

Signed-off-by: Esben Haabendal <esben.haabendal@huawei.com>
---
 .../hc-gen/files/cxx-and-flags.patch          | 25 +++++++++++++++++
 recipes-devtools/hc-gen/hc-gen_3.0.bb         | 27 +++++++++++++++++++
 2 files changed, 52 insertions(+)
 create mode 100644 recipes-devtools/hc-gen/files/cxx-and-flags.patch
 create mode 100644 recipes-devtools/hc-gen/hc-gen_3.0.bb

diff --git a/recipes-devtools/hc-gen/files/cxx-and-flags.patch b/recipes-devtools/hc-gen/files/cxx-and-flags.patch
new file mode 100644
index 00000000..14287b0e
--- /dev/null
+++ b/recipes-devtools/hc-gen/files/cxx-and-flags.patch
@@ -0,0 +1,25 @@
+# SPDX-FileCopyrightText: Huawei Inc.
+#
+# SPDX-License-Identifier: Apache-2.0
+
+Use $CXX, $CXXFLAGS and $LDFLAGS environment variables, for proper Bitbake
+integration.
+
+Signed-off-by: Esben Haabendal <esben.haabendal@huawei.com>
+Upstream-Status: Inappropriate
+
+--- a/Makefile
++++ b/Makefile
+@@ -2,9 +2,9 @@ Q = @
+ BUILD_DIR := build
+ TARGET := $(BUILD_DIR)/hc-gen
+ 
+-CXX := c++
+-CXX_FLAGS := -std=gnu++14
+-CXX_LD_FLAGS := -lstdc++
++CXX ?= c++
++CXX_FLAGS := -std=gnu++14 $(CXXFLAGS)
++CXX_LD_FLAGS := -lstdc++ $(LDFLAGS)
+ 
+ SRCS := $(wildcard src/*.cpp)
+ OBJECTS := $(patsubst %.cpp,$(BUILD_DIR)/%.o,$(SRCS))
diff --git a/recipes-devtools/hc-gen/hc-gen_3.0.bb b/recipes-devtools/hc-gen/hc-gen_3.0.bb
new file mode 100644
index 00000000..14e75024
--- /dev/null
+++ b/recipes-devtools/hc-gen/hc-gen_3.0.bb
@@ -0,0 +1,27 @@
+# SPDX-FileCopyrightText: Huawei Inc.
+#
+# SPDX-License-Identifier: Apache-2.0
+
+SUMMARY = "Meta-build system that generates build files for Ninja"
+LICENSE = "GPL-2.0-or-later | BSD-3-Clause"
+LIC_FILES_CHKSUM = "file://../../LICENSE;md5=e97719e0c951ddc23a7d37facffdf32a"
+
+BBCLASSEXTEND = "native nativesdk"
+
+DEPENDS += "bison-native flex-native"
+
+SRC_URI = "git://gitee.com/openharmony/drivers_framework.git;protocol=https;branch=OpenHarmony-3.0-LTS"
+SRCREV = "9a26a7542281dcab90e7c0e9aa33c921171117cb"
+
+SRC_URI:append = " file://cxx-and-flags.patch"
+
+S = "${WORKDIR}/git/tools/hc-gen"
+
+EXTRA_OEMAKE += "CC='${CC}' CFLAGS='${CFLAGS}' LDFLAGS='${LDFLAGS}'"
+
+# Include debug symbols in build (bitbake will strip place them in -dbg package)
+EXTRA_OEMAKE += "BUILD_TYPE=debug"
+
+do_install () {
+    install -D -t ${D}${bindir} -m 755 ${S}/build/hc-gen
+}
-- 
GitLab