From 36e07578a7f73a60c182e85ebc24af212a5cd7f9 Mon Sep 17 00:00:00 2001 From: Marrub Date: Thu, 11 Jun 2015 10:32:16 -0400 Subject: [PATCH] added gdcc example and makefile support --- Makefile | 62 ++++++++++++++++++++++++++++--------------- examples/gdcc.c | 58 ++++++++++++++++++++++++++++++++++++++++ examples/language.txt | 3 +++ 3 files changed, 102 insertions(+), 21 deletions(-) create mode 100644 examples/gdcc.c create mode 100644 examples/language.txt diff --git a/Makefile b/Makefile index ea61e1e..ff2f2a9 100644 --- a/Makefile +++ b/Makefile @@ -1,39 +1,59 @@ CC= -MKDIR= -RM= +LD= +MKDIR=mkdir -p +RM=rm PCFLAGS= PLFLAGS= LIBNAME= OUTDIR=bin SRCDIR=src -LFLAGS=-shared -g -ggdb -CFLAGS=--std=c99 -g -ggdb -O2 -Wall +LFLAGS= +CFLAGS= RMEXTRA= +GDCCBUILD=OFF +EXAMPLEO= +EXAMPLEC= -ifeq ($(OS),Windows_NT) - CC+=mingw32-gcc - MKDIR+=mkdir -p - RM+=rm - PLFLAGS+=-Wl,--out-implib,bin/libLoveToken.a - LIBNAME+=$(OUTDIR)/LoveToken.dll - RMEXTRA+=bin/libLoveToken.a +ifeq ($(GDCCBUILD),ON) + CC+=gdcc-cc + LD+=gdcc-ld + MKDIR+=mkdir + LIBNAME+=$(OUTDIR)/LoveToken.bin + PCFLAGS+=--bc-target=ZDoom -i$(SRCDIR) + LFLAGS+=--bc-target=ZDoom + EXAMPLEC+=examples/gdcc.c + # These are completely arbitrary. + EXAMPLEO+=$(OUTDIR)/libc.ir $(OUTDIR)/libGDCC.ir $(OUTDIR)/libGDCC-c.ir $(OUTDIR)/libGDCC-ZDACS-asm.ir else - ifeq ($(shell uname -s), Linux) - CC+=gcc - MKDIR+=mkdir -p - RM+=rm - PCFLAGS+=-fPIC - LIBNAME+=$(OUTDIR)/LoveToken.so + EXAMPLEC+=examples/main.c + PCFLAGS+=--std=c99 -g -ggdb -O2 -Wall -c -I$(SRCDIR) + + ifeq ($(OS),Windows_NT) + CC+=mingw32-gcc + LD+=mingw32-gcc + PLFLAGS+=-shared -g -ggdb + PLFLAGS2+=-Wl,--out-implib,bin/libLoveToken.a -liconv + LIBNAME+=$(OUTDIR)/LoveToken.dll + RMEXTRA+=bin/libLoveToken.a + else + ifeq ($(shell uname -s), Linux) + CC+=gcc + LD+=gcc + PCFLAGS+=-fPIC + PLFLAGS2+=-liconv + LIBNAME+=$(OUTDIR)/LoveToken.so + endif endif endif all: $(MKDIR) $(OUTDIR) - $(CC) $(CFLAGS) $(PCFLAGS) -c -o $(OUTDIR)/lt.o $(SRCDIR)/lt.c - $(CC) $(LFLAGS) -o $(LIBNAME) $(OUTDIR)/lt.o $(PLFLAGS) -liconv + $(CC) $(CFLAGS) $(PCFLAGS) -o $(OUTDIR)/lt.o $(SRCDIR)/lt.c + $(LD) $(LFLAGS) $(PLFLAGS) -o $(LIBNAME) $(OUTDIR)/lt.o $(PLFLAGS2) clean: $(RM) $(LIBNAME) $(OUTDIR)/lt.o $(RMEXTRA) -example: - $(CC) $(CFLAGS) -I$(SRCDIR) -L$(OUTDIR) -o $(OUTDIR)/example examples/main.c -lLoveToken +example: all + $(CC) $(CFLAGS) $(PCFLAGS) -o $(OUTDIR)/example.o $(EXAMPLEC) + $(LD) $(LFLAGS) -o $(OUTDIR)/example $(OUTDIR)/example.o $(EXAMPLEO) $(OUTDIR)/lt.o $(PLFLAGS2) diff --git a/examples/gdcc.c b/examples/gdcc.c new file mode 100644 index 0000000..9f425e6 --- /dev/null +++ b/examples/gdcc.c @@ -0,0 +1,58 @@ +// This file is placed under public domain. +#include "lt.h" +#include +#include + +#define Print(...) \ + ( \ + ACS_BeginPrint(), \ + __nprintf(__VA_ARGS__), \ + ACS_EndPrint() \ + ) +#define Log(...) \ + ( \ + ACS_BeginLog(), \ + __nprintf(__VA_ARGS__), \ + ACS_EndLog() \ + ) + +[[extern("ACS"), call("ScriptS"), script("Enter")]] +void ExampleRunScript() +{ + LT_Config initCfg = { 0 }; + LT_Init(initCfg); + + LT_OpenFile(s"EXAMPLESCRIPT"); + + LT_Token tk = LT_GetToken(); + + ACS_Delay(15); + + Print("Printing out the parsed tokens to the console in 3..."); + ACS_Delay(35); + Print("2..."); + ACS_Delay(35); + Print("1..."); + ACS_Delay(35); + Print("Showtime!"); + ACS_Delay(35); + + while (tk.token != LT_TkNames[TOK_EOF]) + { + if (tk.string != NULL) + { + Log("%s - %s", tk.token, tk.string); + } + else + { + Log(tk.token); + } + + tk = LT_GetToken(); + + ACS_Delay(1); + } + + LT_Quit(); + LT_CloseFile(); +} \ No newline at end of file diff --git a/examples/language.txt b/examples/language.txt new file mode 100644 index 0000000..39e5c4f --- /dev/null +++ b/examples/language.txt @@ -0,0 +1,3 @@ +[enu default] + +EXAMPLESCRIPT="The quick brown_fox jumps over the !Lazy_Dog.;\n 5 ** 5 ** 5 + 3 []";