Modify to create .pc file with BuildRequire packages
authorSangYoun Kwak <sy.kwak@samsung.com>
Tue, 14 May 2024 06:27:52 +0000 (15:27 +0900)
committerSangYoun Kwak <sy.kwak@samsung.com>
Thu, 16 May 2024 03:16:24 +0000 (12:16 +0900)
If some other package BuildRequires this hal-rootstrap package with
pkgconfig, it refers hal-rootstrap.pc for the locations of includes and
libraries.
Thus, to make them buildable, it is required to include all possible
paths of headers and libraries in the .pc file.
The script modify_pc.py reads every .pc files then modifies
hal-rootstrap.pc file to include them.

Change-Id: Icf114a20a705b7fd8854041c0ab59e18a192fc30
Signed-off-by: SangYoun Kwak <sy.kwak@samsung.com>
make_rootstrap.sh
modify_pc.py [new file with mode: 0755]
packaging/hal-rootstrap.pc.in
packaging/hal-rootstrap.spec

index a64ff5bcbcf4dec5f6b5c366b14fb4b9a1359be3..e92e4648ff64a74093834fffdb0f58774c850565 100755 (executable)
@@ -319,10 +319,10 @@ if [ "$OPT_TARGET" = true ]; then
        remove_dir ${DIR_TMP} ${DIR_TARGET}
        callRootstrapGen target ${RPM_PKG_SVR_TARGET} ${BASE_PKG_SVR_TARGET}
 
-       log "[INFO] Postscript ${DIR_TARGET}";
+       log "[INFO] Postscript ${GBS_BUILDROOT}";
 
-       mv ${DIR_TARGET}/usr/include/asm-arm ${DIR_TARGET}/usr/include/asm
-       mv ${DIR_TARGET}/usr/include/base/deprecated/* ${DIR_TARGET}/usr/include/base/
+       mv ${GBS_BUILDROOT}/usr/include/asm-arm ${GBS_BUILDROOT}/usr/include/asm
+       mv ${GBS_BUILDROOT}/usr/include/base/deprecated/* ${GBS_BUILDROOT}/usr/include/base/
 
        if [ "$INTERNAL" = false ]; then
                echo "remove Non-Public EFL API"
@@ -335,16 +335,16 @@ if [ "$OPT_TARGET" = true ]; then
 
        if [ "$INTERNAL" = true ]; then
                log "[INFO] Skip .. removing dlog-internal.h"
-               find ${DIR_TARGET} -name "dlog.h" -exec perl -pi -e 's/#include\ \"dlog-internal\.h\"//g' {} \;
+               find ${GBS_BUILDROOT} -name "dlog.h" -exec perl -pi -e 's/#include\ \"dlog-internal\.h\"//g' {} \;
        else
-               find ${DIR_TARGET} -name "dlog.h" -exec perl -pi -e 's/#include\ \"dlog-internal\.h\"//g' {} \;
+               find ${GBS_BUILDROOT} -name "dlog.h" -exec perl -pi -e 's/#include\ \"dlog-internal\.h\"//g' {} \;
        fi
 
-       if [ ! -d "${DIR_TARGET}/usr/lib" ]; then
-               mkdir -p ${DIR_TARGET}/usr/lib
+       if [ ! -d "${GBS_BUILDROOT}/usr/lib" ]; then
+               mkdir -p ${GBS_BUILDROOT}/usr/lib
        fi
 
-       for FILE in $(find ${DIR_TARGET} -name "*.so.*mobile");
+       for FILE in $(find ${GBS_BUILDROOT} -name "*.so.*mobile");
        do
                mv ${FILE} ${FILE%.mobile};
        done;
diff --git a/modify_pc.py b/modify_pc.py
new file mode 100755 (executable)
index 0000000..b86e2ec
--- /dev/null
@@ -0,0 +1,61 @@
+#!/usr/bin/python3
+
+from sys import argv
+from os import listdir
+from re import compile as regex_compile
+
+include_dir_root_path = "hal_rootstrap_dir"
+
+regex_assignment = regex_compile("\s*([-_a-zA-Z0-9]+)\s*=\s*([^\s]*)")
+regex_declaration = regex_compile("\s*([-_a-zA-Z0-9]+)\s*:\s*(.+)\s*")
+regex_substitution = regex_compile("\${([-_a-zA-Z0-9]+)}")
+
+libs = { "-L${" + include_dir_root_path + "}" }
+cflags = { "-I${" + include_dir_root_path + "}" }
+cxxflags = { "-I${" + include_dir_root_path + "}" }
+
+def parse_pc(fname):
+       variables = dict()
+
+       f = open(fname, "r")
+       for line in f:
+               if matches := regex_assignment.findall(line):
+                       symbol, value = matches[0][0], matches[0][1]
+                       matched_symbols = regex_substitution.findall(value)
+                       for matched_symbol in matched_symbols:
+                               value = value.replace("${{{}}}".format(matched_symbol), "{}".format(variables[matched_symbol]))
+                       variables[symbol] = value
+                       continue
+               if matches := regex_declaration.findall(line):
+                       symbol, value = matches[0][0], matches[0][1]
+                       matched_symbols = regex_substitution.findall(value)
+                       for matched_symbol in matched_symbols:
+                               value = value.replace("${{{}}}".format(matched_symbol), "{}".format(variables[matched_symbol]))
+                       if symbol == "Libs":
+                               libs.update(set(map(lambda value: value[:2] + "${" + include_dir_root_path + "}" + value[2:] if value[2] == '/' else value, value.split())))
+                               continue
+                       if symbol == "Cflags":
+                               cflags.update((map(lambda value: value[:2] + "${" + include_dir_root_path + "}" + value[2:] if value[2] == '/' else value, value.split())))
+                               continue
+                       if symbol == "CXXflags":
+                               cxxflags.update(list(map(lambda value: value[:2] + "${" + include_dir_root_path + "}" + value[2:] if value[2] == '/' else value, value.split())))
+                               continue
+
+       f.close()
+
+def write_to_pc(fname):
+       f = open(fname, "a")
+       f.write("\n")
+       f.write("Libs: {}\n".format(' '.join(libs)))
+       f.write("Cflags: {}\n".format(' '.join(cflags)))
+       f.write("CXXflags: {}\n".format(' '.join(cxxflags)))
+       f.close()
+
+hal_rootstrap_pc_path = argv[1]
+pc_dir = argv[2]
+pc_files = listdir(pc_dir)
+
+for pc_file in pc_files:
+       parse_pc("{}/{}".format(pc_dir, pc_file))
+
+write_to_pc(hal_rootstrap_pc_path)
index 47071bdea08e1da7837c407b3f1b708d5bc45a79..f42c89f72fa25012a0d89b5a9fe90413cd06f788 100644 (file)
@@ -3,14 +3,12 @@
 package_name=hal-rootstrap
 prefix=/opt/data/hal-rootstrap@PREFIX@
 exec_prefix=/opt/data/hal-rootstrap@EXEC_PREFIX@
-hal_rootstrap_libdir=/opt/data/hal-rootstrap@LIBDIR@
-hal_rootstrap_include_dir=/opt/data/hal-rootstrap@INCLUDEDIR@
+hal_rootstrap_dir=/opt/data/hal-rootstrap
+hal_rootstrap_libdir=${hal_rootstrap_dir}@LIBDIR@
+hal_rootstrap_include_dir=${hal_rootstrap_dir}@INCLUDEDIR@
 
 Name: ${package_name}
 Description: ${package_name} interface
 Version: @VERSION@
 
 Requires:
-Libs: -L${hal_rootstrap_libdir}
-Cflags: -I${hal_rootstrap_include_dir}
-CXXflags: -I${hal_rootstrap_include_dir}
index f0509783b346ccd8bc6751eaabbccaea82af2044..245be438c1d198fd6b5c8bf67c01f74f7cabbd83 100644 (file)
@@ -438,6 +438,7 @@ mkdir %{buildroot}
 
 mkdir -p %{buildroot}%{_libdir}/pkgconfig/
 cp packaging/hal-rootstrap.pc %{buildroot}%{_libdir}/pkgconfig/
+./modify_pc.py "%{buildroot}%{_libdir}/pkgconfig/hal-rootstrap.pc" "%{buildroot}%{hal_rootstrap_install_path}/%{_libdir}/pkgconfig"
 
 %files
 %{hal_rootstrap_install_path}/lib/*