Makefile和.Mak文件+ CodeBlocks和VStudio [英] Makefile and .Mak File + CodeBlocks and VStudio

查看:121
本文介绍了Makefile和.Mak文件+ CodeBlocks和VStudio的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对整个makefile概念有点陌生,因此对此有一些疑问.

I am a little new to the whole makefile concept so I have some questions regarding it.

我正在Linux中使用CodeBlocks创建一个项目,我使用了一个名为cbp2mak的工具来从CodeBlocks项目中创建一个.make文件(如果有人知道更好的工具,请告诉我).

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).

现在我不确定.mak和.makefile有什么区别,有人可以告诉我吗?我可以使用"make -C .mak"编译.mak.但是有什么区别?

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?

我尝试使用它的原因是因为我想为我的项目提供源代码,并且希望它可以在linux和Windows中构建,所以我不想将它们提供给我的codeblocks项目文件.所以我想我可以使用可以在linux和Windows中构建的makefile.

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.

我还想在Windows中检查MinGW和VC ++编译器是否同时存在,并使用这两个编译器来构建源代码,在Linux中,它将仅使用GNU GCC.

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.

.mak文件还具有一些宏,可以根据要在Windows或Linux上运行(取决于平台特定文件)来确定要构建的内容.

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.

那么问题:

-.mak和.makefile有什么区别

-What is the difference between .mak and .makefile

-我可以在Windows中运行.mak文件吗?说要使用Visual Studio吗?

-Can I run a .mak file in windows? say using visual studio?

-是否可以对我现在正在做的事情有更好的解决方案?(我使用了cpb2mak,因为它会自动生成一个.mak文件,因为我不知道如何创建makefile文件,因此可以节省大量时间)

-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.

我现在已经放了完整的.mak文件

I have now put up the full .mak file

我的项目也是一个库,我同时构建了它的静态版本和共享版本.该.mak文件是自动生成的,但是我使用ifdef和"shell,uname"对平台句柄进行了填充.功能

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 $< $(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
#

推荐答案

我相信Glen的答案是错误的,因为mak和mk(make)文件根本不一样.它们都用于自动化构建中,但这就是相似性结束的地方.

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文件是一种Microsoft标准,可以从Visual Studio命令提示符下使用以下命令来构建:

mak file is a microsoft standard which can be built with the following command out of a visual studio command prompt:

nmake /f NAMEOFfile.mak

nmake是Visual Studio的一部分,并且mak文件的synthax/结构也将不同于mk(make)文件.

nmake is part of Visual Studio and the mak file's synthax/structure will also differ from mk (make) files.

Make或mk文件主要用于具有跨平台支持的某些实例的Linux构建中(前提是Dev支持Windows).要生成mk文件,您需要使用Autotools或CMake(这些工具在Windows和Linux中均可用).mk文件还将随附一个配置脚本,该脚本需要在make步骤之前运行,而mak/nmake则不是这种情况.

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文件+ CodeBlocks和VStudio的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆