posts - 45,  comments - 232,  trackbacks - 0

最近在FreeBSD上写ACE程序,发现写Makefile很烦人,就用perl写了个小程序自动完成。

#!/usr/local/bin/perl
#print program note
use Env;

print("#----------------------------------------------------------------------------\n");
print("# Build ACE Program Perl v0.1\n");
print("# (C)2006 C2217 Studio\n");
print("#----------------------------------------------------------------------------\n\n");
print("#----------------------------------------------------------------------------\n");
print("#       Local macros\n");
print("#----------------------------------------------------------------------------\n\n");
#set bin's name
if(@ARGV==0)
{
 $bin="main";
}
else
{
 $bin=$ARGV[0];
}

print("BIN\t= $bin\n\n");
print("FILES\t= ");

$some_dir = ".";
opendir(DIR, $some_dir) || die "can't opendir $some_dir: $!";

@cpp_files = grep { /\.cpp$/ } readdir(DIR);
if(@cpp_files == 0)
{
 die("Error:No cpp file\n");
}

foreach $cpp_file_name (@cpp_files)
{
 $cpp_file_name =~ s/\.cpp//;
 print("$cpp_file_name ");
 push @cpp_file_names,$cpp_file_name;
}

print("\n\n");
print("SRC      = \$(addsuffix .cpp,\$(FILES))\n");
print("OBJ     = \$(addsuffix .o,\$(FILES))\n\n");
print("LDLIBS  =\n\n");
print("VLDLIBS = \$(LDLIBS:%=%\$(VAR))\n\n");
print("BUILD   = \$(VBIN)\n\n");

print("#----------------------------------------------------------------------------\n");
print("#       Include macros and targets\n");
print("#----------------------------------------------------------------------------\n\n");
print("include \$(ACE_ROOT)/include/makeinclude/wrapper_macros.GNU\n");
print("include \$(ACE_ROOT)/include/makeinclude/macros.GNU\n");
print("include \$(ACE_ROOT)/include/makeinclude/rules.common.GNU\n");
print("include \$(ACE_ROOT)/include/makeinclude/rules.nonested.GNU\n");
print("include \$(ACE_ROOT)/include/makeinclude/rules.bin.GNU\n");
print("include \$(ACE_ROOT)/include/makeinclude/rules.local.GNU\n");

print("#----------------------------------------------------------------------------\n");
print("#       Local macros\n");
print("#----------------------------------------------------------------------------\n\n");
print("# DO NOT DELETE THIS LINE -- g++dep uses it.\n");
print("# DO NOT PUT ANYTHING AFTER THIS LINE, IT WILL GO AWAY.\n\n\n");

$std_ace_file_name = $ENV{"ACE_ROOT"}."/ace/stdace.h";

foreach $cpp_file_name (@cpp_file_names)

 #create object file
 print(".obj/$cpp_file_name.o : $cpp_file_name.cpp");
 
 $cpp_file_name.=".cpp";
 @std_ace_files = &get_include_files($std_ace_file_name);
 foreach $std_file (@std_ace_files)
 {
  &print_include_file($std_file);
 }
 
 @include_files_at_cpp = &get_include_files($cpp_file_name);
 
 foreach $include_file_name (@include_files_at_cpp)
 {
  
#@include_files_at_header = &get_include_files($include_file_name);
  #foreach $include_file_name_at_header(@include_files_at_header)
  #{
  # &print_include_file($include_file_name_at_header);
  #} 
  if($std_ace_file_name ne $include_file_name)
  {
   &print_include_file($include_file_name);
  }

 }
 
 print("\n\n");
 
}
print("# IF YOU PUT ANYTHING HERE IT WILL GO AWAY\n");
closedir DIR;

sub print_include_file()
{
 my($file_name)=@_;
 #It's a ace include file
 if($file_name =~/^ace/)
 {
  print("
\\\n \$(ACE_ROOT)/$file_name ");
 }
 else
 {
  print("
\\\n $file_name ");
 }
}

sub get_include_files
{
 my($file_name)=@_;
 my(@include_files);
 #Open file
 open(file_handle,$file_name)||die("Error:open file $file_name fail.\n");
 my(@file_lines)= <file_handle>;
 #print("#Parse $file_name ....for get include files.\n");
 foreach $file_line (@file_lines)
 {
  if($file_line=~/^#include\s+"(\S+)"/)
  {
   push @include_files,$1;
  } 
 }

 return @include_files;
}


stdace.h文件的内容很简单,包含通常的ACE程序所使用的头文件。内容以下:
#include "ace/OS_main.h"
#include "ace/ACE_export.h"
#include "ace/pre.h"
#include "ace/config.h"
#include "ace/$(ACE_PLATFORM_CONFIG)"
#include "ace/post.h"
#include "ace/ace_wchar.h"
#include "ace/ace_wchar.inl"
#include "ace/streams.h"
#include "ace/config-all.h"
#include "ace/Log_Msg.h"
#include "ace/Global_Macros.h"
#include "ace/OS_Errno.h"
#include "ace/os_include/os_errno.h"
#include "ace/OS_Errno.inl"
#include "ace/Default_Constants.h"
#include "ace/Log_Priority.h"
#include "ace/os_include/os_limits.h"
#include "ace/os_include/os_unistd.h"
#include "ace/os_include/sys/os_types.h"
#include "ace/os_include/os_stddef.h"
#include "ace/os_include/os_inttypes.h"
#include "ace/os_include/os_stdint.h"
#include "ace/os_include/os_stdio.h"
#include "ace/os_include/os_stdarg.h"
#include "ace/OS_Log_Msg_Attributes.h"
#include "ace/iosfwd.h"
#include "ace/OS_Log_Msg_Attributes.inl"
#include "ace/OS_NS_unistd.h "
#include "ace/Time_Value.h"
#include "ace/os_include/sys/os_time.h"
#include "ace/Time_Value.inl"
#include "ace/OS_NS_sys_time.h"
#include "ace/OS_NS_sys_time.inl"
#include "ace/OS_NS_unistd.inl"
#include "ace/OS_NS_sys_utsname.h"
#include "ace/os_include/sys/os_utsname.h"
#include "ace/OS_NS_sys_utsname.inl"
#include "ace/OS_NS_string.h"
#include "ace/Basic_Types.h"
#include "ace/os_include/os_float.h"
#include "ace/os_include/os_stdlib.h"
#include "ace/os_include/sys/os_wait.h"
#include "ace/os_include/os_signal.h"
#include "ace/os_include/os_time.h"
#include "ace/os_include/os_ucontext.h"
#include "ace/os_include/sys/os_resource.h"
#include "ace/Basic_Types.i"
#include "ace/OS_NS_string.inl"
#include "ace/OS_NS_wchar.h"
#include "ace/os_include/os_wchar.h"
#include "ace/os_include/os_string.h"
#include "ace/os_include/os_ctype.h"
#include "ace/OS_NS_wchar.inl"
#include "ace/OS_NS_errno.h"
#include "ace/OS_NS_errno.inl"
#include "ace/OS_NS_macros.h"
#include "ace/OS_NS_fcntl.h"
#include "ace/os_include/os_fcntl.h"
#include "ace/os_include/sys/os_stat.h"
#include "ace/OS_NS_fcntl.inl"
#include "ace/OS_Memory.h"
#include "ace/OS_NS_stdlib.h"
#include "ace/OS_NS_stdlib.inl"
#include "ace/Object_Manager_Base.h"
#include "ace/Cleanup.h"
#include "ace/Cleanup.inl"
#include "ace/Object_Manager_Base.inl"
#include "ace/os_include/os_search.h"
#include "ace/OS_Memory.inl"


工程中,默认使用main.cpp作为最终的编译目标,只是为了方便。
你可以通过其他的参数来指定新的最终编译模块。

posted on 2006-01-16 22:21 天下无双 阅读(1703) 评论(1)  编辑 收藏 引用

FeedBack:
# re: 自动编写ACE程序Makefile文件的Perl程序
2007-04-05 15:54 | fanged
不是有一个MPC可以用吗?  回复  更多评论
  

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   博问   Chat2DB   管理



常用链接

留言簿(15)

随笔分类

随笔档案

相册

我的其它领域Blog

搜索

  •  

积分与排名

  • 积分 - 204126
  • 排名 - 130

最新评论

阅读排行榜

评论排行榜