#
# $Id: GNUmakefile.os4,v 1.8 2004-09-27 15:04:51 tfrieden Exp $
#
# :ts=8
#
# -*- mode: makefile; -*-

##############################################################################

# You may have to tweak this for the native OS4 compiler
SDK_INCLUDE = $(V)/include
NET_INCLUDE = netinclude

# These are for the cross compiler
CC = ppc-amigaos-gcc
AR = ppc-amigaos-ar -q
RANLIB = ppc-amigaos-ranlib
COPY = cp
DELETE = rm -r
MAKEDIR = mkdir

# The following are for the native OS4 compiler
# CC = gcc
# AR = ar -q
# RANLIB = ranlib
# COPY = copy
# DELETE = delete all quiet
# MAKEDIR = makedir

MAKE = make -f GNUmakefile.os4

##############################################################################

ifeq (,$(TYPE))
LIBC_OBJS	= libc_objs
LIBUNIX_OBJS	= libunix_objs
LIBM_OBJS	= libm_objs
LIBSTACK_OBJS	= libstack_objs
LIBNET_OBJS	= libnet_objs
LIBDEBUG_OBJS	= libdebug_objs
LIBAMIGA_OBJS	= libamiga_objs
else
LIBC_OBJS	= $(TYPE)/libc_objs
LIBUNIX_OBJS	= $(TYPE)/libunix_objs
LIBM_OBJS	= $(TYPE)/libm_objs
LIBSTACK_OBJS	= $(TYPE)/libstack_objs
LIBNET_OBJS	= $(TYPE)/libnet_objs
LIBDEBUG_OBJS	= $(TYPE)/libdebug_objs
LIBAMIGA_OBJS	= $(TYPE)/libamiga_objs
endif

##############################################################################

%.o : %.c
	@echo "Compiling $<"
	@$(CC) -c $(CFLAGS) -DPPC_FLOATING_POINT_SUPPORT $<

$(LIBC_OBJS)/%.o : %.c
	@echo "Compiling $< [$(TYPE):c]"
	@$(CC) -o $(LIBC_OBJS)/$*.o -c $(CFLAGS) $<

$(LIBUNIX_OBJS)/%.o : %.c
	@echo "Compiling $< [$(TYPE):unix]"
	@$(CC) -o $(LIBUNIX_OBJS)/$*.o -c $(CFLAGS) -DUNIX_PATH_SEMANTICS $<

$(LIBM_OBJS)/%.o : %.c
	@echo "Compiling $< [$(TYPE):m]"
	@$(CC) -o $(LIBM_OBJS)/$*.o -c $(CFLAGS)  $<

$(LIBSTACK_OBJS)/%.o : %.c
	@echo "Compiling $< [$(TYPE):stack]"
	@$(CC) -o $(LIBSTACK_OBJS)/$*.o -c $(CFLAGS) $<

$(LIBNET_OBJS)/%.o : %.c
	@echo "Compiling $< [$(TYPE):net]"
	@$(CC) -o $(LIBNET_OBJS)/$*.o -c $(CFLAGS) -I$(NET_INCLUDE) -DSOCKET_SUPPORT -DUSERGROUP_SUPPORT $<

$(LIBDEBUG_OBJS)/%.o : %.c
	@echo "Compiling $< [$(TYPE):debug]"
	@$(CC) -o $(LIBDEBUG_OBJS)/$*.o -c $(CFLAGS) $<

$(LIBAMIGA_OBJS)/%.o : %.c
	@echo "Compiling $< [$(TYPE):amiga]"
	@$(CC) -o $(LIBAMIGA_OBJS)/$*.o -c $(CFLAGS) $<

##############################################################################

ifeq (small_data,$(TYPE))
CODE_TYPE := -msdata=sysv -DSMALL_DATA -DPPC_FLOATING_POINT_SUPPORT
endif

ifeq (large_data,$(TYPE))
CODE_TYPE := -msdata=data -DPPC_FLOATING_POINT_SUPPORT
endif

ifeq (large_data_softfloat, $(TYPE))
CODE_TYPE := -msdata=data -msoft-float
endif

##############################################################################

WARNINGS = \
	-Wall -W -Wshadow -Wpointer-arith -Wsign-compare -Wmissing-prototypes \
	-Wundef -Wbad-function-cast -Wmissing-declarations -Wconversion

INCLUDES = -Iinclude -I. -I$(SDK_INCLUDE)
OPTIONS = -DNDEBUG -DUSE_64_BIT_INTS -fno-builtin -D__USE_INLINE__ -Wa,-mregnames
OPTIMIZE = -O3 -fomit-frame-pointer -funroll-loops
#DEBUG = -g

CFLAGS = $(WARNINGS) $(OPTIMIZE) $(DEBUG) $(OPTIONS) $(CODE_TYPE) $(INCLUDES)

##############################################################################

C_LIB = \
	c.lib_rev.o \
	ctype_isalnum.o \
	ctype_isalpha.o \
	ctype_isascii.o \
	ctype_iscntrl.o \
	ctype_isdigit.o \
	ctype_isgraph.o \
	ctype_islower.o \
	ctype_isprint.o \
	ctype_ispunct.o \
	ctype_isspace.o \
	ctype_isupper.o \
	ctype_isxdigit.o \
	ctype_tolower.o \
	ctype_toupper.o \
	ctype_table.o \
	dirent_closedir.o \
	dirent_data.o \
	dirent_opendir.o \
	dirent_readdir.o \
	dirent_rewinddir.o \
	errno_data.o \
	fcntl_close.o \
	fcntl_creat.o \
	fcntl_fcntl.o \
	fcntl_lseek.o \
	fcntl_open.o \
	fcntl_read.o \
	fcntl_write.o \
	fcntl_get_default_file.o \
	libgen_basename.o \
	libgen_dirname.o \
	locale_data.o \
	locale_init_exit.o \
	locale_localeconv.o \
	locale_setlocale.o \
	mount_convertinfo.o \
	mount_fstatfs.o \
	mount_statfs.o \
	signal_checkabort.o \
	signal_data.o \
	signal_kill.o \
	signal_raise.o \
	signal_sigaddset.o \
	signal_sigblock.o \
	signal_sigemptyset.o \
	signal_sigmask.o \
	signal_signal.o \
	signal_sigprocmask.o \
	signal_sigsetmask.o \
	stat_chmod.o \
	stat_convertfileinfo.o \
	stat_data.o \
	stat_fchmod.o \
	stat_fstat.o \
	stat_lstat.o \
	stat_mkdir.o \
	stat_rmdir.o \
	stat_stat.o \
	stat_umask.o \
	stdio_asprintf.o \
	stdio_clearerr.o \
	stdio_data.o \
	stdio_dropiobreadbuffer.o \
	stdio_duplicate_fd.o \
	stdio_fclose.o \
	stdio_fdhookentry.o \
	stdio_feof.o \
	stdio_ferror.o \
	stdio_fflush.o \
	stdio_flush.o \
	stdio_fgetc.o \
	stdio_fgetpos.o \
	stdio_fgets.o \
	stdio_filliobreadbuffer.o \
	stdio_findvacantfdentry.o \
	stdio_findvacantiobentry.o \
	stdio_flushiobwritebuffer.o \
	stdio_fopen.o \
	stdio_fprintf.o \
	stdio_fputc.o \
	stdio_fputs.o \
	stdio_fread.o \
	stdio_freopen.o \
	stdio_fscanf.o \
	stdio_fseek.o \
	stdio_fsetpos.o \
	stdio_ftell.o \
	stdio_fwrite.o \
	stdio_getc.o \
	stdio_getchar.o \
	stdio_get_file_descriptor.o \
	stdio_gets.o \
	stdio_growfdtable.o \
	stdio_growiobtable.o \
	stdio_initializefd.o \
	stdio_initializeiob.o \
	stdio_init_exit.o \
	stdio_iobhookentry.o \
	stdio_locksemaphorename.o \
	stdio_nostdio.o \
	stdio_openiob.o \
	stdio_perror.o \
	stdio_popen.o \
	stdio_printf.o \
	stdio_putc.o \
	stdio_putchar.o \
	stdio_puts.o \
	stdio_remove.o \
	stdio_rename.o \
	stdio_rewind.o \
	stdio_scanf.o \
	stdio_setbuf.o \
	stdio_setvbuf.o \
	stdio_snprintf.o \
	stdio_sprintf.o \
	stdio_sscanf.o \
	stdio_sscanf_hook_entry.o \
	stdio_tmpfile.o \
	stdio_tmpnam.o \
	stdio_translateioerror.o \
	stdio_ungetc.o \
	stdio_vasprintf.o \
	stdio_vasprintf_hook_entry.o \
	stdio_vfprintf.o \
	stdio_vfscanf.o \
	stdio_vprintf.o \
	stdio_vsnprintf.o \
	stdio_vsnprintf_hook_entry.o \
	stdio_vsprintf.o \
	stdio_vsprintf_hook_entry.o \
	stdlib_abort.o \
	stdlib_abs.o \
	stdlib_alloca.o \
	stdlib_assertion_failure.o \
	stdlib_atexit.o \
	stdlib_atoi.o \
	stdlib_atol.o \
	stdlib_bsearch.o \
	stdlib_calloc.o \
	stdlib_data.o \
	stdlib_default_pool_size.o \
	stdlib_default_puddle_size.o \
	stdlib_destructor.o \
	stdlib_disablerequesters.o \
	stdlib_div.o \
	stdlib_modsi3.o \
	stdlib_divsi3.o \
	stdlib_divsi4.o \
	stdlib_umodsi3.o \
	stdlib_udivsi3.o \
	stdlib_udivsi4.o \
	stdlib_exit.o \
	stdlib_free.o \
	stdlib_getenv.o \
	stdlib_getsp.o \
	stdlib_init_exit.o \
	stdlib_labs.o \
	stdlib_ldiv.o \
	stdlib_getdefstacksize.o \
	stdlib_stackargbytes.o \
	stdlib_stack_usage.o \
	stdlib_checkdetach.o \
	stdlib_detach.o \
	stdlib_isresident.o \
	stdlib_sysbase.o \
	stdlib_dosbase.o \
	stdlib_machine_test.o \
	stdlib_malloc.o \
	stdlib_math.o \
	stdlib_mkdtemp.o \
	stdlib_mkstemp.o \
	stdlib_mktemp.o \
	stdlib_mulsi3.o \
	stdlib_never_free.o \
	stdlib_putenv.o \
	stdlib_qsort.o \
	stdlib_rand.o \
	stdlib_realloc.o \
	stdlib_red_black.o \
	stdlib_setenv.o \
	stdlib_setjmp.o \
	stdlib_shell_escape.o \
	stdlib_showerror.o \
	stdlib_socket.o \
	stdlib_srand.o \
	stdlib_stackcheck.o \
	stdlib_stackoverflow.o \
	stdlib_stacksafezone.o \
	stdlib_stacksize.o \
	stdlib_startup.o \
	stdlib_strtol.o \
	stdlib_strtoul.o \
	stdlib_strtoll.o \
	stdlib_strtoull.o \
	stdlib_swapstack.o \
	stdlib_system.o \
	stdlib_termination_message.o \
	stdlib_threshold.o \
	stdlib_unsetenv.o \
	stdlib_usergroup.o \
	stdlib_wildcard_expand.o \
	strings_strcasecmp.o \
	strings_strncasecmp.o \
	string_bcmp.o \
	string_bcopy.o \
	string_bzero.o \
	string_index.o \
	string_memchr.o \
	string_memcmp.o \
	string_memcpy.o \
	string_memmove.o \
	string_memset.o \
	string_rindex.o \
	string_strcat.o \
	string_strchr.o \
	string_strcmp.o \
	string_strcoll.o \
	string_strcpy.o \
	string_strcspn.o \
	string_strdup.o \
	string_strerror.o \
	string_strlen.o \
	string_strncat.o \
	string_strncmp.o \
	string_strncpy.o \
	string_strpbrk.o \
	string_strrchr.o \
	string_strspn.o \
	string_strstr.o \
	string_strtok.o \
	string_strxfrm.o \
	time_asctime.o \
	time_clock.o \
	time_converttime.o \
	time_ctime.o \
	time_data.o \
	time_gettimeofday.o \
	time_gmtime.o \
	time_localtime.o \
	time_mktime.o \
	time_numbertostring.o \
	time_strftime.o \
	time_time.o \
	unistd_access.o \
	unistd_chdir.o \
	unistd_chown.o \
	unistd_currentpathname.o \
	unistd_data.o \
	unistd_dup.o \
	unistd_dup2.o \
	unistd_fchown.o \
	unistd_fdopen.o \
	unistd_fileno.o \
	unistd_ftruncate.o \
	unistd_getcwd.o \
	unistd_getopt.o \
	unistd_getpid.o \
	unistd_init_exit.o \
	unistd_isatty.o \
	unistd_lchown.o \
	unistd_link.o \
	unistd_readlink.o \
	unistd_realpath.o \
	unistd_sleep.o \
	unistd_symlink.o \
	unistd_truncate.o \
	unistd_unlink.o \
	utime_utime.o 


UNIX_LIB = \
	unix.lib_rev.o \
	dirent_closedir.o \
	dirent_data.o \
	dirent_opendir.o \
	dirent_readdir.o \
	dirent_rewinddir.o \
	fcntl_creat.o \
	fcntl_fcntl.o \
	fcntl_open.o \
	fcntl_get_default_file.o \
	mount_convertinfo.o \
	mount_statfs.o \
	stat_chmod.o \
	stat_fstat.o \
	stat_lstat.o \
	stat_mkdir.o \
	stat_rmdir.o \
	stat_stat.o \
	stdio_fdhookentry.o \
	stdio_init_exit.o \
	stdio_locksemaphorename.o \
	stdio_openiob.o \
	stdio_fflush.o \
	stdio_fopen.o \
	stdio_fopen.o \
	stdio_popen.o \
	stdio_remove.o \
	stdio_rename.o \
	stdlib_mkdtemp.o \
	stdlib_mkstemp.o \
	stdlib_mkstemp.o \
	stdlib_mktemp.o \
	stdlib_system.o \
	unistd_access.o \
	unistd_chdir.o \
	unistd_chown.o \
	unistd_getcwd.o \
	unistd_lchown.o \
	unistd_link.o \
	unistd_readlink.o \
	unistd_realpath.o \
	unistd_restorepathname.o \
	unistd_setcurrentpath.o \
	unistd_strip_double_slash.o \
	unistd_translatea2u.o \
	unistd_translaterel.o \
	unistd_translateu2a.o \
	unistd_truncate.o \
	unistd_unix_path_semantics.o \
	unistd_unlink.o \
	unistd_wildcard_expand.o \
	utime_utime.o

MATH_LIB = \
	math_acos.o \
	math_asin.o \
	math_atan.o \
	math_atan2.o \
	math_ceil.o \
	math_cos.o \
	math_cosh.o \
	math_data.o \
	math_exp.o \
	math_fabs.o \
	math_floor.o \
	math_fmod.o \
	math_frexp.o \
	math_hypot.o \
	math_init_exit.o \
	math_isnan.o \
	math_isinf.o \
	math_ldexp.o \
	math_log.o \
	math_log10.o \
	math_logb.o \
	math_modf.o \
	math_pow.o \
	math_rint.o \
	math_rintf.o \
	math_sin.o \
	math_sinh.o \
	math_sqrt.o \
	math_tan.o \
	math_tanh.o \
	math_kernel_expm1.o \
	math_kernel_scalbn.o \
	math_kernel_tan.o \
	math_kernel_cos.o \
	math_kernel_rem_pio2.o \
	math_kernel_sin.o \
	stdio_asprintf.o \
	stdio_flush.o \
	stdio_fprintf.o \
	stdio_fscanf.o \
	stdio_printf.o \
	stdio_scanf.o \
	stdio_snprintf.o \
	stdio_sprintf.o \
	stdio_sscanf.o \
	stdio_vasprintf.o \
	stdio_vfprintf.o \
	stdio_vfscanf.o \
	stdio_vfscanf.o \
	stdio_vprintf.o \
	stdio_vsnprintf.o \
	stdio_vsprintf.o \
	stdlib_atof.o \
	stdlib_machine_test.o \
	stdlib_strtod.o \
	time_difftime.o

MATH_LIB_IEEE = \
	m.lib_rev.o \
	$(MATH_LIB) \
	math_adddf3.o \
	math_addsf3.o \
	math_divdf3.o \
	math_divsf3.o \
	math_eqdf2.o \
	math_eqsf2.o \
	math_extendsfdf2.o \
	math_fixdfsi.o \
	math_fixsfsi.o \
	math_fixunsdfsi.o \
	math_fixunssfsi.o \
	math_floatsidf.o \
	math_floatsisf.o \
	math_gedf2.o \
	math_gesf2.o \
	math_gtdf2.o \
	math_gtsf2.o \
	math_ledf2.o \
	math_lesf2.o \
	math_ltdf2.o \
	math_ltsf2.o \
	math_muldf3.o \
	math_mulsf3.o \
	math_nedf2.o \
	math_negdf2.o \
	math_negsf2.o \
	math_nesf2.o \
	math_subdf3.o \
	math_subsf3.o \
	math_truncdfsf2.o

STACK_LIB = \
	stack.lib_rev.o \
	stdlib_setjmp.o \
	stdlib_stackextension.o \
	stdlib_stackminframe.o \
	stdlib_stackoverflow.o \
	stdlib_stacksafezone.o

NET_LIB = \
	net.lib_rev.o \
	socket_accept.o \
	socket_bind.o \
	socket_connect.o \
	socket_data.o \
	socket_gethostbyaddr.o \
	socket_gethostbyname.o \
	socket_gethostid.o \
	socket_gethostname.o \
	socket_getnetbyaddr.o \
	socket_getnetbyname.o \
	socket_getpeername.o \
	socket_getprotobyname.o \
	socket_getprotobynumber.o \
	socket_getservbyname.o \
	socket_getservbyport.o \
	socket_getsockname.o \
	socket_getsockopt.o \
	socket_get_descriptor.o \
	socket_inet_addr.o \
	socket_inet_aton.o \
	socket_inet_lnaof.o \
	socket_inet_makeaddr.o \
	socket_inet_netof.o \
	socket_inet_network.o \
	socket_inet_ntoa.o \
	socket_init_exit.o \
	socket_ioctl.o \
	socket_isdaemon.o \
	socket_listen.o \
	socket_recv.o \
	socket_recvfrom.o \
	socket_recvmsg.o \
	socket_select.o \
	socket_send.o \
	socket_sendmsg.o \
	socket_sendto.o \
	socket_setsockopt.o \
	socket_shutdown.o \
	socket_socket.o \
	socket_hook_entry.o \
	socket_hstrerror.o \
	usergroup_crypt.o \
	usergroup_data.o \
	usergroup_endgrent.o \
	usergroup_endpwent.o \
	usergroup_getegid.o \
	usergroup_geteuid.o \
	usergroup_getgid.o \
	usergroup_getgrent.o \
	usergroup_getgrgid.o \
	usergroup_getgrnam.o \
	usergroup_getgroups.o \
	usergroup_getpass.o \
	usergroup_getpwent.o \
	usergroup_getpwnam.o \
	usergroup_getpwuid.o \
	usergroup_getuid.o \
	usergroup_initgroups.o \
	usergroup_init_exit.o \
	usergroup_rootmode.o \
	usergroup_setegid.o \
	usergroup_seteuid.o \
	usergroup_setgid.o \
	usergroup_setgrent.o \
	usergroup_setgroups.o \
	usergroup_setpwent.o \
	usergroup_setregid.o \
	usergroup_setreuid.o \
	usergroup_setsid.o \
	usergroup_setuid.o \
	stat_umask.o

DEBUG_LIB = \
	debug.lib_rev.o \
	debug.o \
	debug_level.o \
	debug_cmpstrexec.o \
	debug_kcmpstr.o \
	debug_kdofmt.o \
	debug_kgetc.o \
	debug_kgetch1.o \
	debug_kgetch2.o \
	debug_kgetchar1.o \
	debug_kgetchar2.o \
	debug_kgetnum1.o \
	debug_kgetnum2.o \
	debug_kmaygetch.o \
	debug_kmaygetchar.o \
	debug_kprintf1.o \
	debug_kprintf2.o \
	debug_kputc.o \
	debug_kputch1.o \
	debug_kputch2.o \
	debug_kputchar1.o \
	debug_kputchar2.o \
	debug_kputfmt.o \
	debug_kputs1.o \
	debug_kputs2.o \
	debug_kputstr1.o \
	debug_kputstr2.o \
	debug_kvprintf1.o \
	debug_kvprintf2.o

AMIGA_LIB = \
	amiga.lib_rev.o \
	amiga_acrypt.o \
	amiga_addtof.o \
	amiga_argarraydone.o \
	amiga_argarrayinit.o \
	amiga_argint.o \
	amiga_argstring.o \
	amiga_callhooka.o \
	amiga_coercemethod.o \
	amiga_createstdio.o \
	amiga_deletestdio.o \
	amiga_domethod.o \
	amiga_dosupermethod.o \
	amiga_dotimer.o \
	amiga_fastrand.o \
	amiga_freeievents.o \
	amiga_hotkey.o \
	amiga_invertstring.o \
	amiga_rangerand.o \
	amiga_remtof.o \
	amiga_setsuperattrs.o \
	amiga_timedelay.o \
	amiga_waitbeam.o 

##############################################################################

LIBS := $(LIBC_OBJS)/libc.a $(LIBSTACK_OBJS)/libstack.a $(LIBUNIX_OBJS)/libunix.a \
            $(LIBDEBUG_OBJS)/libdebug.a $(LIBAMIGA_OBJS)/libamiga.a \
            $(LIBM_OBJS)/libm.a $(LIBNET_OBJS)/libnet.a

##############################################################################


##############################################################################

STARTUPS := crt0.o crtbegin.o crtend.o mainnb.o

##############################################################################

all: \
	lib/crt0.o \
	lib/crtbegin.o \
	lib/crtend.o \
	lib/mainnb.o \
	lib/libm.a \
	lib/small-data/libm.a \
	lib/bcrt0.o \
	lib/bcrtbegin.o \
	lib/bcrtend.o \
	lib/soft-float/libc.a

copy:
	$(COPY) $(foreach file,$(LIBS),large_data/$(file)) lib

##############################################################################

clean:
	-$(DELETE) $(TYPE)  $(STARTUPS) \
		$(LIBC_OBJS) $(LIBUNIX_OBJS) $(LIBM_OBJS) $(LIBSTACK_OBJS) $(LIBNET_OBJS) $(LIBDEBUG_OBJS) $(LIBAMIGA_OBJS)

realclean:
	$(MAKE) clean
	-$(DELETE) lib small_data large_data

##############################################################################

version:
	cp c.lib_rev.rev amiga.lib_rev.rev
	cp c.lib_rev.rev debug.lib_rev.rev
	cp c.lib_rev.rev m.lib_rev.rev
	cp c.lib_rev.rev m881.lib_rev.rev
	cp c.lib_rev.rev net.lib_rev.rev
	cp c.lib_rev.rev stack.lib_rev.rev
	cp c.lib_rev.rev unix.lib_rev.rev
	bumprev 1 amiga.lib
	bumprev 1 c.lib
	bumprev 1 debug.lib
	bumprev 1 m.lib
	bumprev 1 m881.lib
	bumprev 1 net.lib
	bumprev 1 stack.lib
	bumprev 1 unix.lib

##############################################################################

cvs-tag:
	cvs -q tag V1_`cat c.lib_rev.rev`

##############################################################################

kitchen_sink: $(TYPE) $(LIBS) $(STARTUPS)

##############################################################################

ifneq (,$(TYPE))
$(TYPE):
	$(MAKEDIR) $@
endif

##############################################################################

lib:
	-$(MAKEDIR) $@

lib/small-data:
	-$(MAKEDIR) $@

lib/soft-float:
	-$(MAKEDIR) $@

lib/libm.a: lib
	$(MAKE) TYPE=large_data kitchen_sink
	$(COPY) $(foreach file,$(LIBS),large_data/$(file)) lib

lib/small-data/libm.a: lib lib/small-data
	$(MAKE) TYPE=small_data kitchen_sink
	$(COPY) $(foreach file,$(LIBS),small_data/$(file)) lib/small-data

lib/soft-float/libc.a: lib lib/soft-float
	$(MAKE) TYPE=large_data_softfloat kitchen_sink
	$(COPY) $(foreach file,$(LIBS),large_data_softfloat/$(file)) lib/soft-float

lib/crt0.o : lib crt0.o
	$(COPY) crt0.o lib

lib/crtbegin.o : lib crtbegin.o
	$(COPY) crtbegin.o lib

lib/crtend.o : lib crtend.o
	$(COPY) crtend.o lib

lib/mainnb.o : lib mainnb.o
	$(COPY) mainnb.o lib

lib/mainb.o : lib mainb.o
	$(COPY) mainb.o lib

lib/bcrt0.o : lib bcrt0.o
	$(COPY) bcrt0.o lib

lib/bcrtbegin.o : lib bcrtbegin.o
	$(COPY) bcrtbegin.o lib

lib/bcrtend.o : lib bcrtend.o
	$(COPY) bcrtend.o lib
	
##############################################################################

$(LIBAMIGA_OBJS)/amiga_hookentry.o : amiga_hookentry.c

$(LIBC_OBJS)/stdlib_getsp.o : stdlib_getsp.c

$(LIBC_OBJS)/stdlib_swapstack.o : stdlib_swapstack.c

$(LIBC_OBJS)/stdlib_setjmp.o : stdlib_setjmp.c

$(LIBSTACK_OBJS)/stdlib_setjmp.o : stdlib_setjmp.c

##############################################################################

$(LIBC_OBJS)/stdlib_stacksize.o : stdlib_stacksize.c stdlib_gcc_help.h

$(LIBC_OBJS)/stdlib_shell_escape.o : stdlib_shell_escape.c stdlib_gcc_help.h

$(LIBC_OBJS)/stdlib_alloca.o : stdlib_alloca.c stdlib_mem_debug.h

$(LIBC_OBJS)/stdlib_calloc.o : stdlib_calloc.c stdlib_mem_debug.h

$(LIBC_OBJS)/stdlib_free.o : stdlib_free.c stdlib_mem_debug.h

$(LIBC_OBJS)/stdlib_init_exit.o : stdlib_init_exit.c stdlib_mem_debug.h

$(LIBC_OBJS)/stdlib_malloc.o : stdlib_malloc.c stdlib_mem_debug.h

$(LIBC_OBJS)/stdlib_realloc.o : stdlib_realloc.c stdlib_mem_debug.h

$(LIBC_OBJS)/stdlib_red_black.o : stdlib_red_black.c stdlib_mem_debug.h

##############################################################################

$(LIBC_OBJS) :
	$(MAKEDIR) $@

$(LIBC_OBJS)/libc.a : $(LIBC_OBJS) $(foreach file,$(C_LIB),$(LIBC_OBJS)/$(file))
	-$(DELETE) $@
	@$(AR) $@ $(foreach file,$(C_LIB),$(LIBC_OBJS)/$(file))
	$(RANLIB) $@

##############################################################################

$(LIBUNIX_OBJS) :
	$(MAKEDIR) $@

$(LIBUNIX_OBJS)/libunix.a : $(LIBUNIX_OBJS) $(foreach file,$(UNIX_LIB),$(LIBUNIX_OBJS)/$(file))
	-$(DELETE) $@
	@$(AR) $@ $(foreach file,$(UNIX_LIB),$(LIBUNIX_OBJS)/$(file))
	$(RANLIB) $@

##############################################################################

$(LIBM_OBJS) :
	$(MAKEDIR) $@

$(LIBM_OBJS)/libm.a : $(LIBM_OBJS) $(foreach file,$(MATH_LIB_IEEE),$(LIBM_OBJS)/$(file))
	-$(DELETE) $@
	@$(AR) $@ $(foreach file,$(MATH_LIB_IEEE),$(LIBM_OBJS)/$(file))
	$(RANLIB) $@

##############################################################################

$(LIBSTACK_OBJS) :
	$(MAKEDIR) $@

$(LIBSTACK_OBJS)/libstack.a : $(LIBSTACK_OBJS) $(foreach file,$(STACK_LIB),$(LIBSTACK_OBJS)/$(file))
	-$(DELETE) $@
	@$(AR) $@ $(foreach file,$(STACK_LIB),$(LIBSTACK_OBJS)/$(file))
	$(RANLIB) $@

##############################################################################

$(LIBNET_OBJS) :
	$(MAKEDIR) $@

$(LIBNET_OBJS)/libnet.a : $(LIBNET_OBJS) $(foreach file,$(NET_LIB),$(LIBNET_OBJS)/$(file))
	-$(DELETE) $@
	@$(AR) $@ $(foreach file,$(NET_LIB),$(LIBNET_OBJS)/$(file))
	$(RANLIB) $@

##############################################################################

$(LIBDEBUG_OBJS) :
	$(MAKEDIR) $@

$(LIBDEBUG_OBJS)/libdebug.a : $(LIBDEBUG_OBJS) $(foreach file,$(DEBUG_LIB),$(LIBDEBUG_OBJS)/$(file))
	-$(DELETE) $@
	@$(AR) $@ $(foreach file,$(DEBUG_LIB),$(LIBDEBUG_OBJS)/$(file))
	$(RANLIB) $@

##############################################################################

$(LIBAMIGA_OBJS) :
	$(MAKEDIR) $@

$(LIBAMIGA_OBJS)/libamiga.a : $(LIBAMIGA_OBJS) $(foreach file,$(AMIGA_LIB),$(LIBAMIGA_OBJS)/$(file))
	-$(DELETE) $@
	@$(AR) $@ $(foreach file,$(AMIGA_LIB),$(LIBAMIGA_OBJS)/$(file))
	$(RANLIB) $@

##############################################################################

crt0.o : crt0.S
	@echo "Assembling $<"
	@$(CC) -Wa,-mregnames -o crt0.o -c crt0.S

bcrt0.o : crt0.S
	@echo "Assembling $<"
	@$(CC) -DSMALL_DATA -Wa,-mregnames -o bcrt0.o -c crt0.S

mainnb.o : stdlib_main.c
	@echo "Compiling $<"
	@$(CC) -o mainnb.o -c $(WARNINGS) $(OPTIMIZE) $(DEBUG) $(OPTIONS) $(INCLUDES) -msdata=data stdlib_main.c

mainb.o : stdlib_main.c
	@echo "Compiling $<"
	@$(CC) -o mainb.o -c $(WARNINGS) $(OPTIMIZE) $(DEBUG) $(OPTIONS) $(INCLUDES) -msdata=sysv -DSMALL_DATA stdlib_main.c

bcrtbegin.o : crtbegin.c
	$(CC) -o bcrtbegin.o -c $(WARNINGS) $(OPTIMIZE) $(DEBUG) $(OPTIONS) $(INCLUDES) -msdata=sysv -DSMALL_DATA crtbegin.c 

bcrtend.o : crtend.c
	$(CC) -o bcrtend.o -c $(WARNINGS) $(OPTIMIZE) $(DEBUG) $(OPTIONS) $(INCLUDES) -msdata=sysv -DSMALL_DATA crtend.c 


##############################################################################

mkid:
#	mkid -v #?.(c|h|asm|i) include/#?.(c|h|asm|i) include/sys/#?.(c|h|asm|i)
	mkid *.[ch] include/*.h include/sys/*.h

update:
	mkid -v -u
