便便代码人生

关注技术, 偶尔动动手

[原]用perl写了个自动配置脚本

Posted by bianbian on 2007-04-08 11:26


本文Tags: , ,

经常要安装各种包,而且每个包的configure参数千差万别;而且以后升级版本或者换个机器装的话又记不得加哪些参数,实在不方便。于是写了个自动配置的脚本。
升级包的版本的时候要把旧版本的目录删除。
我自己用觉得很方便,主要是为了记录configure的参数,省得用到的时候又得找。

配置:
在@list里面第1行写好包的前缀名(省去版本,能grep出唯一结果即可);紧接一行是configure的参数

使用:
./autoConfigure.pl <参数>
<参数>:make(每个目录调用make);install(每个目录调用make install);其他(每个目录configure)

第二次用perl,写得烂不要见效。

  1. #!/usr/bin/perl
  2.  
  3. # AutoConfigure
  4. # first line:  name to match, like nginx-
  5. # second line: configure parameters
  6. @list = (
  7.   "nginx-",
  8.   "--prefix=/home/nginx --without-http_browser_module"
  9.   ,
  10.   "fcgi-",
  11.   "--prefix=/usr"
  12. );
  13.  
  14. # -------- below need not to modify --------
  15. for($i=0; $i < @list; $i += 2) {
  16.   $cmd = "ls -d */ | grep \"$list[$i]\" |";
  17.   open (PIPE, $cmd);
  18.   @out = <PIPE>;
  19.   chomp($out[0]); #chop \n
  20.   $cmd = "cd " . $out[0] . "; ";
  21.   if ($ARGV[0] eq "make") {
  22.     $cmd .= "make";
  23.   } elsif ($ARGV[0] eq "install") {
  24.     $cmd .= "make install";
  25.   } else {
  26.     $cmd .= "./configure " . $list[$i + 1];
  27.   }
  28.   close PIPE;
  29.   $cmd .= "; cd ..";
  30.   system($cmd);
  31. }
标签: , ,

遵守创作共用协议,转载请链接形式注明来自http://bianbian.org 做人要厚道

相关日志

Posted in Linux, Technology | 2 Comments »