include("plat/build.lua")

tabgen {
	name = "ctype_tab",
	srcs = { "./core/ctype/char.tab" }
}

normalrule {
	name = "ctype_files",
	ins = { "./core/ctype/genfiles" },
	outleaves = {
		"isalnum.c",
		"isalpha.c",
		"isascii.c",
		"iscntrl.c",
		"isdigit.c",
		"isgraph.c",
		"islower.c",
		"isprint.c",
		"ispunct.c",
		"isspace.c",
		"isupper.c",
		"isxdigit.c",
	},
	commands = {
		"sh %{ins[1]} %{dir}"
	}
}

for _, plat in ipairs(vars.plats) do
	acklibrary {
		name = "lib_"..plat,
		srcs = {
			"+ctype_files",
			"+ctype_tab",
			"./core/ctype/tolower.c",
			"./core/ctype/toupper.c",
			"./core/errno/errlist.c",
			"./core/errno/perror.c",
			"./core/errno/strerror.c",
			"./core/locale/localeconv.c",
			"./core/locale/setlocale.c",
			"./core/math/asin.c",
			"./core/math/atan2.c",
			"./core/math/atan.c",
			"./core/math/ceil.c",
			"./core/math/exp.c",
			"./core/math/fabs.c",
			"./core/math/floor.c",
			"./core/math/fmod.c",
			"./core/math/frexp.e",
			"./core/math/hugeval.c",
			"./core/math/hypot.c",
			"./core/math/isnan.c",
			"./core/math/ldexp.c",
			"./core/math/log10.c",
			"./core/math/log.c",
			"./core/math/modf.e",
			"./core/math/pow.c",
			"./core/math/sin.c",
			"./core/math/sinh.c",
			"./core/math/sqrt.c",
			"./core/math/tan.c",
			"./core/math/tanh.c",
			"./core/misc/abort.c",
			"./core/misc/assert.c",
			"./core/misc/getopt.c",
			"./core/misc/raise.c",
			"./core/misc/termcap.c",
			"./core/printf/doprnt.c",
			"./core/printf/fltpr.c",
			"./core/printf/fprintf.c",
			"./core/printf/icompute.c",
			"./core/printf/itoa.c",
			"./core/printf/printf.c",
			"./core/printf/snprintf.c",
			"./core/printf/sprintf.c",
			"./core/printf/vfprintf.c",
			"./core/printf/vprintf.c",
			"./core/printf/vsnprintf.c",
			"./core/printf/vsprintf.c",
			"./core/scanf/doscan.c",
			"./core/scanf/fscanf.c",
			"./core/scanf/scanf.c",
			"./core/scanf/sscanf.c",
			"./core/scanf/vfscanf.c",
			"./core/setjmp/setjmp.e",
			"./core/setjmp/sigmisc.c",
			"./core/stdio/clearerr.c",
			"./core/stdio/feof.c",
			"./core/stdio/ferror.c",
			"./core/stdio/fgetc.c",
			"./core/stdio/fgetpos.c",
			"./core/stdio/fgets.c",
			"./core/stdio/fputc.c",
			"./core/stdio/fputs.c",
			"./core/stdio/fread.c",
			"./core/stdio/fsetpos.c",
			"./core/stdio/fwrite.c",
			"./core/stdio/getc.c",
			"./core/stdio/getchar.c",
			"./core/stdio/gets.c",
			"./core/stdio/getw.c",
			"./core/stdio/putc.c",
			"./core/stdio/putchar.c",
			"./core/stdio/puts.c",
			"./core/stdio/putw.c",
			"./core/stdio/rewind.c",
			"./core/stdlib/abs.c",
			"./core/stdlib/atof.c",
			"./core/stdlib/atoi.c",
			"./core/stdlib/atol.c",
			"./core/stdlib/bsearch.c",
			"./core/stdlib/div.c",
			"./core/stdlib/ecvt.c",
			"./core/stdlib/environ.c",
			"./core/stdlib/ext_comp.c",
			"./core/stdlib/getenv.c",
			"./core/stdlib/labs.c",
			"./core/stdlib/ldiv.c",
			"./core/stdlib/mblen.c",
			"./core/stdlib/mbstowcs.c",
			"./core/stdlib/mbtowc.c",
			"./core/stdlib/putenv.c",
			"./core/stdlib/qsort.c",
			"./core/stdlib/rand.c",
			"./core/stdlib/setenv.c",
			"./core/stdlib/strtod.c",
			"./core/stdlib/strtol.c",
			"./core/stdlib/wcstombs.c",
			"./core/stdlib/wctomb.c",
			"./core/string/memchr.c",
			"./core/string/memcmp.c",
			"./core/string/memcpy.c",
			"./core/string/memmove.c",
			"./core/string/memset.c",
			"./core/string/strcat.c",
			"./core/string/strchr.c",
			"./core/string/strcmp.c",
			"./core/string/strcoll.c",
			"./core/string/strcpy.c",
			"./core/string/strcspn.c",
			"./core/string/strdup.c",
			"./core/string/strlen.c",
			"./core/string/strncat.c",
			"./core/string/strncmp.c",
			"./core/string/strncpy.c",
			"./core/string/strpbrk.c",
			"./core/string/strrchr.c",
			"./core/string/strspn.c",
			"./core/string/strstr.c",
			"./core/string/strtok.c",
			"./core/string/strxfrm.c",
			"./core/time/asctime.c",
			"./core/time/ctime.c",
			"./core/time/difftime.c",
			"./core/time/gmtime.c",
			"./core/time/localtime.c",
			"./core/time/misc.c",
			"./core/time/mktime.c",
			"./core/time/strftime.c",
			"./core/time/tzset.c",
			"./sys/exit/atexit.c",
			"./sys/exit/exit.c",
			"./sys/malloc/calloc.c",
			"./sys/malloc/malloc.c",
			"./sys/malloc/realloc.c",
			"./sys/misc/clock.c",
			"./sys/misc/getpass.c",
			"./sys/misc/isatty.c",
			"./sys/misc/mktemp.c",
			"./sys/misc/popen.c",
			"./sys/misc/remove.c",
			"./sys/misc/sleep.c",
			"./sys/misc/system.c",
			"./sys/misc/time.c",
			"./sys/stdio/data.c",
			"./sys/stdio/fclose.c",
			"./sys/stdio/fdopen.c",
			"./sys/stdio/fflush.c",
			"./sys/stdio/fileno.c",
			"./sys/stdio/fillbuf.c",
			"./sys/stdio/flushbuf.c",
			"./sys/stdio/fopen.c",
			"./sys/stdio/freopen.c",
			"./sys/stdio/fseek.c",
			"./sys/stdio/ftell.c",
			"./sys/stdio/setbuf.c",
			"./sys/stdio/setvbuf.c",
			"./sys/stdio/tmpfile.c",
			"./sys/stdio/tmpnam.c",
			"./sys/stdio/ungetc.c",
		},
		hdrs = {}, -- must be empty
		deps = {
			"lang/cem/libcc.ansi/headers+pkg",
			"plat/"..plat.."/include+pkg",
			"./core/math/localmath.h",
			"./core/stdlib/ext_fmt.h",
			"./core/time/loc_time.h",
			"./sys/malloc/malloc.h",
		},
		vars = { plat = plat }
	}

	ackfile {
		name = "crt_"..plat,
		srcs = { "./head_ac.e" },
		vars = { plat = plat },
		deps = {
			"h+emheaders"
		}
	}

	local suffix = plat:find("^em") and "m" or "o"
	installable {
		name = "pkg_"..plat,
		map = {
			"lang/cem/libcc.ansi/headers+pkg",
			["$(PLATIND)/"..plat.."/c-ansi."..suffix] = "+crt_"..plat,
			["$(PLATIND)/"..plat.."/libc.a"] = "+lib_"..plat,
		}
	}
end

