Merge branch 'master' into 'master'

Rearchitect Makefile to support dependency tracking / fast incremental builds.…

See merge request InfiniteNesLives/INL-retro-progdump!8
This commit is contained in:
Paul Molloy 2018-12-01 16:59:43 +00:00
commit 48b7437d10
3 changed files with 50 additions and 14 deletions

10
.gitignore vendored
View File

@ -2,6 +2,7 @@
# Ignore files ending in the following # # Ignore files ending in the following #
######################################## ########################################
*.o *.o
*.d
*.swp *.swp
*.swo *.swo
*.bin *.bin
@ -14,3 +15,12 @@ firmware/source/shared_*.h
# ignore trash/temp files stored in host/ignore # ignore trash/temp files stored in host/ignore
host/ignore host/ignore
# Lua static library
host/source/lua/liblua.a
# Executable (Unix)
host/inlretro
# OS X Metadata
.DS_Store

View File

@ -1,25 +1,39 @@
#compiler flags: -Wall Warnings all, -g gdb debug markings, #compiler flags: -Wall Warnings all, -g gdb debug markings,
CFLAGS=-Wall -O CFLAGS=-Wall -O
LDFLAGS= -llua -lusb-1.0 -Lsource/lua
INCLUDE= -I ./include -I ../shared INCLUDE= -I ./include -I ../shared
WINLIB= -L ./winlib LDFLAGS_WINDOWS= -L ./winlib $(LDFLAGS)
LIBUSB= -lusb-1.0 LDFLAGS_UNIX= -lm $(LDFLAGS)
CC= gcc CC= gcc
SOURCES=$(wildcard source/*.c source/lua/*.c) SOURCES=$(wildcard source/*.c)
OBJECTS=$(patsubst %.c,%.o,$(SOURCES)) 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 TARGET=inlretro
#default to windows build #default to windows build
all: all: liblua $(DEPS) $(OBJECTS)
$(CC) $(INCLUDE) $(LUAOBJ) $(SOURCES) -o $(TARGET) $(WINLIB) $(CFLAGS) $(LIBUSB) $(CC) $(INCLUDE) $(OBJECTS) -o $(TARGET) $(CFLAGS) $(LDFLAGS_WINDOWS)
#unix build doesn't need winlib directory as libusb should be installed on OS. #unix build doesn't need winlib directory as libusb should be installed on OS.
#sudo apt-get install libusb-1.0-0-dev #sudo apt-get install libusb-1.0-0-dev
unix: unix: liblua $(DEPS) $(OBJECTS)
$(CC) $(INCLUDE) $(LUAOBJ) $(SOURCES) -o $(TARGET) $(CFLAGS) -lm $(LIBUSB) $(CC) $(INCLUDE) $(OBJECTS) -o $(TARGET) $(CFLAGS) $(LDFLAGS_UNIX)
# "make debug" will build program with debug print messages # "make debug" will build program with debug print messages
# -DDEBUG show debug logs # -DDEBUG show debug logs
@ -31,7 +45,8 @@ debug: all
unixdebug: CFLAGS += -DDEBUG -g unixdebug: CFLAGS += -DDEBUG -g
unixdebug: unix unixdebug: unix
#clean on unix and windows(.exe) #clean on unix and windows(.exe)
.PHONY: clean
clean: clean:
rm -f $(TARGET) $(TARGET).exe $(OBJECTS) $(LUAOBJ) $(MAKE) -C source/lua clean
rm -f $(TARGET) $(TARGET).exe $(OBJECTS) $(DEPS) $(LUAOBJ) source/lua/liblua.a

View File

@ -29,6 +29,18 @@
#include "lua/lauxlib.h" #include "lua/lauxlib.h"
#include "lua/lualib.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. // Struct used to control functionality.
typedef struct { typedef struct {
char *console_name; char *console_name;
@ -159,9 +171,8 @@ INLOptions* parseOptions(int argc, char *argv[]) {
log_err("Non-option arguement: %s \n", argv[index]); log_err("Non-option arguement: %s \n", argv[index]);
} }
//TODO display better help message
if (opts->display_help) { if (opts->display_help) {
printf("You've asked for help but the help message still needs created...\n"); printf("%s", HELP);
return NULL; return NULL;
} }
return opts; return opts;
@ -334,7 +345,7 @@ int main(int argc, char *argv[])
// USB device is open, pass args and control over to Lua. // USB device is open, pass args and control over to Lua.
// If lua_filename isn't set from args, use default script. // 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; char *script = DEFAULT_SCRIPT;
if (opts->lua_filename) { if (opts->lua_filename) {
script = opts->lua_filename; script = opts->lua_filename;