From 0213df558039120c5025ecb8301a58dc27c45ee9 Mon Sep 17 00:00:00 2001 From: beyondcoast Date: Thu, 29 Nov 2018 20:36:06 -0600 Subject: [PATCH 1/4] Rearchitect Makefile to support dependency tracking / fast incremental builds. Lua now built and linked as static library via its own Makefile. .gitignore modified to ignore *.d Makefile fragments with dependency info. --- .gitignore | 4 ++++ host/Makefile | 37 ++++++++++++++++++++++++++----------- 2 files changed, 30 insertions(+), 11 deletions(-) diff --git a/.gitignore b/.gitignore index e267f26..af62a1d 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ # Ignore files ending in the following # ######################################## *.o +*.d *.swp *.swo *.bin @@ -14,3 +15,6 @@ firmware/source/shared_*.h # ignore trash/temp files stored in host/ignore host/ignore + +# OS X Metadata +.DS_Store \ No newline at end of file diff --git a/host/Makefile b/host/Makefile index f9c4fc0..6ef0497 100644 --- a/host/Makefile +++ b/host/Makefile @@ -1,25 +1,39 @@ #compiler flags: -Wall Warnings all, -g gdb debug markings, CFLAGS=-Wall -O +LDFLAGS= -llua -lusb-1.0 -Lsource/lua INCLUDE= -I ./include -I ../shared -WINLIB= -L ./winlib -LIBUSB= -lusb-1.0 +LDFLAGS_WINDOWS= -L ./winlib $(LDFLAGS) +LDFLAGS_UNIX= -lm $(LDFLAGS) CC= gcc -SOURCES=$(wildcard source/*.c source/lua/*.c) -OBJECTS=$(patsubst %.c,%.o,$(SOURCES)) +SOURCES=$(wildcard source/*.c) +OBJECTS=$(SOURCES:.c=.o) -LUAOBJ=$(wildcard source/lua/*.o) +# Use GCC preprocessor to determine dependencies for all source files. +DEPS=$(OBJECTS:.o=.d) +%.d: %.c + @$(CC) $(CFLAGS) $(INCLUDE) $< -MM -MT $(@:.d=.o) >$@ +# Include generated .d Makefile fragments to manage object dependencies. +-include $(DEPS) + +# Provide recipes for building all objects, dependencies managed via earlier inclusion. +%.o: %.c + $(CC) $(CFLAGS) $(INCLUDE) -o $@ -c $< + +# TODO: Pass through platform when building liblua. +liblua: + $(MAKE) -C source/lua a TARGET=inlretro #default to windows build -all: - $(CC) $(INCLUDE) $(LUAOBJ) $(SOURCES) -o $(TARGET) $(WINLIB) $(CFLAGS) $(LIBUSB) +all: liblua $(DEPS) $(OBJECTS) + $(CC) $(INCLUDE) $(OBJECTS) -o $(TARGET) $(CFLAGS) $(LDFLAGS_WINDOWS) #unix build doesn't need winlib directory as libusb should be installed on OS. #sudo apt-get install libusb-1.0-0-dev -unix: - $(CC) $(INCLUDE) $(LUAOBJ) $(SOURCES) -o $(TARGET) $(CFLAGS) -lm $(LIBUSB) +unix: liblua $(DEPS) $(OBJECTS) + $(CC) $(INCLUDE) $(OBJECTS) -o $(TARGET) $(CFLAGS) $(LDFLAGS_UNIX) # "make debug" will build program with debug print messages # -DDEBUG show debug logs @@ -31,7 +45,8 @@ debug: all unixdebug: CFLAGS += -DDEBUG -g unixdebug: unix - #clean on unix and windows(.exe) +.PHONY: clean clean: - rm -f $(TARGET) $(TARGET).exe $(OBJECTS) $(LUAOBJ) \ No newline at end of file + $(MAKE) -C source/lua clean + rm -f $(TARGET) $(TARGET).exe $(OBJECTS) $(DEPS) $(LUAOBJ) source/lua/liblua.a From 298c9112c5d953e3600f8cc4c62ee4640ff0430a Mon Sep 17 00:00:00 2001 From: beyondcoast Date: Thu, 29 Nov 2018 20:43:41 -0600 Subject: [PATCH 2/4] Implement -h help message for all currently implemented CLI options, fix warning about const string. --- host/source/inlprog.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/host/source/inlprog.c b/host/source/inlprog.c index a87088c..b5ad550 100644 --- a/host/source/inlprog.c +++ b/host/source/inlprog.c @@ -29,6 +29,18 @@ #include "lua/lauxlib.h" #include "lua/lualib.h" + +// TODO: Finish HELP for all currently supported options. +const char *HELP = "Usage: inlretro [options]\n\n"\ + "Options:\n"\ + " -c [console]\t\tConsole port, {NES}\n"\ + " -d [dump_filename]\tIf provided, dump cartridge ROMs to this filename\n"\ + " -m [mapper]\t\tNES console only, mapper ASIC on cartridge\n"\ + " \t\t\t{mmc1,mmc3,nrom}\n"\ + " -p [program_filename]\tIf provided, write this data to cartridge\n"\ + " -s [lua_script]\tIf provided, use this script for main application logic\n"\ + " -h\t\t\tDisplays this message.\n"; + // Struct used to control functionality. typedef struct { char *console_name; @@ -159,9 +171,8 @@ INLOptions* parseOptions(int argc, char *argv[]) { log_err("Non-option arguement: %s \n", argv[index]); } - //TODO display better help message if (opts->display_help) { - printf("You've asked for help but the help message still needs created...\n"); + printf("%s", HELP); return NULL; } return opts; @@ -334,7 +345,7 @@ int main(int argc, char *argv[]) // USB device is open, pass args and control over to Lua. // If lua_filename isn't set from args, use default script. - const char *DEFAULT_SCRIPT = "scripts/inlretro.lua"; + char *DEFAULT_SCRIPT = "scripts/inlretro.lua"; char *script = DEFAULT_SCRIPT; if (opts->lua_filename) { script = opts->lua_filename; From d55cf71ac5e68f841a58792d37c32ba72c8f3064 Mon Sep 17 00:00:00 2001 From: beyondcoast Date: Sat, 1 Dec 2018 00:04:32 -0600 Subject: [PATCH 3/4] Add liblua.a to .gitignore --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index af62a1d..c74d8ff 100644 --- a/.gitignore +++ b/.gitignore @@ -16,5 +16,8 @@ firmware/source/shared_*.h # ignore trash/temp files stored in host/ignore host/ignore +# Lua static library +host/source/lua/liblua.a + # OS X Metadata .DS_Store \ No newline at end of file From 5691721cd60b0974711b432f674c2eb27fcc4a65 Mon Sep 17 00:00:00 2001 From: beyondcoast Date: Sat, 1 Dec 2018 00:23:28 -0600 Subject: [PATCH 4/4] Don't track unix binary in source control --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index c74d8ff..5c4af9b 100644 --- a/.gitignore +++ b/.gitignore @@ -19,5 +19,8 @@ host/ignore # Lua static library host/source/lua/liblua.a +# Executable (Unix) +host/inlretro + # OS X Metadata .DS_Store \ No newline at end of file