CBUILD
From Allegro Wiki
Contents |
Cbuild 
Introduction
A multiplatform build system using (mostly) standard ANSI C aimed at organizing and creating projects with ease.
Usage
CBuild comes with a single source file cbuild.c and it's default script file default.cbd.
The file cbuild.c is self-compiling under Linux and theoretically should be under Windows with a BASH shell (such as MSys).
So issuing:
myshell $ ./cbuild.c
will get it started and read in the default.cbd file and do whatever it is instructed to do within that file.
Example
Lets take a look at the provided default.cbd and explan it's usage:
GeSHi Error: GeSHi could not find the language cbuild (using path /var/www/mediawiki-1.15.1/extensions/SyntaxHighlight_GeSHi/geshi/geshi/) (code 2)
You need to specify a language like this: <source lang="html4strict">...</source>
Supported languages for syntax highlighting:
abap, actionscript, actionscript3, ada, apache, applescript, apt_sources, asm, asp, autoit, bash, basic4gl, blitzbasic, bnf, boo, c, c_mac, caddcl, cadlisp, cfdg, cfm, cil, cobol, cpp, cpp-qt, csharp, css, d, delphi, diff, div, dos, dot, eiffel, fortran, freebasic, genero, gettext, glsl, gml, gnuplot, groovy, haskell, html4strict, idl, ini, inno, io, java, java5, javascript, kixtart, klonec, klonecpp, latex, lisp, lotusformulas, lotusscript, lua, m68k, matlab, mirc, mpasm, mxml, mysql, nsis, objc, ocaml, ocaml-brief, oobas, oracle8, pascal, per, perl, php, php-brief, plsql, powershell, python, qbasic, rails, reg, robots, ruby, sas, scala, scheme, sdlbasic, smalltalk, smarty, sql, tcl, text, thinbasic, tsql, vb, vbnet, verilog, vhdl, visualfoxpro, winbatch, xml, xorg_conf, xpp, z80
Here's another, even simpler, example: CBUILD_Example2
Advanced
Syntax
To read variables, use the syntax ${VARIABLE}. Using ${'VARIABLE'} will encapsulate the given variable's value within 'hard quotes'. To set a variable, use VARIABLE = value.
| Internally Recognized Variables | ||
|---|---|---|
| VARIABLE | DEFAULT | DESCRIPTION |
*
| N/A | All of the cmd-line arguments |
@
| N/A | All of the cmd-line arguments, individually encapsulated in 'hard quotes' (caveat: using ${'@'} will behave like ${'*')!)
|
0...
| N/A | The given cmd-line argument (0 is the executing command, 1 is the first argument, 2 is the second, etc). Out-of-bounds arguments (i.e. anything greater than or equal to argc) will give nothing
|
| CC | gcc
| C compiler to use |
| CXX | =g++= | C++ compiler to use |
| LD | gcc
| Linker to use |
| OUT_OPT | -o
| compiler flag to specify the output file (the object file name will immediately follow this) |
| SRC_OPT | -c
| compiler flag to specify source-to-object compilation (the source file name will immediately follow this) |
| DEP_OPT | -MMD -MF
| compiler flag to generate a dependancy file (the dependancy file name will immediately follow this). If this is blank, dependancy files aren't generated and the other DEP_* vars are ignored |
| OBJ_EXT | .o
| extension to use for objects |
| OBJ_DIR | .
| directory for object files (. means current directory) |
| DEP_EXT | .d
| extension to use for dependency files |
| DEP_DIR | .
| directory for dependency files (. means current directory) |
| EXE_EXT | .exe in dos/windows
| Executable file extension |
| AR | ar
| Archiver to use (to create static libraries) |
| AR_OPT | archiver flags | |
| LIB_PRE | lib
| library prefix |
| LIB_EXT | .a
| library file extension |
| CPPFLAGS | additional preprocessor flags | |
| CFLAGS | additional C compiler flags | |
| CXXFLAGS | additional C++ compiler flags | |
| LDFLAGS | additional linker flags | |
| EXTRA_SRC_DEPS | additional dependancies to check when compiling source files | |
| EXTRA_LD_DEPS | additional dependancies to check when linking (commands that use LD only)
|
The commands below are provided for your use.
| Command Chart | |||
|---|---|---|---|
| COMMAND | USAGE | DESCRIPTION | |
| do | do command | starts a multi line command | |
| else | else | lets you specify an alternate action for if* commands | |
| done | done | ends a multi line command | |
| if | if "foo"="bar" command | runs command if "foo" and "bar" are equal
| |
| ifnot | ifnot "foo"="bar" command | runs command if "foo" and "bar" are not equal
| |
| ifret | ifret NUMBER command | runs command if the last command's result is equal to NUMBER. Note that not all commands will (re)set the return value!
| |
| ifnret | ifnret NUMBER command | runs command if the last command's result is not equal to NUMBER
| |
| ifplat | ifplat PLATFORM command | runs command if the current platform is PLATFORM. Available platforms include win32, linux, macosx, msdos, unix, i386, and more (see below for full list).
| |
| ifnplat | ifnplat PLATFORM command | runs command if the current platform isn't PLATFORM
| |
| ifopt | ifopt OPTION command | runs command if OPTION was passed at the command line
| |
| ifnopt | ifnopt OPTION command | runs command if OPTION wasn't passed at the command line
| |
| ifexist | ifexist FILE command | runs command if FILE exists
| |
| ifnexist | ifnexist FILE command | runs command if FILE doesn't exist
| |
| ifwrite | ifwrite FILE command | runs command if FILE has write permissions (this will be false if the file doesn't exist)
| |
| ifnwrite | ifnwrite FILE command | runs command if FILE doesn't have write permissions
| |
| call | call command | runs command via the system shell
| |
| fixpath | fixpath VARNAME | modifies the given variable to use / as path seperators instead of \. This is required for DOS/Windows-style paths as CBuild will not recognize \-seperators as directories (note: the variable name is given as VARNAME, not ${VARNAME}!) | |
| reinvoke | reinvoke args | reinvokes the current cbuild file with the given optional arguments | |
| invoke | invoke file | invokes a new cbuild file within the current context | |
| define | define NAME COMMAND | creates a command with the given NAME, which will act like the given COMMAND. Commands defined here will not override existing commands. Using ${num} in the COMMAND (within 'quotes' or with the $ escaped, so it doesn't expand when first processed) will be replaced with the arguments passed to the command later (${0} will be the command name, ${1} the first word after, etc). Be aware, the arguments passed to a defined command will be parsed twice, once when read, and again when used, so take this into account
| |
| compile | compile file_list | compiles a list of files, and stores them in a list to be linked later | |
| compileadd | compileadd file_list | same as above, and adds them to the same list as the last compile command
| |
| linkexec | linkexec file | Links an executable file, using the previously-compiled source files. The executable will have EXE_EXT appended.
| |
| linklib | linklib file | Links a standard archive library, using the previously-compiled source files. The file will have LIB_PRE prepended, and is sub-directory-aware, as well as have LIB_EXT appended.
| |
| loadlist | loadlist LIST | Loads a list of words into a buffer, to later execute an action on them | |
| execlist | execlist command | Executes a command on each of the words in the previously loaded list. Use the macro <@> to specify the word being used
| |
| echo | echo TEXT | Prints a string to the console | |
| put | put TEXT | Prints a string to the console without a newline | |
| read | read VARNAME | Reads user-input from stdin until a new-line is encountered, and stores it in the variable VARNAME. The trailing new-line is stripped
| |
| setinput | setinput FILE | Opens FILE for subsequent read calls, in place of stdin. Pass nothing for FILE to revert to stdin
| |
| writefile | writefile FILE TEXT | Creates/truncates a file and writes a string to it | |
| appendfile | appendfile FILE TEXT | Appends a string to a file | |
| goto | goto LABEL | Jumps to the specified label. A label is denoted by a '#:' combo prepended to it at the beginning of a line | |
| src_paths | src_paths DIRLIST | Stores a list of paths to look for source files in. Passing only '.' clears the list. | |
| rmexec | rmexec LIST | Deletes the specified executables, appending EXE_EXT to the names as needed
| |
| rmlib | rmlib LIST | Deletes the specified libraries, prepending LIB_PRE to the filename portions and appending with LIB_EXT
| |
| rmobj | rmobj LIST | Removes a list of object files and their associated dependancy files, replacing the extension of the named file as necesarry | |
| rm | rm LIST | Removes a list of files or empty directories. | |
| mkdir | mkdir DIR | Creates a directory (with mode 700 in Unix) | |
| verbose | verbose NUM | Enables/disables command verboseness. | |
| uninvoke | uninvoke NUM | Leaves the current script, falling back to the previous if the current was started with the invoke command. Otherwise, it behaves like exit.
| |
| copy | copy file1 file2 | Copies a file. | |
| copylib | copylib name1 name2 | Copies a library file, prepending and appending the names as necesarry. | |
| copyexec | copyexec name1 name2 | Copies an executable file, appending the names as necesarry. | |
| popfront | popfront VARNAME | Removes the first word and trailing whitespace from the variable VARMNAME
| |
| associate | associate ext command | Sets a command to compile files with the specified ext with (the command can use the macros <@>, <!>, and <*> to get the object name, source name, and unadorned file name (as passed to the compile or compileadd command, without the extension)
| |
| exit | exit NUM | Exits the script with the specified exitcode. | |
| ADD MORE STUFF |
Using a compiler's pre-defined macro set, CBuild can currently detect the following platforms: aix, amigaos, beos, unicos, dgux, dynix, freebsd, gnuhurd, hpux, irix, linux, macosx, mpeix, msdos, netbsd, openbsd, os2, pyramiddc, qnx4, qnx6, reliantunix, scoopensever, solaris, sunos, solaris, symbian, osf1 (aka tru64), ultrix, unixware, vms, and win32. As well, it detects the following general environments: bsd, svr4, unix, uwin, and windu. As well as the architectures: i386, ia64, powerpc, and sparc.
Note that these are detected when CBuild is compiled, so if you want run-time detection you'll need to do some of your own checking in a script.
When defining your own commands, be aware that there are internal commands not listed here which may take precedance. These commands are prefixed with at least one underscore (_). As well, defining a command that begins with atexit_ will cause that command to be executed when the script exits, in the opposite order in which they were defined. If another exit is triggered, the script will immediately abort.
When used, the following sub-commands will be replaced with the described text. They use the syntax $(command options). Some sub-commands have strict formatting rules regarding the , character and may abort the script if this isn't met. Prefixing the command name with * will cause the returned value to be encapsulated in 'hard quotes' (important when dealing with user input).
| Sub-command Chart | ||
|---|---|---|
| COMMAND | USAGE | DESCRIPTION |
| getoptval | $(getoptval variable) | gets the value of command line arguments in the form --foo=blah or --foo blah
|
| word | $(word n,list-of-words) | gives the n th word from the given list (1-based)
|
| libname | $(libname name) | builds the name of a library, ie: $(libname name) may give: libname.a
|
| findsrc | $(findsrc list-of-files) | looks for the given source files, by searching the paths given to src_paths, and returns the files with the proper path |
| ifeq | $(ifeq A,B,YES,NO) | returns YES if A and B are the same, NO if not.
|
| add | $(add A,B) | returns the result of A+B
|
| sub | $(sub A,B) | returns the result of A-B
|
| mult | $(mult A,B) | returns the result of A*B
|
| div | $(div A,B) | returns the result of A/B (warning: if B evaluates to 0, the script will abort with a divide-by-0 error)
|
| lsa | $(lsa list-of-files) | for directories, returns a listing of all files and directories inside it, including . and ... For files, returns the given name if it exists
|
| ls | $(ls list-of-files) | same as lsa except it disregards files starting with .
|
| tolower | $(tolower string) | returns string with all uppercase characters converted to lowercase
|
| toupper | $(toupper string) | returns string with all lowercase characters converted to uppercase
|
| which | $(which program) | returns the full location of program by searching the path. Note for DOS and Windows, you need to specify the .exe extension (${EXE_EXT} may be used)
|
| suffix | $(suffix list-of-files) | strips out the path and base filename of the given list, returning only the file extensions |
| basename | $(basename list-of-files) | strips out the suffixes of the given file list |
| addprefix | $(addprefix pre,list-of-words) | prefixes the given list of words with pre
|
| addsuffix | $(addsuffix suf,list-of-words) | appends suf to the given list of words
|
| dir | $(dir list-of-files) | removes the filename portions, leaving only the paths (note: only / is seen valid path seperator) |
| notdir | $(notdir list-of-files) | removes the paths, leaving only the filenames |
Note: lsa, ls, suffix, basename, addprefix, addsuffix, join, dir, and notdir will only leave one space between returned words.
Bash Autocompletion Code:
Add this to your ~/.bashrc and see a miracle ;)
alias cbuild="./cbuild.c" _cbuild_opts () { FILES=( default.cbd ) COMPREPLY=() k=${#FILES[@]} for (( i=0; i < $k; i++ )); do for j in `grep -s -E 'invoke .*.cbd' ${FILES[i]} | cut -d' ' -f2`; do FILES[$k]="$j"; let k+=1 done done rm -fr tmp touch tmp k=0 for i in ${FILES[@]} ; do echo $i >> tmp done tmp=`sort -u tmp` rm -fr tmp touch tmp for i in $tmp; do if [ -f $i ] ; then for j in `cat $i | sed -n -e 's/.*ifn\?opt\s\+\([^ \t]\+\).*/\1/p' -e 's/\$(getoptval\s\+\(\[^)]+\))/\1/p'`; do echo $j >> tmp done fi done k=0 for i in `sort -u tmp`; do COMPREPLY[$k]=$i let k+=1 done rm -fr tmp } complete -F _cbuild_opts ./cbuild cbuild
Credits
Files: Latest Cbuild
Written by KittyCat
- File:Cbuild.xml: Kate syntax file
- Place into ~/.kde/share/apps/katepart/syntax/ and kate will highlight cbuild files
Requests
- $(backticks program) or
- capture VAR program
- $VAR now contains the output of "program"
