Oninit® SQLMorph — Makefile
sqlmorph does not emit a per-procedure Makefile. Drop the canonical Makefile below into any directory of generated .c + _install.sql bundles and run make. All UDRs in the directory are linked into one shared object (default sqlmorph.so), and each procedure's install SQL references that one library with a different C entry point — so adding a new UDR is just dropping another .c next to the Makefile and re-running make.
Direct downloads: three files belong together in the build directory — the Makefile, the shared header, and the runtime helper source. Fetch with wget or curl -O:
wget https://www.oninit.com/sqlmorph/Makefile wget https://www.oninit.com/sqlmorph/standard.h wget https://www.oninit.com/sqlmorph/sqlmorph_util.c
standard.h defines the ONIERR_/ONI_EXEC/DBDK_TRACE_ macros every generated UDR uses; sqlmorph_util.c ships shared runtime helpers (currently oni_clean_sql for whitespace-normalising a SQL string at runtime) and is linked into the same sqlmorph.so via $(wildcard *.c).
Save it as Makefile alongside your .c files. The targets are:
| Target | Effect |
|---|---|
| all | Compile every *.c in this directory and link them into a single $(LIBNAME).so (default sqlmorph.so). |
| install | Run every *_install.sql against $(IFXDB) via dbaccess. |
| deploy | Copy $(LIBNAME).so into $(INFORMIXDIR)/extend/sqlmorph/, creating the directory if it does not exist. |
| jar | Compile every *.java under com.oninit.sqlmorph and pack into $(LIBNAME).jar (default sqlmorph.jar). For the java output target. |
| java-install | Copy $(LIBNAME).jar into $(INFORMIXDIR)/extend/sqlmorph/, register it with sqlj.install_jar, then run every *_install.sql. |
| db2-install | For each DB2 SQL PL file in the directory (*.sql excluding the Informix *_install.sql scripts), connect to $(IFXDB) and run db2 -td@ -vf <file>. Bracketed automatically with db2 connect / db2 disconnect; the @-terminator is required because SQL PL bodies use ; internally for statement separation. |
| clean | Remove $(LIBNAME).so, every .o, and the JAR build tree. |
| Variable | Default | Purpose |
|---|---|---|
| INFORMIXDIR | /opt/informix | Informix installation root. |
| LIBNAME | sqlmorph | Base name of the produced shared object. |
| INSTALL_DIR | $(INFORMIXDIR)/extend/sqlmorph | Where deploy copies the built library. |
| IFXDB | (unset) | Required for make install; the database to register procedures into. |
Vendor-SQL install scripts
The Makefile above builds and installs Informix C UDRs, Informix Java UDRs, and DB2 LUW SQL PL via the db2-install target above. For the remaining SQL-only targets (MSSQL, MySQL, Oracle), sqlmorph ships per-vendor install shell scripts that loop over the bundle's .sql files and run the appropriate vendor CLI. Drop the script into the bundle directory alongside the emitted .sql files and invoke with connection parameters.
| Target | Install script | Underlying tool |
|---|---|---|
| mssql | install.mssql.sh | sqlcmd — one invocation per .sql |
| mysql | install.mysql.sh | mysql client — .sql piped via stdin so DELIMITER pragmas take effect |
| oracle | install.oracle.sh | sqlplus — with WHENEVER SQLERROR EXIT FAILURE so installs halt on first compile error |
Each script reads connection parameters from $MSSQL_* / $MYSQL_* / $ORA_* environment variables or command-line flags. Run with --help for usage. The bundle's .sql files are idempotent — MSSQL emits an IF OBJECT_ID() DROP preamble + GO before CREATE OR ALTER for pre-2016 compatibility; MySQL uses DROP FUNCTION/PROCEDURE IF EXISTS; Oracle uses CREATE OR REPLACE.
Makefile
# sqlmorph — generic Informix UDR Makefile (C + Java). Built by Oninit LLC.
#
# Place this file alongside the .c / .java sources and *_install.sql scripts
# that sqlmorph produces, then:
#
# make # build LIBNAME.so from every *.c
# make IFXDB=mydb install # run every install SQL against mydb
# make deploy # copy LIBNAME.so into $(INFORMIXDIR)/extend/sqlmorph
# make jar # build LIBNAME.jar from every *.java
# make IFXDB=mydb java-install # register the JAR + every install SQL
# make IFXDB=mydb db2-install # install every DB2 SQL PL file into mydb
# make clean
#
# All C UDRs in this directory link into one shared object (LIBNAME.so).
# All Java UDRs pack into one JAR (LIBNAME.jar) under the
# com.oninit.sqlmorph package. The install SQL each sqlmorph procedure
# emits references whichever artefact is appropriate; add new UDRs by
# dropping more .c / .java files next to this Makefile, no further
# wiring required.
#
# Override INFORMIXDIR if it is not /opt/informix, or LIBNAME if you want
# an artefact name other than the default sqlmorph.
INFORMIXDIR ?= /opt/informix
CC ?= cc
SOEXT ?= so
INSTALL_DIR ?= $(INFORMIXDIR)/extend/sqlmorph
LIBNAME ?= sqlmorph
IFXDB ?=
JAVAC ?= javac
JAR ?= jar
JAVA_PKG ?= com.oninit.sqlmorph
JAVA_PKGDIR := $(subst .,/,$(JAVA_PKG))
CFLAGS += -fPIC -I$(INFORMIXDIR)/incl/public -I$(INFORMIXDIR)/incl/dbdk
LDFLAGS += -shared -L$(INFORMIXDIR)/lib -lifdmi
SRCS := $(wildcard *.c)
OBJS := $(SRCS:.c=.o)
TARGET := $(LIBNAME).$(SOEXT)
INSTALLS := $(wildcard *_install.sql)
JAVA_SRCS := $(wildcard *.java)
JAR_TARGET := $(LIBNAME).jar
# DB2 SQL PL files emitted by sqlmorph land as bare <proc>.sql (no
# _install suffix), so we glob *.sql excluding the Informix C UDR
# install scripts above.
DB2_INSTALLS := $(filter-out %_install.sql,$(wildcard *.sql))
.PHONY: all install deploy jar java-install db2-install clean
all: $(TARGET)
$(TARGET): $(OBJS)
$(CC) $(LDFLAGS) -o $@ $^
%.o: %.c
$(CC) $(CFLAGS) -c $<
deploy: all
@mkdir -p $(INSTALL_DIR)
@echo "==> install $(TARGET) -> $(INSTALL_DIR)/"
@cp -f $(TARGET) $(INSTALL_DIR)/
install:
@if [ -z "$(IFXDB)" ]; then echo "set IFXDB=<database> on the make command line"; exit 2; fi
@for f in $(INSTALLS); do echo "==> dbaccess $(IFXDB) $$f"; dbaccess $(IFXDB) $$f; done
# Java UDR build: compile every *.java under $(JAVA_PKG), package into
# $(LIBNAME).jar. The package directory layout is created on the fly so
# sqlmorph's emitted .java files (which carry `package com.oninit.sqlmorph;`)
# end up at the right path inside the JAR.
jar: $(JAR_TARGET)
$(JAR_TARGET): $(JAVA_SRCS)
@mkdir -p $(JAVA_PKGDIR)
@cp -f $(JAVA_SRCS) $(JAVA_PKGDIR)/
$(JAVAC) -d . $(JAVA_PKGDIR)/*.java
$(JAR) cf $@ $(JAVA_PKGDIR)/*.class
# Java install: copies the JAR to $(INSTALL_DIR), registers it via
# sqlj.install_jar, then runs every Java install SQL.
java-install: jar
@if [ -z "$(IFXDB)" ]; then echo "set IFXDB=<database> on the make command line"; exit 2; fi
@mkdir -p $(INSTALL_DIR)
@cp -f $(JAR_TARGET) $(INSTALL_DIR)/
@echo "==> sqlj.install_jar('file://$(INSTALL_DIR)/$(JAR_TARGET)', '$(LIBNAME)_jar')"
@echo "EXECUTE FUNCTION sqlj.remove_jar('$(LIBNAME)_jar');" | dbaccess $(IFXDB) 2>/dev/null || true
@echo "EXECUTE FUNCTION sqlj.install_jar('file://$(INSTALL_DIR)/$(JAR_TARGET)', '$(LIBNAME)_jar');" | dbaccess $(IFXDB)
@for f in $(INSTALLS); do echo "==> dbaccess $(IFXDB) $$f"; dbaccess $(IFXDB) $$f; done
# DB2 install: for each DB2 SQL PL file in this directory, connect to
# $(IFXDB) and run db2 -td@ -vf $$f. The @-terminator is required because
# SQL PL bodies use ; internally for statement separation. Connection is
# bracketed automatically so the customer just needs the database name.
db2-install:
@if [ -z "$(IFXDB)" ]; then echo "set IFXDB=<database> on the make command line"; exit 2; fi
@if [ -z "$(DB2_INSTALLS)" ]; then echo "no DB2 SQL files (*.sql) found in this directory"; exit 0; fi
@db2 connect to $(IFXDB)
@for f in $(DB2_INSTALLS); do echo "==> db2 -td@ -vf $$f"; db2 -td@ -vf $$f; done
@db2 disconnect $(IFXDB)
clean:
rm -f $(TARGET) $(OBJS) $(JAR_TARGET)
rm -rf $(JAVA_PKGDIR)