From 979e483f1f1d70b1024f02ac111c58010689a29d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Sun, 3 Jan 2016 03:25:12 +0100 Subject: [PATCH] Work on build system --- Makefile | 41 ++++++++++++++++++++++++++++++++++++++--- include/luares.h | 0 include/lupi.h | 0 scripts/txt2c | 40 ++++++++++++++++++++++++++++++++++++++++ src/c/main.c | 5 ++++- src/lua/core/init.lua | 1 + 6 files changed, 83 insertions(+), 4 deletions(-) create mode 100644 include/luares.h create mode 100644 include/lupi.h create mode 100755 scripts/txt2c create mode 100644 src/lua/core/init.lua diff --git a/Makefile b/Makefile index 46873a8..9860ab8 100644 --- a/Makefile +++ b/Makefile @@ -1,11 +1,46 @@ CC=gcc -CFLAGS=-g -SRCDIR=src/c/ +CFLAGS=-g -Isrc/lib/lua -Iinclude +SRCDIR=src/c +CORELUA = src/lua/core +LIBS=-llua -OBJ=$(SRCDIR)main.o +GENERATED=include/luares.h src/c/gen/luares.c +LUAPARAMS = $(CORELUA) include/luares.h src/c/gen/luares.c lua_ +LFLAGS=$(LIBS) +OBJ=\ +$(SRCDIR)/main.o \ +$(SRCDIR)/gen/luares.o + +BUILDDIRECTORIES = $(patsubst $(SOURCE)%, $(BUILD)%, $(SRCDIRECTORIES)) +#Rules +#Build +all: smallclean $(BUILDDIRECTORIES) luaresources lupi + +smallclean: + find . -name '*~' -type f -exec rm {} \; + +build: clean all lupi: $(OBJ) $(CC) $(LFLAGS) $^ -o $@ $(OBJ): %.o: %.c $(CC) -c $(CFLAGS) $< -o $@ + +#Resources +luaresources: cleanresourcues + scripts/txt2c $(LUAPARAMS) + +$(BUILDDIRECTORIES): + mkdir $@ + +#Clean rules +cleanresourcues: + -rm -f $(GENERATED) + + mkdir -p src/c/gen/ + touch src/c/gen/luares.c + touch include/luares.h + +clean : cleanresourcues + -rm -f $(OBJ) \ No newline at end of file diff --git a/include/luares.h b/include/luares.h new file mode 100644 index 0000000..e69de29 diff --git a/include/lupi.h b/include/lupi.h new file mode 100644 index 0000000..e69de29 diff --git a/scripts/txt2c b/scripts/txt2c new file mode 100755 index 0000000..aa3fd31 --- /dev/null +++ b/scripts/txt2c @@ -0,0 +1,40 @@ +#!/bin/bash +# $1 scripts folder +# $2 file to generate OUTPUTH C +# $3 file to generate OUTPUTH H +# $4 prefix + +LUAFILES="$1/*" +OUTPUTH="$2" +OUTPUTC="$3" +PREFIX="$4" + + + +outname="$(basename "$OUTPUTH")" +outname="${outname%.*}" +guard=$(echo "$outname" | tr '[:lower:]' '[:upper:]') +guard="$guard""_H" + +printf "#ifndef %s\n" "$guard" >> "$OUTPUTH" +printf "#define %s\n" "$guard" >> "$OUTPUTH" + +for file in $LUAFILES +do + +filename="$(basename "$file")" +filename="${filename%.*}" + +echo "extern char $PREFIX$filename[];" >> "$OUTPUTH" + + +echo "char $PREFIX$filename[] = {" >> "$OUTPUTC" +echo " " $(xxd -i < "$file") ",0x00" >> "$OUTPUTC" +echo "};" >> "$OUTPUTC" + +done + +echo "#endif" >> "$OUTPUTH" + +exit 0 + diff --git a/src/c/main.c b/src/c/main.c index fbcb4e5..cdddfe6 100644 --- a/src/c/main.c +++ b/src/c/main.c @@ -1,5 +1,8 @@ #include +#include "luares.h" + int main (void) { - puts("LuPI 2"); + puts("LuPI 2\n"); + puts(lua_init); return 0; } diff --git a/src/lua/core/init.lua b/src/lua/core/init.lua new file mode 100644 index 0000000..76e7177 --- /dev/null +++ b/src/lua/core/init.lua @@ -0,0 +1 @@ +print("HeelloLua") \ No newline at end of file