File: install

package info (click to toggle)
gdis 0.89-2.1
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 7,888 kB
  • ctags: 4,879
  • sloc: ansic: 64,430; makefile: 281; python: 115; perl: 114; sh: 107
file content (170 lines) | stat: -rwxr-xr-x 2,853 bytes parent folder | download | duplicates (2)
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
#! /usr/bin/perl

# --- GDIS install script (redirect errors -> install.log)

open(STDERR, ">install.log");

# pre-checks os / files (eg pkg-config) / libs

$osmakefile = &check_os();

# TODO - print help on where to get if not installed?
&check_program("pkg-config") || die;

print ("Checking pre-requisite packages.\n");

# TODO - print help on where to get if not installed?
&check_library("gtk+-2.0") || die;
&check_library("gtkglext-1.0") || die;

# print current options + any warnings etc
do
  {
  print "Enter Install location: ";
  $_ = <>;
  chomp;
  }
while (&check_install($_));

$dest = $_."/";

# allow editing of make/install options
# TODO - if cant open - attempt to open in current directory
&build_makefile($osmakefile);

# perform make
if (system("make -f makefile.gdis") != 0)
  {
  print "GDIS compile failed - check install.log\n";
  close(STDERR);
  exit;
  }
else
  {
  print "GDIS compile successful.\n";
  }

# perform install / strip 
# copy gdis exec + manual etc etc to install location
# dont install if dest is ./
if (length($dest) > 2)
  {
  print "Installing GDIS in: [$dest]\n";

  system("strip gdis");
  system("cp gdis $dest");
  system("cp gdis.elements $dest");
  system("cp gdis.library $dest");
  system("cp gdis.manual $dest");
  }

print "done.\n";

close(STDERR);
exit;

# --- subroutines

# --- returns the os specific makefile
sub check_os
{
$os = "makefile.linux";

open(OUT, "uname -a |");

while (<OUT>)
  {
  if (/Linux/)
    {
    $os = "makefile.linux";
    }
  if (/Darwin Kernel/)
    {
    $os = "makefile.osx";
    }
  }

close(OUT);

return $os;
}

# -- checks is directory is a valid install location
sub check_install
{
print "$_[0] : ";

stat($_[0]);

if (!-e _)
  {
  print "does not exist.\n";
  return(1);
  }
if (!-d _)
  {
  print "is not a directory.\n";
  return(1);
  }
if (!-w _)
  {
  print "is not writable by you.\n";
  return(1);
  }

print " [ok]\n";

return(0);
}

# -- checks if argument string is a valid executable
sub check_program
{
$ret = system($_[0]);

if ($ret == -1)
  {
  print "Missing program: $_[0]\n";
  return(0);
  }
return(1);
}

# -- primitive for pkg-config checking
sub check_library
{
print "$_[0] 		";
if (system("pkg-config --exists $_[0]"))
  {
  print "[not found]\n";
  return(0);
  }
else
  {
  print "[ok]\n";
  }
return(1);
}

# CURRENT - create a minimal makefile
# NB: can effect a make clean etc etc through perl script
sub build_makefile
{
open(OUT, ">makefile.gdis") || die;

print OUT "# --- auto generated GDIS makefile\n\n";

# TODO - pass OS as argument
print OUT "include $_[0]\n";
print OUT "include makefile.src\n\n";

print OUT "OBJ = \$(SRC:.c=.o)\n\n";

print OUT "gdis: \$(OBJ)\n";
print OUT "\t\$(CC) \$(OBJ) \$(LDFLAGS) -o gdis \$(LIBS)\n";

print OUT ".c.o:\n";
print OUT "\t\$(CC) \$(CFLAGS) -c \$< \$(INCS)\n";

close(OUT);
}