# Makefile for src directory
# $Id: Makefile,v 1.86 2002/01/09 21:11:53 vadz Exp $

# Our master target.  Put it here so all the intermediate targets generated
# while reading the Names.mk files won't be considered the master one.
all:	binary

# Get all the names that need to be generated.  The Names.mk file in each
# subdirectory fills in these parameters.
#
# Objects we will build to be included in the M binary
MOBJS	:=
# Modules, compiled separately or bound directly
MSOS	:=
# Source files to be scanned for translation strings
MSGSRC	:=
# Generated objects to be removed by clean
CLEAN	:=
#
include ../makeopts $(wildcard .src/*/Names.mk) $(wildcard $(patsubst .src/%/Names.mk,%/*.d,$(wildcard .src/*/Names.mk)))

# modules: MOBJS get linked in statically, MSOS installed as shared libs
ifeq ($(USE_MODULES),static)
# static, link modules directly
MOBJS	+= $(MSOS:.so=.o)
MSOS	:= 
else
ifeq ($(USE_MODULES),dynamic)
# dynamic, nothing to do
else
# none, don't compile modules
MSOS	:=
endif
endif

# LeakTracer must be the last object on the linker line!
ifdef USE_LEAKTRACER
MOBJS += util/LeakTracer.o
endif

include ../makerules

# OK, we've got all the names and the rules to generate them; we can
# now actually specify the dependencies.
binary:	M $(MSOS)
	@true
M:	$(MOBJS)
	$(LINK) -o M $(MOBJS) $(LDFLAGS) $(GUI_LIBS) $(LIBS)

Mdll:	libM.so
	$(LINK) -o M $(LDFLAGS) libM.so

libM.so: $(MOBJS)
	$(CXX) -o libM.so -shared -Xlinker -z -Xlinker nodefs $(MOBJS) $(LDFLAGS) $(NONPLIBS) $(LDFLAGS) $(GUI_LIBS) $(LIBS)

# build the binary which is statically linked to wxGTK, dynamically to
# everything else
quartstatic: $(MOBJS)
	$(LINK) -o M $(MOBJS) $(LDFLAGS) $(GUI_LIBS_QUARTSTATIC) $(LIBS)

# build the binary which is statically linked to wxGTK and GTK+, dynamically
# to everything else
semistatic: $(MOBJS)
	$(LINK) -o M $(MOBJS) $(LDFLAGS) $(GUI_LIBS_SEMISTATIC) $(LIBS)

# build a (completely) statically linked binary
static: $(MOBJS)
	$(LINK) -o M $(MOBJS) $(LDFLAGS) -static $(GUI_LIBS_STATIC) $(LIBS)

doc:
	@true

clean:
	$(RM) core libM.so M $(CLEAN)
	$(RM) $(MOBJS) $(MSOS)
	$(RM) $(MOBJS:.o=.d) $(MSOS:.so=.d)

install:
	$(INSTALL_PROGRAM) -s -m 755 M $(DATADIR)/$(CANONICAL_HOST)/bin
	if test -f libM.so; \
	then $(INSTALL_PROGRAM) libM.so $(DATADIR)/$(CANONICAL_HOST)/lib; \
	fi
	$(RM) -f $(BINDIR)/M $(DATADIR)/bin/M
	ln -f -s ../share/Mahogany/$(CANONICAL_HOST)/bin/M $(BINDIR)/M
	$(RM) $(BINDIR)/mahogany
	ln -f -s ../share/Mahogany/$(CANONICAL_HOST)/bin/M $(BINDIR)/mahogany
ifeq ($(USE_MODULES),dynamic)
	$(INSTALL) -d $(MODULEDIR)
	set -e $(MSOS); while test $$# -ge 1; \
	do $(INSTALL_PROGRAM) $$1 $(MODULEDIR); shift; done
endif
	$(INSTALL) -d $(DATADIR)/icons
	for i in .src/icons/*.xpm; \
	do $(INSTALL_DATA) $$i $(DATADIR)/icons; \
	done
ifdef USE_PYTHON
	$(INSTALL) -d $(DATADIR)/scripts
	for i in Python/*.py Python/.src/Scripts/*.py; \
		do $(INSTALL_DATA) $$i $(DATADIR)/scripts; \
	done
endif

# invoked from locale to build message catalog
msgcat:
ifeq "$(TRANSLATIONS)" "yes"
	cd .src; exec $(XGETTEXT) -C -k_ -o $(BUILDDIR)/messages.po $(MSGSRC)
# Yes, there really are some translatable strings in ../include
	$(MAKE) -C ../include msgcat
else
	false translation tools are not installed
endif

.PHONY:	all clean doc quartstatic semistatic static install msgcat
