source: roaraudio/roarclients/roar-config.c @ 5672:ac5f50ae33f2

Last change on this file since 5672:ac5f50ae33f2 was 5672:ac5f50ae33f2, checked in by phi, 12 years ago

Improved roar-config.

File size: 4.9 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
55const struct path {
56 const char * name;
57 const char * path;
58} paths[] = {
59 {"prefix-plugins", ROAR_PREFIX_PLUGINS},
60 {"<<<END>>>", NULL}
61};
62
63void print_path(const char * name) {
64 size_t i;
65
66 for (i = 0; i < (sizeof(paths)/sizeof(*paths)); i++) {
67  if ( !strcasecmp(name, paths[i].name) ) {
68   printf("%s\n", paths[i].path);
69   return;
70  }
71 }
72}
73
74void usage (void) {
75 printf("Usage: roar-config [--version] [--libs] [--cflags] [lib]\n");
76
77 printf("\nOptions:\n\n");
78
79 printf(
80        "  --version          - Show version of library\n"
81        "  --path NAME        - Print path NAME\n"
82        "  --libs             - Show linker flags (-lxxx) needed to link library\n"
83        "  --cflags           - Show compiler flags needed to link library\n"
84        "  --output-pc        - Output PC format\n"
85        "  --output-normal    - Output PC format\n"
86       );
87
88}
89
90#define _strcat(buf, n) strncat(buf, n, sizeof(buf)-1-strlen(buf))
91
92int main (int argc, char * argv[]) {
93 enum { NORMAL, PC } mode = NORMAL;
94 int i, h;
95 int cflags = 0;
96 int libs   = 0;
97 char buf[1024] = {0};
98
99 if ( argc == 1 ) {
100  usage();
101  return 0;
102 }
103
104 for (i = 1; i < argc; i++) {
105  if ( !strcmp(argv[i], "--version") ) {
106   printf("%s\n", COMMON_VERSION);
107  } else if ( !strcmp(argv[i], "--help") || !strcmp(argv[i], "-h") ) {
108   usage();
109   return 0;
110  } else if ( !strcmp(argv[i], "--path") ) {
111   print_path(argv[++i]);
112  } else if ( !strcmp(argv[i], "--libs") ) {
113   libs   = 1;
114  } else if ( !strcmp(argv[i], "--cflags") ) {
115   cflags = 1;
116  } else if ( !strcmp(argv[i], "--output-normal") ) {
117   mode = NORMAL;
118  } else if ( !strcmp(argv[i], "--output-pc") ) {
119   mode = PC;
120  } else if ( flags_ptr == NULL ) {
121   if ( !strncmp(argv[i], "lib", 3) )
122    argv[i] += 3;
123
124   for (h = 0; flags[h].name != NULL; h++) {
125    if ( !strcasecmp(argv[i], flags[h].name) )
126     flags_ptr = &(flags[h]);
127   }
128
129   if ( flags_ptr == NULL ) {
130    fprintf(stderr, "Unknown lib: %s\n", argv[i]);
131    return 2;
132   }
133  } else {
134   fprintf(stderr, "Unknown option: %s\n", argv[i]);
135   usage();
136   return 1;
137  }
138 }
139
140 if ( flags_ptr == NULL )
141  flags_ptr = &(flags[0]);
142
143 switch (mode) {
144  case NORMAL:
145    if ( cflags || libs ) {
146     if ( cflags )
147      _strcat(buf, flags_ptr->cflags);
148
149     if ( libs )
150      _strcat(buf, flags_ptr->libs);
151
152     puts(buf);
153    }
154   break;
155  case PC:
156    printf(
157           "prefix=%s\n"
158           "exec_prefix=${prefix}\n"
159           "libdir=%s\n"
160           "includedir=%s\n",
161           PREFIX, PREFIX_LIB, PREFIX_INC
162          );
163    printf("\n");
164    printf(
165           "Name: lib%s\n"
166           "Description: lib%s is part of RoarAudio Sound System\n"
167           "Version: %s\n"
168//           "Requires: libroar\n"
169           "Conflicts:\n"
170           "Libs: -L${libdir} %s\n"
171           "Cflags: -I${includedir} %s\n",
172           flags_ptr->name,
173           flags_ptr->name,
174           COMMON_VERSION,
175           flags_ptr->libs,
176           flags_ptr->cflags
177          );
178   break;
179 }
180
181 return 0;
182}
183
184//ll
Note: See TracBrowser for help on using the repository browser.