Version 3 of Building Starkits and Starpacks using a Makefile 2

Updated 2007-09-19 16:50:57 by dcd

The gorilla example was great, but it rebuilds the whole shebang every time. I was looking for a Makefile that would let me make local changes, rebuild, and test before checking the source back in. Another difference is that this depends on the local Tcl installation more for it's packages.

Ok, here it is in all it's rawness:

  WINTCLBIN = c:/usr/share/Tcl/bin
  WINTCLLIB = c:/usr/share/Tcl/lib
  WINKIT = $(WINTCLBIN)/tclkitsh-win32.upx.exe
  WINSDX = $(WINTCLBIN)/tclsh.exe $(WINTCLBIN)/sdx.kit

  LIBTCL = $(WINTCLLIB)
  TCLLIB = $(WINTCLLIB)/tcllib1.8
  KIT = $(WINKIT)
  SDX = $(WINSDX)

Up to here, I'm just getting the local Tcl installation set up

  TCLLIBS = aes sha1 crc
  SimpleDevLibLoc = $(LIBTCL)/SimpleDevLib-1.0

These are packages I'm using that have various naming idiosyncracies.

  APP = wsem
  VFS = $(APP).vfs
  KIT_LIB = $(VFS)/lib
  KIT_APP = $(VFS)/lib/app-$(APP)/$(APP).tcl

The section above should be common for any starkit or starpack, just replace your app name.

  PACKAGES = $(TCLLIBS) SimpleDevLib winserv
  CONFIGS = $(VFS)/wifi.cfg  $(VFS)/cdma.cfg 
  SERVERCFG = wifi.cfg
  TESTS =  $(VFS)/upgrade.test
  DEFTEST = upgrade.test

Other stuff that I want in the starkit is above. Now the rules (fixed some dependencies)

  all: $(APP).exe
  kit: $(APP).kit

  $(APP).exe: $(APP).kit
        $(SDX) wrap $@ -runtime $(KIT)

  $(APP).kit: $(VFS) $(KIT_APP) $(PACKAGES) $(CONFIGS) $(TESTS)
        touch $<

  $(VFS):
          if [ ! -d $(APP).vfs ]; \
             then $(SDX) qwrap $(APP).tcl; $(SDX) unwrap $(APP).kit; fi

  $(KIT_APP): $(APP).tcl 
          cp -f $< $@

The rules up to this point should be fairly common. Every starkit starts with one <app>.tcl file to base the kit on. The Makefile is in the same directory as <app>.tcl. If you edit <app>.tcl and run Make the starkit / starpack will be rebuilt.

  $(CONFIGS):$(VFS)/%:%
          cp -f $< $@; \
          if [ $< == $(SERVERCFG) ]; then \
             cp -f $< $(VFS)/server.cfg; fi; \

  $(TESTS):$(VFS)/%:%
          cp -f $< $@; \
          if [ $< == $(DEFTEST) ]; then \
             cp -f $< $(VFS)/test.test; fi; \

The two rules above are static pattern rules that make the files in the vfs dependent on the files of the same name in the current directory, so if you change any of these files, the starkit will be rebuilt. As an example: if wifi.cfg is newer than wsem.vfs/wifi.cfg then copy wifi.cfg to the root of the vfs.

  # put packages here, they each have different idiosyncracies

All of the rules below simply copy entire packages from the local tcl lib into the vfs lib. Since I'm using only small parts of tcllib, I flatten it out in the starkit.

  SimpleDevLib:
          if [ ! -d $(KIT_LIB)/$@ ] ; then \
             mkdir $(KIT_LIB)/$@ ; \
             cp $(SimpleDevLibLoc)/*.tcl $(KIT_LIB)/$@; \
          fi

  winserv:
          if [ ! -d $(KIT_LIB)/$@ ] ; then \
             mkdir $(KIT_LIB)/$@ ; \
             cp $(LIBTCL)/$@/* $(KIT_LIB)/$@; \
          fi

  # put packages from tcllib here

  aes:
          if [ ! -d $(KIT_LIB)/$@ ] ; then \
             mkdir $(KIT_LIB)/$@ ;  \
             for f in pkgIndex aes; do \
             cp $(TCLLIB)/$(@)/$$f.tcl $(KIT_LIB)/$@; done \
          fi
  sha1:
          if [ ! -d $(KIT_LIB)/$@ ] ; then \
             mkdir $(KIT_LIB)/$@ ; \
             for f in pkgIndex sha1 sha1 sha256; do \
             cp $(TCLLIB)/$(@)/$$f.tcl $(KIT_LIB)/$@; done \
          fi

  crc:
          if [ ! -d $(KIT_LIB)/$@ ] ; then \
             mkdir $(KIT_LIB)/$@ ; \
             for f in pkgIndex cksum crc16 crc32 crcc sum; do \
             cp $(TCLLIB)/$(@)/$$f.tcl $(KIT_LIB)/$@; done \
          fi

  clean:
          rm -f $(APP).kit $(APP).exe
          rm -rf $(VFS)