From 1053351da66d93391ab53b943bc881f125b274d2 Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Fri, 23 Dec 2016 17:29:19 -0600 Subject: [PATCH] Update build system --- .gitignore | 5 ++-- CMakeLists.txt | 7 +++-- Makefile | 55 ++++++++++++++++++++++++----------- build/Makefile | 30 +++++++++++++------ cmake/Modules/Mingw.cmake | 18 ++++++++++++ scripts/setup_build | 28 ++++++++++++++++-- scripts/setup_build_debug | 8 ----- scripts/setup_build_gba | 8 ----- src/CMakeLists.txt | 12 ++++---- src/common/bounds.cpp | 2 +- src/common/bounds.hpp | 2 +- src/common/common.hpp | 2 +- src/common/memops.cpp | 2 +- src/common/memops.hpp | 2 +- src/common/point.cpp | 2 +- src/common/point.hpp | 2 +- src/core/CMakeLists.txt | 8 +++-- src/core/{gba => }/core.cpp | 11 +++---- main.cpp => src/core/core.hpp | 14 ++++----- src/core/gba/gfx.cpp | 21 ++++++++++++- src/core/gba/registers.hpp | 2 +- src/core/gfx.hpp | 17 +++++++++++ src/core/types.hpp | 6 ++-- src/player/CMakeLists.txt | 19 +++++++----- src/player/main.cpp | 12 +++++++- 25 files changed, 203 insertions(+), 92 deletions(-) create mode 100644 cmake/Modules/Mingw.cmake delete mode 100755 scripts/setup_build_debug delete mode 100755 scripts/setup_build_gba rename src/core/{gba => }/core.cpp (75%) rename main.cpp => src/core/core.hpp (51%) create mode 100644 src/core/gfx.hpp diff --git a/.gitignore b/.gitignore index 8e642525..b90a9bf8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +build/current build/gba -build/sdl -build/sdl_debug +build/*-release +build/*-debug diff --git a/CMakeLists.txt b/CMakeLists.txt index be7c95b2..7da99146 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,10 +6,13 @@ set(WOMBAT_BUILD_TYPE "Native" CACHE STRING "The type of build to produce(Native list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/Modules) include(address_sanitizer) -include(GBA) + +if (WOMBAT_BUILD_TYPE STREQUAL "GBA") + include(GBA) +endif() add_definitions( - -std=c++14 + -std=c++11 -Wall -Wsign-compare -nostdlib diff --git a/Makefile b/Makefile index 9c5ba5cc..f2ac9c1a 100644 --- a/Makefile +++ b/Makefile @@ -1,21 +1,25 @@ +OS=$(shell uname | tr [:upper:] [:lower:]) +TARGET=${OS}-$(shell uname -m) 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 + ${ENV_RUN} make -j -C build TARGET=${TARGET} preinstall: - ${ENV_RUN} make -j -C build ARGS="preinstall" + ${ENV_RUN} make -j -C build ARGS="preinstall" TARGET=${TARGET} install: - ${ENV_RUN} make -j -C build ARGS="install" + ${ENV_RUN} make -j -C build ARGS="install" TARGET=${TARGET} clean: - ${ENV_RUN} make -j -C build ARGS="clean" + ${ENV_RUN} make -j -C build ARGS="clean" TARGET=${TARGET} +purge: + ${ENV_RUN} rm -rf $(shell find build -mindepth 1 -maxdepth 1 -type d) test: - ${ENV_RUN} make -j -C build ARGS="test" + ${ENV_RUN} make -j -C build ARGS="test" TARGET=${TARGET} run: make ./build/current/src/wombat/wombat -debug -debug: make +gdb: make gdb ./build/current/src/wombat/wombat devenv: docker pull wombatant/devenv @@ -24,18 +28,35 @@ devenv: --name ${DEVENV} -t wombatant/devenv bash devenv-destroy: docker rm -f ${DEVENV} +devenv-shell: + docker exec -i --user $(shell id -u ${USER}) ${DEVENV} ls /usr/bin/x86_64-w64-mingw32-g++ -sdl: - ${ENV_RUN} ./scripts/setup_build - rm -f build/current - ln -s sdl build/current +release: + ${ENV_RUN} rm -rf build/${TARGET}-release + ${ENV_RUN} ./scripts/setup_build ${TARGET} + ${ENV_RUN} rm -f build/current + ${ENV_RUN} ln -s ${TARGET}-release build/current -sdl_debug: - ${ENV_RUN} ./scripts/setup_build_debug - rm -f build/current - ln -s sdl_debug build/current +debug: + ${ENV_RUN} rm -rf build/${TARGET}-debug + ${ENV_RUN} ./scripts/setup_build ${TARGET} debug + ${ENV_RUN} rm -f build/current + ${ENV_RUN} ln -s ${TARGET}-debug build/current + +windows: + ${ENV_RUN} rm -rf build/windows + ${ENV_RUN} ./scripts/setup_build windows + ${ENV_RUN} rm -f build/current + ${ENV_RUN} ln -s windows build/current + +windows-debug: + ${ENV_RUN} rm -rf build/windows + ${ENV_RUN} ./scripts/setup_build windows debug + ${ENV_RUN} rm -f build/current + ${ENV_RUN} ln -s windows build/current gba: - ${ENV_RUN} ./scripts/setup_build_gba - rm -f build/current - ln -s gba build/current + ${ENV_RUN} rm -rf build/gba-release + ${ENV_RUN} ./scripts/setup_build gba + ${ENV_RUN} rm -f build/current + ${ENV_RUN} ln -s gba-release build/current diff --git a/build/Makefile b/build/Makefile index 7dfde4b0..2d669231 100644 --- a/build/Makefile +++ b/build/Makefile @@ -1,16 +1,28 @@ -all: gba_build sdl_build sdl_debug_build +all: gba_build native_build native_debug_build windows_release windows_debug + +MAKE=make -j gba_build: - @if [ -d gba ]; then \ - make -C gba ${ARGS}; \ + @if [ -d gba-release ]; then \ + ${MAKE} -C gba-release ${ARGS}; \ fi -sdl_build: - @if [ -d sdl ]; then \ - make -C sdl ${ARGS}; \ +native_build: + @if [ -d ${TARGET}-release ]; then \ + ${MAKE} -C ${TARGET}-release ${ARGS}; \ fi -sdl_debug_build: - @if [ -d sdl_debug ]; then \ - make -C sdl_debug ${ARGS}; \ +native_debug_build: + @if [ -d ${TARGET}-debug ]; then \ + ${MAKE} -C ${TARGET}-debug ${ARGS}; \ + fi + +windows_release: + @if [ -d windows-release ]; then \ + ${MAKE} -C windows-release ${ARGS}; \ + fi + +windows_debug: + @if [ -d windows-debug ]; then \ + ${MAKE} -C windows-debug ${ARGS}; \ fi diff --git a/cmake/Modules/Mingw.cmake b/cmake/Modules/Mingw.cmake new file mode 100644 index 00000000..12768c2c --- /dev/null +++ b/cmake/Modules/Mingw.cmake @@ -0,0 +1,18 @@ +set(CMAKE_SYSTEM_NAME Windows) +set(TOOLCHAIN_PREFIX x86_64-w64-mingw32) + +# cross compilers to use for C and C++ +set(CMAKE_C_COMPILER ${TOOLCHAIN_PREFIX}-gcc) +set(CMAKE_CXX_COMPILER ${TOOLCHAIN_PREFIX}-g++) +set(CMAKE_RC_COMPILER ${TOOLCHAIN_PREFIX}-windres) + +# target environment on the build host system +# set 1st to dir with the cross compiler's C/C++ headers/libs +set(CMAKE_FIND_ROOT_PATH /usr/${TOOLCHAIN_PREFIX}) + +# modify default behavior of FIND_XXX() commands to +# search for headers/libs in the target environment and +# search for programs in the build host environment +set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) +set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) +set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) diff --git a/scripts/setup_build b/scripts/setup_build index bc6a1455..2aa0a7c3 100755 --- a/scripts/setup_build +++ b/scripts/setup_build @@ -1,8 +1,30 @@ #! /usr/bin/env bash -project=`pwd`/ -buildDir="build/sdl" + +set -e + +project=$(pwd)/ + +TARGET=$1 +BUILD_TYPE=$2 + +if [[ $TARGET == windows ]]; then + toolchain="-DCMAKE_TOOLCHAIN_FILE=cmake/Modules/Mingw.cmake" +elif [[ $TARGET == gba ]]; then + toolchain="-DCMAKE_TOOLCHAIN_FILE=cmake/Modules/GBA.cmake -DWOMBAT_BUILD_TYPE=GBA" +fi + +if [[ $BUILD_TYPE == debug ]]; then + buildTypeArgs="-DUSE_ASAN=ON -DCMAKE_BUILD_TYPE=Debug" + buildDir="build/${TARGET}-debug" +else + buildTypeArgs="-DCMAKE_BUILD_TYPE=Release" + buildDir="build/${TARGET}-release" +fi mkdir -p $buildDir pushd $buildDir -cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DCMAKE_BUILD_TYPE=Release $project +cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON \ + $buildTypeArgs \ + $toolchain \ + $project popd diff --git a/scripts/setup_build_debug b/scripts/setup_build_debug deleted file mode 100755 index 64ba2b52..00000000 --- a/scripts/setup_build_debug +++ /dev/null @@ -1,8 +0,0 @@ -#! /usr/bin/env bash -project=`pwd` -buildDir="build/sdl_debug" - -mkdir -p $buildDir -pushd $buildDir -cmake -DUSE_ASAN=ON -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DCMAKE_BUILD_TYPE=Debug $project -popd diff --git a/scripts/setup_build_gba b/scripts/setup_build_gba deleted file mode 100755 index 240a24f0..00000000 --- a/scripts/setup_build_gba +++ /dev/null @@ -1,8 +0,0 @@ -#! /usr/bin/env bash -project=`pwd` -buildDir="build/gba" - -mkdir -p $buildDir -pushd $buildDir -cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DCMAKE_TOOLCHAIN_FILE=cmake/Modules/GBA.cmake -DWOMBAT_BUILD_TYPE=GBA $project -popd diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 13c88f42..b754e49e 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -11,13 +11,13 @@ if(WOMBAT_BUILD_TYPE STREQUAL "Native") include_directories(${OPENGL_INCLUDE_DIR}) set(LIBS ${LIBS} ${OPENGL_LIBRARY}) - find_package(SDL_IMAGE REQUIRED) - include_directories(${SDL_IMAGE_INCLUDE_DIR}) - set(LIBS ${LIBS} ${SDL_IMAGE_LIBRARY}) + #find_package(SDL_IMAGE REQUIRED) + #include_directories(${SDL_IMAGE_INCLUDE_DIR}) + #set(LIBS ${LIBS} ${SDL_IMAGE_LIBRARY}) - find_package(SDL_ttf REQUIRED) - include_directories(${SDL_TTF_INCLUDE_DIR}) - set(LIBS ${LIBS} ${SDL_TTF_LIBRARY}) + #find_package(SDL_ttf REQUIRED) + #include_directories(${SDL_TTF_INCLUDE_DIR}) + #set(LIBS ${LIBS} ${SDL_TTF_LIBRARY}) elseif(WOMBAT_BUILD_TYPE STREQUAL "GBA") endif() diff --git a/src/common/bounds.cpp b/src/common/bounds.cpp index 0ea95c96..40f81bc4 100644 --- a/src/common/bounds.cpp +++ b/src/common/bounds.cpp @@ -1,6 +1,6 @@ /* * Copyright 2016 gtalent2@gmail.com - * + * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. diff --git a/src/common/bounds.hpp b/src/common/bounds.hpp index ddbc00e4..b5aa4a99 100644 --- a/src/common/bounds.hpp +++ b/src/common/bounds.hpp @@ -1,6 +1,6 @@ /* * Copyright 2016 gtalent2@gmail.com - * + * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. diff --git a/src/common/common.hpp b/src/common/common.hpp index fe9c05b0..ae6d6a24 100644 --- a/src/common/common.hpp +++ b/src/common/common.hpp @@ -1,6 +1,6 @@ /* * Copyright 2016 gtalent2@gmail.com - * + * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. diff --git a/src/common/memops.cpp b/src/common/memops.cpp index baa1f6e6..515c3171 100644 --- a/src/common/memops.cpp +++ b/src/common/memops.cpp @@ -1,6 +1,6 @@ /* * Copyright 2016 gtalent2@gmail.com - * + * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. diff --git a/src/common/memops.hpp b/src/common/memops.hpp index 6b8ebc5b..7325156c 100644 --- a/src/common/memops.hpp +++ b/src/common/memops.hpp @@ -1,6 +1,6 @@ /* * Copyright 2016 gtalent2@gmail.com - * + * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. diff --git a/src/common/point.cpp b/src/common/point.cpp index 676d39a1..e6444ad4 100644 --- a/src/common/point.cpp +++ b/src/common/point.cpp @@ -1,6 +1,6 @@ /* * Copyright 2016 gtalent2@gmail.com - * + * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. diff --git a/src/common/point.hpp b/src/common/point.hpp index 5d1fc687..34152979 100644 --- a/src/common/point.hpp +++ b/src/common/point.hpp @@ -1,6 +1,6 @@ /* * Copyright 2016 gtalent2@gmail.com - * + * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 8c327a1d..f9e779ea 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -1,16 +1,18 @@ cmake_minimum_required(VERSION 2.8.8) if(WOMBAT_BUILD_TYPE STREQUAL "GBA") + enable_language(C ASM) set( CPP - gba/core.cpp gba/gfx.cpp ) - include_directories("gba") elseif(WOMBAT_BUILD_TYPE STREQUAL "Native") endif() -add_library(NostalgiaCore OBJECT ${CPP}) +add_library(NostalgiaCore + ${CPP} + core.cpp +) install( FILES diff --git a/src/core/gba/core.cpp b/src/core/core.cpp similarity index 75% rename from src/core/gba/core.cpp rename to src/core/core.cpp index ab59f979..5d567917 100644 --- a/src/core/gba/core.cpp +++ b/src/core/core.cpp @@ -1,18 +1,19 @@ /* * Copyright 2016 gtalent2@gmail.com - * + * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "../types.hpp" -#include "registers.hpp" +#include "gfx.hpp" +#include "types.hpp" namespace nostalgia { namespace core { -int init() { - return 0; +Error init() { + auto err = initGfx(); + return err; } } diff --git a/main.cpp b/src/core/core.hpp similarity index 51% rename from main.cpp rename to src/core/core.hpp index ec7c4a32..18fd4fdf 100644 --- a/main.cpp +++ b/src/core/core.hpp @@ -1,19 +1,17 @@ /* * Copyright 2016 gtalent2@gmail.com - * + * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -int main() { - *(unsigned int*)0x04000000 = 0x0403; +#include "gfx.hpp" - ((unsigned short*)0x06000000)[120+80*240] = 0x001F; - ((unsigned short*)0x06000000)[136+80*240] = 0x03E0; - ((unsigned short*)0x06000000)[120+96*240] = 0x7C00; +namespace nostalgia { +namespace core { - while(1); +Error init(); - return 0; +} } diff --git a/src/core/gba/gfx.cpp b/src/core/gba/gfx.cpp index fbbf6795..40d5bb87 100644 --- a/src/core/gba/gfx.cpp +++ b/src/core/gba/gfx.cpp @@ -1,8 +1,27 @@ /* * Copyright 2016 gtalent2@gmail.com - * + * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + #include "registers.hpp" +#include "../types.hpp" + +namespace nostalgia { +namespace core { + +Error initGfx() { + /* Sprite Mode ----\ */ + /* ---\| */ + /* Background 2 -\|| */ + /* Objects -----\||| */ + /* |||| */ + REG_DISPCNT = 0x1400; + + return 0; +} + +} +} diff --git a/src/core/gba/registers.hpp b/src/core/gba/registers.hpp index a30dd38d..50810f89 100644 --- a/src/core/gba/registers.hpp +++ b/src/core/gba/registers.hpp @@ -1,6 +1,6 @@ /* * Copyright 2016 gtalent2@gmail.com - * + * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. diff --git a/src/core/gfx.hpp b/src/core/gfx.hpp new file mode 100644 index 00000000..50e6a6b1 --- /dev/null +++ b/src/core/gfx.hpp @@ -0,0 +1,17 @@ +/* + * Copyright 2016 gtalent2@gmail.com + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include "types.hpp" + +namespace nostalgia { +namespace core { + +Error initGfx(); + +} +} diff --git a/src/core/types.hpp b/src/core/types.hpp index cb4a279d..9fe56d22 100644 --- a/src/core/types.hpp +++ b/src/core/types.hpp @@ -1,6 +1,6 @@ /* * Copyright 2016 gtalent2@gmail.com - * + * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. @@ -8,8 +8,6 @@ #ifndef NOSTALGIA_CORE_TYPES_HPP #define NOSTALGIA_CORE_TYPES_HPP -#include - namespace nostalgia { namespace core { @@ -23,6 +21,8 @@ typedef unsigned uint_t; typedef long long int64_t; typedef unsigned long long uint64_t; +typedef uint32_t Error; + #ifdef _LP64 typedef uint64_t size_t; #elif _LP32 diff --git a/src/player/CMakeLists.txt b/src/player/CMakeLists.txt index c748d602..a0dad24b 100644 --- a/src/player/CMakeLists.txt +++ b/src/player/CMakeLists.txt @@ -7,13 +7,16 @@ set(WOMBAT_BUILD_TYPE "Native" CACHE STRING "The type of build to produce(Native add_executable( nostalgia main.cpp - ${OBJS} ) -#target_link_libraries(wombat ${LIBS}) -set_target_properties(nostalgia - PROPERTIES - LINK_FLAGS ${LINKER_FLAGS} - COMPILER_FLAGS "-mthumb -mthumb-interwork" -) -objcopy_file(nostalgia) +if(COMMAND objcopy_file) + set_target_properties(nostalgia + PROPERTIES + LINK_FLAGS ${LINKER_FLAGS} + COMPILER_FLAGS "-mthumb -mthumb-interwork" + ) + + objcopy_file(nostalgia) +endif() + +target_link_libraries(nostalgia NostalgiaCore) diff --git a/src/player/main.cpp b/src/player/main.cpp index b14cb9dd..62f8e15f 100644 --- a/src/player/main.cpp +++ b/src/player/main.cpp @@ -1,11 +1,21 @@ /* * Copyright 2016 gtalent2@gmail.com - * + * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +#include "core/core.hpp" + +using namespace nostalgia; + int main() { + core::init(); + + ((unsigned short*)0x06000000)[120+80*240] = 0x001F; + ((unsigned short*)0x06000000)[136+80*240] = 0x03E0; + ((unsigned short*)0x06000000)[120+96*240] = 0x7C00; + return 0; }