source: roaraudio/roarclients/roar-config.c @ 5747:17e1c9dacc8f

Last change on this file since 5747:17e1c9dacc8f was 5747:17e1c9dacc8f, checked in by phi, 11 years ago

Provide a more common interface for path config.

File size: 5.4 KB
Line 
1//roar-config.c:
2
3/*
4 *      Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2008-2012
5 *
6 *  This file is part of roarclients a part of RoarAudio,
7 *  a cross-platform sound system for both, home and professional use.
8 *  See README for details.
9 *
10 *  This file is free software; you can redistribute it and/or modify
11 *  it under the terms of the GNU General Public License version 3
12 *  as published by the Free Software Foundation.
13 *
14 *  RoarAudio is distributed in the hope that it will be useful,
15 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 *  GNU General Public License for more details.
18 *
19 *  You should have received a copy of the GNU General Public License
20 *  along with this software; see the file COPYING.  If not, write to
21 *  the Free Software Foundation, 51 Franklin Street, Fifth Floor,
22 *  Boston, MA 02110-1301, USA.
23 *
24 */
25
26#include <roaraudio.h>
27
28const struct {
29 const char * name;
30 const char * cflags;
31 const char * libs;
32} flags[] = {
33 // native/own libs:
34 {"roar",      ROAR_CFLAGS, ROAR_LIBS        }, // NOTE: libroar *MUST* be the first entry
35 {"roardsp",   ROAR_CFLAGS, ROAR_LIBS_DSP    },
36 {"roarmidi",  ROAR_CFLAGS, ROAR_LIBS_MIDI   },
37 {"roarlight", ROAR_CFLAGS, ROAR_LIBS_LIGHT  },
38 {"roareio",   ROAR_CFLAGS, ROAR_LIBS_EIO    },
39 // comp libs:
40 {"roaresd",   ROAR_CFLAGS, ROAR_LIBS_C_ESD  },
41 {"esd",       ROAR_CFLAGS, ROAR_LIBS_C_ESD  },
42 {"roarartsc", ROAR_CFLAGS, ROAR_LIBS_C_ARTSC},
43 {"artsc",     ROAR_CFLAGS, ROAR_LIBS_C_ARTSC},
44 {"roarpulse", ROAR_CFLAGS, ROAR_LIBS_C_PULSE},
45 {"pulse",     ROAR_CFLAGS, ROAR_LIBS_C_PULSE},
46 {"roarpulse-simple", ROAR_CFLAGS, ROAR_LIBS_C_PULSE_SIMPLE},
47 {"pulse-simple",     ROAR_CFLAGS, ROAR_LIBS_C_PULSE_SIMPLE},
48 {"roarsndio", ROAR_CFLAGS, ROAR_LIBS_C_SNDIO},
49 {"sndio",     ROAR_CFLAGS, ROAR_LIBS_C_SNDIO},
50 {"roaryiff",  ROAR_CFLAGS, ROAR_LIBS_C_YIFF },
51 {"Y2",        ROAR_CFLAGS, ROAR_LIBS_C_YIFF },
52 {NULL, NULL, NULL}
53}, * flags_ptr = NULL;
54
55void print_path(const char * name, int null_as_universal, const char * product, const char * provider) {
56 char * path = roar_libroar_get_path(name, null_as_universal, product, provider);
57 if ( path == NULL )
58  return;
59 printf("%s\n", path);
60 roar_mm_free(path);
61}
62
63void usage (void) {
64 printf("Usage: roar-config [--version] [--libs] [--cflags] [lib]\n");
65
66 printf("\nOptions:\n\n");
67
68 printf(
69        "  --version           - Show version of library\n"
70        "  --path NAME         - Print path NAME\n"
71        "  --product PRODUCT   - Product string for --path\n"
72        "  --provider PROVIDER - Provider string for --path\n"
73        "  --universal         - Use universal path for --path\n"
74        "  --libs              - Show linker flags (-lxxx) needed to link library\n"
75        "  --cflags            - Show compiler flags needed to link library\n"
76        "  --output-pc         - Output PC format\n"
77        "  --output-normal     - Output PC format\n"
78       );
79
80}
81
82#define _strcat(buf, n) strncat(buf, n, sizeof(buf)-1-strlen(buf))
83
84int main (int argc, char * argv[]) {
85 enum { NORMAL, PC } mode = NORMAL;
86 int null_as_universal = 0;
87 const char * product = NULL;
88 const char * provider = NULL;
89 int i, h;
90 int cflags = 0;
91 int libs   = 0;
92 char buf[1024] = {0};
93
94 if ( argc == 1 ) {
95  usage();
96  return 0;
97 }
98
99 for (i = 1; i < argc; i++) {
100  if ( !strcmp(argv[i], "--version") ) {
101   printf("%s\n", COMMON_VERSION);
102  } else if ( !strcmp(argv[i], "--help") || !strcmp(argv[i], "-h") ) {
103   usage();
104   return 0;
105  } else if ( !strcmp(argv[i], "--product") ) {
106   product = argv[++i];
107  } else if ( !strcmp(argv[i], "--provider") ) {
108   provider = argv[++i];
109  } else if ( !strcmp(argv[i], "--universal") ) {
110   null_as_universal = 1;
111  } else if ( !strcmp(argv[i], "--path") ) {
112   print_path(argv[++i], null_as_universal, product, provider);
113  } else if ( !strcmp(argv[i], "--libs") ) {
114   libs   = 1;
115  } else if ( !strcmp(argv[i], "--cflags") ) {
116   cflags = 1;
117  } else if ( !strcmp(argv[i], "--output-normal") ) {
118   mode = NORMAL;
119  } else if ( !strcmp(argv[i], "--output-pc") ) {
120   mode = PC;
121  } else if ( flags_ptr == NULL ) {
122   if ( !strncmp(argv[i], "lib", 3) )
123    argv[i] += 3;
124
125   for (h = 0; flags[h].name != NULL; h++) {
126    if ( !strcasecmp(argv[i], flags[h].name) )
127     flags_ptr = &(flags[h]);
128   }
129
130   if ( flags_ptr == NULL ) {
131    fprintf(stderr, "Unknown lib: %s\n", argv[i]);
132    return 2;
133   }
134  } else {
135   fprintf(stderr, "Unknown option: %s\n", argv[i]);
136   usage();
137   return 1;
138  }
139 }
140
141 if ( flags_ptr == NULL )
142  flags_ptr = &(flags[0]);
143
144 switch (mode) {
145  case NORMAL:
146    if ( cflags || libs ) {
147     if ( cflags )
148      _strcat(buf, flags_ptr->cflags);
149
150     if ( libs )
151      _strcat(buf, flags_ptr->libs);
152
153     puts(buf);
154    }
155   break;
156  case PC:
157    printf(
158           "prefix=%s\n"
159           "exec_prefix=${prefix}\n"
160           "libdir=%s\n"
161           "includedir=%s\n",
162           PREFIX, PREFIX_LIB, PREFIX_INC
163          );
164    printf("\n");
165    printf(
166           "Name: lib%s\n"
167           "Description: lib%s is part of RoarAudio Sound System\n"
168           "Version: %s\n"
169//           "Requires: libroar\n"
170           "Conflicts:\n"
171           "Libs: -L${libdir} %s\n"
172           "Cflags: -I${includedir} %s\n",
173           flags_ptr->name,
174           flags_ptr->name,
175           COMMON_VERSION,
176           flags_ptr->libs,
177           flags_ptr->cflags
178          );
179   break;
180 }
181
182 return 0;
183}
184
185//ll
Note: See TracBrowser for help on using the repository browser.