Work on build system

This commit is contained in:
Łukasz Magiera 2016-01-03 03:25:12 +01:00
parent e35dea7bce
commit 979e483f1f
6 changed files with 83 additions and 4 deletions

View File

@ -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)

0
include/luares.h Normal file
View File

0
include/lupi.h Normal file
View File

40
scripts/txt2c Executable file
View File

@ -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

View File

@ -1,5 +1,8 @@
#include <stdio.h>
#include "luares.h"
int main (void) {
puts("LuPI 2");
puts("LuPI 2\n");
puts(lua_init);
return 0;
}

1
src/lua/core/init.lua Normal file
View File

@ -0,0 +1 @@
print("HeelloLua")