Search code examples
cdebuggingsyntax-errorphp-extension

Tools/Tips to determine Error Location in configure stage - PHP Extension Coding


I was trying to code a PHP Extension in C After phpize , I did ./configure and got this error

checking Whether extensionB is enabled... yes, shared
./configure: line 4171: syntax error near unexpected token `;'
./configure: line 4171: ;' 

How am I supposed to locate the line that caused the error? Any tools for this?

Folder Structure

extensionB
         config.m4
         extensionB.c
         extensionB.h

config.m4

PHP_ARG_ENABLE(extensionB, Whether extensionB is enabled, [--enable-extensionB enable extensionB support])

if $PHP_EXTENSIONB != "no" then
    PHP_NEW_EXTENSION(extensionB,extensionB.c,$ext_shared);
fi

extensionB.h

#ifndef PHP_EXTENSIONB_H
#define PHP_EXTENSIONB_H 1

#define PHP_EXTENSIONB_VERSION "1.0"
#define PHP_EXTENSIONB_EXTNAME "extensionB"

PHP_FUNCTION(extensionBFn1);

extern zend_module_entry extensionB_module_entry;
#define phpext_extensionB_ptr &extensionB_module_entry

#endif

extensionB.c

#include "php.h"
#include "extensionB.h"

static function_entry extensionBFns[] = 
{
 PHP_FE(extensionBFn1,NULL)
 {NULL,NULL,NULL}
};

zend_module_entry extensionB_module_entry = 
{
    STANDARD_MODULE_HEADER,
    PHP_EXTENSIONB_EXTNAME,
    extensionBFns,
    NULL,NULL,NULL,NULL,NULL,
    PHP_EXTENSIONB_VERSION,
    STANDARD_MODULE_PROPERTIES
};

#ifdef COMPILE_DL_EXTENSIONB
    ZEND_GET_MODULE(extensionB)
#endif

PHP_FUNCTION(extensionB)
{ 
  RETURN_STRING("Extension B returns a string from Fn 1",1);
}

EDIT

Going through my code I realised my file config.m4 should contain

if test "$PHP_EXTENSIONB" != "no";
then

NOw it passes ./configure stage, but is there any tool to show the location. like gdb?


Solution

  • Nothing like GDB for this, but the configure.log file : search for the test that fails, and in the lines around that, it tells you what was executed exactly and what failed.