From ef85eea6912307a2434d03460dc03ac8e49dd224 Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Sat, 7 Nov 2020 17:38:41 -0600 Subject: [PATCH] [nostalgia] Get Makefile working on Windows --- Makefile | 50 ++++++++++++++++++++-------- scripts/setup-build.py | 74 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 111 insertions(+), 13 deletions(-) create mode 100644 scripts/setup-build.py diff --git a/Makefile b/Makefile index 18f20678..b81daf20 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,15 @@ -OS=$(shell uname | tr [:upper:] [:lower:]) -HOST_ENV=${OS}-$(shell uname -m) +ifeq (${OS},Windows_NT) + SHELL := powershell.exe + .SHELLFLAGS := -NoProfile -Command + OS=windows + HOST_ENV=${OS} + RM_RF=Remove-Item -ErrorAction Ignore -Recurse -Path +else + OS=$(shell uname | tr [:upper:] [:lower:]) + HOST_ENV=${OS}-$(shell uname -m) + RM_RF=rm -rf +endif + DEVENV=devenv$(shell pwd | sed 's/\//-/g') DEVENV_IMAGE=nostalgia-devenv ifndef VCPKG_DIR_BASE @@ -14,12 +24,6 @@ ifneq ($(shell which docker 2> /dev/null),) endif endif -ifeq ($(OS),windows) - RM_RF=Remove-Item -ErrorAction Ignore -Path -Recurse -else - RM_RF=rm -rf -endif - ifeq ($(OS),darwin) NOSTALGIA_STUDIO=./dist/${CURRENT_BUILD}/nostalgia-studio.app/Contents/MacOS/nostalgia-studio NOSTALGIA_STUDIO_PROFILE=dist/${CURRENT_BUILD}/nostalgia-studio.app/Contents/Resources/nostalgia-studio.json @@ -93,36 +97,56 @@ devenv-shell: vcpkg: ${VCPKG_DIR} vcpkg-install ${VCPKG_DIR}: +ifneq (,$(wildcard ${VCPKG_DIR})) ${ENV_RUN} ${RM_RF} ${VCPKG_DIR} +endif ${ENV_RUN} mkdir -p ${VCPKG_DIR_BASE} ${ENV_RUN} git clone -b release --depth 1 --branch ${VCPKG_VERSION} https://github.com/microsoft/vcpkg.git ${VCPKG_DIR} +ifneq (${OS},windows) ${ENV_RUN} ${VCPKG_DIR}/bootstrap-vcpkg.sh +else + ${ENV_RUN} ${VCPKG_DIR}/bootstrap-vcpkg.bat +endif .PHONY: vcpkg-install vcpkg-install: +ifneq (${OS},windows) ${VCPKG_DIR}/vcpkg install sdl2 jsoncpp +else + ${VCPKG_DIR}/vcpkg install --triplet x64-windows sdl2 jsoncpp +endif .PHONY: configure-release configure-release: +ifneq (,$(wildcard build/${HOST_ENV}-release)) ${ENV_RUN} ${RM_RF} build/${HOST_ENV}-release - ${ENV_RUN} ./scripts/setup-build ${HOST_ENV} release ${VCPKG_DIR} +endif + ${ENV_RUN} python ./scripts/setup-build.py ${HOST_ENV} release ${VCPKG_DIR} .PHONY: configure-debug configure-debug: +ifneq (,$(wildcard build/${HOST_ENV}-debug)) ${ENV_RUN} ${RM_RF} build/${HOST_ENV}-debug - ${ENV_RUN} ./scripts/setup-build ${HOST_ENV} debug ${VCPKG_DIR} +endif + ${ENV_RUN} python ./scripts/setup-build.py ${HOST_ENV} debug ${VCPKG_DIR} .PHONY: configure-asan configure-asan: +ifneq (,$(wildcard build/${HOST_ENV}-asan)) ${ENV_RUN} ${RM_RF} build/${HOST_ENV}-asan - ${ENV_RUN} ./scripts/setup-build ${HOST_ENV} asan ${VCPKG_DIR} +endif + ${ENV_RUN} python ./scripts/setup-build.py ${HOST_ENV} asan ${VCPKG_DIR} .PHONY: configure-gba configure-gba: +ifneq (,$(wildcard build/gba-release)) ${ENV_RUN} ${RM_RF} build/gba-release - ${ENV_RUN} ./scripts/setup-build gba release ${VCPKG_DIR} +endif + ${ENV_RUN} python ./scripts/setup-build.py gba release ${VCPKG_DIR} .PHONY: configure-gba-debug configure-gba-debug: +ifneq (,$(wildcard build/gba-debug)) ${ENV_RUN} ${RM_RF} build/gba-debug - ${ENV_RUN} ./scripts/setup-build gba debug ${VCPKG_DIR} +endif + ${ENV_RUN} python ./scripts/setup-build.py gba debug ${VCPKG_DIR} diff --git a/scripts/setup-build.py b/scripts/setup-build.py new file mode 100644 index 00000000..85164441 --- /dev/null +++ b/scripts/setup-build.py @@ -0,0 +1,74 @@ +#! /usr/bin/env python3 + +import os +import platform +import shutil +import subprocess +import sys + +target = sys.argv[1] +build_type = sys.argv[2] +vcpkg_dir = sys.argv[3] + +project = os.getcwd() + +def mkdir(path): + if not os.path.exists(path) and os.path.isdir(path): + os.mkdir(path) + +def rm(path): + if os.path.exists(path) or os.path.islink(path): + os.remove(path) + +if target == 'gba': + toolchain = '-DCMAKE_TOOLCHAIN_FILE=cmake/modules/GBA.cmake' + nostalgia_build_type = 'GBA' +else: + toolchain = '-DCMAKE_TOOLCHAIN_FILE={:s}/scripts/buildsystems/vcpkg.cmake'.format(vcpkg_dir) + nostalgia_build_type = 'Native' + +if build_type == 'asan': + build_type_arg = 'Debug' + sanitizer_status = 'ON' +elif build_type == 'debug': + build_type_arg = 'Debug' + sanitizer_status = 'OFF' +elif build_type == 'release': + build_type_arg = 'Release' + sanitizer_status = 'OFF' + + +build_config = '{:s}-{:s}'.format(target, build_type) + +if 'NOSTALGIA_QT_PATH' in os.environ: + qt_path = '-DNOSTALGIA_QT_PATH={:s}'.format(os.environ['NOSTALGIA_QT_PATH']) +else: + qt_path = '' + +if shutil.which('ninja') == None: + build_tool = '' +else: + build_tool = '-GNinja' + +build_dir = '{:s}/build/{:s}'.format(project, build_config) +mkdir(build_dir) +subprocess.run(['cmake', '-S', project, '-B', build_dir, build_tool, + '-DCMAKE_EXPORT_COMPILE_COMMANDS=ON', + '-DCMAKE_BUILD_TYPE={:s}'.format(build_type_arg), + '-DUSE_ASAN={:s}'.format(sanitizer_status), + '-DNOSTALGIA_IDE_BUILD=OFF', + '-DNOSTALGIA_BUILD_CONFIG={:s}'.format(build_config), + '-DNOSTALGIA_BUILD_TYPE={:s}'.format(nostalgia_build_type), + qt_path, + toolchain, + ]) + +mkdir('dist') +if target != 'gba': + cb = open('.current_build', 'w') + cb.write(build_type) + cb.close() + +rm('compile_commands.json') +if platform.system() != 'Windows': + os.symlink('build/{:s}/compile_commands.json'.format(build_config), 'compile_commands.json')