2 * This file is part of duit.
4 * duit is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation; either version 2.1 of the License, or
7 * (at your option) any later version.
9 * duit is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with duit; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 private import ui
.Main
;
22 private import ui
.Exec
;
23 private import gtk
.Duit
;
24 private import gtk
.MainWindow
;
25 private import gtk
.Widget
;
26 private import gtk
.ProgressBar
;
27 private import gtk
.Label
;
28 private import gtk
.VBox
;
30 private import gdk
.Gdk
;
31 private import gdk
.Event
;
33 private import compd
.Compiler
;
35 private import std
.stdio
;
37 private import std
.path
;
38 private import std
.file
;
39 private import std
.process
;
41 private import std
.thread
;
42 private import std
.c
.time
;
46 * From the informatino collected from the UI this will install Duit, Duitgl and or leds
48 class Installer
: MainWindow
50 InstallerUI installerUI
;
52 ProgressBar progressBar
;
56 this(InstallerUI installerUI
)
58 super("Installing Duit components");
59 this.installerUI
= installerUI
;
60 setDefaultSize(400,300);
64 progressBar
.setFraction(1.0);
65 progressBar
.setText("");
70 VBox vbox
= new VBox(false, 7);
71 vbox
.setBorderWidth(11);
72 label
= new Label("");
73 vbox
.packStart(new Label("Installing"), false, false, 14);
74 vbox
.packStart(label
, false, false, 14);
75 progressBar
= new ProgressBar();
76 progressBar
.setPulseStep(0.01);
77 vbox
.packStart(progressBar
, false, false, 14);
81 protected int windowDelete(Event event
, Widget widget
)
85 return super.windowDelete(event
, widget
);
96 private void install()
99 duitDevHome
= installerUI
.getDirectory("duitDevHome");
100 dmdHome
= installerUI
.getDirectory("dmdHome");
101 phobos
= std
.path
.join(std
.path
.join(dmdHome
,"src"),"phobos");
102 compilerExec
= std
.path
.join(installerUI
.getDirectory("dmdHome"),"bin");
105 compilerExec
= std
.path
.join(compilerExec
,"dmd.exe");
109 compilerExec
= std
.path
.join(compilerExec
,"dmd");
112 // if ( ok && installerUI.getSelection("duit") )
114 // label.setText("");
116 // ok = installDuit();
121 class CompileThread
: Thread
123 bool delegate() compile
;
126 this(char[] stepLabel
, bool delegate() compile
)
129 this.compile
= compile
;
130 label
.setText(stepLabel
);
131 progressBar
.setText(stepLabel
);
138 std
.gc
.fullCollect();
140 while ( !cancel
&& getState() != Thread
.TS
.TERMINATED
)
143 while ( Duit
.eventsPending() )
145 Duit
.mainIterationDo(false);
147 std
.c
.time
.usleep(30000);
159 if ( !cancel
&& ok
&& installerUI
.getSelection("duitDev") )
161 ok
= (new CompileThread("Duit Development", &installDuitDev
)).ok
;
164 // if ( ok && installerUI.getSelection("duitgl") )
166 // label.setText("Duitgl - openGL bindings");
168 // ok = installDuitgl();
171 if ( !cancel
&& ok
&& installerUI
.getSelection("duiglDev") )
173 ok
= (new CompileThread("Duitgl Development", &installDuitglDev
)).ok
;
176 // if ( !cancel && ok && installerUI.getSelection("leds") )
178 // label.setText("leds");
180 // ok = installLeds();
183 // if ( !cancel && ok && installerUI.getSelection("duitdi") )
185 // label.setText("Duit .di files");
187 // ok = installDuitdi();
190 // if ( !cancel && ok && installerUI.getSelection("duitSource") )
192 // label.setText("Duit source files");
194 // ok = installDuitSource();
197 if ( !cancel
&& ok
&& installerUI
.getSelection("duitTests") )
199 ok
= (new CompileThread("Duit Test and demos programs", &installDuitTests
)).ok
;
202 if ( !cancel
&& ok
&& installerUI
.getSelection("duitglSimple") )
204 ok
= (new CompileThread("Duitgl SimpleGL demo program", &installDuitglSimpleGL
)).ok
;
207 if ( !cancel
&& ok
&& installerUI
.getSelection("duitglShapes") )
209 ok
= (new CompileThread("Duitgl ShapeGL and demo program", &installDuitglShapesGL
)).ok
;
212 // if ( !cancel && ok && installerUI.getSelection("ledsDuit") )
214 // label.setText("Leds project for Duit");
216 // ok = installLedsDuit();
219 // if ( !cancel && ok && installerUI.getSelection("ledsLeds") )
221 // label.setText("Leds project for leds");
223 // ok = installLedsLeds();
226 // if ( !cancel && ok && installerUI.getSelection("ledsDool") )
228 // label.setText("Leds project for Dool");
230 // ok = installLedsDool();
233 // if ( !cancel && ok && installerUI.getSelection("ledsDante") )
235 // label.setText("Leds project for Dante");
237 // ok = installLedsDante();
240 // if ( !cancel && ok && installerUI.getSelection("ledsPhobos") )
242 // label.setText("Leds project for phobos");
244 // ok = installLedsPhobos();
250 private bool makeDirs(char[] dir
)
259 system("mkdir -p "~dir
);
266 catch ( FileException fe
)
273 private bool installDuitglSimpleGL()
275 bool ok
= moveDuitDev();
278 char[] cwd = std
.file
.getcwd();
280 std
.file
.chdir(duitDevHome
);
282 compiler
= new Compiler();
283 compiler
.setExecutor(new Exec());
284 compiler
.setCompilerExec(compilerExec
);
286 compiler
.addArg("-Isrc");
287 compiler
.addArg("-Isrcgl");
288 compiler
.addArg("-Idemos");
289 compiler
.addArg("demos/gl/SimpleGL.d");
290 compiler
.addArg("-I"~phobos
);
291 compiler
.addArg("-L"~std
.path
.join(dmdHome
,"lib"));
292 compiler
.addArg("-o SimpleGL");
293 compiler
.addArg("-L .");
294 compiler
.addArg("-lduit");
295 compiler
.addArg("-lduitgl");
296 compiler
.addArg("-lGL");
297 compiler
.addArg("-lGLU");
298 version(linux
)compiler
.addArg("-ldl");
300 compiler
.addArg("-c");
301 compiler
.addArg("-op");
305 compiler
.addArg("-lkernel32");
306 compiler
.addArg("-luser32");
310 compiler
.addArg("-lpthread");
311 compiler
.addArg("-lm");
314 if ( compiler
.compileStatus
== 0
315 && compiler
.linkStatus
== 0
330 private bool installDuitglShapesGL()
332 bool ok
= moveDuitDev();
335 char[] cwd = std
.file
.getcwd();
337 std
.file
.chdir(duitDevHome
);
339 compiler
= new Compiler();
340 compiler
.setExecutor(new Exec());
341 compiler
.setCompilerExec(compilerExec
);
343 compiler
.addArg("-Isrc");
344 compiler
.addArg("-Isrcgl");
345 compiler
.addArg("demos/gl/TrackBall.d");
346 compiler
.addArg("demos/gl/ShapesGL.d");
347 compiler
.addArg("-I"~phobos
);
348 compiler
.addArg("-L"~std
.path
.join(dmdHome
,"lib"));
349 compiler
.addArg("-o ShapesGL");
350 compiler
.addArg("-L .");
351 compiler
.addArg("-lduit");
352 compiler
.addArg("-lduitgl");
353 compiler
.addArg("-lGL");
354 compiler
.addArg("-lGLU");
355 version(linux
)compiler
.addArg("-ldl");
357 compiler
.addArg("-c");
358 compiler
.addArg("-op");
362 compiler
.addArg("-lkernel32");
363 compiler
.addArg("-luser32");
367 compiler
.addArg("-lpthread");
368 compiler
.addArg("-lm");
371 if ( compiler
.compileStatus
== 0
372 && compiler
.linkStatus
== 0
387 private bool installDuitglDev()
393 char[] cwd = std
.file
.getcwd();
399 char[] libDuitgl
= "duitgl";
403 char[] libDuitgl
= "libduitgl";
411 std
.file
.chdir(duitDevHome
);
412 compiler
= new Compiler();
413 compiler
.setExecutor(new Exec());
414 compiler
.setCompilerExec(compilerExec
);
416 compiler
.addArg("-Isrc");
417 compiler
.addArg("-Isrcgl");
418 compiler
.addArg("srcgl/glgdk");
419 compiler
.addArg("srcgl/glgtk");
420 compiler
.addArg("srcgl/lib");
421 compiler
.addArg("-I"~phobos
);
422 compiler
.addArg("-L"~std
.path
.join(dmdHome
,"lib"));
423 compiler
.addArg("-olib "~libDuitgl
);
424 compiler
.addArg("-L. ");
425 compiler
.addArg("-lduit ");
426 compiler
.addArg("-c");
427 compiler
.addArg("-op");
431 compiler
.addArg("-lkernel32");
432 compiler
.addArg("-luser32");
436 compiler
.addArg("-lpthread");
437 compiler
.addArg("-lm");
440 if ( compiler
.compileStatus
== 0
441 && compiler
.linkStatus
== 0
457 private bool installDuitTests()
459 bool ok
= moveDuitDev();
462 char[] cwd = std
.file
.getcwd();
464 std
.file
.chdir(duitDevHome
);
466 compiler
= new Compiler();
467 compiler
.setExecutor(new Exec());
468 compiler
.setCompilerExec(compilerExec
);
470 compiler
.addArg("-Isrc");
471 compiler
.addArg("-Idemos");
472 compiler
.addArg("demos/duit");
473 compiler
.addArg("-I"~phobos
);
474 compiler
.addArg("-L"~std
.path
.join(dmdHome
,"lib"));
475 compiler
.addArg("-o DuitTests");
476 compiler
.addArg("-L .");
477 compiler
.addArg("-lduit");
478 version(linux
)compiler
.addArg("-ldl");
480 compiler
.addArg("-c");
481 compiler
.addArg("-op");
485 compiler
.addArg("-lkernel32");
486 compiler
.addArg("-luser32");
490 compiler
.addArg("-lpthread");
491 compiler
.addArg("-lm");
494 if ( compiler
.compileStatus
== 0
495 && compiler
.linkStatus
== 0
510 private bool movePackToDestiny(char[] from
, char[] to
)
515 ok
= system("xcopy /s /Y /E /Q "~from
~" "~to
);
519 ok
= system("cp -R "~from
~" "~to
);
526 private bool moveDuitDev()
530 if ( makeDirs(duitDevHome
) )
532 duitDevMoved
= movePackToDestiny("*", duitDevHome
);
538 // private bool installDuit()
544 private bool installDuitDev()
550 char[] cwd = std
.file
.getcwd();
556 char[] libDuit
= "duit";
560 char[] libDuit
= "libduit";
567 std
.file
.chdir(duitDevHome
);
568 compiler
= new Compiler();
569 compiler
.setExecutor(new Exec());
571 compiler
.setCompilerExec(compilerExec
);
573 compiler
.addArg("-Isrc");
574 compiler
.addArg("src/atk");
575 compiler
.addArg("src/cairoLib");
576 compiler
.addArg("src/gdk");
577 compiler
.addArg("src/glib");
578 compiler
.addArg("src/gobject");
579 compiler
.addArg("src/gthread");
580 compiler
.addArg("src/gtk");
581 compiler
.addArg("src/lib");
582 compiler
.addArg("src/pango");
583 compiler
.addArg("-I"~phobos
);
584 compiler
.addArg("-L"~std
.path
.join(dmdHome
,"lib"));
585 compiler
.addArg("-olib "~libDuit
);
586 compiler
.addArg("-c");
587 compiler
.addArg("-op");
591 compiler
.addArg("-lkernel32");
592 compiler
.addArg("-luser32");
596 compiler
.addArg("-lpthread");
597 compiler
.addArg("-lm");
600 if ( compiler
.compileStatus
== 0
601 && compiler
.linkStatus
== 0