#
#     This program is free software; you can redistribute it and/or modify
#     it under the terms of the GNU General Public License as published by
#     the Free Software Foundation; either version 2 of the License, or
#     (at your option) any later version.
#
#     A copy of the GNU General Public License can be found at
#     http://www.gnu.org/
#
# Written by Corinna Vinschen <vinschen@redhat.de>
#
# Makefile for Cygwin subauthentication DLL.

SHELL := /bin/sh

srcdir          := /usr/src/testing/newlib-cygwin-2.11.2-1/newlib-cygwin/winsup/lsaauth
VPATH           := /usr/src/testing/newlib-cygwin-2.11.2-1/newlib-cygwin/winsup/lsaauth
prefix          := /usr
exec_prefix     := ${prefix}

bindir          := ${exec_prefix}/bin
etcdir          := $(exec_prefix)/etc

INSTALL         := /usr/bin/install -c
INSTALL_PROGRAM := /usr/bin/install -c
INSTALL_DATA    := /usr/bin/install -c -m 644

CC              := x86_64-pc-cygwin-cc -L/usr/src/testing/newlib-cygwin-2.11.2-1/build/x86_64-pc-cygwin/winsup/cygwin -isystem /usr/src/testing/newlib-cygwin-2.11.2-1/newlib-cygwin/winsup/cygwin/include -B/usr/src/testing/newlib-cygwin-2.11.2-1/build/x86_64-pc-cygwin/newlib/ -isystem /usr/src/testing/newlib-cygwin-2.11.2-1/build/x86_64-pc-cygwin/newlib/targ-include -isystem /usr/src/testing/newlib-cygwin-2.11.2-1/newlib-cygwin/newlib/libc/include   
CC_FOR_TARGET   := $(CC)

MINGW32_CC	:= 
MINGW64_CC	:= x86_64-w64-mingw32-gcc

CFLAGS          := -g -O2 

include $(srcdir)/../Makefile.common

target_cpu:=x86_64

WIN32_INCLUDES  := -I. -I$(srcdir)
WIN32_CFLAGS    := $(CFLAGS) $(WIN32_INCLUDES)
WIN32_LDFLAGS	:= $(CFLAGS) -nostdlib -Wl,-shared

# Never again try to remove advapi32.  It does not matter if the DLL calls
# advapi32 functions or the equivalent ntdll functions.
# But if the LSA authentication DLL is not linked against advapi32, it's
# not recognized by LSA.
LIBS		:= -ladvapi32 -lkernel32 -lntdll

ifneq ($(target_cpu),x86_64)
DLL32	:=	cyglsa.dll
DEF32	:=	cyglsa.def
OBJ32	:=	cyglsa.o
endif

DLL64	:=	cyglsa64.dll
DEF64	:=	cyglsa64.def
OBJ64	:=	cyglsa64.o

.SUFFIXES:
.NOEXPORT:

all: Makefile $(DLL32) $(DLL64)

$(DEF32): cyglsa.din config.status
	$(SHELL) config.status

$(DLL32): $(OBJ32) $(DEF32)
	$(MINGW32_CC) -s $(WIN32_LDFLAGS) -e _DllMain@12 -o $@ $^ $(LIBS)

$(OBJ32): cyglsa.c
	$(MINGW32_CC) $(WIN32_CFLAGS) -c -o $@ $<

$(DLL64): $(OBJ64) $(DEF64)
	$(MINGW64_CC) -s $(WIN32_LDFLAGS) -e DllMain -o $@ $^ $(LIBS)

$(OBJ64): cyglsa.c
	$(MINGW64_CC) $(WIN32_CFLAGS) -c -o $@ $<

.PHONY: all install clean realclean

realclean: clean
	rm -f  Makefile config.cache

clean:
	rm -f *.o *.dll cyglsa.def

install: all
	/bin/mkdir -p $(DESTDIR)$(bindir)
ifneq ($(target_cpu),x86_64)
	$(INSTALL_PROGRAM) $(DLL32) $(DESTDIR)$(bindir)/$(DLL32)
endif
	$(INSTALL_PROGRAM) $(DLL64) $(DESTDIR)$(bindir)/$(DLL64)
	$(INSTALL_PROGRAM) $(srcdir)/cyglsa-config $(DESTDIR)$(bindir)/cyglsa-config
