File: find_compilers_linux.dpr

package info (click to toggle)
lazarus 2.0.0%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 214,460 kB
  • sloc: pascal: 1,862,622; xml: 265,709; cpp: 56,595; sh: 3,008; java: 609; makefile: 535; perl: 297; sql: 222; ansic: 137
file content (489 lines) | stat: -rw-r--r-- 8,119 bytes parent folder | download | duplicates (7)
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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
{target:linux}
{linux_console_app}
//
// AggPas 2.4 RM3 Helper utility application
// Milan Marusinec alias Milano (c) 2006 - 2008
//
program
 find_compilers_linux ;

uses
 SysUtils ,
 agg_basics ,
 file_utils_ ,
 libc ;

{$I agg_mode.inc }
{$- }
type
 src_key = record
   key ,
   val : string[99 ];

  end;

const
 key_max  = 99; 
 pool_max = 65536;
 make_max = 99;

 fpc_comp = 'ppc386';
 fpc_libs = '-Fu"src;src/ctrl;src/platform/linux;src/util;src/svg;expat-wrap"';
 fpc_incl = '-Fisrc';
 fpc_outd = '-FU_debug';
 fpc_conf = '-Mdelphi -Tlinux -Sg -Se3 -XX -Xs -B -v0i';
 fpc_gapp = '-WG';
 fpc_capp = '-WC';

var
 key_array : array[0..key_max - 1 ] of src_key;
 key_count ,
 key_lastx : unsigned;
 key_scanx : shortstring;

 pool_buff : pointer;
 pool_aloc ,
 pool_size : unsigned;

 make_array : array[0..make_max - 1 ] of string[99 ];
 make_count : unsigned;

{ WRPOOL }
procedure WrPool(str : shortstring; crlf : boolean = false );
begin
 if crlf then
  str:=str + #10;

 if pool_size + length(str ) < pool_aloc then
  begin
   System.move(
    str[1 ] ,
    pointer(ptrcomp(pool_buff ) + pool_size )^ ,
    length(str ) );

   inc(pool_size ,length(str ) );	

  end;

end;

{ WRFILE }
function WrFile(fname : shortstring ) : boolean;
var
 df : file;
 wr : int;

begin
 result:=false;

 AssignFile(df ,fname );
 rewrite   (df ,1 );

 if IOResult = 0 then
  begin
   blockwrite(df ,pool_buff^ ,pool_size ,wr );
   close     (df );

   fname:=fname + #0;

   libc.chmod(
    PChar(@fname[1 ] ) ,
    S_IRWXU or S_IRWXG or S_IROTH or S_IWOTH );

   if pool_size = wr then
    result:=true;

  end;

end;

{ NEXTKEY }
function NextKey(var val : shortstring ) : boolean;
begin
 result:=false;

 while key_lastx < key_count do
  begin
   inc(key_lastx );

   if cmp_str(key_array[key_lastx - 1 ].key ) = key_scanx then
    begin
     val   :=key_array[key_lastx - 1 ].val;
     result:=true;

     break;

    end;

  end;

end;

{ FIRSTKEY } 
function FirstKey(key : shortstring; var val : shortstring ) : boolean;
begin
 key_lastx:=0;
 key_scanx:=cmp_str(key );

 result:=NextKey(val );

end;

{ LOADKEYS }
procedure LoadKeys(buff : char_ptr; size : int );
type
 e_scan = (expect_lp ,load_key ,load_val ,next_ln ,expect_crlf );

var 
 scan : e_scan;
 key  ,
 val  : shortstring;

procedure add_key;
begin
 if key_count < key_max then
  begin
   key_array[key_count ].key:=key;
   key_array[key_count ].val:=val;

   inc(key_count );

  end;

 key:='';
 val:='';

end; 

begin
 key_count:=0;

 scan:=expect_lp;
 key :='';
 val :='';

 while size > 0 do
  begin
   case scan of
    expect_lp :
     case buff^ of
      '{' :
       scan:=load_key;

      else
       break;

     end;

    load_key :
     case buff^ of
      #13 ,#10 :
       break;

      ':' :
       scan:=load_val;

      '}' :
       begin
        add_key;

        scan:=next_ln;

       end;

      else
       key:=key + buff^; 

     end;

    load_val :
     case buff^ of
      #13 ,#10 :
       break;

      '}' :
       begin
        add_key;

        scan:=next_ln;

       end;

      else
       val:=val + buff^; 

     end;

    next_ln :
     case buff^ of
      #13 ,#10 :
       scan:=expect_crlf;

      ' ' :
      else
       break;

     end;

    expect_crlf :
     case buff^ of
      '{' :
       scan:=load_key;

      #13 ,#10 :
      else
       break;

      end;

   end;

   dec(size );
   inc(ptrcomp(buff ) );

  end;

end;

{ WRITECOMPILESCRIPT }
function WriteCompileScript(name ,ext : shortstring ) : boolean;
var
 cp : shortstring;

begin
 result:=false;

// Create the script in memory
 pool_size:=0;

 WrPool(fpc_comp + ' ' );
 WrPool(fpc_libs + ' ' );
 WrPool(fpc_incl + ' ' );
 WrPool(fpc_outd + ' ' );
 WrPool(fpc_conf + ' ' );

 if FirstKey('linux_console_app' ,cp ) then
  WrPool(fpc_capp + ' ' )
 else
  WrPool(fpc_gapp + ' ' );

 WrPool(name + ext ,true );


// WriteFile
 name:='compile-' + name;

 if WrFile(name ) then
  begin
   if make_count < make_max then
    begin
     make_array[make_count ]:=name;	

     inc(make_count );

    end; 

   result:=true; 

  end; 

end;

{ CREATECOMPILESCRIPT }
procedure CreateCompileScript(name ,ext : shortstring );
var
 loaded : boolean;

 target ,value : shortstring;

 lf : file;
 fs ,
 ls : int;
 bf : pointer;

begin
 write(' ' ,name ,ext ,' ... ' );

// Open Source .DPR file
 AssignFile(lf ,name + ext );
 reset     (lf ,1 );

 if IOResult = 0 then
  begin
   loaded:=false;

  // Load DPR keys
   fs:=filesize(lf );

   if (fs > 0 ) and
      agg_getmem(bf ,fs ) then
    begin
     blockread(lf ,bf^ ,fs ,ls );

     if fs = ls then
      begin
       loaded:=true;

       LoadKeys(bf ,fs );

      end;

     agg_freemem(bf ,fs );

    end;

  // Close DPR
   close(lf );

  // Create compilation script
   if loaded then
    begin
     if FirstKey('skip' ,value ) then
      writeln('to be not included -> skipped' )
     else
      begin
       target:='linux';

       FirstKey('target' ,target );

       if cmp_str(target ) = cmp_str('linux' ) then
        if WriteCompileScript(name ,ext ) then
         writeln('OK' )
        else
         writeln('Failed to generate compile script !' )
       else
        writeln('different target (' ,target ,') -> skipped' );

      end;

    end
   else
    writeln('Failed to read the source file !' );

  end
 else
  writeln('Failed to open !' ); 

end;

{ PROCESSOBJECT }
procedure ProcessObject(found : shortstring );
var
 file_path ,file_name ,file_ext : shortstring;

begin
 spread_name(found ,file_path ,file_name ,file_ext );

 if cmp_str(file_ext ) = cmp_str('.dpr' ) then
  CreateCompileScript(file_name ,file_ext );

end;

{ ITERATEFOLDER }
procedure IterateFolder(inFolder : shortstring );
var
 dp : libc.PDIR;
 ep : libc.Pdirent;

begin
 inFolder:=inFolder + #0;

 dp:=libc.opendir(PChar(@inFolder[1 ] ) );

 if dp <> NIL then
  begin
   repeat
    ep:=libc.readdir(dp );

    if ep <> NIL then
     ProcessObject(strpas(ep.d_name ) );

   until ep = NIL;

   libc.closedir(dp );

  end;

end;

{ CREATEMAKEFILE }
procedure CreateMakeFile;
var
 i : unsigned;

begin
 pool_size:=0;

 i:=0;

 while i < make_count do
  begin
   WrPool('./' + make_array[i ] ,true ); 

   inc(i );

  end;

 WrFile('compile_make_all' ); 

end;

{ SCANDEMOS }
procedure ScanDemos;
begin
 IterateFolder('./' );
 writeln;

 if make_count > 0 then
  begin
   CreateMakeFile;

   writeln('SUCCESS: FPC compilation script files were created' );
   writeln('         for the AggPas demos listed above.' );
   writeln;
   writeln('         To compile the demos, run Terminal, change to the current' );
   writeln('         directory and type "./compile_make_all"' );
   writeln('         or "./compile-xxx", where "xxx" is the name of the demo.' );

  end
 else
  writeln('MESSAGE: No AggPas demo files were found in current folder !' );

 writeln;

end;

BEGIN
 writeln;
 writeln('*************************************************************' );
 writeln('* Welcome to the AggPas 2.4 RM3 vector graphics library.    *' );
 writeln('*************************************************************' ); 
 writeln('*                                                           *' );
 writeln('* This helper utility will generate the compilation script  *' );
 writeln('* files with current paths and options needed to compile    *' );
 writeln('* properly all the AggPas demos on your Linux station.      *' );
 writeln('*                                                           *' );
 writeln('* Currently the Free Pascal compiler is supported.          *' );
 writeln('* (www.freepascal.org)                                      *' ); 
 writeln('*                                                           *' );
 writeln('*************************************************************' );
 writeln;
 writeln('[Press ENTER key to continue ...]' );
 writeln; 
 readln;

 if agg_getmem(pool_buff ,pool_max ) then
  begin
   pool_aloc :=pool_max;
   pool_size :=0;
   make_count:=0;

   ScanDemos;

   agg_freemem(pool_buff ,pool_aloc );

  end
 else
  writeln('ERROR: Not enough memory for the pool buffer !' ); 

END.