premake 生成makefile
1.编写简单的测试代码,hello_world.cpp
// .cpp file: test hello world #include <iostream> int main() { char szTest[] = "hello world."; std::cout << szTest << std::endl; return 0; }
2.直接编译运行测试代码
g++ hello_world.cpp -o hello_world.out
3.可以在控制台得到输出结果(用来测试程序是否正确,这一步可以跳过)。通过ll指令,可以看到生成的执行文件hello_world.out
4.编写premake脚本, hello_world.lua
solution "hello_world" configurations {"Debug", "Release"} project "hello_world" kind "ConsoleApp" language "C++" files {"**.h", "**.cpp"} configuration "Debug" defines {"DEBUG"} flags {"Symbols"} configuration "Release" defines {"NDEBUG"} flags {"Optimize"}
note:这里脚本比较简单,实际项目会更复杂一些。
5.执行premake脚本,生成makefile文件
premake4 --file=hello_world.lua --os=linux gmake
[root@instance-4420gg0f hello_world]# premake4 --file=hello_world.lua --os=linux gmake Building configurations... Running action 'gmake'... Generating Makefile... Generating hello_world.make... Done. [root@instance-4420gg0f hello_world]# ll 总用量 28 -rw-r--r-- 1 root root 147 9月 18 13:48 hello_world.cpp -rw-r--r-- 1 root root 455 9月 18 13:54 hello_world.lua -rw-r--r-- 1 root root 2959 9月 18 14:08 hello_world.make -rwxr-xr-x 1 root root 9056 9月 18 13:59 hello_world.out -rw-r--r-- 1 root root 721 9月 18 14:08 Makefile
可以看到执行成功,通过ll指令,可以看到生成了hello_world.make和Makefile文件。
6.指定通过premake4生成的Makefile文件
[root@instance-4420gg0f hello_world]# make ==== Building hello_world (debug) ==== Creating obj/Debug hello_world.cpp Linking hello_world [root@instance-4420gg0f hello_world]# ll 总用量 52 -rwxr-xr-x 1 root root 19736 9月 18 14:13 hello_world -rw-r--r-- 1 root root 147 9月 18 13:48 hello_world.cpp -rw-r--r-- 1 root root 455 9月 18 13:54 hello_world.lua -rw-r--r-- 1 root root 2959 9月 18 14:08 hello_world.make -rwxr-xr-x 1 root root 9056 9月 18 13:59 hello_world.out -rw-r--r-- 1 root root 721 9月 18 14:08 Makefile drwxr-xr-x 3 root root 4096 9月 18 14:13 obj
通过上面可以看到,make指令默认是debug模式。通过ll指令可以看到生成hello_world执行文件。
7.运行执行文件
[root@instance-4420gg0f hello_world]# ./hello_world
hello world.
8.下面来说一下其它的东西。
obj,这是个文件夹,存放的是编译过程中生成的中间文件;可以通过make clean来清除文件夹里的文件。

浙公网安备 33010602011771号