CC=clang-19
LLD_PATH=/prog/rust/build/x86_64-unknown-linux-gnu/lld/bin

PACKAGE = bash
prefix = /usr/local
datarootdir = ${prefix}/share
datadir = ${datarootdir}
infodir = ${datarootdir}/info
localedir = ${datarootdir}/locale

Machine = wasm32
OS = wasi
VENDOR = wasmer
MACHTYPE = wasm32-wasmer-wasi

CFLAGS = --target=wasm32-wasmer-wasi \
         -O2 \
         -include ../../config.h \
         --sysroot ../../../wasix-libc/sysroot32 \
         -I. \
         -I.. \
         -I../.. \
         -I../../include \
         -I../../lib \
         -matomics \
         -mbulk-memory \
         -mmutable-globals \
         -pthread \
         -mthread-model posix \
         -ftls-model=local-exec \
         -fno-trapping-math \
         -DLOCALEDIR='"$(localedir)"' \
         -DPACKAGE='"$(PACKAGE)"' \
         -DCONF_HOSTTYPE='"$(Machine)"' \
         -DCONF_OSTYPE='"$(OS)"' \
         -DCONF_MACHTYPE='"$(MACHTYPE)"' \
         -DCONF_VENDOR='"$(VENDOR)"' \
         -D_WASI_EMULATED_MMAN \
         -D_WASI_EMULATED_SIGNAL \
         -D_WASI_EMULATED_PROCESS_CLOCKS \
         -Wall \
         -Wextra \
         -Werror \
         -Wno-null-pointer-arithmetic \
         -Wno-unused-parameter \
         -Wno-sign-compare \
         -Wno-unused-variable \
         -Wno-unused-function \
         -Wno-ignored-attributes \
         -Wno-missing-braces \
         -Wno-ignored-pragmas \
         -Wno-unused-but-set-variable \
         -Wno-unknown-warning-option \
         -Wno-parentheses \
         -Wno-shift-op-parentheses \
         -Wno-bitwise-op-parentheses \
         -Wno-logical-op-parentheses \
         -Wno-string-plus-int \
         -Wno-dangling-else \
         -Wno-unknown-pragmas \
         -Wno-format-security \
         -Wno-unused-label \
         -Wno-incompatible-pointer-types \
         -Wno-deprecated-non-prototype \
         -Wno-deprecated-declarations \
         -MD \
         -MP

#SRC=$(wildcard *.c)
      
SRC = casemod \
      clktck \
      clock \
      dprintf \
      eaccess \
      fmtullong \
      fmtulong \
      fmtumax \
      fnxform \
      fpurge \
      getcwd \
      getenv \
      gettimeofday \
      inet_aton \
      input_avail \
      itos \
      mailstat \
      makepath \
      mbscasecmp \
      mbschr \
      mbscmp \
      mktime \
      netconn \
      netopen \
      oslib \
      pathcanon \
      pathphys \
      random \
      rename \
      setlinebuf \
      shmatch \
      shmbchar \
      shquote \
      shtty \
      snprintf \
      spell \
      strcasecmp \
      strcasestr \
      strchrnul \
      strdup \
      strerror \
      strftime \
      stringlist \
      stringvec \
      strnlen \
      strpbrk \
      strstr \
      strtod \
      strtol \
      strtoll \
      strtoul \
      strtoull \
      strtrans \
      times \
      timeval \
      tmpfile \
      uconvert \
      ufuncs \
      unicode \
      utf8 \
      vprint \
      wcsdup \
      wcsnwidth \
      wcswidth \
      winsize \
      zcatfd \
      zgetline \
      zmapfd \
      zread \
      zwrite

OBJS = $(SRC:=.o)

all: $(OBJS)

%: %.c
	$(CC) $(CFLAGS) \
              $@.c \
			  -c \
              -o $@.o

export PATH := $(LLD_PATH):$(PATH)

clean:
	rm -f *.o
	rm -f *.s
	rm -f *.ll
	rm -f *.wasm
