Makefileについて
Qtで、ちょっとしたプログラムを書いたのですが、あえてqmakeは使わずに自分でMakefileを書いてみました。
以下、Makefileの内容(タブは全角空白2個に置き換えてます)
#QtApp template
#Variables
# Package infomation
NAME = DPMWindow
# Resources
C_SOURCE =
CPP_SOURCE = src/DPMArk.cpp\
src/DPMMaster.cpp \
src/DPMNode.cpp \
src/DPMResult.cpp \
src/DPMWindow.cpp \
src/main.cpp
MO_HEADER = include/DPMWindow.h
UI = share/ui/DPMWindow/DPMWindow.ui
OTHER_RESOURCE1 = share/icons/DPMWindow/icon.png
OTHER_RESOURCE2 =
# Compiling settings
DEFINE = -DPATH=\"/usr/local\"
INC_DIR = include
LIB_DIR =
LINK_LIB_FLAG =
PKG_CONFIG = `pkg-config --cflags --libs QtGui`
OUTPUT_DIR = bin
# Install settings
INSTALL_ROOT = /usr/local
BIN_INSTALL_DIR = bin
OTHER_RESOURCE1_INSTALL_DIR = share/icons/DPMWindow
OTHER_RESOURCE2_INSTALL_DIR =
#Invariables
# Package infomation
BIN_FILE_NAME = $(NAME)
# Resources
MOC_CPP_SOURCE = $(MO_HEADER:%.h=%.mo.cpp)
UI_HEADER = $(UI:%.ui=%.ui.h)
OBJ = $(C_SOURCE:%.c=%.o) $(CPP_SOURCE:%.cpp=%.o) $(MOC_CPP_SOURCE:%.cpp=%.o)
# Compiling and Archiving settings
OUTPUT = $(OUTPUT_DIR)/$(BIN_FILE_NAME)
INCLUDE_FLAG = $(patsubst %,-I%,$(INC_DIR)) $(patsubst %,-I%,$(dir $(UI)))
LIB_FLAG = $(patsubst %,-L%,$(LIB_DIR))
# Commands
CC = gcc -o
CPPC = g++ -o
CC_OBJ = gcc -c -o
CPPC_OBJ = g++ -c -o
MOC = moc-qt4 -o
UIC = uic-qt4 -o
RM = rm -Rf
MKDIR = mkdir -p
TEST = test -d
INSTALL = install -m 0755 -p
CP = cp -R
# Install settings
INSTALLED_BIN = $(addprefix $(INSTALL_ROOT)/$(BIN_INSTALL_DIR)/, $(notdir $(OUTPUT)))
INSTALLED_OTHER1 = $(addprefix $(INSTALL_ROOT)/$(OTHER_RESOURCE1_INSTALL_DIR)/, $(notdir $(OTHER_RESOURCE1)))
INSTALLED_OTHER2 = $(addprefix $(INSTALL_ROOT)/$(OTHER_RESOURCE2_INSTALL_DIR)/, $(notdir $(OTHER_RESOURCE2)))
all: $(OUTPUT)
$(OUTPUT): $(UI_HEADER) $(OBJ)
$(CPPC) $(OUTPUT) $(OBJ) $(LIB_FLAG) $(LINK_LIB_FLAG) $(PKG_CONFIG)
%.o: %.c
$(CC_OBJ) "$@" $(DEFINE) $(INCLUDE_FLAG) $(LIB_FLAG) "$<" $(LINK_LIB_FLAG) $(PKG_CONFIG)
%.o: %.cpp
$(CPPC_OBJ) "$@" $(DEFINE) $(INCLUDE_FLAG) $(LIB_FLAG) "$<" $(LINK_LIB_FLAG) $(PKG_CONFIG)
%.mo.cpp: %.h
$(MOC)"$@" "$<"
%.ui.h: %.ui
$(UIC) "$@" "$<"
clean:
$(RM) $(OBJ) $(MOC_CPP_SOURCE) $(UI_HEADER)
$(RM) ./*/*~ ./*~
install: install_bin install_other1 install_other2
install_bin:
$(TEST) $(INSTALL_ROOT)/$(BIN_INSTALL_DIR) | $(MKDIR) $(INSTALL_ROOT)/$(BIN_INSTALL_DIR)
$(INSTALL) $(OUTPUT) $(INSTALL_ROOT)/$(BIN_INSTALL_DIR)/$(LIB_FILE_NAME)
install_other1: $(OTHER_RESOURCE1)
$(OTHER_RESOURCE1):
$(TEST) $(INSTALL_ROOT)/$(OTHER_RESOURCE1_INSTALL_DIR) | $(MKDIR) $(INSTALL_ROOT)/$(OTHER_RESOURCE1_INSTALL_DIR)
$(CP) $(OTHER_RESOURCE1) $(INSTALL_ROOT)/$(OTHER_RESOURCE1_INSTALL_DIR)
install_other2: $(OTHER_RESOURCE2)
$(OTHER_RESOURCE2):
$(TEST) $(INSTALL_ROOT)/$(OTHER_RESOURCE2_INSTALL_DIR) | $(MKDIR) $(INSTALL_ROOT)/$(OTHER_RESOURCE2_INSTALL_DIR)
$(CP) $(OTHER_RESOURCE2) $(INSTALL_ROOT)/$(OTHER_RESOURCE2_INSTALL_DIR)
uninstall: uninstall_bin
uninstall_bin:
$(RM) $(INSTALLED_BIN)
以上、Makefileの内容
makeはちゃんとでき、プログラムも実行できるのですが、makeの最後に記述した覚えのない
rm include/DPMWindow.mo.cpp
が実行されます。
まぁ、別に困らないのですが、Makefileを何度か見直しても分からなかったので、原因が分かれば回答をお願いします。