aboutsummaryrefslogtreecommitdiffstats
path: root/code/unix/Conscript-pk3
blob: 9232ae4dc58bbeb5501d2269330cf0e8ba1e67f3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# build pk3 on the fly

Import qw( INSTALL_DIR BUILD_DIR CONFIG_DIR CC CXX LINK );

use Data::Dumper;

$env = new cons(); # the env on which we will be working for all pk3s (NOTE: maybe we need several ctually)

$hcf_do_exec = 1;
sub do_command($)
{
  printf("@_[0]\n");
  if ($hcf_do_exec)
  {
    system("@_[0]");
  }
}

sub build_pk3 {

	sub launch {
		#print "In launch\n";		
		$Data::Dumper::Indent = 2;
		#print Dumper(@_);
		$tmpdir = "/tmp/pk3-builder$$";
		do_command("rm -rf $tmpdir");
		
		($target, $sets) = @_;
		$base=`basename $target`; chomp($base);
		$dirname=`dirname $target`; chomp($dirname);
		
		foreach (@{$sets})
		{
			($sourcepath, $destpath, $file) = @{$_};
			#print "source: $sourcepath dest: $destpath file: $file\n";
			do_command("mkdir -p $tmpdir/$destpath");
			if ($sourcepath =~ /#.*/)
			{
				#print "$sourcepath is absolute\n";
				$sourcepath =~ s/#//;
				if (ref($file))
				{
					foreach(@{$file})
					{
						do_command("cp $sourcepath/$_ $tmpdir/$destpath/$_");
					}
				}
				else
				{
					do_command("cp $sourcepath/$file $tmpdir/$destpath/$file");
				}
			}
			else
			{
				#print "$sourcepath in linked dir\n";
				if (ref($file))
				{
					foreach(@{$file})
					{
						do_command("cp $BUILD_DIR/$sourcepath/$_ $tmpdir/$destpath/$_");
					}
				}
				else
				{
					do_command("cp $BUILD_DIR/$sourcepath/$file $tmpdir/$destpath/$file");
				}
			}			
		}
		
		do_command("cd $tmpdir ; zip -r $base *");
		do_command("mkdir -p $BUILD_DIR/$dirname");
		do_command("cp $tmpdir/$base $BUILD_DIR/$target");
		do_command("rm -rf $tmpdir");
		
		return 1;
	}
	
	# extract the parameters
	($target, $sets) = @_;
	
	$base=`basename $target`; chomp($base);
	$dirname=`dirname $target`; chomp($dirname);
	
	# the build command is stored and called later on by cons
	# this makes it impossible to have several build_pk3 working together
	# there is probably a cleaner solution than this hack, but this works
	$target_uniquename="target_$base";
	$target_uniquename=~s/\.//g;
	eval("\$$target_uniquename=\$target");
	$sets_uniquename="sets_$base";
	$sets_uniquename=~s/\.//g;
	eval("\$$sets_uniquename=\$sets");
	#print "name: $target_uniquename after the hack: $target_pak8pk3";
	
	# don't pass @{@_} .. since this will be called during the process
	$command = "[perl] &launch( \$$target_uniquename, [ \@{\$$sets_uniquename} ] )";
	#print "$command\n";
		
	foreach(@{$sets})
	{
		($sourcepath, $destpath, $file) = @{$_};
		if (ref($file))
		{
			foreach(@{$file})
			{
				Depends $env $target, $sourcepath . '/' . $_;
			}
		}
		else
		{
			Depends $env $target, $sourcepath . '/' . $file;
		}
	}
	Command $env $target, $command;
	Install $env $INSTALL_DIR . "/$dirname", $target;
}

# quick rundown on the syntax:
# <target file>, [ <fileset1>, <fileset2>, ... ]
# where <fileset>: [ <source directory>, <directory in zip>, <file1>, <file2>, .. ]

build_pk3('baseq3/pak8.pk3', 
	[ [ '#../../../media/Q3Media-1.32/baseq3/menu/art', 'menu/art', 'pblogo.tga' ],
	[ '../Q3/q3_ui/q3_ui', 'vm', 'ui.qvm' ],
	[ '../Q3/cgame/cgame', 'vm', 'cgame.qvm' ],
	[ '../Q3/game/game', 'vm', 'qagame.qvm' ] ]
);

build_pk3('missionpack/pak3.pk3',
	[	[ '#../ui', 'ui', [ 'createserver.menu', 'joinserver.menu', 'filter.menu', 'punkbuster.menu', 'menus.txt' ] ],
	[ '../TA/ui/ui', 'vm', 'ui.qvm' ],
	[ '../TA/cgame/cgame', 'vm', 'cgame.qvm' ],
	[ '../TA/game/game', 'vm', 'qagame.qvm' ],
	[ '#../../../media/Q3Media-1.32/missionpack/scripts', 'scripts', 'models2.shader' ] ]
);