Menu

Tree [c62484] default tip /
 History

Read Only access


File Date Author Commit
 examples 2025-03-14 ggb ggb [5af96c] Fix some compile flag issues
 .hgignore 2024-02-28 ggb ggb [66d758] Initial load
 .hgtags 2025-03-14 ggb ggb [c62484] Added tag V0-18 for changeset 5af96c95d988
 README.md 2024-11-25 ggb ggb [703ab2] Build leg files
 crune.pl 2025-03-14 ggb ggb [5af96c] Fix some compile flag issues
 gcc_check_ver.pl 2025-03-14 ggb ggb [5af96c] Fix some compile flag issues

Read Me

Compile and execute C source file

The command crune.pl is a Perl script that is intended to allow the execution of short C programs. This is primarily intended to allow the experimental testing of small segments of C code without having to create a makefiles, executables, etc; but can also be used to build
complete micro-projects, again without the need for makefiles.

Prerequisites

Linux commands required

The following linux commands are dependencies of this command:

  • perl
This is the Perl interpreter required to execute this script.
  • g++
This is the gnu compiler required to compile C++ or leg code.
  • gcc
This is the gnu compiler required to compile C code.
  • leg
This is the gnu compiler required to compile leg code.
  • pkg-config
This is the utility used to determine flags required for determining the location of headers and libraries required for building the application.
  • fltk-config
This is required to be able to build applications with the fltk library. It is not required if there is no intention to use the fltk library.

Command syntax

Command line is: crune.pl [ options ] source_file_name [ sub_options ]

options are:

-help

Display this help message.
If this option is selected then all other options will be ignored.

-run

Compile and execute source file.
If no other options are specified then this is the default action.
If other options are specified then the default is not to run the compiled application, but that default can be overridden by specifying this option.

-build[=target_file]

If this option is specified then the source if compiled but not run (unless the -run option is also spefified).
If a target_file is specified then the output will generate the target file.
If no target_file is specified then a temporary output file will be created and removed when finished.
If no target_file is epcified then an executable will be created in the current directory using the basename of the source file.
If the target_file is the name of an existing directory then the executable will be created in that directory using the basename of the source file.
If the target_file ends in a slash ('/') then a directory of that name will be created (unless it already exists) and the executable will be created in that directory using the basename of the source file.

-show

Will display the compile options.
By default, if this switch is specified then the program will not actually be compiled or run.
If the -build option is selected then the compile command will be displayed and executed.
If the -run option is specified then the compile command will be displayed and the program compiled and executed.

-optimise

If set then some optimisation flags will be set for the compiler. The switches still prioritise safety over ultimate optimisation.
If not set the no compiler optimisation will be done but debugging information will be included in the generated executable.

-define=name

Will pass defined name to compiler.
Name is restricted to being an alphabetic followd by zero or more alphamerics or underscores.
Multiple names may defined in a comma seperated list.
Multiple -define options may be included on the command line.

Options are not case sensitive, and may yse '--' prefix in place of '-' prefix.

Options may be shortened to single characters (i.e.-h is the same as -H is the same as --help).

source_file_name may not start with a hyphen.

sub-options

These are passed verbatim to the executing program (i.e. they have no impact upon the processing by the crune.pl script but when the -run option is used then after the source file has been compiled then when the compiled file is being executed then these sub-options will be added to the command line of the executing program).

Example:

  crune.pl examples/colours.c

The above will attempt to compile a temporary executable from the source file examples/colours.c, then if the compile succeeds it will execute the compiled program and finally delete the temporary executable that was created.

Source file types

This command can be executed against C files (with .c or .h file extensions) or C++ files (with .cpp or .hpp file extensions).

Special comments

Within the source code the script will look for special C comment lines of the form:

   //% options <flags>

or

   //% library <library-list>

or

   //% pack <flags>

or

   //% show <text>

or

   //% use <file-list>

or

   //% fltk <flag>

or

   //%  version <version-list>

These special comments must be on a line of their own, but do not have to be left aligned in the file (i.e. they may have preceding spaces).

OPTIONS comment

The options flags will insert the flags directly into the gcc command line.

You may also use option or opt as an alias for options.

Example

If you have a file called colours.c that contains the following line:

    //% option -lncurses

and you execute the command: crune.pl colours.c -s -b

The it will execute the following gcc command: gcc "colours.c" -o "./colours" -lncurses

LIBRARY comment

This is merely a convenient alternative to the option copmmant for libraries.

You may also use libas an alias forlibrary`.

You may include a list of space separated libraries in the same line.

Example

    //% library ncurses

is exactly equivalent to

    //% opt -lncurses

PACKAGE comment

The pack flags will generate compiler flags using the pkg-config command.

You may also use pack as an alias for package.

Example

If you have a file called gtk_test.cpp that contains the following line:

    //% pack --cflags --libs gtkmm-3.0

and you execute the line: crune.pl -s -b gtk_test.cpp

This will case the following compilation command to be executed:

    g++ -x c++  "/home/ggb/Dev/crune/examples/gtk_test.cpp" -o "./gtk_test" -g -O0 -Wall -fstack-check -I/usr/include/gtkmm-3.0 -I/usr/lib/x86_64-linux-gnu/gtkmm-3.0/include -I/usr/include/giomm-2.4 -I/usr/lib/x86_64-linux-gnu/giomm-2.4/include -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I/usr/include/libmount -I/usr/include/blkid -I/usr/include/glibmm-2.4 -I/usr/lib/x86_64-linux-gnu/glibmm-2.4/include -I/usr/include/sigc++-2.0 -I/usr/lib/x86_64-linux-gnu/sigc++-2.0/include -I/usr/include/gtk-3.0 -I/usr/include/pango-1.0 -I/usr/include/harfbuzz -I/usr/include/freetype2 -I/usr/include/libpng16 -I/usr/include/fribidi -I/usr/include/cairo -I/usr/include/pixman-1 -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/x86_64-linux-gnu -I/usr/include/gio-unix-2.0 -I/usr/include/atk-1.0 -I/usr/include/at-spi2-atk/2.0 -I/usr/include/at-spi-2.0 -I/usr/include/dbus-1.0 -I/usr/lib/x86_64-linux-gnu/dbus-1.0/include -I/usr/include/cairomm-1.0 -I/usr/lib/x86_64-linux-gnu/cairomm-1.0/include -I/usr/include/pangomm-1.4 -I/usr/lib/x86_64-linux-gnu/pangomm-1.4/include -I/usr/include/atkmm-1.6 -I/usr/lib/x86_64-linux-gnu/atkmm-1.6/include -I/usr/include/gtk-3.0/unix-print -I/usr/include/gdkmm-3.0 -I/usr/lib/x86_64-linux-gnu/gdkmm-3.0/include -pthread -lgtkmm-3.0 -latkmm-1.6 -lgdkmm-3.0 -lgiomm-2.4 -lgtk-3 -lgdk-3 -lz -latk-1.0 -lcairo-gobject -lgio-2.0 -lpangomm-1.4 -lglibmm-2.4 -lcairomm-1.0 -lsigc-2.0 -lpangocairo-1.0 -lpango-1.0 -lharfbuzz -lcairo -lgdk_pixbuf-2.0 -lgobject-2.0 -lglib-2.0

FLTK comment

This invokes fltk-config to add appropriate library and include paths for includinf fltk in the compiled object.

The additional option on the command is either static or dynamic to indicate whether the target compile should include a static or dynamic library.

Example

    //% fltk static

USE comment

Will cause another file to be read for further special comment lines. The other file may be another source file (e.g. another header file) or just a plain text file that contains no source code but only comment lines.

A semicolon delimited list of files may be included within the command.

Every file mentioned in any use command will be parsed exactly once, even if it is mentioned multiple times in multiple files.

Example

    //% use my-comments.txt ; my-header-file.h

SHOW comment

Will cause the text specified on the line to be printed to STDOUT while the file is being parsed.

The command is primarily intended to aid in determining which files are being processed.

You may also use sho as an alias for show.

Example

    //% show Display this text when file is being parsed.

VERSION version-list

Will check that the compiler supports the specified language version.

version-list can be a space separated list of lanuage versions. This is primarily intended to allow the same file to be used for both C and C++
programs, and that it might check that the language version is applicable for the language being used.

You may also use ver or vers as aliases for version.

Example

    //% version c11 c++14

If this is being compiled in a C++ content then the c11 check will be ignored, and if this is being compiled in a C content then the c++14 check will be ignored.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.