SDCC Compiler User Guide

SDCC Compiler User Guide

Chapter 2

Installing SDCC

For most users it is sufficient to skip to either section

2.4.1

or section

2.4.9

. More detailled instructions follow

below.

2.1

Configure Options

The install paths, search paths and other options are defined when running ’configure’. The defaults can be overridden by:

--prefix see table below

--exec_prefix see table below

--bindir see table below

--datadir see table below docdir environment variable, see table below include_dir_suffix environment variable, see table below lib_dir_suffix environment variable, see table below sdccconf_h_dir_separator environment variable, either / or \\ makes sense here. This character will only be used in sdccconf.h; don’t forget it’s a C-header, therefore a double-backslash is needed there.

--disable-mcs51-port Excludes the Intel mcs51 port

--disable-gbz80-port Excludes the Gameboy gbz80 port

--disable-z80-port Excludes the z80 port

--disable-avr-port Excludes the AVR port

--disable-ds390-port Excludes the DS390 port

--disable-hc08-port Excludes the HC08 port

--disable-pic-port Excludes the PIC port

--disable-xa51-port Excludes the XA51 port

--disable-ucsim Disables configuring and building of ucsim

--disable-device-lib-build Disables automatically building device libraries

--disable-packihx Disables building packihx

--enable-libgc Use the Bohem memory allocator. Lower runtime footprint.

8

2.1. CONFIGURE OPTIONS CHAPTER 2. INSTALLING SDCC

Furthermore the environment variables CC, CFLAGS, ... the tools and their arguments can be influenced. Please see ‘configure --help‘ and the man/info pages of ‘configure‘ for details.

The names of the standard libraries STD_LIB, STD_INT_LIB, STD_LONG_LIB, STD_FP_LIB,

STD_DS390_LIB, STD_XA51_LIB and the environment variables SDCC_DIR_NAME, SDCC_INCLUDE_NAME,

SDCC_LIB_NAME are defined by ‘configure‘ too. At the moment it’s not possible to change the default settings

(it was simply never required).

These configure options are compiled into the binaries, and can only be changed by rerunning ’configure’ and recompiling SDCC. The configure options are written in italics to distinguish them from run time environment variables (see section search paths).

The settings for ”Win32 builds” are used by the SDCC team to build the official Win32 binaries.

The

SDCC team uses Mingw32 to build the official Windows binaries, because it’s

1. open source,

2. a gcc compiler and last but not least

3. the binaries can be built by cross compiling on Sourceforge’s compile farm.

See the examples, how to pass the Win32 settings to ’configure’. The other Win32 builds using Borland, VC or whatever don’t use ’configure’, but a header file sdcc_vc_in.h is the same as sdccconf.h built by ’configure’ for

Win32.

These defaults are:

Variable

PREFIX

EXEC_PREFIX

BINDIR

DATADIR

DOCDIR

INCLUDE_DIR_SUFFIX

LIB_DIR_SUFFIX

default Win32 builds

/usr/local \sdcc

$PREFIX $PREFIX

$EXECPREFIX/bin $EXECPREFIX\bin

$PREFIX/share

$DATADIR/sdcc/doc sdcc/include sdcc/lib

$PREFIX

$DATADIR\doc include lib

’configure’ also computes relative paths. This is needed for full relocatability of a binary package and to complete search paths (see section search paths below):

Variable (computed) default

BIN2DATA_DIR

PREFIX2BIN_DIR

../share bin

PREFIX2DATA_DIR

share/sdcc

Win32 builds

..

bin

Examples:

./configure

./configure --prefix=”/usr/bin” --datadir=”/usr/share”

./configure --disable-avr-port --disable-xa51-port

To cross compile on linux for Mingw32 (see also ’sdcc/support/scripts/sdcc_mingw32’):

./configure \

CC=”i586-mingw32msvc-gcc” CXX=”i586-mingw32msvc-g++” \

RANLIB=”i586-mingw32msvc-ranlib” \

STRIP=”i586-mingw32msvc-strip” \

--prefix=”/sdcc” \

9

2.2. INSTALL PATHS CHAPTER 2. INSTALLING SDCC

--datadir=”/sdcc” \ docdir=”/sdcc/doc” \ include_dir_suffix=”include” \ lib_dir_suffix=”lib” \ sdccconf_h_dir_separator=”\\\\” \

--disable-device-lib-build\

--disable-ucsim\

--host=i586-mingw32msvc --build=unknown-unknown-linux-gnu

To ”cross”compile on Cygwin for Mingw32 (see also sdcc/support/scripts/sdcc_cygwin_mingw32):

./configure -C \

CFLAGS=”-mno-cygwin -O2” \

LDFLAGS=”-mno-cygwin” \

--prefix=”/sdcc” \

--datadir=”/sdcc” \ docdir=”/sdcc/doc” \ include_dir_suffix=”include” \ lib_dir_suffix=”lib” \ sdccconf_h_dir_separator=”\\\\” \

--disable-ucsim

’configure’ is quite slow on Cygwin (at least on windows before Win2000/XP). The option ’--C’ turns on caching, which gives a little bit extra speed. However if options are changed, it can be necessary to delete the config.cache

file.

2.2

Install paths

Description

Binary files*

Include files

Library file**

Documentation

Path Default Win32 builds

$EXEC_PREFIX

/usr/local/bin \sdcc\bin

$DATADIR/ $INCLUDE_DIR_SUFFIX

/usr/local/share/sdcc/include \sdcc\include

$DATADIR/$LIB_DIR_SUFFIX

/usr/local/share/sdcc/lib \sdcc\lib

$DOCDIR

/usr/local/share/sdcc/doc \sdcc\doc

*compiler, preprocessor, assembler, and linker

**the model is auto-appended by the compiler, e.g. small, large, z80, ds390 etc

The install paths can still be changed during ‘make install‘ with e.g.: make install prefix=$(HOME)/local/sdcc

Of course this doesn’t change the search paths compiled into the binaries.

Moreover the install path can be changed by defining DESTDIR: make install DESTDIR=$(HOME)/sdcc.rpm/

Please note that DESTDIR must have a trailing slash!

2.3

Search Paths

Some search paths or parts of them are determined by configure variables (in italics, see section above). Further search paths are determined by environment variables during runtime.

The paths searched when running the compiler are as follows (the first catch wins):

1. Binary files (preprocessor, assembler and linker)

10

2.4. BUILDING SDCC CHAPTER 2. INSTALLING SDCC

2. Include files

Search path default Win32 builds

$SDCC_HOME/$PPREFIX2BIN_DIR $SDCC_HOME/bin $SDCC_HOME\bin

Path of argv[0] (if available)

$PATH

Path of argv[0]

$PATH

Path of argv[0]

$PATH

Search path

--I dir

$SDCC_INCLUDE

$SDCC_HOME/

$PREFIX2DATA_DIR/

$INCLUDE_DIR_SUFFIX

path(argv[0])/

$BIN2DATADIR/

$INCLUDE_DIR_SUFFIX

$DATADIR/

$INCLUDE_DIR_SUFFIX

default

--I dir

$SDCC_INCLUDE

$SDCC_ HOME/ share/sdcc/ include path(argv[0])/

../sdcc/include

/usr/local/share/sdcc/ include

The option --nostdinc disables the last two search paths.

Win32 builds

--I dir

$SDCC_INCLUDE

$SDCC_HOME\include path(argv[0])\..\include

(not on Win32)

3. Library files

With the exception of ”--L dir” the model is auto-appended by the compiler (e.g. small, large, z80, ds390 etc.).

Search path

--L dir

$SDCC_LIB/

<model>

$SDCC_HOME/

$PREFIX2DATA_DIR/

$LIB_DIR_SUFFIX/<model>

path(argv[0])/

$BIN2DATADIR/

$LIB_DIR_SUFFIX/<model>

$DATADIR/

$LIB_DIR_SUFFIX/<model>

default

--L dir

$SDCC_LIB/

<model>

$SDCC_HOME/ share/sdcc/ lib/<model> path(argv[0])/

../sdcc/lib/<model>

/usr/local/share/sdcc/ lib/<model>

The option --nostdlib disables the last two search paths.

Win32 builds

--L dir

$SDCC_LIB\

<model>

$SDCC_HOME\lib\

<model>

path(argv[0])\

..\lib\<model>

(not on Win32)

2.4

Building SDCC

2.4.1

Building SDCC on Linux

1. Download the source package either from the SDCC CVS repository or from the nightly snapshots, it will be named something like sdcc.src.tar.gz

http://sdcc.sourceforge.net/snap.php

.

2. Bring up a command line terminal, such as xterm.

3. Unpack the file using a command like:

"tar -xvzf sdcc.src.tar.gz

", this will create a sub-directory called sdcc with all of the sources.

4. Change directory into the main SDCC directory, for example type:

"cd sdcc".

5. Type

"./configure

". This configures the package for compilation on your system.

6. Type

"make

". All of the source packages will compile, this can take a while.

7. Type

"make install"

as root. This copies the binary executables, the include files, the libraries and the documentation to the install directories. Proceed with section

2.7

.

11

2.4. BUILDING SDCC CHAPTER 2. INSTALLING SDCC

2.4.2

Building SDCC on OSX 2.x

Follow the instruction for Linux.

On OSX 2.x it was reported, that the default gcc (version 3.1 20020420 (prerelease)) fails to compile SDCC.

Fortunately there’s also gcc 2.9.x installed, which works fine. This compiler can be selected by running ’configure’ with:

./configure CC=gcc2 CXX=g++2

2.4.3

Cross compiling SDCC on Linux for Windows

With the Mingw32 gcc cross compiler it’s easy to compile SDCC for Win32. See section ’Configure Options’.

2.4.4

Building SDCC on Windows

With the exception of Cygwin the SDCC binaries uCsim and sdcdb can’t be built on Windows. They use Unixsockets, which are not available on Win32.

2.4.5

Building SDCC using Cygwin and Mingw32

For building and installing a Cygwin executable follow the instructions for Linux.

On Cygwin a ”native” Win32-binary can be built, which will not need the Cygwin-DLL. For the necessary

’configure’ options see section ’configure options’ or the script ’sdcc/support/scripts/sdcc_cygwin_mingw32’.

In order to install Cygwin on Windows download setup.exe from www.cygwin.com

http://www.cygwin.com/

.

Run it, set the ”default text file type” to ”unix” and download/install at least the following packages. Some packages are selected by default, others will be automatically selected because of dependencies with the manually selected packages. Never deselect these packages!

• flex

• bison

• gcc ; version 3.x is fine, no need to use the old 2.9x

• binutils ; selected with gcc

• make

• rxvt ; a nice console, which makes life much easier under windoze (see below)

• man ; not really needed for building SDCC, but you’ll miss it sooner or later

• less ; not really needed for building SDCC, but you’ll miss it sooner or later

• cvs ; only if you use CVS access

If you want to develop something you’ll need:

• python ; for the regression tests

• gdb ; the gnu debugger, together with the nice GUI ”insight”

• openssh ; to access the CF or commit changes

• autoconf and autoconf-devel ; if you want to fight with ’configure’, don’t use autoconf-stable!

rxvt is a nice console with history. Replace in your cygwin.bat the line bash --login -i

12

2.4. BUILDING SDCC CHAPTER 2. INSTALLING SDCC with (one line): rxvt -sl 1000 -fn "Lucida Console-12" -sr -cr red

-bg black -fg white -geometry 100x65 -e bash --login

Text selected with the mouse is automatically copied to the clipboard, pasting works with shift-insert.

The other good tip is to make sure you have no //c/-style paths anywhere, use /cygdrive/c/ instead. Using // invokes a network lookup which is very slow. If you think ”cygdrive” is too long, you can change it with e.g.

mount -s -u -c /mnt

SDCC sources use the unix line ending LF. Life is much easier, if you store the source tree on a drive which is mounted in binary mode. And use an editor which can handle LF-only line endings. Make sure not to commit files with windows line endings. The tabulator spacing used in the project is 8. Although a tabulator spacing of 8 is a sensible choice for programmers (it’s a power of 2 and allows to display 8/16 bit signed variables without loosing columns) the plan is to move towards using only spaces in the source.

2.4.6

Building SDCC Using Microsoft Visual C++ 6.0/NET (MSVC)

Download the source package either from the SDCC CVS repository or from the nightly snapshots http://sdcc.sourceforge.net/snap.php

, it will be named something like sdcc.src.tgz.

SDCC is distributed with all the projects, workspaces, and files you need to build it using Visual C++ 6.0/NET (except for sdcdb.exe which currently doesn’t build under MSVC). The workspace name is ’sdcc.dsw’. Please note that as it is now, all the executables are created in a folder called sdcc\bin_vc. Once built you need to copy the executables from sdcc\bin_vc to sdcc\bin before running SDCC.

WARNING: Visual studio is very picky with line terminations; it expects the 0x0d, 0x0a DOS style line endings, not the 0x0a Unix style line endings. When using the CVS repository it’s easiest to configure the cvs client to convert automatically for you. If however you are getting a message such as "This makefile was not generated by Developer Studio etc. etc.” when opening the sdcc.dsw workspace or any of the *.dsp projects, then you need to convert the Unix style line endings to DOS style line endings. To do so you can use the ”unix2dos” utility freely available on the internet. Doug Hawkins reported in the sdcc-user list that this works:

C:\Programming\SDCC> unix2dos sdcc.dsw

C:\Programming\SDCC> for /R %I in (*.dsp) do @unix2dos "%I"

In order to build SDCC with MSVC you need win32 executables of bison.exe, flex.exe, and gawk.exe. One good place to get them is here http://unxutils.sourceforge.net

Download the file UnxUtils.zip. Now you have to install the utilities and setup MSVC so it can locate the required programs. Here there are two alternatives (choose one!):

1. The easy way: a) Extract UnxUtils.zip to your C:\ hard disk PRESERVING the original paths, otherwise bison won’t work.

(If you are using WinZip make certain that ’Use folder names’ is selected) b) In the Visual C++ IDE click Tools, Options, select the Directory tab, in ’Show directories for:’ select ’Executable files’, and in the directories window add a new path: ’C:\user\local\wbin’, click ok.

(As a side effect, you get a bunch of Unix utilities that could be useful, such as diff and patch.)

2. A more compact way:

This one avoids extracting a bunch of files you may not use, but requires some extra work: a) Create a directory were to put the tools needed, or use a directory already present. Say for example ’C:\util’.

13

2.4. BUILDING SDCC CHAPTER 2. INSTALLING SDCC b) Extract ’bison.exe’, ’bison.hairy’, ’bison.simple’, ’flex.exe’, and gawk.exe to such directory WITHOUT preserving the original paths. (If you are using WinZip make certain that ’Use folder names’ is not selected) c) Rename bison.exe to ’_bison.exe’.

d) Create a batch file ’bison.bat’ in ’C:\util\’ and add these lines: set BISON_SIMPLE=C:\util\bison.simple

set BISON_HAIRY=C:\util\bison.hairy

_bison %1 %2 %3 %4 %5 %6 %7 %8 %9

Steps ’c’ and ’d’ are needed because bison requires by default that the files ’bison.simple’ and ’bison.hairy’ reside in some weird Unix directory, ’/usr/local/share/’ I think. So it is necessary to tell bison where those files are located if they are not in such directory. That is the function of the environment variables BISON_SIMPLE and BISON_HAIRY.

e) In the Visual C++ IDE click Tools, Options, select the Directory tab, in ’Show directories for:’ select ’Executable files’, and in the directories window add a new path: ’c:\util’, click ok. Note that you can use any other path instead of ’c:\util’, even the path where the Visual C++ tools are, probably: ’C:\Program

Files\Microsoft Visual Studio\Common\Tools’. So you don’t have to execute step ’e’ :)

That is it. Open ’sdcc.dsw’ in Visual Studio, click ’build all’, when it finishes copy the executables from sdcc\bin_vc to sdcc\bin, and you can compile using SDCC.

2.4.7

Building SDCC Using Borland

1. From the sdcc directory, run the command "make -f Makefile.bcc". This should regenerate all the .exe files in the bin directory except for sdcdb.exe (which currently doesn’t build under Borland C++).

2. If you modify any source files and need to rebuild, be aware that the dependencies may not be correctly calculated. The safest option is to delete all .obj files and run the build again. From a Cygwin BASH prompt, this can easily be done with the command (be sure you are in the sdcc directory):

find . \( -name ’*.obj’ -o -name ’*.lib’ -o -name ’*.rul’ \) -print -exec rm {} \;

or on Windows NT/2000/XP from the command prompt with the command:

del /s *.obj *.lib *.rul

from the sdcc directory.

2.4.8

Windows Install Using a ZIP Package

1. Download the binary zip package from http://sdcc.sf.net/snap.php

and unpack it using your favorite unpacking tool (gunzip, WinZip, etc). This should unpack to a group of sub-directories. An example directory structure after unpacking the mingw32 package is: c:\sdcc\bin for the executables, c:\sdcc\include and c:\sdcc\lib for the include and libraries.

2. Adjust your environment variable PATH to include the location of the bin directory or start sdcc using the full path.

2.4.9

Windows Install Using the Setup Program

Download the setup program sdcc-x.y.z-setup.exe for an official release from http://sf.net/project/showfiles.php?group_id=599 or a setup program for one of the snapshots

sdcc_yyyymmdd_setup.exe from http://sdcc.sf.net/snap.php

and execute it. A windows typical installer will guide you through the installation process.

14

2.5. BUILDING THE DOCUMENTATION CHAPTER 2. INSTALLING SDCC

2.5

Building the Documentation

If the necessary tools (LYX, L TEX, L

A

TEX2HTML) are installed it is as easy as changing into the doc directory and typing

”make”

there. You’re invited to make changes and additions to this manual (sdcc/doc/sdccman.lyx).

Using LYX http://www.lyx.org

as editor this is straightforward. Prebuilt documentation in html and pdf format is available from http://sdcc.sf.net/snap.php

.

2.6

Reading the Documentation

Currently reading the document in pdf format is recommended, as for unknown reason the hyperlinks are working

there whereas in the html version they are not

1

.

You’ll find the pdf version at http://sdcc.sf.net/doc/sdccman.pdf

.

A html version should be online at http://sdcc.sf.net/doc/sdccman.html/index.html

.

This documentation is in some aspects different from a commercial documentation:

• It tries to document SDCC for several processor architectures in one document (commercially these probably would be separate documents/products). This document currently matches SDCC for mcs51 and DS390 best and does give too few information about f.e. Z80, PIC14, PIC16 and HC08.

• There are many references pointing away from this documentation. Don’t let this distract you. If there f.e.

was a reference like http://www.opencores.org

together with a statement ”some processors which are targetted by SDCC can be implemented in a f ield programmable gate array” we expect you to have a quick look there and come back. If you read this you are on the right track.

• Some sections attribute more space to problems, restrictions and warnings than to the solution.

• The installation section and the section about the debugger is intimidating.

• There are still lots of typos and there are more different writing styles than pictures.

2.7

Testing the SDCC Compiler

The first thing you should do after installing your SDCC compiler is to see if it runs. Type

"sdcc --version"

at the prompt, and the program should run and tell you the version. If it doesn’t run, or gives a message about not finding sdcc program, then you need to check over your installation. Make sure that the sdcc bin directory is in your executable search path defined by the PATH environment setting (see section

2.8

Install trouble-shooting for suggestions). Make sure that the sdcc program is in the bin folder, if not perhaps something did not install correctly.

SDCC is commonly installed as described in section ”Install and search paths”.

Make sure the compiler works on a very simple example. Type in the following test.c program using your favorite ASCII editor: char test; void main(void) { test=0;

}

Compile this using the following command:

"sdcc -c test.c".

If all goes well, the compiler will generate a test.asm

and test.rel file. Congratulations, you’ve just compiled your first program with SDCC. We used the -c option to tell

SDCC not to link the generated code, just to keep things simple for this step.

The next step is to try it with the linker. Type in

"sdcc test.c

". If all goes well the compiler will link with the libraries and produce a test.ihx output file. If this step fails (no test.ihx, and the linker generates warnings), then the problem is most likely that SDCC cannot find the /usr/local/share/sdcc/lib directory (see section

2.8

Install

1

If you should know why please drop us a note

15

2.8. INSTALL TROUBLE-SHOOTING CHAPTER 2. INSTALLING SDCC trouble-shooting for suggestions).

The final test is to ensure SDCC can use the standard header files and libraries. Edit test.c and change it to the following:

#include <string.h> char str1[10]; void main(void) { strcpy(str1, "testing");

}

Compile this by typing

"sdcc test.c"

. This should generate a test.ihx output file, and it should give no warnings such as not finding the string.h file. If it cannot find the string.h file, then the problem is that SDCC cannot find the /usr/local/share/sdcc/include directory (see the section

2.8

Install trouble-shooting section for suggestions). Use option --print-search-dirs to find exactly where SDCC is looking for the include and lib files.

2.8

Install Trouble-shooting

2.8.1

If SDCC does not build correctly

A thing to try is starting from scratch by unpacking the .tgz source package again in an empty directory. Configure it like:

./configure 2>&1 | tee configure.log

and build it like:

make 2>&1 | tee make.log

If anything goes wrong, you can review the log files to locate the problem. Or a relevant part of this can be attached to an email that could be helpful when requesting help from the mailing list.

2.8.2

What the ”./configure” does

The ”./configure” command is a script that analyzes your system and performs some configuration to ensure the source package compiles on your system. It will take a few minutes to run, and will compile a few tests to determine what compiler features are installed.

2.8.3

What the ”make” does

This runs the GNU make tool, which automatically compiles all the source packages into the final installed binary executables.

2.8.4

What the ”make install” command does.

This will install the compiler, other executables libraries and include files into the appropriate directories. See sections

2.2

, 2.3

about install and search paths.

On most systems you will need super-user privileges to do this.

2.9

Components of SDCC

SDCC is not just a compiler, but a collection of tools by various developers. These include linkers, assemblers, simulators and other components. Here is a summary of some of the components. Note that the included simulator and assembler have separate documentation which you can find in the source package in their respective directories.

16

2.9. COMPONENTS OF SDCC CHAPTER 2. INSTALLING SDCC

As SDCC grows to include support for other processors, other packages from various developers are included and may have their own sets of documentation.

You might want to look at the files which are installed in <installdir>. At the time of this writing, we find the following programs for gcc-builds:

In <installdir>/bin:

• sdcc - The compiler.

• sdcpp - The C preprocessor.

• asx8051 - The assembler for 8051 type processors.

• as-z80, as-gbz80 - The Z80 and GameBoy Z80 assemblers.

• aslink -The linker for 8051 type processors.

• link-z80, link-gbz80 - The Z80 and GameBoy Z80 linkers.

• s51 - The ucSim 8051 simulator. Not available on Win32 platforms.

• sdcdb - The source debugger. Not available on Win32 platforms.

• packihx - A tool to pack (compress) Intel hex files.

In <installdir>/share/sdcc/include

• the include files

In <installdir>/share/sdcc/lib

• the subdirs src and small, large, z80, gbz80 and ds390 with the precompiled relocatables.

In <installdir>/share/sdcc/doc

• the documentation

As development for other processors proceeds, this list will expand to include executables to support processors like AVR, PIC, etc.

2.9.1

sdcc - The Compiler

This is the actual compiler, it in turn uses the c-preprocessor and invokes the assembler and linkage editor.

2.9.2

sdcpp - The C-Preprocessor

The preprocessor is a modified version of the GNU preprocessor. The C preprocessor is used to pull in #include sources, process #ifdef statements, #defines and so on.

2.9.3

asxxxx, aslink, link-xxx - The Assemblers and Linkage Editors

This is retargettable assembler & linkage editor, it was developed by Alan Baldwin. John Hartman created the version for 8051, and I (Sandeep) have made some enhancements and bug fixes for it to work properly with SDCC.

2.9.4

s51 - The Simulator

S51 is a freeware, opensource simulator developed by Daniel Drotos. The simulator is built as part of the build process. For more information visit Daniel’s web site at: http://mazsola.iit.uni-miskolc.hu/~drdani/ embedded/s51

. It currently supports the core mcs51, the Dallas DS80C390 and the Phillips XA51 family. S51 is currently not available on Win32 platfors.

17

2.9. COMPONENTS OF SDCC CHAPTER 2. INSTALLING SDCC

2.9.5

sdcdb - Source Level Debugger

Sdcdb is the companion source level debugger. More about sdcdb in section

5 . The current version of the debugger

uses Daniel’s Simulator S51, but can be easily changed to use other simulators. Sdcdb is currently not available on

Win32 platfors.

18

Was this manual useful for you? yes no
Thank you for your participation!

* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project

Download PDF

advertisement

Table of contents