eCos配置工具在MSYS2上的编译方法
1 为什么要在MSYS2开发eCos
eCos这样的操作系统,是从GNU的环境中诞生的。正因为如此,它最初的开发环境都是在Linux上的。直到cygwin出现以后,有了在Windows下开发eCos的工具。但是cygwin的发展路线就好比是Linux中的wine(这样比较好像不太贴切),它目的是建立一个完整的GNU环境,所以我们能看到XWindows的几乎一切都可以在cygwin上运行,但这些应用都必须依赖cygwin的运行库。
与此同时,我们必须意识到,即使再钟爱GNU我们也无法让Windows本身有所改变。也许我们可以用GNU的环境来开发出Windows本源的程序更好吧。所以,开始有了MinGW。再这个环境中提供的GCC编译器,可以脱离GNU的模拟层独立运行,当然编译出来的应用程序也是Windows原生的。有很多IDE因此而崛起,它们集成MinGW的GCC,轻松的完成特殊项目的配置和编译。但是,我们还有未解决的问题。因为我们是GNU粉丝,我们还希望能用GNU的思路就开发项目,比如我用autotools,用python, 用lua。于是又有了msys,有个很小的Posix模拟层,让我们之前在Linux上用的GNU Tools能在Windows运行。有了这样的环境,我们就可以利用GNU的开发工具,编译出windows的原生应用程序了。
在MSYS出生的这些年,有无数的开发把它都集成在自己的工具中。但是,天知道为什么MSYS发展会那么缓慢。但是,这是在GNU架构里,只要爱好者需求强烈到一个暴发点,就会有爱好者站出来去发展和改进或者创新。
于是有了MSYS2, 它并不是MSYS的升级版,是不同的组织重新成立的项目,个人认为它是目前看来Windows下最好GNU环境,因为它使用了ArchLinux的pacman包管理工具,而且有更简易的包编译和发布方法。而且它集成了MingW64,能够编译出windows x64和32两种二进制代码。本人使用多年GTK+开发,我们从GTK+的网站上会看到这样一段话:
Downloading GTK and its dependencies The preferred way to obtain GTK+ and its dependencies in binary form for Windows is to use the MSYS2 project. You can use the installer to set up the MSYS2 environment for developing your application by following the instructions on the website. MSYS2 provides packages for the GTK stack, so all you have to do is install them and build your application inside the MSYS2 environment. You can also use MSYS2 to build your application, and create an installer with all the build artifacts necessary for distributing it. You can find more information in this article.
对于我自己而言,MSYS2让我的GTK+环境更利于管理和开发,GTK+官方更认为在Windows开发GTK+应用程序从来没有这么容易过。既然这么好的环境,为什么不能同时用来开发嵌入式系统呢,所以我会在这里建立我需要的嵌入式开发环境,当然从eCos开始。
2 利用MingW64和MSYS2编译出可用的ecosconfig工具
有了之前的分析,我们应该大致已经知道如何入手编译msys2自己的ecosconfig工具了。这里可能要稍微啰嗦两句,eCos在Host上的工具,除了ecosconfig这个配置工具之外,还包括UNIX上的模拟器。但是UNIX上的模拟器,需要运行在XWindow上,因为msys2没有模拟XWindows,因此我们无法正确的编译和运行ecos的模拟器。先浏览一下ecos的目录:
d:\ecos>ls acinclude.m4 aclocal.m4 acsupport ChangeLog configure configure.in COPYING doc examples host Makefile.am Makefile.in packages README.host
如果我们使用eCos根目录的configure,ecos会默认编译host上的所有工具。我们需要执行ecos/host/configure来编译ecosconfig。
- 进入MSYS环境配置编译条件,如下:
rickleaf@msys2 MSYS ~ /ecos/configure --build=x86_64 --with-tk=/mingw64/
- 如果提示没有找到tk的头文件,可能需要从generic里面把tk的头函数复制到tk的根目录。
- MSYS2的64bit版本中,已经不再需要cygwinconvtowin32path这样的函数,因此需要 对代码做部份的修改。下面是需要修改的文件和位置,请大家仔细看。
diff -r 49c50185f3c9 host/tools/configtool/common/common/build.cxx --- a/host/tools/configtool/common/common/build.cxx Mon Dec 29 16:50:47 2014 +0800 +++ b/host/tools/configtool/common/common/build.cxx Sun Dec 27 19:29:13 2015 +0800 @@ -142,13 +142,7 @@ // convert a Cygwin filepath to a DOS filepath std::string nativepath (const std::string input) { -#ifdef __CYGWIN__ - char buffer [MAX_PATH + 1]; - cygwin_conv_to_win32_path (input.c_str (), buffer); - return buffer; -#else return input; -#endif } // convert a DOS filepath to a Cygwin filepath @@ -160,9 +154,7 @@ // convert the DOS filepath to Cygwin notation using Cygwin if available #if defined(__CYGWIN__) && (ECOS_USE_CYGDRIVE == 0) - char buffer [MAX_PATH + 1]; - cygwin_conv_to_posix_path (path.c_str (), buffer); - output = buffer; + ; #else #if ECOS_USE_CYGDRIVE == 1 diff -r 49c50185f3c9 host/tools/configtool/standalone/common/ecosconfig.cxx --- a/host/tools/configtool/standalone/common/ecosconfig.cxx Mon Dec 29 16:50:47 2014 +0800 +++ b/host/tools/configtool/standalone/common/ecosconfig.cxx Sun Dec 27 19:29:13 2015 +0800 @@ -262,13 +262,6 @@ } // convert a DOS format repository directory to POSIX format for backward compatibility (Cygwin only) -#ifdef __CYGWIN__ - if (1 < repository.size() && ':' == repository [1]) { - char buffer [MAX_PATH + 1]; - cygwin_conv_to_posix_path (repository.c_str (), buffer); - repository = buffer; - } -#endif // Initialize the cdl_exec code (not quite sure why this needs a // separate object rather than just a bunch of statics).
经过了上面的折腾,你应该已经可以make出自己的ecosconfig了。
3 利用ecosconfig在MingW64中编译ecos
这个部份有点多余了,因为和Linux的过程是一样的。
rickleaf@msys2 ecosconfig new mini2440 rickleaf@msys2 ecosconfig tree rickleaf@msys2 make
4 结论
MSYS2的环境就好像一个没有图形界面的Linux系统,能提供大部份的Posix应用。再配合MingW64可以和Windows的应用程序结合的更好。希望,MSYS2能更好的发展,让我们能有一个Posix的开发环境。