Created
October 21, 2018 21:56
-
-
Save danielgustafsson/e9837e2d0e450ba1734bbdb512060061 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From 7149a19ad877ac873c3c5648ed666895f3d42c27 Mon Sep 17 00:00:00 2001 | |
From: Daniel Gustafsson <daniel@yesql.se> | |
Date: Sun, 21 Oct 2018 23:53:18 +0200 | |
Subject: [PATCH] curl-config: reimplement app in C | |
There has been portability concerns raised over the sh implementation | |
of curl-config, mainly in stripped down cloud environments were commands | |
such as bc aren't guaranteed to be avialable. This reimplements the app | |
in C with no external dependencies to get around this. No functinality | |
should be altered by this. | |
--- | |
Makefile.am | 2 - | |
configure.ac | 2 +- | |
curl-config.in | 182 ---------------------------------------- | |
src/Makefile.am | 4 +- | |
src/curl-config.c.in | 230 +++++++++++++++++++++++++++++++++++++++++++++++++++ | |
5 files changed, 234 insertions(+), 186 deletions(-) | |
delete mode 100644 curl-config.in | |
create mode 100644 src/curl-config.c.in | |
diff --git a/Makefile.am b/Makefile.am | |
index dd93a383e..daecdfcad 100644 | |
--- a/Makefile.am | |
+++ b/Makefile.am | |
@@ -165,8 +165,6 @@ CLEANFILES = $(VC6_LIBDSP) $(VC6_SRCDSP) $(VC7_LIBVCPROJ) $(VC7_SRCVCPROJ) \ | |
$(VC11_LIBVCXPROJ) $(VC11_SRCVCXPROJ) $(VC12_LIBVCXPROJ) $(VC12_SRCVCXPROJ) \ | |
$(VC14_LIBVCXPROJ) $(VC14_SRCVCXPROJ) $(VC15_LIBVCXPROJ) $(VC15_SRCVCXPROJ) | |
-bin_SCRIPTS = curl-config | |
- | |
SUBDIRS = lib src | |
DIST_SUBDIRS = $(SUBDIRS) tests packages scripts include docs | |
diff --git a/configure.ac b/configure.ac | |
index 82ff50320..8f4dd027f 100755 | |
--- a/configure.ac | |
+++ b/configure.ac | |
@@ -4353,7 +4353,7 @@ AC_CONFIG_FILES([Makefile \ | |
packages/AIX/Makefile \ | |
packages/AIX/RPM/Makefile \ | |
packages/AIX/RPM/curl.spec \ | |
- curl-config \ | |
+ src/curl-config.c \ | |
libcurl.pc | |
]) | |
AC_OUTPUT | |
diff --git a/curl-config.in b/curl-config.in | |
deleted file mode 100644 | |
index 2f958ca94..000000000 | |
--- a/curl-config.in | |
+++ /dev/null | |
@@ -1,182 +0,0 @@ | |
-#! /bin/sh | |
-#*************************************************************************** | |
-# _ _ ____ _ | |
-# Project ___| | | | _ \| | | |
-# / __| | | | |_) | | | |
-# | (__| |_| | _ <| |___ | |
-# \___|\___/|_| \_\_____| | |
-# | |
-# Copyright (C) 2001 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al. | |
-# | |
-# This software is licensed as described in the file COPYING, which | |
-# you should have received as part of this distribution. The terms | |
-# are also available at https://curl.haxx.se/docs/copyright.html. | |
-# | |
-# You may opt to use, copy, modify, merge, publish, distribute and/or sell | |
-# copies of the Software, and permit persons to whom the Software is | |
-# furnished to do so, under the terms of the COPYING file. | |
-# | |
-# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | |
-# KIND, either express or implied. | |
-# | |
-########################################################################### | |
- | |
-prefix=@prefix@ | |
-exec_prefix=@exec_prefix@ | |
-includedir=@includedir@ | |
-cppflag_curl_staticlib=@CPPFLAG_CURL_STATICLIB@ | |
- | |
-usage() | |
-{ | |
- cat <<EOF | |
-Usage: curl-config [OPTION] | |
- | |
-Available values for OPTION include: | |
- | |
- --built-shared says 'yes' if libcurl was built shared | |
- --ca ca bundle install path | |
- --cc compiler | |
- --cflags pre-processor and compiler flags | |
- --checkfor [version] check for (lib)curl of the specified version | |
- --configure the arguments given to configure when building curl | |
- --features newline separated list of enabled features | |
- --help display this help and exit | |
- --libs library linking information | |
- --prefix curl install prefix | |
- --protocols newline separated list of enabled protocols | |
- --ssl-backends output the SSL backends libcurl was built to support | |
- --static-libs static libcurl library linking information | |
- --version output version information | |
- --vernum output the version information as a number (hexadecimal) | |
-EOF | |
- | |
- exit $1 | |
-} | |
- | |
-if test $# -eq 0; then | |
- usage 1 | |
-fi | |
- | |
-while test $# -gt 0; do | |
- case "$1" in | |
- # this deals with options in the style | |
- # --option=value and extracts the value part | |
- # [not currently used] | |
- -*=*) value=`echo "$1" | sed 's/[-_a-zA-Z0-9]*=//'` ;; | |
- *) value= ;; | |
- esac | |
- | |
- case "$1" in | |
- --built-shared) | |
- echo @ENABLE_SHARED@ | |
- ;; | |
- | |
- --ca) | |
- echo @CURL_CA_BUNDLE@ | |
- ;; | |
- | |
- --cc) | |
- echo "@CC@" | |
- ;; | |
- | |
- --prefix) | |
- echo "$prefix" | |
- ;; | |
- | |
- --feature|--features) | |
- for feature in @SUPPORT_FEATURES@ ""; do | |
- test -n "$feature" && echo "$feature" | |
- done | |
- ;; | |
- | |
- --protocols) | |
- for protocol in @SUPPORT_PROTOCOLS@; do | |
- echo "$protocol" | |
- done | |
- ;; | |
- | |
- --version) | |
- echo libcurl @CURLVERSION@ | |
- exit 0 | |
- ;; | |
- | |
- --checkfor) | |
- checkfor=$2 | |
- cmajor=`echo $checkfor | cut -d. -f1` | |
- cminor=`echo $checkfor | cut -d. -f2` | |
- # when extracting the patch part we strip off everything after a | |
- # dash as that's used for things like version 1.2.3-CVS | |
- cpatch=`echo $checkfor | cut -d. -f3 | cut -d- -f1` | |
- checknum=`echo "$cmajor*256*256 + $cminor*256 + ${cpatch:-0}" | bc` | |
- numuppercase=`echo @VERSIONNUM@ | tr 'a-f' 'A-F'` | |
- nownum=`echo "obase=10; ibase=16; $numuppercase" | bc` | |
- | |
- if test "$nownum" -ge "$checknum"; then | |
- # silent success | |
- exit 0 | |
- else | |
- echo "requested version $checkfor is newer than existing @CURLVERSION@" | |
- exit 1 | |
- fi | |
- ;; | |
- | |
- --vernum) | |
- echo @VERSIONNUM@ | |
- exit 0 | |
- ;; | |
- | |
- --help) | |
- usage 0 | |
- ;; | |
- | |
- --cflags) | |
- if test "X$cppflag_curl_staticlib" = "X-DCURL_STATICLIB"; then | |
- CPPFLAG_CURL_STATICLIB="-DCURL_STATICLIB " | |
- else | |
- CPPFLAG_CURL_STATICLIB="" | |
- fi | |
- if test "X@includedir@" = "X/usr/include"; then | |
- echo "$CPPFLAG_CURL_STATICLIB" | |
- else | |
- echo "${CPPFLAG_CURL_STATICLIB}-I@includedir@" | |
- fi | |
- ;; | |
- | |
- --libs) | |
- if test "X@libdir@" != "X/usr/lib" -a "X@libdir@" != "X/usr/lib64"; then | |
- CURLLIBDIR="-L@libdir@ " | |
- else | |
- CURLLIBDIR="" | |
- fi | |
- if test "X@REQUIRE_LIB_DEPS@" = "Xyes"; then | |
- echo ${CURLLIBDIR}-lcurl @LIBCURL_LIBS@ | |
- else | |
- echo ${CURLLIBDIR}-lcurl | |
- fi | |
- ;; | |
- --ssl-backends) | |
- echo "@SSL_BACKENDS@" | |
- ;; | |
- | |
- --static-libs) | |
- if test "X@ENABLE_STATIC@" != "Xno" ; then | |
- echo @libdir@/libcurl.@libext@ @LDFLAGS@ @LIBCURL_LIBS@ | |
- else | |
- echo "curl was built with static libraries disabled" >&2 | |
- exit 1 | |
- fi | |
- ;; | |
- | |
- --configure) | |
- echo @CONFIGURE_OPTIONS@ | |
- ;; | |
- | |
- *) | |
- echo "unknown option: $1" | |
- usage 1 | |
- ;; | |
- esac | |
- shift | |
-done | |
- | |
-exit 0 | |
diff --git a/src/Makefile.am b/src/Makefile.am | |
index 80cbce206..23f1290b7 100644 | |
--- a/src/Makefile.am | |
+++ b/src/Makefile.am | |
@@ -41,7 +41,7 @@ AM_CPPFLAGS = -I$(top_srcdir)/include \ | |
-I$(top_srcdir)/lib \ | |
-I$(top_srcdir)/src | |
-bin_PROGRAMS = curl | |
+bin_PROGRAMS = curl curlconfig | |
SUBDIRS = ../docs | |
@@ -54,6 +54,8 @@ include Makefile.inc | |
# CURL_FILES comes from Makefile.inc | |
curl_SOURCES = $(CURL_FILES) | |
+curlconfig_SOURCES = curl-config.c | |
+ | |
# This might hold -Werror | |
CFLAGS += @CURL_CFLAG_EXTRAS@ | |
diff --git a/src/curl-config.c.in b/src/curl-config.c.in | |
new file mode 100644 | |
index 000000000..3b7a3a2a5 | |
--- /dev/null | |
+++ b/src/curl-config.c.in | |
@@ -0,0 +1,230 @@ | |
+/*************************************************************************** | |
+ * _ _ ____ _ | |
+ * Project ___| | | | _ \| | | |
+ * / __| | | | |_) | | | |
+ * | (__| |_| | _ <| |___ | |
+ * \___|\___/|_| \_\_____| | |
+ * | |
+ * Copyright (C) 1998 - 2018, Daniel Stenberg, <daniel@haxx.se>, et al. | |
+ * | |
+ * This software is licensed as described in the file COPYING, which | |
+ * you should have received as part of this distribution. The terms | |
+ * are also available at https://curl.haxx.se/docs/copyright.html. | |
+ * | |
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell | |
+ * copies of the Software, and permit persons to whom the Software is | |
+ * furnished to do so, under the terms of the COPYING file. | |
+ * | |
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | |
+ * KIND, either express or implied. | |
+ * | |
+ ***************************************************************************/ | |
+ | |
+#include <stdio.h> | |
+#include <stdlib.h> | |
+#include <string.h> | |
+ | |
+static void | |
+usage(const char *program) | |
+{ | |
+ printf("Usage: %s [OPTION]\n\n", program); | |
+ printf("Available values for OPTION include:\n\n"); | |
+ printf(" --built-shared says 'yes' if libcurl was built shared\n"); | |
+ printf(" --ca ca bundle install path\n"); | |
+ printf(" --cc compiler\n"); | |
+ printf(" --cflags pre-processor and compiler flags\n"); | |
+ printf(" --checkfor [version] check for (lib)curl of the specified " | |
+ "version\n"); | |
+ printf(" --configure the arguments given to configure when building " | |
+ "curl\n"); | |
+ printf(" --features newline separated list of enabled features\n"); | |
+ printf(" --help display this help and exit\n"); | |
+ printf(" --libs library linking information\n"); | |
+ printf(" --prefix curl install prefix\n"); | |
+ printf(" --protocols newline separated list of enabled protocols\n"); | |
+ printf(" --ssl-backends output the SSL backends libcurl was built to " | |
+ "support\n"); | |
+ printf(" --static-libs static libcurl library linking information\n"); | |
+ printf(" --version output version information\n"); | |
+ printf(" --vernum output the version information as a number " | |
+ "(hexadecimal)\n"); | |
+} | |
+ | |
+static char * | |
+expand_prefix(char *prefix, char *str) | |
+{ | |
+ int plen; | |
+ int slen; | |
+ char *tmp; | |
+ char *new; | |
+ | |
+ plen = strlen(prefix); | |
+ tmp = strchr(str, '}'); | |
+ | |
+ /* If the prefix is empty, we just fast-forward the pointer to str */ | |
+ if(plen == 0) { | |
+ if(tmp) | |
+ str = tmp + 1; | |
+ return str; | |
+ } | |
+ | |
+ slen = strlen(str); | |
+ | |
+ new = (char *) malloc(slen - (tmp - str) + plen); | |
+ | |
+ memcpy(new, prefix, plen); | |
+ memcpy(new + plen, tmp + 1, slen - (tmp - str) - 1); | |
+ | |
+ return new; | |
+} | |
+ | |
+int | |
+main(int argc, char *argv[]) | |
+{ | |
+ int i = 1; | |
+ int cmajor; | |
+ int cminor; | |
+ int cpatch = 0; | |
+ | |
+ int versionnum = 0x073E00; | |
+ char *prefix = strdup("@prefix@"); | |
+ char *_exec_prefix = strdup("@exec_prefix@"); | |
+ char *_includedir = strdup("@includedir@"); | |
+ char *_libdir = strdup("@libdir@"); | |
+ /* !checksrc! disable LONGLINE 2 */ | |
+ char *protocols = strdup("@SUPPORT_PROTOCOLS@"); | |
+ char *features = strdup("@SUPPORT_FEATURES@"); | |
+ | |
+ char *exec_prefix = expand_prefix(prefix, _exec_prefix); | |
+ char *includedir = expand_prefix(prefix, _includedir); | |
+ char *libdir = expand_prefix(exec_prefix, _libdir); | |
+ | |
+ if(argc == 1) { | |
+ usage(argv[0]); | |
+ return 1; | |
+ } | |
+ | |
+ do { | |
+ | |
+ if(i >= argc) | |
+ break; | |
+ | |
+ /* Hunt for long opts */ | |
+ if(*argv[i] == '-' && *(argv[i] + 1) == '-') { | |
+ argv[i] += 2; | |
+ | |
+ if(strcmp(argv[i], "built-shared") == 0) { | |
+ printf("@ENABLE_SHARED@\n"); | |
+ } | |
+ else if(strcmp(argv[i], "ca") == 0) { | |
+ printf("@CURL_CA_BUNDLE@\n"); | |
+ } | |
+ else if(strcmp(argv[i], "cc") == 0) { | |
+ printf("@CC@\n"); | |
+ } | |
+ else if(strcmp(argv[i], "prefix") == 0) { | |
+ printf("%s\n", prefix); | |
+ } | |
+ else if(strcmp(argv[i], "features") == 0 | |
+ || strcmp(argv[i], "feature") == 0) { | |
+ char *tmp; | |
+ while((tmp = strchr(features, ' ')) != NULL) | |
+ *tmp = '\n'; | |
+ printf("%s\n", features); | |
+ } | |
+ else if(strcmp(argv[i], "protocols") == 0) { | |
+ char *tmp; | |
+ while((tmp = strchr(protocols, ' ')) != NULL) | |
+ *tmp = '\n'; | |
+ printf("%s\n", protocols); | |
+ } | |
+ else if(strcmp(argv[i], "version") == 0) { | |
+ printf("libcurl @CURLVERSION@\n"); | |
+ return 0; | |
+ } | |
+ else if(strcmp(argv[i], "checkfor") == 0) { | |
+ | |
+ if((i == argc - 1) || (*argv[i + 1] == '-')) { | |
+ printf("ERROR: --checkfor requires argument\n"); | |
+ usage(argv[0]); | |
+ return 1; | |
+ } | |
+ | |
+ if(sscanf(argv[++i], "%d.%d.%d%*s", &cmajor, &cminor, &cpatch) < 2) { | |
+ printf("ERROR: Invalid --checkfor argument\n"); | |
+ usage(argv[0]); | |
+ return 1; | |
+ } | |
+ | |
+ int checkfor = (cmajor * 256 * 256) + (cminor * 256) + cpatch; | |
+ | |
+ if(versionnum >= checkfor) | |
+ return 0; | |
+ else { | |
+ printf("requested version %s is newer than existing @CURLVERSION@\n", | |
+ argv[i]); | |
+ return 1; | |
+ } | |
+ } | |
+ else if(strcmp(argv[i], "vernum") == 0) { | |
+ printf("@VERSIONNUM@\n"); | |
+ return 0; | |
+ } | |
+ else if(strcmp(argv[i], "help") == 0) { | |
+ usage(argv[0]); | |
+ return 0; | |
+ } | |
+ else if(strcmp(argv[i], "cflags") == 0) { | |
+ int staticlib = 0; | |
+ | |
+ if(strcmp("@CPPFLAG_CURL_STATICLIB@", "-DCURL_STATICLIB") == 0) | |
+ staticlib = 1; | |
+ | |
+ if(strcmp(includedir, "/usr/include") == 0) | |
+ printf("%s\n", (staticlib ? "-DCURL_STATICLIB" : "")); | |
+ else | |
+ printf("%s-I%s\n", | |
+ (staticlib ? "-DCURL_STATICLIB " : ""), includedir); | |
+ } | |
+ else if(strcmp(argv[i], "libs") == 0) { | |
+ int have_libdir = 0; | |
+ | |
+ if((strcmp(libdir, "/usr/lib") != 0) | |
+ && strcmp(libdir, "/usr/lib64") != 0) | |
+ have_libdir = 1; | |
+ | |
+ if(strcmp("@REQUIRE_LIB_DEPS@", "yes") == 0) { | |
+ if(have_libdir) | |
+ printf("-L%s -lcurl @LIBCURL_LIBS@\n", libdir); | |
+ else | |
+ printf("-lcurl\n"); | |
+ } | |
+ } | |
+ else if(strcmp(argv[i], "ssl-backends") == 0) { | |
+ printf("@SSL_BACKENDS@\n"); | |
+ } | |
+ else if(strcmp(argv[i], "static-libs") == 0) { | |
+ if(strcmp("X@ENABLE_STATIC@", "Xno") != 0) | |
+ printf("%s/libcurl.@libext@ @LDFLAGS@ @LIBCURL_LIBS@\n", libdir); | |
+ else | |
+ printf("curl was built with static libraries disabled\n"); | |
+ | |
+ return 1; | |
+ } | |
+ else if(strcmp(argv[i], "configure") == 0) { | |
+ /* !checksrc! disable LONGLINE 1 */ | |
+ printf(@CONFIGURE_OPTIONS@ "\n"); | |
+ } | |
+ } | |
+ else { | |
+ printf("unknown option: \"%s\"\n", argv[i]); | |
+ usage(argv[0]); | |
+ return 1; | |
+ } | |
+ | |
+ i++; | |
+ } | |
+ while(i < argc); | |
+ | |
+ return 0; | |
+} | |
-- | |
2.14.1.145.gb3622a4ee | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment