How to obtain and install GNU Pascal (GPC) for DOS/DJGPP [1.03] ======================================================== 1. Introduction Caution - While the information contained herein is believed to be mostly accurate, you are advised that it might contain some errors, possibly even serious ones. It is provided "AS IS", so use it at your own risk. This document is intended to provide concise yet comprehensive instructions, for obtaining and installing the DOS port of the GNU Pascal Compiler (GPC), for the DJGPP development environment (www.delorie.com/djgpp). No previous experience with DJGPP is assumed. GPC supports the ISO-7185 and most of the ISO-10206 standard Pascal dialects, and additionally, most proprietry dialect extensions. The various DJGPP packages mentioned here were the most recent at the time of writing. You should be able to use later versions if and when they become available, except for the 'gcc2953b' and 'gpp2953b' C/C++ packages, which GPC currently uses for it's code generator "back end". Any trademarks that may be found in this document are the property of their respective owners and are used solely for identification purposes. 2. Long file names You need to decide whether or not your development environment will use "long file names". The use of "long file names" is assumed by DJGPP versions 2.01 and later, however, it is possible to create a fully functional DJGPP environment using a traditional "8+3" DOS file system. Once you have decided on your file name system, you must use it consistently, else your DJGPP environment will likely be "broken". However, if you are adventurous, you may be able to install DJGPP/GPC in such a way that it will work under either file name system - see "http://www.delorie.com/djgpp/v2faq/faq22_19.html" for details. Long filename systems are : - MS-W95/98/ME (MS-DOS 7.XX) "DOS prompt" window. - MS-DOS 7.XX (MS-W9X "DOS mode") with DOSLFN (see note). - MS-DOS 6.XX with DOSLFN ??? - PC-DOS 6.XX, 7.00, 2000 with DOSLFN ??? - DR-DOS 7.02 or later with DOSLFN. - OpenDOS 7.01 with DOSLFN ??? Traditional 8+3 filename systems are : - MS-DOS 7.XX (MS-W95/98/ME) in "DOS mode" (without GUI or DOSLFN). - MS-DOS 5.XX, 6.XX without DOSLFN. - PC-DOS 5.XX, 6.XX, 7.00, 2000 without DOSLFN. - DR-DOS/Novell-DOS/OpenDOS 5.XX, 6.XX, 7.XX without DOSLFN. Note, DOSLFN is a TSR which provides a "long file name" API for some DOS systems (www.tu-chemnitz.de/~heha/hs_freeware/doslfn.zip). 3. Unzipping tools DJGPP packages are normally available as ZIP archives, so you will obviously need unzipping software. However, your choice here is not arbitrary, rather, it depends on whether or not you have chosen to use a "long file name" system, as follows : - For traditional 8+3 filename systems, you will need InfoZip's (www.info-zip.org) UNZIP program. InfoZip's UNZIP32 program is probably also suitable here. PKUNZIP 2.50 is not suitable. - For long filename systems, you will need InfoZip's UNZIP32 program. PKUNZIP 2.50 is suitable only in an MS-W "DOS window", and only if using the default MS-W "NameNumericTail" registry setting. 4. What packages to download If you haven't installed these DJGPP packages already, you will need to download them via "http://www.simtel.net/pub/djgpp/" : - v2/djdev203.zip (DJGPP development kit and RTL) - v2/faq230b.zip (FAQ's in various formats) - v2gnu/gcc2953b.zip (C compiler) - v2gnu/gpp2953b.zip (C++ compiler, optional) - v2gnu/mak3791b.zip (Make utility, optional) - v2gnu/bnu2112b.zip (Binary utilities) - v2gnu/txi42b.zip (Texinfo hypertext system) - v2misc/csdpmi5b.zip (DPMI server - if required, see below) Download GPC 2.1 and libraries from "http://gnu-pascal.de/" : - binary/gpc-2.1.i586-pc-msdosdjgpp.zip - libs/binary/i386-pc-msdosdjgpp/rx-1.55-i386-pc-msdosdjgpp.zip - libs/binary/i386-pc-msdosdjgpp/gmp-4.0.1-i386-pc-msdosdjgpp.zip - libs/binary/i386-pc-msdosdjgpp/pdcurses-2.4-i386-pc-msdosdjgpp.zip Note, see "http://gnu-pascal.de/contrib/maurice/" for alternative versions of the GPC compiler, including latest alpha/beta binaries. Alternative downloads, via "http://www.simtel.net/pub/djgpp/" : - v2gnu/gmp401b.zip (GNU Multiple Precision Arithmetic) - v2tk/pdcur24b.zip (Generic screen terminal interface) Note - You may not require the CSDPMI package if your environment already provides suitable DPMI services, for example MS-W9X, etc. Beware however, some DPMI implementations have been known to have compatibility problems with DJGPP, in which case these should be disabled, in favour of CSDPMI (cwsdpmi.exe). 5. Installing the packages All packages for DJGPP are installed in a common directory tree, commonly "C:\DJGPP". If you wish, you may choose any other directory for your DJGPP development software, except for "C:\DEV", "D:\DEV", etc. or any subdirectory of these. Now, assuming you are installing DJGPP & GPC "from scratch" ... - Create your chosen directory for DJGPP. Eg. : MD C:\djgpp - Change to your chosen directory. Eg. : C: CD \djgpp - Unzip each package from (4), using the appropriate unzipping utility, and preserving the archive's directory structure. Eg. : UNZIP32 LocationOfZipFiles\ZipFileName Except for 'cxxfilt.exe', all the files contained in the various ZIP archives should be unique (ie. not duplicated in multiple archives). In the case of 'cxxfilt.exe', the one in 'bnu2112b.zip' appears to be newer, so should be preferred to the one in 'gpp2953b.zip'. 6. Configuration Firstly, edit your 'autoexec.bat' file to add the DJGPP 'bin' directory to your PATH and create an environment variable 'DJGPP' which "points to" the DJGPP 'djgpp.env' file. (You will need to reboot for these changes to take effect.) Eg. : SET PATH=C:\djgpp\bin;%PATH% SET DJGPP=C:\djgpp\djgpp.env Now, edit the DJGPP 'djgpp.env' file. Locate the [gcc] section and duplicate it to create a [gpc] section. Additionally, create a new [gpcpp] section. The result should be similar to the following : [gcc] COMPILER_PATH=%/>;COMPILER_PATH%%DJDIR%/bin LIBRARY_PATH=%/>;LIBRARY_PATH%%DJDIR%/lib [gpc] COMPILER_PATH=%/>;COMPILER_PATH%%DJDIR%/bin LIBRARY_PATH=%/>;LIBRARY_PATH%%DJDIR%/lib [gpcpp] C_INCLUDE_PATH=%/>;C_INCLUDE_PATH%%DJDIR%/include Finally, edit the DJGPP 'info\dir' file. Locate the section ... From gccNNNb.zip * CPP: (cpp). The GNU C-Preprocessor * GCC: (gcc). The GNU C, C++, and Objective-C Compiler ... and add the following new section : From gpcNNNb.zip * GPC: (gpc). The GNU Pascal Compiler 7. Usage notes Since the GPC compiler can be invoked to compile either Pascal or C/C++ programs, it requires that source files have an appropriate filename extension and that this is specified when you invoke the compiler. For instance, to compile a source file 'test.pas', you must type "GPC test.pas", not just "GPC test". In addition, there may be command line switches that are appropriate, one of the most common of which is "--autobuild" (eg. "GPC --autobuild test.pas"). The documentation for GPC and DJGPP is based on a simple hypertext system called Info. This is accessed by typing "info TopicName", for instance, "info gpc" to access the GPC documentation, or just "info" to access the top level of the documentation. The first "TopicName" you will need to access however, is "Info" itself, to learn how to operate this hypertext system (ie. type "info info"). 8. Executable file issues Once you have successfully compiled your program, you will (by default) have an executable file called "A.EXE" and an object file called "A.OUT", both of which are over 450K bytes in size. You can delete the latter, and you can rename "A.EXE" to something more appropriate, of course. However, you may also want to reduce the size of your executable file ... The first step to reducing the size of your executable file is to strip symbol information from the file, by typing "strip a.exe". The second step is to apply an executable packer, such as "UPX" (http://upx.sourceforge.net) or "WDOSX", which incorporates "APACK" compression (http://michael.tippach.bei.t-online.de/wdosx). Both packers will result in a substantially reduced file size, particularly "UPX" (as low as 125K bytes). However, "WDOSX" is not simply an executable packer, it is primarily a "DOS extender", embedding a DPMI server within executable files created with DJGPP, whereas these files normally depend on external DPMI services, with fallback to CSDPMI (cwsdpmi.exe). You should be aware however, that programs stubbed with "WDOSX" lack a built-in maths co-processor (FPU) emulator capability, such as provided with CSDPMI. Consequently, on 386/486SX systems without an FPU fitted, a warning message will be displayed when the program is invoked and, if the program actually attempts to use the non-existant FPU, it will crash. However, if a suitable (external) FPU emulator package is available, it is still possible to use programs stubbed with "WDOSX" on such systems, without these problems. Executable files which are not stubbed using "WDOSX" will require external DPMI services, so should be distributed together with CSDPMI (cwsdpmi.exe), just in case the recipient doesn't already have a DPMI server. Generally, all that DJGPP programs require is for CWSDPMI.EXE to be in the user's path (one exception is LD.EXE, the DJGPP linker, which seems to expect that CWSDPMI.EXE be in the DJGPP 'bin' directory). Joe da Silva