# vim: ft=make ts=4 sw=4 noet
.DEFAULT_GOAL := all

NAME    = motif
VERSION = 2.3.8
GARTYPE = v2

MASTER_SITES =
DYNURLS      = https://download.sourceforge.net/motif/$(DISTNAME).tar.gz
DISTFILES   += $(DISTNAME).tar.gz

LICENSE = COPYING

PACKAGES               += OZSWmotif
SPKG_DESC_OZSWmotif     = Motif widget toolkit and window manager (libXm, MWM)
CATALOGNAME_OZSWmotif   = motif

BUILD_DEP_PKGS += OZSWlibX11 OZSWlibXt OZSWlibXext OZSWlibXmu OZSWlibXft
BUILD_DEP_PKGS += OZSWlibXrender OZSWlibXpm OZSWlibICE OZSWlibSM
BUILD_DEP_PKGS += OZSWfreetype OZSWfontconfig OZSWlibjpeg OZSWlibpng
BUILD_DEP_PKGS += OZSWflex OZSWbison OZSWpkgconf OZSWxorgproto OZSWxbitmaps

RUNTIME_DEP_PKGS_OZSWmotif += OZSWlibX11 OZSWlibXt OZSWlibXext OZSWlibXmu OZSWlibXft
RUNTIME_DEP_PKGS_OZSWmotif += OZSWlibXrender OZSWlibXpm OZSWlibICE OZSWlibSM
RUNTIME_DEP_PKGS_OZSWmotif += OZSWfreetype OZSWfontconfig OZSWlibjpeg OZSWlibpng

EXTENSIONS = 1
EXTRA_LD_FLAGS += -lsocket -lnsl

# Point configure at our X11 tree; disable Xprint (no libXp on this system)
EXTRA_CONFIGURE_ARGS += --x-includes=$(includedir)
EXTRA_CONFIGURE_ARGS += --x-libraries=$(libdir)
EXTRA_CONFIGURE_ARGS += --disable-printing
EXTRA_CONFIGURE_ARGS += --enable-jpeg
EXTRA_CONFIGURE_ARGS += --enable-png
EXTRA_CONFIGURE_ARGS += --enable-xft
EXTRA_CONFIGURE_ARGS += --disable-static

# Xmfuncs.h defines bcopy/bzero/bcmp as function-like macros.  On Solaris,
# X11/Xos.h later includes <strings.h> which tries to declare these as
# 'extern void bcopy(const void*, void*, size_t)'.  The preprocessor expands
# the bcopy macro at the declaration site, producing invalid C syntax.
# Fix: gate both macro-definition sections with !defined(__sun) so that on
# Solaris/GCC the macros are never defined and the real prototypes stay intact.
post-extract:
	/opt/ozsw/bin/python3 $(GARDIR)/../pkg/motif/patch-motif-xmfuncs.py \
	    $(WORKSRC)/lib/Xm/Xmfuncs.h
	@$(MAKECOOKIE)

# Fix libtool ksh ECHO on Solaris (bash doesn't have "print -r --")
post-configure:
	@find $(WORKSRC) -name "libtool" -type f -exec \
	    gsed -i 's/ECHO="print -r --"/ECHO="printf %s\\n"/g' {} \;
	@$(MAKECOOKIE)

include gar/category.mk
