ifeq "$(targ)" "macarm"
# makefile.m64 needs to have been run in pdpclib first
# with tools=mac altld=pdld
CC=clang -S -O2 -D__ARM__ -fno-builtin -D__MACOS__ \
    -D__64BIT__ -fno-stack-protector -D__USEBIVA__ \
    -Wno-error=implicit-function-declaration \
    -mmacosx-version-min=10 \
    -D__LONG64__ \
    -I../pdpclib
AR=ar
AS=as -mmacosx-version-min=10
LD=clang -Wl,-e, -Wl,___pdpent -mmacosx-version-min=10
EXTRA2=../pdpclib/pdpmacos.a


else ifeq "$(targ)" "macamd64"
# makefile.mx6 needs to have been run in pdpclib first
CC=clang -arch x86_64 -mmacosx-version-min=11 \
    -S -O2 -fno-builtin -D__MACOS__ \
    -D__64BIT__ -D__LONG64__ \
    -fno-stack-protector  -D__gnu_linux__  -D__USEBIVA__ \
    -nostdinc \
    -I../pdpclib
AR=ar
AS=as -arch x86_64 -mmacosx-version-min=11
LD=clang -arch x86_64 -Wl,-no_uuid -Wl,-no_adhoc_codesign \
    -Wl,-e, -Wl,__start \
    -mmacosx-version-min=11
EXTRA2=../pdpclib/pdpmacos.a



else ifeq "$(targ)" "gccarm64"
# makefile.a64 needs to have been run in pdpclib first
CC=gcc -S -O2 -D__ARM__ -nostdinc -nostdlib -fno-builtin \
   -D__64BIT__ -fno-stack-protector --no-pie -D__USEBIVA__ \
   -D__LONG64__ \
   -I../pdpclib
AR=ar
AS=as
# -m64 isn't always recognized
LD=gcc -static -s -nostdlib
EXTRA1=../pdpclib/linstart.o
EXTRA2=../pdpclib/pdplinux.a

else ifeq "$(targ)" "gccamd64"
# makefile.l64 needs to have been run in pdpclib first
CC=gcc -S -O2 -D__gnu_linux__ -nostdinc -nostdlib -fno-builtin \
    -D__64BIT__ -fno-stack-protector --no-pie -D__USEBIVA__ \
    -m64 -fno-common -D__LONG64__ \
    -I../pdpclib
AR=ar
AS=as
LD=gcc -s -static -m64 -nostdlib -Wl,-e -Wl,__pdpent
EXTRA1=../pdpclib/linstart.o ../pdpclib/pdplinux.a
EXTRA2=../pdpclib/pdplinux.a


else ifeq "$(targ)" "x64"
# links with PDPCLIB created with makefile.ms6
CC=gcc
#CC=x86_64-w64-mingw32-gcc
CFLAGS=-O2
AS=pdas --64 --oformat coff
AR=xar
COPTS=-S -fno-common -fno-builtin -O2 -D__WIN32__ \
    -D__NOBIVA__ -I . -I ../pdpclib -D__64BIT__
LD=pdld
LDFLAGS=-s -nostdlib --no-insert-timestamp
EXTRA1=../pdpclib/w32start.o
EXTRA2=../pdpclib/msvcrt.a ../pdpclib/x64supb.o


else ifeq "$(targ)" "winx64e"
# You need to have run makefile.web first
AS=pdas --64 --oformat coff
#AS=as --64
CC=gcc
# Note use of EBCDIC version of pdld
# Note that we don't need an EBCDIC version of pdas because
# we're currently not using string literals that need to be
# converted, and gcc generates octal constants that aren't affected

# Note that gcc 15.2.0 was used on a Debian Linux x64 machine, with
# the following patch (released to the public domain) to
# libcpp/charset.cc :

# 654a655,657
# >       char *out_before = outbuf;
# >       char *out_after;
# >       char *out_p;
# 655a659,664
# >       out_after = outbuf;
# >       while ((out_p =
# >               (char *)memchr(out_before, 0x25, out_after - out_before)) != NULL)
# >       {
# >           *out_p = 0x15;
# >       }

# in order to get EBCDIC newline as x'15' instead of x'25'.

# Then built with:
# ./configure --target=x86_64-mingw64 --disable-multilib --enable-languages=c
# make
#

LD=pdlde --no-insert-timestamp -nostdlib
COPTS=-S -O2 -mno-sse -fno-builtin -D__64BIT__ -m64 \
    -mno-red-zone \
    -fno-common -U__gnu_linux__ -fno-stack-protector \
    -D__USEBIVA__ -D__NOSPECBIVA__ \
    -nostdlib -nostdinc \
    -D__WIN32__ --no-pie -fno-leading-underscore \
    -I../src -D__EBCDIC__ -funsigned-char \
    -fexec-charset=IBM1047 \
    -I . -I ../pdpclib -DEBCDIC
EXTRA1=../pdpclib/w32start.obj
EXTRA2=../pdpclib/msvcrt.lib ../pdpclib/x64supa.obj

else
AS=pdas --oformat coff
CC=gccwin
LD=pdld --no-insert-timestamp -nostdlib
COPTS=-S -O2 -fno-common -ansi -I. -I../pdpclib -D__WIN32__ -D__NOBIVA__
EXTRA1=../pdpclib/w32start.obj
EXTRA2=../pdpclib/msvcrt.lib
endif


COBJ=mcc.obj

all: clean mcc.exe

mcc.exe: $(COBJ)
  $(LD) $(LDFLAGS) -o mcc.exe $(EXTRA1) $(COBJ) $(EXTRA2)

.c.obj:
  $(CC) $(COPTS) $<
  $(AS) -o $@ $*.s
  rm -f $*.s

clean:
  rm -f *.o mcc.exe
