#
# This file and its contents are supplied under the terms of the
# Common Development and Distribution License ("CDDL"), version 1.0.
# You may only use this file in accordance with the terms of version
# 1.0 of the CDDL.
#
# A full copy of the text of the CDDL should have accompanied this
# source.  A copy of the CDDL is also available via the Internet at
# http://www.illumos.org/license/CDDL.
#

#
# Copyright 2018 Jason King.
# Copyright 2019 Joyent, Inc.
#

include $(SRC)/Makefile.master
include $(SRC)/cmd/Makefile.cmd
include $(SRC)/cmd/Makefile.ctf
include $(SRC)/test/Makefile.com

ROOTBINDIR = $(ROOTOPTPKG)/bin

PROG = cxx rust

OBJS_common = main.o
OBJS_rust = rust.o
OBJS_cxx = afl-fast.o gcc-libstdc++.o llvm-stdcxxabi.o

ROOTOPTPKG = $(ROOT)/opt/util-tests
TESTDIR = $(ROOTOPTPKG)/tests/demangle

CMDS = $(PROG:%=$(TESTDIR)/%)
$(CMDS) := FILEMODE = 0555

cxx := OBJS = $(OBJS_common) $(OBJS_cxx)
rust := OBJS = $(OBJS_common) $(OBJS_cxx)

$(OBJS_rust) $(OBJS_cxx) := SMATCH = off

SRCS = $(OBJS:%.o=%.c)

CSTD = $(CSTD_GNU99)

LDLIBS += -ldemangle-sys -lumem

all: $(PROG)

cxx: $(OBJS_common) $(OBJS_cxx)
	$(LINK.c) -o $@ $(OBJS_common) $(OBJS_cxx) $(LDLIBS)
	$(POST_PROCESS)

rust: $(OBJS_rust)
	$(LINK.c) -o $@ $(OBJS_common) $(OBJS_rust) $(LDLIBS)
	$(POST_PROCESS)

install: all $(CMDS)

clobber: clean
	-$(RM) $(PROG)

clean:
	-$(RM) $(OBJ_common) $(OBJS_cxx) $(OBJS_rust)

$(CMDS): $(TESTDIR) $(PROG)

$(ROOTBINDIR):
	$(INS.dir)

$(ROOTBINDIR)/%: %
	$(INS.file)

$(TESTDIR):
	$(INS.dir)

$(TESTDIR)/%: %
	$(INS.file)
