[143] | 1 | //roar-config.c: |
---|
| 2 | |
---|
[669] | 3 | /* |
---|
[5381] | 4 | * Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2008-2012 |
---|
[669] | 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 |
---|
[3517] | 21 | * the Free Software Foundation, 51 Franklin Street, Fifth Floor, |
---|
| 22 | * Boston, MA 02110-1301, USA. |
---|
[669] | 23 | * |
---|
| 24 | */ |
---|
| 25 | |
---|
[144] | 26 | #include <roaraudio.h> |
---|
| 27 | |
---|
[5672] | 28 | const struct { |
---|
| 29 | const char * name; |
---|
| 30 | const char * cflags; |
---|
| 31 | const char * libs; |
---|
[2025] | 32 | } flags[] = { |
---|
[2875] | 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}, |
---|
[3826] | 46 | {"roarpulse-simple", ROAR_CFLAGS, ROAR_LIBS_C_PULSE_SIMPLE}, |
---|
| 47 | {"pulse-simple", ROAR_CFLAGS, ROAR_LIBS_C_PULSE_SIMPLE}, |
---|
[2875] | 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 }, |
---|
[2025] | 52 | {NULL, NULL, NULL} |
---|
| 53 | }, * flags_ptr = NULL; |
---|
| 54 | |
---|
[5747] | 55 | void 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); |
---|
[5672] | 61 | } |
---|
| 62 | |
---|
[3093] | 63 | void usage (void) { |
---|
[5748] | 64 | printf("Usage: roar-config --version\n" |
---|
| 65 | " roar-config [{--output-pc|--output-normal}] [--libs] [--cflags] [LIB]\n" |
---|
| 66 | " roar-config [--product PRODUCT] [--provider PROVIDER] [--universal] --path PATH\n"); |
---|
[3093] | 67 | |
---|
| 68 | printf("\nOptions:\n\n"); |
---|
| 69 | |
---|
| 70 | printf( |
---|
[5747] | 71 | " --version - Show version of library\n" |
---|
| 72 | " --path NAME - Print path NAME\n" |
---|
| 73 | " --product PRODUCT - Product string for --path\n" |
---|
| 74 | " --provider PROVIDER - Provider string for --path\n" |
---|
| 75 | " --universal - Use universal path for --path\n" |
---|
| 76 | " --libs - Show linker flags (-lxxx) needed to link library\n" |
---|
| 77 | " --cflags - Show compiler flags needed to link library\n" |
---|
| 78 | " --output-pc - Output PC format\n" |
---|
[5748] | 79 | " --output-normal - Output in \"classical\" format\n" |
---|
[3093] | 80 | ); |
---|
| 81 | |
---|
| 82 | } |
---|
| 83 | |
---|
[4885] | 84 | #define _strcat(buf, n) strncat(buf, n, sizeof(buf)-1-strlen(buf)) |
---|
| 85 | |
---|
[143] | 86 | int main (int argc, char * argv[]) { |
---|
[3827] | 87 | enum { NORMAL, PC } mode = NORMAL; |
---|
[5747] | 88 | int null_as_universal = 0; |
---|
| 89 | const char * product = NULL; |
---|
| 90 | const char * provider = NULL; |
---|
[2025] | 91 | int i, h; |
---|
| 92 | int cflags = 0; |
---|
| 93 | int libs = 0; |
---|
| 94 | char buf[1024] = {0}; |
---|
[144] | 95 | |
---|
| 96 | if ( argc == 1 ) { |
---|
[3093] | 97 | usage(); |
---|
[144] | 98 | return 0; |
---|
| 99 | } |
---|
| 100 | |
---|
| 101 | for (i = 1; i < argc; i++) { |
---|
| 102 | if ( !strcmp(argv[i], "--version") ) { |
---|
[4650] | 103 | printf("%s\n", COMMON_VERSION); |
---|
[3093] | 104 | } else if ( !strcmp(argv[i], "--help") || !strcmp(argv[i], "-h") ) { |
---|
| 105 | usage(); |
---|
| 106 | return 0; |
---|
[5747] | 107 | } else if ( !strcmp(argv[i], "--product") ) { |
---|
| 108 | product = argv[++i]; |
---|
| 109 | } else if ( !strcmp(argv[i], "--provider") ) { |
---|
| 110 | provider = argv[++i]; |
---|
| 111 | } else if ( !strcmp(argv[i], "--universal") ) { |
---|
| 112 | null_as_universal = 1; |
---|
[5672] | 113 | } else if ( !strcmp(argv[i], "--path") ) { |
---|
[5747] | 114 | print_path(argv[++i], null_as_universal, product, provider); |
---|
[144] | 115 | } else if ( !strcmp(argv[i], "--libs") ) { |
---|
[2025] | 116 | libs = 1; |
---|
[144] | 117 | } else if ( !strcmp(argv[i], "--cflags") ) { |
---|
[2025] | 118 | cflags = 1; |
---|
[3827] | 119 | } else if ( !strcmp(argv[i], "--output-normal") ) { |
---|
| 120 | mode = NORMAL; |
---|
| 121 | } else if ( !strcmp(argv[i], "--output-pc") ) { |
---|
| 122 | mode = PC; |
---|
[2025] | 123 | } else if ( flags_ptr == NULL ) { |
---|
[2063] | 124 | if ( !strncmp(argv[i], "lib", 3) ) |
---|
| 125 | argv[i] += 3; |
---|
| 126 | |
---|
[2025] | 127 | for (h = 0; flags[h].name != NULL; h++) { |
---|
| 128 | if ( !strcasecmp(argv[i], flags[h].name) ) |
---|
| 129 | flags_ptr = &(flags[h]); |
---|
| 130 | } |
---|
| 131 | |
---|
| 132 | if ( flags_ptr == NULL ) { |
---|
[5532] | 133 | fprintf(stderr, "Unknown lib: %s\n", argv[i]); |
---|
[2025] | 134 | return 2; |
---|
| 135 | } |
---|
[144] | 136 | } else { |
---|
| 137 | fprintf(stderr, "Unknown option: %s\n", argv[i]); |
---|
[3093] | 138 | usage(); |
---|
[144] | 139 | return 1; |
---|
| 140 | } |
---|
| 141 | } |
---|
| 142 | |
---|
[2025] | 143 | if ( flags_ptr == NULL ) |
---|
| 144 | flags_ptr = &(flags[0]); |
---|
| 145 | |
---|
[3827] | 146 | switch (mode) { |
---|
| 147 | case NORMAL: |
---|
[4725] | 148 | if ( cflags || libs ) { |
---|
| 149 | if ( cflags ) |
---|
[4885] | 150 | _strcat(buf, flags_ptr->cflags); |
---|
[3827] | 151 | |
---|
[4725] | 152 | if ( libs ) |
---|
[4885] | 153 | _strcat(buf, flags_ptr->libs); |
---|
[2025] | 154 | |
---|
[4725] | 155 | puts(buf); |
---|
| 156 | } |
---|
[3827] | 157 | break; |
---|
| 158 | case PC: |
---|
| 159 | printf( |
---|
| 160 | "prefix=%s\n" |
---|
| 161 | "exec_prefix=${prefix}\n" |
---|
| 162 | "libdir=%s\n" |
---|
| 163 | "includedir=%s\n", |
---|
| 164 | PREFIX, PREFIX_LIB, PREFIX_INC |
---|
| 165 | ); |
---|
| 166 | printf("\n"); |
---|
| 167 | printf( |
---|
| 168 | "Name: lib%s\n" |
---|
[3829] | 169 | "Description: lib%s is part of RoarAudio Sound System\n" |
---|
[3827] | 170 | "Version: %s\n" |
---|
[3828] | 171 | // "Requires: libroar\n" |
---|
[3827] | 172 | "Conflicts:\n" |
---|
| 173 | "Libs: -L${libdir} %s\n" |
---|
| 174 | "Cflags: -I${includedir} %s\n", |
---|
| 175 | flags_ptr->name, |
---|
[3829] | 176 | flags_ptr->name, |
---|
[3827] | 177 | COMMON_VERSION, |
---|
| 178 | flags_ptr->libs, |
---|
| 179 | flags_ptr->cflags |
---|
| 180 | ); |
---|
| 181 | break; |
---|
| 182 | } |
---|
[2025] | 183 | |
---|
[143] | 184 | return 0; |
---|
| 185 | } |
---|
| 186 | |
---|
| 187 | //ll |
---|