Makefile 和 .Mak 文件 + CodeBlocks 和 VStudio
我对整个 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 文件吗?说使用视觉工作室?
-对于我现在正在做的事情,有更好的解决方案吗? (我使用 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
#
I am a little new to the whole makefile concept so I have some questions regarding it.
I am creating a project using CodeBlocks in linux, I used a tool called cbp2mak to create a .make file out of the CodeBlocks project (if anyone knows a better tool please let me know).
Now I am not sure what the difference is between .mak and .makefile, could anyone tell me? I can compile .mak using "make -C .mak" but what is the difference?
The reason im trying to use it is because I want provide the source code for my project and want it to be buildable in both linux and windows so I don't want to give them my codeblocks project file. So i thought I could use a makefile that can be used to build in both linux and windows.
I would also like to check in Windows if both MinGW and VC++ compiler exists and build the source with both compilers, in Linux it will be only with GNU GCC.
The .mak file also has some macros to determine what to build depending on if it is being run on windows or linux as there are platform specific files.
So questions:
-What is the difference between .mak and .makefile
-Can I run a .mak file in windows? say using visual studio?
-Could there be a better solution to what I am doing now? (I used cpb2mak as it automatically generates a .mak file which saves a lot of time as I don't know how to create makefiles)
Also feel free to provide any advice or tips regarding this.
EDIT:
I have now put up the full .mak file
Also my project is a library which I build both a static and shared versions of it. The .mak file was auto generated but I hadded the platform handle with the ifdef and "shell, uname" function
# 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 lt; $(MAKEDEP) $(INCLUDES)
COMPILE_cpp = g++ $(CFLAGS) -o $@ -c lt; $(MAKEDEP) $(INCLUDES)
COMPILE_rc = windres $(RCFLAGS) -J rc -O coff -i lt; -o $@ -I$(dir lt;)
%.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
#
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我相信 Glen 的答案是不正确的,因为 mak 和 mk (make) 文件根本不一样。它们都用于自动化构建,但相似之处仅此而已。
mak 文件是一个 microsoft 标准,可以在 Visual Studio 命令提示符下使用以下命令构建:
nmake 是 Visual Studio 的一部分,mak 文件的合成/结构也与 mk (make) 文件不同。
Make 或 mk 文件主要用于具有跨平台支持的某些实例的 Linux 构建(前提是开发支持 Windows)。要构建 mk 文件,您需要 Autotools 或 CMake(这些工具在 Windows 和 Linux 中都可用)。 mk 文件还将附带一个配置脚本,该脚本需要在 make 步骤之前运行,而 mak/nmake 则不然。
I beleive Glen's answer is incorrect as mak and mk (make) files are not at all the same. They are both used in automating builds but that's where the similarity ends.
mak file is a microsoft standard which can be built with the following command out of a visual studio command prompt:
nmake is part of Visual Studio and the mak file's synthax/structure will also differ from mk (make) files.
Make or mk files are mainly used in Linux builds with some instances of Cross Platform support (provided that the Dev is supporting Windows). To build mk file you need either Autotools or CMake (these tools are available in both Windows and Linux). mk files will also be accompanied with a configure script that needs to be run before the make step which is not the case for mak/nmake.
我认为没有什么区别。它只是一个不同名称的 makefile。
尝试编辑您的问题并发布 .mak 文件的内容,然后我们会更清楚
I don't think there is a difference. It's just a makefile by a different name.
Try editing your question and posting up the contents of the .mak file and it'll be clearer to us then