Logo
~Sockets~
~Examples~
~Contact~


Sockets-config.cpp File Reference

#include <stdio.h>
#include <string.h>
#include "sockets-config.h"
#include "socket_include.h"
#include <map>
#include <string>

Include dependency graph for Sockets-config.cpp:

Go to the source code of this file.


Functions

void show_info ()
void setup_configuration ()
void set (const char *param, bool enable)
void show_configuration ()
void replace_makefile (const std::string &name, const std::string &value)
void set_platform (const char *platform)
void set_namespace (const char *ns)
int main (int argc, char *argv[])

Variables

static bool any_set = false
static std::map< std::string,
std::string > 
mmap

Detailed Description

Date:
2006-09-04
Author:
grymse@alhem.net

Definition in file Sockets-config.cpp.


Function Documentation

int main ( int  argc,
char *  argv[] 
)

Definition at line 359 of file Sockets-config.cpp.

References any_set, replace_makefile(), set_namespace(), set_platform(), setup_configuration(), show_configuration(), and show_info().

00360 {
00361         bool info = false;
00362         bool usage = false;
00363         setup_configuration();
00364         for (int i = 1; i < argc; i++)
00365                 if (!strcmp(argv[i], "-info"))
00366                         info = true;
00367                 else
00368                 if (!strncmp(argv[i], "--enable-", 9))
00369                         set(&argv[i][9], true);
00370                 else
00371                 if (!strncmp(argv[i], "--disable-", 10))
00372                         set(&argv[i][10], false);
00373                 else
00374                 if (!strncmp(argv[i], "--platform=", 11))
00375                         set_platform(&argv[i][11]);
00376                 else
00377                 if (!strncmp(argv[i], "--name=", 7))
00378                         replace_makefile("NAME", &argv[i][7]);
00379                 else
00380                 if (!strncmp(argv[i], "--prefix=", 9))
00381                         replace_makefile("PREFIX", &argv[i][9]);
00382                 else
00383                 if (!strncmp(argv[i], "--namespace=", 12))
00384                         set_namespace(&argv[i][12]);
00385                 else
00386                 if (!strcmp(argv[i], "-v"))
00387                         any_set = true;
00388                 else
00389                 if (*argv[i] == '-')
00390                 {
00391                         fprintf(stderr, "Unknown command line option: %s\n", argv[i]);
00392                         usage = true;
00393                 }
00394                 else
00395                         usage = true;
00396         if (usage)
00397         {
00398                 fprintf(stderr, "Usage: %s [-info] [-v] [-h] [--platform=PLATFORM] [--prefix=<path>] [--name=<Name>] [--namespace=<ns>] [--enable-OPTION] [--disable-OPTION]\n", *argv);
00399                 fprintf(stderr, "\n");
00400                 fprintf(stderr, "Options (default value)\n");
00401                 fprintf(stderr, "\n");
00402                 fprintf(stderr, "  -info        Show compiled options\n");
00403                 fprintf(stderr, "  -v           Show configuration options\n");
00404                 fprintf(stderr, "  -h           Show this help\n");
00405                 fprintf(stderr, "\n");
00406                 fprintf(stderr, "  --platform=  Select target platform\n");
00407                 fprintf(stderr, "  --prefix=    Set installation path (/usr/local/$NAME)\n");
00408                 fprintf(stderr, "  --name=      Set library name (Sockets)\n");
00409                 fprintf(stderr, "  --namespace= Set C++ namespace for entire library\n");
00410                 fprintf(stderr, "\n");
00411                 fprintf(stderr, "Defined platforms\n");
00412                 fprintf(stderr, "\n");
00413                 fprintf(stderr, "  linux-x86-32\n");
00414                 fprintf(stderr, "  linux-x86-64\n");
00415                 fprintf(stderr, "  win32-cygwin\n");
00416                 fprintf(stderr, "  solaris9-sparc-64\n");
00417                 fprintf(stderr, "  macosx\n");
00418                 fprintf(stderr, "  solaris8\n");
00419                 fprintf(stderr, "\n");
00420                 fprintf(stderr, "Possible OPTION values:\n");
00421                 fprintf(stderr, "\n");
00422                 fprintf(stderr, "  openssl      Enable openssl library\n");
00423                 fprintf(stderr, "  ipv6         Add ipv6 support\n");
00424                 fprintf(stderr, "  sctp         Add SCTP support\n");
00425                 fprintf(stderr, "  no_addrinfo  Do not use addrinfo API for dns requests\n");
00426                 fprintf(stderr, "  pool         Enable client connection pool\n");
00427                 fprintf(stderr, "  socks4       Enable socks4 client support\n");
00428                 fprintf(stderr, "  resolver     Enable asynchronous dns\n");
00429                 fprintf(stderr, "  reconnect    Enable tcp reconnect\n");
00430                 fprintf(stderr, "  detach       Enable detach functionality\n");
00431                 fprintf(stderr, "  exceptions   Enable C++ exceptions on some error conditions\n");
00432                 fprintf(stderr, "  xml2         Enable libxml2 support\n");
00433                 fprintf(stderr, "\n");
00434                 fprintf(stderr, "Use with no options to show platform configuration options in CFLAGS format.\n");
00435                 return 0;
00436         }
00437         if (argc > 1 && info)
00438         {
00439                 show_info();
00440                 return 0;
00441         }
00442         if (any_set)
00443         {
00444                 show_configuration();
00445                 return 0;
00446         }
00447         printf(" -D_VERSION='\"%s\"'", _VERSION);
00448 
00449 #ifdef LINUX
00450         printf(" -DLINUX");
00451 #endif
00452 #ifdef MACOSX
00453         printf(" -DMACOSX");
00454 #endif
00455 #ifdef SOLARIS
00456         printf(" -DSOLARIS");
00457 #endif
00458 #ifdef SOLARIS8
00459         printf(" -DSOLARIS8");
00460 #endif
00461 #ifdef _WIN32
00462         printf(" -D_WIN32");
00463 #endif
00464 #ifdef __CYGWIN__
00465         printf(" -D__CYGWIN__");
00466 #endif
00467 #ifdef SOCKETS_NAMESPACE
00468         printf(" -DSOCKETS_NAMESPACE=%s", SOCKETS_NAMESPACE_STR);
00469 #endif
00470 #ifdef _DEBUG
00471         printf(" -D_DEBUG");
00472 #endif
00473 
00474 }

void replace_makefile ( const std::string &  name,
const std::string &  value 
)

Definition at line 237 of file Sockets-config.cpp.

References any_set.

Referenced by main(), and set_platform().

00238 {
00239         FILE *fil = fopen("Makefile", "rt");
00240         if (!fil)
00241         {
00242                 fprintf(stderr, "Can't read file: Makefile, aborting\n");
00243                 exit(-5);
00244         }
00245         FILE *fil2 = fopen("Makefile.tmp", "wt");
00246         if (!fil2)
00247         {
00248                 fprintf(stderr, "Can't write to file: Makefile.tmp, aborting\n");
00249                 exit(-6);
00250         }
00251         char slask[1000];
00252         fgets(slask, 1000, fil);
00253         while (!feof(fil))
00254         {
00255                 while (strlen(slask) && (slask[strlen(slask) - 1] == 13 || slask[strlen(slask) - 1] == 10))
00256                         slask[strlen(slask) - 1] = 0;
00257                 if (!strncmp(slask, name.c_str(), name.size()) && slask[name.size()] == 32)
00258                 {
00259                         if (name.size() < 6)
00260                                 fprintf(fil2, "%s =\t\t%s\n", name.c_str(), value.c_str());
00261                         else
00262                                 fprintf(fil2, "%s =\t%s\n", name.c_str(), value.c_str());
00263                 }
00264                 else
00265                 {
00266                         fprintf(fil2, "%s\n", slask);
00267                 }
00268                 fgets(slask, 1000, fil);
00269         }
00270         fclose(fil);
00271         fclose(fil2);
00272         rename("Makefile.tmp", "Makefile");
00273         any_set = true;
00274 }

void set ( const char *  param,
bool  enable 
)

Definition at line 127 of file Sockets-config.cpp.

References any_set, and mmap.

00128 {
00129         std::map<std::string, std::string>::iterator it = mmap.find(param);
00130         if (it == mmap.end())
00131         {
00132                 fprintf(stderr, "Option '%s' not found, aborting\n", param);
00133                 exit(-1);
00134         }
00135         FILE *fil = fopen("sockets-config.h", "rt");
00136         if (!fil)
00137         {
00138                 fprintf(stderr, "Can't open configuration file 'sockets-config.h', aborting\n");
00139                 exit(-2);
00140         }
00141         FILE *fil2 = fopen("sockets-config.h.tmp", "wt");
00142         if (!fil2)
00143         {
00144                 fprintf(stderr, "Can't write to temporary configuration file, aborting\n");
00145                 exit(-3);
00146         }
00147         char slask[1000];
00148         fgets(slask, 1000, fil);
00149         while (!feof(fil))
00150         {
00151                 bool replaced = false;
00152                 while (strlen(slask) && (slask[strlen(slask) - 1] == 13 || slask[strlen(slask) - 1] == 10))
00153                         slask[strlen(slask) - 1] = 0;
00154                 if (!strncmp(slask, "#define ", 8) ||
00155                     !strncmp(slask, "//#define ", 10))
00156                 {
00157                         int i = (*slask == '#') ? 8 : 10;
00158                         if (!strncmp(slask + i, it -> second.c_str(), it -> second.size()))
00159                         {
00160                                 if (!enable)
00161                                         fprintf(fil2, "//");
00162                                 fprintf(fil2, "#define %s\n", it -> second.c_str());
00163                                 replaced = true;
00164                         }
00165                 }
00166                 if (!replaced)
00167                         fprintf(fil2, "%s\n", slask);
00168                 //
00169                 fgets(slask, 1000, fil);
00170         }
00171         fclose(fil);
00172         fclose(fil2);
00173         rename("sockets-config.h.tmp", "sockets-config.h");
00174         any_set = true;
00175 }

void set_namespace ( const char *  ns  ) 

Definition at line 303 of file Sockets-config.cpp.

References any_set.

Referenced by main().

00304 {
00305 /*
00306 # uncomment these lines if the library should be in its own namespace
00307 #CFLAGS +=      -DSOCKETS_NAMESPACE=sockets
00308 #CFLAGS +=      -DSOCKETS_NAMESPACE_STR='"sockets"'
00309 */
00310         bool found = false;
00311         bool set = false;
00312         FILE *fil = fopen("Makefile", "rt");
00313         if (!fil)
00314         {
00315                 fprintf(stderr, "Can't read file: Makefile, aborting\n");
00316                 exit(-8);
00317         }
00318         FILE *fil2 = fopen("Makefile.tmp", "wt");
00319         if (!fil2)
00320         {
00321                 fprintf(stderr, "Can't write to file: Makefile.tmp, aborting\n");
00322                 exit(-9);
00323         }
00324         char slask[1000];
00325         fgets(slask, 1000, fil);
00326         while (!feof(fil))
00327         {
00328                 while (strlen(slask) && (slask[strlen(slask) - 1] == 13 || slask[strlen(slask) - 1] == 10))
00329                         slask[strlen(slask) - 1] = 0;
00330                 if (strstr(slask, "SOCKETS_NAMESPACE"))
00331                 {
00332                         if (*slask == '#')
00333                                 fprintf(fil2, "%s\n", slask);
00334                         else
00335                                 fprintf(fil2, "# %s\n", slask);
00336                         found = true;
00337                 }
00338                 else
00339                 if (found && !set)
00340                 {
00341                         fprintf(fil2, "CFLAGS +=\t-DSOCKETS_NAMESPACE=%s\n", ns);
00342                         fprintf(fil2, "CFLAGS +=\t-DSOCKETS_NAMESPACE_STR='\"%s\"'\n", ns);
00343                         fprintf(fil2, "%s\n", slask);
00344                         set = true;
00345                 }
00346                 else
00347                 {
00348                         fprintf(fil2, "%s\n", slask);
00349                 }
00350                 fgets(slask, 1000, fil);
00351         }
00352         fclose(fil);
00353         fclose(fil2);
00354         rename("Makefile.tmp", "Makefile");
00355         any_set = true;
00356 }

void set_platform ( const char *  platform  ) 

Definition at line 289 of file Sockets-config.cpp.

References replace_makefile().

Referenced by main().

00290 {
00291         if (!strcmp(platform, "linux-x86-32") ||
00292             !strcmp(platform, "linux-x86-64") ||
00293             !strcmp(platform, "win32-cygwin") ||
00294             !strcmp(platform, "solaris9-sparc-64") ||
00295             !strcmp(platform, "macosx") ||
00296             !strcmp(platform, "solaris8"))
00297         {
00298                 replace_makefile("PLATFORM", platform);
00299         }
00300 }

void setup_configuration (  ) 

Definition at line 111 of file Sockets-config.cpp.

References mmap.

Referenced by main().

00112 {
00113         mmap["openssl"] =     "HAVE_OPENSSL";
00114         mmap["ipv6"] =        "ENABLE_IPV6";
00115         mmap["sctp"] =        "USE_SCTP";
00116         mmap["no_addrinfo"] = "NO_GETADDRINFO";
00117         mmap["pool"] =        "ENABLE_POOL";
00118         mmap["socks4"] =      "ENABLE_SOCKS4";
00119         mmap["resolver"] =    "ENABLE_RESOLVER";
00120         mmap["reconnect"] =   "ENABLE_RECONNECT";
00121         mmap["detach"] =      "ENABLE_DETACH";
00122         mmap["exceptions"] =  "ENABLE_EXCEPTIONS";
00123         mmap["xml2"] =        "ENABLE_XML";
00124 }

void show_configuration (  ) 

Definition at line 178 of file Sockets-config.cpp.

References mmap.

Referenced by main().

00179 {
00180         printf("Library options (sockets-config.h)\n");
00181         FILE *fil = fopen("sockets-config.h", "rt");
00182         if (!fil)
00183         {
00184                 fprintf(stderr, "Can't open configuration file 'sockets-config.h', aborting\n");
00185                 exit(-4);
00186         }
00187         char slask[1000];
00188         fgets(slask, 1000, fil);
00189         while (!feof(fil))
00190         {
00191                 while (strlen(slask) && (slask[strlen(slask) - 1] == 13 || slask[strlen(slask) - 1] == 10))
00192                         slask[strlen(slask) - 1] = 0;
00193                 if (!strncmp(slask, "#define ", 8) ||
00194                     !strncmp(slask, "//#define ", 10))
00195                 {
00196                         int i = (*slask == '#') ? 8 : 10;
00197                         std::string def(&slask[i]);
00198                         for (std::map<std::string, std::string>::iterator it = mmap.begin(); it != mmap.end(); it++)
00199                         {
00200                                 if (def == it -> second)
00201                                 {
00202                                         std::string tmp(it -> first);
00203                                         tmp += " ";
00204                                         while (tmp.size() < 15)
00205                                                 tmp += ".";
00206                                         printf("%s %s\n", tmp.c_str(), (*slask == '#') ? "ENABLED" : "DISABLED");
00207                                 }
00208                         }
00209                 }
00210                 fgets(slask, 1000, fil);
00211         }
00212         fclose(fil);
00213         printf("Build options (Makefile)\n");
00214         fil = fopen("Makefile", "rt");
00215         if (!fil)
00216         {
00217                 fprintf(stderr, "Can't read file: Makefile, aborting\n");
00218                 exit(-7);
00219         }
00220         fgets(slask, 1000, fil);
00221         while (!feof(fil))
00222         {
00223                 while (strlen(slask) && (slask[strlen(slask) - 1] == 13 || slask[strlen(slask) - 1] == 10))
00224                         slask[strlen(slask) - 1] = 0;
00225                 if (!strncmp(slask, "PLATFORM ", 9) ||
00226                     !strncmp(slask, "PREFIX ", 7) ||
00227                     (strstr(slask, "SOCKETS_NAMESPACE") && *slask != '#') ||
00228                     !strncmp(slask, "NAME ", 5)
00229                 )
00230                         printf("%s\n", slask);
00231                 fgets(slask, 1000, fil);
00232         }
00233         fclose(fil);
00234 }

void show_info (  ) 

Definition at line 35 of file Sockets-config.cpp.

Referenced by main().

00036 {
00037 #ifdef HAVE_OPENSSL
00038                 printf("SSL support\n");
00039 #endif
00040 #ifdef IPPROTO_IPV6
00041                 printf("IPv6 support\n");
00042 #endif
00043 #ifdef USE_SCTP
00044 #ifdef IPPROTO_SCTP
00045                 printf("SCTP support\n");
00046 #       ifdef HAVE_SCTP
00047                 printf("  HAVE_SCTP: yes\n");
00048 #       else
00049                 printf("  HAVE_SCTP: no\n");
00050 #       endif
00051 #       ifdef HAVE_KERNEL_SCTP
00052                 printf("  HAVE_KERNEL_SCTP: yes\n");
00053 #       else
00054                 printf("  HAVE_KERNEL_SCTP: no\n");
00055 #       endif
00056 #       ifdef HAVE_SCTP_PRSCTP
00057                 printf("  HAVE_SCTP_PRSCTP: yes\n");
00058 #       else
00059                 printf("  HAVE_SCTP_PRSCTP: no\n");
00060 #       endif
00061 #       ifdef HAVE_SCTP_ADDIP
00062                 printf("  HAVE_SCTP_ADDIP: yes\n");
00063 #       else
00064                 printf("  HAVE_SCTP_ADDIP: no\n");
00065 #       endif
00066 #       ifdef HAVE_SCTP_CANSET_PRIMARY
00067                 printf("  HAVE_SCTP_CANSETPRIMARY: yes\n");
00068 #       else
00069                 printf("  HAVE_SCTP_CANSETPRIMARY: no\n");
00070 #       endif
00071 #       ifdef HAVE_SCTP_SAT_NETWORK_CAPABILITY
00072                 printf("  HAVE_SCTP_SAT_NETWORK_CAPABILITY: yes\n");
00073 #       else
00074                 printf("  HAVE_SCTP_SAT_NETWORK_CAPABILITY: no\n");
00075 #       endif
00076 #       ifdef HAVE_SCTP_MULTIBUF
00077                 printf("  HAVE_SCTP_MULTIBUF: yes\n");
00078 #       else
00079                 printf("  HAVE_SCTP_MULTIBUF: no\n");
00080 #       endif
00081 #       ifdef HAVE_SCTP_NOCONNECT
00082                 printf("  HAVE_SCTP_NOCONNECT: yes\n");
00083 #       else
00084                 printf("  HAVE_SCTP_NOCONNECT: no\n");
00085 #       endif
00086 #       ifdef HAVE_SCTP_EXT_RCVINFO
00087                 printf("  HAVE_SCTP_EXT_RCVINFO: yes\n");
00088 #       else
00089                 printf("  HAVE_SCTP_EXT_RCVINFO: no\n");
00090 #       endif
00091 #else
00092                 printf("No SCTP support\n");
00093 #endif
00094 #endif
00095 }


Variable Documentation

bool any_set = false [static]

Definition at line 31 of file Sockets-config.cpp.

Referenced by main(), replace_makefile(), set(), and set_namespace().

std::map<std::string, std::string> mmap [static]

Definition at line 32 of file Sockets-config.cpp.

Referenced by set(), setup_configuration(), and show_configuration().

Page, code, and content Copyright (C) 2007 by Anders Hedström
Generated for C++ Sockets by  doxygen 1.4.4