Inline_C getting start

	Inline_C is one of the most powerful hacks I have ever seen for PHP. 	
	You can run compile C-Code and link this on the fly to the running php process. 
	Thus you can call C-function by php...				
	Inline_C was developed by 
		George Schlossnagle  (http://www.schlossnagle.org/~george/) 

		A modified version from me (A.Bohne)  Inline_C_ABL.tar.gz
			
		Compiling the Inline_c module (http://pear.php.net/package/Inline_C) 
			for php comes with lot of problems on my system. 

			(adjust the pathes to your system...)

		--------
			go to the PEAR directory on your computer (I have it at /www/lib/php)

			and run the following comands	
	
			/www/php.437_andreas.php/bin/pear config-set preferred_state alpha

			/www/php.437_andreas.php/bin/pear install Inline_C

			/www/php.437_andreas.php/bin/pear config-set preferred_state stable	
			
			# you have to call the program with absolut path!
			mkbuildtree.head /www/lib/php/Inline_C   //or mkbuildtree.4.2.3 Inline_C for older php versions

		--------
			
			[PROBLEM]: Warning: mkdir(/usr/local/lib/php/extensions/no-debug-non-zts-20020429/inline_libs): No such file or directory in - on line 1
			
			[FIX]:	mkdir /usr/local/lib/php/extensions/no-debug-non-zts-20020429/

		--------
			
			[PROBLEM]: The phpize program called in mkbuildtree.head (for php 4.3) causes the following problem:
			configure.in:65: error: possibly undefined macro: AC_PROG_LIBTOOL

			[FIX]: search the phpize on your system (comes with PHP)
				d=`pwd`; cd /; find . -name "phpize" -print 2> /dev/null; cd $d

				find the phpize.m4 file
				d=`pwd`; cd /; find . -name "phpize.m4" -print 2> /dev/null; cd $d

				edir this file and comment the AC_PROG_LIBTOOL line
				and change it to
				#AC_PROG_LIBTOOL

		--------

			[PROBLEM]: /www/php.437_andreas.php/bin/phpize: -f: command not found

			[FIX]: edit the phpize file and search for line $libtoolize -f -c || exit 1
			change it to:	
			#$libtoolize -f -c || exit 1
			$libtoolize   || exit 1
			

		--------

			Now you should see something like this:

			zsweb:/www/lib/php # mkbuildtree.head Inline_C
			Inline_C
			autoheader: config.h.in is unchanged
			Configuring for:
		  		PHP Api Version:   20010901
	    			Zend Module Api No:   20010901
    				Zend Extension Api No:   20010710
    			configure: error: cannot run /bin/sh ./config.sub

   		--------
			
			cd Inline_C and run ./configure	
			
		--------
			[PROBLEM]: configure: error: cannot run /bin/sh ./config.sub
			[FIX]: stealing ./config.sub and ./config.guess from php.4.3 source
				ls -l /www/source/php-4.3.7/config

				cd Inline_C		
				cp  /www/source/php-4.3.7/config.sub . 
				cp /www/source/php-4.3.7/config.guess .	

		--------
			
			Now you can run ./configure and you should see something like this:
			
			zsweb:/www/lib/php/Inline_C # ./configure 
			checking build system type... i686-pc-linux-gnu
			checking host system type... i686-pc-linux-gnu
			checking for gcc... gcc
			checking for C compiler default output... a.out
			checking whether the C compiler works... yes
			checking whether we are cross compiling... no
			checking for executable suffix... 
			checking for object suffix... o
			checking whether we are using the GNU C compiler... yes
			checking whether gcc accepts -g... yes
			checking whether gcc and cc understand -c and -o together... yes
			checking if compiler supports -R... no
			checking if compiler supports -Wl,-rpath,... yes
			checking for PHP prefix... /usr/local
			checking for PHP includes... -I/usr/local/include/php -I/usr/local/include/php/main -I/usr/local/include/php/Zend -I/usr/local/include/php/TSRM
			checking for PHP extension directory... /usr/local/lib/php/extensions/no-debug-non-zts-20020429
			checking for re2c... exit 0;
			checking for mawk... no
			checking for gawk... gawk
			checking blah... yes, shared
			configure: creating ./config.status
			config.status: creating config.h

		--------
			
			[PROBLEM]: Running make causes gcc: unrecognized option `-prefer-pic'

			zsweb:/www/lib/php/Inline_C # make
			mode=compile gcc  -I. -I/www/lib/php/Inline_C -DPHP_ATOM_INC -I/www/lib/php/Inline_C/include -I/www/lib/php/Inline_C/main -I/www/lib/php/Inline_C -I/usr/local/include/php -I/usr/local/include/php/main -I/usr/local/include/php/Zend -I/usr/local/include/php/TSRM  -DHAVE_CONFIG_H  -g -O2  -prefer-pic -c /www/lib/php/Inline_C/__MD5NAME__.c -o __MD5NAME__.lo 
			gcc: unrecognized option `-prefer-pic'
			mode=link gcc -DPHP_ATOM_INC -I/www/lib/php/Inline_C/include -I/www/lib/php/Inline_C/main -I/www/lib/php/Inline_C -I/usr/local/include/php -I/usr/local/include/php/main -I/usr/local/include/php/Zend -I/usr/local/include/php/TSRM  -DHAVE_CONFIG_H  -g -O2   -o __MD5NAME__.la -export-dynamic -avoid-version -prefer-pic -module -rpath /www/lib/php/Inline_C/modules  __MD5NAME__.lo __SHARED_LIBADD__
			gcc: __SHARED_LIBADD__: Datei oder Verzeichnis nicht gefunden
			gcc: unrecognized option `-prefer-pic'
			gcc: unrecognized option `-rpath'
			make: [__MD5NAME__.la] Fehler 1 (ignoriert)
			mode=install cp ./__MD5NAME__.la /www/lib/php/Inline_C/modules
			cp: Aufruf von stat f?r ?./__MD5NAME__.la? nicht m?glich: Datei oder Verzeichnis nicht gefunden
			make: [/www/lib/php/Inline_C/modules/__MD5NAME__.la] Fehler 1 (ignoriert)

			Build complete.
			(It is safe to ignore warnings about tempnam and tmpnam).

			
			[FIX]: find the libtool
				d=`pwd`; cd /; find . -name "libtool" -print 2> /dev/null; cd $d

				I took the libtool from php.4.3
				
				edit Makefile and add the libtool 

				LIBTOOL = /www/source/php-4.3.7/libtool

		--------

			Running make sould show you this:

			zsweb:/www/lib/php/Inline_C # make
			/www/source/php-4.3.7/libtool  --mode=link gcc -DPHP_ATOM_INC -I/www/lib/php/Inline_C/include -I/www/lib/php/Inline_C/main -I/www/lib/php/Inline_C -I/usr/local/include/php -I/usr/local/include/php/main -I/usr/local/include/php/Zend -I/usr/local/include/php/TSRM  -DHAVE_CONFIG_H  -g -O2   -o __MD5NAME__.la -export-dynamic -avoid-version -prefer-pic -module -rpath /www/lib/php/Inline_C/modules  __MD5NAME__.lo __SHARED_LIBADD__
			mkdir .libs
			rm -fr .libs/__MD5NAME__.la .libs/__MD5NAME__.* .libs/__MD5NAME__.*
			(cd . && ln -s __MD5NAME__.lo __MD5NAME__.o)
			ar cru .libs/__MD5NAME__.a  __MD5NAME__.o 
			ranlib .libs/__MD5NAME__.a
			creating __MD5NAME__.la
			(cd .libs && rm -f __MD5NAME__.la && ln -s ../__MD5NAME__.la __MD5NAME__.la)
			/www/source/php-4.3.7/libtool  --mode=install cp ./__MD5NAME__.la /www/lib/php/Inline_C/modules
			cp ./.libs/__MD5NAME__.lai /www/lib/php/Inline_C/modules/__MD5NAME__.la
			cp ./.libs/__MD5NAME__.a /www/lib/php/Inline_C/modules/__MD5NAME__.a
			ranlib /www/lib/php/Inline_C/modules/__MD5NAME__.a
			chmod 644 /www/lib/php/Inline_C/modules/__MD5NAME__.a
			PATH="$PATH:/sbin" ldconfig -n /www/lib/php/Inline_C/modules
			----------------------------------------------------------------------
			Libraries have been installed in:
   			/www/lib/php/Inline_C/modules

   			If you ever happen to want to link against installed libraries
   			in a given directory, LIBDIR, you must either use libtool, and
   			specify the full pathname of the library, or use the `-LLIBDIR'
   			flag during linking and do at least one of the following:
   			- add LIBDIR to the `LD_LIBRARY_PATH' environment variable during execution
     			- add LIBDIR to the `LD_RUN_PATH' environment variable during linking
       			- use the `-Wl,--rpath -Wl,LIBDIR' linker flag
       			- have your system administrator add LIBDIR to `/etc/ld.so.conf'

       			See any operating system documentation about shared libraries for
      			 more information, such as the ld(1) and ld.so(8) manual pages.
       			----------------------------------------------------------------------

       			Build complete.
			(It is safe to ignore warnings about tempnam and tmpnam).

			----

			maybe you want to link the php-file to the install dir
			ln -s ../Inline_C.php . 
		--------

			There is a shtool in build - but why and for what ...???
			
		--------

			Functions supported by Inline_C:
			#
		   	function Inline_C() 
		   	function add_preproccesor($code)
			function add_code($code) 
			function library($library, $path = null) 
			function library_path($path) 
			function include_path($path) 
			function compile() 
		
	
		
	-----------------------------------------------------------------------------------
	AHHHHHHHHHHHHHHHHRRRRRRRRRRRRRRRRRRRRRRRRR
	-----------------------------------------------------------------------------------	
			
		

A modivied Version - much mor easy to use...

		I removed all the phpzize, autoconfig,... stuff and reduce the complete system to 2 PHP lines - 
		one for compiling and one for linking. 
				
		0) Become uid of the webserver (or root - be careful) 		
				
		1) Download  Inline_C_ABL.tar.gz

		2) Move file to the PHP lib directory (often found in /usr/local/lib/php)
		
		3) Untar: tar xvfz Inline_C_ABL.tar.gz		

		4) Check if Include path is set in php.ini (should look like this:)
		;;;;;;;;;;;;;;;;;;;;;;;;;
		; Paths and Directories ;
		;;;;;;;;;;;;;;;;;;;;;;;;;

		; UNIX: "/path1:/path2"  
		include_path = ".:/usr/local/lib/php"


		5) Edit Inline_C.php - configure the pathes in the header part.

		6) run a test-script by: ./test.php 	

		7) There is a ZEND_API_NO hack - if you call the constructor of Inline_C by  Inline_C() 
		the system ZEND_API_NO no is used. If you call  Inline_C("api_hack") a generic no is 
		used.