# To use this file, first run "makemake" and then run "make".
# (makemake is part of the JX distribution)

# Useful directories

JX_ROOT := ../..

CODEDIR := ./code

JCOREDIR := ${JX_ROOT}/include/jcore
JCOREDIR := ${shell if { test -d ${JCOREDIR}; } \
                    then { echo ${JCOREDIR}; } \
                    else { echo /usr/include/jcore; } fi }

JXDIR := ${JX_ROOT}/include/jx
JXDIR := ${shell if { test -d ${JXDIR}; } \
                 then { echo ${JXDIR}; } \
                 else { echo /usr/include/jx; } fi }

JLIBDIR := ${JX_ROOT}/lib
JLIBDIR := ${shell if { test -d ${JLIBDIR}; } \
                   then { echo ${JLIBDIR}; } \
                   else { echo /usr/lib; } fi }

JCORELIBDIR := ${JX_ROOT}/libjcore
JXLIBDIR    := ${JX_ROOT}/libjx
ACELIBDIR   := ${JX_ROOT}/ACE

# Directories to search for header files (= for J_X11_INCLUDE_DIR)

SEARCHDIRS = -I- \
             -I${CODEDIR} \
             -I${JCOREDIR} \
             -I${JXDIR} \
             ${J_X11_INCLUDE_DIR}

ifdef ACE_ROOT
SEARCHDIRS += -I${ACE_ROOT}
endif

# other constants

XDND_VERSION := v3
XDND_DIR     := xdnd-${XDND_VERSION}

# makemake variables

MAKE_INCLUDE_DIR := ${JX_ROOT}/include/make
MAKE_INCLUDE_DIR := ${shell if { test -d ${MAKE_INCLUDE_DIR}; } \
                            then { echo ${MAKE_INCLUDE_DIR}; } \
                            else { echo /usr/lib/jx/make; } fi }

include ${MAKE_INCLUDE_DIR}/jx_constants
include ${MAKE_INCLUDE_DIR}/jx_config

DEPENDFLAGS := ${J_COMPILER_DEPEND_FLAGS} \
               -g ${SEARCHDIRS}

# library dependencies

ifdef J_BUILD_SHARED_LIB
  LIB_DEPS := ${JLIBDIR}/libjcore-${JX_LIB_VERSION}.so \
              ${JLIBDIR}/libjx-${JX_LIB_VERSION}.so
else
  LIB_DEPS := ${JLIBDIR}/libjcore-${JX_LIB_VERSION}.a \
              ${JLIBDIR}/libjx-${JX_LIB_VERSION}.a
endif

# make variables

LOADLIBES := -L${JLIBDIR} ${ljx} ${ljcore} ${J_SYS_LIBS}
LDFLAGS   := 

#####

.PHONY : default
default: libs all

.PHONY : Makefiles
Makefiles:

#
# required libraries
#

.PHONY : libs
libs:
	@${shell if { test -f ${JCORELIBDIR}/Makefile; } \
             then { echo "cd ${JCORELIBDIR}; ${MAKE}"; } fi }
	@${shell if { test -f ${JXLIBDIR}/Makefile; } \
             then { echo "cd ${JXLIBDIR}; ${MAKE}"; } fi }

.PHONY : touch
touch::
	@${shell if { test -f ${JCORELIBDIR}/Makefile; } \
             then { echo "cd ${JCORELIBDIR}; \
                    ${MAKE} TOUCHSTRING=${TOUCHSTRING} touch"; } fi }
	@${shell if { test -f ${JXLIBDIR}/Makefile; } \
             then { echo "cd ${JXLIBDIR}; \
                    ${MAKE} TOUCHSTRING=${TOUCHSTRING} touch"; } fi }

#
# JX source distribution (DISTR_TAR_FILE)
#

SRC_FILE_DIR := ${JX}/libjx/test

.PHONY : jxsource
jxsource: jxshared
	@cd ${J_DISTR_TAR_DIR}; \
     tar -rf ${DISTR_TAR_FILE} \
             ${SRC_FILE_DIR}/README_xdnd_source \
             ${SRC_FILE_DIR}/README_xdnd_binary

#
# JX binary distributions (DISTR_TAR_FILE)
#

.PHONY : jxshared
jxshared:
	@cd ${J_DISTR_TAR_DIR}; \
     tar -rf ${DISTR_TAR_FILE} ${filter-out %.o %~, \
                                 ${shell cd ${J_DISTR_TAR_DIR}; echo \
             ${addprefix ${SRC_FILE_DIR}/, \
               Make.* testjx.fd about_* test.html} \
             ${SRC_FILE_DIR}/code/* \
             ${SRC_FILE_DIR}/image/* }}

.PHONY : jxlink
jxlink: jxshared

#
# debugging version
#

DEBUG_LOADLIBES := -L${JLIBDIR} \
                   -Xlinker -Bstatic \
                   ${ljx} ${ljcore} ${J_ACE_LIBS} \
                   -Xlinker -Bdynamic \
                   ${J_X11_LIBS} ${J_GCC_LIBS}

.PHONY : debug
debug: libs
	@cd ${ACELIBDIR}; ${MAKE} static
	@${RM} testjx
	@${MAKE} "LOADLIBES=${DEBUG_LOADLIBES}" testjx

#
# XDND sample distribution
#

.PHONY : xdnd
xdnd: debug
	@strip testjx
	@${RM} -r ${XDND_DIR}
	@mkdir ${XDND_DIR}
	@strip ${XDND_DIR}/test_xdnd
	@cp README_xdnd_binary ${XDND_DIR}/README_binary
	@tar -czf xdnd-${XDND_VERSION}-binary.tgz ${XDND_DIR}/
	@${RM} -r ${XDND_DIR}

	@cp README_xdnd_source ${XDND_DIR}/README_source
	@cp ${JX_ROOT}/jx/JXDNDManager.cc \
        ${JX_ROOT}/jx/JXDNDManager.h \
        ${JX_ROOT}/jx/JXDNDChooseDropActionDialog.cc \
        ${JX_ROOT}/jx/JXDNDChooseDropActionDialog.h \
        ${JX_ROOT}/jx/JXSelectionManager.cc \
        ${JX_ROOT}/jx/JXSelectionManager.h \
        ${JX_ROOT}/jx/jXUtil.cc \
        ${JX_ROOT}/jx/jXUtil.h \
        ${XDND_DIR}/
	@tar -czf xdnd-${XDND_VERSION}-source.tgz ${XDND_DIR}/
	@${RM} -r ${XDND_DIR}
