#
# Makefile for the DXE library and the respective test programs.
# Copyright (C) 2000 Andrew Zabolotny <bit@eltech.ru>
#
# Type `make' to get the dxe2gen tool and the libdl.a library.
# Type `make install' to build and install the tool and library.
# Type `make test' to build all the test programs and DXE modules.
# Type `make clean' to remove all generated files.
#

.SUFFIXES: .o .c .cpp .exe .dxe
VPATH = src test

DEBUG = 0

CC = gcc -c
CFLAGS = -Iinclude -Wall

CXX = gxx -c
CXXFLAGS = $(CFLAGS) -fno-exceptions

LD = gcc
LDFLAGS =

AR = ar

ifeq ($(DEBUG),1)
  CFLAGS += -g
  LDFLAGS += -g
else
  CFLAGS += -s -O6
  LDFLAGS += -s
endif

DXE2GEN = dxe2gen.exe
LIBDL = libdl.a

%.o: %.cpp
	$(CXX) $(CXXFLAGS) -o $@ $<
%.o: %.c
	$(CC) $(CFLAGS) -o $@ $<
%.exe:
	$(LD) $(LDFLAGS) -o $@ $^

all: $(DXE2GEN) $(LIBDL)

install: all
	copy $(subst /,\,$(DXE2GEN) $(DJDIR)/bin)
	copy $(subst /,\,$(LIBDL) $(DJDIR)/lib)
	copy $(subst /,\,src/dxe2.ld $(DJDIR)/lib)
	copy $(subst /,\,include/*.* $(DJDIR)/include)

clean:
	rm -f *.o *.a *.dxe *.exe

test: simple.exe unresolv.exe reexp.exe statsimp.exe statlink.exe \
      test1.dxe test2.dxe test3.dxe

dxe2gen.exe: dxe2gen.o
simple.exe: simple.o $(LIBDL)
unresolv.exe: unresolv.o $(LIBDL)
reexp.exe: reexp.o $(LIBDL)
statsimp.exe: statsimp.o libtest1.a $(LIBDL)
statlink.exe: statlink.o libtest2.a $(LIBDL)

$(LIBDL): dxe2api.o dxe2stat.o
	$(AR) crs $@ $^

libtest1.a: test1.dxe $(DXE2GEN)
	$(DXE2GEN) -I $@ $<

libtest2.a: test2.dxe $(DXE2GEN)
	$(DXE2GEN) -I $@ $<

test1.dxe: $(DXE2GEN) test1.o
	$(DXE2GEN) -o $@ $(filter-out $(DXE2GEN),$^) -lc

test2.dxe: $(DXE2GEN) test2.o
	$(DXE2GEN) -o $@ $(filter-out $(DXE2GEN),$^) -U

test3.dxe: $(DXE2GEN) test3.o
	$(DXE2GEN) -o $@ $(filter-out $(DXE2GEN),$^) -U
