Update build system

This commit is contained in:
Gary Talent 2016-12-23 17:29:19 -06:00
parent 5d3c02e077
commit 1053351da6
25 changed files with 203 additions and 92 deletions

5
.gitignore vendored
View File

@ -1,3 +1,4 @@
build/current
build/gba build/gba
build/sdl build/*-release
build/sdl_debug build/*-debug

View File

@ -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) list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/Modules)
include(address_sanitizer) include(address_sanitizer)
include(GBA)
if (WOMBAT_BUILD_TYPE STREQUAL "GBA")
include(GBA)
endif()
add_definitions( add_definitions(
-std=c++14 -std=c++11
-Wall -Wall
-Wsign-compare -Wsign-compare
-nostdlib -nostdlib

View File

@ -1,21 +1,25 @@
OS=$(shell uname | tr [:upper:] [:lower:])
TARGET=${OS}-$(shell uname -m)
DEVENV=devenv$(shell pwd | sed 's/\//-/g') DEVENV=devenv$(shell pwd | sed 's/\//-/g')
ifeq ($(shell docker inspect --format="{{.State.Status}}" ${DEVENV} 2>&1),running) ifeq ($(shell docker inspect --format="{{.State.Status}}" ${DEVENV} 2>&1),running)
ENV_RUN=docker exec --user $(shell id -u ${USER}) ${DEVENV} ENV_RUN=docker exec --user $(shell id -u ${USER}) ${DEVENV}
endif endif
make: make:
${ENV_RUN} make -j -C build ${ENV_RUN} make -j -C build TARGET=${TARGET}
preinstall: preinstall:
${ENV_RUN} make -j -C build ARGS="preinstall" ${ENV_RUN} make -j -C build ARGS="preinstall" TARGET=${TARGET}
install: install:
${ENV_RUN} make -j -C build ARGS="install" ${ENV_RUN} make -j -C build ARGS="install" TARGET=${TARGET}
clean: 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: test:
${ENV_RUN} make -j -C build ARGS="test" ${ENV_RUN} make -j -C build ARGS="test" TARGET=${TARGET}
run: make run: make
./build/current/src/wombat/wombat -debug ./build/current/src/wombat/wombat -debug
debug: make gdb: make
gdb ./build/current/src/wombat/wombat gdb ./build/current/src/wombat/wombat
devenv: devenv:
docker pull wombatant/devenv docker pull wombatant/devenv
@ -24,18 +28,35 @@ devenv:
--name ${DEVENV} -t wombatant/devenv bash --name ${DEVENV} -t wombatant/devenv bash
devenv-destroy: devenv-destroy:
docker rm -f ${DEVENV} docker rm -f ${DEVENV}
devenv-shell:
docker exec -i --user $(shell id -u ${USER}) ${DEVENV} ls /usr/bin/x86_64-w64-mingw32-g++
sdl: release:
${ENV_RUN} ./scripts/setup_build ${ENV_RUN} rm -rf build/${TARGET}-release
rm -f build/current ${ENV_RUN} ./scripts/setup_build ${TARGET}
ln -s sdl build/current ${ENV_RUN} rm -f build/current
${ENV_RUN} ln -s ${TARGET}-release build/current
sdl_debug: debug:
${ENV_RUN} ./scripts/setup_build_debug ${ENV_RUN} rm -rf build/${TARGET}-debug
rm -f build/current ${ENV_RUN} ./scripts/setup_build ${TARGET} debug
ln -s sdl_debug build/current ${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: gba:
${ENV_RUN} ./scripts/setup_build_gba ${ENV_RUN} rm -rf build/gba-release
rm -f build/current ${ENV_RUN} ./scripts/setup_build gba
ln -s gba build/current ${ENV_RUN} rm -f build/current
${ENV_RUN} ln -s gba-release build/current

View File

@ -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: gba_build:
@if [ -d gba ]; then \ @if [ -d gba-release ]; then \
make -C gba ${ARGS}; \ ${MAKE} -C gba-release ${ARGS}; \
fi fi
sdl_build: native_build:
@if [ -d sdl ]; then \ @if [ -d ${TARGET}-release ]; then \
make -C sdl ${ARGS}; \ ${MAKE} -C ${TARGET}-release ${ARGS}; \
fi fi
sdl_debug_build: native_debug_build:
@if [ -d sdl_debug ]; then \ @if [ -d ${TARGET}-debug ]; then \
make -C sdl_debug ${ARGS}; \ ${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 fi

18
cmake/Modules/Mingw.cmake Normal file
View File

@ -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)

View File

@ -1,8 +1,30 @@
#! /usr/bin/env bash #! /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 mkdir -p $buildDir
pushd $buildDir pushd $buildDir
cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DCMAKE_BUILD_TYPE=Release $project cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
$buildTypeArgs \
$toolchain \
$project
popd popd

View File

@ -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

View File

@ -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

View File

@ -11,13 +11,13 @@ if(WOMBAT_BUILD_TYPE STREQUAL "Native")
include_directories(${OPENGL_INCLUDE_DIR}) include_directories(${OPENGL_INCLUDE_DIR})
set(LIBS ${LIBS} ${OPENGL_LIBRARY}) set(LIBS ${LIBS} ${OPENGL_LIBRARY})
find_package(SDL_IMAGE REQUIRED) #find_package(SDL_IMAGE REQUIRED)
include_directories(${SDL_IMAGE_INCLUDE_DIR}) #include_directories(${SDL_IMAGE_INCLUDE_DIR})
set(LIBS ${LIBS} ${SDL_IMAGE_LIBRARY}) #set(LIBS ${LIBS} ${SDL_IMAGE_LIBRARY})
find_package(SDL_ttf REQUIRED) #find_package(SDL_ttf REQUIRED)
include_directories(${SDL_TTF_INCLUDE_DIR}) #include_directories(${SDL_TTF_INCLUDE_DIR})
set(LIBS ${LIBS} ${SDL_TTF_LIBRARY}) #set(LIBS ${LIBS} ${SDL_TTF_LIBRARY})
elseif(WOMBAT_BUILD_TYPE STREQUAL "GBA") elseif(WOMBAT_BUILD_TYPE STREQUAL "GBA")
endif() endif()

View File

@ -1,6 +1,6 @@
/* /*
* Copyright 2016 gtalent2@gmail.com * Copyright 2016 gtalent2@gmail.com
* *
* This Source Code Form is subject to the terms of the Mozilla Public * 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 * 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/. * file, You can obtain one at http://mozilla.org/MPL/2.0/.

View File

@ -1,6 +1,6 @@
/* /*
* Copyright 2016 gtalent2@gmail.com * Copyright 2016 gtalent2@gmail.com
* *
* This Source Code Form is subject to the terms of the Mozilla Public * 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 * 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/. * file, You can obtain one at http://mozilla.org/MPL/2.0/.

View File

@ -1,6 +1,6 @@
/* /*
* Copyright 2016 gtalent2@gmail.com * Copyright 2016 gtalent2@gmail.com
* *
* This Source Code Form is subject to the terms of the Mozilla Public * 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 * 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/. * file, You can obtain one at http://mozilla.org/MPL/2.0/.

View File

@ -1,6 +1,6 @@
/* /*
* Copyright 2016 gtalent2@gmail.com * Copyright 2016 gtalent2@gmail.com
* *
* This Source Code Form is subject to the terms of the Mozilla Public * 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 * 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/. * file, You can obtain one at http://mozilla.org/MPL/2.0/.

View File

@ -1,6 +1,6 @@
/* /*
* Copyright 2016 gtalent2@gmail.com * Copyright 2016 gtalent2@gmail.com
* *
* This Source Code Form is subject to the terms of the Mozilla Public * 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 * 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/. * file, You can obtain one at http://mozilla.org/MPL/2.0/.

View File

@ -1,6 +1,6 @@
/* /*
* Copyright 2016 gtalent2@gmail.com * Copyright 2016 gtalent2@gmail.com
* *
* This Source Code Form is subject to the terms of the Mozilla Public * 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 * 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/. * file, You can obtain one at http://mozilla.org/MPL/2.0/.

View File

@ -1,6 +1,6 @@
/* /*
* Copyright 2016 gtalent2@gmail.com * Copyright 2016 gtalent2@gmail.com
* *
* This Source Code Form is subject to the terms of the Mozilla Public * 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 * 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/. * file, You can obtain one at http://mozilla.org/MPL/2.0/.

View File

@ -1,16 +1,18 @@
cmake_minimum_required(VERSION 2.8.8) cmake_minimum_required(VERSION 2.8.8)
if(WOMBAT_BUILD_TYPE STREQUAL "GBA") if(WOMBAT_BUILD_TYPE STREQUAL "GBA")
enable_language(C ASM)
set( set(
CPP CPP
gba/core.cpp
gba/gfx.cpp gba/gfx.cpp
) )
include_directories("gba")
elseif(WOMBAT_BUILD_TYPE STREQUAL "Native") elseif(WOMBAT_BUILD_TYPE STREQUAL "Native")
endif() endif()
add_library(NostalgiaCore OBJECT ${CPP}) add_library(NostalgiaCore
${CPP}
core.cpp
)
install( install(
FILES FILES

View File

@ -1,18 +1,19 @@
/* /*
* Copyright 2016 gtalent2@gmail.com * Copyright 2016 gtalent2@gmail.com
* *
* This Source Code Form is subject to the terms of the Mozilla Public * 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 * 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/. * file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/ */
#include "../types.hpp" #include "gfx.hpp"
#include "registers.hpp" #include "types.hpp"
namespace nostalgia { namespace nostalgia {
namespace core { namespace core {
int init() { Error init() {
return 0; auto err = initGfx();
return err;
} }
} }

View File

@ -1,19 +1,17 @@
/* /*
* Copyright 2016 gtalent2@gmail.com * Copyright 2016 gtalent2@gmail.com
* *
* This Source Code Form is subject to the terms of the Mozilla Public * 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 * 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/. * file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/ */
int main() { #include "gfx.hpp"
*(unsigned int*)0x04000000 = 0x0403;
((unsigned short*)0x06000000)[120+80*240] = 0x001F; namespace nostalgia {
((unsigned short*)0x06000000)[136+80*240] = 0x03E0; namespace core {
((unsigned short*)0x06000000)[120+96*240] = 0x7C00;
while(1); Error init();
return 0; }
} }

View File

@ -1,8 +1,27 @@
/* /*
* Copyright 2016 gtalent2@gmail.com * Copyright 2016 gtalent2@gmail.com
* *
* This Source Code Form is subject to the terms of the Mozilla Public * 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 * 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/. * file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/ */
#include "registers.hpp" #include "registers.hpp"
#include "../types.hpp"
namespace nostalgia {
namespace core {
Error initGfx() {
/* Sprite Mode ----\ */
/* ---\| */
/* Background 2 -\|| */
/* Objects -----\||| */
/* |||| */
REG_DISPCNT = 0x1400;
return 0;
}
}
}

View File

@ -1,6 +1,6 @@
/* /*
* Copyright 2016 gtalent2@gmail.com * Copyright 2016 gtalent2@gmail.com
* *
* This Source Code Form is subject to the terms of the Mozilla Public * 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 * 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/. * file, You can obtain one at http://mozilla.org/MPL/2.0/.

17
src/core/gfx.hpp Normal file
View File

@ -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();
}
}

View File

@ -1,6 +1,6 @@
/* /*
* Copyright 2016 gtalent2@gmail.com * Copyright 2016 gtalent2@gmail.com
* *
* This Source Code Form is subject to the terms of the Mozilla Public * 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 * 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/. * file, You can obtain one at http://mozilla.org/MPL/2.0/.
@ -8,8 +8,6 @@
#ifndef NOSTALGIA_CORE_TYPES_HPP #ifndef NOSTALGIA_CORE_TYPES_HPP
#define NOSTALGIA_CORE_TYPES_HPP #define NOSTALGIA_CORE_TYPES_HPP
#include <cstdint>
namespace nostalgia { namespace nostalgia {
namespace core { namespace core {
@ -23,6 +21,8 @@ typedef unsigned uint_t;
typedef long long int64_t; typedef long long int64_t;
typedef unsigned long long uint64_t; typedef unsigned long long uint64_t;
typedef uint32_t Error;
#ifdef _LP64 #ifdef _LP64
typedef uint64_t size_t; typedef uint64_t size_t;
#elif _LP32 #elif _LP32

View File

@ -7,13 +7,16 @@ set(WOMBAT_BUILD_TYPE "Native" CACHE STRING "The type of build to produce(Native
add_executable( add_executable(
nostalgia nostalgia
main.cpp main.cpp
${OBJS}
) )
#target_link_libraries(wombat ${LIBS}) if(COMMAND objcopy_file)
set_target_properties(nostalgia set_target_properties(nostalgia
PROPERTIES PROPERTIES
LINK_FLAGS ${LINKER_FLAGS} LINK_FLAGS ${LINKER_FLAGS}
COMPILER_FLAGS "-mthumb -mthumb-interwork" COMPILER_FLAGS "-mthumb -mthumb-interwork"
) )
objcopy_file(nostalgia)
objcopy_file(nostalgia)
endif()
target_link_libraries(nostalgia NostalgiaCore)

View File

@ -1,11 +1,21 @@
/* /*
* Copyright 2016 gtalent2@gmail.com * Copyright 2016 gtalent2@gmail.com
* *
* This Source Code Form is subject to the terms of the Mozilla Public * 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 * 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/. * file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/ */
#include "core/core.hpp"
using namespace nostalgia;
int main() { 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; return 0;
} }