Skip to content

Commit

Permalink
Merge pull request #351 from berryzplus/feature/update_mingw_makefile
Browse files Browse the repository at this point in the history
MinGWでサクラエディタをビルドできるようにメイクファイルを更新する
  • Loading branch information
berryzplus authored Aug 25, 2018
2 parents 62f742c + c737e5d commit f3825cf
Show file tree
Hide file tree
Showing 11 changed files with 87 additions and 48 deletions.
30 changes: 30 additions & 0 deletions build.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
- [開発者向けの情報](#開発者向けの情報)
- [githash.h の更新のスキップ](#githashh-の更新のスキップ)
- [Powershell によるZIPファイルの圧縮、解凍、内容確認の強制](#powershell-によるzipファイルの圧縮解凍内容確認の強制)
- [MinGW-w64 ビルド](#MinGW-w64-ビルド)

<!-- /TOC -->

Expand Down Expand Up @@ -140,3 +141,32 @@ build-sln.bat x64 Release
build-sln.bat x64 Debug
```

### MinGW w64 ビルド

生成されるバイナリは正しく動作しないが、MinGWでのビルドも可能。


MinGW64のビルド環境

* [pleiades 4.6 Neon](http://mergedoc.osdn.jp/)
* [MSYS2+MinGW-w64](https://gist.github.com/Hamayama/eb4b4824ada3ac71beee0c9bb5fa546d)
* [MinGW-w64](https://sourceforge.net/projects/mingw-w64/files/Toolchains%20targetting%20Win64/)

cpu | thread モデル | 例外モデル | コメント
---- | ---- | ---- | ----
x86_64 | win32 | seh | windows向け。外部DLL不要
x86_64 | posix | seh | 標準。pthreadのDLLが必要
x86_64 | win32 | sjlj | 外部DLL不要
x86_64 | posix | sjlj | pthreadのDLLが必要

標準的なMinGWセットアップでビルドしたバイナリは ```libwinpthread-1.dll``` に依存することに注意。


コマンド実行例

```
path=D:\eclipse4.6\eclipse\mingw\bin;%path%
cd sakura_core
mingw32-make githash stdafx sakura_rc.o
mingw32-make -j4
```
26 changes: 26 additions & 0 deletions sakura/mingw32-del.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
@echo off

SETLOCAL

:引数で渡されたファイル群を取得
set OUTFILES=%*
:パス区切りを置換
set OUTFILES=%OUTFILES:/=\%


:del_file
:1ファイルずつdelコマンドに渡して削除
for /F "tokens=1,*" %%f in ("%OUTFILES%") DO (
if exist %%f del /F /Q %%f
set OUTFILES=%%g
)

:ぜんぶ削除できたら終了
if "%OUTFILES%" == "" goto :EOF
goto :del_file


:END

ENDLOCAL
exit /b
40 changes: 20 additions & 20 deletions sakura_core/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,20 @@ endif
CC= $(PREFIX)gcc
CXX= $(PREFIX)g++
RC= $(RCPREFIX)windres
SUBWCREV= SubWCRev.exe
RM= cmd /c $(CURDIR)/../sakura/mingw32-del.bat

DEFINES= \
-DWIN32 \
-DWINVER=0x500 \
-D_WIN32_WINNT=0x500 \
-D_WIN32_IE=0x501 \
-DMINGW_HAS_SECURE_API=1 \
-DNOMINMAX \
-D_UNICODE \
-DUNICODE \
-DNDEBUG
CFLAGS= -O2 \
-finput-charset=cp932 -fexec-charset=cp932 \
-finput-charset=utf-8 -fexec-charset=cp932 \
-I. \
$(DEFINES) $(MYCFLAGS)
CXXFLAGS= $(CFLAGS) $(MYCXXFLAGS)
Expand Down Expand Up @@ -416,47 +417,46 @@ _os/CDropTarget.o \
_os/COsVersionInfo.o \
sakura_rc.o \

GENERATED_FILES= \
Funccode_define.h \
Funccode_enum.h \
githash.h \

RCTOOLDIR=../btool
RCTOOL=$(RCTOOLDIR)/mrc2grc.exe
HEADERMAKETOOLDIR= ../HeaderMake
HEADERMAKE= $(HEADERMAKETOOLDIR)/HeaderMake.exe

all: $(RCTOOL) $(HEADERMAKE) $(exe)
all: $(exe)

$(exe): Funccode_define.h Funccode_enum.h svnrev stdafx $(OBJS)
$(exe): githash $(OBJS)
$(CXX) -o $@ $(OBJS) $(LIBS)

Funccode_define.h: Funccode_x.hsrc
Funccode_define.h: $(HEADERMAKE) Funccode_x.hsrc
$(HEADERMAKE) -in=../sakura_core/Funccode_x.hsrc -out=../sakura_core/Funccode_define.h -mode=define

Funccode_enum.h: Funccode_x.hsrc
Funccode_enum.h: $(HEADERMAKE) Funccode_x.hsrc
$(HEADERMAKE) -in=../sakura_core/Funccode_x.hsrc -out=../sakura_core/Funccode_enum.h -mode=enum -enum=EFunctionCode

svnrev:
cp svnrev_unknown.h svnrev.h
-$(SUBWCREV) ".\\" ".\svnrev_template.h" ".\svnrev.h"
githash:
cmd /c $(CURDIR)/../sakura/githash.bat ..\\sakura_core

stdafx:
stdafx: Funccode_enum.h StdAfx.h
$(CXX) $(CXXFLAGS) -c StdAfx.h

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

$(RCTOOL): $(RCTOOLDIR)/mrc2grc.cpp
$(CXX) $(CXXFLAGS) $(RCTOOLDIR)/mrc2grc.cpp -o $@ -static-libgcc

$(HEADERMAKE): $(HEADERMAKETOOLDIR)/HeaderMake.cpp
$(CXX) $(CXXFLAGS) $(HEADERMAKETOOLDIR)/HeaderMake.cpp -o $@ -static-libgcc

.rc.o:
$(RCTOOL) $< sakura_grc.rc
$(RC) --language=0411 $(DEFINES) sakura_grc.rc -o $@
$(RM) sakura_grc.rc
sakura_rc.o: Funccode_define.h githash sakura_rc.rc
$(RC) -c utf-8 --language=0411 $(DEFINES) sakura_rc.rc -o $@

clean:
$(RM) $(exe) $(OBJS) $(RCTOOL) $(HEADERMAKE) StdAfx.h.gch
$(RM) $(exe) $(OBJS) $(HEADERMAKE) StdAfx.h.gch $(GENERATED_FILES)

depend: svnrev
depend: githash
$(CXX) -E -MM -w $(DEFINES) $(CXXFLAGS) *.cpp */*.cpp */*/*.cpp > depend.mak

.SUFFIXES: .cpp .o .rc
Expand Down
6 changes: 0 additions & 6 deletions sakura_core/StdAfx.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,6 @@
#endif
#endif

#ifdef __MINGW32__
#include <_mingw.h>
#ifdef MINGW_HAS_SECURE_API
#undef MINGW_HAS_SECURE_API
#endif // MINGW_HAS_SECURE_API
#endif // __MINGW32__
//グローバル
#include "_main/global.h"

Expand Down
2 changes: 1 addition & 1 deletion sakura_core/io/CFileLoad.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -656,7 +656,7 @@ const char* CFileLoad::GetNextLineCharCode(
if( pData[i] == '\x0d' || pData[i] == '\x25' ){
char szEof[3] = {
(pData[i] == '\x25' ? '\x0a' : '\x0d'),
(pData[i+1]== '\x25' ? '\x0a' :
(pData[i+1]== '\x25' ? '\x0a' : (char)
(pData[i+1] == '\x0a' ? 0 : // EBCDIC の"\x0aがLFにならないように細工する
(i + 1 < nDataLen ? pData[i+1] : 0))),
0
Expand Down
12 changes: 0 additions & 12 deletions sakura_core/io/CZipFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,6 @@
#include "StdAfx.h"
#include <ShellAPI.h>
#include "CZipFile.h"
#ifdef __MINGW32__
//uuid(D8F015C0-C278-11CE-A49E-444553540000);
const GUID IID_IShellDispatch =
{
0xD8F015C0, 0xc278, 0x11ce, { 0xa4, 0x9e, 0x44, 0x45, 0x53, 0x54 }
};
// 13709620-C279-11CE-A49E-444553540000
const GUID CLSID_Shell =
{
0x13709620, 0xc279, 0x11ce, { 0xa4, 0x9e, 0x44, 0x45, 0x53, 0x54 }
};
#endif


// コンストラクタ
Expand Down
2 changes: 1 addition & 1 deletion sakura_core/macro/CMacroFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ bool CMacroFactory::RegisterCreator( Creator f )
bool CMacroFactory::Unregister( Creator f )
{
// Creator Listからの削除
auto& c_it = m_mMacroCreators.begin();
auto c_it = m_mMacroCreators.begin();
while( c_it != m_mMacroCreators.end() ){
if( *c_it == f ){
// いきなり削除するとiteratorが無効になるので,
Expand Down
5 changes: 2 additions & 3 deletions sakura_core/mem/CNativeA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,8 @@ void CNativeA::AppendStringF(const char* pszData, ...)
va_end(v);

if (len == -1) {
char cbuf[128];
sprintf_s(cbuf, _countof(cbuf), "AppendStringF error. errno = %d", e);
throw std::exception(cbuf);
DEBUG_TRACE(L"AppendStringF error. errno = %d", e);
throw std::exception();
}

// 追加
Expand Down
5 changes: 2 additions & 3 deletions sakura_core/mem/CNativeW.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,8 @@ void CNativeW::AppendStringF(const wchar_t* pszData, ...)
va_end(v);

if (len == -1) {
char cbuf[128];
sprintf_s(cbuf, _countof(cbuf), "AppendStringF error. errno = %d", e);
throw std::exception(cbuf);
DEBUG_TRACE(L"AppendStringF error. errno = %d", e);
throw std::exception();
}

// 追加
Expand Down
4 changes: 3 additions & 1 deletion sakura_core/util/string_ex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,9 @@ const char* stristr_j( const char* s1, const char* s2 )
// 互換 //
// -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- //

#if (defined(_MSC_VER) && _MSC_VER<1400) || defined(__MINGW32__) //VS2005より前なら
#if (defined(_MSC_VER) && _MSC_VER<1400) \
|| (defined(__MINGW32__) && defined(MINGW_HAS_SECURE_API) && MINGW_HAS_SECURE_API) //VS2005より前なら

errno_t wcscat_s(wchar_t* szDst, size_t nDstCount, const wchar_t* szSrc)
{
// 本物は _set_invalid_parameter_handler で設定されたハンドラが起動します
Expand Down
3 changes: 2 additions & 1 deletion sakura_core/util/string_ex.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,8 @@ int my_strnicmp( const char *s1, const char *s2, size_t n );
// -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- //

// VS2005以降の安全版文字列関数
#if (defined(_MSC_VER) && _MSC_VER<1400) || defined(__MINGW32__) //VS2005より前なら
#if (defined(_MSC_VER) && _MSC_VER<1400) \
|| (defined(__MINGW32__) && defined(MINGW_HAS_SECURE_API) && MINGW_HAS_SECURE_API) //VS2005より前なら
typedef int errno_t;
#define _TRUNCATE ((size_t)-1)
errno_t strcpy_s(char *dest, size_t num, const char *src);
Expand Down

0 comments on commit f3825cf

Please sign in to comment.