#### Start of system configuration section. ####

srcdir =	@srcdir@
VPATH =		@srcdir@

# Common prefix for machine-independent installed files.
prefix =	@prefix@

# Common prefix for machine-dependent installed files.
exec_prefix =	@exec_prefix@

bindir =	$(exec_prefix)/bin
libdir =	$(exec_prefix)/Sys/libs

INSTALL =	@INSTALL@
INSTALL_DATA =	@INSTALL_DATA@

CC =		@CC@

CFLAGS =	@CFLAGS@
LDFLAGS =	@LDFLAGS@

RANLIB =	@RANLIB@
AR =		ar

#### End system configuration section ####

FLAVOR_CFLAGS =	-m$(CPU) -m$(FPU)
#Use the flag to suppress stack extension when 2.6.4/2.7 is installed.
#STACKEXTEND =	-mnostackextend
OTHER_CFLAGS =	-fomit-frame-pointer $(STACKEXTEND)
ALL_CFLAGS =	$(CFLAGS) $(FLAVOR_CFLAGS) $(OTHER_CFLAGS) $(INCS) $(DEFS)

DEFS =
INCS =		-I$(srcdir) -I$(srcdir)/../library -I$(srcdir)/../include
LIB =		library.a

# Strip the executable (-s), don't look for standard libraries (-nostdlib)
# don't link in crt0.o (-nostartfiles) and tell the linker explicitly to
# load the module from the library that defines the symbol "___load_seg"
# (-Xlinker -u -Xlinker ___load_seg).

LINKFLAGS =	-s -nostdlib -nostartfiles -Xlinker -u -Xlinker ___load_seg

# Go ahead and link in KPrintF even if its not used, since it's more trouble
# to remember to include it in debugging versions than its worth to save a
# few bytes by leaving it out.

DEBUG =		debugstub.o
DEBUGS =	debugstub.s

.SUFFIXES:	.ot

.s.o:
		cp $< x.c
		$(CC) $(ALL_CFLAGS) -traditional -E x.c -o x.s
		$(CC) $(ALL_CFLAGS) -c x.s -o $@
		rm -f x.c x.s

.s.ot:
		cp $< x.c
		$(CC) $(ALL_CFLAGS) -traditional -DTRACE_LIBRARY -E x.c -o x.s
		$(CC) $(ALL_CFLAGS) -c x.s -o $@
		rm -f x.c x.s

.c.o:
		$(CC) $(ALL_CFLAGS) -c $< -o $@

.c.ot:
		$(CC) $(ALL_CFLAGS) -DTRACE_LIBRARY -c $< -o $@


all:		ixemul.library ixemul.trace ixconfig

SRCS =		start.s version.c __close.c __fioctl.c __fselect.c __fstat.c \
		__init_std_packet.c __ioctl.c __ioerr_to_errno.c __lock.c \
		__make_link.c __mclose.c __mread.c __open.c __plock.c __read.c \
		__swrite.c __tioctl.c __unlock.c __wait_packet.c __write.c \
		access.c chdir.c chmod.c close.c creat.c fchmod.c fsync.c \
		ftime.c ftruncate.c getpriority.c getrlimit.c gettimeofday.c \
		getcrap.c ioctl.c isatty.c ix_close.c ix_expunge.c ix_init.c \
		ix_open.c link.c lseek.c malloc.c mkdir.c open.c read.c \
		readlink.c readv.c rename.c rmdir.c select.c smallfuncs.c \
		setpriority.c setrlimit.c settimeofday.c stat.c symlink.c \
		truncate.c umask.c unlink.c utime.c utimes.c write.c writev.c \
		ix_panic.c kern_sig.c machdep.c trap.s dsyscall.c kern_time.c \
		ix_timer.c kern_descrip.c ix_startup.c _cli_parse.c _wb_parse.c \
		_main.c createextio.c createport.c createstdio.c createtask.c \
		deleteextio.c deleteport.c deletestdio.c deletetask.c exit.c \
		__pipe.c pipe.c convert_dir.c opendir.c readdir.c rewinddir.c \
		closedir.c telldir.c seekdir.c ix_patch_functions.c \
		__load_seg.c mathsup.c kmalloc.c ix_get_vars2.c \
		ix_exec_entry.c vfork.c ix_sleep.c profil.c ptrace.c \
		__amiga_filehandle.c fchdir.c get_file.c ix_resident.c \
		posixconf.c ix_stubs.c statfs.c ix_sigwinch.c buddy-alloc.c \
		hwck.c __must_recompile.c socket.c $(DEBUGS)

OBJS =		version.o __close.o __fioctl.o __fselect.o __fstat.o \
		__init_std_packet.o __ioctl.o __ioerr_to_errno.o __lock.o \
		__make_link.o __mclose.o __mread.o __open.o __plock.o __read.o \
		__swrite.o __tioctl.o __unlock.o __wait_packet.o __write.o \
		access.o chdir.o chmod.o close.o creat.o fchmod.o fsync.o \
		ftime.o ftruncate.o getpriority.o getrlimit.o gettimeofday.o \
		getcrap.o ioctl.o isatty.o ix_close.o ix_expunge.o ix_init.o \
		ix_open.o link.o lseek.o malloc.o mkdir.o open.o read.o \
		readlink.o readv.o rename.o rmdir.o select.o smallfuncs.o \
		setpriority.o setrlimit.o settimeofday.o stat.o symlink.o \
		truncate.o umask.o unlink.o utime.o utimes.o write.o writev.o \
		ix_panic.o kern_sig.o machdep.o trap.o kern_time.o \
		ix_timer.o kern_descrip.o ix_startup.o _cli_parse.o _wb_parse.o \
		_main.o createextio.o createport.o createstdio.o createtask.o \
		deleteextio.o deleteport.o deletestdio.o deletetask.o exit.o \
		__pipe.o pipe.o convert_dir.o opendir.o readdir.o rewinddir.o \
		closedir.o telldir.o seekdir.o ix_patch_functions.o \
		__load_seg.o mathsup.o kmalloc.o ix_get_vars2.o \
		ix_exec_entry.o vfork.o ix_sleep.o profil.o ptrace.o \
		__amiga_filehandle.o fchdir.o get_file.o ix_resident.o \
		posixconf.o ix_stubs.o statfs.o ix_sigwinch.o buddy-alloc.o \
		hwck.o __must_recompile.o socket.o $(DEBUG)

OBJS1_N =	start.o tracecntl.o

OBJS1_T =	start.ot tracecntl.ot

LIBS =		$(LIB) \
		../../../string/$(CPU)/$(FPU)/libstring.a \
		../../../gen_library/$(CPU)/$(FPU)/libgen.a \
		../../../stdlib/$(CPU)/$(FPU)/libstdlib.a \
		../../../gnulib/$(CPU)/$(FPU)/libgnu.a \
		../../../gnulib-$(FPU)/$(CPU)/$(FPU)/libgnu.a \
		../../../stdio_2/$(CPU)/$(FPU)/libstdio.a \
		/gnu/os-lib/libamiga.a

$(LIB) :	$(OBJS)
		rm -f $@
		$(AR) rv $@ $(OBJS)
		$(RANLIB) $@

ixemul.library:	$(OBJS1_N) $(OBJS) $(OBJS1_D) $(LIBS)
		$(CC) $(LINKFLAGS) $(OBJS1_N) $(LIBS) -o $@


#LIBSFPU =	../string/libstring.a ../gen_library/libgen.a \
#		../stdlib/libstdlib.a ../gnulibfpu/libgnufpu.a ../stdio_2/libstdio.a 
#
#ixemul.library:	$(OBJS1_N) $(OBJS) $(OBJS1_D) $(LIBSFPU)
#		$(CC) -nostdlib -nostartfiles -Xlinker -u -Xlinker Start -Xlinker -s $(OBJS1_N) \
#			$(OBJS) $(LIBSFPU) -o $@
#
#ixemul.library.68020noffp: $(OBJS1_N) $(OBJS) $(OBJS1_D) $(LIBS)
#		$(CC) -nostdlib -nostartfiles -Xlinker -u -Xlinker Start -Xlinker -s $(OBJS1_N) \
#			$(OBJS) $(LIBS) -o $@
#
#ixemul.library.68020ffp: $(OBJS1_N) $(OBJS) $(OBJS1_D) $(LIBSFPU)
#		$(CC) -nostdlib -nostartfiles -Xlinker -u -Xlinker Start -Xlinker -s $(OBJS1_N) \
#			$(OBJS) $(LIBSFPU) -o $@

ixconfig:	ixconfig.c
		$(CC) $(ALL_CFLAGS) $< -o $@

ixemul.trace:	$(OBJS1_T) $(OBJS) $(OBJS1_D) $(LIBS)
		$(CC) $(LINKFLAGS) $(OBJS1_T) $(LIBS) -o $@

clean:
		rm -f *!

clobber:	clean
		rm -f $(OBJS) $(LIB)

start.o:	start.s version.h $(srcdir)/../include/sys/syscall.def

start.ot:	start.s version.h $(srcdir)/../include/sys/syscall.def

# this depends on the size of struct user (besides files that need field
# from struct user)

ix_open.o:	$(srcdir)/../include/user.h

# Force -m68020 & -m68881 so the assembler won't bitch about fpu
# instructions.  This means we have to leave out FLAVOR_CFLAGS.

trap.o:		trap.s
		cp $< x.c
		$(CC) $(CFLAGS) $(OTHER_CFLAGS) $(INCS) -traditional -E x.c -o x.s
		$(CC) $(CFLAGS) $(OTHER_CFLAGS) $(INCS) -c -m68020 -m68881 x.s -o trap.o
		rm -f x.s x.c

ix_timer.o:	ix_timer.c
		$(CC) -O2 -m68000 -msoft-float $(STACKEXTEND) -c $<

# those may not use A4, because they call back into the main program

ix_startup.o:	ix_startup.c
		$(CC) $(ALL_CFLAGS) -ffixed-a4 -c $<

debugstub.o:	debugstub.s
		$(CC) $(ALL_CFLAGS) -c $<

_main.o:	_main.c
		$(CC) $(ALL_CFLAGS) -ffixed-a4 -c $<

ix_exec_entry.o: ix_exec_entry.c
		$(CC) $(ALL_CFLAGS) -ffixed-a4 -c $<

exit.o:		exit.c
		$(CC) $(ALL_CFLAGS) -ffixed-a4 -c $<

ix_resident.o:	ix_resident.c
		$(CC) $(ALL_CFLAGS) -ffixed-a4 -c $<

tracecntl.o:	tracecntl.c
		$(CC) $(ALL_CFLAGS) -ffixed-a4 -c $<

dsyscall.o:	dsyscall.c $(srcdir)/../include/sys/syscall.def
		$(CC) $(ALL_CFLAGS) -ffixed-a4 -c $<

$(OBJS):	ixemul.h
$(OBJS1_N):	ixemul.h
$(OBJS1_T):	ixemul.h
