~ubuntu-branches/ubuntu/vivid/oss4/vivid-proposed

« back to all changes in this revision

Viewing changes to .pc/103_kfreebsd-gnu.patch/setup/srcconf.c

  • Committer: Package Import Robot
  • Author(s): Sebastien NOEL
  • Date: 2012-11-19 11:47:24 UTC
  • mfrom: (1.1.6)
  • Revision ID: package-import@ubuntu.com-20121119114724-svu8mq7x3pk64nez
Tags: 4.2-build2007-1
* New upstream release.
* Acknowledge NMU, thanks Michael Gilbert.
* Add debian/patches/110_ld-as-needed.patch: Rearrange order of linker
  arguments to fix building with "ld --as-needed" (closes: #630737).
* Add missing dependency on dpkg-dev to oss4-dkms and oss4-source
  (closes: #687086).
* Fix typo in the changelog (closes: #628876, #675933)
* Add debian/patches/002_fix-linux-oss_native_word.patch (closes: #693657).
  Thanks to Ben Hutchings.
* Add debian/patches/003_linux-error-logging-fixes.patch (closes: #693657).
  Thanks to Ben Hutchings.
* check for /lib/modules/${kernelver}/build in addition of
  /lib/modules/${kernelver}/source (closes: #587191).
* oss4-dkms.dkms.in: fix 'CLEAN' rules (closes: #653374).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *
 
3
 * This file is part of Open Sound System.
 
4
 *
 
5
 * Copyright (C) 4Front Technologies 1996-2008.
 
6
 *
 
7
 * This this source file is released under GPL v2 license (no other versions).
 
8
 * See the COPYING file included in the main directory of this source
 
9
 * distribution for the license terms and conditions.
 
10
 *
 
11
 */
 
12
 
 
13
#include <stdio.h>
 
14
#include <stdlib.h>
 
15
#include <unistd.h>
 
16
#include <string.h>
 
17
#include <sys/types.h>
 
18
#include <dirent.h>
 
19
#include <sys/stat.h>
 
20
#include <sys/utsname.h>
 
21
#include <errno.h>
 
22
 
 
23
#define MAX_SUBDIRS     64
 
24
#define MAX_OBJECTS     64
 
25
#define MAX_INCLUDES    32
 
26
#define MAXOPTS         64
 
27
 
 
28
static char *vmix_mode="FIXEDPOINT";
 
29
static char *config_midi="ENABLED"; // Actually this depends on the configure script
 
30
 
 
31
static int exact_architectures=0; /* 1=Compile only drivers that have matching arch given in their .config file. */
 
32
 
 
33
static int config_phpmake=0;
 
34
 
 
35
typedef struct
 
36
{
 
37
  char project_name[64];
 
38
  char os_name[64];
 
39
  int mode;
 
40
#define MD_UNDEF        0
 
41
#define MD_USERLAND     1
 
42
#define MD_SBIN         2
 
43
#define MD_KERNEL       3
 
44
#define MD_KERNEL_      4
 
45
#define MD_MODULE_      5
 
46
#define MD_MODULE       6
 
47
#define MD_SHLIB        7
 
48
  char cflags[256];
 
49
  char ldflags[256];
 
50
  char OSflags[256];
 
51
  int license;
 
52
#define LIC_FREE        0
 
53
#define LIC_RESTRICTED  1
 
54
  char bus[16];
 
55
  char endianess[16];
 
56
  char ccomp[256];
 
57
  char cplusplus[256];
 
58
  char system[32], arch[32], platform[32];
 
59
 
 
60
  unsigned int flags;
 
61
#define F_USEARCH               0x00000001
 
62
 
 
63
 
 
64
  int check_os, os_ok, os_bad;
 
65
  int check_cpu, cpu_ok, cpu_bad;
 
66
  int check_endian, endian_ok;
 
67
  int check_platform, platform_ok;
 
68
 
 
69
  int power_manage;     /* Supports device power management (under Solaris) */
 
70
  int suspend_resume;   /* Supports suspend/resume (under Solaris) */
 
71
 
 
72
  char *purpose;
 
73
} conf_t;
 
74
 
 
75
#define DEFAULT_CC "cc"
 
76
 
 
77
static conf_t conf = {
 
78
  "Open Sound System",
 
79
  "Solaris",
 
80
  MD_USERLAND,
 
81
  "",                           /* cflags */
 
82
  "",                           /* ldflags */
 
83
  "",                           /* OSflags */
 
84
  LIC_FREE,
 
85
  "PCI",                        /* bus */
 
86
  "LITTLE",                     /* Endianess */
 
87
  DEFAULT_CC,                   /* c compiler */
 
88
  "c++"                         /* cplusplus */
 
89
};
 
90
 
 
91
static char this_os[64] = "kernel/OS/SunOS";
 
92
static int kernelonly = 0;
 
93
static int useronly = 0;
 
94
static int do_warning_checks=1;
 
95
 
 
96
static char *shlib_cflags = "-shared -fPIC";
 
97
static char *shlib_ldflags = "-shared -fPIC";
 
98
 
 
99
static char *extra_libraries = "";
 
100
 
 
101
char *hostcc;
 
102
char *targetcc;
 
103
 
 
104
static int nincludes = 0;
 
105
static char *includes[MAX_INCLUDES];
 
106
static int do_cleanup = 0;
 
107
 
 
108
static char arch[32] = "";
 
109
 
 
110
static void
 
111
generate_driver (char *name, conf_t * conf, char *cfg_name, char *cfg_header,
 
112
                 char *dirname, char *topdir);
 
113
 
 
114
typedef void
 
115
(*generate_driver_t) (char *name, conf_t * conf, char *cfg_name, char *cfg_header,
 
116
                 char *dirname, char *topdir);
 
117
 
 
118
generate_driver_t driver_gen = generate_driver;
 
119
 
 
120
#ifdef linux
 
121
#include "srcconf_vxworks.inc"
 
122
#include "srcconf_linux.inc"
 
123
#endif
 
124
 
 
125
#ifdef __FreeBSD__
 
126
#include "srcconf_freebsd.inc"
 
127
#endif
 
128
 
 
129
#ifdef sun
 
130
#include "srcconf_vxworks.inc"
 
131
#include "srcconf_solaris.inc"
 
132
#endif
 
133
 
 
134
#if defined(__BEOS__) || defined(__HAIKU__)
 
135
#include "srcconf_beos.inc"
 
136
#endif
 
137
 
 
138
static int
 
139
parse_config (FILE * f, conf_t * conf, char *comment)
 
140
{
 
141
  char line[256], *p, *parms;
 
142
 
 
143
  while (fgets (line, sizeof (line) - 1, f) != NULL)
 
144
    {
 
145
      p = line + strlen (line) - 1;
 
146
      if (*p == '\n')
 
147
        *p = 0;
 
148
 
 
149
      if (*line == '#')         /* Comment line */
 
150
        continue;
 
151
 
 
152
      parms = p = line;
 
153
      while (*parms && *parms != '=')
 
154
        parms++;
 
155
 
 
156
      if (*parms == '=')
 
157
        *parms++ = 0;
 
158
 
 
159
#if defined(__BEOS__) || defined(__HAIKU__)
 
160
      if (strcmp (parms, "-lm") == 0)
 
161
        {
 
162
          parms = "";
 
163
        }
 
164
#endif
 
165
 
 
166
      if (strcmp (parms, "$GTKCFLAGS") == 0)
 
167
        {
 
168
          parms = "";
 
169
          if (getenv ("GTK1") != NULL)
 
170
            parms = "`gtk-config --cflags` -DGTK1_ONLY";
 
171
          else
 
172
          if (getenv ("GTK2") != NULL)
 
173
            parms = "`pkg-config gtk+-2.0 --cflags`";
 
174
        }
 
175
 
 
176
      if (strcmp (parms, "$GTKLDFLAGS") == 0)
 
177
        {
 
178
          parms = "";
 
179
          if (getenv ("GTK1") != NULL)
 
180
            parms = "`gtk-config --libs`";
 
181
          else
 
182
          if (getenv ("GTK2") != NULL)
 
183
            parms = "`pkg-config gtk+-2.0 --libs`";
 
184
        }
 
185
 
 
186
      if (strcmp (parms, "$DLOPENLDFLAGS") == 0)
 
187
        {
 
188
          parms = "";
 
189
#ifndef __FreeBSD__
 
190
          if (getenv ("OGG_SUPPORT") != NULL)
 
191
            parms = "-ldl";
 
192
#endif
 
193
        }
 
194
 
 
195
      if (strcmp (parms, "$OGGDEFINE") == 0)
 
196
        {
 
197
          parms = "";
 
198
          if (getenv ("OGG_SUPPORT") != NULL)
 
199
            parms = "-DOGG_SUPPORT";
 
200
        }
 
201
 
 
202
      if (strcmp (line, "project") == 0)
 
203
        {
 
204
          strcpy (conf->project_name, parms);
 
205
          continue;
 
206
        }
 
207
 
 
208
      if (strcmp (line, "cflags") == 0)
 
209
        {
 
210
          strcpy (conf->cflags, parms);
 
211
          continue;
 
212
        }
 
213
 
 
214
      if (strcmp (line, "ldflags") == 0)
 
215
        {
 
216
          strcpy (conf->ldflags, parms);
 
217
          continue;
 
218
        }
 
219
 
 
220
      if (strcmp (line, "osflags") == 0)
 
221
        {
 
222
          if (*conf->OSflags)
 
223
            strcat (conf->OSflags, " ");
 
224
          strcat (conf->OSflags, parms);
 
225
          continue;
 
226
        }
 
227
 
 
228
      if (strcmp (line, "bus") == 0)
 
229
        {
 
230
          strcpy (conf->bus, parms);
 
231
          continue;
 
232
        }
 
233
 
 
234
      if (strcmp (line, "OS") == 0)
 
235
        {
 
236
          strcpy (conf->os_name, parms);
 
237
          continue;
 
238
        }
 
239
 
 
240
      if (strcmp (line, "mode") == 0)
 
241
        {
 
242
          if (strcmp (parms, "user") == 0)
 
243
            {
 
244
              conf->mode = MD_USERLAND;
 
245
              continue;
 
246
            }
 
247
 
 
248
          if (strcmp (parms, "sbin") == 0)
 
249
            {
 
250
              conf->mode = MD_SBIN;
 
251
              continue;
 
252
            }
 
253
 
 
254
          if (strcmp (parms, "shlib") == 0)
 
255
            {
 
256
              conf->mode = MD_SHLIB;
 
257
              continue;
 
258
            }
 
259
 
 
260
          if (strcmp (parms, "kernel") == 0)
 
261
            {
 
262
              conf->mode = MD_KERNEL;
 
263
              continue;
 
264
            }
 
265
 
 
266
          if (strcmp (parms, "undefined") == 0)
 
267
            {
 
268
              conf->mode = MD_UNDEF;
 
269
              continue;
 
270
            }
 
271
 
 
272
          if (strcmp (parms, "kernelmode") == 0)
 
273
            {
 
274
              conf->mode = MD_KERNEL_;
 
275
              continue;
 
276
            }
 
277
 
 
278
          if (strcmp (parms, "module") == 0)
 
279
            {
 
280
              conf->mode = MD_MODULE_;
 
281
              continue;
 
282
            }
 
283
 
 
284
          fprintf (stderr, "Bad mode %s\n", parms);
 
285
          exit (-1);
 
286
        }
 
287
 
 
288
      if (strcmp (line, "license") == 0)
 
289
        {
 
290
          if (strcmp (parms, "free") == 0)
 
291
            conf->license = LIC_FREE;
 
292
          if (strcmp (parms, "restricted") == 0)
 
293
            conf->license = LIC_RESTRICTED;
 
294
          continue;
 
295
        }
 
296
 
 
297
      if (strcmp (line, "depends") == 0)
 
298
        {
 
299
          char tmp[64];
 
300
          sprintf (tmp, "HAVE_%s", parms);
 
301
          if (getenv (tmp) == NULL)
 
302
            {
 
303
              printf
 
304
                ("Directory depends on the %s package which is not available\n",
 
305
                 parms);
 
306
 
 
307
              return 0;
 
308
            }
 
309
          continue;
 
310
        }
 
311
 
 
312
      if (strcmp (line, "configcheck") == 0)
 
313
        {
 
314
          if (strcmp (parms, "VMIX") == 0)
 
315
            {
 
316
              if (strcmp(vmix_mode, "DISABLED")==0)
 
317
                 {
 
318
                      printf
 
319
                        ("Directory depends on the VMIX subsystem which is not enabled\n");
 
320
        
 
321
                      return 0;
 
322
                 }
 
323
              continue;
 
324
            }
 
325
 
 
326
          if (strcmp (parms, "MIDI") == 0) // Skip if MIDI is disabled 
 
327
            {
 
328
              if (strcmp(config_midi, "DISABLED")==0)
 
329
                 {
 
330
                      printf
 
331
                        ("Directory depends on the MIDI subsystem which is not enabled\n");
 
332
        
 
333
                      return 0;
 
334
                 }
 
335
              continue;
 
336
            }
 
337
 
 
338
          if (strcmp (parms, "NO_MIDI") == 0) // Skip if MIDI is enabled
 
339
            {
 
340
              if (strcmp(config_midi, "DISABLED")!=0)
 
341
                 {
 
342
                        // printf ("Directory not compatible with MIDI subsystem (which is enabled)\n");
 
343
        
 
344
                      return 0;
 
345
                 }
 
346
              continue;
 
347
            }
 
348
 
 
349
          fprintf (stderr, "Unknown configcheck parameter '%s'\n", parms);
 
350
          exit(-1);
 
351
        }
 
352
 
 
353
      if (strcmp (line, "targetos") == 0)
 
354
        {
 
355
          conf->check_os = 1;
 
356
          if (strcmp (conf->system, parms) == 0)
 
357
            conf->os_ok = 1;
 
358
          continue;
 
359
        }
 
360
 
 
361
      if (strcmp (line, "forgetos") == 0)
 
362
        {
 
363
          if (strcmp (conf->system, parms) == 0)
 
364
            conf->os_bad = 1;
 
365
          continue;
 
366
        }
 
367
 
 
368
      if (strcmp (line, "targetcpu") == 0)
 
369
        {
 
370
          conf->check_cpu = 1;
 
371
          if (strcmp (parms, "any") == 0)
 
372
             conf->cpu_ok = 1;
 
373
          else
 
374
             if (strcmp (conf->arch, parms) == 0)
 
375
                conf->cpu_ok = 1;
 
376
          continue;
 
377
        }
 
378
 
 
379
      if (strcmp (line, "forgetcpu") == 0)
 
380
        {
 
381
          if (strcmp (conf->arch, parms) == 0)
 
382
            conf->cpu_bad = 1;
 
383
          continue;
 
384
        }
 
385
 
 
386
      if (strcmp (line, "endian") == 0)
 
387
        {
 
388
          conf->check_endian = 1;
 
389
          if (strcmp (conf->endianess, parms) == 0)
 
390
            conf->endian_ok = 1;
 
391
          continue;
 
392
        }
 
393
 
 
394
      if (strcmp (line, "platform") == 0)
 
395
        {
 
396
          conf->check_platform = 1;
 
397
          if (strcmp (conf->platform, parms) == 0)
 
398
            conf->platform_ok = 1;
 
399
          continue;
 
400
        }
 
401
 
 
402
      if (strcmp (line, "pm_support") == 0)
 
403
        {
 
404
            conf->power_manage=1;
 
405
        }
 
406
 
 
407
      if (strcmp (line, "suspend_resume") == 0)
 
408
        {
 
409
            conf->suspend_resume=1;
 
410
        }
 
411
 
 
412
      if (strcmp (line, "force_endian") == 0)
 
413
         {
 
414
              if (strcmp (parms, "BIG") == 0)
 
415
                 {
 
416
                    strcpy (conf->endianess, "BIG");
 
417
                 }
 
418
              else
 
419
              if (strcmp (parms, "LITTLE") == 0)
 
420
                 {
 
421
                    strcpy (conf->endianess, "LITTLE");
 
422
                 }
 
423
              else
 
424
              if (strcmp (parms, "UNKNOWN") == 0)
 
425
                 {
 
426
                    strcpy (conf->endianess, "UNKNOWN");
 
427
                 }
 
428
         }
 
429
 
 
430
      printf ("\t     %s\n", line);
 
431
      printf ("\t     ^\n");
 
432
      printf ("\t*** Unknown parameter ***\n");
 
433
    }
 
434
 
 
435
  if (conf->os_bad)
 
436
    {
 
437
      return 0;
 
438
    }
 
439
 
 
440
  if (conf->check_os && !conf->os_ok)
 
441
    {
 
442
      return 0;
 
443
    }
 
444
 
 
445
  if (conf->cpu_bad)
 
446
    {
 
447
      return 0;
 
448
    }
 
449
 
 
450
  if (conf->check_cpu && !conf->cpu_ok)
 
451
    {
 
452
      return 0;
 
453
    }
 
454
 
 
455
  if (conf->check_endian && !conf->endian_ok)
 
456
    {
 
457
      return 0;
 
458
    }
 
459
 
 
460
  if (conf->check_platform && !conf->platform_ok)
 
461
    {
 
462
      return 0;
 
463
    }
 
464
 
 
465
/*
 
466
 * Under some CPU architectures we should compile only the driver modules
 
467
 * that have proper targetcpu line in their .config file. It doesn't make any
 
468
 * sense to compile PCI drivers for architectures that don't have any PCI bus.
 
469
 */
 
470
  if (conf->mode == MD_MODULE && exact_architectures && !conf->check_cpu)
 
471
     {
 
472
        printf ("Ignoring %s - No CPU specified\n", comment);
 
473
        return 0;
 
474
     }
 
475
 
 
476
  return 1;
 
477
}
 
478
 
 
479
#if defined(linux)
 
480
#include "gen_driver_linux.inc"
 
481
#endif
 
482
 
 
483
#if defined(__FreeBSD__)
 
484
#include "gen_driver_freebsd.inc"
 
485
#endif
 
486
 
 
487
#if defined(sun)
 
488
#include "gen_driver_solaris.inc"
 
489
#endif
 
490
 
 
491
#if defined(__SCO_VERSION__)
 
492
#include "gen_driver_sco.inc"
 
493
#endif
 
494
 
 
495
#if defined(__BEOS__) || defined(__HAIKU__)
 
496
#include "gen_driver_beos.inc"
 
497
#endif
 
498
 
 
499
static int
 
500
is_cplusplus (char *fname)
 
501
{
 
502
  while (*fname && *fname != '.')
 
503
    fname++;
 
504
 
 
505
  if (strcmp (fname, ".cpp") == 0)
 
506
    return 1;
 
507
  if (strcmp (fname, ".C") == 0)
 
508
    return 1;
 
509
 
 
510
  return 0;
 
511
}
 
512
 
 
513
static int
 
514
cmpstringp (const void *p1, const void *p2)
 
515
{
 
516
  /* The arguments to this function are "pointers to
 
517
   * pointers to char", but strcmp() arguments are "pointers
 
518
   * to char", hence the following cast plus dereference
 
519
   */
 
520
 
 
521
  /*
 
522
   * Make sure "lib" directories get compiles before any other
 
523
   * subdirectories.
 
524
   */
 
525
 
 
526
   if (strcmp(*(char **) p1, "lib")==0)
 
527
      return -1;
 
528
   else
 
529
      if (strcmp(*(char **) p2, "lib")==0)
 
530
         return 1;
 
531
 
 
532
  return strcmp (*(char **) p1, *(char **) p2);
 
533
}
 
534
 
 
535
static int
 
536
scan_dir (char *path, char *name, char *topdir, conf_t * cfg, int level)
 
537
{
 
538
  int i;
 
539
  DIR *dir;
 
540
  struct dirent *de;
 
541
  struct stat st;
 
542
  char tmp[256];
 
543
  FILE *f;
 
544
  FILE *cf;
 
545
  char cfg_name[64];
 
546
  char cfg_header[64];
 
547
  int cfg_seen = 0;
 
548
 
 
549
  conf_t conf;
 
550
 
 
551
  int ndirs = 0;
 
552
  char *subdirs[MAX_SUBDIRS];
 
553
 
 
554
  int nobjects = 0;
 
555
  char *objects[MAX_OBJECTS], *obj_src[MAX_OBJECTS];
 
556
  int nsources = 0;
 
557
  char *sources[MAX_OBJECTS];
 
558
  char obj[128], *p, *suffix;
 
559
  char *objdir = "OBJDIR";
 
560
  int include_local_makefile = 0;
 
561
 
 
562
#define MAX_FILENAME 128
 
563
  char *filenames[MAX_FILENAME];
 
564
  int n_filenames = 0;
 
565
 
 
566
  char tmp_endian[100]="";
 
567
  char autogen_sources[1024]="";
 
568
 
 
569
  memcpy (&conf, cfg, sizeof (conf));
 
570
 
 
571
  if (conf.mode == MD_MODULE_)
 
572
    conf.mode = MD_MODULE;
 
573
 
 
574
  if (conf.mode == MD_KERNEL_)
 
575
    conf.mode = MD_KERNEL;
 
576
 
 
577
  sprintf (tmp, "%s/.name", path);
 
578
  if ((cf = fopen (tmp, "r")) != NULL)
 
579
    {
 
580
      char *p;
 
581
 
 
582
      if (fgets(tmp, sizeof(tmp)-1, cf)==NULL)
 
583
         strcpy(tmp, name);
 
584
      fclose (cf);
 
585
 
 
586
      p=tmp+strlen(tmp)-1;
 
587
      if (*p=='\n')*p=0;
 
588
 
 
589
      conf.purpose=strdup(tmp);
 
590
    }
 
591
  else
 
592
    {
 
593
            conf.purpose=strdup(name);
 
594
    }
 
595
 
 
596
  sprintf (tmp, "%s/.config", path);
 
597
  if ((cf = fopen (tmp, "r")) != NULL)
 
598
    {
 
599
      if (!parse_config (cf, &conf, path))
 
600
        {
 
601
          /* Not compatible with this environment */
 
602
          fclose (cf);
 
603
          return 0;
 
604
        }
 
605
      fclose (cf);
 
606
    }
 
607
  else
 
608
    if (conf.mode == MD_MODULE && exact_architectures) /* .config required for this arch */
 
609
     {
 
610
        printf ("Ignoring %s - No CPU specified\n", path);
 
611
        return 0;
 
612
     }
 
613
 
 
614
  sprintf (tmp, "%s/.nativemake", path);        /* Use the existing makefile */
 
615
  if (stat (tmp, &st) != -1)
 
616
    {
 
617
      return 1;
 
618
    }
 
619
 
 
620
  sprintf (cfg_name, "%s_cfg.c", name);
 
621
  sprintf (cfg_header, "%s_cfg.h", name);
 
622
 
 
623
  sprintf (tmp, "%s/Makefile.%s", path, conf.system);
 
624
  unlink (tmp);
 
625
 
 
626
  sprintf (tmp, "%s/Makefile", path);
 
627
  unlink (tmp);
 
628
 
 
629
  sprintf (tmp, "%s/.nomake", path);
 
630
  if (stat (tmp, &st) != -1)
 
631
    return 0;
 
632
 
 
633
  sprintf (tmp, "%s/.makefile", path);
 
634
  if (stat (tmp, &st) != -1)
 
635
    include_local_makefile = 1;
 
636
 
 
637
  if (kernelonly)
 
638
    if (conf.mode == MD_USERLAND || conf.mode == MD_SBIN)
 
639
      return 0;
 
640
 
 
641
  if (useronly)
 
642
    if (conf.mode == MD_KERNEL || conf.mode == MD_MODULE ||
 
643
        conf.mode == MD_KERNEL_ || conf.mode == MD_MODULE_)
 
644
      return 0;
 
645
 
 
646
  if (conf.mode == MD_MODULE)
 
647
    driver_gen (name, &conf, cfg_name, cfg_header, path, topdir);
 
648
 
 
649
  if ((dir = opendir (path)) == NULL)
 
650
    {
 
651
      perror (path);
 
652
      fprintf(stderr, "scan_dir(%s): Opendir failed\n", path);
 
653
      exit (-1);
 
654
    }
 
655
 
 
656
  while ((de = readdir (dir)) != NULL)
 
657
    {
 
658
      if (de->d_name[0] == '.')
 
659
        continue;
 
660
 
 
661
      if (n_filenames >= MAX_FILENAME)
 
662
        {
 
663
          fprintf (stderr, "Too many files in directory %s\n", path);
 
664
          exit (-1);
 
665
        }
 
666
 
 
667
      filenames[n_filenames++] = strdup (de->d_name);
 
668
    }
 
669
 
 
670
  qsort (filenames, n_filenames, sizeof (char *), cmpstringp);
 
671
 
 
672
  for (i = 0; i < n_filenames; i++)
 
673
    {
 
674
      sprintf (tmp, "%s/%s", path, filenames[i]);
 
675
      if (stat (tmp, &st) == -1)
 
676
        {
 
677
          perror (tmp);
 
678
          continue;
 
679
        }
 
680
 
 
681
      if (S_ISDIR (st.st_mode))
 
682
        {
 
683
          char top[256];
 
684
 
 
685
          if (topdir == NULL)
 
686
            strcpy (top, "..");
 
687
          else
 
688
            sprintf (top, "../%s", topdir);
 
689
 
 
690
          if (scan_dir (tmp, filenames[i], top, &conf, level + 1))
 
691
            {
 
692
              if (ndirs >= MAX_SUBDIRS)
 
693
                {
 
694
                  fprintf (stderr, "Too many subdirs in %s\n", path);
 
695
                  exit (-1);
 
696
                }
 
697
 
 
698
              subdirs[ndirs++] = strdup (filenames[i]);
 
699
            }
 
700
          continue;
 
701
        }
 
702
      /*      printf("%s/%s\n", path, filenames[i]); */
 
703
 
 
704
      if (nobjects >= MAX_OBJECTS || nsources >= MAX_OBJECTS)
 
705
        {
 
706
          fprintf (stderr, "Too many objects in %s\n", path);
 
707
          exit (-1);
 
708
        }
 
709
 
 
710
      strcpy (obj, filenames[i]);
 
711
      p = obj;
 
712
      suffix = "";
 
713
 
 
714
      while (*p)
 
715
        {
 
716
          if (*p == '.')
 
717
            suffix = p;
 
718
          p++;
 
719
        }
 
720
 
 
721
      if (strcmp (suffix, ".c") == 0)
 
722
        {
 
723
          sources[nsources++] = strdup (obj);
 
724
          if (strcmp (obj, cfg_name) == 0)
 
725
            cfg_seen = 1;
 
726
        }
 
727
 
 
728
      if (config_phpmake)
 
729
         {
 
730
                 if (strcmp(suffix, ".PHc") == 0)
 
731
                    {
 
732
                            if (*autogen_sources != 0)
 
733
                               strcat(autogen_sources, " ");
 
734
                            *suffix=0;
 
735
                            strcat(autogen_sources, obj);
 
736
                            strcat(autogen_sources, ".c");
 
737
                            *suffix='.';
 
738
                            strcpy(suffix, ".c");
 
739
                    }
 
740
                 else
 
741
                 if (strcmp(suffix, ".PHh") == 0)
 
742
                    {
 
743
                            if (*autogen_sources != 0)
 
744
                               strcat(autogen_sources, " ");
 
745
                            *suffix=0;
 
746
                            strcat(autogen_sources, obj);
 
747
                            strcat(autogen_sources, ".h");
 
748
                            *suffix='.';
 
749
                    }
 
750
                 else
 
751
                 if (strcmp(suffix, ".PHinc") == 0)
 
752
                    {
 
753
                            if (*autogen_sources != 0)
 
754
                               strcat(autogen_sources, " ");
 
755
                            *suffix=0;
 
756
                            strcat(autogen_sources, obj);
 
757
                            strcat(autogen_sources, ".inc");
 
758
                            *suffix='.';
 
759
                    }
 
760
         }
 
761
      else
 
762
         {
 
763
                 char source[256], target[256];
 
764
 
 
765
                 if (strcmp(suffix, ".PHc") == 0)
 
766
                    {
 
767
                            *suffix=0;
 
768
                            sprintf (source, "%s.PHc", obj);
 
769
                            sprintf (target, "%s/%s.c", path, obj);
 
770
                            *suffix='.';
 
771
                            if (symlink (source, target) == -1)
 
772
                               {
 
773
                                       perror(source);
 
774
                                       exit(1);
 
775
                               }
 
776
                    }
 
777
                 else
 
778
                 if (strcmp(suffix, ".PHh") == 0)
 
779
                    {
 
780
                            *suffix=0;
 
781
                            sprintf (source, "%s.PHh", obj);
 
782
                            sprintf (target, "%s/%s.h", path, obj);
 
783
                            *suffix='.';
 
784
                            if (symlink (source, target) == -1)
 
785
                               {
 
786
                                       perror(source);
 
787
                                       exit(1);
 
788
                               }
 
789
                    }
 
790
                 else
 
791
                 if (strcmp(suffix, ".PHinc") == 0)
 
792
                    {
 
793
                            *suffix=0;
 
794
                            sprintf (source, "%s.PHinc", obj);
 
795
                            sprintf (target, "%s/%s.inc", path, obj);
 
796
                            *suffix='.';
 
797
printf("Symlink %s -> %s\n", source, target);
 
798
                            if (symlink (source, target) == -1)
 
799
                               {
 
800
                                       perror(source);
 
801
                                       exit(1);
 
802
                               }
 
803
                    }
 
804
         }
 
805
 
 
806
      if (strcmp (suffix, ".c") == 0 ||
 
807
          strcmp (suffix, ".C") == 0 || strcmp (suffix, ".cpp") == 0)
 
808
        {
 
809
          obj_src[nobjects] = strdup (obj);
 
810
          *suffix = 0;
 
811
          strcat (obj, ".o");
 
812
          objects[nobjects++] = strdup (obj);
 
813
        }
 
814
    }
 
815
 
 
816
  closedir (dir);
 
817
  sprintf (tmp, "%s/.depend", path);
 
818
  unlink (tmp);
 
819
  sprintf (tmp, "touch %s/.depend", path);
 
820
  system (tmp);
 
821
 
 
822
  if (level == 1 && *this_os && !useronly)
 
823
    {
 
824
      subdirs[ndirs++] = strdup (this_os);
 
825
    }
 
826
 
 
827
#if 0
 
828
  // This block is no longer necessary because the driver_gen () call was moved.
 
829
  // Now the _cfg.c file should get created so that it gets picked by the readdir() loop.
 
830
  // However keep it here for a while.
 
831
  if (!cfg_seen && conf.mode == MD_MODULE)
 
832
    {
 
833
# if !defined(linux) && !defined(__FreeBSD__)
 
834
      sprintf (tmp, "%s_cfg.c", name);
 
835
      sources[nsources++] = strdup (tmp);
 
836
 
 
837
      obj_src[nobjects] = strdup (tmp);
 
838
      sprintf (tmp, "%s_cfg.o", name);
 
839
      objects[nobjects++] = strdup (tmp);
 
840
# endif
 
841
    }
 
842
#endif
 
843
 
 
844
#if 0
 
845
  // This stuff has been moved above the readdir() loop.
 
846
  if (conf.mode == MD_MODULE)
 
847
    driver_gen (name, &conf, cfg_name, cfg_header, path, topdir);
 
848
#endif
 
849
 
 
850
  if (do_cleanup || (ndirs == 0 && nobjects == 0))
 
851
    {
 
852
      return 0;
 
853
    }
 
854
 
 
855
  if (config_phpmake)
 
856
     sprintf (tmp, "%s/Makefile.php", path);
 
857
  else
 
858
     sprintf (tmp, "%s/Makefile", path);
 
859
 
 
860
#if 0
 
861
  if ((f = fopen (tmp, "w")) == NULL)
 
862
    {
 
863
      perror (tmp);
 
864
      exit (-1);
 
865
    }
 
866
 
 
867
  if (include_local_makefile)
 
868
    {
 
869
      fprintf (f, "\n");
 
870
      fprintf (f, "include .makefile\n");
 
871
      fprintf (f, "\n");
 
872
    }
 
873
 
 
874
  fprintf (f, "all:\n");
 
875
  fprintf (f,
 
876
           "\t$(MAKE) $(BUILDFLAGS) BUILDFLAGS=\"$(BUILDFLAGS)\" -f Makefile.`uname -s` all\n\n");
 
877
 
 
878
  fprintf (f, "config:\n");
 
879
  fprintf (f,
 
880
           "\t$(MAKE) $(BUILDFLAGS) BUILDFLAGS=\"$(BUILDFLAGS)\" -f make.defs config\n\n");
 
881
 
 
882
  fprintf (f, "purge:\n");
 
883
  fprintf (f,
 
884
           "\t$(MAKE) $(BUILDFLAGS) BUILDFLAGS=\"$(BUILDFLAGS)\" -f make.defs purge\n\n");
 
885
 
 
886
  fprintf (f, "dirs:\n");
 
887
  fprintf (f,
 
888
           "\t$(MAKE) $(BUILDFLAGS) BUILDFLAGS=\"$(BUILDFLAGS)\" -f Makefile.`uname -s` dirs\n\n");
 
889
 
 
890
  fprintf (f, "clean:\n");
 
891
  fprintf (f,
 
892
           "\t$(MAKE)  $(BUILDFLAGS) BUILDFLAGS=\"$(BUILDFLAGS)\" -f Makefile.`uname -s` clean\n\n");
 
893
 
 
894
  fprintf (f, "lint:\n");
 
895
  fprintf (f,
 
896
           "\t$(MAKE)  $(BUILDFLAGS) BUILDFLAGS=\"$(BUILDFLAGS)\" -f Makefile.`uname -s` lint\n\n");
 
897
 
 
898
  fprintf (f, "dep:\n");
 
899
  fprintf (f,
 
900
           "\t$(MAKE)  $(BUILDFLAGS) BUILDFLAGS=\"$(BUILDFLAGS)\" -f Makefile.`uname -s` dep\n\n");
 
901
 
 
902
  fclose (f);
 
903
 
 
904
  sprintf (tmp, "%s/Makefile.%s", path, conf.system);
 
905
#endif
 
906
  if ((f = fopen (tmp, "w")) == NULL)
 
907
    {
 
908
      perror (tmp);
 
909
      exit (-1);
 
910
    }
 
911
 
 
912
  fprintf (f, "# Makefile for %s module %s\n\n", conf.project_name, name);
 
913
 
 
914
  if (config_phpmake)
 
915
     fprintf (f, "<?php require getenv(\"PHPMAKE_LIBPATH\") . \"library.php\"; phpmake_makefile_top_rules(); ?>\n");
 
916
 
 
917
  fprintf (f, "CC=%s\n", conf.ccomp);
 
918
  // fprintf (f, "LD=ld\n");
 
919
  fprintf (f, "HOSTCC=%s\n", hostcc);
 
920
  fprintf (f, "CPLUSPLUS=%s\n", conf.cplusplus);
 
921
 
 
922
#ifdef VXWORKS
 
923
  vxworks_genheader (f, path);
 
924
#endif
 
925
 
 
926
#if defined(__SCO_VERSION__)
 
927
  if (*conf.cflags != 0)
 
928
    fprintf (f, "CFLAGS=%s\n", conf.cflags);
 
929
#endif
 
930
  if (*conf.ldflags != 0)
 
931
    fprintf (f, "LDFLAGS=%s\n", conf.ldflags);
 
932
 
 
933
  if (strcmp(conf.endianess, "UNKNOWN") != 0)
 
934
     sprintf (tmp_endian, " -DOSS_%s_ENDIAN", conf.endianess);
 
935
 
 
936
  fprintf (f, "OSFLAGS=%s%s\n", conf.OSflags, tmp_endian);
 
937
 
 
938
  fprintf (f, "OS=%s\n", conf.system);
 
939
  fprintf (f, "ARCH=%s\n", conf.arch);
 
940
 
 
941
  if (topdir == NULL)
 
942
    fprintf (f, "TOPDIR=.\n");
 
943
  else
 
944
    fprintf (f, "TOPDIR=%s\n", topdir);
 
945
 
 
946
  fprintf (f, "OBJDIR=$(TOPDIR)/target/objects\n");
 
947
  fprintf (f, "TMPDIR=.\n");
 
948
  fprintf (f, "MODDIR=$(TOPDIR)/target/modules\n");
 
949
  fprintf (f, "BINDIR=$(TOPDIR)/target/bin\n");
 
950
  fprintf (f, "LIBDIR=$(TOPDIR)/target/lib\n");
 
951
  fprintf (f, "SBINDIR=$(TOPDIR)/target/sbin\n");
 
952
  if ((p = getenv("OSSLIBDIR")) != NULL)
 
953
    fprintf (f, "OSSLIBDIR=\"%s\"\n", p);
 
954
 
 
955
  fprintf (f, "THISOS=%s\n", this_os);
 
956
 
 
957
  if (config_phpmake)
 
958
     fprintf (f, "CFLAGS+=-D__USE_PHPMAKE__\n");
 
959
 
 
960
  if (conf.mode == MD_KERNEL || conf.mode == MD_MODULE)
 
961
    {
 
962
#if defined(__SCO_VERSION__)
 
963
      fprintf (f, "CFLAGS=-O -D_KERNEL -D_DDI=8\n");
 
964
#else
 
965
      fprintf (f, "CFLAGS += -D_KERNEL\n");
 
966
#endif
 
967
#ifdef HAVE_KERNEL_FLAGS
 
968
      add_kernel_flags (f);
 
969
#endif
 
970
    }
 
971
#ifndef __SCO_VERSION__
 
972
  else
 
973
    {
 
974
      fprintf (f, "CFLAGS+=-O\n");
 
975
    }
 
976
#endif
 
977
 
 
978
#if !defined(__SCO_VERSION__)
 
979
  if (*conf.cflags != 0)
 
980
    fprintf (f, "CFLAGS += %s\n", conf.cflags);
 
981
  if (conf.mode == MD_SHLIB)
 
982
    fprintf (f, "CFLAGS += %s\n", shlib_cflags);
 
983
#endif
 
984
  if (conf.mode != MD_KERNEL)
 
985
    objdir = "TMPDIR";
 
986
 
 
987
  if (nincludes > 0)
 
988
    {
 
989
      int i;
 
990
      fprintf (f, "INCLUDES=");
 
991
      for (i = 0; i < nincludes; i++)
 
992
        {
 
993
          if (i > 0)
 
994
            fprintf (f, " ");
 
995
          if (includes[i][0] == '/')
 
996
            fprintf (f, "%s", includes[i]);
 
997
          else
 
998
            fprintf (f, "-I$(TOPDIR)/%s", includes[i]);
 
999
        }
 
1000
      fprintf (f, "\n");
 
1001
    }
 
1002
 
 
1003
  if (ndirs > 0)
 
1004
    {
 
1005
      int i;
 
1006
 
 
1007
      if (config_phpmake)
 
1008
         {
 
1009
              fprintf (f, "<?php\n");
 
1010
              fprintf (f, "\t$subdirs=array(");
 
1011
              for (i = 0; i < ndirs; i++)
 
1012
                {
 
1013
                  if (i > 0)
 
1014
                    fprintf (f, ", ");
 
1015
                  fprintf (f, "\"%s\"", subdirs[i]);
 
1016
                }
 
1017
              fprintf (f, ");\n");
 
1018
              fprintf (f, "phpmake_print_subdirs($subdirs);\n");
 
1019
              fprintf (f, "?>\n");
 
1020
         }
 
1021
      else
 
1022
         {
 
1023
              fprintf (f, "SUBDIRS=");
 
1024
              for (i = 0; i < ndirs; i++)
 
1025
                {
 
1026
                  if (i > 0)
 
1027
                    fprintf (f, " ");
 
1028
                  fprintf (f, "%s", subdirs[i]);
 
1029
                }
 
1030
              fprintf (f, "\n");
 
1031
         }
 
1032
    }
 
1033
 
 
1034
  if (nobjects > 0)
 
1035
    {
 
1036
      int i;
 
1037
 
 
1038
      fprintf (f, "OBJECTS=");
 
1039
 
 
1040
      for (i = 0; i < nobjects; i++)
 
1041
        {
 
1042
          if (i > 0)
 
1043
            fprintf (f, " ");
 
1044
          fprintf (f, "$(%s)/%s", objdir, objects[i]);
 
1045
        }
 
1046
 
 
1047
      fprintf (f, "\n");
 
1048
    }
 
1049
 
 
1050
  if (conf.mode == MD_MODULE)
 
1051
    {
 
1052
      fprintf (f, "TARGETS=$(MODDIR)/%s $(MODDIR)/%s.o\n", name, name);
 
1053
      fprintf (f, "DEPDIR=$(TMPDIR)\n");
 
1054
    }
 
1055
  else if ((conf.mode == MD_USERLAND) && nobjects > 0)
 
1056
    {
 
1057
      fprintf (f, "TARGETS=$(BINDIR)/%s\n", name);
 
1058
      fprintf (f, "DEPDIR=$(BINDIR)/\n");
 
1059
    }
 
1060
  else if ((conf.mode == MD_SBIN) && nobjects > 0)
 
1061
    {
 
1062
      fprintf (f, "TARGETS=$(SBINDIR)/%s\n", name);
 
1063
      fprintf (f, "DEPDIR=$(SBINDIR)/\n");
 
1064
    }
 
1065
  else
 
1066
    {
 
1067
      fprintf (f, "TARGETS=%s\n", name);
 
1068
      fprintf (f, "DEPDIR=\n");
 
1069
    }
 
1070
 
 
1071
  if (nsources > 0)
 
1072
    {
 
1073
      int i;
 
1074
 
 
1075
      fprintf (f, "CSOURCES=");
 
1076
 
 
1077
      for (i = 0; i < nsources; i++)
 
1078
        {
 
1079
          if (i > 0)
 
1080
            fprintf (f, " ");
 
1081
          fprintf (f, "%s", sources[i]);
 
1082
        }
 
1083
 
 
1084
      fprintf (f, "\n");
 
1085
    }
 
1086
 
 
1087
  if (*autogen_sources != 0)
 
1088
     fprintf (f, "AUTOGEN_SOURCES=%s\n", autogen_sources);
 
1089
 
 
1090
  fprintf (f, "\n");
 
1091
 
 
1092
  if (include_local_makefile)
 
1093
    {
 
1094
      fprintf (f, "include .makefile\n");
 
1095
      fprintf (f, "\n");
 
1096
    }
 
1097
 
 
1098
  if (config_phpmake)
 
1099
     fprintf (f, "<?php phpmake_makefile_rules(); ?>\n");
 
1100
  /*
 
1101
   * Create the default target
 
1102
   */
 
1103
  fprintf (f, "all: ");
 
1104
 
 
1105
  if (conf.mode == MD_USERLAND && nsources > 0)
 
1106
    {
 
1107
      fprintf (f, "$(TARGETS) ");
 
1108
    }
 
1109
  else if (conf.mode == MD_MODULE)
 
1110
    {
 
1111
      if (nobjects > 0)
 
1112
        fprintf (f, "$(MODDIR)/%s.o ", name);
 
1113
    }
 
1114
  else if (conf.mode == MD_SHLIB)
 
1115
    {
 
1116
        fprintf (f, "$(LIBDIR)/%s.so ", name);
 
1117
    }
 
1118
  else if (conf.mode != MD_KERNEL)
 
1119
    {
 
1120
      if (nobjects > 0)
 
1121
        {
 
1122
          if (conf.mode == MD_SBIN)
 
1123
            fprintf (f, "$(SBINDIR)/%s ", name);
 
1124
          else
 
1125
            fprintf (f, "$(BINDIR)/%s ", name);
 
1126
        }
 
1127
    }
 
1128
  else
 
1129
    {
 
1130
      if (nobjects > 0)
 
1131
        fprintf (f, "$(AUTOGEN_SOURCES) objects ");
 
1132
    }
 
1133
 
 
1134
  if (ndirs > 0)
 
1135
    fprintf (f, "subdirs ");
 
1136
  fprintf (f, "\n");
 
1137
#if 0
 
1138
  if (level == 1)
 
1139
    fprintf (f,
 
1140
             "\t-sh $(THISOS)/build.sh \"$(ARCH)\" \"$(INCLUDES)\" \"$(CFLAGS)\"\n");
 
1141
  fprintf (f, "\n");
 
1142
#endif
 
1143
 
 
1144
  /*
 
1145
   * Create the lint target
 
1146
   */
 
1147
  fprintf (f, "lint: ");
 
1148
  if (nobjects > 0)
 
1149
    fprintf (f, "lint_sources ");
 
1150
  if (ndirs > 0)
 
1151
    fprintf (f, "lint_subdirs ");
 
1152
  fprintf (f, "\n\n");
 
1153
 
 
1154
  /*
 
1155
   * Create the dep target
 
1156
   */
 
1157
  fprintf (f, "dep: ");
 
1158
  if (nobjects > 0)
 
1159
    fprintf (f, "$(AUTOGEN_SOURCES) dep_local ");
 
1160
  if (ndirs > 0)
 
1161
    fprintf (f, "dep_subdirs ");
 
1162
  fprintf (f, "\n\n");
 
1163
 
 
1164
  fprintf (f, "include $(TOPDIR)/make.defs\n");
 
1165
  fprintf (f, "\n");
 
1166
 
 
1167
  if (conf.mode == MD_USERLAND)
 
1168
    {
 
1169
      fprintf (f, "%s:\t$(BINDIR)/%s\n\n", name, name);
 
1170
 
 
1171
      fprintf (f, "$(BINDIR)/%s:\t$(OBJECTS)\n", name);
 
1172
      fprintf (f,
 
1173
               "\t$(CC) $(CFLAGS) -s -o $(BINDIR)/%s $(OBJECTS) $(LIBRARIES) $(LDFLAGS) %s\n",
 
1174
               name, extra_libraries);
 
1175
      fprintf (f, "\n\n");
 
1176
    }
 
1177
 
 
1178
  if (conf.mode == MD_SHLIB)
 
1179
    {
 
1180
      fprintf (f, "%s.so:\t$(LIBDIR)/%s.so\n\n", name, name);
 
1181
 
 
1182
      fprintf (f, "$(LIBDIR)/%s.so:\t$(OBJECTS)\n", name);
 
1183
#if defined(linux)
 
1184
      /* gcc -shared works much better than ld on Linux */
 
1185
      fprintf (f,
 
1186
               "\t$(CC) $(LDFLAGS) %s -o $(LIBDIR)/%s.so $(OBJECTS)\n",
 
1187
               shlib_cflags, name);
 
1188
#else
 
1189
      fprintf (f,
 
1190
               "\t$(LD) $(LDFLAGS) %s -o $(LIBDIR)/%s.so $(OBJECTS)\n",
 
1191
               shlib_ldflags, name);
 
1192
#endif
 
1193
      fprintf (f, "\n\n");
 
1194
    }
 
1195
 
 
1196
  if (conf.mode == MD_SBIN)
 
1197
    {
 
1198
      fprintf (f, "%s:\t$(SBINDIR)/%s\n\n", name, name);
 
1199
 
 
1200
      fprintf (f, "$(SBINDIR)/%s:\t$(OBJECTS)\n", name);
 
1201
      fprintf (f,
 
1202
               "\t$(CC) $(CFLAGS) -s -o $(SBINDIR)/%s $(OBJECTS) $(LIBRARIES) $(LDFLAGS) %s\n",
 
1203
               name, extra_libraries);
 
1204
      fprintf (f, "\n\n");
 
1205
    }
 
1206
 
 
1207
  if (conf.mode == MD_MODULE)
 
1208
    {
 
1209
      fprintf (f, "$(MODDIR)/%s.o:\t$(OBJECTS)\n", name);
 
1210
      fprintf (f, "\t$(LD) $(LDARCH) -r -o $(MODDIR)/%s.o $(OBJECTS)\n",
 
1211
               name);
 
1212
      fprintf (f, "\n\n");
 
1213
    }
 
1214
 
 
1215
  if (nobjects > 0)
 
1216
    {
 
1217
      int i;
 
1218
 
 
1219
      for (i = 0; i < nobjects; i++)
 
1220
        {
 
1221
          fprintf (f, "$(%s)/%s:\t%s\n", objdir, objects[i], obj_src[i]);
 
1222
 
 
1223
          if (is_cplusplus (obj_src[i]))
 
1224
            fprintf (f,
 
1225
                     "\t$(CPLUSPLUS) -c $(CFLAGS) $(OSFLAGS) $(INCLUDES) %s -o $(%s)/%s\n",
 
1226
                     obj_src[i], objdir, objects[i]);
 
1227
          else
 
1228
            fprintf (f,
 
1229
                     "\t$(CC) -c $(CFLAGS) $(OSFLAGS) $(LIBRARIES) $(INCLUDES) %s -o $(%s)/%s\n",
 
1230
                     obj_src[i], objdir, objects[i]);
 
1231
          fprintf (f, "\n");
 
1232
        }
 
1233
    }
 
1234
 
 
1235
  fprintf (f, "clean: clean_local");
 
1236
  if (ndirs > 0)
 
1237
    fprintf (f, " clean_subdirs");
 
1238
  fprintf (f, "\n\n");
 
1239
 
 
1240
  fclose (f);
 
1241
  return 1;
 
1242
}
 
1243
 
 
1244
static int already_configured = 0;
 
1245
 
 
1246
static void
 
1247
produce_output (conf_t * conf)
 
1248
{
 
1249
  if (already_configured)
 
1250
    return;
 
1251
 
 
1252
  scan_dir (".", "main", NULL, conf, 1);
 
1253
  scan_dir (this_os, "main", "../../..", conf, 3);
 
1254
 
 
1255
  symlink (this_os, "targetos");
 
1256
 
 
1257
  already_configured = 1;
 
1258
}
 
1259
 
 
1260
static void
 
1261
check_endianess (conf_t * conf)
 
1262
{
 
1263
  unsigned char probe[4] = { 1, 2, 3, 4 };
 
1264
 
 
1265
  if ((*(unsigned int *) &probe) == 0x01020304)
 
1266
    {
 
1267
      strcpy (conf->endianess, "BIG");
 
1268
    }
 
1269
  else
 
1270
    {
 
1271
      strcpy (conf->endianess, "LITTLE");
 
1272
    }
 
1273
}
 
1274
 
 
1275
static void
 
1276
produce_local_config_h (conf_t * conf)
 
1277
{
 
1278
/*
 
1279
 * Produce local_config.h
 
1280
 */
 
1281
        int grc_min=3, grc_max=3; // GRC3 min/max quality settings
 
1282
 
 
1283
        FILE *f;
 
1284
        char *p;
 
1285
        int q;
 
1286
 
 
1287
        if ((f=fopen ("kernel/framework/include/local_config.h", "w"))==NULL)
 
1288
           {
 
1289
                   perror ("kernel/framework/include/local_config.h");
 
1290
                   exit(-1);
 
1291
           }
 
1292
 
 
1293
        fprintf (f, "/*\n");
 
1294
        fprintf (f, " * Automatically generated by the configure script (srcconf.c) - Do not edit.\n");
 
1295
        fprintf (f, "*/\n");
 
1296
 
 
1297
/*
 
1298
 * GRC3 sample rate converter min/max quality settings
 
1299
 */
 
1300
        if ((p=getenv("GRC_MIN_QUALITY"))!= NULL)
 
1301
        {
 
1302
           if (sscanf(p, "%d", &q) != 1)
 
1303
              {
 
1304
                      fprintf (stderr, "Bad GRC_MIN_QUALITY '%s'\n", p);
 
1305
                      exit (EXIT_FAILURE);
 
1306
              }
 
1307
 
 
1308
           if (q >= 0 && q <= 6)
 
1309
              grc_min = q;
 
1310
        }
 
1311
 
 
1312
        if ((p=getenv("GRC_MAX_QUALITY"))!= NULL)
 
1313
        {
 
1314
           if (sscanf(p, "%d", &q) != 1)
 
1315
              {
 
1316
                      fprintf (stderr, "Bad GRC_MAX_QUALITY '%s'\n", p);
 
1317
                      exit (EXIT_FAILURE);
 
1318
              }
 
1319
 
 
1320
           if (q >= 0 && q <= 6)
 
1321
              grc_max = q;
 
1322
        }
 
1323
 
 
1324
        if (grc_max < grc_min)
 
1325
           grc_max = grc_min = 3;
 
1326
 
 
1327
        fprintf (f, "#define CONFIG_OSS_GRC_MIN_QUALITY %d\n", grc_min);
 
1328
        fprintf (f, "#define CONFIG_OSS_GRC_MAX_QUALITY %d\n", grc_max);
 
1329
 
 
1330
/*
 
1331
 * Generate VMIX configuration
 
1332
 */
 
1333
 
 
1334
        if (strcmp (vmix_mode, "DISABLED") == 0)
 
1335
           {
 
1336
                   fprintf (f, "#undef  CONFIG_OSS_VMIX\n");
 
1337
           }
 
1338
        else
 
1339
           {
 
1340
                   fprintf (f, "#define CONFIG_OSS_VMIX\n");
 
1341
 
 
1342
                   if (strcmp (vmix_mode, "FLOAT") == 0)
 
1343
                      fprintf (f, "#define CONFIG_OSS_VMIX_FLOAT\n");
 
1344
                   else
 
1345
                      fprintf (f, "#undef  CONFIG_OSS_VMIX_FLOAT\n");
 
1346
           }
 
1347
 
 
1348
/*
 
1349
 * Generate MIDI configuration
 
1350
 */
 
1351
 
 
1352
        if (strcmp (config_midi, "DISABLED") == 0)
 
1353
           fprintf (f, "#undef  CONFIG_OSS_MIDI\n");
 
1354
        else
 
1355
           fprintf (f, "#define CONFIG_OSS_MIDI\n");
 
1356
 
 
1357
/*
 
1358
 * Enable DO_TIMINGS code
 
1359
 */
 
1360
 
 
1361
        if (getenv("DO_TIMINGS") != NULL)
 
1362
           fprintf (f, "#define DO_TIMINGS\n");
 
1363
 
 
1364
        fclose (f);
 
1365
}
 
1366
 
 
1367
static void
 
1368
produce_errno_h(void)
 
1369
{
 
1370
        FILE *f;
 
1371
 
 
1372
/*
 
1373
 * Generate oss_errno.h that contains all the errno.h codes used by OSS
 
1374
 * but defined as negative numbers.
 
1375
 */
 
1376
 
 
1377
        if ((f=fopen ("kernel/framework/include/oss_errno.h", "w"))==NULL)
 
1378
           {
 
1379
                   perror ("kernel/framework/include/oss_errno.h");
 
1380
                   exit(-1);
 
1381
           }
 
1382
#define GEN_ERRNO(e) \
 
1383
        fprintf (f, "#define OSS_"#e"\t\t%d\n", (e<=0) ? e : -(e));
 
1384
 
 
1385
        fprintf (f, "#ifndef OSS_ERRNO_H\n");
 
1386
        fprintf (f, "#define OSS_ERRNO_H\n");
 
1387
        fprintf (f, "\n");
 
1388
        fprintf (f, "/*\n");
 
1389
        fprintf (f, " * Error (errno) codes used by OSS.\n");
 
1390
        fprintf (f, " * \n");
 
1391
        fprintf (f, " * This file is automatically generated by srcconf.c (produce_errno_h()) - do not edit.\n");
 
1392
        fprintf (f, " * \n");
 
1393
        fprintf (f, " * The following codes are derived from the system dependent\n");
 
1394
        fprintf (f, " * error numbers defined in <errno.h>\n");
 
1395
        fprintf (f, " */\n");
 
1396
        fprintf (f, "\n");
 
1397
 
 
1398
#ifndef EBADE /* Not in FreeBSD, Haiku */
 
1399
#define EBADE EINVAL
 
1400
#endif
 
1401
 
 
1402
#ifndef EIDRM /* Not in POSIX, but is in SuS */
 
1403
#define EIDRM EFAULT
 
1404
#endif
 
1405
 
 
1406
#ifndef ENOTSUP /* Not in Haiku */
 
1407
#define ENOTSUP ENOSYS
 
1408
#endif
 
1409
 
 
1410
#ifndef EFAULT
 
1411
#define EFAULT ENOTSUP
 
1412
#endif
 
1413
 
 
1414
        GEN_ERRNO(E2BIG);
 
1415
        GEN_ERRNO(EACCES);
 
1416
        GEN_ERRNO(EAGAIN);
 
1417
        GEN_ERRNO(EBADE);
 
1418
        GEN_ERRNO(EBUSY);
 
1419
        GEN_ERRNO(ECONNRESET);
 
1420
        GEN_ERRNO(EDOM);
 
1421
        GEN_ERRNO(EFAULT);
 
1422
        GEN_ERRNO(EIDRM);
 
1423
        GEN_ERRNO(EINTR);
 
1424
        GEN_ERRNO(EINVAL);
 
1425
        GEN_ERRNO(EIO);
 
1426
        GEN_ERRNO(ELOOP);
 
1427
        GEN_ERRNO(ENODEV);
 
1428
        GEN_ERRNO(ENOENT);
 
1429
        GEN_ERRNO(ENOMEM);
 
1430
        GEN_ERRNO(ENOSPC);
 
1431
        GEN_ERRNO(ENOTSUP);
 
1432
        GEN_ERRNO(ENXIO);
 
1433
        GEN_ERRNO(EPERM);
 
1434
        GEN_ERRNO(EPIPE);
 
1435
        GEN_ERRNO(ERANGE);
 
1436
        GEN_ERRNO(EWOULDBLOCK);
 
1437
 
 
1438
        fprintf (f, "\n");
 
1439
        fprintf (f, "#endif\n");
 
1440
        fclose(f);
 
1441
}
 
1442
 
 
1443
static void
 
1444
check_system (conf_t * conf)
 
1445
{
 
1446
  struct utsname un;
 
1447
  char *p;
 
1448
 
 
1449
  if (uname (&un) == -1)
 
1450
    {
 
1451
      perror ("uname");
 
1452
      exit (-1);
 
1453
    }
 
1454
 
 
1455
  if (strcmp (un.sysname, "UnixWare") == 0)
 
1456
    strcpy (un.sysname, "SCO_SV");
 
1457
  if (strcmp (un.sysname, "Haiku") == 0)
 
1458
    strcpy (un.sysname, "BeOS");
 
1459
  printf ("System: %s\n", un.sysname);
 
1460
  strcpy (conf->system, un.sysname);
 
1461
  sprintf (this_os, "kernel/OS/%s", un.sysname);
 
1462
  printf ("Release: %s\n", un.release);
 
1463
  printf ("Machine: %s\n", un.machine);
 
1464
  strcpy (conf->arch, un.machine);
 
1465
 
 
1466
#ifdef HAVE_SYSDEP
 
1467
  check_sysdep (conf, &un);
 
1468
#else
 
1469
 
 
1470
# if defined(__SCO_VERSION__)
 
1471
        shlib_ldflags = "-G -lsocket -lnsl";
 
1472
# endif
 
1473
 
 
1474
  if (strcmp (un.machine, "i386") == 0 ||
 
1475
      strcmp (un.machine, "i486") == 0 ||
 
1476
      strcmp (un.machine, "i586") == 0 || strcmp (un.machine, "i686") == 0)
 
1477
    {
 
1478
      strcpy (conf->platform, "i86pc");
 
1479
    }
 
1480
  else
 
1481
    {
 
1482
      fprintf (stderr, "Cannot determine the platform for %s\n", un.machine);
 
1483
      exit (-1);
 
1484
    }
 
1485
#endif
 
1486
 
 
1487
  if (*conf->platform == 0)
 
1488
    {
 
1489
      fprintf (stderr, "Panic: No platform\n");
 
1490
      exit (-1);
 
1491
    }
 
1492
 
 
1493
  check_endianess (conf);
 
1494
 
 
1495
/*
 
1496
 * Check virtual mixer configuration (as set by the configure script).
 
1497
 */
 
1498
 
 
1499
  if ((p=getenv("VMIX_MODE"))!=NULL)
 
1500
     {
 
1501
             vmix_mode = strdup(p);
 
1502
     }
 
1503
 
 
1504
/*
 
1505
 * Check MIDI enabled/disabled status
 
1506
 */
 
1507
 
 
1508
  if ((p=getenv("CONFIG_MIDI"))!=NULL)
 
1509
     {
 
1510
             config_midi = strdup(p);
 
1511
     }
 
1512
 
 
1513
  produce_local_config_h (conf);
 
1514
}
 
1515
 
 
1516
int
 
1517
main (int argc, char *argv[])
 
1518
{
 
1519
  int i;
 
1520
  char tmp[256], *env;
 
1521
 
 
1522
  struct stat st;
 
1523
 
 
1524
  if (getenv("USE_PHPMAKE") != NULL)
 
1525
  if (stat("phpmake/library.php", &st) != -1)
 
1526
     config_phpmake=1;
 
1527
 
 
1528
  for (i = 1; i < argc; i++)
 
1529
    if (argv[i][0] == '-')
 
1530
      switch (argv[i][1])
 
1531
        {
 
1532
        case 'A':
 
1533
          strcpy (arch, &argv[i][2]);
 
1534
          printf ("Arch=%s\n", arch);
 
1535
          break;
 
1536
        case 'K':
 
1537
          kernelonly = 1;
 
1538
          break;                /* Compile only the kernel mode parts */
 
1539
        case 'U':
 
1540
          useronly = 1;
 
1541
          break;                /* Compile only the user land utilities */
 
1542
        }
 
1543
 
 
1544
  if (getenv("NO_WARNING_CHECKS")!=NULL)
 
1545
     do_warning_checks = 0;
 
1546
 
 
1547
  hostcc = getenv ("HOSTCC");
 
1548
  targetcc = getenv ("CC");
 
1549
  if (hostcc == NULL) hostcc = DEFAULT_CC;
 
1550
  if (targetcc == NULL) targetcc = DEFAULT_CC;
 
1551
 
 
1552
#if defined(linux) || defined(__FreeBSD__) || defined(__SCO_VERSION__)
 
1553
  mkdir ("target", 0755);
 
1554
  mkdir ("target/build", 0755);
 
1555
  system ("touch target/build/.nomake");
 
1556
#endif
 
1557
 
 
1558
  if (getenv ("SOL9") != NULL)
 
1559
    system ("touch kernel/drv/oss_usb/.nomake");
 
1560
 
 
1561
  check_system (&conf);
 
1562
 
 
1563
/*
 
1564
 * Check if setup/$CROSSCOMPILE.conf exists and load the settings in it.
 
1565
 */
 
1566
  if ((env=getenv("CROSSCOMPILE"))!=NULL)
 
1567
     {
 
1568
             FILE *cf;
 
1569
 
 
1570
             sprintf (tmp, "setup/%s.conf", env);
 
1571
             if ((cf = fopen (tmp, "r")) != NULL)
 
1572
                {
 
1573
                        parse_config (cf, &conf, tmp);
 
1574
                        fclose (cf);
 
1575
                }
 
1576
     }
 
1577
  
 
1578
 
 
1579
  produce_output (&conf);
 
1580
 
 
1581
  produce_errno_h();
 
1582
  exit (0);
 
1583
}