嘿伙计们,我对整个makefile概念有点新意,所以我对此有一些疑问。
我正在使用linux中的CodeBlocks创建一个项目,我使用一个名为cbp2mak的工具从CodeBlocks项目中创建一个.make文件(如果有人知道更好的工具,请告诉我)。
现在我不确定.mak和.makefile之间的区别是什么,谁能告诉我?我可以使用“make -C .mak”编译.mak,但有什么区别?
我试图使用它的原因是因为我想为我的项目提供源代码并希望它可以在linux和windows中构建,所以我不想给他们我的codeblocks项目文件。所以我想我可以使用一个可以用来构建linux和windows的makefile。
我还想检查Windows中是否存在MinGW和VC ++编译器,并使用两个编译器构建源代码,在Linux中它只能使用GNU GCC。
.mak文件还有一些宏来确定要构建的内容,具体取决于它是否在Windows或Linux上运行,因为有特定于平台的文件。
所以问题:
- .mak和.makefile
之间有什么区别- 我在Windows中运行.mak文件?说使用visual studio?
对于我现在正在做的事情,是否有更好的解决方案? (我使用cpb2mak,因为它会自动生成.mak文件,因为我不知道如何创建makefile,所以节省了大量时间)
也可以随时提供有关此方面的任何建议或提示。
编辑:
我现在已经提供了完整的.mak文件
此外,我的项目是一个库,我构建了它的静态和共享版本。 .mak文件是自动生成的,但是我使用ifdef和“shell,uname”函数来支持平台句柄
# project performer-1.0
export PATH := /opt/wx/2.8/bin:$(PATH)
export LD_LIBRARY_PATH := /opt/wx/2.8/lib:$(LD_LIBRARY_PATH)
_WX = /home/gr/projects/gui/codeblocks/wx
_WX.LIB = $(_WX)/lib
_WX.INCLUDE = $(_WX)/include
_CB = /home/gr/projects/gui/codeblocks/cb/src
_CB.INCLUDE = $(_CB)/include
_CB.LIB = $(_CB)/devel
CFLAGS_C = $(filter-out -include "sdk.h",$(CFLAGS))
# -----------------------------------------
# MAKE_DEP = -MMD -MT $@ -MF $(@:.o=.d)
CFLAGS = -Wall
INCLUDES = -I../performer-1.0
LDFLAGS = -s
RCFLAGS =
LDLIBS = $(T_LDLIBS) -lrt -lboost_regex-gcc43-mt -lxerces-c -lstdc++
LINK_exe = gcc -o $@ $^ $(LDFLAGS) $(LDLIBS)
LINK_con = gcc -o $@ $^ $(LDFLAGS) $(LDLIBS)
LINK_dll = gcc -o $@ $^ $(LDFLAGS) $(LDLIBS) -shared
LINK_lib = rm -f $@ && ar rcs $@ $^
COMPILE_c = gcc $(CFLAGS_C) -o $@ -c $< $(MAKEDEP) $(INCLUDES)
COMPILE_cpp = g++ $(CFLAGS) -o $@ -c $< $(MAKEDEP) $(INCLUDES)
COMPILE_rc = windres $(RCFLAGS) -J rc -O coff -i $< -o $@ -I$(dir $<)
%.o : %.c ; $(COMPILE_c)
%.o : %.cpp ; $(COMPILE_cpp)
%.o : %.cxx ; $(COMPILE_cpp)
%.o : %.rc ; $(COMPILE_rc)
.SUFFIXES: .o .d .c .cpp .cxx .rc
all: all.before all.targets all.after
all.before :
-
all.after : $(FIRST_TARGET)
# -----------------------------------------------------------
ifeq "$(shell uname)" "Linux"
# -----------------------------------------------------------
all.targets : Linux_Dynamic_target Linux_Static_target
# -----------------------------------------------------------
else
# -----------------------------------------------------------
all.targets : Windows_Dynamic_target
# -----------------------------------------------------------
endif
# -----------------------------------------------------------
clean :
rm -fv $(clean.OBJ)
rm -fv $(DEP_FILES)
.PHONY: all clean distclean
# -----------------------------------------------------------
ifeq "$(shell uname)" "Linux"
# -----------------------------------------------------------
# -----------------------------------------
# Linux_Dynamic_target
Linux_Dynamic_target.BIN = libs/libperformer-1.so
Linux_Dynamic_target.OBJ = src/analysis/analyzer.o src/analysis/comparer.o src/analysis/paverage.o src/analysis/pfunctor.o src/analysis/pmax.o src/analysis/pmin.o src/config/configfile.o src/data_collection/datacollector.o src/data_collection/linux/linfactory.o src/data_collection/linux/linmemprof.o src/data_collection/linux/lintimer.o src/data_collection/linux/procsmaps.o src/data_collection/linux/procstatus.o src/data_collection/pstructs.o src/data_collection/resultxml.o
DEP_FILES += src/analysis/analyzer.d src/analysis/comparer.d src/analysis/paverage.d src/analysis/pfunctor.d src/analysis/pmax.d src/analysis/pmin.d src/config/configfile.d src/data_collection/datacollector.d src/data_collection/linux/linfactory.d src/data_collection/linux/linmemprof.d src/data_collection/linux/lintimer.d src/data_collection/linux/procsmaps.d src/data_collection/linux/procstatus.d src/data_collection/pstructs.d src/data_collection/resultxml.d
clean.OBJ += $(Linux_Dynamic_target.BIN) $(Linux_Dynamic_target.OBJ)
Linux_Dynamic_target : Linux_Dynamic_target.before $(Linux_Dynamic_target.BIN) Linux_Dynamic_target.after_always
Linux_Dynamic_target : CFLAGS += -Wall -g -Os
Linux_Dynamic_target : INCLUDES +=
Linux_Dynamic_target : RCFLAGS +=
Linux_Dynamic_target : LDFLAGS += $(CREATE_LIB) $(CREATE_DEF)
Linux_Dynamic_target : T_LDLIBS =
ifdef LMAKE
Linux_Dynamic_target : CFLAGS -= -O1 -O2 -g -pipe
endif
Linux_Dynamic_target.before :
Linux_Dynamic_target.after_always : $(Linux_Dynamic_target.BIN)
$(Linux_Dynamic_target.BIN) : $(Linux_Dynamic_target.OBJ)
$(LINK_dll)
# -----------------------------------------
# Linux_Static_target
Linux_Static_target.BIN = libs/libperformer-1.a
Linux_Static_target.OBJ = src/analysis/analyzer.o src/analysis/comparer.o src/analysis/paverage.o src/analysis/pfunctor.o src/analysis/pmax.o src/analysis/pmin.o src/config/configfile.o src/data_collection/datacollector.o src/data_collection/linux/linfactory.o src/data_collection/linux/linmemprof.o src/data_collection/linux/lintimer.o src/data_collection/linux/procsmaps.o src/data_collection/linux/procstatus.o src/data_collection/pstructs.o src/data_collection/resultxml.o
DEP_FILES += src/analysis/analyzer.d src/analysis/comparer.d src/analysis/paverage.d src/analysis/pfunctor.d src/analysis/pmax.d src/analysis/pmin.d src/config/configfile.d src/data_collection/datacollector.d src/data_collection/linux/linfactory.d src/data_collection/linux/linmemprof.d src/data_collection/linux/lintimer.d src/data_collection/linux/procsmaps.d src/data_collection/linux/procstatus.d src/data_collection/pstructs.d src/data_collection/resultxml.d
clean.OBJ += $(Linux_Static_target.BIN) $(Linux_Static_target.OBJ)
Linux_Static_target : Linux_Static_target.before $(Linux_Static_target.BIN) Linux_Static_target.after_always
Linux_Static_target : CFLAGS += -Wall -g -Os
Linux_Static_target : INCLUDES +=
Linux_Static_target : RCFLAGS +=
Linux_Static_target : LDFLAGS += $(CREATE_DEF)
Linux_Static_target : T_LDLIBS =
ifdef LMAKE
Linux_Static_target : CFLAGS -= -O1 -O2 -g -pipe
endif
Linux_Static_target.before :
Linux_Static_target.after_always : $(Linux_Static_target.BIN)
$(Linux_Static_target.BIN) : $(Linux_Static_target.OBJ)
$(LINK_lib)
# -----------------------------------------
# -----------------------------------------------------------
else
# -----------------------------------------------------------
# -----------------------------------------
# Windows_Dynamic_target
Windows_Dynamic_target.BIN = libs/performer-1.so
Windows_Dynamic_target.OBJ = src/analysis/analyzer.o src/analysis/comparer.o src/analysis/paverage.o src/analysis/pfunctor.o src/analysis/pmax.o src/analysis/pmin.o src/config/configfile.o src/data_collection/datacollector.o src/data_collection/pstructs.o src/data_collection/resultxml.o src/data_collection/windows/winfactory.o src/data_collection/windows/wintimer.o
DEP_FILES += src/analysis/analyzer.d src/analysis/comparer.d src/analysis/paverage.d src/analysis/pfunctor.d src/analysis/pmax.d src/analysis/pmin.d src/config/configfile.d src/data_collection/datacollector.d src/data_collection/pstructs.d src/data_collection/resultxml.d src/data_collection/windows/winfactory.d src/data_collection/windows/wintimer.d
clean.OBJ += $(Windows_Dynamic_target.BIN) $(Windows_Dynamic_target.OBJ)
Windows_Dynamic_target : Windows_Dynamic_target.before $(Windows_Dynamic_target.BIN) Windows_Dynamic_target.after_always
Windows_Dynamic_target : CFLAGS += -Wall -g -Os
Windows_Dynamic_target : INCLUDES +=
Windows_Dynamic_target : RCFLAGS +=
Windows_Dynamic_target : LDFLAGS += $(CREATE_LIB) $(CREATE_DEF)
Windows_Dynamic_target : T_LDLIBS =
ifdef LMAKE
Windows_Dynamic_target : CFLAGS -= -O1 -O2 -g -pipe
endif
Windows_Dynamic_target.before :
Windows_Dynamic_target.after_always : $(Windows_Dynamic_target.BIN)
$(Windows_Dynamic_target.BIN) : $(Windows_Dynamic_target.OBJ)
$(LINK_dll)
ifdef MAKE_DEP
-include $(DEP_FILES)
endif
# -----------------------------------------------------------
endif
#
答案 0 :(得分:1)
我认为没有区别。它只是一个不同名称的makefile。
尝试编辑您的问题并张贴.mak文件的内容,然后我们会更清楚
答案 1 :(得分:1)
我相信Glen的答案是不正确的,因为mak和mk(make)文件完全没有相同。它们都用于自动构建,但这就是相似性结束的地方。
mak文件是一个微软标准,可以使用visual studio命令提示符中的以下命令构建:
nmake /f NAMEOFfile.mak
nmake是Visual Studio的一部分,mak文件的synthax /结构也不同于mk(make)文件。
Make或mk文件主要用于Linux版本,并提供一些跨平台支持实例(假设Dev支持Windows)。要构建mk文件,您需要Autotools或CMake(这些工具在Windows和Linux中均可用)。 mk文件还将附带一个需要在make步骤之前运行的配置脚本,这与mak / nmake不同。