Introduction to the Barracuda Examples

Understanding the Example Build Structure

CSP development requires a number of tools which are located in the "bin" directory. It is possible to run all tools from the command prompt, but this would be very inefficient. A makefile can automate the task of developing CSP pages.

Each example directory has its own makefile. Most of the makefiles are similar in the way they use tools for translating the CSP files.

Making a change in a CSP file requires a rebuild of the server. Making a change to static HTML files, JavaScript, etc, does not require a rebuild of the server when compiled with the DiskIo -- i.e. when running make with io=disk . Pressing refresh in the browser is sufficient when changing static content. All examples contain a CSP directory and a HTML directory. The CSP files goes into the CSP directory and the static content goes into the HTML directory. The Barracuda Virtual File System combines the two directories in a running server, thus making them appear as one directory.

All Barracuda Embedded Web Server examples send information, warning, and error messages to HttpTrace.txt when using the standard host build.

Example Directory Structure

Most of the example directories contain the following subdirectories:

makeThe make directory.
vcMakeVC++ project files.
srcCommon host and target Source code.
cspHTML files with CSP tags.
htmlRegular HTML files, JavaScript files, and images.
All temporary data is put here, including the host/target libraries.

In addition to the directories above, all examples include files from ../misc/standalone, which contain common startup code for the examples.

The src directory contains code that is common to both target and host. Some of the examples can be used without any modifications, but some examples require that you make small changes to the code in the src directory as the code use file system operations and standard I/O operations.

Building the Example Code

The makefiles are designed such that they can create libraries for host development and for target code. The makefiles are based on GNU make. Windows users can compile using VC++ or Cygwin. All tools required are included in the bin directory and you do not need to install Cygwin if using VC++.

You can also use the makefiles as a template when either creating a new build or extending one of the examples. The makefiles are designed such that they automatically compile all code in the "src" directory and compile all CSP files in the "csp" directory using CspCompile. The makefiles create two libraries, which you can link with your target code. You can, for example, execute the makefiles from within a target IDE or from your makefiles creating the target code.

Please note that that there are many ways to create a build structure for CSP. You can use our makefiles as a template when creating a Barracuda build structure, but you should also consider incorporating the Barracuda host tools into your own build environment. See the CSP Tools page for more information on the tools used by the makefiles.

Building for Host

Barracuda can run on the following host platforms:

We provide a GNU makefile which you can run from a command window for these platforms. For example, the Native Windows API is compiled from within the VC++ IDE.

Command Line Build

Open a console window in the make directory "examples/introduction/make".

You should see the following if you type make plat=posix, and press ENTER.

$ make plat=posix *********** Building release *********** No io. Setting default: io=ezip Build one of: make build=debug|release io=disk|net|zip|ezip [neturl=path] plat=type lib|exe - build: debug: Include debug information. release: Build release. Default is release. - io type: disk: Use DiskIo. DiskIo path is set to: ../../html. net: Use NetIo. You must also set neturl. zip: ZIP HTML, but read from disk. ezip: ZIP HTML, embed ZIP file and CSP dat file in executable. Default is ezip. - neturl: Must be set if you set io=net. example: neturl=http://localhost/fs/c/ba-inst-dir-path/examples/introduction/ - Platform type: set plat = One of the supported platforms. Example: plat=win - Make one of: libraries (lib) or example executable (exe).

The following two initial messages are printed since we have not set build=debug|release and not set io to one of the io types:

*********** Building release
*********** No io. Setting default: io=ezip

The variables are optional, except for plat which must be set to one of the supported platforms. Examples:

Type the following command in the shell:

make plat=posix build=debug io=disk exe

This will build the host test program using the DiskIo. The DiskIo and the NetIo are useful during development. The ZipIo is typically used for deployment.

The following command starts the demo program:

$ ../obj/bademo

Using the Visual C++ IDE

You must setup the VC++ environment before you can use any of the workspace files. The VC project files require that the VCINSTALLDIR environment variable is set.

Using the VC++ IDE is very simple; you open the workspace for VC++ .NET and build the example code from within the IDE. The workspace includes a special VC++ wrapper project for running the external makefile. Any errors generated from the external makefile show up within the environment, and you can click on the error message and the file will be loaded.

You can run the example web-server program from within the IDE when you have successfully built the example.

Running the Example Programs

You can run the example program from the command prompt or from within the VC++ IDE.

The example program will not print out anything and might appear to be frozen. This is a server and nothing is printed out. Open your browser and type in when the example program is running. The IP address is your local loopback address. The example code is configured to use port 9357, thus the port number must also be specified in the URL.

Debugging CSP

You can set breakpoints directly in the CSP files if your compiler and debugger support the #line directive. See the CspCompiler for more information on this flag.

Building for Target (Embedded System)

You build the target libraries by using the makefile in the make directory. See Using Command Line Tools for an introduction.

  1. Type "make plat=xxx, where xxx is the target platform. You can alternatively set the variable TINC -- i.e. make TINC=../../../builds/standalone/Windows/". This builds the two introduction libraries CspPages and GLib.
  2. Include the following in your target IDE project file or target makefile.

Please note that you must replace TINC=../../../builds/standalone/Windows/ above with the path to your target platform.

Using the Target Libraries

You must write some support code for your target build before you can use the Barracuda libraries and the example code.