[C++] 221 Visual C++ : 非IDE開発環境 その5 アプリMakefile Debug, Release

[Windows11, Visual C++2017, FLTK 1.3.8, GNU Make 3.81, NO IDE]

カラーアプリのMakefileをDebugモード、Releaseモードで実行できるようにしました。

# コンパイラ設定他
COMPILER = cl
DEBUG = /D "_DEBUG"
# DEBUG = 
CONSOLE = /SUBSYSTEM:CONSOLE
WINDOWS = /SUBSYSTEM:WINDOWS
LINKER = LINK
RESOURCE = "D:\code\VC++\Projects\ColorSampleJP\images\ColorSampleJP.res"

# オプション設定
CPPFLAGS = /std:c++17 /GS /W3 /Zc:wchar_t /ZI /Gm- /Od /sdl  /Zc:inline /fp:precise /D "_UNICODE" \
/errorReport:prompt /WX- /Zc:forScope /RTC1 /Gd /MDd /FC /c /diagnostics:column /EHsc
LDFLAGS = /MACHINE:X64

# includeパス(-I)
INCLUDE = /I"C:\packages\fltk-1.3.8\include" \
/I"C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.30.30705\atlmfc\include" \
/I"C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.30.30705\include" \
/I"C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\VS\include" \
/I"C:\Program Files (x86)\Windows Kits\10\Include\10.0.22000.0\ucrt" \
/I"C:\Program Files (x86)\Windows Kits\10\Include\10.0.22000.0\um" \
/I"C:\Program Files (x86)\Windows Kits\10\Include\10.0.22000.0\shared" \
/I"C:\Program Files (x86)\Windows Kits\10\Include\10.0.22000.0\winrt" \
/I"C:\Program Files (x86)\Windows Kits\10\Include\10.0.22000.0\cppwinrt" \
/I"C:\Program Files (x86)\Windows Kits\NETFXSDK\4.8\Include\um" \
/I"D:\code\VC++\Projects\ColorSampleJP\include" \
/I"D:\code\VC++\Projects\ColorConvert\ColorConvert" \
/I"D:\code\VC++\Projects\Split\Split" \
/I"D:\code\VC++\mylib_vc\include" \
/I"D:\code\VC++\Projects\ColorSampleJP\images"

# ライブラリ(-l)
LIBRARY_l = /DYNAMICBASE "wsock32.lib" "comctl32.lib" \
"kernel32.lib" "user32.lib" "gdi32.lib" "winspool.lib" \
"comdlg32.lib" "advapi32.lib" "shell32.lib" "ole32.lib" "oleaut32.lib" \
"uuid.lib" "odbc32.lib" "odbccp32.lib" \
"CharExtract.lib" "Funcs.lib" "ColorConvert.lib" "Split.lib"

LIBRARY_l_Debug = "fltkd.lib" "fltk_jpegd.lib" "fltk_imagesd.lib"
LIBRARY_l_Release = "fltk.lib" "fltk_jpeg.lib" "fltk_images.lib"

# ライブラリパス(-L)
LIBRARY_L = /LIBPATH:"C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.30.30705\ATLMFC\lib\x64" \
/LIBPATH:"C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.30.30705\lib\x64" \
/LIBPATH:"C:\Program Files (x86)\Windows Kits\NETFXSDK\4.8\lib\um\x64" \
/LIBPATH:"C:\Program Files (x86)\Windows Kits\10\lib\10.0.22000.0\ucrt\x64" \
/LIBPATH:"C:\Program Files (x86)\Windows Kits\10\\lib\10.0.22000.0\\um\x64" \
/LIBPATH:"D:\code\VC++\mylib_vc\lib"

LIBRARY_L_Debug = /LIBPATH:"C:\packages\fltk-1.3.8\lib\Debug" \
/LIBPATH:"D:\code\VC++\Projects\ColorConvert\x64\Debug" \
/LIBPATH:"D:\code\VC++\Projects\Split\x64\Debug"
LIBRARY_L_Release = /LIBPATH:"C:\packages\fltk-1.3.8\lib\Release" \
/LIBPATH:"D:\code\VC++\Projects\ColorConvert\x64\Release" \
/LIBPATH:"D:\code\VC++\Projects\Split\x64\Release"

# ソースファイル
SRCDIR = .\src
SRCS = $(SRCDIR)\btnAction.cpp $(SRCDIR)\FileChooser.cpp $(SRCDIR)\FileChooser2.cpp $(SRCDIR)\main.cpp \
$(SRCDIR)\modalDialog.cpp $(SRCDIR)\searchLocation.cpp $(SRCDIR)\csvProcessChar.cpp

# オブジェクトファイル
OBJDIR = .\obj
OBJS = $(OBJDIR)\btnAction.obj $(OBJDIR)\FileChooser.obj $(OBJDIR)\FileChooser2.obj $(OBJDIR)\main.obj \
$(OBJDIR)\modalDialog.obj $(OBJDIR)\searchLocation.obj $(OBJDIR)\csvProcessChar.obj

# 実行ファイル
TARGETDIR = .\bin
TARGET = ColorSampleJP.exe

# cppファイルからoファイル作成 $<:依存ファイル
$(OBJDIR)\btnAction.obj: $(SRCDIR)\btnAction.cpp
	$(COMPILER) $(CPPFLAGS) $(DEBUG) $(INCLUDE) $<
	move btnAction.obj $(OBJDIR) >nul

$(OBJDIR)\FileChooser.obj: $(SRCDIR)\FileChooser.cpp
	$(COMPILER) $(CPPFLAGS) $(DEBUG) $(INCLUDE) $<
	move FileChooser.obj $(OBJDIR) >nul

$(OBJDIR)\FileChooser2.obj: $(SRCDIR)\FileChooser2.cpp
	$(COMPILER) $(CPPFLAGS) $(DEBUG) $(INCLUDE) $<
	move FileChooser2.obj $(OBJDIR) >nul

$(OBJDIR)\main.obj: $(SRCDIR)\main.cpp
	$(COMPILER) $(CPPFLAGS) $(DEBUG) $(INCLUDE) $<
	move main.obj $(OBJDIR) >nul

$(OBJDIR)\modalDialog.obj: $(SRCDIR)\modalDialog.cpp
	$(COMPILER) $(CPPFLAGS) $(DEBUG) $(INCLUDE) $<
	move modalDialog.obj $(OBJDIR) >nul

$(OBJDIR)\searchLocation.obj: $(SRCDIR)\searchLocation.cpp
	$(COMPILER) $(CPPFLAGS) $(DEBUG) $(INCLUDE) $<
	move searchLocation.obj $(OBJDIR) >nul

$(OBJDIR)\csvProcessChar.obj: $(SRCDIR)\csvProcessChar.cpp
	$(COMPILER) $(CPPFLAGS) $(DEBUG) $(INCLUDE) $<
	move csvProcessChar.obj $(OBJDIR) >nul

# oファイルから実行ファイル作成
$(TARGET):$(OBJS)
	$(LINKER) $(CONSOLE) $(LIBRARY_l) $(LIBRARY_l_Debug) $(LIBRARY_L) $(LIBRARY_L_Debug) $(OBJS) $(LDFLAGS) $(RESOURCE)
	rename btnAction.exe $(TARGET)
	move $(TARGET) $(TARGETDIR) >nul

# Releaseモード
# $(TARGET):$(OBJS)
# 	$(LINKER) $(WINDOWS) $(LIBRARY_l) $(LIBRARY_l_Release) $(LIBRARY_L) $(LIBRARY_L_Release) $(OBJS) $(LDFLAGS) $(RESOURCE)
# 	rename btnAction.exe $(TARGET)
# 	move $(TARGET) $(TARGETDIR) >nul

# ビルド
.PHONY:all
all: clean $(TARGET)

# ファイル削除
.PHONY:clean
clean:
	del /Q $(TARGET) $(OBJS) vc140.idb vc140.pdb