# ===========================================================================
#
#                            PUBLIC DOMAIN NOTICE
#               National Center for Biotechnology Information
#
#  This software/database is a "United States Government Work" under the
#  terms of the United States Copyright Act.  It was written as part of
#  the author's official duties as a United States Government employee and
#  thus cannot be copyrighted.  This software/database is freely available
#  to the public for use. The National Library of Medicine and the U.S.
#  Government have not placed any restriction on its use or reproduction.
#
#  Although all reasonable efforts have been taken to ensure the accuracy
#  and reliability of the software and data, the NLM and the U.S.
#  Government do not and cannot warrant the performance or results that
#  may be obtained by using this software or data. The NLM and the U.S.
#  Government disclaim all warranties, express or implied, including
#  warranties of performance, merchantability or fitness for any particular
#  purpose.
#
#  Please cite the author in any work or product based on this material.
#
# ===========================================================================


## build rules
LOC_INFO = -D__mod_name__=$(MODULE) -D__file_name__=$*

# executable image
%.$(OBJX): %.c
	$(CC) -o $@ $(OPT) $< $(LOC_INFO) -D__file_ext__=c
%.$(OBJX): %.cpp
	$(CP) -o $@ $(OPT) $< $(LOC_INFO) -D__file_ext__=cpp
%.$(OBJX): %.cxx
	$(CP) -o $@ $(OPT) $< $(LOC_INFO) -D__file_ext__=cxx

# non-optimized executable image
%.nopt.$(OBJX): %.c
	$(CC) -o $@ $(NOPT) $< $(LOC_INFO) -D__file_ext__=c
%.nopt.$(OBJX): %.cpp
	$(CP) -o $@ $(NOPT) $< $(LOC_INFO) -D__file_ext__=cpp
%.nopt.$(OBJX): %.cxx
	$(CP) -o $@ $(NOPT) $< $(LOC_INFO) -D__file_ext__=cxx

# relocatable image
%.$(LOBX): %.c
	$(CC) -o $@ -fPIC $(OPT) -D_LIBRARY $< $(LOC_INFO) -D__file_ext__=c
%.$(LOBX): %.cpp
	$(CP) -o $@ -fPIC $(OPT) -D_LIBRARY $< $(LOC_INFO) -D__file_ext__=cpp
%.$(LOBX): %.cxx
	$(CP) -o $@ -fPIC $(OPT) -D_LIBRARY $< $(LOC_INFO) -D__file_ext__=cxx

# non-optimized relocatable image
%.nopt.$(LOBX): %.c
	$(CC) -o $@ -fPIC $(NOPT) -D_LIBRARY $< $(LOC_INFO) -D__file_ext__=c
%.nopt.$(LOBX): %.cpp
	$(CP) -o $@ -fPIC $(NOPT) -D_LIBRARY $< $(LOC_INFO) -D__file_ext__=cpp
%.nopt.$(LOBX): %.cxx
	$(CP) -o $@ -fPIC $(NOPT) -D_LIBRARY $< $(LOC_INFO) -D__file_ext__=cxx

# non-optimized relocatable image with persisted image byte swapping
%.swap.nopt.$(LOBX): %.c
	$(CC) -o $@ -fPIC -DSWAP_PERSISTED $(NOPT) -D_LIBRARY $< $(LOC_INFO) -D__file_ext__=c
%.swap.nopt.$(LOBX): %.cpp
	$(CP) -o $@ -fPIC -DSWAP_PERSISTED $(NOPT) -D_LIBRARY $< $(LOC_INFO) -D__file_ext__=cpp
%.swap.nopt.$(LOBX): %.cxx
	$(CP) -o $@ -fPIC -DSWAP_PERSISTED $(NOPT) -D_LIBRARY $< $(LOC_INFO) -D__file_ext__=cxx

# assembly
%.$(OBJX) %.$(LOBX): %.s
	$(CC) -o $@ $<

# assembly language output
%.s: %.c
	$(CC) -S -o $@ $(OPT) $<
%.s: %.cpp
	$(CP) -S -o $@ $(OPT) $<
%.s: %.cxx
	$(CP) -S -o $@ $(OPT) $<

%.nopt.s: %.c
	$(CC) -S -o $@ $(NOPT) $<
%.nopt.s: %.cpp
	$(CP) -S -o $@ $(NOPT) $<
%.nopt.s: %.cxx
	$(CP) -S -o $@ $(NOPT) $<

%.pic.s: %.c
	$(CC) -S -o $@ -fPIC $(OPT) $<
%.pic.s: %.cpp
	$(CP) -S -o $@ -fPIC $(OPT) $<
%.pic.s: %.cxx
	$(CP) -S -o $@ -fPIC $(OPT) $<

%.nopt.pic.s: %.c
	$(CC) -S -o $@ -fPIC $(NOPT) $<
%.nopt.pic.s: %.cpp
	$(CP) -S -o $@ -fPIC $(NOPT) $<
%.nopt.pic.s: %.cxx
	$(CP) -S -o $@ -fPIC $(NOPT) $<


# version include generation
%.vers.h: %.vers
	$(TOP)/build/make-vers-inc.sh $^ > $@
