changeset 611:f2aff78644db

mlk-bcc: update to 2.2.0
author David Demelier <markand@malikania.fr>
date Sun, 20 Aug 2023 10:47:46 +0200
parents 90ac81e4c190
children 297fa28cac90
files cmake/MlkBcc.cmake cmake/MlkExecutable.cmake cmake/MlkLibrary.cmake mlk-bcc/arg.h mlk-bcc/mlk-bcc.c
diffstat 5 files changed, 34 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- a/cmake/MlkBcc.cmake	Sat Aug 12 09:44:49 2023 +0200
+++ b/cmake/MlkBcc.cmake	Sun Aug 20 10:47:46 2023 +0200
@@ -20,7 +20,11 @@
 # mlk_bcc(
 #   OUTPUT_VAR variable
 #   ASSETS files...
+#   [CONST]
+#   [NUL]
 #   [OUTPUT_DIRECTORY directory]
+#   [STATIC]
+#   [TYPE char]
 # )
 #
 # Convert binary files to header files using mlk-bcc utility.
@@ -45,9 +49,9 @@
 # - <output-directory>/assets/sounds/volume-down.h
 #
 macro(mlk_bcc)
-	set(options "")
+	set(options "CONST;NUL;STATIC")
 	set(oneValueArgs "OUTPUT_DIRECTORY;OUTPUTS_VAR")
-	set(multiValueArgs ASSETS)
+	set(multiValueArgs "ASSETS")
 
 	cmake_parse_arguments(_bcc "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
 
@@ -73,13 +77,17 @@
 		cmake_path(REPLACE_EXTENSION _bcc_filename .h)
 		set(_bcc_output_file ${_bcc_base_directory}/${_bcc_dirname}/${_bcc_filename})
 
-		# Text files are better NUL terminated.
-		cmake_path(GET a EXTENSION _bcc_extension)
-
-		if (_bcc_extension MATCHES "\\.sql")
-			set(_bcc_args "-0cs")
-		else ()
-			set(_bcc_args "-cs")
+		if (_bcc_CONST)
+			list(APPEND _bcc_args -c)
+		endif ()
+		if (_bcc_NUL)
+			list(APPEND _bcc_args -0)
+		endif ()
+		if (_bcc_STATIC)
+			list(APPEND _bcc_args -s)
+		endif ()
+		if (_bcc_TYPE)
+			list(APPEND _bcc_args -t ${_bcc_TYPE})
 		endif ()
 
 		# This is the mlk-bcc variable to generate the C identifier.
--- a/cmake/MlkExecutable.cmake	Sat Aug 12 09:44:49 2023 +0200
+++ b/cmake/MlkExecutable.cmake	Sun Aug 20 10:47:46 2023 +0200
@@ -30,7 +30,11 @@
 	endif ()
 
 	if (EXE_ASSETS)
-		mlk_bcc(ASSETS ${EXE_ASSETS} OUTPUTS_VAR HEADERS)
+		mlk_bcc(
+			CONST STATIC
+			ASSETS ${EXE_ASSETS}
+			OUTPUTS_VAR HEADERS
+		)
 		source_group(build/assets FILES ${HEADERS})
 	endif ()
 
--- a/cmake/MlkLibrary.cmake	Sat Aug 12 09:44:49 2023 +0200
+++ b/cmake/MlkLibrary.cmake	Sun Aug 20 10:47:46 2023 +0200
@@ -34,7 +34,11 @@
 	endif ()
 
 	if (LIB_ASSETS)
-		mlk_bcc(ASSETS ${LIB_ASSETS} OUTPUTS_VAR assets)
+		mlk_bcc(
+			CONST STATIC
+			ASSETS ${LIB_ASSETS}
+			OUTPUTS_VAR assets
+		)
 	endif ()
 
 	if (LIB_LANGS AND MLK_WITH_NLS)
--- a/mlk-bcc/arg.h	Sat Aug 12 09:44:49 2023 +0200
+++ b/mlk-bcc/arg.h	Sun Aug 20 10:47:46 2023 +0200
@@ -6,10 +6,8 @@
 #ifndef ARG_H__
 #define ARG_H__
 
-extern char *argv0;
-
 /* use main(int argc, char *argv[]) */
-#define ARGBEGIN	for (argv0 = *argv, argv++, argc--;\
+#define ARGBEGIN	for (argv++, argc--;\
 					argv[0] && argv[0][0] == '-'\
 					&& argv[0][1];\
 					argc--, argv++) {\
--- a/mlk-bcc/mlk-bcc.c	Sat Aug 12 09:44:49 2023 +0200
+++ b/mlk-bcc/mlk-bcc.c	Sun Aug 20 10:47:46 2023 +0200
@@ -22,22 +22,17 @@
 #include <stdlib.h>
 #include <string.h>
 
-#if defined(__OpenBSD__)
-#       include <unistd.h>
-#endif
-
 #include "arg.h"
 
-char *argv0;
-
 static const char *charset = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_";
+static const char *ftype = "unsigned char";
 static char findentchar = '\t';
 static int findent = 1, fconst, fnull, fstatic;
 
 static void
 usage(void)
 {
-	fprintf(stderr, "usage: mlk-bcc [-0cs] [-I tab-indent] [-i space-indent] input variable\n");
+	fprintf(stderr, "usage: bcc [-0cs] [-I tab-num] [-i space-num] [-t type] input variable\n");
 	exit(1);
 }
 
@@ -99,7 +94,7 @@
 	if (fconst)
 		printf("const ");
 
-	printf("unsigned char %s[] = {\n", variable);
+	printf("%s %s[] = {\n", ftype, variable);
 
 	for (ch = fgetc(fp); ch != EOF; ) {
 		if (col == 0)
@@ -157,6 +152,9 @@
 	case 's':
 		fstatic = 1;
 		break;
+	case 't':
+		ftype = EARGF(usage());
+		break;
 	default:
 		usage();
 		break;