# Include configuration rules
include MCONFIG

LIBOBJS = \
	abort.o atexit.o atoi.o atol.o atoll.o calloc.o creat.o		\
	ctypes.o errno.o fgetc.o fgets.o fopen.o fprintf.o fputc.o	\
	fclose.o putchar.o setjmp.o					\
	fputs.o fread2.o fread.o free.o fwrite2.o fwrite.o getopt.o	\
	lrand48.o malloc.o stack.o memccpy.o memchr.o memcmp.o		\
	memcpy.o mempcpy.o memmem.o memmove.o memset.o memswap.o	\
	exit.o onexit.o	\
	perror.o printf.o puts.o qsort.o realloc.o seed48.o snprintf.o	\
	sprintf.o srand48.o sscanf.o stack.o strcasecmp.o strcat.o	\
	strchr.o strcmp.o strcpy.o strdup.o strerror.o strlen.o		\
	strnlen.o							\
	strncasecmp.o strncat.o strncmp.o strncpy.o strndup.o		\
	stpcpy.o stpncpy.o 						\
	strntoimax.o strntoumax.o strrchr.o strsep.o strspn.o strstr.o	\
	strtoimax.o strtok.o strtol.o strtoll.o strtoul.o strtoull.o	\
	strtoumax.o vfprintf.o vprintf.o vsnprintf.o vsprintf.o		\
	asprintf.o vasprintf.o strlcpy.o strlcat.o			\
	vsscanf.o zalloc.o						\
	\
	libgcc/__ashldi3.o libgcc/__udivdi3.o			\
	libgcc/__negdi2.o libgcc/__ashrdi3.o libgcc/__lshrdi3.o		\
	libgcc/__muldi3.o libgcc/__udivmoddi4.o libgcc/__umoddi3.o	\
	libgcc/__divdi3.o libgcc/__moddi3.o				\
	\
	sys/intcall.o sys/farcall.o sys/cfarcall.o sys/zeroregs.o	\
	sys/entry.o sys/exit.o sys/argv.o sys/times.o			\
	sys/fileinfo.o sys/opendev.o sys/read.o sys/write.o sys/ftell.o \
	sys/close.o sys/open.o sys/fileread.o sys/fileclose.o		\
	sys/isatty.o sys/fstat.o					\
	\
	sys/zfile.o sys/zfopen.o					\
	\
	sys/openconsole.o sys/line_input.o				\
	sys/colortable.o sys/screensize.o				\
	\
	sys/stdcon_read.o sys/stdcon_write.o sys/rawcon_read.o		\
	sys/rawcon_write.o sys/err_read.o sys/err_write.o		\
	sys/null_read.o sys/null_write.o sys/serial_write.o		\
	\
	sys/xserial_write.o						\
	\
	sys/ansi.o							\
	\
	sys/ansicon_write.o sys/ansiserial_write.o			\
	\
	sys/vesacon_write.o sys/vesaserial_write.o			\
	sys/vesa/initvesa.o sys/vesa/drawtxt.o	sys/vesa/background.o	\
	sys/vesa/alphatbl.o sys/vesa/screencpy.o sys/vesa/fmtpixel.o	\
	\
	pci/cfgtype.o pci/scan.o					\
	pci/readb.o pci/readw.o pci/readl.o pci/readbios.o		\
	pci/writeb.o pci/writew.o pci/writel.o pci/writebios.o		\
	\
	zlib/adler32.o zlib/compress.o zlib/crc32.o zlib/gzio.o		\
	zlib/uncompr.o zlib/deflate.o zlib/trees.o zlib/zutil.o		\
	zlib/inflate.o zlib/infback.o zlib/inftrees.o zlib/inffast.o	\
	\
	libpng/png.o libpng/pngset.o libpng/pngget.o libpng/pngrutil.o  \
	libpng/pngtrans.o libpng/pngwutil.o libpng/pngread.o		\
	libpng/pngrio.o libpng/pngwio.o libpng/pngwrite.o		\
	libpng/pngrtran.o libpng/pngwtran.o libpng/pngmem.o		\
	libpng/pngerror.o libpng/pngpread.o				\
	\
	jpeg/tinyjpeg.o jpeg/jidctflt.o	jpeg/decode1.o jpeg/decode3.o   \
	jpeg/rgb24.o jpeg/bgr24.o jpeg/yuv420p.o jpeg/grey.o		\
	jpeg/rgba32.o jpeg/bgra32.o					\
	\
	sys/x86_init_fpu.o math/pow.o math/strtod.o			\
	\
	syslinux/idle.o	syslinux/reboot.o				\
	syslinux/features.o syslinux/config.o syslinux/serial.o		\
	syslinux/ipappend.o syslinux/dsinfo.o syslinux/version.o	\
	\
	syslinux/addlist.o syslinux/freelist.o syslinux/memmap.o	\
	syslinux/movebits.o syslinux/shuffle.o syslinux/shuffle_pm.o	\
	syslinux/shuffle_rm.o syslinux/zonelist.o			\
	syslinux/dump_mmap.o syslinux/dump_movelist.o			\
	\
	syslinux/run_default.o syslinux/run_command.o			\
	syslinux/cleanup.o syslinux/localboot.o	syslinux/runimage.o	\
	\
	syslinux/loadfile.o syslinux/floadfile.o syslinux/zloadfile.o	\
	\
	syslinux/load_linux.o syslinux/initramfs.o			\
	syslinux/initramfs_file.o syslinux/initramfs_loadfile.o		\
	syslinux/initramfs_archive.o					\
	\
	syslinux/pxe_get_cached.o					\
	\
	syslinux/adv.o syslinux/advwrite.o syslinux/getadv.o		\
	syslinux/setadv.o

BINDIR   = /usr/bin
LIBDIR   = /usr/lib
DATADIR  = /usr/share
AUXDIR   = $(DATADIR)/syslinux
INCDIR   = /usr/include
COM32DIR = $(AUXDIR)/com32

all: libcom32.a

libcom32.a : $(LIBOBJS)
	rm -f $@
	$(AR) cq $@ $^
	$(RANLIB) $@

tidy dist clean:
	rm -f sys/vesa/alphatbl.c
	find . \( -name \*.o -o -name .\*.d -o -name \*.tmp \) -print0 | \
		xargs -0r rm -f

spotless: clean
	rm -f *.a
	rm -f *~ \#* */*~ */\#*

install: all
	mkdir -m 755 -p $(INSTALLROOT)$(COM32DIR)
	install -m 644 libcom32.a com32.ld $(INSTALLROOT)$(COM32DIR)
	-rm -rf $(INSTALLROOT)$(COM32DIR)/include
	cp -r ../include $(INSTALLROOT)$(COM32DIR)

# These files are performance critical, and doesn't compile well with -Os
sys/vesa/drawtxt.o: sys/vesa/drawtxt.c
	$(CC) $(CFLAGS) -O3 -c -o $@ $<

sys/vesa/alphatbl.c: sys/vesa/alphatbl.pl
	$(PERL) $< > $@

jpeg/jidctflt.o: jpeg/jidctflt.c
	$(CC) $(CFLAGS) -O3 -c -o $@ $<

-include .*.d */.*.d */*/.*.d
