Conscript-pk3 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. # build pk3 on the fly
  2. Import qw( INSTALL_DIR BUILD_DIR CONFIG_DIR CC CXX LINK );
  3. use Data::Dumper;
  4. $env = new cons(); # the env on which we will be working for all pk3s (NOTE: maybe we need several ctually)
  5. $hcf_do_exec = 1;
  6. sub do_command($)
  7. {
  8. printf("@_[0]\n");
  9. if ($hcf_do_exec)
  10. {
  11. system("@_[0]");
  12. }
  13. }
  14. sub build_pk3 {
  15. sub launch {
  16. #print "In launch\n";
  17. $Data::Dumper::Indent = 2;
  18. #print Dumper(@_);
  19. $tmpdir = "/tmp/pk3-builder$$";
  20. do_command("rm -rf $tmpdir");
  21. ($target, $sets) = @_;
  22. $base=`basename $target`; chomp($base);
  23. $dirname=`dirname $target`; chomp($dirname);
  24. foreach (@{$sets})
  25. {
  26. ($sourcepath, $destpath, $file) = @{$_};
  27. #print "source: $sourcepath dest: $destpath file: $file\n";
  28. do_command("mkdir -p $tmpdir/$destpath");
  29. if ($sourcepath =~ /#.*/)
  30. {
  31. #print "$sourcepath is absolute\n";
  32. $sourcepath =~ s/#//;
  33. if (ref($file))
  34. {
  35. foreach(@{$file})
  36. {
  37. do_command("cp $sourcepath/$_ $tmpdir/$destpath/$_");
  38. }
  39. }
  40. else
  41. {
  42. do_command("cp $sourcepath/$file $tmpdir/$destpath/$file");
  43. }
  44. }
  45. else
  46. {
  47. #print "$sourcepath in linked dir\n";
  48. if (ref($file))
  49. {
  50. foreach(@{$file})
  51. {
  52. do_command("cp $BUILD_DIR/$sourcepath/$_ $tmpdir/$destpath/$_");
  53. }
  54. }
  55. else
  56. {
  57. do_command("cp $BUILD_DIR/$sourcepath/$file $tmpdir/$destpath/$file");
  58. }
  59. }
  60. }
  61. do_command("cd $tmpdir ; zip -r $base *");
  62. do_command("mkdir -p $BUILD_DIR/$dirname");
  63. do_command("cp $tmpdir/$base $BUILD_DIR/$target");
  64. do_command("rm -rf $tmpdir");
  65. return 1;
  66. }
  67. # extract the parameters
  68. ($target, $sets) = @_;
  69. $base=`basename $target`; chomp($base);
  70. $dirname=`dirname $target`; chomp($dirname);
  71. # the build command is stored and called later on by cons
  72. # this makes it impossible to have several build_pk3 working together
  73. # there is probably a cleaner solution than this hack, but this works
  74. $target_uniquename="target_$base";
  75. $target_uniquename=~s/\.//g;
  76. eval("\$$target_uniquename=\$target");
  77. $sets_uniquename="sets_$base";
  78. $sets_uniquename=~s/\.//g;
  79. eval("\$$sets_uniquename=\$sets");
  80. #print "name: $target_uniquename after the hack: $target_pak8pk3";
  81. # don't pass @{@_} .. since this will be called during the process
  82. $command = "[perl] &launch( \$$target_uniquename, [ \@{\$$sets_uniquename} ] )";
  83. #print "$command\n";
  84. foreach(@{$sets})
  85. {
  86. ($sourcepath, $destpath, $file) = @{$_};
  87. if (ref($file))
  88. {
  89. foreach(@{$file})
  90. {
  91. Depends $env $target, $sourcepath . '/' . $_;
  92. }
  93. }
  94. else
  95. {
  96. Depends $env $target, $sourcepath . '/' . $file;
  97. }
  98. }
  99. Command $env $target, $command;
  100. Install $env $INSTALL_DIR . "/$dirname", $target;
  101. }
  102. # quick rundown on the syntax:
  103. # <target file>, [ <fileset1>, <fileset2>, ... ]
  104. # where <fileset>: [ <source directory>, <directory in zip>, <file1>, <file2>, .. ]
  105. build_pk3('baseq3/pak8.pk3',
  106. [ [ '#../../../media/Q3Media-1.32/baseq3/menu/art', 'menu/art', 'pblogo.tga' ],
  107. [ '../Q3/q3_ui/q3_ui', 'vm', 'ui.qvm' ],
  108. [ '../Q3/cgame/cgame', 'vm', 'cgame.qvm' ],
  109. [ '../Q3/game/game', 'vm', 'qagame.qvm' ] ]
  110. );
  111. build_pk3('missionpack/pak3.pk3',
  112. [ [ '#../ui', 'ui', [ 'createserver.menu', 'joinserver.menu', 'filter.menu', 'punkbuster.menu', 'menus.txt' ] ],
  113. [ '../TA/ui/ui', 'vm', 'ui.qvm' ],
  114. [ '../TA/cgame/cgame', 'vm', 'cgame.qvm' ],
  115. [ '../TA/game/game', 'vm', 'qagame.qvm' ],
  116. [ '#../../../media/Q3Media-1.32/missionpack/scripts', 'scripts', 'models2.shader' ] ]
  117. );