CFILES=\
	diskpart.c    elf64.c	    load.c	  paloio.c      \
	elf32.c	      error.c	    gzip.c	  palo.c

OFILES=$(CFILES:.c=.o)


INCLUDES=common.h load.h palo.h

OS := $(shell uname -s)
CC?=cc
ifeq ($(strip ${OS}),HP-UX)
CFLAGS=-g -O -I../include -I../lib -I$(PA)/include
else
CFLAGS=-g -O -I../include -I../lib -D_FILE_OFFSET_BITS=64
endif

ifneq ("$(wildcard /etc/debian_version)","")
BLDINFO := $(shell echo https://parisc.docs.kernel.org - `dpkg-parsechangelog -l../debian/changelog -SDate`)
else
BLDINFO := $(shell echo https://parisc.docs.kernel.org - `LC_TIME=C date`)
endif

# LDFLAGS=-Wl,-Bstatic 
LDFLAGS=

OFILES2=mkbootable.o elf64.o load.o paloio.o elf32.o error.o gzip.o

# Source sharing with ipl
VPATH=../lib:.

all:	palo mkbootable

palo:	palo.a
	echo "const char bld_info[] = \"$(BLDINFO)\";" > build.c
	$(CC) $(CFLAGS) -c -o build.o build.c
	-rm -f build.c
	$(CC) $(CFLAGS) $(LDFLAGS) -o palo palo.a build.o

palo.a:	$(OFILES)
	$(AR) rv palo.a $?

mkbootable:	$(OFILES2)
	$(CC) $(CFLAGS) $(LDFLAGS) -o mkbootable $(OFILES2)

clean:
	rm -f palo mkbootable *.a *.o usage.h

distclean: clean

usage.h:	usage.txt
	sed 's/.*/"&\\n"/' < usage.txt > usage.h

###############}

diskpart.o :		common.h

elf32.o \
elf64.o \
load.o :		common.h load.h

som.o :		common.h load.h

palo.o :		load.h palo.h

paloio.o :		palo.h

error.o:	usage.h error.c
