#
# Makefile.in for UAE
#


CC        = gcc
WRC       = not-found
CPP       = gcc -E
LDFLAGS   =  -L.
CFLAGS    = -O2 -fomit-frame-pointer  -Wall -Wno-unused -Wno-format -W -Wmissing-prototypes -Wstrict-prototypes   -DGCCCONSTFUNC="__attribute__((const))" -DREGPARAM= -DUSE_ZFILE -DSUPPORT_THREADS -D_REENTRANT -D__inline__=inline
X_CFLAGS  =  -I/usr/include/gtk-2.0 -I/usr/lib/gtk-2.0/include -I/usr/include/atk-1.0 -I/usr/include/cairo -I/usr/include/pango-1.0 -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include -I/usr/include/freetype2 -I/usr/include/libpng12   -DSHM_SUPPORT_LINKS=1
TARGET    = x11
LIBRARIES =   -lSM -lICE -lXext -lX11   -lasound -lpthread -lgtk-x11-2.0 -lgdk-x11-2.0 -latk-1.0 -lgdk_pixbuf-2.0 -lm -lpangocairo-1.0 -lpango-1.0 -lcairo -lgobject-2.0 -lgmodule-2.0 -ldl -lglib-2.0  
MATHLIB   = -lm
RESOBJS   = 

NO_SCHED_CFLAGS = 

INSTALL         = @INSTALL@
INSTALL_PROGRAM = @INSTALL_PROGRAM@
INSTALL_DATA    = @INSTALL_DATA@
prefix          = /usr/local
exec_prefix     = ${prefix}
bindir          = ${exec_prefix}/bin
libdir          = ${exec_prefix}/lib
sysconfdir      = ${prefix}/etc

VPATH = ../src

.SUFFIXES: .o .c .h .m .i .S .rc .res

#.SECONDARY: cpuemu.c cpustbl.c cputbl.h

INCLUDES=-I. -I../src/include/

OBJS = main.o newcpu.o memory.o cpuemu.o custom.o cia.o serial.o blitter.o \
       autoconf.o ersatz.o filesys.o hardfile.o keybuf.o expansion.o zfile.o \
       fpp.o readcpu.o cpudefs.o gfxutil.o gfxlib.o blitfunc.o blittable.o \
       disk.o audio.o uaelib.o drawing.o picasso96.o cpustbl.o inputdevice.o \
       uaeexe.o bsdsocket.o missing.o sd-sound.o od-joy.o md-support.o \
       fsusage.o cfgfile.o native2amiga.o fsdb.o identify.o crc32.o \
       savestate.o writelog.o hotkeys.o \
        xwin.o x11keys.o gtkui.o debug.o scsi-none.o fsdb_unix.o


all: $(TARGET)

x11: progs

svgalib: progs

win32: progs $(RESOBJS)
	$(WRC) $(RESOBJS) uae.exe

ggilib: progs

asciiart: progs

amigaos: progs

p_os: progs

beos: progs

next: progs
	cp uae ../Uae.app/Uae

progs: uae readdisk

install:

readdisk: readdisk.o missing.o
	$(CC) readdisk.o missing.o -o readdisk $(LDFLAGS) $(DEBUGFLAGS)

uae: $(OBJS)
	$(CC) $(OBJS) -o uae $(GFXLDFLAGS) $(LDFLAGS) $(DEBUGFLAGS) $(LIBRARIES) $(MATHLIB)

clean:
	$(MAKE) -C tools clean
	-rm -f $(OBJS) *.o uae readdisk
	-rm -f blit.h cpudefs.c
	-rm -f cpuemu.c build68k cputmp.s cpustbl.c cputbl.h
	-rm -f blitfunc.c blitfunc.h blittable.c

halfclean:
	-rm -f $(OBJS)

streifenfrei: clean
	-rm -f Makefile sysconfig.h
	-rm -f od-joy.c md-X86.S sd-sound.c md-support.c
	-rm -f machdep osdep threaddep sounddep target.h config.h

blit.h: tools/genblitter
	./tools/genblitter i >blit.h
blitfunc.c: tools/genblitter blitfunc.h
	./tools/genblitter f >blitfunc.c
blitfunc.h: tools/genblitter
	./tools/genblitter h >blitfunc.h
blittable.c: tools/genblitter blitfunc.h
	./tools/genblitter t >blittable.c

tools/genblitter:
	$(MAKE) -C tools genblitter
tools/build68k:
	$(MAKE) -C tools build68kc
tools/gencpu: 
	$(MAKE) -C tools gencpu

custom.o: blit.h
drawing.o: linetoscr.c

cpudefs.c: tools/build68k ../src/table68k
	./tools/build68k <../src/table68k >cpudefs.c

cpuemu.c: tools/gencpu
	./tools/gencpu

# gencpu also creates cpustbl.c and cputbl.h
cpustbl.c: cpuemu.c
cputbl.h: cpuemu.c

console_missing.o: missing.c
	$(CC) $(INCLUDES) -c $(INCDIRS) $(CFLAGS) $(X_CFLAGS) $(DEBUGFLAGS) $(CFLAGS_$@) $< -o $@

osdep/beos.o: osdep/beos.cpp
	$(CC) $(INCLUDES) -c $(INCDIRS) $(CFLAGS) $(X_CFLAGS) $(DEBUGFLAGS) osdep/beos.cpp -o osdep/beos.o

.rc.res:
	$(WRC) $(INCLUDES) $<
.m.o:
	$(CC) $(INCLUDES) -c $(INCDIRS) $(CFLAGS) $(X_CFLAGS) $(DEBUGFLAGS) $<
.c.o:
	$(CC) $(INCLUDES) -c $(INCDIRS) $(CFLAGS) $(X_CFLAGS) $(DEBUGFLAGS) $(CFLAGS_$@) $< -o $@
.c.s:
	$(CC) $(INCLUDES) -S $(INCDIRS) $(CFLAGS) $(X_CFLAGS) $(DEBUGFLAGS) $< -o $@
.c.i:
	$(CC) $(INCLUDES) -E $(INCDIRS) $(CFLAGS) $(X_CFLAGS) $(DEBUGFLAGS) $< > $@
.S.o:
	$(CC) $(INCLUDES) -c $(INCDIRS) $(CFLAGS) $(X_CFLAGS) $(DEBUGFLAGS) $< -o $@
.s.o:
	$(CC) $(INCLUDES) -c $(INCDIRS) $(CFLAGS) $(X_CFLAGS) $(DEBUGFLAGS) $< -o $@

# Saves recompiling...
touch:
	touch *.o; touch build68k; touch cpudefs.c; touch cpudefs.o; touch gencpu; touch cpuemu.c; touch cpuemu.o

build68k.o: include/readcpu.h
readcpu.o: include/readcpu.h

main.o: config.h
cia.o: config.h include/events.h
custom.o: config.h include/events.h blit.h
newcpu.o: config.h include/events.h
autoconf.o: config.h
expansion.o: config.h
xwin.o: config.h
svga.o: config.h
audio.o: config.h include/events.h
memory.o: config.h
debug.o: config.h
identify.o: config.h
fpp.o: config.h
ersatz.o: config.h
filesys.o: config.h
execlib.o: config.h
disk.o: config.h include/events.h
blitter.o: config.h include/events.h blit.h

# sam: this is for people with low memory. (is there a way do do this with a single rule ?)
cpuemu1.o: cpuemu.c
	$(CC) -DPART_1 $(INCLUDES) -c $(INCDIRS) $(CFLAGS) $(X_CFLAGS) $(DEBUGFLAGS) $< -o $@
cpuemu2.o: cpuemu.c
	$(CC) -DPART_2 $(INCLUDES) -c $(INCDIRS) $(CFLAGS) $(X_CFLAGS) $(DEBUGFLAGS) $< -o $@
cpuemu3.o: cpuemu.c
	$(CC) -DPART_3 $(INCLUDES) -c $(INCDIRS) $(CFLAGS) $(X_CFLAGS) $(DEBUGFLAGS) $< -o $@
cpuemu4.o: cpuemu.c
	$(CC) -DPART_4 $(INCLUDES) -c $(INCDIRS) $(CFLAGS) $(X_CFLAGS) $(DEBUGFLAGS) $< -o $@
cpuemu5.o: cpuemu.c
	$(CC) -DPART_5 $(INCLUDES) -c $(INCDIRS) $(CFLAGS) $(X_CFLAGS) $(DEBUGFLAGS) $< -o $@
cpuemu6.o: cpuemu.c
	$(CC) -DPART_6 $(INCLUDES) -c $(INCDIRS) $(CFLAGS) $(X_CFLAGS) $(DEBUGFLAGS) $< -o $@
cpuemu7.o: cpuemu.c
	$(CC) -DPART_7 $(INCLUDES) -c $(INCDIRS) $(CFLAGS) $(X_CFLAGS) $(DEBUGFLAGS) $< -o $@
cpuemu8.o: cpuemu.c
	$(CC) -DPART_8 $(INCLUDES) -c $(INCDIRS) $(CFLAGS) $(X_CFLAGS) $(DEBUGFLAGS) $< -o $@
