.DEFAULT: all
.DELETE_ON_ERROR:

SOEKRIS_KERNEL=/home/pmg/ganges/2.6.9/linux-2.6.9/include

CC=gcc
RM=rm
CP=cp
LDFLAGS=
CPPFLAGS=
CFLAGS= -O3 -Wall -Wshadow -Wpointer-arith -Wcast-qual -Wcast-align \
        -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations \
        -Winline -Wwrite-strings

.PHONY : clean all tar

APPS = \
	lcd \
	lcdtest \
	lcdraw \
	lcdwork2 \

SRCS = \
	lcd.c \
	lcdraw.c \
	lcdwork2.c \
	lcdtest.c \
	lcdfuncs.c \

APPS_SOEKRIS = $(addprefix soekris/,$(notdir $(APPS)))
OBJS_SOEKRIS = $(addprefix soekris/,$(notdir $(SRCS:.c=.o)))

APPS_PPORT = $(addprefix pport/,$(notdir $(APPS)))
OBJS_PPORT = $(addprefix pport/,$(notdir $(SRCS:.c=.o)))

all: pport soekris

pport: $(APPS_PPORT)
soekris: $(APPS_SOEKRIS)

.PHONY: all pport soekris

soekris/%.o: %.c
	$(CC) -c $(CPPFLAGS) $(CFLAGS) $< -o $@

pport/%.o: %.c
	$(CC) -c $(CPPFLAGS) $(CFLAGS) $< -o $@

$(OBJS_SOEKRIS): CPPFLAGS += -DSOEKRIS -I$(SOEKRIS_KERNEL)

$(OBJS_SOEKRIS): lcdfuncs.h soekris/.touch
$(OBJS_PPORT): lcdfuncs.h pport/.touch

%/.touch:
	mkdir -p $(dir $@)
	@touch $@

soekris/lcd:       soekris/lcd.o soekris/lcdfuncs.o
soekris/lcdwork2:  soekris/lcdwork2.o soekris/lcdfuncs.o
soekris/lcdtest:   soekris/lcdtest.o soekris/lcdfuncs.o
soekris/lcdraw:    soekris/lcdraw.o

pport/lcd:       pport/lcd.o pport/lcdfuncs.o
pport/lcdwork2:  pport/lcdwork2.o pport/lcdfuncs.o
pport/lcdtest:   pport/lcdtest.o pport/lcdfuncs.o
pport/lcdraw:    pport/lcdraw.o


clean:
	$(RM) -rf soekris pport core

tar:
	cd .. && tar -zcf lcd.tgz $(addprefix lcd/,$(SRCS) lcdfuncs.h Makefile)
