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

# Useful directories

JX_ROOT := ../..

CODEDIR  := .
JCOREDIR := ${JX_ROOT}/include/jcore
JXDIR    := ${JX_ROOT}/include/jx

JLIBDIR     := ${JX_ROOT}/lib
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}

# other constants

DATA_FILES := class_map option_map need_font_list

# makemake variables

include ${JX_ROOT}/include/make/jx_constants
include ${JX_ROOT}/include/make/jx_config

DEPENDFLAGS := ${J_COMPILER_DEPEND_FLAGS} \
               ${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 jxlayout

.PHONY : Makefiles
Makefiles:

#
# required libraries
#

.PHONY : libs
libs:
	@cd ${JCORELIBDIR}; ${MAKE}
	@cd ${JXLIBDIR};    ${MAKE}

.PHONY : touch
touch::
	@cd ${JCORELIBDIR}; ${MAKE} TOUCHSTRING=${TOUCHSTRING} touch
	@cd ${JXLIBDIR};    ${MAKE} TOUCHSTRING=${TOUCHSTRING} touch

#
# JX source distribution (DISTR_TAR_FILE)
#

SRC_FILE_DIR := ${JX}/programs/jxlayout

.PHONY : jxsource
jxsource:
	@cd ${J_DISTR_TAR_DIR}; \
     tar -rf ${DISTR_TAR_FILE} ${addprefix ${SRC_FILE_DIR}/, \
             README LICENSE Make.header Make.files \
             jfdesign jxlayout.cc ${DATA_FILES}}

#
# JX binary distributions (DISTR_TAR_FILE)
#

.PHONY : jxshared
jxshared: jxlayout
	@strip jxlayout
	@ln -s ${JX_INSTALL_ROOT}/fdesign ./fdesign
	@cd ${J_DISTR_TAR_DIR}; \
     tar -rhf ${DISTR_TAR_FILE} ${addprefix ${SRC_FILE_DIR}/, \
              README LICENSE fdesign jfdesign jxlayout ${DATA_FILES}}
	@${RM} fdesign

#
# install binaries
#

.PHONY : jxinstall
jxinstall: jxlayout
	@strip jxlayout
	@mv jxlayout ${JX_INSTALL_ROOT}/
	@cp ${DATA_FILES} ${JX_INSTALL_ROOT}/
	@chmod a+x jfdesign
	@cp jfdesign ${JX_INSTALL_ROOT}/

.PHONY : jxuninstall
jxuninstall:
	@${RM} ${addprefix ${JX_INSTALL_ROOT}/, jxlayout ${DATA_FILES} jfdesign}

#
# debugging version
#

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

.PHONY : debug
debug: staticACE libs
	@${RM} jxlayout
	@${MAKE} "LOADLIBES=${DEBUG_LOADLIBES}" jxlayout

.PHONY : staticACE
staticACE:
	@cd ${ACELIBDIR}; ${MAKE} static

#
# personal install
#

.PHONY : jafl
jafl: debug
	@strip jxlayout
	@mv jxlayout ${JX_INSTALL_ROOT}/
