Skip to content

Commit

Permalink
MinGW用のビルドバッチを組みなおす
Browse files Browse the repository at this point in the history
  • Loading branch information
berryzplus committed May 18, 2021
1 parent fab295e commit 11755f1
Show file tree
Hide file tree
Showing 7 changed files with 249 additions and 36 deletions.
61 changes: 58 additions & 3 deletions build-gnu.bat
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,69 @@ if "%configuration%" == "Release" (

@rem https://www.appveyor.com/docs/environment-variables/
@rem path=C:\mingw-w64\x86_64-7.2.0-posix-seh-rt_v5-rev1\mingw64\bin;%path%
path=C:\msys64\mingw64\bin;%path%
path=C:\msys64\usr\bin;%path:C:\msys64\usr\bin;=%
path=C:\msys64\mingw64\bin;%path:C:\msys64\mingw64\bin;=%

@echo mingw32-make -C sakura_core MYDEFINES="%MYDEFINES%" MYCFLAGS="%MYCFLAGS%" MYLIBS="%MYLIBS%"
mingw32-make -C sakura_core MYDEFINES="%MYDEFINES%" MYCFLAGS="%MYCFLAGS%" MYLIBS="%MYLIBS%" -j4
:: find generic tools
if not defined CMD_NINJA call %~dp0tools\find-tools.bat

@rem create output directory, all executables will be placed here.
set OUTDIR=../../../../%platform%/%configuration%
mkdir "%~dp0%platform%\%configuration%" > NUL 2>&1

@rem build "sakura_core".
set SAKURA_CORE_MAKEFILE=%~dp0sakura_core\Makefile
set SAKURA_CORE_BUILD_DIR=%~dp0build\%platform%\%configuration%\sakura_core
mkdir "%SAKURA_CORE_BUILD_DIR%" > NUL 2>&1
pushd "%SAKURA_CORE_BUILD_DIR%"
mingw32-make -f "%SAKURA_CORE_MAKEFILE%" MYDEFINES="%MYDEFINES%" MYCFLAGS="%MYCFLAGS%" MYLIBS="%MYLIBS%" OUTDIR=%OUTDIR% StdAfx.h.gch sakura_rc.o
if errorlevel 1 (
echo error 2 errorlevel %errorlevel%
popd
exit /b 1
)
mingw32-make -f "%SAKURA_CORE_MAKEFILE%" MYDEFINES="%MYDEFINES%" MYCFLAGS="%MYCFLAGS%" MYLIBS="%MYLIBS%" OUTDIR=%OUTDIR% -j4
if errorlevel 1 (
echo error 2 errorlevel %errorlevel%
popd
exit /b 1
)
popd

@rem build "sakura_lang_en_US".
set SAKURA_LANG_EN_US_MAKEFILE=%~dp0sakura_lang_en_US\Makefile
set SAKURA_LANG_EN_US_BUILD_DIR=%~dp0build\%platform%\%configuration%\sakura_lang_en_US
mkdir "%SAKURA_LANG_EN_US_BUILD_DIR%" > NUL 2>&1
pushd "%SAKURA_LANG_EN_US_BUILD_DIR%"
mingw32-make -f "%SAKURA_LANG_EN_US_MAKEFILE%" MYDEFINES="%MYDEFINES%" SAKURA_CORE=../sakura_core OUTDIR=%OUTDIR%
if errorlevel 1 (
echo error 2 errorlevel %errorlevel%
popd
exit /b 1
)
popd

@rem build "googletest".
call %~dp0tests\googletest.build.cmd %~dp0build\%platform%\%configuration%\gtest_build\ %~dp0build\%platform%\%configuration%\googletest\
if errorlevel 1 (
echo error 2 errorlevel %errorlevel%
popd
exit /b 1
)

@rem build "tests1".
set TESTS1_MAKEFILE=%~dp0tests\unittests\Makefile
set TESTS1_BUILD_DIR=%~dp0build\%platform%\%configuration%\tests1
mkdir "%TESTS1_BUILD_DIR%" > NUL 2>&1
pushd "%TESTS1_BUILD_DIR%"
mingw32-make -f "%TESTS1_MAKEFILE%" MYDEFINES="%MYDEFINES%" SAKURA_CORE=../sakura_core OUTDIR=%OUTDIR% -j4
if errorlevel 1 (
echo error 2 errorlevel %errorlevel%
popd
exit /b 1
)
popd

exit /b 0


Expand Down
3 changes: 2 additions & 1 deletion ci/azure-pipelines/template.job.build-on-msys2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ jobs:
displayName: Build with MinGW-w64-gcc

# Unit tests
- script: tests\build-and-test.bat $(BuildPlatform) $(Configuration)
- pwsh: .\tests1.exe --gtest_output=xml:$(build.sourcesDirectory)\tests1.exe-googletest-$(BuildPlatform)-$(Configuration).xml
workingDirectory: $(build.sourcesDirectory)\$(BuildPlatform)\$(Configuration)
displayName: Unit test

# see https://docs.microsoft.com/en-us/azure/devops/pipelines/tasks/utility/copy-files?view=azure-devops&tabs=yaml
Expand Down
7 changes: 2 additions & 5 deletions ci/azure-pipelines/template.steps.install-mingw-w64-gcc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,5 @@
# なし
#############################################################################################################
steps:
- script: C:\msys64\usr\bin\bash --login -c "pacman -S --noconfirm p7zip"
displayName: install 7zip

- script: C:\msys64\usr\bin\bash --login -c "pacman -S --noconfirm mingw-w64-x86_64-gtest"
displayName: install MinGW-w64-gtest
- script: echo nothing to do.
displayName: nothing to do
6 changes: 3 additions & 3 deletions sakura_core/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ MKDIR = md
RM = del
DIRSEP = $(strip \ )
DEVNULL = NUL
ICONV = C:\msys64\usr\bin\iconv.exe
SED = C:\msys64\usr\bin\sed.exe
P7Z = C:\msys64\usr\bin\7z
ICONV = iconv.exe
SED = sed.exe
P7Z = 7z.exe
else
# If unix-like shell is used.
MKDIR = mkdir -p
Expand Down
4 changes: 2 additions & 2 deletions sakura_lang_en_US/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ MKDIR = md
RM = del
DIRSEP = $(strip \ )
DEVNULL = NUL
ICONV = C:\msys64\usr\bin\iconv.exe
SED = C:\msys64\usr\bin\sed.exe
ICONV = iconv.exe
SED = sed.exe
else
# If unix-like shell is used.
MKDIR = mkdir -p
Expand Down
54 changes: 32 additions & 22 deletions tests/googletest.build.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,18 @@ set GOOGLETEST_INSTALL_PATH=%~dp2
set SOURCE_DIR=%~dp0googletest

:: find generic tools
if not defined CMD_VSWHERE call %~dp0..\tools\find-tools.bat

set /a NUM_VSVERSION_NEXT=NUM_VSVERSION + 1
if not defined CMD_NINJA call %~dp0..\tools\find-tools.bat

if not exist "%CMD_CMAKE%" (
echo "no cmake found."
exit /b 1
)

if not exist "%CMD_NINJA%" (
echo "no ninja found."
exit /b 1
)

pushd "%SOURCE_DIR%" || exit /b 1
if not exist CMakeLists.txt (
if not exist "%CMD_GIT%" (
Expand All @@ -24,16 +27,6 @@ if not exist CMakeLists.txt (
)
popd

if not exist "%CMD_NINJA%" (
set GENERATOR="%CMAKE_G_PARAM%"
set GENERATOR_OPTS=-A %PLATFORM% "-DCMAKE_CONFIGURATION_TYPES=Debug;Release"
set "MAKE_PROGRAM=%CMD_MSBUILD%"
) else (
set GENERATOR=Ninja
set GENERATOR_OPTS=-DCMAKE_BUILD_TYPE=%CONFIGURATION%
set "MAKE_PROGRAM=%CMD_NINJA%"
)

mkdir %BUILD_DIR% > NUL 2>&1
pushd %BUILD_DIR%

Expand All @@ -47,21 +40,27 @@ call :run_cmake_configure
goto :EOF

:run_cmake_configure
call :find_cl_compiler

:: replace back-slash to slash in the path.
set CL_COMPILER=%CMD_CL:\=/%
if "%PLATFORM%" == "Win32" (
call :find_cl_compilers
)
if "%PLATFORM%" == "x64" (
call :find_cl_compilers
)
if "%PLATFORM%" == "MinGW" (
call :find_gcc_compilers
)

:: install lib64 for x64-platform.
if "%PLATFORM%" == "x64" (
set GENERATOR_OPTS=-DCMAKE_INSTALL_LIBDIR=lib64 %GENERATOR_OPTS%
)

:: run cmake configuration.
"%CMD_CMAKE%" -G %GENERATOR% ^
"-DCMAKE_MAKE_PROGRAM=%MAKE_PROGRAM%" ^
"-DCMAKE_C_COMPILER=%CL_COMPILER%" ^
"-DCMAKE_CXX_COMPILER=%CL_COMPILER%" ^
"%CMD_CMAKE%" -G Ninja ^
"-DCMAKE_MAKE_PROGRAM=%CMD_NINJA%" ^
"-DCMAKE_C_COMPILER=%C_COMPILER%" ^
"-DCMAKE_CXX_COMPILER=%CXX_COMPILER%" ^
-DCMAKE_BUILD_TYPE=%CONFIGURATION% ^
-DCMAKE_INSTALL_PREFIX=%GOOGLETEST_INSTALL_PATH% ^
%GENERATOR_OPTS% ^
-DBUILD_GMOCK=OFF ^
Expand All @@ -71,9 +70,20 @@ if "%PLATFORM%" == "x64" (
|| endlocal && exit /b 1
goto :EOF

:find_cl_compiler
:find_cl_compilers
call :find_cl
set C_COMPILER=%CMD_CL:\=/%
set CXX_COMPILER=%CMD_CL:\=/%
goto :EOF

:find_cl
for /f "usebackq delims=" %%a in (`where cl.exe`) do (
set "CMD_CL=%%a"
goto :EOF
)
goto :EOF

:find_gcc_compilers
set C_COMPILER=C:/msys64/mingw64/bin/gcc.exe
set CXX_COMPILER=C:/msys64/mingw64/bin/g++.exe
goto :EOF
150 changes: 150 additions & 0 deletions tests/unittests/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
# Makefile for MinGW32/MinGW-W64

# Example usages:
# Out-of-source build (build in the same directory as sakura_core):
# $ mkdir -p build/MinGW/Release/
# $ cd build/MinGW/Release
# $ mingw32-make -f ../../../tests/unittests/Makefile SAKURA_CORE=. OUTDIR=. -j4
#
# Out-of-source build (create tests1 and sakura_core in a common directory):
# $ mkdir -p build/MinGW/Release/tests1/
# $ cd build/MinGW/Release/tests1
# $ mingw32-make -f ../../../../tests/unittests/Makefile OUTDIR=.. -j4
#
# Debug build with coverage:
# $ cd tests/unittests
# $ mingw32-make MYCFLAGS="-g --coverage" MYLIBS=--coverage -j4

# Path of "sakura_core" directory. Compute it from the path of Makefile.
SRCDIR = $(patsubst %/,%,$(subst \,/,$(dir $(firstword $(MAKEFILE_LIST)))))

# If SRCDIR is different from the current directory, set it to VPATH.
# (If SRCDIR ends with a backslash, remove it before set to VPATH.)
ifneq ($(SRCDIR),.)
VPATH = $(patsubst %\,%,$(SRCDIR))
endif

# The directory where "sakura_core" is built.
SAKURA_CORE = ../sakura_core

GOOGLETEST_INSTALL_DIR = ../googletest

# The directory where the .exe files will be output.
# If empty, they will be output to the default directories.
OUTDIR =

ifeq ($(SHELL),sh.exe)
# If cmd.exe is used as a shell.
MKDIR = md
RM = del
DIRSEP = $(strip \ )
DEVNULL = NUL
else
# If unix-like shell is used.
MKDIR = mkdir -p
RM = rm -f
DIRSEP = /
DEVNULL = /dev/null
endif

ifndef PREFIX
PREFIX=
RCPREFIX=
else ifeq ($(PREFIX),x86_64-w64-mingw32-)
RCPREFIX=$(PREFIX)
else ifeq ($(PREFIX),i686-w64-mingw32-)
ifeq ($(OS),Windows_NT)
RCPREFIX=
else
RCPREFIX=$(PREFIX)
endif
endif

CC= $(PREFIX)gcc
CXX= $(PREFIX)g++
RC= $(RCPREFIX)windres

DEFINES= \
-DWIN32 \
-D_WIN32_WINNT=_WIN32_WINNT_WIN7 \
-D_UNICODE \
-DUNICODE \
$(MYDEFINES)

ifeq (,$(findstring -D_DEBUG,$(DEFINES)))
ifeq (,$(findstring -DNDEBUG,$(DEFINES)))
DEFINES += -DNDEBUG
endif
else
LIB_SUFFIX = d
endif

CFLAGS= \
-finput-charset=utf-8 \
-fexec-charset=cp932 \
-MMD \
-isystem $(GOOGLETEST_INSTALL_DIR)/include \
-I$(SAKURA_CORE) \
-I$(SRCDIR)/../../sakura_core \
-I. \
-I$(SRCDIR) \
$(DEFINES) $(MYCFLAGS)

CXXFLAGS= $(CFLAGS) \
-std=c++17 \
$(MYCXXFLAGS)

LIBS= \
-static \
-lwinspool \
-lole32 \
-loleaut32 \
-luuid \
-lcomctl32 \
-limm32 \
-lmpr \
-limagehlp \
-lshlwapi \
-lwinmm \
-lwindowscodecs \
-lmsimg32 \
-lkernel32 \
-lgdi32 \
-lcomdlg32 \
-L$(GOOGLETEST_INSTALL_DIR)/lib \
-lgtest$(or $(LIB_SUFFIX),) \
-lgtest_main$(or $(LIB_SUFFIX),) \
$(MYLIBS)

exe= $(or $(OUTDIR),.)/tests1.exe

SRCS = $(wildcard $(SRCDIR)/test-*.cpp) \
$(wildcard $(SRCDIR)/code-*.cpp)
OBJS = $(SRCS:$(SRCDIR)/%.cpp=%.o)

DEPS= $(OBJS:%.o=%.d)

SAKURA_SRCS = $(wildcard $(SRCDIR)/../../sakura_core/*.cpp) \
$(wildcard $(SRCDIR)/../../sakura_core/*/*.cpp) \
$(wildcard $(SRCDIR)/../../sakura_core/*/*/*.cpp)
SAKURA_OBJS = $(SAKURA_SRCS:$(SRCDIR)/../../sakura_core/%.cpp=$(SAKURA_CORE)/%.o) \
$(SAKURA_CORE)/sakura_rc.o

all: $(exe)

$(exe): $(OBJS) $(SAKURA_OBJS)
$(CXX) -o $@ $(OBJS) $(SAKURA_OBJS) $(LIBS)

.cpp.o:
$(CXX) $(CXXFLAGS) -o $@ -c $<

$(OBJS):

clean:
-$(RM) $(subst /,$(DIRSEP),$(exe) $(OBJS))
-$(RM) $(subst /,$(DIRSEP),$(DEPS))

.SUFFIXES: .cpp .o
.PHONY: all clean

-include $(DEPS)

0 comments on commit 11755f1

Please sign in to comment.