##=============================================================
## Common Makefile defines for building EQUINOX-3D plugins
##
## AUTHOR:  Gabor Nagy
## DATE:    2024-Aug-07 21:03:59
##
## Copyright (C) 1996-2026 by Gabor Nagy. All rights reserved.
##=============================================================

ifeq ($(EQUINOX3D_DIR),)
EQUINOX3D_DIR = ../..
endif

## Identify the operating system
##
ifeq ($(OSNAME),)
	ifeq ($(OS),Windows_NT)
		OSNAME = WIN32
		DSO_SUFFIX = .dll
		ifeq ($(PROCESSOR_ARCHITEW6432),AMD64)
			OSNAME += -AMD64
		else
			ifeq ($(PROCESSOR_ARCHITECTURE),AMD64)
				OSNAME += -AMD64
			endif
			ifeq ($(PROCESSOR_ARCHITECTURE),x86)
				OSNAME += -IA32
			endif
		endif
	else
		UNAME_S := $(shell uname -s)
		ifeq ($(UNAME_S),Linux)
			OSNAME = Linux
			DSO_SUFFIX = .so
		endif
		ifeq ($(UNAME_S),Darwin)
			OSNAME = -MacOSX
			DSO_SUFFIX = .so
		endif

		UNAME_M := $(shell uname -m)
		ifneq ($(filter %x86,$(UNAME_Mw)),)
			ARCH := x86
		endif

		UNAME_P := $(shell uname -p)
		ifeq ($(UNAME_P),x86_64)
			OSNAME += -x86_64
		endif
		ifneq ($(filter %86,$(UNAME_P)),)
			OSNAME += -IA32
		endif
		ifneq ($(filter arm%,$(UNAME_P)),)
			OSNAME += -ARM
		endif
	endif
endif


E_DIR					= $(HOME)/eqxbuild
ESRC_DIR			= $(EQUINOX3D_DIR)/src
EINC_DIR      =	$(ESRC_DIR)/include
EINC          =	-I$(EINC_DIR)
EOBJ_DIR      =	$(E_DIR)/obj
EICON_DIR			=	$(E_DIR)/icons

CF            =	-Wall
OPTFLAG       =	-O3

## Mac OS-X
ifeq ($(shell uname),Darwin)
XINC       = -I/opt/X11/include
#DSO_CF    = -fPIC -Wall -flat_namespace -export-dynamic -mfpmath=387
DSO_CF     = -fPIC -Wall
DSO_LD     = cc -bundle -flat_namespace -undefined dynamic_lookup
DSO_LD_CPP = g++ -bundle -undefined dynamic_lookup

UNAME_M := $(shell uname -m)
ifeq ($(filter %86,$(UNAME_M)),)
# Un-comment this if Eqx3D was built on an Intel CPU on MacOS. It forces x64 architecture for builds, so they are compatible with the released x64 Eqx3D binary.
# Starting with 1.4.0-beta-38, we have native Arm / Apple Silicon builds for MacOS now.
#ARCH_FLAG  = -arch x86_64
endif
else
## Linux/IRIX
##
XINC       = -I/usr/X11R6/include
#DSO_LD    = ld -shared
DSO_LD     = gcc -shared
DSO_LD_CPP = gcc -shared
DSO_CF     = -fPIC -Wall -Wshadow -mfpmath=387
endif

DSO_CF     += $(ARCH_FLAG)
DSO_LD     += $(ARCH_FLAG)
DSO_LD_CPP += $(ARCH_FLAG)

include		$(EQUINOX3D_DIR)/src/Plugins/IconRules.make


DSO_DIR =	$(EQUINOX3D_DIR)/Plugins

CFLAGS  =	-c $(OPTFLAG) $(CF) -fPIC -DUSEOpenGL -DEX11 $(STDINC) $(EINC)
