Example #1
0
 /**
  * Create test case for this function
  *
  * @access public
  * @param  object  extension the function is part of
  * @return object  generated test case
  */
 function createTest(CodeGen_PECL_Extension $extension)
 {
     if (!$this->testCode) {
         return false;
     }
     $test = new CodeGen_PECL_Element_Test();
     $test->setName($this->name);
     $test->setTitle($this->name . "() function");
     if ($this->testDescription) {
         $test->setDescription($this->testDescription);
     }
     if ($this->testIni) {
         $test->addIni($this->testIni);
     }
     $test->setSkipIf("!extension_loaded('" . $extension->getName() . "')");
     if ($this->testSkipIf) {
         $test->addSkipIf($this->testSkipIf);
     }
     $test->setCode($this->testCode);
     if (!empty($this->testResult)) {
         $test->setOutput($this->testResult['result']);
         if (isset($this->testResult['mode'])) {
             $test->setMode($this->testResult['mode']);
         }
     }
     return $test;
 }
Example #2
0
 /**
  * config.m4 code snippet
  *
  * @return string
  */
 function configm4(CodeGen_PECL_Extension $extension)
 {
     $code = "\n";
     $withName = str_replace("-", "_", $this->getName());
     $withUpname = strtoupper($withName);
     $extName = $extension->getName();
     $extUpname = strtoupper($extName);
     if ($withName != $extName) {
         $code .= $this->m4Line() . "\n\n";
     }
     switch ($this->mode) {
         case "pkg-config":
             // TODO support --with-pkgconfig
             // TODO check "--exists" first
             // TODO add version checks
             $code .= "  if test -z \"\$PKG_CONFIG\"; then\n";
             $code .= "    AC_PATH_PROG(PKG_CONFIG, pkg-config, no)\n";
             $code .= "  fi\n";
             $code .= "  PHP_EVAL_INCLINE(`\$PKG_CONFIG --cflags-only-I {$withName}`)\n";
             $code .= "  PHP_EVAL_LIBLINE(`\$PKG_CONFIG --libs {$withName}`, {$extUpname}_SHARED_LIBADD)\n\n";
             break;
         default:
             if ($this->testfile) {
                 $code .= "\n  if test -r \"\$PHP_{$withUpname}/" . $this->testfile . "\"; then\n    PHP_{$withUpname}_DIR=\"\$PHP_{$withUpname}\"\n  else\n    AC_MSG_CHECKING(for " . $this->name . " in default path)\n    for i in " . str_replace(":", " ", $this->getDefaults()) . "; do\n      if test -r \"\$i/" . $this->testfile . "\"; then\n        PHP_{$withUpname}_DIR=\$i\n        AC_MSG_RESULT(found in \$i)\n        break\n      fi\n    done\n    if test \"x\" = \"x\$PHP_{$withUpname}_DIR\"; then\n      AC_MSG_ERROR(not found)\n    fi\n  fi\n\n";
             }
             $pathes = array();
             foreach ($this->getHeaders() as $header) {
                 $pathes[$header->getPath()] = true;
             }
             foreach (array_keys($pathes) as $path) {
                 $code .= "  PHP_ADD_INCLUDE(\$PHP_{$withUpname}_DIR/{$path})\n";
             }
             break;
     }
     $code .= "\n";
     $code .= "  export OLD_CPPFLAGS=\"\$CPPFLAGS\"\n";
     $code .= "  export CPPFLAGS=\"\$CPPFLAGS \$INCLUDES -DHAVE_{$withUpname}\"\n";
     foreach ($this->headers as $header) {
         $code .= $header->configm4($extName, $this->name);
     }
     foreach ($this->getLibs() as $lib) {
         $code .= $lib->configm4($extName, $this->name);
     }
     $code .= "  export CPPFLAGS=\"\$OLD_CPPFLAGS\"\n";
     return $code . "\n";
 }