Tag Archives: swift

Apple Swift and D-ISAM

As with any standard C library, D-ISAM is fully supported in Apple Xcode and therefore Swift as covered in Using Swift with Cocoa and Objective-C.

Pure C libraries like D-ISAM and the system libraries are core components of Objective-C, and are imported in the same way (but without most of the fuss) and the real details are covered in Interacting with C APIs.

Building D-ISAM in the Xcode IDE is a guide to working with D-ISAM in the Xcode Integrated Developer Environment, while Building D-ISAM in Xcode from the command line covers the manual installation details.

For quite sensible reasons, Swift Strings will not convert directly to character pointer arrays, unless these are declared as constant, and unfortunately the current D-ISAM library does not include this syntax, although it should. An Update for Constant Chars is available.

Building D-ISAM in the Xcode IDE

Before starting please see Update for Constant Chars.

D-ISAM is probably best deployed as a framework, which may be created as follows.

  1. Start a new Framework project in the IDE.
  2. Add your D-ISAM headers, and make sure they are set Public under Target Membership in the File Inspector.
  3. Add your D-ISAM source, at least the contents of the base folder, and any other modules you need.
  4. In the Framework header (created automatically) #include "isbase.h", or the D-ISAM headers of your choice.

You can use an existing D-ISAM library, including an evaluation library, in place of step 3.

Once built and installed, your D-ISAM framework may be imported into any project by adding the installation directory to Framework Search Paths under Search Paths in Build Options, and optionally, if your installation employs rpath, to Runpath Search Paths under Linking.

Installation is not required if all of your application projects share the same build directory as your D-ISAM framework.

See Creating a Framework and Installing your Framework for the full details.

D-ISAM can also be linked directly into an application by means of the Bridging Header.

This file should include the disam header(s) of your choice.

You may simply add the disam headers directly to your project, or add the disam header directory to the list of User Header Search Paths, in your project Build Settings under Search Paths, in which case you should also set Always Search User Paths to Yes.

You can now copy or link your disam source files directly into your project, or copy or link an existing disam library – including an evaluation library.

You may also wish to see Building D-ISAM in Xcode from the command line.

Building D-ISAM in Xcode from the command line

Makefile for D-ISAM dynamic library in Xcode shows the details needed to build D-ISAM as an Xcode dynamic library, suitable for direct inclusion in any Xcode project.

To build a single arch library for your current development target only

make clean new lib

You can also build D-ISAM for devices other than the default by setting the compiler and sdk-path explicitly

BIN=$(xcrun --sdk iphonesimulator --find clang)
SDK=$(xcrun --sdk iphonesimulator --show-sdk-path)

To build a multi arch library for the selected device

make CC="$BIN -isysroot $SDK -miphoneos-version-min=6.0 -arch i386 -arch x86_64" clean new lib

Static D-ISAM libararies (.a) and regular shared libraries (.so) – as generated by the makefiles distributed with D-ISAM – are also compatible with Xcode, as needed or preferred.

Building a D-ISAM framework for Xcode shows how to build a framework from the command line.

Building D-ISAM in the Xcode IDE covers D-ISAM installation from the Integrated Development Environment.

Makefile for D-ISAM dynamic library in Xcode

This makefile differs from a static build in the following ways:

The library filename extension is .dylib

-fPIC is added to compiler flags.

-dynamiclib is added to linker flags.

INSTALL_NAME is set to the full destination path and name of the library, as finally installed.

Without setting install_name it would be necessary to link the library directly into the install folder, or to use the install_name_tool to set this value later. The Xcode linker refers to this value when setting the library load path in your applications.

Please see Building D-ISAM in Xcode from the command line for more details.

# ------------------------------------------------------------------------
# DISAM                                                           MAKEFILE 
# ------------------------------------------------------------------------
#
# this version is designed to operate from your disam root folder,
# and does NOT require moving everything into a common folder
#
# ------------------------------------------------------------------------

INSTALL_NAME = /Library/Disam72/libdisam72.dylib

ISLIBNAME = disam72
ISLIBWHAT = shared
ISEXTWHAT = dylib
ISCFWHAT = -fPIC
ISLFWHAT =
ISCFOFFB = -D_FILE_OFFSET_BITS=64
ISLFOFFB =
ISBINLIBS =
ISCFLAGS =
ISLFLAGS =

# ------------------------------------------------------------------------

ISINCLUDE = -Ihead -Ibase -Idecs -Iutil -Itest -Iexport

NAME = $(ISLIBNAME)
WHAT = $(ISLIBWHAT)
TYPE = $(ISEXTWHAT)

WHERE= target/$(NAME)_$(WHAT)

ISAM = $(WHERE)/lib/lib$(NAME)

LIBS = -l$(NAME) $(ISBINLIBS)

CFLG = $(ISCFWHAT) $(ISCFOFFB) $(ISCFLAGS) $(CFLAGS)
LFLG = $(ISLFWHAT) $(ISLFOFFB) $(ISLFLAGS) $(LDFLAGS)

BASE =	base/isaccess.o \
	base/isapface.o \
	base/isremote.o \
	base/isadmin.o \
	base/isaudit.o \
	base/isbuild.o \
	base/ischeck.o \
	base/isclustr.o \
	base/iscomp.o \
	base/iscustom.o \
	base/isdatio.o \
	base/isdelete.o \
	base/isentry.o \
	base/iserase.o \
	base/isfree.o \
	base/isglobal.o \
	base/isgrow.o \
	base/ishead.o \
	base/isidxdel.o \
	base/isidxio.o \
	base/isindex.o \
	base/isinfo.o \
	base/iskey.o \
	base/islast.o \
	base/islocate.o \
	base/islock.o \
	base/ismemory.o \
	base/ismif.o \
	base/isnode.o \
	base/isopen.o \
	base/ispath.o \
	base/isprune.o \
	base/isread.o \
	base/isrepair.o \
	base/issquash.o \
       	base/isbytes.o \
	base/isdebug.o \
	base/issystem.o \
	base/isnetsys.o \
	base/isschema.o \
	base/istrans.o \
	base/istree.o \
	base/isunique.o \
	base/isupdate.o \
	base/isvarlen.o \
	base/iswrite.o

WRAP =	wrap/stdbuild.o \
	wrap/stdcheck.o \
	wrap/stdextra.o \
	wrap/stdinfo.o \
	wrap/stdlast.o \
	wrap/stdlock.o \
	wrap/stdmif.o \
	wrap/stdread.o \
	wrap/stdtrans.o \
	wrap/stdwrap.o \
	wrap/stdwrite.o

DECS = 	decs/dec_roun.o \
	decs/decadd.o \
	decs/deccmp.o \
	decs/decconv.o \
	decs/deccvasc.o \
	decs/decdiv.o \
	decs/dececvt.o \
	decs/decefcvt.o \
	decs/decextra.o \
	decs/decfcvt.o \
	decs/decmul.o \
	decs/decsub.o \
	decs/dectoasc.o

CO = $(CC) $(ISINCLUDE) $(CFLG)
CL = $(CC) $(LFLG) -L$(WHERE)/lib
AR = ar 
# RANLIB = $(AR) ts
RANLIB = ranlib

.c.o:
	$(CO) -c $*.c -o $*.o

$(ISAM).a:	$(BASE) $(WRAP) $(DECS)
	$(AR) r $(ISAM).$(TYPE) $(BASE) $(WRAP) $(DECS)
	$(RANLIB) $(ISAM).$(TYPE)

$(ISAM).dylib:	$(BASE) $(WRAP) $(DECS)
	$(CO) -dynamiclib $(BASE) $(WRAP) $(DECS) -o $(ISAM).$(TYPE) -install_name $(INSTALL_NAME)

lib:	$(ISAM).$(TYPE)

test_A:	test/bench.o test/auto.o test/mult.o test/user.o test/lock.o test/dups.o
	$(CL) test/auto.o test/bench.o $(LIBS) -o $(WHERE)/bin/auto_test
	$(CL) test/mult.o test/bench.o $(LIBS) -o $(WHERE)/bin/mult_test
	$(CL) test/user.o test/bench.o $(LIBS) -o $(WHERE)/bin/user_test
	$(CL) test/lock.o test/bench.o $(LIBS) -o $(WHERE)/bin/lock_test
	$(CL) test/dups.o test/bench.o $(LIBS) -o $(WHERE)/bin/dups_test

test_B:	test/mifs.o test/bash.o test/life.o
	$(CL) test/mifs.o              $(LIBS) -o $(WHERE)/bin/mifs_test
	$(CL) test/bash.o              $(LIBS) -o $(WHERE)/bin/bash_test
	$(CL) test/life.o              $(LIBS) -o $(WHERE)/bin/life_test

test:	test_A test_B

util_base: util/utility.o util/dcheck.o util/dstats.o util/dpack.o util/dbugscan.o
	$(CL) util/dcheck.o	util/utility.o	$(LIBS) -o $(WHERE)/bin/dcheck
	$(CL) util/dstats.o	util/utility.o	$(LIBS) -o $(WHERE)/bin/dstats
	$(CL) util/dpack.o	util/utility.o	$(LIBS) -o $(WHERE)/bin/dpack
	$(CL) util/dbugscan.o	                $(LIBS) -o $(WHERE)/bin/dbugscan

util_core: util/dsplit.o util/dlist.o util/dschema.o
	$(CL) util/dsplit.o	util/utility.o	$(LIBS) -o $(WHERE)/bin/dsplit
	$(CL) util/dlist.o	util/utility.o	$(LIBS) -o $(WHERE)/bin/dlist
	$(CL) util/dschema.o	util/utility.o	$(LIBS) -o $(WHERE)/bin/dschema

remote: util/disamnet.o util/dswabnet.o
	$(CL) util/disamnet.o	$(LIBS) -o $(WHERE)/bin/disamnet
	$(CL) util/dswabnet.o	$(LIBS) -o $(WHERE)/bin/dswabnet

util:	util_base util_core

export:	export/isreport.o export/isfield.o export/isload.o export/dreport.o
	$(CL) export/isreport.o export/isfield.o export/isload.o \
	      export/dreport.o $(LIBS) -o $(WHERE)/bin/dreport

check:  test
	$(WHERE)/bin/dstats
	$(WHERE)/bin/dcheck
	$(WHERE)/bin/mifs_test
	$(WHERE)/bin/bash_test
	$(WHERE)/bin/dcheck bashfile
	$(WHERE)/bin/auto_test
	$(WHERE)/bin/dcheck autofile
	rm -f autofile.dat autofile.idx
	rm -f bashfile.idx bashfile.dat

parts: lib util test check export

squeaky:
	rm -rf target/*

clean:	
	rm -rf base/*.o wrap/*.o decs/*.o test/*.o util/*.o export/*.o server/*.o

new:
	rm -rf $(WHERE)
	mkdir -p $(WHERE)/lib $(WHERE)/bin
	cp head/isconfig.h $(WHERE)

all: squeaky clean new lib util test remote