Title: Advanced Compilation
1Advanced Compilation
- Simon Rees
- jBASE International
2Overview
- The Basics
- BASIC
- CATALOG
- New in jBASE 4.1
- JCOMPILE
- Compiled jQL
- Using Make
3BASIC
- Front end to the jBASE compiler
- 2 stage process
- Converts the jBC code into C
- Invokes the native C compiler of the OS to
convert the C code into machine native object
code
4CATALOG
- Uses the referenced c compiler (PATH, LIB,
INCLUDE) to produce a binary executable
(programs) or shared object (subroutines and
functions) - Programs are placed in the JBCDEV_BIN folder
- Subroutines are placed in the JBDEV_LIB folder
- Defaults are HOME/bin and /HOME/lib if these
environment variables are not set
5Subroutines and Functions
- Multiple subroutines and functions in each shared
object
- jLibDefinition config file in the JBCDEV_LIB
directory defines size and name of shared
objects
- Original catalog order defines order in shared
object
- Catalog your most frequently used, and most
stable, subroutines first
6jLibDefinition
- Configuration file defining the naming and sizing
of jBC developed shared objects (subroutines and
functions)
- libname - shared object name
- literal text
- a - account name (JBCLOGNAME)
- n - sequence number starting with 0
- f - source file name
- exportname - cross reference .def or .el file
- objectdir - shared object directory
- maxsize - of each shared object
- baseaddress - prevents shared object from
becoming private (Windows)
7Directing CATLOG
- Configuration file defining the naming and sizing
of jBC developed shared objects (subroutines and
functions)
- libname - shared object name
- literal text
- a - account name (JBCLOGNAME)
- n - sequence number starting with 0
- f - source file name
- exportname - cross reference .def or .el file
- objectdir - shared object directory
- maxsize - of each shared object
- baseaddress - prevents shared object from
becoming private (Windows)
8Be Careful!
- All programs, subroutines and functions must be
cataloged
- PATH and JBCOBJECTLIST should include the same
directory as JBCDEV_BIN and JBCDEV_LIB
- DO NOT CATALOG PROGRAMS FROM DIFFERENT FILES WITH
THE SAME NAME INTO THE SAME bin or lib
DIRECTORY!!!
- The last one cataloged wins
9jcompile
10jcompile
- Replacement for 3.x jbc command and the
jBuildSLib command used for building shared
libraries
- Users who only use BASIC and CATALOG will not be
affected
- jcompile H option will list the available
options
11jcompile
- jsh Simon Rees C\ --jcompile -H
- Usage jcompile.exe -abcefhjmrvxEHJRSX?
- -bBaseAddres -lLibraryName -oOutputExec
- -Ffiledir -sOutputSharedName
-BBaseAddres
- -DCompileDefine -IIncludePath
-LLibraryPath
- -Jqdom -JJ
- -O1-4 filename filename filename ...
12jcompile
- The ! and .d files no longer exist - the debugger
information is built into the object itself
- When an executable PROGRAM is built, jBASE not
only creates an executable, but also a shared
library version (.dll or .sl or .so) for thread
usage. This is also true for CATALOG in jBASE
4.1 - When a PERFORM statement attempts to execute a
program, the statement first looks for a shared
library version of the program and if found
executes the program as a thread. If the shared
library version of the program cannot be found
then the program is executed as an external
program in a child process.
13jcompile
- Why use jcompile?
- Allows you take complete control, and
responsibility of where and how programs are
compiled and cataloged
- Use jcompile to better organize your shared
objects by placing subroutines and functions into
specified shared objects
14Compiled jQL
15Compiled jQL
- Enable execution of queries and retrieval of the
query result set within the jBASE BASIC program.
- Only data fields specified by the query need be
retrieved
- Query can be efficiently compiled and executed,
and then the results retrieved directly.
- Removes the need to execute/perform a SELECT
command, which generates the select list, which
in turn must then be processed by a readnext and
a read statement in order to access the data
field in the record.
16Compiled jQL Functions
- JQLCOMPILE
- Compiles a jQL statement
- JQLCOMPILE (Statement, Command, Options,
Messages)
- JQLEXECUTE
- Starts executing a compiled jQL statement
- JQLEXECUTE (Statement, SelectVar)
- JQLFETCH
- JFetches the next result in a compiled jQL
statement
- JQLFETCH (Statement, ControlVar, DataVar)
- JQLGETPROPERTY
- Receives the requested property value from the
system or if the property is not set
- JQLGETPROPERTY (PropertyValue, Statement, Column,
PropertyName)
- JQLPUTPROPERTY
- Sets a property in a compiled jQL statement
- JQLPUTPROPERTY (PropertyValue, Statement, Column,
PropertyName)
- Examples of these functions in JBCRELEASEDIR/samp
les/JQLBASIC
17Basics of Make and makefiles
18Why Not Use BASIC/CATALOG?
- Consistent builds
- Never build an older version or forget a compile
- No what program build this binary and when?
- Total control of dll/shared library content
- Almost total automation of build process
- make clean make world make install
- Use any editor or tool
- Assumes moving source from hashed files to
directories
- Sometimes easier to use jcompile
- Integrating C/C source
- Simplifies the compilation process especially if
there are many files involved
19What is Make?
- Examples shown in the presentation use the GNU
Make utility
- Other Make versions available
- A tool which controls the generation of
executables and other non-source files from the
programs source files. GNU
- Make is a utility to track dependencies in a
system of files, and to automate compilation
- One of the original nix tools for software
development (circa 1975 by ATT)
20Capabilities of Make
- Enables the end user to build and install
packages without knowing the details
- Automatically determines what files to update
- Based on a series of pre-defined rules
- Also knows the proper order to build
- Not limited to any one language
- Not limited to building a package
- Can do any repeatable task
21How does Make know what to do?
- Make uses a Makefile
- Makefile is a series of instructions of how/what
to do
- Makefile specified on command-line
- Make f name_of_makefile
- If no Makefile specified, make uses a default
file
- Makefile or makefile, in the current directory
- Other paths also searched depends on version of
make
- Make also supports default rules
- So make can be used without a Makefile
- Not recommended
22Using Make
- Make is a command line utility
- Make can be invoked with a target
- make clean is a classic example
- Multiple targets can be specified at once
- Targets separated by semicolon
- make clean make all make install
- If no target specified default rule is used
- Default rule is first rule that doesnt start
with a period
23What does Make do?
- Make first evaluates ALL variable assignments
- From top to bottom
- Searches for the specified target
- If no target specified on command line, first
rule found is used
- Evaluates the associated rule(s)
- Recursively handles dependencies
- Checks to see if dependency is up-to-date
- If not the command list is processed
24Structure of a Makefile
- Comments
- Lines starting with
- Lines containing only whitespace
- Macros (or Variable definitions)
- CC gcc
- Referenced as (CC) in Makefile
- Rules
- Identify what is to be made
- How to make it
- What its made from
- Many more extensions, functions and tricks
- Left as an exercise for the reader
25Rules
- Rules have three components
- The target
- What to make
- The dependencies
- What the target is made from
- The commands
- How to make the target
26Example Rule
- TARGET DEPENDENCIES
- TAB COMMAND(S) \
- TAB COMMAND(S)
HELLO.exe HELLO.b jbc Hello.b o Hello.exe
27Rules the Target
- When do Targets get built?
- When one (or more) dependency changes
- Phony Targets
- Have no dependencies
- Executed every time target is goal
- UNLESS file exists with same name as target
- Can be defined as phony
- .PHONY clean
- GNU Make specific
28Rules - Dependencies
- Lists files target depends on
- Dependencies evaluated in order
- Each dependency treated as a target
- Recursively processed
- Timestamp of target/dependencies
- Only evaluates out of date dependencies
- Dependency is newer than target
29Rules - Commands
- Always start with TAB
- Obscure errors can result if missing
- Each command line is executed in its own shell
- Can stack commands with \ construct
- Any errors stop make
- ANY command returns -1
- Such as compile error
- Use Make -n command switch to test
- Will echo, not execute commands
30Variable Assignment
- Format name string
- Environment Variables available
- Usage (name)
- Use UPPERCASE for names
- Standard convention
- Be consistent!
- Some default values pre-defined
- CC gcc
- Best to be explicit
31Single-source Example
Simple make example all mkjdpdemofile2.exe
mkjdpdemofile2.exe mkjdpdemofile2.b mkjdpdem
ofile2.h jbc mkjdpdemofile2.b -o mkjdpdemofile2.
exe clean del mkjdpdemofile2.exe
32Shared Library (.dll) Example
PROGS SIMON.exe SUBS SIMON1.obj LIBNAME S
IMON1.dll all (LIBNAME) (PROGS) How to
build the .DLL (LIBNAME) (SUBS) jBuildSLib
.obj .b jbc -c an executable .exe .b jbc
33Using Compiler and Linker Flags
- Use variables whenever possible
- Easy to change (for debugging)
INCLUDES -I.. I../headers JBCFLAGS -JO3 -Jv
(INCLUDE_PATH) HELLO.exe HELLO.b jbc (JB
CFLAGS) HELLO.b o HELLO.exe
34Using File-Type Rules
- Generic rule for a given file type
- How to make a .exe from .b
- Simplifies makefiles
- Special Variables (macros)
-
- Matches the stem of the target
- Stem is file name MINUS the extension
-
- The dependency list that was matched by the rule
- _at_
- Actual name of the target
35File-Type Rules Example
Simple test for File-Types PROGS PROG1.exe
PROG2.exe PROG3.exe all (PROGS) .exe .b
jbc
36jBC Dependencies
- Program depends on includes and interfaces
- If an include changes the program is rebuilt
- Called subroutine interface changes
- Probably the real issue
- Mistakes can be hard to find
- Can be Difficult to automate
- Currently a manual process
- Help may come in future 4.x release
- Difficulty depends on how code built
- Worth the effort?
- Reduces build times
- May not be real issue with todays hardware
37Anything Else?
- If you are looking to move towards makefiles for
software builds, consider your Source Control
strategy
- Do you have one at the moment?
38Why Use Source Control?
- Maintains changes to documents in a controlled
manner
- Easy to reproduce any previous version
- Provides ability to track changes
- See differences between any two versions
- Facilitates teams of concurrent developers
- Handles multiple edits to same document
39Basics of Source Control
- Source code kept in a repository
- Central database of documents
- Client/Server architecture
- Can be on same system
- Group of documents is called a module
- Documents checked out for use
- Creates local copy of repository
- Can be synced to repository at will
- Modified documents commited
- Places modified document in repository
- Handles merging of any concurrent changes
40Software Life Cycle
- Source code is placed in repository
- To view/edit, code is checked out
- Results in a local copy of the documents
- Specific versions can be requested
- Code is edited/tested
- Code must be explicitly updated
- Modified code is commited
- Specific versions of code tagged
- Tags identify a specific revision
- When a build is required, specific versions can
be checked out to source directories for your
makefiles
41Source Control
- Many source control tools available
- Some free, some require licenses
- Choose the solution that best fits your
development needs
42Questions?