Now that I’ve switched to GPUTILS from MPLAB, makefiles have re-entered my life. I’ve always hated writing them, the last time being five or six years ago for BREW projects, an atavism not unlike my recent return to assembler. As I sat down to write three new ones (and they’re about as straightforward as makefiles get), all the unpleasantness came flooding back to me. Forgettable macros, single stems, arcane completion rules—I thought about documenting my innumerable complaints, but found someone had already summarized them perfectly.
Three little makefiles suffice for my needs, and I worked on them just long enough to get them operational. I shall not think on them again. Here’s what I came up with to build one of the libraries (the other is essentially identical, except for the target and objects):
LIB=modbus.lib DEVICE=18F242 OBJS=ascii.o diag.o frame.o modbus.o rtu.o INCS=../framework/framework.inc ../framework/macros.inc modbus.inc private.inc AS=gpasm ASFLAGS=-c -p p$(DEVICE) -w 2 AR=gplib ARFLAGS=-c $(LIB): $(OBJS) $(AR) $(ARFLAGS) $(LIB) $^ $(OBJS): $(INCS) %.o : %.asm $(AS) $(ASFLAGS) $< clean: $(RM) *.o *.lst *.lib
For the actual executable (the PIC hex file), I added a couple of targets to control the K150 programmer, using my updated and corrected version of pp. This makefile recurses into the library directories to build them if necessary. There’s better make-fu than my hack approach, but did I mention it works fine?
HEX=ifos.hex PORT=/dev/ttyK150 export DEVICE=18F242 OBJS=anim.o conf.o file.o ifos.o init.o led.o mei.o modbus.o system.o INCS=../framework/framework.inc ../framework/macros.inc ../modbus/modbus.inc ifos.inc LIBS=../framework/framework.lib ../modbus/modbus.lib LIBDIRS=framework modbus AS=gpasm ASFLAGS=-c -p p$(DEVICE) -w 2 AR=gplib ARFLAGS=-c LD=gplink LDFLAGS=-c -m -o $(HEX) -s /usr/local/share/gputils/lkr/$(DEVICE).lkr PR=pp PRFLAGS=-f -d $(DEVICE) -p $(PORT) $(HEX): $(OBJS) $(LIBS) $(LIBDIRS) $(LD) $(LDFLAGS) $(OBJS) $(LIBS) $(LIBS): $(LIBDIRS) $(LIBDIRS): $(MAKE) -C ../$@ $(OBJS): $(INCS) %.o : %.asm $(AS) $(ASFLAGS) $< clean: $(RM) *.o *.lst *.lib erase: $(PR) $(PRFLAGS) -e flash: $(PR) $(PRFLAGS) -w $(HEX)