views:

705

answers:

1

Hey guys, 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'm 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 $< $(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
#
A: 

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

Glen
Yeah sorry, I'm writing from somwhere else now so I don't have .mak file with me but I'll post something up along lines
iQ
@iQ From what you've posted that does look like a Makefile, just one with a different name.
Glen
So the nmake utility from microsoft will happily run the .mak file I generated?What if the .mak file also wants to compile with MinGW as well as VC++ will the nmake utility complain? Or is there any better tools?
iQ
Some makefiles are specific to certain make programs. for example pmake and standard make seem to have issues running makefiles that target each other. What does the documentation for cbp2mak documentation (if any) state?
Glen
sadly there is not much documentation just a readme telling how to use it. It just generates a .mak file which I have no posted above. Honestly I don't understand most of it so i'm not sure if it will run on windows.I'm not sure of any good multi-platform build system, Linux is the main target so it would be ideal to have a gnu compatible make system. What about cmake? does that generate a make file that can be written on a GNU make system? Or does the user need to have cmake installed which I am trying to avoid.
iQ