trade

trade

part of shnell – a source to source compiler enhancement tool

© Jens Gustedt, 2019

compiler prefix for source-to-source amendment with #pragma

If the dialect TRADE exists, that dialect is loaded before all processing.

Usage:

#$0 COMPILER COMPILERARGS

Picks and removes C source file names from COMPILERARGS, processes them through shnell and puts the result file names back into the COMPILERARGS. If no output file option (-o) is found, a target is derived from the “job” type.

Source file names are recognize by an suffix .c (for C) and .o (for object files).

A “job” is recognized in COMPILERARGS when finding the following options.

-M for each C source, do renaming with shnell and generate header (if the export directive is used) and makefile (if the implicit directive is used).

-E like before followed by C preprocessing

-S like before and then compile to assembler

-c like before and then compile to object

If none is found, full compilation and linking to a working executable is done, if possible. Object files .o given on the commandline are only effective for this phase.

If no -o options is given, the -E and -M modes write to stdout. The other modes write into files, where the default output suffixes for the resulting files are .o for -c, .s for -S and none for compilation and linking. An output filename of /dev/null switches the compiler phase off, only runs shnell and discards its output.

All compilation modes may produce header and makefiles. -M only suppresses other compilation phases. Header files are placed in the directory that is given by the SHNELL_INCLUDE environement variable, if any. Makefiles are are placed in the directory that is given by the SHNELL_MAKEFILE environement variable, if any. Both types of files are only overwritten, if there were changes.

Library directories that are passed with -L options are expanded for their real name, and the list of such directories is kept in a list, lpath, for later processing. If the environment variable SHNELL_RPATH is not empty it contains a prefix for directory arguments for dynamic linking. All names in lpath are added with that prefix to the compile time arguments.

All unrecognized options are passed through to the compilation.

Coding and configuration

The following code is needed to enable the sh-module framework.

SRC="$_" . "${0%%/${0##*/}}/import.sh"

imports We are using the following components of the sh-module system:

Imports

The following sh-modules are imported:

Details

SHNELL_LEGACY is a directory that contains legacy headers, in particular stdc.h.

SHNELL_LEGACY=${SHNELL_LEGACY:-$(realpath "${EXEDIR}/../legacy")}
export SHNELL_LEGACY

export SHNELL_INCLUDE=${SHNELL_INCLUDE:-.include}
export SHNELL_MAKEFILE=${SHNELL_MAKEFILE:-.makef}

See TRADE for the dialect that is loaded before all processing.