3- COMPILAR (Y MÁS COSAS) PARA CREAR EL NUEVO COMPILADOR




Este es el punto del que menos me acuerdo de como se hacía.
 
 

 He encontrado un archivo readme. en bailalo\s6\pp\source\compiler que me dice de ejecutar:
mppc386.bat

Pero este me sobreescribiría el ppc386 que tengo en ese directorio no me vale.
Y me parece que no lo compilaba así. Veamos en un pdf online.

http://www.freepascal.org/docs/prog.pdf

Este en concreto. Y nos vamos a Compiling the Compiler yourself.
Y a Compiling by hand.

Hay varias opciones, seguramente haya usado varias, y me haya quedado con una de ellos.
No me acuerdo cual use.

Voy a copiar las instrucciones, para tenerlas presentes si alguna vez las cambian.

=== Extracto del prog.pdf

F.4 Compiling by hand
Compiling by hand is difficult and tedious, but can be done. We’ll treat the compilation of RTL and
compiler separately.
F.4.1 Compiling the RTL
To recompile the RTL, so a new compiler can be built, at least the following units must be built, in
the order specified:
loaders the program stubs, that are the startup code for each pascal program. These files have the .as
extension, because they are written in assembler. They must be assembled with the GNU as
assembler. These stubs are in the OS-dependent directory, except for LINUX, where they are
in a processor dependent subdirectory of the linux directory (i386 or m68k).
system the system unit. This unit is named differently on different systems:
Only on GO32v2, it’s called system.
For LINUX it’s called syslinux.
For WINDOWS NT it’s called syswin32.
For OS/2 it’s called sysos2
This unit resides in the OS-dependent subdirectories of the RTL.
strings The strings unit. This unit resides in the inc subdirectory of the RTL.
dos The dos unit. It resides in the OS-dependent subdirectory of the RTL. Possibly other units will
be compiled as a consequence of trying to compile this unit (e.g. on LINUX, the linux unit will
be compiled, on go32, the go32 unit will be compiled).
objects the objects unit. It resides in the inc subdirectory of the RTL.
To compile these units on a i386, the following statements will do:

ppc386 -Tlinux -b- -Fi../inc -Fi../i386 -FE. -di386 -Us -Sg syslinux.pp
ppc386 -Tlinux -b- -Fi../inc -Fi../i386 -FE. -di386 ../inc/strings.pp
ppc386 -Tlinux -b- -Fi../inc -Fi../i386 -FE. -di386 dos.pp
ppc386 -Tlinux -b- -Fi../inc -Fi../i386 -FE. -di386 ../inc/objects.pp
These are the minimum command-line options, needed to compile the RTL.
For another processor, you should change the i386 into the appropriate processor. For another
operating system (target) you should change the syslinux in the appropriate system unit file, and you
should change the target OS setting (-T).
Depending on the target OS there are other units that you may wish to compile, but which are not
strictly needed to recompile the compiler. The following units are available for all plaforms:
objpas Needed for Delphi mode. Needs -S2 as an option. Resides in the objpas subdirectory.
sysutils many utility functions, like in Delphi. Resides in the objpas directory, and needs -S2 to
compile.
typinfo functions to access RTTI information, like Delphi. Resides in the objpas directory.
math math functions like in Delphi. Resides in the objpas directory.
mmx extensions for MMX class Intel processors. Resides in in the i386 directory.
getopts a GNU compatible getopts unit. resides in the inc directory.
heaptrc to debug the heap. resides in the inc directory.
F.4.2 Compiling the compiler
Compiling the compiler can be done with one statement. It’s always best to remove all units from
the compiler directory first, so something like
rm *.ppu *.o
on LINUX, and on DOS
del *.ppu
del *.o
After this, the compiler can be compiled with the following command-line:
ppc386 -Tlinux -Fu../rtl/linux -di386 -dGDB pp.pas
So, the minimum options are:
1. The target OS. Can be skipped if you’re compiling for the same target as the compiler you’re
using.
2. A path to an RTL. Can be skipped if a correct ppc386.cfg configuration is on your system. If
you want to compile with the RTL you compiled first, this should be ../rtl/OS (replace the OS
with the appropriate operating system subdirectory of the RTL).
3. A define with the processor you’re compiling for. Required.
4. -dGDB is not strictly needed, but is better to add since otherwise you won’t be able to compile
with debug information.
Table F.1: Possible defines when compiling FPC
Define does what
USE_RHIDE Generates errors and warnings in a format recognized
by RHIDE.
TP Needed to compile the compiler with Turbo or Borland Pascal.
Delphi Needed to compile the compiler with Delphi from Borland.
GDB Support of the GNU Debugger.
I386 Generate a compiler for the Intel i386+ processor family.
M68K Generate a compiler for the M68000 processor family.
USEOVERLAY Compiles a TP version which uses overlays.
EXTDEBUG Some extra debug code is executed.
SUPPORT_MMX only i386: enables the compiler switch MMX which
allows the compiler to generate MMX instructions.
EXTERN_MSG Don’t compile the msgfiles in the compiler, always use
external messagefiles (default for TP).
NOAG386INT no Intel Assembler output.
NOAG386NSM no NASM output.
NOAG386BIN leaves out the binary writer.
5. -Sg is needed, some parts of the compiler use goto statements (to be specific: the scanner).
So the absolute minimal command line is
ppc386 -di386 -Sg pp.pas
You can define some other command-line options, but the above are the minimum. A list of recog-nised
options can be found in table (F.1).
This list may be subject to change, the source file pp.pas always contains an up-to-date list.

=== Fin extracto prog.pdf

Bueno ya está. Voy a remirarmela otra vez.

Vamos a ver segun nos dice antes de poder hacer un nuevo compilador tenemos que tener compilado
el rtl.

Deberemos ejecutar:
ppc386 -Tlinux -b- -Fi../inc -Fi../i386 -FE. -di386 -Us -Sg syslinux.pp
ppc386 -Tlinux -b- -Fi../inc -Fi../i386 -FE. -di386 ../inc/strings.pp
ppc386 -Tlinux -b- -Fi../inc -Fi../i386 -FE. -di386 dos.pp
ppc386 -Tlinux -b- -Fi../inc -Fi../i386 -FE. -di386 ../inc/objects.pp

que traducido a lo que es nuestro DOS será:

ppc386 -TGO32V2 -b- -Fi../inc -Fi../i386 -FE. -di386 -Us -Sg system.pp
ppc386 -TGO32V2 -b- -Fi../inc -Fi../i386 -FE. -di386 ../inc/strings.pp
ppc386 -TGO32V2 -b- -Fi../inc -Fi../i386 -FE. -di386 dos.pp
ppc386 -TGO32V2 -b- -Fi../inc -Fi../i386 -FE. -di386 ../inc/objects.pp

Creo que no me equivoco al poner como target GO32V2, DOS no me suena como tal.
Vale y cambio el syslinux.pp por system.pp

Ahora me surge la duda donde demonios (en que directorio) ¿hay que ejecutar esto?

Bueno vamos a suponer... que lo hacemos en ... tal y como están los directorios no veo donde hay que hacerlo... bueno... creo que el rtl al final no lo compile. Este punto más tarde lo revisaré.
 

En fpc-devel Preguntar la mejor manera de compilar un nuevo compilador con un nuevo rtl y si ese rtl hay que cambiarlo o no.
 

Vayamos con compilar el compilador.

Primero en el directorio del compilador: bailalo\s6\pp\source\compiler

*** Nota
Para que esto funcione ha de estar en el path, el ppc386 que es el compilador original del
pascal que se encuentra en:

bailalo\s6\pp\bin\go32v2

Por ejemplo, para añadir el path sería:
path=%path%;d:\bailalo\s6\pp\bin\go32v2
*** Fin Nota

hay que borrar los *.ppu y los *.o
del *.ppu
y
del *.o

Luego la instrucción:
ppc386 -Tlinux -Fu../rtl/linux -di386 -dGDB pp.pas
que será para nosotros:
ppc386 -TGO32V2 -Fu..\rtl\go32v2 -di386 -dGDB pp.pas

He estado mirando y... el directorio bailalo\s6\pp\source\rtl\go32v2

no existe... voy a suponer que... YA ME ACUERDO... Compile el compilador sin el rtl.

Y esto se hace así:

ppc386 -di386 -Sg pp.pas

en el directorio: bailalo\s6\pp\source\compiler

Esto te crea, si va bien que aun no lo he comprobado, un pp.exe que es el que se copia
al directorio pp2\bin\go32v2 y se borra el pp.exe de donde estaba antes, es decir del
bailalo\s6\pp\source\compiler.

Con esto ya tenemos nuestro compilador: pp.exe
que sin embargo necesita buscar un rtl... para compilar cualquier tipo de archivo.

Comprobar que la compilación en verdad es así. Porque sino no se puede repetir el proceso y...
es una faena. Yo tenía un problema con la inclusión de más de 3 directorios en la linea de comandos, o aquí o en el siguiente apartado de compilar archivos hispascal. Hay que ver ese error.

Yo recuerdo que había que hacer algo de ensamblador y que necesitabamos unas utilidades gnu para ensamblar.