We add a menu option to provide a main() function, and set it to on by
default so that in the standard case a user can choose a platform,
compile and run.
Signed-off-by: Felipe Huici <felipe.huici@xxxxxxxxx>
---
Config.uk | 6 +++---
Makefile.uk | 19 ++++++++++++++++---
main.c | 10 ++++++++++
3 files changed, 29 insertions(+), 6 deletions(-)
create mode 100644 main.c
diff --git a/Config.uk b/Config.uk
index b8beab2..bad29fd 100644
--- a/Config.uk
+++ b/Config.uk
@@ -6,7 +6,7 @@ menuconfig LIBLUA
select UKUNISTD
if LIBLUA
- config LIBLUA_MAIN_FUNCTION
- bool "Provide main function"
- default y
+ config LIBLUA_MAIN_FUNCTION
+ bool "Provide main function"
+ default y
endif
diff --git a/Makefile.uk b/Makefile.uk
index 6768de3..9251ff2 100644
--- a/Makefile.uk
+++ b/Makefile.uk
@@ -32,11 +32,24 @@ CXXINCLUDES-$(CONFIG_LIBLUA) += -I$(LIBLUA_BUILD)/include
LIBLUA_CINCLUDES-y += -I$(LIBLUA_SRCS_BASE)
################################################################################
-# Compilation unit
+# Glue code
################################################################################
-LIBLUA_CFLAGS-y += -DLUA_COMPAT_5_2
+LIBLUA_SRCS-$(CONFIG_LIBLUA_MAIN_FUNCTION) += $(LIBLUA_BASE)/main.c
+################################################################################
+# Library flags
+################################################################################
+LIBLUA_SUPPRESS_FLAGS += -Wno-implicit-function-declaration
+LIBLUA_FLAGS += -DLUA_COMPAT_5_2
+
+LIBLUA_CFLAGS-y += $(LIBLUA_FLAGS) $(LIBLUA_SUPPRESS_FLAGS)
+LIBLUA_CXXFLAGS-y += $(LIBLUA_FLAGS) $(LIBLUA_SUPPRESS_FLAGS)
+
+################################################################################
+# Sources
+################################################################################
# Main loop
+LIBLUA_LUA_FLAGS-y += -Dmain=lua_main
LIBLUA_SRCS-y += $(LIBLUA_SRCS_BASE)/lua.c
# CORE_O
@@ -78,7 +91,7 @@ LIBLUA_SRCS-y += $(LIBLUA_SRCS_BASE)/linit.c
################################################################################
-# libray API headers
+# Libray API headers
################################################################################
$(LIBLUA_SRCS_BASE)/%.h: $(LIBLUA_BUILD)/.origin
@# empty recipe to enforce dependency to archive extraction
diff --git a/main.c b/main.c
new file mode 100644
index 0000000..4964b69
--- /dev/null
+++ b/main.c
@@ -0,0 +1,10 @@
+#include <stdio.h>
+
+/* Import user configuration: */
+#include <uk/config.h>
+
+int main(int argc, char *argv[])
+{
+ lua_main(argc, argv);
+ return 0;
+}