QT용 Makefile

qmake가 생성해주는 Makefile은 너무.. 너저분하다..
아래와 같이 심플하게 만들어 봤다.


QT = c:/Qt/2010.05/qt
CC = g++
DEFINES = -DUNICODE -DQT_LARGEFILE_SUPPORT -DQT_DLL \
		  -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB \
		  -DQT_THREAD_SUPPORT -DQT_NEEDS_QMAIN
CFLAGS = -O2 -frtti -fexceptions -mthreads -Wall $(DEFINES)
INCPATH = -I$(QT)/include/QtCore -I$(QT)/include/QtGui \
		  -I$(QT)/include -I$(QT)/include/ActiveQt \
		  -I$(QT)/mkspecs/win32-g++
LFLAGS = -enable-stdcall-fixup -Wl,-enable-auto-import \
		 -Wl,-enable-runtime-pseudo-reloc \
		 -mthreads -Wl -Wl,-subsystem,windows
LIBS = -L$(QT)/lib -lmingw32 -lqtmaind -lQtGuid4 -lQtCored4 

SOURCES     = main.cpp mainwindow.cpp \
			  moc_mainwindow.cpp qrc_dockwidgets.cpp
TARGET      = dockwidgets.exe
OBJECTS 	= $(SOURCES:.cpp=.o)

.SUFFIXES:
.SUFFIXES: .cpp .o
.cpp.o:
	$(CC) -c $(CFLAGS) $(INCPATH) -o $*.o $<

all: $(TARGET)

moc_%.cpp: %.h
	moc $< -o $@

qrc_%.cpp: %.qrc
	rcc -name $(basename $<) $< -o $@

$(TARGET): $(OBJECTS)
	$(CC) $(LFLAGS) -o $@ $(OBJECTS) $(LIBS)

clean:
	rm -f *.o *.exe moc_*.cpp qrc_*.cpp

Makefile 예제

가끔 만들어 써야하는데, 이런 샘플이 있으면 좋을것 같아 정리해둔다.

# for make

CC = gcc
TARGET = sample

LDFLAGS = 
CFLAGS = 

# User code comes here
USER_SRCS = 

SRC = ./sample.c $(USER_SRCS)
OBJS = $(SRC:.c=.o)

.SUFFIXES:
.SUFFIXES: .c .o
.c.o: ; $(CC) -c $(CFLAGS) -o $*.o $<

all: $(TARGET)

$(TARGET): $(OBJS)
	$(CC) -o $@ $(OBJS) $(LDFLAGS)

run: all
	$(TARGET)

clean:
	$(RM) -f $(OBJS) $(TARGET)

Visual C++ 8.0 Makefile 예제

커맨드 라인을 자주 이용하는 나는..
Visual Studio 6.0 이후부터는 “Export Makefile” 메뉴를 지원하지 않는다는 별로 반갑지 않은 글을 보고야 말았다. 젠장!!
고로 Makefile 샘플하나씩 가지고 있으면 좋을것이다.
아래는 직접 작성한 “Xtreme Tool Kit”을 이용한 예제의 Makefile이다.

XTP 	= C:\Program Files\Codejock Software\MFC\Xtreme ToolkitPro v12.1.1
OUTDIR	= .\Release
TARGET 	= test.exe

# -------------------------------
ALL: $(OUTDIR)\$(TARGET)

# -------------------------------
"$(OUTDIR)":
	if not exist "$(OUTDIR)" mkdir "$(OUTDIR)"

# -------------------------------
MT		= 	mt.exe

RSC		= 	rc.exe
RSC_PROJ=	/d "_DEBUG" /d "_AFXDLL" /l 0x409\
		 	/i "$(XTP)\Source"\
			/i "$(XTP)\Samples\AboutDlg"\
			/fo".\test.res"

CPP		= 	cl.exe
CFLAGS 	= 	/D "WIN32" /D "NDEBUG" /D "_WINDOWS"\
			/D "_AFXDLL" /D "_MBCS" /nologo /MD /W3 /O2\
			/I"$(XTP)\Source"\
			/Fp"test.pch"\
			/Yc"stdafx.h" /FD /Zm200 /c

LINK32	= 	link.exe
LDFLAGS	= 	/nologo /subsystem:windows /incremental:no \
			/machine:I386\
			/out:"$(OUTDIR)\test.exe"\
			/libpath:"$(XTP)\lib\vc80"

SRC = 	StdAfx.cpp ChildFrm.cpp\
		CntrItem.cpp ControlSelector.cpp\
		MainFrm.cpp SmartLayout.cpp SmartLayoutDoc.cpp\
		SmartLayoutView.cpp StdAfx.cpp\
		test.res
OBJS = $(SRC:.cpp=.obj)

# -------------------------------
CLEAN:
	-@DEL /q *.idb *.pch
	-@DEL /q $(OBJS)
	-@RMDIR /s /q $(OUTDIR)

# -------------------------------
# Compile
.SUFFIXES:
.SUFFIXES: .cpp .obj
.cpp.obj:
	$(CPP) $(CFLAGS) /Fo$*.obj $<

# -------------------------------
# Link
$(OUTDIR)\$(TARGET): $(OUTDIR) $(OBJS)
	$(LINK32) $(LDFLAGS) $(OBJS)
	$(MT) -nologo -manifest test.exe.manifest -outputresource:$(OUTDIR)\test.exe
	-@DEL $(OUTDIR)\test.exe.manifest

# -------------------------------
# Resource
test.res: test.rc
	$(RSC) $(RSC_PROJ) test.rc