source: roaraudio/roarclients/roar-config.c @ 5532:af3bb470fec0

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

added missing \n in error message

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