From bfb22ab16fa2160f6a5a9fe22ec15aa09b77b02e Mon Sep 17 00:00:00 2001 From: Felipe Zimmerle Date: Wed, 18 Nov 2015 14:45:28 -0800 Subject: [PATCH] ModSec 2.x without libxml --- apache2/apache2_config.c | 14 ++- apache2/mod_security2.c | 6 +- apache2/modsecurity.c | 4 + apache2/modsecurity.h | 11 +- apache2/msc_crypt.c | 27 +++- apache2/msc_crypt.h | 2 + apache2/msc_logging.c | 2 + apache2/msc_remote_rules.c | 2 +- apache2/msc_reqbody.c | 7 ++ apache2/msc_status_engine.c | 5 + apache2/msc_xml.c | 6 +- apache2/msc_xml.h | 6 + apache2/re_actions.c | 4 + apache2/re_operators.c | 6 +- apache2/re_variables.c | 8 ++ build/compile | 245 +++++++++++++++++++++++++++++++++--- build/find_xml.m4 | 7 -- 17 files changed, 323 insertions(+), 39 deletions(-) diff --git a/apache2/apache2_config.c b/apache2/apache2_config.c index bfbcb834..049b7410 100644 --- a/apache2/apache2_config.c +++ b/apache2/apache2_config.c @@ -157,7 +157,9 @@ void *create_directory_config(apr_pool_t *mp, char *path) /* xml external entity */ +#ifdef WITH_LIBXML dcfg->xml_external_entity = NOT_SET; +#endif return dcfg; } @@ -616,8 +618,10 @@ void *merge_directory_configs(apr_pool_t *mp, void *_parent, void *_child) ? parent->crypto_hash_framesrc_pm : child->crypto_hash_framesrc_pm); /* xml external entity */ +#ifdef WITH_LIBXML merged->xml_external_entity = (child->xml_external_entity == NOT_SET ? parent->xml_external_entity : child->xml_external_entity); +#endif return merged; } @@ -722,6 +726,7 @@ void init_directory_config(directory_config *dcfg) if (dcfg->col_timeout == NOT_SET) dcfg->col_timeout = 3600; /* Hash */ +#ifdef WITH_LIBXML if (dcfg->crypto_key == NOT_SET_P) dcfg->crypto_key = getkey(dcfg->mp); if (dcfg->crypto_key_len == NOT_SET) dcfg->crypto_key_len = strlen(dcfg->crypto_key); if (dcfg->crypto_key_add == NOT_SET) dcfg->crypto_key_add = HASH_KEYONLY; @@ -738,9 +743,12 @@ void init_directory_config(directory_config *dcfg) if (dcfg->crypto_hash_location_pm == NOT_SET) dcfg->crypto_hash_location_pm = 0; if (dcfg->crypto_hash_iframesrc_pm == NOT_SET) dcfg->crypto_hash_iframesrc_pm = 0; if (dcfg->crypto_hash_framesrc_pm == NOT_SET) dcfg->crypto_hash_framesrc_pm = 0; +#endif +#ifdef WITH_LIBXML /* xml external entity */ if (dcfg->xml_external_entity == NOT_SET) dcfg->xml_external_entity = 0; +#endif } @@ -2592,6 +2600,7 @@ static const char *cmd_sensor_id(cmd_parms *cmd, void *_dcfg, const char *p1) * \retval NULL On failure * \retval apr_psprintf On Success */ +#ifdef WITH_LIBXML static const char *cmd_xml_external_entity(cmd_parms *cmd, void *_dcfg, const char *p1) { directory_config *dcfg = (directory_config *)_dcfg; @@ -2607,7 +2616,7 @@ static const char *cmd_xml_external_entity(cmd_parms *cmd, void *_dcfg, const ch return NULL; } - +#endif /** * \brief Add SecHashEngine configuration option @@ -3610,7 +3619,7 @@ const command_rec module_directives[] = { "Abort or Warn" ), - +#ifdef WITH_LIBXML AP_INIT_TAKE1 ( "SecXmlExternalEntity", cmd_xml_external_entity, @@ -3618,6 +3627,7 @@ const command_rec module_directives[] = { CMD_SCOPE_ANY, "On or Off" ), +#endif AP_INIT_FLAG ( "SecRuleInheritance", diff --git a/apache2/mod_security2.c b/apache2/mod_security2.c index 519f2cc8..394a4c02 100644 --- a/apache2/mod_security2.c +++ b/apache2/mod_security2.c @@ -135,9 +135,11 @@ static void version(apr_pool_t *mp) { ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, NULL, "ModSecurity: YAJL compiled version=\"%d.%d.%d\"", YAJL_MAJOR, YAJL_MINOR, YAJL_MICRO); #endif /* WITH_YAJL */ - +#ifdef WITH_LIBXML ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, NULL, - "ModSecurity: LIBXML compiled version=\"%s\"", LIBXML_DOTTED_VERSION); + "ModSecurity: LIBXML compiled version=\"%s\"", LIBXML_DOTTED_VERSION +); +#endif } diff --git a/apache2/modsecurity.c b/apache2/modsecurity.c index 5bda4cff..4dd85b3d 100644 --- a/apache2/modsecurity.c +++ b/apache2/modsecurity.c @@ -179,7 +179,9 @@ int modsecurity_init(msc_engine *msce, apr_pool_t *mp) { */ void modsecurity_child_init(msc_engine *msce) { /* Need to call this once per process before any other XML calls. */ +#ifdef WITH_LIBXML xmlInitParser(); +#endif if (msce->auditlog_lock != NULL) { apr_status_t rc = apr_global_mutex_child_init(&msce->auditlog_lock, NULL, msce->mp); @@ -266,7 +268,9 @@ static apr_status_t modsecurity_tx_cleanup(void *data) { if (msr->mpd != NULL) multipart_cleanup(msr); /* XML processor cleanup. */ +#ifdef WITH_LIBXML if (msr->xml != NULL) xml_cleanup(msr); +#endif #ifdef WITH_YAJL /* JSON processor cleanup. */ diff --git a/apache2/modsecurity.h b/apache2/modsecurity.h index bbec3faa..8ced5e65 100644 --- a/apache2/modsecurity.h +++ b/apache2/modsecurity.h @@ -19,8 +19,10 @@ #include #include +#ifdef WITH_LIBXML #include #include +#endif typedef struct rule_exception rule_exception; typedef struct rule_exception hash_method; @@ -384,8 +386,11 @@ struct modsec_rec { char *multipart_filename; char *multipart_name; multipart_data *mpd; /* MULTIPART processor data structure */ - +#ifdef WITH_LIBXML xml_data *xml; /* XML processor data structure */ +#else + void *xml; +#endif #ifdef WITH_YAJL json_data *json; /* JSON processor data structure */ #endif @@ -465,7 +470,9 @@ struct modsec_rec { /* Generic request body processor context to be used by custom parsers. */ void *reqbody_processor_ctx; +#ifdef WITH_LIBXML htmlDocPtr crypto_html_tree; +#endif #if defined(WITH_LUA) #ifdef CACHE_LUA lua_State *L; @@ -628,7 +635,9 @@ struct directory_config { int crypto_hash_framesrc_pm; /* xml */ +#ifdef WITH_LIBXML int xml_external_entity; +#endif /* This will be used whenever ModSecurity will be ready * to ask the server for newer rules. diff --git a/apache2/msc_crypt.c b/apache2/msc_crypt.c index e7590b66..953f180f 100644 --- a/apache2/msc_crypt.c +++ b/apache2/msc_crypt.c @@ -18,8 +18,10 @@ #include "apr_uri.h" #include "apr_base64.h" #include "acmp.h" +#ifdef WITH_LIBXML #include "libxml/HTMLtree.h" #include "libxml/uri.h" +#endif #include /** @@ -32,6 +34,7 @@ * \retval NULL on fail */ char *normalize_path(modsec_rec *msr, char *input) { +#ifdef WITH_LIBXML xmlURI *uri = NULL; char *parsed_content = NULL; char *content = NULL; @@ -136,6 +139,8 @@ char *normalize_path(modsec_rec *msr, char *input) { if(uri != NULL) xmlFreeURI(uri); return apr_pstrdup(msr->mp, input); +#endif + return; } /** @@ -146,6 +151,7 @@ char *normalize_path(modsec_rec *msr, char *input) { * \retval key random key */ char *getkey(apr_pool_t *mp) { +#ifdef WITH_LIBXML unsigned char digest[APR_SHA1_DIGESTSIZE]; char *sig, *key, *value; apr_sha1_ctx_t ctx; @@ -168,6 +174,8 @@ char *getkey(apr_pool_t *mp) { apr_base64_encode (sig, (const char*)digest, sizeof (digest)); return sig; +#endif + return NULL; } @@ -184,6 +192,7 @@ char *getkey(apr_pool_t *mp) { */ char *hmac(modsec_rec *msr, const char *key, int key_len, unsigned char *msg, int msglen) { +#ifdef WITH_XML apr_sha1_ctx_t ctx; unsigned char digest[APR_SHA1_DIGESTSIZE]; unsigned char hmac_ipad[HMAC_PAD_SIZE], hmac_opad[HMAC_PAD_SIZE]; @@ -227,6 +236,8 @@ char *hmac(modsec_rec *msr, const char *key, int key_len, *hmac_digest = '\0'; return apr_pstrdup (msr->mp, hex_digest); +#endif + return NULL; } @@ -239,6 +250,7 @@ char *hmac(modsec_rec *msr, const char *key, int key_len, * \retval -1 on fail */ int init_response_body_html_parser(modsec_rec *msr) { +#ifdef WITH_LIBXML char *charset = NULL; char *final_charset = NULL; char sep; @@ -319,7 +331,7 @@ int init_response_body_html_parser(modsec_rec *msr) { "init_response_body_html_parser: Successfully html parser generated."); return 1; } - +#endif return 1; } @@ -335,6 +347,7 @@ int init_response_body_html_parser(modsec_rec *msr) { * \retval -1 on fail */ int do_hash_method(modsec_rec *msr, char *link, int type) { +#ifdef WITH_LIBXML hash_method **em = NULL; int i = 0; char *error_msg = NULL; @@ -633,6 +646,7 @@ int do_hash_method(modsec_rec *msr, char *link, int type) { } } +#endif return 0; } @@ -646,6 +660,7 @@ int do_hash_method(modsec_rec *msr, char *link, int type) { * \retval -1 On fail */ int hash_response_body_links(modsec_rec *msr) { +#ifdef WITH_LIBXML int lsize = 0, fsize = 0, lcount = 0, fcount = 0, i; int isize = 0, icount = 0, frsize = 0, frcount = 0; int bytes = 0; @@ -987,6 +1002,7 @@ obj_error: if(xpathCtx != NULL) xmlXPathFreeContext(xpathCtx); ctx_error: +#endif return -1; } @@ -1000,6 +1016,7 @@ ctx_error: * \retval -1 On fail */ int inject_hashed_response_body(modsec_rec *msr, int elts) { +#ifdef WITH_LIBXML xmlOutputBufferPtr output_buf = NULL; xmlCharEncodingHandlerPtr handler = NULL; char *p = NULL; @@ -1215,7 +1232,7 @@ int inject_hashed_response_body(modsec_rec *msr, int elts) { if (msr->txcfg->debuglog_level >= 4) msr_log(msr, 4, "inject_hashed_response_body: Stream buffer [%"APR_SIZE_T_FMT"]. Done",msr->stream_output_length); - +#endif return 1; } @@ -1230,6 +1247,7 @@ int inject_hashed_response_body(modsec_rec *msr, int elts) { * \retval NULL on fail */ char *do_hash_link(modsec_rec *msr, char *link, int type) { +#ifdef WITH_LIBXML char *mac_link = NULL; char *path_chunk = NULL; char *hash_value = NULL; @@ -1433,6 +1451,8 @@ char *do_hash_link(modsec_rec *msr, char *link, int type) { } return mac_link; +#endif + return NULL; } /** @@ -1444,6 +1464,7 @@ char *do_hash_link(modsec_rec *msr, char *link, int type) { * \retval 0 on fail */ int modify_response_header(modsec_rec *msr) { +#ifdef WITH_LIBXML char *mac_link = NULL; const char *location = NULL; int rc = 0; @@ -1500,6 +1521,6 @@ int modify_response_header(modsec_rec *msr) { apr_table_unset(msr->r->headers_out,"Location"); apr_table_set(msr->r->headers_out, "Location",(char*)apr_psprintf(msr->mp,"%s", mac_link)); } - +#endif return 1; } diff --git a/apache2/msc_crypt.h b/apache2/msc_crypt.h index 3b3aa6da..62208ecf 100644 --- a/apache2/msc_crypt.h +++ b/apache2/msc_crypt.h @@ -16,8 +16,10 @@ #define _MSC_CRYPT_H_ #include "modsecurity.h" +#ifdef WITH_LIBXML #include #include +#endif #define HMAC_PAD_SIZE 65 #define HASH_ONLY 0 diff --git a/apache2/msc_logging.c b/apache2/msc_logging.c index 3323fac9..6f0de3a6 100644 --- a/apache2/msc_logging.c +++ b/apache2/msc_logging.c @@ -23,7 +23,9 @@ #include "msc_util.h" #include "apr_version.h" +#ifdef WITH_LIBXML #include +#endif /** * Write the supplied data to the audit log (if the FD is ready), update diff --git a/apache2/msc_remote_rules.c b/apache2/msc_remote_rules.c index 8a6df9e0..eaadac0e 100644 --- a/apache2/msc_remote_rules.c +++ b/apache2/msc_remote_rules.c @@ -15,7 +15,7 @@ #include "msc_remote_rules.h" #include "msc_status_engine.h" -#include +// #include #ifdef WITH_CURL #include diff --git a/apache2/msc_reqbody.c b/apache2/msc_reqbody.c index 7d150eed..bbc86eb4 100644 --- a/apache2/msc_reqbody.c +++ b/apache2/msc_reqbody.c @@ -120,13 +120,16 @@ apr_status_t modsecurity_request_body_start(modsec_rec *msr, char **error_msg) { } } else if (strcmp(msr->msc_reqbody_processor, "XML") == 0) { +#ifdef WITH_LIBXML if (xml_init(msr, &my_error_msg) < 0) { *error_msg = apr_psprintf(msr->mp, "XML parsing error (init): %s", my_error_msg); msr->msc_reqbody_error = 1; msr->msc_reqbody_error_msg = my_error_msg; msr_log(msr, 2, "%s", *error_msg); } +#endif } + else if (strcmp(msr->msc_reqbody_processor, "JSON") == 0) { #ifdef WITH_YAJL if (json_init(msr, &my_error_msg) < 0) { @@ -352,12 +355,14 @@ apr_status_t modsecurity_request_body_store(modsec_rec *msr, msr->msc_reqbody_no_files_length += length; /* Process data as XML. */ +#ifdef WITH_LIBXML if (xml_process_chunk(msr, data, length, &my_error_msg) < 0) { *error_msg = apr_psprintf(msr->mp, "XML parsing error: %s", my_error_msg); msr->msc_reqbody_error = 1; msr->msc_reqbody_error_msg = *error_msg; msr_log(msr, 2, "%s", *error_msg); } +#endif } else if (strcmp(msr->msc_reqbody_processor, "JSON") == 0) { /* Increase per-request data length counter. */ @@ -657,6 +662,7 @@ apr_status_t modsecurity_request_body_end(modsec_rec *msr, char **error_msg) { return modsecurity_request_body_end_urlencoded(msr, error_msg); } else if (strcmp(msr->msc_reqbody_processor, "XML") == 0) { +#ifdef WITH_LIBXML if (xml_complete(msr, &my_error_msg) < 0) { *error_msg = apr_psprintf(msr->mp, "XML parser error: %s", my_error_msg); msr->msc_reqbody_error = 1; @@ -664,6 +670,7 @@ apr_status_t modsecurity_request_body_end(modsec_rec *msr, char **error_msg) { msr_log(msr, 2, "%s", *error_msg); return -1; } +#endif } } else if (msr->txcfg->reqbody_buffering != REQUEST_BODY_FORCEBUF_OFF) { /* Convert to a single continous buffer, but don't do anything else. */ diff --git a/apache2/msc_status_engine.c b/apache2/msc_status_engine.c index 834ecc3e..52f12e1b 100644 --- a/apache2/msc_status_engine.c +++ b/apache2/msc_status_engine.c @@ -347,7 +347,12 @@ int DSOLOCAL msc_beacon_string (char *beacon_string, int beacon_string_max_len) #ifdef WITH_LUA lua = LUA_VERSION; #endif +#ifdef WITH_LIBXML libxml = LIBXML_DOTTED_VERSION; +#else + libxml = "(null)"; +#endif + modsec = MODSEC_VERSION; #ifdef VERSION_IIS apache = "IIS"; diff --git a/apache2/msc_xml.c b/apache2/msc_xml.c index a31decb5..32d3a4aa 100644 --- a/apache2/msc_xml.c +++ b/apache2/msc_xml.c @@ -14,6 +14,7 @@ #include "msc_xml.h" +#ifdef WITH_XML static xmlParserInputBufferPtr xml_unload_external_entity(const char *URI, xmlCharEncoding enc) { return NULL; @@ -32,10 +33,11 @@ int xml_init(modsec_rec *msr, char **error_msg) { msr->xml = apr_pcalloc(msr->mp, sizeof(xml_data)); if (msr->xml == NULL) return -1; +#ifdef WITH_LIBXML if(msr->txcfg->xml_external_entity == 0) { entity = xmlParserInputBufferCreateFilenameDefault(xml_unload_external_entity); } - +#endif return 1; } @@ -144,3 +146,5 @@ apr_status_t xml_cleanup(modsec_rec *msr) { return 1; } + +#endif diff --git a/apache2/msc_xml.h b/apache2/msc_xml.h index f2390686..a7ac2271 100644 --- a/apache2/msc_xml.h +++ b/apache2/msc_xml.h @@ -15,18 +15,24 @@ #ifndef _MSC_XML_H_ #define _MSC_XML_H_ +#ifdef WITH_LIBXML typedef struct xml_data xml_data; +#endif #include "modsecurity.h" +#if WITH_LIBXML #include #include +#endif /* Structures */ struct xml_data { +#ifdef WITH_LIBXML xmlSAXHandler *sax_handler; xmlParserCtxtPtr parsing_ctx; xmlDocPtr doc; +#endif // WITH_LIBXML unsigned int well_formed; }; diff --git a/apache2/re_actions.c b/apache2/re_actions.c index e06ebe65..49b668cd 100644 --- a/apache2/re_actions.c +++ b/apache2/re_actions.c @@ -1293,6 +1293,7 @@ static apr_status_t msre_action_ctl_execute(modsec_rec *msr, apr_pool_t *mptmp, return -1; } +#ifdef WITH_LIBXML /* xmlns */ static char *msre_action_xmlns_validate(msre_engine *engine, apr_pool_t *mp, msre_action *action) { char *name = NULL; @@ -1313,6 +1314,7 @@ static char *msre_action_xmlns_validate(msre_engine *engine, apr_pool_t *mp, msr return NULL; } +#endif /* sanitizeArg */ static apr_status_t msre_action_sanitizeArg_execute(modsec_rec *msr, apr_pool_t *mptmp, @@ -2629,6 +2631,7 @@ void msre_engine_register_default_actions(msre_engine *engine) { msre_action_ctl_execute ); +#ifdef WITH_LIBXML /* xmlns */ msre_engine_action_register(engine, "xmlns", @@ -2641,6 +2644,7 @@ void msre_engine_register_default_actions(msre_engine *engine) { NULL, NULL ); +#endif /* capture */ msre_engine_action_register(engine, diff --git a/apache2/re_operators.c b/apache2/re_operators.c index 4f748d77..73587997 100644 --- a/apache2/re_operators.c +++ b/apache2/re_operators.c @@ -2536,6 +2536,7 @@ static int msre_op_validateDTD_init(msre_rule *rule, char **error_msg) { static int msre_op_validateDTD_execute(modsec_rec *msr, msre_rule *rule, msre_var *var, char **error_msg) { +#ifdef WITH_LIBXML xmlValidCtxtPtr cvp; xmlDtdPtr dtd; @@ -2591,7 +2592,7 @@ static int msre_op_validateDTD_execute(modsec_rec *msr, msre_rule *rule, msre_va xmlFreeValidCtxt(cvp); xmlFreeDtd(dtd); - +#endif /* Match. */ return 0; } @@ -2606,6 +2607,7 @@ static int msre_op_validateSchema_init(msre_rule *rule, char **error_msg) { static int msre_op_validateSchema_execute(modsec_rec *msr, msre_rule *rule, msre_var *var, char **error_msg) { +#ifdef WITH_LIBXML xmlSchemaParserCtxtPtr parserCtx; xmlSchemaValidCtxtPtr validCtx; xmlSchemaPtr schema; @@ -2673,7 +2675,7 @@ static int msre_op_validateSchema_execute(modsec_rec *msr, msre_rule *rule, msre xmlSchemaFree(schema); xmlSchemaFreeValidCtxt(validCtx); - +#endif return 0; } diff --git a/apache2/re_variables.c b/apache2/re_variables.c index c69085fe..ee132c8c 100644 --- a/apache2/re_variables.c +++ b/apache2/re_variables.c @@ -19,7 +19,9 @@ #include "re.h" #include "msc_util.h" +#ifdef WITH_LIBXML #include "libxml/xpathInternals.h" +#endif /** * Generates a variable from a string and a length. @@ -560,6 +562,7 @@ static int var_reqbody_processor_error_msg_generate(modsec_rec *msr, msre_var *v /* XML */ +#ifdef WITH_LIBXML static char *var_xml_validate(msre_ruleset *ruleset, msre_var *var) { /* It's OK if there's no parameter. */ if (var->param == NULL) return NULL; @@ -674,6 +677,8 @@ static int var_xml_generate(modsec_rec *msr, msre_var *var, msre_rule *rule, return count; } +#endif + /* WEBSERVER_ERROR_LOG */ static int var_webserver_error_log_generate(modsec_rec *msr, msre_var *var, msre_rule *rule, @@ -4159,6 +4164,7 @@ void msre_engine_register_default_variables(msre_engine *engine) { PHASE_REQUEST_HEADERS ); +#ifdef WITH_LIBXML /* XML */ msre_engine_variable_register(engine, "XML", @@ -4169,4 +4175,6 @@ void msre_engine_register_default_variables(msre_engine *engine) { VAR_DONT_CACHE, /* dynamic */ PHASE_REQUEST_BODY ); +#endif + } diff --git a/build/compile b/build/compile index 1b1d2321..531136b0 100755 --- a/build/compile +++ b/build/compile @@ -1,9 +1,9 @@ #! /bin/sh -# Wrapper for compilers which do not understand `-c -o'. +# Wrapper for compilers which do not understand '-c -o'. -scriptversion=2005-05-14.22 +scriptversion=2012-10-14.11; # UTC -# Copyright (C) 1999, 2000, 2003, 2004, 2005 Free Software Foundation, Inc. +# Copyright (C) 1999-2013 Free Software Foundation, Inc. # Written by Tom Tromey . # # This program is free software; you can redistribute it and/or modify @@ -17,8 +17,7 @@ scriptversion=2005-05-14.22 # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +# along with this program. If not, see . # As a special exception to the GNU General Public License, if you # distribute this file as part of a program that contains a @@ -29,21 +28,224 @@ scriptversion=2005-05-14.22 # bugs to or send patches to # . +nl=' +' + +# We need space, tab and new line, in precisely that order. Quoting is +# there to prevent tools from complaining about whitespace usage. +IFS=" "" $nl" + +file_conv= + +# func_file_conv build_file lazy +# Convert a $build file to $host form and store it in $file +# Currently only supports Windows hosts. If the determined conversion +# type is listed in (the comma separated) LAZY, no conversion will +# take place. +func_file_conv () +{ + file=$1 + case $file in + / | /[!/]*) # absolute file, and not a UNC file + if test -z "$file_conv"; then + # lazily determine how to convert abs files + case `uname -s` in + MINGW*) + file_conv=mingw + ;; + CYGWIN*) + file_conv=cygwin + ;; + *) + file_conv=wine + ;; + esac + fi + case $file_conv/,$2, in + *,$file_conv,*) + ;; + mingw/*) + file=`cmd //C echo "$file " | sed -e 's/"\(.*\) " *$/\1/'` + ;; + cygwin/*) + file=`cygpath -m "$file" || echo "$file"` + ;; + wine/*) + file=`winepath -w "$file" || echo "$file"` + ;; + esac + ;; + esac +} + +# func_cl_dashL linkdir +# Make cl look for libraries in LINKDIR +func_cl_dashL () +{ + func_file_conv "$1" + if test -z "$lib_path"; then + lib_path=$file + else + lib_path="$lib_path;$file" + fi + linker_opts="$linker_opts -LIBPATH:$file" +} + +# func_cl_dashl library +# Do a library search-path lookup for cl +func_cl_dashl () +{ + lib=$1 + found=no + save_IFS=$IFS + IFS=';' + for dir in $lib_path $LIB + do + IFS=$save_IFS + if $shared && test -f "$dir/$lib.dll.lib"; then + found=yes + lib=$dir/$lib.dll.lib + break + fi + if test -f "$dir/$lib.lib"; then + found=yes + lib=$dir/$lib.lib + break + fi + if test -f "$dir/lib$lib.a"; then + found=yes + lib=$dir/lib$lib.a + break + fi + done + IFS=$save_IFS + + if test "$found" != yes; then + lib=$lib.lib + fi +} + +# func_cl_wrapper cl arg... +# Adjust compile command to suit cl +func_cl_wrapper () +{ + # Assume a capable shell + lib_path= + shared=: + linker_opts= + for arg + do + if test -n "$eat"; then + eat= + else + case $1 in + -o) + # configure might choose to run compile as 'compile cc -o foo foo.c'. + eat=1 + case $2 in + *.o | *.[oO][bB][jJ]) + func_file_conv "$2" + set x "$@" -Fo"$file" + shift + ;; + *) + func_file_conv "$2" + set x "$@" -Fe"$file" + shift + ;; + esac + ;; + -I) + eat=1 + func_file_conv "$2" mingw + set x "$@" -I"$file" + shift + ;; + -I*) + func_file_conv "${1#-I}" mingw + set x "$@" -I"$file" + shift + ;; + -l) + eat=1 + func_cl_dashl "$2" + set x "$@" "$lib" + shift + ;; + -l*) + func_cl_dashl "${1#-l}" + set x "$@" "$lib" + shift + ;; + -L) + eat=1 + func_cl_dashL "$2" + ;; + -L*) + func_cl_dashL "${1#-L}" + ;; + -static) + shared=false + ;; + -Wl,*) + arg=${1#-Wl,} + save_ifs="$IFS"; IFS=',' + for flag in $arg; do + IFS="$save_ifs" + linker_opts="$linker_opts $flag" + done + IFS="$save_ifs" + ;; + -Xlinker) + eat=1 + linker_opts="$linker_opts $2" + ;; + -*) + set x "$@" "$1" + shift + ;; + *.cc | *.CC | *.cxx | *.CXX | *.[cC]++) + func_file_conv "$1" + set x "$@" -Tp"$file" + shift + ;; + *.c | *.cpp | *.CPP | *.lib | *.LIB | *.Lib | *.OBJ | *.obj | *.[oO]) + func_file_conv "$1" mingw + set x "$@" "$file" + shift + ;; + *) + set x "$@" "$1" + shift + ;; + esac + fi + shift + done + if test -n "$linker_opts"; then + linker_opts="-link$linker_opts" + fi + exec "$@" $linker_opts + exit 1 +} + +eat= + case $1 in '') - echo "$0: No command. Try \`$0 --help' for more information." 1>&2 + echo "$0: No command. Try '$0 --help' for more information." 1>&2 exit 1; ;; -h | --h*) cat <<\EOF Usage: compile [--help] [--version] PROGRAM [ARGS] -Wrapper for compilers which do not understand `-c -o'. -Remove `-o dest.o' from ARGS, run PROGRAM with the remaining +Wrapper for compilers which do not understand '-c -o'. +Remove '-o dest.o' from ARGS, run PROGRAM with the remaining arguments, and rename the output as expected. If you are trying to build a whole package this is not the -right script to run: please start by reading the file `INSTALL'. +right script to run: please start by reading the file 'INSTALL'. Report bugs to . EOF @@ -53,11 +255,13 @@ EOF echo "compile $scriptversion" exit $? ;; + cl | *[/\\]cl | cl.exe | *[/\\]cl.exe ) + func_cl_wrapper "$@" # Doesn't return... + ;; esac ofile= cfile= -eat= for arg do @@ -66,8 +270,8 @@ do else case $1 in -o) - # configure might choose to run compile as `compile cc -o foo foo.c'. - # So we strip `-o arg' only if arg is an object. + # configure might choose to run compile as 'compile cc -o foo foo.c'. + # So we strip '-o arg' only if arg is an object. eat=1 case $2 in *.o | *.obj) @@ -94,22 +298,22 @@ do done if test -z "$ofile" || test -z "$cfile"; then - # If no `-o' option was seen then we might have been invoked from a + # If no '-o' option was seen then we might have been invoked from a # pattern rule where we don't need one. That is ok -- this is a # normal compilation that the losing compiler can handle. If no - # `.c' file was seen then we are probably linking. That is also + # '.c' file was seen then we are probably linking. That is also # ok. exec "$@" fi # Name of file we expect compiler to create. -cofile=`echo "$cfile" | sed -e 's|^.*/||' -e 's/\.c$/.o/'` +cofile=`echo "$cfile" | sed 's|^.*[\\/]||; s|^[a-zA-Z]:||; s/\.c$/.o/'` # Create the lock directory. -# Note: use `[/.-]' here to ensure that we don't use the same name +# Note: use '[/\\:.-]' here to ensure that we don't use the same name # that we are using for the .o file. Also, base the name on the expected # object file name, since that is what matters with a parallel build. -lockdir=`echo "$cofile" | sed -e 's|[/.-]|_|g'`.d +lockdir=`echo "$cofile" | sed -e 's|[/\\:.-]|_|g'`.d while true; do if mkdir "$lockdir" >/dev/null 2>&1; then break @@ -124,9 +328,9 @@ trap "rmdir '$lockdir'; exit 1" 1 2 15 ret=$? if test -f "$cofile"; then - mv "$cofile" "$ofile" + test "$cofile" = "$ofile" || mv "$cofile" "$ofile" elif test -f "${cofile}bj"; then - mv "${cofile}bj" "$ofile" + test "${cofile}bj" = "$ofile" || mv "${cofile}bj" "$ofile" fi rmdir "$lockdir" @@ -138,5 +342,6 @@ exit $ret # eval: (add-hook 'write-file-hooks 'time-stamp) # time-stamp-start: "scriptversion=" # time-stamp-format: "%:y-%02m-%02d.%02H" -# time-stamp-end: "$" +# time-stamp-time-zone: "UTC" +# time-stamp-end: "; # UTC" # End: diff --git a/build/find_xml.m4 b/build/find_xml.m4 index 691679e4..3335dcd6 100644 --- a/build/find_xml.m4 +++ b/build/find_xml.m4 @@ -80,11 +80,4 @@ AC_SUBST(LIBXML2_CPPFLAGS) AC_SUBST(LIBXML2_LDADD) AC_SUBST(LIBXML2_LDFLAGS) -if test -z "${LIBXML2_VERSION}"; then - AC_MSG_NOTICE([*** xml library not found.]) - ifelse([$2], , AC_MSG_ERROR([libxml2 is required]), $2) -else - AC_MSG_NOTICE([using libxml2 v${LIBXML2_VERSION}]) - ifelse([$1], , , $1) -fi ])