Mega Code Archive

 
Categories / Delphi / Examples
 

How to use the command line compiler

Title: How to use the command line compiler Question: The great advantage is to have a unified configuration file of the project configuration settings when you work in a team or on different machines. So you are independent of installed packages, options or components in the IDE. The magic of the command-line compiler. Answer: The great advantage is to have a unified configuration file of the project configuration settings when you work in a team. So you are independent of installed packages, options or components in the IDE. More you are in a certain context independent of the machine and each developer runs the same configuration file over the INTRANET. So we never again have to listen on sentences like this: On my machine the app is just fine ;) Further small non visual changes are possible in a simple editor and just start the clc. The command-line compiler (clc) lets you invoke all functions of the IDE from a command line shell. Running the clc from the command line prompt using the syntax: dcc32 [options] filename [options] for example you work with a project named mcclient.dpr you type in the shell or start the equivalent batch: D:\Programs\Borland\Delphi7\Bin\dcc32 -B D:\FRANKT~1\DELPHMAX\LOADER\HEXER3\mcclient.dpr Then you get something like this: -------------------------------------------------------------------- Borland Delphi Version 15.0 Copyright (c) 1983,2002 Borland Software Corporation 14 lines, 1.67 seconds, 337236 bytes code, 7661 bytes data. -------------------------------------------------------------------- where options are zero or more parameters that provide information to the compiler and filename is the name of the source file to compile. Option -B means to build all units. Note: The command-line compiler options are not case-sensitive. To display a help screen of command-line options and syntax you just type dcc32. If the source text contained in filename is a program, the compiler creates an executable file named filename.exe. If filename contains a library, the compiler creates a filename.dll or if filename contains a package, the compiler creates filename.bpl or with a unit, the compiler creates filename.dcu. You can specify a number of options for the clc. An option consists of a slash (/) or hyphen (-) immediately followed by an option letter. In some cases, the option letter is followed by additional information, such as a number, a symbol, or a directory name. So the magic is found in a configuration file named DCC32.cfg or in our case mcclient.cfg which is build by Delphi. The compiler searches for a dcc32.cfg in the compiler executable directory, then for dcc32.cfg in the current directory, and then finally for projectname.cfg in the project directory. In our case we deal with two configuration files: - DCC32.cfg for Delphi specific or general options and libraries - mcclient.cfg for Project specific options and libs You can set up a list of options in a configuration file, which will then be used in addition to the options entered on the command line. Each line in configuration file corresponds to an extra command-line argument inserted before the actual command-line arguments. Thus, by creating a configuration file, you can change the default setting of any command-line option. So you have to know that the clc lets you enter the same command-line option several times, ignoring all but the last occurrence. This way, even though you've changed some settings with a configuration file, you can still override them on the command line. When dcc32 starts, it looks for DCC32.CFG in the current directory. If the file isn't found there, dcc32 looks in the directory where DCC32.EXE resides. Here's an example DCC32.CFG file, defining some default directories for include, object, and unit files, and changing the default states of the $O and $R compiler directives: -ID:\DELPHI\INC;D:\DELPHI\SRC -OD:\DELPHI\ASM -UD:\DELPHI\UNITS -$R+ -$O- -aWinTypes=Windows;WinProcs=Windows;DbiProcs=BDE;DbiTypes=BDE;DbiErrs=BDE -u"D:\Programme\Borland\Delphi7\lib";"D:\Programme\Borland\Delphi7\lib\Obj" You can also type: make -f -B Hexer2projectgroup.bpg to compile all the targets in the project group! Many version control systems are also indepedent of the IDE and you can control them in a make file. At last an example of our project configuration file with some explanations: mcclient.cfg ----------------------------------------------------------- -$A8 -$B- -$C+ -$D+ -$E- -$F- -$G+ -$H+ -$I+ -$J- -$K- -$L+ -$M- -$N+ -$O+ -$P+ -$Q- -$R- -$S- -$T- -$U- -$V+ -$W- -$X+ -$YD -$Z1 -GP -cg -H+ -W+ -M -$M16384,1048576 -K$00400000 -LU"W:\franktech\Delphmax\Loader\hexer3\rpackages\" //The -U option lets you specify additional directories in which to search for run time packages. -U"W:\franktech\Delphmax\Loader\hexer3\units\" //The -U option lets you specify additional directories in which to search for units. -LE"W:\franktech\Delphmax\Loader\hexer3\bpl" //This option tells the clc where to put the file it creates when it compiles a package. -LN"W:\franktech\Delphmax\Loader\hexer3\bpl" //This option tellsl the clc where to put the .dcp (package symbol info) file it creates. -E"D:\franktech\Delphmax\Loader\hexer3\executables" //This option lets you tell the clc where to put the executable file it creates. -w -UNSAFE_TYPE -w -UNSAFE_CODE -w -UNSAFE_CAST //Disabled Output warning messages one last compile on max.kleiner.com/download/pascalspeed.exe you can find a classic clc assembler app (10kb) which draws a fire on your screen ;) this is my one cent contribution to the 50th article.