FLAGS =
LIBSWIN = -l:libkernel32.a -l:libuser32.a -l:libshell32.a -l:libadvapi32.a\
	-l:libws2_32.a -l:liboleaut32.a -l:libimm32.a -l:libwinmm.a -l:libole32.a\
	-l:libuuid.a -l:libopengl32.a -l:libole32.a -l:libgdi32.a

LIBSMINGW = -l:libmingw32.a -l:libgcc.a -l:libgcc_eh.a -l:libmoldname.a -l:libmingwex.a -l:libmsvcrt.a -l:libadvapi32.a -l:libshell32.a -l:libuser32.a -l:libkernel32.a -l:libiconv.a -l:libmingw32.a -l:libgcc.a -l:libgcc_eh.a -l:libmoldname.a -l:libmingwex.a -l:libmsvcrt.a

# Lookup the file flags.make
# in folder T:\libcxxabi_build\src\CMakeFiles\cxxabi_objects.dir
# to see what LIBCXXABI_FLAGS needs to be
LIBCXXABI_FLAGS = -O3 -DNDEBUG -nostdinc++ -std=c++11 -Werror=return-type -W -Wall -Wchar-subscripts -Wconversion -Wmissing-braces -Wunused-function -Wshadow -Wsign-compare -Wsign-conversion -Wstrict-aliasing=2 -Wstrict-overflow=4 -Wunused-parameter -Wunused-variable -Wwrite-strings -Wundef -Wno-error -pedantic -fstrict-aliasing -funwind-tables

# The flags.make file also tells what LIBCXXABI_DEFINES should be
#
LIBCXX_DEFINES = -D_WIN32 -D_LIBCPP_BUILDING_LIBRARY -D_LIBCPP_HAS_THREAD_API_WIN32 -D_LIBCPP_DISABLE_EXTERN_TEMPLATE -D_LIBCPP_ENABLE_CXX17_REMOVED_UNEXPECTED_FUNCTIONS

LIBCXXABI_DEFINES = -D_WIN32 -U_LIBCXXABI_DISABLE_VISIBILITY_ANNOTATIONS -D_LIBCXXABI_BUILDING_LIBRARY -Dcxxabi_shared_EXPORTS

LIBCXX_INC = -I../../libcxx/include
LIBCXXABI_INC = -I../../libcxxabi/include

OBJ_FILES = abort_message.o cxa_aux_runtime.o cxa_default_handlers.o cxa_demangle.o cxa_exception.o cxa_exception_storage.o cxa_guard.o cxa_handlers.o cxa_noexception.o cxa_personality.o cxa_thread_atexit.o cxa_unexpected.o cxa_vector.o cxa_virtual.o fallback_malloc.o private_typeinfo.o stdlib_exception.o stdlib_new_delete.o stdlib_stdexcept.o stdlib_typeinfo.o

SRC_FOLDER = ../../libcxxabi/src

all: libc++abi.dll

libc++abi.dll : cxxabi_objects.a
	g++ -shared -nodefaultlibs $(LIBSMINGW) cxxabi_objects.a -Wl,--out-implib,libc++abi.dll.a -o libc++abi.dll

cxxabi_objects.a : $(OBJ_FILES) cxa_personality_pre.cpp
	ar rc cxxabi_objects.a $(OBJ_FILES)

abort_message.o : $(SRC_FOLDER)/abort_message.cpp
	g++ -c $(LIBCXXABI_FLAGS) $(FLAGS) $(LIBCXX_DEFINES) $(LIBCXX_INC) $(LIBCXXABI_DEFINES) $(LIBCXXABI_INC) $(SRC_FOLDER)/abort_message.cpp >> result.txt

cxa_aux_runtime.o : $(SRC_FOLDER)/cxa_aux_runtime.cpp
	g++ -c $(LIBCXXABI_FLAGS) $(FLAGS) $(LIBCXX_DEFINES) $(LIBCXX_INC) $(LIBCXXABI_DEFINES) $(LIBCXXABI_INC) $(SRC_FOLDER)/cxa_aux_runtime.cpp >> result.txt

cxa_default_handlers.o : $(SRC_FOLDER)/cxa_default_handlers.cpp
	g++ -c $(LIBCXXABI_FLAGS) $(FLAGS) $(LIBCXX_DEFINES) $(LIBCXX_INC) $(LIBCXXABI_DEFINES) $(LIBCXXABI_INC) $(SRC_FOLDER)/cxa_default_handlers.cpp >> result.txt

cxa_demangle.o : $(SRC_FOLDER)/cxa_demangle.cpp
	g++ -c $(LIBCXXABI_FLAGS) $(FLAGS) $(LIBCXX_DEFINES) $(LIBCXX_INC) $(LIBCXXABI_DEFINES) $(LIBCXXABI_INC) $(SRC_FOLDER)/cxa_demangle.cpp >> result.txt

cxa_exception.o : $(SRC_FOLDER)/cxa_exception.cpp
	g++ -c $(LIBCXXABI_FLAGS) $(FLAGS) $(LIBCXX_DEFINES) $(LIBCXX_INC) $(LIBCXXABI_DEFINES) $(LIBCXXABI_INC) $(SRC_FOLDER)/cxa_exception.cpp >> result.txt

cxa_exception_storage.o : $(SRC_FOLDER)/cxa_exception_storage.cpp
	g++ -c $(LIBCXXABI_FLAGS) $(FLAGS) $(LIBCXX_DEFINES) $(LIBCXX_INC) $(LIBCXXABI_DEFINES) $(LIBCXXABI_INC) $(SRC_FOLDER)/cxa_exception_storage.cpp >> result.txt

cxa_guard.o : $(SRC_FOLDER)/cxa_guard.cpp
	g++ -c $(LIBCXXABI_FLAGS) $(FLAGS) $(LIBCXX_DEFINES) $(LIBCXX_INC) $(LIBCXXABI_DEFINES) $(LIBCXXABI_INC) $(SRC_FOLDER)/cxa_guard.cpp >> result.txt

cxa_handlers.o : $(SRC_FOLDER)/cxa_handlers.cpp
	g++ -c $(LIBCXXABI_FLAGS) $(FLAGS) $(LIBCXX_DEFINES) $(LIBCXX_INC) $(LIBCXXABI_DEFINES) $(LIBCXXABI_INC) $(SRC_FOLDER)/cxa_handlers.cpp >> result.txt

cxa_noexception.o : $(SRC_FOLDER)/cxa_noexception.cpp
	g++ -c $(LIBCXXABI_FLAGS) $(FLAGS) $(LIBCXX_DEFINES) $(LIBCXX_INC) $(LIBCXXABI_DEFINES) $(LIBCXXABI_INC) $(SRC_FOLDER)/cxa_noexception.cpp >> result.txt

cxa_personality.o : $(SRC_FOLDER)/cxa_personality.cpp
	g++ -c $(LIBCXXABI_FLAGS) $(FLAGS) $(LIBCXX_DEFINES) $(LIBCXX_INC) $(LIBCXXABI_DEFINES) $(LIBCXXABI_INC) $(SRC_FOLDER)/cxa_personality.cpp >> result.txt

cxa_personality_pre.cpp : $(SRC_FOLDER)/cxa_personality.cpp
	g++ -E $(LIBCXXABI_FLAGS) $(FLAGS) $(LIBCXX_DEFINES) $(LIBCXX_INC) $(LIBCXXABI_DEFINES) $(LIBCXXABI_INC) $(SRC_FOLDER)/cxa_personality.cpp -o cxa_personality_pre.cpp >> result.txt

cxa_thread_atexit.o : $(SRC_FOLDER)/cxa_thread_atexit.cpp
	g++ -c $(LIBCXXABI_FLAGS) $(FLAGS) $(LIBCXX_DEFINES) $(LIBCXX_INC) $(LIBCXXABI_DEFINES) $(LIBCXXABI_INC) $(SRC_FOLDER)/cxa_thread_atexit.cpp >> result.txt

cxa_unexpected.o : $(SRC_FOLDER)/cxa_unexpected.cpp
	g++ -c $(LIBCXXABI_FLAGS) $(FLAGS) $(LIBCXX_DEFINES) $(LIBCXX_INC) $(LIBCXXABI_DEFINES) $(LIBCXXABI_INC) $(SRC_FOLDER)/cxa_unexpected.cpp >> result.txt

cxa_vector.o : $(SRC_FOLDER)/cxa_vector.cpp
	g++ -c $(LIBCXXABI_FLAGS) $(FLAGS) $(LIBCXX_DEFINES) $(LIBCXX_INC) $(LIBCXXABI_DEFINES) $(LIBCXXABI_INC) $(SRC_FOLDER)/cxa_vector.cpp >> result.txt

cxa_virtual.o : $(SRC_FOLDER)/cxa_virtual.cpp
	g++ -c $(LIBCXXABI_FLAGS) $(FLAGS) $(LIBCXX_DEFINES) $(LIBCXX_INC) $(LIBCXXABI_DEFINES) $(LIBCXXABI_INC) $(SRC_FOLDER)/cxa_virtual.cpp >> result.txt

fallback_malloc.o : $(SRC_FOLDER)/fallback_malloc.cpp
	g++ -c $(LIBCXXABI_FLAGS) $(FLAGS) $(LIBCXX_DEFINES) $(LIBCXX_INC) $(LIBCXXABI_DEFINES) $(LIBCXXABI_INC) $(SRC_FOLDER)/fallback_malloc.cpp >> result.txt

private_typeinfo.o : $(SRC_FOLDER)/private_typeinfo.cpp
	g++ -c $(LIBCXXABI_FLAGS) $(FLAGS) $(LIBCXX_DEFINES) $(LIBCXX_INC) $(LIBCXXABI_DEFINES) $(LIBCXXABI_INC) $(SRC_FOLDER)/private_typeinfo.cpp >> result.txt

stdlib_exception.o : $(SRC_FOLDER)/stdlib_exception.cpp
	g++ -c $(LIBCXXABI_FLAGS) $(FLAGS) $(LIBCXX_DEFINES) $(LIBCXX_INC) $(LIBCXXABI_DEFINES) $(LIBCXXABI_INC) $(SRC_FOLDER)/stdlib_exception.cpp >> result.txt

stdlib_new_delete.o : $(SRC_FOLDER)/stdlib_new_delete.cpp
	g++ -c $(LIBCXXABI_FLAGS) $(FLAGS) $(LIBCXX_DEFINES) $(LIBCXX_INC) $(LIBCXXABI_DEFINES) $(LIBCXXABI_INC) $(SRC_FOLDER)/stdlib_new_delete.cpp >> result.txt

stdlib_stdexcept.o : $(SRC_FOLDER)/stdlib_stdexcept.cpp
	g++ -c $(LIBCXXABI_FLAGS) $(FLAGS) $(LIBCXX_DEFINES) $(LIBCXX_INC) $(LIBCXXABI_DEFINES) $(LIBCXXABI_INC) $(SRC_FOLDER)/stdlib_stdexcept.cpp >> result.txt

stdlib_typeinfo.o : $(SRC_FOLDER)/stdlib_typeinfo.cpp
	g++ -c $(LIBCXXABI_FLAGS) $(FLAGS) $(LIBCXX_DEFINES) $(LIBCXX_INC) $(LIBCXXABI_DEFINES) $(LIBCXXABI_INC) $(SRC_FOLDER)/stdlib_typeinfo.cpp >> result.txt

clean:
	del $(OBJ_FILES)