开发者

makefile which build the library (lib.a)from the list of object files (*.o)

I have a problem because i have never written any makefile. So if any could help me I become happy. I have a lot of different .开发者_运维问答o files, which stored in the different folders. For example:

folder1: obj1.o

folder2: obj2.o

folder3: obj3.o

I need makefile, which will build the library from files which I send to makefile like param. Param should be makefile too and include info about folders where stored necessary files.

For example I would like to build lib from objects stored at folder1 and folder2 without folder3. So makefile which I send as param to the main makefile must include routes to folder1 and folder2:

local_libs := ../folder1

local_libs += ../folder2

main makefile should parse that info and call libtool utilite for creating lib from files at this folders. Could anybody help?

I suppose it is easy for realization, example will be great!


You need a rule that inputs the .o files, outputs the .a file and calls the ar command to do the work. Something like:

lib.a: $(OBJECTS)
    ${AR} -cr ${@} ${^}


GNU make does not support passing parameters "to the makefile" on the command line.

You have two basic mechanism for setting parameters to be used by make while executing a makefile (I'm assuming that you are using GNU make, and not all of his advice will apply to other makes):

  • Write to submakefiles, possibly using a script. If you makefile has a line like

    include file.mk
    

    gmake will include the contents of file.mk. Change the contents of file.mk and you change the behavior of your makefile.

  • Make can take variable values from environment variables when set. This provides a powerful mechanism for letting the user customize the behavior of your makefile.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜