CSDJGPP3.DOC  Robin Whittle 11 September 1995
--------------------------------------------

This explains how to get the DJGPP compliler and set it up so you can 
compile Csound.  It is based on my experiences in May 95, with DJGPP 
1.12.  There is now a version 2 DJGPP, which I have not used yet.

This also documents how I got the csound source from John Fitch's ftp 
site at Bath University, and how I tweaked a few things so I could 
compile it.  Parts of this are relevant now, because it explains what 
I had to do to the 14 April 95 source code to compile it.  That 
release serves as the basis for my Csound work.

John Fitch has later releases at the Bath site now.

This is based on stuff written in May, but has been edited and updated 
in September 95.


Intended Audience
-----------------

This is likely to be of interest to anyone using Csound on MSDOS, and 
to people just starting to use DJGPP.  

For people unfamiliar with either of these:

Csound is a program for calculating sound - based on two text files, 
one for "score" and the other for the "orchestra". I think it is a 
fascinating way to make music.

DJGPP is a 32 bit C and C++ compiler for MSDOS, based on the Free 
Software Foundations GCC (Gnu C Compiler - GPP means Gnu for C Plus 
Plus?).  It was written by DJ Delorie, and is widely available under a 
licence based on that of the Free Software Foundation.

Check out DJ Delorie's WWW site at http://www.delorie.com for the 
latest - or check out the busy Usenet newsgroup comp.os.msdos.djgpp.



Getting DJGPP
-------------

After a false start with some very old files, I found the central ftp 
site for DJGPP.  HOST=oak.oakland.edu  DIR=pub/SimTel/vendors/djgpp
[Previously DIR=pub/SimTel/msdos/djgpp.]

[In September, everything looks the same as it was in May except for 
a newer faq102 file.]

There is a daunting array of files there. I downloaded DJGPP.FAQ 
(940807) and FAQ101.ZIP (950503) [Get the latest FAQs of any 
description!] and printed them out.  These told me that the Australian 
Mirror site was archie.au, and I found a complete mirror of the 
Oakland files at HOST=archie.au DIR=micros/pc/SimTel/vendors/djgpp

I retrieved all my files from the archie.au site: 
HOST=archie.au  DIR=micros/pc/SimTel/vendors/djgpp

The DJGPP package is complex, and parts of it are being upgraded from 
time to time.  There is a DJGPP newsgroup and WWW site as noted above.

The first question facing the newbie is "What files do I download?".  
FAQ101 (now faq102?) is the best source of advice here.  However it is 
not totally accurate with respect to the changing files and their 
functions.  The second essential reference was the 00_INDEX.TXT file, 
which was totally up-to-date on the files in the directory.  This 
gives brief discriptions of what the files are. I printed this out as 
well, and after thinking about things, made a list of what I wanted.  
This was not totally correct, but what I will report here is the 
correct list.

Here is the list of files I got, with their descriptions from the 
00_INDEX.TXT file, with extra notes on why I got them.  This will be 
useful guide to getting things in the future, but be sure to read the 
latest FAQ10x.ZIP and 00_INDEX.TXT.

bnu252bn.zip  B 1004073  950120  binutils-2.5.2 binaries (gas, ld, strip, etc)
bnu252dc.zip  B  286160  950120  binutils-2.5.2 sources (gas, ld, strip, etc)

cbgrd103.zip  B  258429  931207  GRX graphics library docs (for djgpp)
cbgrx103.zip  B  874383  931207  GRX graphics library libs/headers (for djgpp)

        The following maintenance updgrades are needed - they replace 
        buggy files in the entire DJGPP system, and delete unwanted 
        files.  

dj112m1.doc   A    2933  940903  djgpp's 1.12.maint1 update, documentation
dj112m1.zip   B  805698  940903  djgpp's 1.12.maint1 update, files
dj112m2.doc   A     773  940913  djgpp's 1.12.maint2 update, documentation
dj112m2.zip   B   79558  940913  djgpp's 1.12.maint2 update, files
dj112m3.doc   A    1491  950120  djgpp's 1.12.maint3 update, documentation
dj112m3.zip   B  168908  950120  djgpp's 1.12.maint3 update, files
dj112m4.doc   A     970  950131  djgpp's 1.12.maint4 update, documentation
dj112m4.zip   B   49707  950203  djgpp's 1.12.maint4 update, files

djdev112.zip  B  462241  940807  djgpp Base development kit
djdoc112.zip  B  224477  940807  djgpp Base documentation

djeoe112.zip  B  120681  940807  djgpp Execution only environment

djgpp.faq     A   14236  940807  Frequently asked questions about djgpp

djtst112.zip  B   28992  940807  djgpp test programs

faq101            57470  950503  FAQ list for DJGPP port of GCC and utilities

      This is the main set of binaries, but do not be fooled by the "includes 
      1.12.m4 fix (the maintenance 4 fix) because you still need all the 
      maintenance fixed to bring other elements of the system up-to-date.

gcc263bn.zip  B  628956  950131  gcc-2.6.3 binaries (C only) (incl 1.12.m4 fix)

gcc263dc.zip  B  853230  950120  gcc-2.6.3 documentation for djgpp

     I got the Gnu debugger as well, but have not used it yet.

gdb412bn.zip  B  656854  940807  gdb-4.12 binaries (for djgpp)
gdb412dc.zip  B  147106  940807  gdb-4.12 documentation (for djgpp)

     Get this if you want to do C++ - I do not at this stage.

gpp263.zip    B  681632  950120  gcc-2.6.3 cc1plus.exe (C++ compiler) for djgpp


     These update the cbgrx103.zip graphics library.

grx103m1.doc  A    1402  940331  Installation instructions for grx103m1.zip
grx103m1.zip  B   80323  940331  Maint. release for DJGPP GRX graphics library

     I didn't get these - maybe I should have.

install.dat   A    3530  940807  Data file for install.exe
install.exe   B   25782  940807  Install program for djgpp

     I got their MAKE program, rather than use one I had from Borland.

mak371bn.zip  B  102124  940807  make-3.71 binaries (for djgpp)
mak371dc.zip  B  228557  940807  make-3.71 documentation (for djgpp)

readme.1st    A    9302  950123  djgpp's installation instructions, 1.12
readme.dj     A   16749  940807  djgpp's setup instructions, 1.12

     This is the hypertext based help system - what kind of help system needs
     378k (compressed) of documentation??  I have fired it once and found 
     I wanted - just type INFO.

txi310bn.zip  B  153701  940807  texinfo-3.10 binaries inc info.exe (for djgpp)
txi310dc.zip  B  378420  940807  texinfo-3.10 documentation (for djgpp)

      I didn't get this - I used PKUNZIP -o -d instead.

unzip386.exe  B  193908  940807  Free unzip program for djgpp files (386 ver.)

Installing DJGPP
-----------------

The most complete installation instructions are in README.DJ, but 
parts of FAQ101 were useful as well.

I put all these files in a F:\DJGPP directory, and prepared an 
E:\DJGPP directory on E: drive.  I wanted a relatively simple 
mechanism for re-creating the system from the source files, since I do 
not always want the DJGPP files present.  They take up valuable space, 
and most annoying, it takes an excessively long time for XT-Gold to 
log drive E: with all these files.  The 22 .ZIP files occupy 7.6 
Megabytes and when expanded into the full DJGPP directory structure, 
there are 1329 files, occupying 17.5 Megabytes in 111 subdirectories. 

I prepared the following batch file to automate the process.  The 
order of some of the operations is crucial.  The maintenance fixes 
must come after the things they are supposed to fix.  

Each of the four main maintenence fixes also generate a batch file in 
/DJGPP, and this should be run to delete unwanted files.

I did not notice the installation program when I looked at the ftp 
site - maybe it does some of this stuff.

<<<< Start of UNZIPLOT.BAT with some rem doco lines removed.

rem Master file for unzipping DJGPP into its various subdirectories.

rem First the binaries.

pkunzip -o -d f:\djgpp\DJEOE112
pkunzip -o -d f:\djgpp\DJDEV112
pkunzip -o -d f:\djgpp\GCC263BN
pkunzip -o -d f:\djgpp\BNU252BN
pkunzip -o -d f:\djgpp\TXI310BN

pkunzip -o -d f:\djgpp\MAK371BN
pkunzip -o -d f:\djgpp\DJTST112
pkunzip -o -d f:\djgpp\GDB412BN

rem End of binaries - now do the graphics library.

pkunzip -o -d f:\djgpp\CBGRX103
pkunzip -o -d f:\djgpp\GRX103M1

rem Now do the documentation files.

pkunzip -o -d f:\djgpp\DJDOC112

rem The above is the first doc file.  However I presume I don't need to read 
rem anything in it regarding unzipping.

pkunzip -o -d f:\djgpp\GCC263DC
pkunzip -o -d f:\djgpp\BNU252DC
pkunzip -o -d f:\djgpp\CBGRD103
pkunzip -o -d f:\djgpp\GDB412DC
pkunzip -o -d f:\djgpp\MAK371DC
pkunzip -o -d f:\djgpp\TXI310DC

rem Now for the maintenance upgrades.

pkunzip -o -d f:\djgpp\DJ112M1
call 112M1

pkunzip -o -d f:\djgpp\DJ112M2
call 112M2

pkunzip -o -d f:\djgpp\DJ112M3
call 112M3

pkunzip -o -d f:\djgpp\DJ112M4
call 112M4

<<<< End of UNZIPLOT.BAT

While PKUNZIP is doing this, it sometimes complains that it cannot 
create some subirectories - this is fine, the complaint arises because 
they already exist.

The final stages of installation are well documented in README.DJ.  I 
changed my CONFIG.SYS to ensure there were plenty of files and 1k 
bytes of environment space.

I inserted E:\DJGPP\BIN in my PATH statement in my AUTOEXEC.BAT file.  

I made a policy decision never to have both my E:\BC (Borland Turbo 
C++ 2.0) and DJGPP in the path at the same time.  One problem was with 
which MAKE.EXE would run - and there could well be others too.  

Consequenly there is a note to this effect above the PATH line in the 
AUTOEXEC.BAT - I will re-edit it to put E:\BC there when I want. (Does 
anyone know how to make a path with longer than 128 characters?????)

Here is some magic incantations at the end of my AUTOEXEC.BAT file:

<<<<

rem  For CSOUND
rem  Put these in your autoexec.bat

SET SFDIR=f:\0snd
SET SSDIR=f:\0snd
SET SADIR=f:\0snd

rem     For CSOUND batch files and other things, make a long PROJ env variable
rem     so that when I run things in a DOS box under Win3.1, I can redefine the 
rem     PROJ environment variable without running out of environment space.

SET PROJ=AVERYLONGNAME

rem Various things for the DJGPP C Compiler:

SET DJGPP=E:/DJGPP/DJGPP.ENV
SET TMPDIR=F:/tmp
SET GO32TMP=F:/tmp

SET GO32=driver e:/DJGPP/DRIVERS/TRID89.GRD gw 800 gh 768

<<<<

I have not verified that the graphics driver stuff is valid.  There 
are quite a few GO32 parameters which I will probably set differently 
later.  For now, this was sufficient to run DJGPP.

I followed the FAQ101 instructions and sucessfully compiled HELLO.  I 
ran the TESTIT batch file - which seemed to do the right thing.

Then, after the tweaks described below, I was able to compile Csound!


Compiling CSOUND
----------------

I FTPed the csound_src.zip (406232 bytes 17 April 1995) file from 
ftp://ftp.maths.bath.ac.uk/pub/dream and put it in E:\CS_SOURCE. I 
also got csound_486.zip (728110 bytes 17 April 1995) which contains 
the full set of Csound executables.  The source and the 486 
executables were both version 3.28.12.  See README.csound (README.CS) 
(36596 bytes 14 April 1995) for a description of this version, which 
includes convolution, grainular synthesis, butterworth filters and a 
power function.

(I find the Bath FTP site to be slow at the best of times, and 
sometimes impossibly slow.  I got these files at a slow rate at an odd 
hour in Australia on the weekend, other times it would have taken me 
hours to get them.)

PKZIP -D expanded csound_s.zip into a CS_SOURCE directory.  This 
created a daunting array of files - with the paucity of comments which 
I find so distressing in a lot of C code - and Csound code.

I created a DOIT.BAT file to perform the compilation - in the 
CS_SOURCE directory.  It says "make -fmakefile.gcc"

I editted the MAKEFILE.GCC and after a few attempts, here are the 
results which I arrived at which are different from its original form.

At line 124 of the MAKEFILE.GCC (after "do not edit below this line") 
there is a command "aout2exe" to create an .EXE file from the  output 
of the compiler.  For DJGPP, this needs to be changed to "coff2exe".

To produce a standalone CSOUND.EXE, with GO32 built in, use the 
following command:  coff2exe -s e:\djgpp\bin\go32.exe csound 

Later, I changed area in the makefile to:



csound.exe:     $(COBJS) $(CSCM) $(CDEP)
                $(CC) -o csound $(COBJS) $(LIBS)

#RW was ...     aout2exe csound

#RW use . . .   coff2exe csound #for CSOUND.EXE to rely on an external GO32

#RW . . . however we want GO32 built into the CSOUND.EXE, so place GO32.EXE in
#RW       the same directory as the compilaton occurs in, and . . .

                coff2exe -s go32.exe csound



I changed the three directories for DEST, DESTDIR and MANDIR from 
c:\csound\xxx to:

DEST = e:\csound\beta
DESTDIR = e:\csound\beta
MANDIR = e:\csound\man

However these directories - which I had prepared to suit the makefile 
- had nothing in them after Csound was succesfully compiled.  I don't 
think these lines make any difference.

In line 332 of the original file, there was a typo which the compiler 
complained bitterly about.  A line starting:

DECaudio.o DECplay.o:

should have started:

DECaudio.o:

The same problem existed in the makefile.486.

When these changes were made, I was able to type DOIT, and lo and 
behold it would be DONE!  There were a number of warnings about such 
things as comparing pointers which were of disimilar types.  These are 
problems in the source code which really should be weeded out one day.

A CSOUND.EXE was produced which has a stub of code at the start which 
finds GO32 (the DOS extender).  GO32 uses the environment variable 
GO32 (see changes to AUTOEXEC.BAT) above and runs the program.

Then I made one more change to the MAKEFILE.GCC.  On line 36 are some 
command line parameters which are given to the DJGPP C compiler 
(GCC.EXE).  If the "-O" is changed to "-O2", then it optimises the 
code for speed.  Interestingly the file is exactly the same length, 
but the internal code is changed and shortened in sections. 

CFLAGS = -O2 $(DEFINES)


DJGPP version - speed and no graphics
-------------------------------------

This is the version which gave me the 4 hour 11 minute run for my 
SL_ONE piece (Spare Luxury One).  The one made with -O is only about 
2% slower.

The fully optimized DJGPP version took 124 seconds to calulate 10 
seconds of sound on another simpler piece.  The 17 April (Zortech?) 
486 version from John Fitch took 162 seconds.  So the DJGPP version 
had 1.3 times the throughput of the (Zortech?) 486 version.  A test 
with the Xanadu example files yeilded similar figures.  The DJPP 
version was 30% faster producing the first 22.6 seconds - 912 seconds 
compared to 1188.

John Fitch now used Watcom for his compilations and the speed seems 
comparable to the DJGPP version - it depends on the .orc and .sco 
files which of the two CSOUND.EXE programs is faster

This DJGPP version of Csound runs fine in a Windows 3.1 DOS Box.  
Pressing Control C will stop it after a few seconds.  GO32 does its 
best (within the limits of a DOS box if it is in one) to take over the 
machine and give Csound as much memory as it needs.  

I have not extensively tested the DJGPP version. One thing it does 
not do is use the graphics display for drawing graphs.  I expect that 
this would require some further work.  It might be difficult to make a 
generally distributable CSOUND.EXE using graphic display, since it 
seems that GO32 needs to be told to get a particular graphics driver 
for the various boards, and to be told some other things as well. GO32 
does some tricks to make the CSOUND program think it is writing to the 
display memory, when in fact GO32 is controlling things.  Since video 
boards vary significantly, GO32 needs to know about their specifics.  

So if you want a CSOUND.EXE which draws graphs, use one of John Fitch's 
versions.

From my reading of the documentation on licencing (in FAQ101) there is 
no restriction placed on what can be done with the CSOUND.EXE created 
by DJGPP - since I don't think it uses any of the code elements which 
are covered by licencing agreements.  This means that it should be 
fine to place this GCC compiled CSOUND on an ftp or WWW site - subject 
to whatever requirements there are for CSOUND in general.



Giving GO32 a temporary directory for a swap file
-------------------------------------------------

GO32 is the DOS extender which tries to provide the CSOUND program 
with all the memory it wants.  If this exceeds the RAM available via 
tha DPMI system in your machine, then it will use a disk file for 
swapping. This would certainly slow things down, but it enables CSOUND 
to use huge amounts of memory.

SET GO32TMP=F:/tmp

There is a GO32 environment variable which can tell it various things, 
such where to get the right one of its graphics drivers.  I suggest 
you get the DJGPP package if you want to check this out.


 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
 . Robin Whittle                      rwhittle@ozonline.com.au . 
 . http://www.ozemail.com.au/~firstpr   firstpr@ozemail.com.au .
 . 11 Miller St. Heidelberg Heights 3081 Melbourne Australia   .
 . Ph +61-3-9459-2889    Fax +61-3-9458-1736                   . 
 . Consumer advocacy in telecommunications, especially privacy .     
 .                                                             .
 . First Principles      - Research and expression - music,    .
 .                         music industry, telecommunications  .
 .                         human factors in technology adoption.
 .                                                             .   
 . Real World Interfaces - Hardware and software, especially   .
 .                         for music                           . 
 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 

