From eeff110b312d40701f17cc62025c0faaaeb1e485 Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Thu, 22 Dec 2016 20:57:57 -0600 Subject: [PATCH] Add a master Makefile with docker dev env support and address compiler warning that showed up in the Docker dev env --- .gitignore | 4 +++- CMakeLists.txt | 2 +- Makefile | 46 +++++++++++++++++++++++++++++++++++++ build/Makefile | 16 +++++++++++++ src/ox/fs/oxfstool.cpp | 52 ++++++++++++++++++++++-------------------- 5 files changed, 93 insertions(+), 27 deletions(-) create mode 100644 Makefile create mode 100644 build/Makefile diff --git a/.gitignore b/.gitignore index 593c5e89f..d31139a33 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ -build +build/gba +build/debug +build/release tags diff --git a/CMakeLists.txt b/CMakeLists.txt index 68bbb4df9..83a4f297d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,7 +16,7 @@ if(NOT MSVC) -fno-rtti -Wsign-compare -Wunused-variable - #-Werror + -Werror #--analyze #-Os # GCC size optimization flag ) diff --git a/Makefile b/Makefile new file mode 100644 index 000000000..f39c3597c --- /dev/null +++ b/Makefile @@ -0,0 +1,46 @@ +DEVENV=devenv$(shell pwd | sed 's/\//-/g') +ifeq ($(shell docker inspect --format="{{.State.Status}}" ${DEVENV} 2>&1),running) + ENV_RUN=docker exec --user $(shell id -u ${USER}) ${DEVENV} +endif + +make: + ${ENV_RUN} make -j -C build +preinstall: + ${ENV_RUN} make -j -C build ARGS="preinstall" +install: + ${ENV_RUN} make -j -C build ARGS="install" +clean: + ${ENV_RUN} make -j -C build ARGS="clean" +purge: + ${ENV_RUN} rm -rf $(find build -mindepth 1 -maxdepth 1 -type d) +test: + ${ENV_RUN} make -j -C build ARGS="test" +run: make + ./build/current/src/wombat/wombat -debug +debug: make + gdb ./build/current/src/wombat/wombat +devenv: + docker pull wombatant/devenv + docker run -d -v $(shell pwd):/usr/src/project \ + -e LOCAL_USER_ID=$(shell id -u ${USER}) \ + --name ${DEVENV} -t wombatant/devenv bash +devenv-destroy: + docker rm -f ${DEVENV} + +native: + ${ENV_RUN} rm -rf build/release + ${ENV_RUN} ./scripts/setup_build + ${ENV_RUN} rm -f build/current + ${ENV_RUN} ln -s release build/current + +native_debug: + ${ENV_RUN} rm -rf build/debug + ${ENV_RUN} ./scripts/setup_build_debug + ${ENV_RUN} rm -f build/current + ${ENV_RUN} ln -s debug build/current + +gba: + ${ENV_RUN} rm -rf build/gba + ${ENV_RUN} ./scripts/setup_build_gba + ${ENV_RUN} rm -f build/current + ${ENV_RUN} ln -s gba build/current diff --git a/build/Makefile b/build/Makefile new file mode 100644 index 000000000..dc0c5bb77 --- /dev/null +++ b/build/Makefile @@ -0,0 +1,16 @@ +all: gba_build native_build native_debug_build + +gba_build: + @if [ -d gba ]; then \ + make -C gba ${ARGS}; \ + fi + +native_build: + @if [ -d release ]; then \ + make -C release ${ARGS}; \ + fi + +native_debug_build: + @if [ -d debug ]; then \ + make -C debug ${ARGS}; \ + fi diff --git a/src/ox/fs/oxfstool.cpp b/src/ox/fs/oxfstool.cpp index 5a420f037..5c088a512 100644 --- a/src/ox/fs/oxfstool.cpp +++ b/src/ox/fs/oxfstool.cpp @@ -179,41 +179,43 @@ int write(int argc, char **args) { if (fsFile) { fseek(fsFile, 0, SEEK_END); - const auto fsSize = (::size_t) ftell(fsFile); + const auto fsSize = (size_t) ftell(fsFile); rewind(fsFile); auto fsBuff = (char*) malloc(fsSize); - fread(fsBuff, fsSize, 1, fsFile); + auto itemsRead = fread(fsBuff, fsSize, 1, fsFile); fclose(fsFile); - auto srcBuff = loadFileBuff(srcPath, &srcSize); - if (srcBuff) { - auto fs = createFileSystem(fsBuff); - if (fs) { - err |= fs->write(inode, srcBuff, srcSize); - if (err) { - fprintf(stderr, "Could not write to file system.\n"); - } - } else { - fprintf(stderr, "Invalid file system type: %d.\n", *(uint32_t*) fsBuff); - err = 1; - } - - if (!err) { - fsFile = fopen(fsPath, "wb"); - - if (fsFile) { - err = fwrite(fsBuff, fsSize, 1, fsFile) != 1; - err |= fclose(fsFile); + if (itemsRead) { + auto srcBuff = loadFileBuff(srcPath, &srcSize); + if (srcBuff) { + auto fs = createFileSystem(fsBuff); + if (fs) { + err |= fs->write(inode, srcBuff, srcSize); if (err) { - fprintf(stderr, "Could not write to file system file.\n"); + fprintf(stderr, "Could not write to file system.\n"); } } else { + fprintf(stderr, "Invalid file system type: %d.\n", *(uint32_t*) fsBuff); err = 1; } + + if (!err) { + fsFile = fopen(fsPath, "wb"); + + if (fsFile) { + err = fwrite(fsBuff, fsSize, 1, fsFile) != 1; + err |= fclose(fsFile); + if (err) { + fprintf(stderr, "Could not write to file system file.\n"); + } + } else { + err = 1; + } + } + } else { + err = 1; + fprintf(stderr, "Could not load source file.\n"); } - } else { - err = 1; - fprintf(stderr, "Could not load source file.\n"); } free(fsBuff);