3
* This file is part of Open Sound System.
5
* Copyright (C) 4Front Technologies 1996-2008.
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.
17
#include <sys/types.h>
20
#include <sys/utsname.h>
23
#define MAX_SUBDIRS 64
24
#define MAX_OBJECTS 64
25
#define MAX_INCLUDES 32
28
static char *vmix_mode="FIXEDPOINT";
29
static char *config_midi="ENABLED"; // Actually this depends on the configure script
31
static int exact_architectures=0; /* 1=Compile only drivers that have matching arch given in their .config file. */
33
static int config_phpmake=0;
37
char project_name[64];
53
#define LIC_RESTRICTED 1
58
char system[32], arch[32], platform[32];
61
#define F_USEARCH 0x00000001
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;
69
int power_manage; /* Supports device power management (under Solaris) */
70
int suspend_resume; /* Supports suspend/resume (under Solaris) */
75
#define DEFAULT_CC "cc"
77
static conf_t conf = {
86
"LITTLE", /* Endianess */
87
DEFAULT_CC, /* c compiler */
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;
96
static char *shlib_cflags = "-shared -fPIC";
97
static char *shlib_ldflags = "-shared -fPIC";
99
static char *extra_libraries = "";
104
static int nincludes = 0;
105
static char *includes[MAX_INCLUDES];
106
static int do_cleanup = 0;
108
static char arch[32] = "";
111
generate_driver (char *name, conf_t * conf, char *cfg_name, char *cfg_header,
112
char *dirname, char *topdir);
115
(*generate_driver_t) (char *name, conf_t * conf, char *cfg_name, char *cfg_header,
116
char *dirname, char *topdir);
118
generate_driver_t driver_gen = generate_driver;
121
#include "srcconf_vxworks.inc"
122
#include "srcconf_linux.inc"
126
#include "srcconf_freebsd.inc"
130
#include "srcconf_vxworks.inc"
131
#include "srcconf_solaris.inc"
134
#if defined(__BEOS__) || defined(__HAIKU__)
135
#include "srcconf_beos.inc"
139
parse_config (FILE * f, conf_t * conf, char *comment)
141
char line[256], *p, *parms;
143
while (fgets (line, sizeof (line) - 1, f) != NULL)
145
p = line + strlen (line) - 1;
149
if (*line == '#') /* Comment line */
153
while (*parms && *parms != '=')
159
#if defined(__BEOS__) || defined(__HAIKU__)
160
if (strcmp (parms, "-lm") == 0)
166
if (strcmp (parms, "$GTKCFLAGS") == 0)
169
if (getenv ("GTK1") != NULL)
170
parms = "`gtk-config --cflags` -DGTK1_ONLY";
172
if (getenv ("GTK2") != NULL)
173
parms = "`pkg-config gtk+-2.0 --cflags`";
176
if (strcmp (parms, "$GTKLDFLAGS") == 0)
179
if (getenv ("GTK1") != NULL)
180
parms = "`gtk-config --libs`";
182
if (getenv ("GTK2") != NULL)
183
parms = "`pkg-config gtk+-2.0 --libs`";
186
if (strcmp (parms, "$DLOPENLDFLAGS") == 0)
190
if (getenv ("OGG_SUPPORT") != NULL)
195
if (strcmp (parms, "$OGGDEFINE") == 0)
198
if (getenv ("OGG_SUPPORT") != NULL)
199
parms = "-DOGG_SUPPORT";
202
if (strcmp (line, "project") == 0)
204
strcpy (conf->project_name, parms);
208
if (strcmp (line, "cflags") == 0)
210
strcpy (conf->cflags, parms);
214
if (strcmp (line, "ldflags") == 0)
216
strcpy (conf->ldflags, parms);
220
if (strcmp (line, "osflags") == 0)
223
strcat (conf->OSflags, " ");
224
strcat (conf->OSflags, parms);
228
if (strcmp (line, "bus") == 0)
230
strcpy (conf->bus, parms);
234
if (strcmp (line, "OS") == 0)
236
strcpy (conf->os_name, parms);
240
if (strcmp (line, "mode") == 0)
242
if (strcmp (parms, "user") == 0)
244
conf->mode = MD_USERLAND;
248
if (strcmp (parms, "sbin") == 0)
250
conf->mode = MD_SBIN;
254
if (strcmp (parms, "shlib") == 0)
256
conf->mode = MD_SHLIB;
260
if (strcmp (parms, "kernel") == 0)
262
conf->mode = MD_KERNEL;
266
if (strcmp (parms, "undefined") == 0)
268
conf->mode = MD_UNDEF;
272
if (strcmp (parms, "kernelmode") == 0)
274
conf->mode = MD_KERNEL_;
278
if (strcmp (parms, "module") == 0)
280
conf->mode = MD_MODULE_;
284
fprintf (stderr, "Bad mode %s\n", parms);
288
if (strcmp (line, "license") == 0)
290
if (strcmp (parms, "free") == 0)
291
conf->license = LIC_FREE;
292
if (strcmp (parms, "restricted") == 0)
293
conf->license = LIC_RESTRICTED;
297
if (strcmp (line, "depends") == 0)
300
sprintf (tmp, "HAVE_%s", parms);
301
if (getenv (tmp) == NULL)
304
("Directory depends on the %s package which is not available\n",
312
if (strcmp (line, "configcheck") == 0)
314
if (strcmp (parms, "VMIX") == 0)
316
if (strcmp(vmix_mode, "DISABLED")==0)
319
("Directory depends on the VMIX subsystem which is not enabled\n");
326
if (strcmp (parms, "MIDI") == 0) // Skip if MIDI is disabled
328
if (strcmp(config_midi, "DISABLED")==0)
331
("Directory depends on the MIDI subsystem which is not enabled\n");
338
if (strcmp (parms, "NO_MIDI") == 0) // Skip if MIDI is enabled
340
if (strcmp(config_midi, "DISABLED")!=0)
342
// printf ("Directory not compatible with MIDI subsystem (which is enabled)\n");
349
fprintf (stderr, "Unknown configcheck parameter '%s'\n", parms);
353
if (strcmp (line, "targetos") == 0)
356
if (strcmp (conf->system, parms) == 0)
361
if (strcmp (line, "forgetos") == 0)
363
if (strcmp (conf->system, parms) == 0)
368
if (strcmp (line, "targetcpu") == 0)
371
if (strcmp (parms, "any") == 0)
374
if (strcmp (conf->arch, parms) == 0)
379
if (strcmp (line, "forgetcpu") == 0)
381
if (strcmp (conf->arch, parms) == 0)
386
if (strcmp (line, "endian") == 0)
388
conf->check_endian = 1;
389
if (strcmp (conf->endianess, parms) == 0)
394
if (strcmp (line, "platform") == 0)
396
conf->check_platform = 1;
397
if (strcmp (conf->platform, parms) == 0)
398
conf->platform_ok = 1;
402
if (strcmp (line, "pm_support") == 0)
404
conf->power_manage=1;
407
if (strcmp (line, "suspend_resume") == 0)
409
conf->suspend_resume=1;
412
if (strcmp (line, "force_endian") == 0)
414
if (strcmp (parms, "BIG") == 0)
416
strcpy (conf->endianess, "BIG");
419
if (strcmp (parms, "LITTLE") == 0)
421
strcpy (conf->endianess, "LITTLE");
424
if (strcmp (parms, "UNKNOWN") == 0)
426
strcpy (conf->endianess, "UNKNOWN");
430
printf ("\t %s\n", line);
432
printf ("\t*** Unknown parameter ***\n");
440
if (conf->check_os && !conf->os_ok)
450
if (conf->check_cpu && !conf->cpu_ok)
455
if (conf->check_endian && !conf->endian_ok)
460
if (conf->check_platform && !conf->platform_ok)
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.
470
if (conf->mode == MD_MODULE && exact_architectures && !conf->check_cpu)
472
printf ("Ignoring %s - No CPU specified\n", comment);
480
#include "gen_driver_linux.inc"
483
#if defined(__FreeBSD__)
484
#include "gen_driver_freebsd.inc"
488
#include "gen_driver_solaris.inc"
491
#if defined(__SCO_VERSION__)
492
#include "gen_driver_sco.inc"
495
#if defined(__BEOS__) || defined(__HAIKU__)
496
#include "gen_driver_beos.inc"
500
is_cplusplus (char *fname)
502
while (*fname && *fname != '.')
505
if (strcmp (fname, ".cpp") == 0)
507
if (strcmp (fname, ".C") == 0)
514
cmpstringp (const void *p1, const void *p2)
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
522
* Make sure "lib" directories get compiles before any other
526
if (strcmp(*(char **) p1, "lib")==0)
529
if (strcmp(*(char **) p2, "lib")==0)
532
return strcmp (*(char **) p1, *(char **) p2);
536
scan_dir (char *path, char *name, char *topdir, conf_t * cfg, int level)
552
char *subdirs[MAX_SUBDIRS];
555
char *objects[MAX_OBJECTS], *obj_src[MAX_OBJECTS];
557
char *sources[MAX_OBJECTS];
558
char obj[128], *p, *suffix;
559
char *objdir = "OBJDIR";
560
int include_local_makefile = 0;
562
#define MAX_FILENAME 128
563
char *filenames[MAX_FILENAME];
566
char tmp_endian[100]="";
567
char autogen_sources[1024]="";
569
memcpy (&conf, cfg, sizeof (conf));
571
if (conf.mode == MD_MODULE_)
572
conf.mode = MD_MODULE;
574
if (conf.mode == MD_KERNEL_)
575
conf.mode = MD_KERNEL;
577
sprintf (tmp, "%s/.name", path);
578
if ((cf = fopen (tmp, "r")) != NULL)
582
if (fgets(tmp, sizeof(tmp)-1, cf)==NULL)
589
conf.purpose=strdup(tmp);
593
conf.purpose=strdup(name);
596
sprintf (tmp, "%s/.config", path);
597
if ((cf = fopen (tmp, "r")) != NULL)
599
if (!parse_config (cf, &conf, path))
601
/* Not compatible with this environment */
608
if (conf.mode == MD_MODULE && exact_architectures) /* .config required for this arch */
610
printf ("Ignoring %s - No CPU specified\n", path);
614
sprintf (tmp, "%s/.nativemake", path); /* Use the existing makefile */
615
if (stat (tmp, &st) != -1)
620
sprintf (cfg_name, "%s_cfg.c", name);
621
sprintf (cfg_header, "%s_cfg.h", name);
623
sprintf (tmp, "%s/Makefile.%s", path, conf.system);
626
sprintf (tmp, "%s/Makefile", path);
629
sprintf (tmp, "%s/.nomake", path);
630
if (stat (tmp, &st) != -1)
633
sprintf (tmp, "%s/.makefile", path);
634
if (stat (tmp, &st) != -1)
635
include_local_makefile = 1;
638
if (conf.mode == MD_USERLAND || conf.mode == MD_SBIN)
642
if (conf.mode == MD_KERNEL || conf.mode == MD_MODULE ||
643
conf.mode == MD_KERNEL_ || conf.mode == MD_MODULE_)
646
if (conf.mode == MD_MODULE)
647
driver_gen (name, &conf, cfg_name, cfg_header, path, topdir);
649
if ((dir = opendir (path)) == NULL)
652
fprintf(stderr, "scan_dir(%s): Opendir failed\n", path);
656
while ((de = readdir (dir)) != NULL)
658
if (de->d_name[0] == '.')
661
if (n_filenames >= MAX_FILENAME)
663
fprintf (stderr, "Too many files in directory %s\n", path);
667
filenames[n_filenames++] = strdup (de->d_name);
670
qsort (filenames, n_filenames, sizeof (char *), cmpstringp);
672
for (i = 0; i < n_filenames; i++)
674
sprintf (tmp, "%s/%s", path, filenames[i]);
675
if (stat (tmp, &st) == -1)
681
if (S_ISDIR (st.st_mode))
688
sprintf (top, "../%s", topdir);
690
if (scan_dir (tmp, filenames[i], top, &conf, level + 1))
692
if (ndirs >= MAX_SUBDIRS)
694
fprintf (stderr, "Too many subdirs in %s\n", path);
698
subdirs[ndirs++] = strdup (filenames[i]);
702
/* printf("%s/%s\n", path, filenames[i]); */
704
if (nobjects >= MAX_OBJECTS || nsources >= MAX_OBJECTS)
706
fprintf (stderr, "Too many objects in %s\n", path);
710
strcpy (obj, filenames[i]);
721
if (strcmp (suffix, ".c") == 0)
723
sources[nsources++] = strdup (obj);
724
if (strcmp (obj, cfg_name) == 0)
730
if (strcmp(suffix, ".PHc") == 0)
732
if (*autogen_sources != 0)
733
strcat(autogen_sources, " ");
735
strcat(autogen_sources, obj);
736
strcat(autogen_sources, ".c");
738
strcpy(suffix, ".c");
741
if (strcmp(suffix, ".PHh") == 0)
743
if (*autogen_sources != 0)
744
strcat(autogen_sources, " ");
746
strcat(autogen_sources, obj);
747
strcat(autogen_sources, ".h");
751
if (strcmp(suffix, ".PHinc") == 0)
753
if (*autogen_sources != 0)
754
strcat(autogen_sources, " ");
756
strcat(autogen_sources, obj);
757
strcat(autogen_sources, ".inc");
763
char source[256], target[256];
765
if (strcmp(suffix, ".PHc") == 0)
768
sprintf (source, "%s.PHc", obj);
769
sprintf (target, "%s/%s.c", path, obj);
771
if (symlink (source, target) == -1)
778
if (strcmp(suffix, ".PHh") == 0)
781
sprintf (source, "%s.PHh", obj);
782
sprintf (target, "%s/%s.h", path, obj);
784
if (symlink (source, target) == -1)
791
if (strcmp(suffix, ".PHinc") == 0)
794
sprintf (source, "%s.PHinc", obj);
795
sprintf (target, "%s/%s.inc", path, obj);
797
printf("Symlink %s -> %s\n", source, target);
798
if (symlink (source, target) == -1)
806
if (strcmp (suffix, ".c") == 0 ||
807
strcmp (suffix, ".C") == 0 || strcmp (suffix, ".cpp") == 0)
809
obj_src[nobjects] = strdup (obj);
812
objects[nobjects++] = strdup (obj);
817
sprintf (tmp, "%s/.depend", path);
819
sprintf (tmp, "touch %s/.depend", path);
822
if (level == 1 && *this_os && !useronly)
824
subdirs[ndirs++] = strdup (this_os);
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)
833
# if !defined(linux) && !defined(__FreeBSD__)
834
sprintf (tmp, "%s_cfg.c", name);
835
sources[nsources++] = strdup (tmp);
837
obj_src[nobjects] = strdup (tmp);
838
sprintf (tmp, "%s_cfg.o", name);
839
objects[nobjects++] = strdup (tmp);
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);
850
if (do_cleanup || (ndirs == 0 && nobjects == 0))
856
sprintf (tmp, "%s/Makefile.php", path);
858
sprintf (tmp, "%s/Makefile", path);
861
if ((f = fopen (tmp, "w")) == NULL)
867
if (include_local_makefile)
870
fprintf (f, "include .makefile\n");
874
fprintf (f, "all:\n");
876
"\t$(MAKE) $(BUILDFLAGS) BUILDFLAGS=\"$(BUILDFLAGS)\" -f Makefile.`uname -s` all\n\n");
878
fprintf (f, "config:\n");
880
"\t$(MAKE) $(BUILDFLAGS) BUILDFLAGS=\"$(BUILDFLAGS)\" -f make.defs config\n\n");
882
fprintf (f, "purge:\n");
884
"\t$(MAKE) $(BUILDFLAGS) BUILDFLAGS=\"$(BUILDFLAGS)\" -f make.defs purge\n\n");
886
fprintf (f, "dirs:\n");
888
"\t$(MAKE) $(BUILDFLAGS) BUILDFLAGS=\"$(BUILDFLAGS)\" -f Makefile.`uname -s` dirs\n\n");
890
fprintf (f, "clean:\n");
892
"\t$(MAKE) $(BUILDFLAGS) BUILDFLAGS=\"$(BUILDFLAGS)\" -f Makefile.`uname -s` clean\n\n");
894
fprintf (f, "lint:\n");
896
"\t$(MAKE) $(BUILDFLAGS) BUILDFLAGS=\"$(BUILDFLAGS)\" -f Makefile.`uname -s` lint\n\n");
898
fprintf (f, "dep:\n");
900
"\t$(MAKE) $(BUILDFLAGS) BUILDFLAGS=\"$(BUILDFLAGS)\" -f Makefile.`uname -s` dep\n\n");
904
sprintf (tmp, "%s/Makefile.%s", path, conf.system);
906
if ((f = fopen (tmp, "w")) == NULL)
912
fprintf (f, "# Makefile for %s module %s\n\n", conf.project_name, name);
915
fprintf (f, "<?php require getenv(\"PHPMAKE_LIBPATH\") . \"library.php\"; phpmake_makefile_top_rules(); ?>\n");
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);
923
vxworks_genheader (f, path);
926
#if defined(__SCO_VERSION__)
927
if (*conf.cflags != 0)
928
fprintf (f, "CFLAGS=%s\n", conf.cflags);
930
if (*conf.ldflags != 0)
931
fprintf (f, "LDFLAGS=%s\n", conf.ldflags);
933
if (strcmp(conf.endianess, "UNKNOWN") != 0)
934
sprintf (tmp_endian, " -DOSS_%s_ENDIAN", conf.endianess);
936
fprintf (f, "OSFLAGS=%s%s\n", conf.OSflags, tmp_endian);
938
fprintf (f, "OS=%s\n", conf.system);
939
fprintf (f, "ARCH=%s\n", conf.arch);
942
fprintf (f, "TOPDIR=.\n");
944
fprintf (f, "TOPDIR=%s\n", topdir);
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);
955
fprintf (f, "THISOS=%s\n", this_os);
958
fprintf (f, "CFLAGS+=-D__USE_PHPMAKE__\n");
960
if (conf.mode == MD_KERNEL || conf.mode == MD_MODULE)
962
#if defined(__SCO_VERSION__)
963
fprintf (f, "CFLAGS=-O -D_KERNEL -D_DDI=8\n");
965
fprintf (f, "CFLAGS += -D_KERNEL\n");
967
#ifdef HAVE_KERNEL_FLAGS
968
add_kernel_flags (f);
971
#ifndef __SCO_VERSION__
974
fprintf (f, "CFLAGS+=-O\n");
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);
984
if (conf.mode != MD_KERNEL)
990
fprintf (f, "INCLUDES=");
991
for (i = 0; i < nincludes; i++)
995
if (includes[i][0] == '/')
996
fprintf (f, "%s", includes[i]);
998
fprintf (f, "-I$(TOPDIR)/%s", includes[i]);
1009
fprintf (f, "<?php\n");
1010
fprintf (f, "\t$subdirs=array(");
1011
for (i = 0; i < ndirs; i++)
1015
fprintf (f, "\"%s\"", subdirs[i]);
1017
fprintf (f, ");\n");
1018
fprintf (f, "phpmake_print_subdirs($subdirs);\n");
1019
fprintf (f, "?>\n");
1023
fprintf (f, "SUBDIRS=");
1024
for (i = 0; i < ndirs; i++)
1028
fprintf (f, "%s", subdirs[i]);
1038
fprintf (f, "OBJECTS=");
1040
for (i = 0; i < nobjects; i++)
1044
fprintf (f, "$(%s)/%s", objdir, objects[i]);
1050
if (conf.mode == MD_MODULE)
1052
fprintf (f, "TARGETS=$(MODDIR)/%s $(MODDIR)/%s.o\n", name, name);
1053
fprintf (f, "DEPDIR=$(TMPDIR)\n");
1055
else if ((conf.mode == MD_USERLAND) && nobjects > 0)
1057
fprintf (f, "TARGETS=$(BINDIR)/%s\n", name);
1058
fprintf (f, "DEPDIR=$(BINDIR)/\n");
1060
else if ((conf.mode == MD_SBIN) && nobjects > 0)
1062
fprintf (f, "TARGETS=$(SBINDIR)/%s\n", name);
1063
fprintf (f, "DEPDIR=$(SBINDIR)/\n");
1067
fprintf (f, "TARGETS=%s\n", name);
1068
fprintf (f, "DEPDIR=\n");
1075
fprintf (f, "CSOURCES=");
1077
for (i = 0; i < nsources; i++)
1081
fprintf (f, "%s", sources[i]);
1087
if (*autogen_sources != 0)
1088
fprintf (f, "AUTOGEN_SOURCES=%s\n", autogen_sources);
1092
if (include_local_makefile)
1094
fprintf (f, "include .makefile\n");
1099
fprintf (f, "<?php phpmake_makefile_rules(); ?>\n");
1101
* Create the default target
1103
fprintf (f, "all: ");
1105
if (conf.mode == MD_USERLAND && nsources > 0)
1107
fprintf (f, "$(TARGETS) ");
1109
else if (conf.mode == MD_MODULE)
1112
fprintf (f, "$(MODDIR)/%s.o ", name);
1114
else if (conf.mode == MD_SHLIB)
1116
fprintf (f, "$(LIBDIR)/%s.so ", name);
1118
else if (conf.mode != MD_KERNEL)
1122
if (conf.mode == MD_SBIN)
1123
fprintf (f, "$(SBINDIR)/%s ", name);
1125
fprintf (f, "$(BINDIR)/%s ", name);
1131
fprintf (f, "$(AUTOGEN_SOURCES) objects ");
1135
fprintf (f, "subdirs ");
1140
"\t-sh $(THISOS)/build.sh \"$(ARCH)\" \"$(INCLUDES)\" \"$(CFLAGS)\"\n");
1145
* Create the lint target
1147
fprintf (f, "lint: ");
1149
fprintf (f, "lint_sources ");
1151
fprintf (f, "lint_subdirs ");
1152
fprintf (f, "\n\n");
1155
* Create the dep target
1157
fprintf (f, "dep: ");
1159
fprintf (f, "$(AUTOGEN_SOURCES) dep_local ");
1161
fprintf (f, "dep_subdirs ");
1162
fprintf (f, "\n\n");
1164
fprintf (f, "include $(TOPDIR)/make.defs\n");
1167
if (conf.mode == MD_USERLAND)
1169
fprintf (f, "%s:\t$(BINDIR)/%s\n\n", name, name);
1171
fprintf (f, "$(BINDIR)/%s:\t$(OBJECTS)\n", name);
1173
"\t$(CC) $(CFLAGS) $(LIBRARIES) $(LDFLAGS) -s -o $(BINDIR)/%s $(OBJECTS) %s\n",
1174
name, extra_libraries);
1175
fprintf (f, "\n\n");
1178
if (conf.mode == MD_SHLIB)
1180
fprintf (f, "%s.so:\t$(LIBDIR)/%s.so\n\n", name, name);
1182
fprintf (f, "$(LIBDIR)/%s.so:\t$(OBJECTS)\n", name);
1184
/* gcc -shared works much better than ld on Linux */
1186
"\t$(CC) $(LDFLAGS) %s -o $(LIBDIR)/%s.so $(OBJECTS)\n",
1187
shlib_cflags, name);
1190
"\t$(LD) $(LDFLAGS) %s -o $(LIBDIR)/%s.so $(OBJECTS)\n",
1191
shlib_ldflags, name);
1193
fprintf (f, "\n\n");
1196
if (conf.mode == MD_SBIN)
1198
fprintf (f, "%s:\t$(SBINDIR)/%s\n\n", name, name);
1200
fprintf (f, "$(SBINDIR)/%s:\t$(OBJECTS)\n", name);
1202
"\t$(CC) $(CFLAGS) $(LIBRARIES) $(LDFLAGS) -s -o $(SBINDIR)/%s $(OBJECTS) %s\n",
1203
name, extra_libraries);
1204
fprintf (f, "\n\n");
1207
if (conf.mode == MD_MODULE)
1209
fprintf (f, "$(MODDIR)/%s.o:\t$(OBJECTS)\n", name);
1210
fprintf (f, "\t$(LD) $(LDARCH) -r -o $(MODDIR)/%s.o $(OBJECTS)\n",
1212
fprintf (f, "\n\n");
1219
for (i = 0; i < nobjects; i++)
1221
fprintf (f, "$(%s)/%s:\t%s\n", objdir, objects[i], obj_src[i]);
1223
if (is_cplusplus (obj_src[i]))
1225
"\t$(CPLUSPLUS) -c $(CFLAGS) $(OSFLAGS) $(INCLUDES) %s -o $(%s)/%s\n",
1226
obj_src[i], objdir, objects[i]);
1229
"\t$(CC) -c $(CFLAGS) $(OSFLAGS) $(LIBRARIES) $(INCLUDES) %s -o $(%s)/%s\n",
1230
obj_src[i], objdir, objects[i]);
1235
fprintf (f, "clean: clean_local");
1237
fprintf (f, " clean_subdirs");
1238
fprintf (f, "\n\n");
1244
static int already_configured = 0;
1247
produce_output (conf_t * conf)
1249
if (already_configured)
1252
scan_dir (".", "main", NULL, conf, 1);
1253
scan_dir (this_os, "main", "../../..", conf, 3);
1255
symlink (this_os, "targetos");
1257
already_configured = 1;
1261
check_endianess (conf_t * conf)
1263
unsigned char probe[4] = { 1, 2, 3, 4 };
1265
if ((*(unsigned int *) &probe) == 0x01020304)
1267
strcpy (conf->endianess, "BIG");
1271
strcpy (conf->endianess, "LITTLE");
1276
produce_local_config_h (conf_t * conf)
1279
* Produce local_config.h
1281
int grc_min=3, grc_max=3; // GRC3 min/max quality settings
1287
if ((f=fopen ("kernel/framework/include/local_config.h", "w"))==NULL)
1289
perror ("kernel/framework/include/local_config.h");
1293
fprintf (f, "/*\n");
1294
fprintf (f, " * Automatically generated by the configure script (srcconf.c) - Do not edit.\n");
1295
fprintf (f, "*/\n");
1298
* GRC3 sample rate converter min/max quality settings
1300
if ((p=getenv("GRC_MIN_QUALITY"))!= NULL)
1302
if (sscanf(p, "%d", &q) != 1)
1304
fprintf (stderr, "Bad GRC_MIN_QUALITY '%s'\n", p);
1305
exit (EXIT_FAILURE);
1308
if (q >= 0 && q <= 6)
1312
if ((p=getenv("GRC_MAX_QUALITY"))!= NULL)
1314
if (sscanf(p, "%d", &q) != 1)
1316
fprintf (stderr, "Bad GRC_MAX_QUALITY '%s'\n", p);
1317
exit (EXIT_FAILURE);
1320
if (q >= 0 && q <= 6)
1324
if (grc_max < grc_min)
1325
grc_max = grc_min = 3;
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);
1331
* Generate VMIX configuration
1334
if (strcmp (vmix_mode, "DISABLED") == 0)
1336
fprintf (f, "#undef CONFIG_OSS_VMIX\n");
1340
fprintf (f, "#define CONFIG_OSS_VMIX\n");
1342
if (strcmp (vmix_mode, "FLOAT") == 0)
1343
fprintf (f, "#define CONFIG_OSS_VMIX_FLOAT\n");
1345
fprintf (f, "#undef CONFIG_OSS_VMIX_FLOAT\n");
1349
* Generate MIDI configuration
1352
if (strcmp (config_midi, "DISABLED") == 0)
1353
fprintf (f, "#undef CONFIG_OSS_MIDI\n");
1355
fprintf (f, "#define CONFIG_OSS_MIDI\n");
1358
* Enable DO_TIMINGS code
1361
if (getenv("DO_TIMINGS") != NULL)
1362
fprintf (f, "#define DO_TIMINGS\n");
1368
produce_errno_h(void)
1373
* Generate oss_errno.h that contains all the errno.h codes used by OSS
1374
* but defined as negative numbers.
1377
if ((f=fopen ("kernel/framework/include/oss_errno.h", "w"))==NULL)
1379
perror ("kernel/framework/include/oss_errno.h");
1382
#define GEN_ERRNO(e) \
1383
fprintf (f, "#define OSS_"#e"\t\t%d\n", (e<=0) ? e : -(e));
1385
fprintf (f, "#ifndef OSS_ERRNO_H\n");
1386
fprintf (f, "#define OSS_ERRNO_H\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");
1398
#ifndef EBADE /* Not in FreeBSD, Haiku */
1399
#define EBADE EINVAL
1402
#ifndef EIDRM /* Not in POSIX, but is in SuS */
1403
#define EIDRM EFAULT
1406
#ifndef ENOTSUP /* Not in Haiku */
1407
#define ENOTSUP ENOSYS
1411
#define EFAULT ENOTSUP
1419
GEN_ERRNO(ECONNRESET);
1436
GEN_ERRNO(EWOULDBLOCK);
1439
fprintf (f, "#endif\n");
1444
check_system (conf_t * conf)
1449
if (uname (&un) == -1)
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);
1467
check_sysdep (conf, &un);
1470
# if defined(__SCO_VERSION__)
1471
shlib_ldflags = "-G -lsocket -lnsl";
1474
if (strcmp (un.machine, "i386") == 0 ||
1475
strcmp (un.machine, "i486") == 0 ||
1476
strcmp (un.machine, "i586") == 0 || strcmp (un.machine, "i686") == 0)
1478
strcpy (conf->platform, "i86pc");
1482
fprintf (stderr, "Cannot determine the platform for %s\n", un.machine);
1487
if (*conf->platform == 0)
1489
fprintf (stderr, "Panic: No platform\n");
1493
check_endianess (conf);
1496
* Check virtual mixer configuration (as set by the configure script).
1499
if ((p=getenv("VMIX_MODE"))!=NULL)
1501
vmix_mode = strdup(p);
1505
* Check MIDI enabled/disabled status
1508
if ((p=getenv("CONFIG_MIDI"))!=NULL)
1510
config_midi = strdup(p);
1513
produce_local_config_h (conf);
1517
main (int argc, char *argv[])
1520
char tmp[256], *env;
1524
if (getenv("USE_PHPMAKE") != NULL)
1525
if (stat("phpmake/library.php", &st) != -1)
1528
for (i = 1; i < argc; i++)
1529
if (argv[i][0] == '-')
1533
strcpy (arch, &argv[i][2]);
1534
printf ("Arch=%s\n", arch);
1538
break; /* Compile only the kernel mode parts */
1541
break; /* Compile only the user land utilities */
1544
if (getenv("NO_WARNING_CHECKS")!=NULL)
1545
do_warning_checks = 0;
1547
hostcc = getenv ("HOSTCC");
1548
targetcc = getenv ("CC");
1549
if (hostcc == NULL) hostcc = DEFAULT_CC;
1550
if (targetcc == NULL) targetcc = DEFAULT_CC;
1552
#if defined(linux) || defined(__FreeBSD__) || defined(__SCO_VERSION__)
1553
mkdir ("target", 0755);
1554
mkdir ("target/build", 0755);
1555
system ("touch target/build/.nomake");
1558
if (getenv ("SOL9") != NULL)
1559
system ("touch kernel/drv/oss_usb/.nomake");
1561
check_system (&conf);
1564
* Check if setup/$CROSSCOMPILE.conf exists and load the settings in it.
1566
if ((env=getenv("CROSSCOMPILE"))!=NULL)
1570
sprintf (tmp, "setup/%s.conf", env);
1571
if ((cf = fopen (tmp, "r")) != NULL)
1573
parse_config (cf, &conf, tmp);
1579
produce_output (&conf);