7ba4603ab198e1a814cde2d6629fe2c89d2371e6
[xonotic/xonotic.git] / misc / tools / rebrand-darkplaces-engine.sh
1 #!/bin/sh
2
3 # all these shall be defined in a .brand file passed as first argument
4 flags="-quake"
5 name=DarkPlaces-Quake
6 dirname1=id1
7 dirname2=
8 screenshotname=dp
9 userdirname=darkplaces
10 icon_icns=Darkplaces.app/Contents/Resources/Darkplaces.icns
11 icon_ico=darkplaces.ico
12 icon_xpm=darkplaces.xpm
13
14 . "$1"; shift
15
16 flags="$flags -customgamename \"$name\" -customgamedirname1 \"$dirname1\" -customgamedirname2 \"$dirname2\" -customgamescreenshotname \"$screenshotname\" -customuserdirname \"$userdirname\""
17 echo "$flags" > darkplaces.opt
18
19 for EXECUTABLE in "$@"; do
20         uses_xpm=false
21         uses_ico=false
22         uses_icns=false
23
24         # detect what the executable is
25         case "`file -b "$EXECUTABLE"`" in
26                 *ELF*)
27                         case "$EXECUTABLE" in
28                                 *-dedicated)
29                                         ;;
30                                 *)
31                                         uses_xpm=true
32                                         ;;
33                         esac
34                         ;;
35                 *Mach*)
36                         uses_icns=true
37                         case "$EXECUTABLE" in
38                                 *-sdl)
39                                         uses_xpm=true
40                                         ;;
41                                 *)
42                                         ;;
43                         esac
44                         ;;
45                 *PE*)
46                         uses_ico=true
47                         ;;
48         esac
49
50         # add a selfpack
51         rm -f darkplaces.zip
52         zip -9r darkplaces.zip darkplaces.opt
53
54         if $uses_xpm; then
55                 cp "$icon_xpm" darkplaces-icon.xpm
56                 zip -9r darkplaces.zip darkplaces-icon.xpm
57                 rm -f darkplaces-icon.xpm
58         fi
59
60         if $uses_ico; then
61                 e=$EXECUTABLE \
62                 i=$icon_ico \
63                 n=$name \
64                 perl <<'EOF'
65                 use strict;
66                 use warnings;
67                 use Win32::Exe;
68
69                 my $n = $ENV{n};
70                 my $i = $ENV{i};
71                 my $e = $ENV{e};
72
73                 my $exe = Win32::Exe->new($e)
74                         or die "Win32::Exe->new: $!";
75                 $exe = $exe->create_resource_section()
76                         unless $exe->has_resource_section();
77                 $exe->update(icon => $i);
78                 $exe->update(info => ["InternalName=$e"]);
79                 $exe->update(info => ["OriginalFilename=$e"]);
80                 $exe->update(info => ["ProductName=$n"]);
81                 $exe->write($e)
82                         or die "Win32::Exe->write: $!";
83 EOF
84         fi
85
86         if $uses_icns; then
87                 # OS X is special here
88                 case "$EXECUTABLE" in
89                         */*)
90                                 pkgdir="${EXECUTABLE%/*}/.."
91                                 ;;
92                         *)
93                                 pkgdir=..
94                                 ;;
95                 esac
96                 cp "$icon_icns" "$pkgdir/Resources/Darkplaces.icns"
97                 cat <<EOF >"$pkgdir/Resources/English.lproj/InfoPlist.strings"
98 /* Localized versions of Info.plist keys */
99
100 CFBundleName = "$name";
101 CFBundleShortVersionString = "$name";
102 CFBundleGetInfoString = "Darkplaces by Forest 'LordHavoc' Hale";
103 NSHumanReadableCopyright = "Copyright `date +%Y`";
104 EOF
105         fi
106
107         cat darkplaces.zip >> "$EXECUTABLE"
108         rm -f darkplaces.zip
109 done
110
111 rm -f darkplaces.opt