all: rmgr

CPPFLAGS = -I../include -I../../../lib/libl4sys/include -I../../../../oskit \
  -I../../../../oskit/flux/c

include ../../../Makeconf

C = startup.c rmgr.c oskit_support.c exec.c globals.c init.c memmap.c \
    trampoline.c irq.c cfg-parse.c cfg-mem.c

O = $(C:.c=.o)
CRT0 = crt0.o

CFLAGS += -Wall -O -g
LIBS = -L ../../../../oskit/lib -lkern -lexec -lmc -llmm
PICFLAGS = -fpic

SIZE = $(TARGET)size
YACC = byacc
LEX = flex

rmgr: rmgr.ld $(CRT0) $(O)
	$(LD) -o $@ -T $^ $(LIBS)

# special rule for trampoline.o:  need to be position independent
trampoline.o: trampoline.c
	$(CC) $(CFLAGS) $(PICFLAGS) -c $<
# assert we don't need data
	@data_size="`$(SIZE) --format=sysv $@ | grep ^.data | awk '{print $$2}'`"; \
	  bss_size="`$(SIZE) --format=sysv $@ | grep ^.bss | awk '{print $$2}'`"; \
	  if [ $$bss_size -gt 0 -o $$data_size -gt 0 ]; then \
	    echo "ERROR: $@: data or bss size > 0"; \
	    rm -f $@; \
	    exit 1; \
	  else \
	    true; \
	  fi



###

clean:
	rm -f *.o rmgr cfg-scan.c cfg-parse.c

realclean: clean
	rm -f *.d *~

cfg-parse.d cfg-parse.o: cfg-scan.c
include $(C:.c=.d)
