From: Vadim Konovalov <vkonovalov@lucent.com>
Date: Sat, 9 Jun 2007 19:41:44 +0000 (+0200)
Subject: cross-compilation for linux
X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=608969de9d8f7b5ff63543f0fb8b9f3bee668da2;p=p5sagit%2Fp5-mst-13.2.git

cross-compilation for linux
From: "Konovalov, Vadim Vladimirovich \(Vadim\)** CTR **" <vkonovalov@alcatel-lucent.com>
Message-ID: <D16F05D0CAAA234BA2B753B80DE6100D278EBC@DEEXC1U02.de.lucent.com>

p4raw-id: //depot/perl@31362
---

diff --git a/Cross/Makefile-cross-SH b/Cross/Makefile-cross-SH
index c910a9b..bb1e0e3 100755
--- a/Cross/Makefile-cross-SH
+++ b/Cross/Makefile-cross-SH
@@ -327,9 +327,7 @@ CCCMDSRC = \`sh \$(shellflags) cflags-cross-${CROSS_NAME} "optimize='\$(OPTIMIZE
 ## In the following dollars and backticks do not need the extra backslash.
 $spitshell >>$Makefile <<'!NO!SUBS!'
 
-XCOREDIR	= ./xlib/$(CROSS_NAME)/CORE
-
-CONFIGPM = xlib/$(CROSS_NAME)/Config.pm xlib/$(CROSS_NAME)/Config_heavy.pl
+CONFIGPM = xlib/$(CROSS_NAME)/Config.pm
 
 private = preplibrary $(CONFIGPM) $(CROSS_LIB)/Config.pod
 
@@ -766,17 +764,11 @@ makeppport: miniperl$(EXE_EXT) $(CONFIGPM)
 	$(LDLIBPTH) ./miniperl$(EXE_EXT) -Ilib mkppport
 
 $(CROSS_LIB)/Config.pod: config.sh miniperl configpm Porting/Glossary
-	$(LDLIBPTH) ./miniperl -Ilib configpm --cross=$(CROSS_NAME) --heavy=$(CROSS_LIB)/Config_heavy.pl
-	#TODO $(XCOPY) ..\*.h $(XCOREDIR)\*.*
-	#TODO $(XCOPY) ..\*.inc $(XCOREDIR)\*.*
-	#TODO $(XCOPY) *.h $(XCOREDIR)\*.*
-	#TODO $(XCOPY) ..\ext\re\re.pm $(LIBDIR)\*.*
-	#TODO $(RCOPY) include $(XCOREDIR)\*.*
-	#TODO $(LDLIBPTH) ./miniperl -Ilib -MCross=$(CROSS_NAME) config_h.PL "INST_VER=$(INST_VER)" "CORE_DIR=$(XCOREDIR)" "CONFIG_H=xconfig.h"
-	#TODO cp xconfig.h $(CROSS_LIB)/config.h
-	#TODO cp xconfig.h $(CROSS_LIB)/xconfig.h
-
-$(CONFIGPM): $(CROSS_LIB)/Config.pod
+	$(LDLIBPTH) ./miniperl -Ilib configpm --cross=$(CROSS_NAME)
+	cp *.h $(CROSS_LIB)/
+	cp ext/re/re.pm $(LIBDIR)/
+
+$(CONFIGPM): $(CROSS_LIB)/Config.pod xconfig.h
 
 lib/re.pm: ext/re/re.pm
 	@-rm -f $@
@@ -1103,7 +1095,9 @@ config.h: config_h.SH config.sh
 
 xconfig.h: config_h.SH Cross/config-$(CROSS_NAME).sh
 	CONFIG_SH=Cross/config-$(CROSS_NAME).sh CONFIG_H=xconfig.h $(SHELL) config_h.SH
+	#TODO $(LDLIBPTH) ./miniperl -Ilib -MCross=$(CROSS_NAME) config_h.PL "INST_VER=$(INST_VER)" "CORE_DIR=$(CROSS_LIB)" "CONFIG_H=xconfig.h"
 	cp xconfig.h $(CROSS_LIB)/
+	cp xconfig.h $(CROSS_LIB)/config.h
 
 # When done, touch perlmain.c so that it doesn't get remade each time.
 .PHONY: depend
diff --git a/Cross/README b/Cross/README
index ea848b4..683ef93 100644
--- a/Cross/README
+++ b/Cross/README
@@ -34,17 +34,14 @@ your path.
 Your built Perl environment is in install_me_here/ in your build
 directory.  From here you can package and deploy as you wish.
 
-The Obvious Ommissions
-----------------------
+Omissions
+----------
 
-This does NOT perform any installation as site installation method
-will be dependent on the target architecture and OS. 
+This does NOT perform any installation.
 
-make test will NOT work as the binaries and libraries will not execute
-on your BUILD machine. 
+Make test will NOT work.
 
-Due to space limitations on the Zaurus (it's a PDA) we do not provide
-documentation in the core - Therefore man pages are not even generated.
+We do not provide documentation in the core,  man pages are not generated.
 
 Other Targets (For Developers)
 ------------------------------
diff --git a/Cross/README.new b/Cross/README.new
new file mode 100644
index 0000000..05e59f6
--- /dev/null
+++ b/Cross/README.new
@@ -0,0 +1,89 @@
+You're reading ./Cross/README.new, describing Perl cross-compilation process.
+NOTE: this file will replace ./Cross/README, after cross-compilation scheme
+will stabilize;
+
+=head1 Cross-compilation for linux
+
+This is second approach to linux cross-compiling, which should allow building
+full perl and entensions for target platform. Cross-compiling for linux
+uses similar approach and share same files as cross-compiling for WINCE.
+
+We refer to HOST as the platform where the build is performed, and to
+TARGET as where final executables will run.
+
+=head2 Basic ideas
+
+=head3 common
+
+Unlike WINCE, output files from GCC cross-compiler are produced in the same
+directory where C files are. All TARGET binaries have different extensions
+so to distinguish HOST and TARGET binaries. Namely, object files for C<arm>
+cross-compilation will have extension C<.armo>, executable files will have
+C<.arm>.
+
+After typical cross-compilation the following files will be built, among
+others:
+
+  sv.c
+  sv.o
+  sv.armo
+  libperl.arma
+
+(this approach may be reconsidered, however.)
+
+=head3 build process
+
+C<miniperl> is built. This executable is intended to run on HOST, and it
+will facilitate the remaining build process; all binaries built after it are
+foreign (TARGET) and should not run locally (HOST).
+
+Unlike HOST build, miniperl will not have C<Config.pm> of HOST within reach;
+it rather will use the C<Config.pm> from the cross-compilation directories.
+In fact, if the build process does have Config.pm within reach, this is only
+an indication of a mistake somewhere in the middle.
+
+  # following command is okay:
+  ./miniperl -Ilib -MCross -MConfig -e 1
+  # following command should cluck, and it is bad if it does not:
+  ./miniperl -Ilib -MConfig -e 1
+
+After C<miniperl> is built, C<configpm> is invoked to create right C<Config.pm>
+in right place and its corresponding Cross.pm.
+
+File C<Cross.pm> is dead simple: for given cross-architecture places in @INC
+a path where perl modules are, and right C<Config.pm> in that place.
+
+That said, C<miniperl -Ilib -MConfig -we 1> should report an error, because
+it can not find C<Config.pm>. If it does not give an error -- wrong C<Config.pm>
+is substituted, and resulting binaries will be a mess.
+
+C<miniperl -MCross -MConfig -we 1> should run okay, and it will provide right
+C<Config.pm> for further compilations.
+
+During extensions build phase, the script C<./ext/util/make_ext_cross> is
+invoked.
+
+All invokes of C<Makefile.PL> are provided with C<-MCross> so to enable cross-
+compile.
+
+=head2 BUILD
+
+=head3 Tools & SDK
+
+For compiling, you need following:
+
+=over 4
+
+=item * TODO
+
+=back
+
+=head1 Things to be done
+
+=over 4
+
+=item * better distinguishing of config.h/xconfig.h, dependancies
+
+=item * object files created in ./xlib/cross-name/ ?
+
+=back
diff --git a/Cross/build-arm-n770-sh b/Cross/build-arm-n770-sh
index a43236e..75922e5 100755
--- a/Cross/build-arm-n770-sh
+++ b/Cross/build-arm-n770-sh
@@ -3,6 +3,8 @@
 # this approach is like Perl-CE cross-compiling, and allows
 # for full TARGET perl (as opposed to renamed miniperl)
 
+# to skip Configure/build for HOST miniperl, pass "noconf" argument to this script
+
 # some trick is different, however - the file extension for objects files
 # are choosen to be .${CROSS_NAME}, .armo in our case
 
@@ -31,8 +33,7 @@ cp config.sh-arm-linux-n770 config-${CROSS_NAME}.sh
 # following should be done better:
 cd ..
 
-if false
-then
+if [[ "x$1" != xnoconf* ]] ; then
 # do miniperl on HOST
 ./Configure -des -D prefix=./dummy -Dusedevel
 make miniperl
@@ -57,10 +58,8 @@ PERL_CONFIG_SH=Cross/config-${CROSS_NAME}.sh
 rm cflags-cross-$CROSS_NAME
 cp Cross/cflags-cross-$CROSS_NAME .
 rm Makefile-cross-$CROSS_NAME
-sh Cross/Makefile-cross.SH
+sh Cross/Makefile-cross-SH
 cp Cross/Makefile-cross-$CROSS_NAME .
-# makefile hack-patching TODO generation from Makefile.SH
-#./miniperl -pi.bak -w0777ne "s{^(CCCMD.*?)cflags}{\$1cflags-cross-$CROSS_NAME}gm" Makefile-cross-$CROSS_NAME
 
 mkdir xlib
 mkdir xlib/$CROSS_NAME
diff --git a/MANIFEST b/MANIFEST
index fcdb71c..194ec52 100644
--- a/MANIFEST
+++ b/MANIFEST
@@ -36,6 +36,7 @@ Cross/Makefile.SH.patch	Cross-compilation
 Cross/Makefile-cross-SH	Cross-compilation
 Cross/cflags-cross-arm	Cross-compilation
 Cross/README		Cross-compilation
+Cross/README.new	Cross-compilation
 Cross/TODO		Cross-compilation
 Cross/warp		Cross-compilation
 cv.h			Code value header
diff --git a/README.ce b/README.ce
index 5d338c8..25cef84 100644
--- a/README.ce
+++ b/README.ce
@@ -39,7 +39,7 @@ File C<Cross.pm> is dead simple: for given cross-architecture places in @INC
 a path where perl modules are, and right C<Config.pm> in that place.
 
 That said, C<miniperl -Ilib -MConfig -we 1> should report an error, because
-it can not find C<Config.pm>. If it does not gives an error -- wrong C<Config.pm>
+it can not find C<Config.pm>. If it does not give an error -- wrong C<Config.pm>
 is substituted, and resulting binaries will be a mess.
 
 C<miniperl -MCross -MConfig -we 1> should run okay, and it will provide right
diff --git a/win32/Makefile.ce b/win32/Makefile.ce
index c7b5a50..7503656 100644
--- a/win32/Makefile.ce
+++ b/win32/Makefile.ce
@@ -710,7 +710,7 @@ all: hostminiperl $(MINIMOD) $(CONFIGPM) $(UNIDATAFILES) $(PERLEXE) MakePPPort E
 
 $(DYNALOADER)$(o) : $(DYNALOADER).c xconfig.h $(EXTDIR)\DynaLoader\dlutils.c
 
-$(CONFIGPM) : $(HPERL) ..\config.sh config_h.PL ..\minimod.pl
+$(CONFIGPM) : $(HPERL) ..\config.sh .\xconfig.h config_h.PL ..\minimod.pl
 	cd .. && $(HPERL) configpm --cross=$(CROSS_NAME) --no-glossary
 	-mkdir $(XCOREDIR)
 	$(XCOPY) ..\*.h $(XCOREDIR)\*.*
@@ -718,12 +718,12 @@ $(CONFIGPM) : $(HPERL) ..\config.sh config_h.PL ..\minimod.pl
 	$(XCOPY) *.h $(XCOREDIR)\*.*
 	$(XCOPY) ..\ext\re\re.pm $(LIBDIR)\*.*
 	$(RCOPY) include $(XCOREDIR)\*.*
-	-$(HPERL) -I..\lib -MCross=$(CROSS_NAME) config_h.PL "INST_VER=$(INST_VER)" "CORE_DIR=$(XCOREDIR)" "CONFIG_H=xconfig.h"
-	$(XCOPY) xconfig.h $(XCOREDIR)\config.h
 
 .\xconfig.h:
 	-del /f xconfig.h
-	copy config_H.ce xconfig.h
+	-mkdir $(XCOREDIR)
+	-$(HPERL) -I..\lib -MCross=$(CROSS_NAME) config_h.PL "INST_VER=$(INST_VER)" "CORE_DIR=$(XCOREDIR)" "CONFIG_H=xconfig.h"
+	$(XCOPY) xconfig.h $(XCOREDIR)\config.h
 
 ..\config.sh: config.ce config_sh.PL
 	$(HPERL) -I..\lib -I. config_sh.PL $(CFG_VARS) config.ce > ..\config.sh