CFLAGS=-M
PROG1=problem1
PROG2=problem1_analyse

#
# a generic makefile for sample use ... feel free to customize
# 
# Programs using this must define:
#   PROG           name of program  (eg. grep)
#   (PROG1/PROG2 etc.. can be used for more than 1 program
#
# Programs using this may define:                    defaults
#   OBJS           list of object file names.        $(PROG).o
#   USAGEFILE      where usage message is kept       $(PROG).c
#   INCPATH        extra include directories
#   LIBPATH        extra library directory
#   DEBUG          set the debug flag                -g1
#
#   PRIV           privity to link program at.       nil
#   STACKSIZE32    stack requirement for 32-bit program     32k
#   LIBS           extra libraries                   nil
#
#   CFLAGS         compiler flags (generic)          -O1 -M
#   CC386          386 compiler to invoke            cc -3 -mf
#   CC386FLAGS     386 compiler flags.

VPATH=$(shell pwd)

ifndef OBJS1
	OBJS1= $(PROG1).o
endif

ifndef OBJS2
	OBJS2= $(PROG2).o
endif

ifndef OBJS3
	OBJS3= $(PROG3).o
endif

ifndef USAGEFILE1
	USAGEFILE1= $(PROG1).c
endif

ifndef USAGEFILE2
	USAGEFILE2= $(PROG2).c
endif

ifndef USAGEFILE3
	USAGEFILE3= $(PROG3).c
endif

ifndef DEBUG
    DEBUG = -g
endif

ifdef PRIV
	LDFLAGS += $(PRIV)
endif

ifdef DEFS
	CFLAGS += $(DEFS)
endif

ifndef STACKSIZE32
    STACKSIZE32 = -N32k
endif

ifdef CODEGEN
	CFLAGS += $(CODEGEN)
else
	CFLAGS += -O1 -M -w9
endif

ifndef CC386
	CC386 = cc -3 
endif

ifdef INCPATH
CFLAGS += -I$(INCPATH)
endif

ifndef LIBPATH
	LIBPATH= 
endif

LDFLAGS = 

QNXLDFLAGS = $(LIBPATH) $(LDFLAGS)

$(PROG1): $(OBJS1)
	$(CC386) -T1 $(DEBUG) $(QNXLDFLAGS) $(LIBS) $(STACKSIZE32) -o $@ $^
	usemsg $@ $(USAGEFILE1)

$(PROG2): $(OBJS2)
	$(CC386) -T1 $(DEBUG) $(QNXLDFLAGS) $(LIBS) $(STACKSIZE32) -o $@ $^
	usemsg $@ $(USAGEFILE2)

$(PROG3): $(OBJS3)
	$(CC386) $(DEBUG) $(QNXLDFLAGS) $(LIBS) $(STACKSIZE32) -o $@ $^
	usemsg $@ $(USAGEFILE3)

%.o: %.c 
	$(CC386) $(DEBUG) -c  -o $@ $(CFLAGS) $(CC386FLAGS) $^

clean:
	-rm $(PROG1) $(PROG2) $(PROG3) $(OBJS1) $(OBJS2) $(OBJS3)

