##
##	$VER: XModule_Makefile 4.1 (15.8.98)
##
##	Copyright (C) 1993,94,95,96,97,98 by Bernardo Innocenti
##
##	This Makefile must be processed with GNU make 3.76.1
##	Use 4 chars wide TABs to read this file
##
##	Please see below to know what developement tools you need to
##	install in order to build XModule and all related files.
##
##
##	Relevant build targets:
##
##		make all		- Make all binaries. This is the default
##		make release	- Make distribution archives
##		make bumprev	- Bump the revision number of XModule
##		make newctfiles	- Make new .ct files for catalog translators
##		make clean		- Removes all objects and temporary files

include config.mk

###########################################################
# Tools used to make this project:
###########################################################
#
# SAS/C 6.58        is a commercial product. Updates are available on Aminet
# PhxAss 4.38       is on Aminet in the archive "dev/asm/PhxAss438.lha"
# PhxLnk 4.31       is on Aminet in the archive "dev/asm/PhxLnk431.lha"
# FlexCat 2.1       is on Aminet in the archive "dev/misc/FlexCat.lha"
# FD2Pragma 2.52    is on Aminet in the archive "dev/misc/FD2Pragma.lha"
# ADtoHT 2.1        is on Aminet in the archive "text/hyper/ADtoHT2_1.lha"
# RevUp 1.4         is on Aminet in the archive "dev/misc/RevUp1_4.lha"
# GNU Make 3.76.1   is on Aminet in the archive "dev/c/make_bin.lha"
# GNU MakeInfo 1.64 is part of the GeekGadgets project
# scompare          is part of the SAS/C Developement System and is not freely distributable
# autodoc           is in the 3.1 NDTK or in the Amiga Developer CD 1.2
#
# 3.1 Includes      is in the 3.1 NDTK or in the Amiga Developer CD 1.2
# XPK 2.5 DTK       is on Aminet in the archive "util/pack/×pk25dev.lha"
# ReqTools DTK      is on Aminet in the archive "util/libs/ReqToolDev.lha"
#
#
# My ethernal gratitude to the clever authors of these useful tools!
#

###########################################################
# Additional configuration
###########################################################
#
# Subdirectories to work in
#
SUBDIRS := Hooks gadgets manuals


###########################################################
# Source files to compile for the XModule executible
###########################################################
#
#

SRCS := Main.c Misc.c Rexx.c Gui.c Requesters.c Prefs.c Locale.c \
 Audio.c Compress.c App.c Cx.c Help.c Operators.c Instr.c \
 SongClass.c Library.c XModuleHook.c TrackerHook.c CustomClasses.c \
 ToolBoxWin.c OptimizationWin.c ClearWin.c InstrumentsWin.c \
 SongInfoWin.c SequenceWin.c ProgressWin.c SaversWin.c \
 PlayWin.c PrefsWin.c PatternWin.c PattPrefsWin.c

# List the objects from the source files
OBJS := $(SRCS:%.c=$(OBJDIR)/%.o)


# NOTE: SampleWin.o removed because still not updated to new GUI system



###########################################################
# Targets to make for normal builds. This is the default
###########################################################
#
# NOTE: the GST file is put here to have it remade when needed.
#       the source files do not depend on $(GST) because otherwise
#       make would rebuild all them when the GST is rebuild.

all: $(GST) $(PROJNAME) Players/32Channels.player subdirs

final: $(GST) $(PROJNAME)_final Players/32Channels.player subdirs

subdirs:
	@$(foreach subdir, $(SUBDIRS), $(MAKE) -w $(MAKEFLAGS) -C $(subdir) @@)



###########################################################
# Patch files for special binary versions
###########################################################

patches:								\
 Patches/XModule_020.pch				\
 Patches/XModule_020_OS30.pch			\
 Patches/XModule.guide_39.pch			\
 Patches/XModule.guide_40.pch			\
 Patches/XModule.doc.pch				\
 Patches/pattedit.gadget_020.pch		\
 Patches/pattedit.gadget_020_OS30.pch


###########################################################
# Files to make for the distribution
###########################################################

release: all patches catalogs autodocs

catalogs:
	@$(MAKE) -w $(MAKEFLAGS) -C catalogs


###########################################################
# Make the Global Symbol Table used to speed up SAS/C
###########################################################

ifneq ($(strip $(GST)),)

$(GST): XModulePriv.h Gui.h LocaleStrings.h Gst.c \
 include/libraries/xmodule.h include/libraries/xmoduleclass.h \
 include/libraries/songclass.h include/libraries/patteditclass.h \
 include/pragmas/xmodule_pragmas.h include/clib/xmodule_protos.h
	$(CC) FROM Gst.c MakeGst=$(GST) NOOBJNAME $(CFLAGS)

endif

###########################################################
# Make the main XModule executable
###########################################################
#
# Generic rule for making all the objects
# NOTE: the `:' path separator must be escaped to avoid confusing GNU make
#
$(OBJS): $(subst :,\:,$(OBJDIR))/%.o: %.c LocaleStrings.h
	$(CC) $< $(CC_OUT) $@ $(CFLAGS) $(MORE_CFLAGS)

$(OBJDIR)/Startup.o: Startup.asm
	$(AS) Startup.asm TO $@ $(ASFLAGS) $(MORE_ASFLAGS) SET "STKSIZE=$(STACKSIZE)"

# NOTE: the following rule works around the command line length limit of the
#       Amiga native shell by striping away the path component from $(OBJECTS)
$(PROJNAME): $(OBJDIR)/Startup.o $(OBJS)
	cd $(OBJDIR) @@\
	$(LD) FROM $(OBJDIR)/Startup.o $(OBJS:$(OBJDIR)/%=%) TO $@ $(LDFLAGS) $(LIBS) @@\
	move $@ $(TOP)/$@

# EXPERIMENTAL: to get better code optimization, we compile all the source
# code modules at once, by including all them in a single dummy source file.
#
$(PROJNAME)_final: $(OBJDIR)/Startup.o $(PROJNAME)_final.o
	$(LD) FROM $(OBJDIR)/Startup.o $(OBJDIR)/$(PROJNAME)_final.o TO $@ $(LDFLAGS) $(LIBS)

$(PROJNAME)_final.o: $(PROJNAME)_final.c
	$(CC) $(PROJNAME)_final.c $(CC_OUT) $(OBJDIR)/$(PROJNAME)_final.o $(CFLAGS) $(MORE_CFLAGS) \
		DEF SINGLE_OBJECT

$(PROJNAME)_final.c: $(SRCS)
	echo "/** This source file is automatically generated - do not edit **/" >$(PROJNAME)_final.c
	list $(SRCS) LFORMAT "#include *"%p%n*"" >>$(PROJNAME)_final.c


###########################################################
# Make other executable flavors
###########################################################

XModule_020: XModule
	$(MAKE) -u "MORE_CFLAGS=CPU 68020" "MORE_ASFLAGS=MACHINE 68020" XModule
	Move XModule XModule_020
	$(MAKE) clean

XModule_OS30: XModule
	$(MAKE) -u "MORE_CFLAGS=DEF OS30_ONLY" "MORE_ASFLAGS=SET OS30_ONLY" $(GST) XModule
	Move XModule XModule_OS30
	$(MAKE) clean

XModule_020_OS30: XModule
	$(MAKE) -u "MORE_CFLAGS=CPU 68020 DEF OS30_ONLY" \
	 "MORE_ASFLAGS=SET OS30_ONLY MACHINE 68020" $(GST) XModule
	Move XModule XModule_020_OS30
	$(MAKE) clean




###########################################################
# Make 32Channels.player
###########################################################

Player.o: Player.asm
	$(AS) Player.asm $(ASFLAGS) $(MORE_ASFLAGS)

Players/32Channels.player: Player.o
	$(LD) Player.o TO Players/32Channels.player LIB:Small.lib NODEBUG SMALLCODE SMALLDATA



###########################################################
# Locale related stuff
###########################################################
#

LocaleStrings.h Locale.c: LocaleStrings_h.sd Locale_c.sd Catalogs/$(PROJNAME).cd
	$(FLEXCAT) Catalogs/$(PROJNAME).cd LocaleStrings.h=LocaleStrings_h.sd Locale.c=Locale_c.sd

# Make NewCTFiles to create updated CT files for all supported languages

NewCTFiles:
	@$(MAKE) -w $(MAKEFLAGS) -C catalogs NewCTFiles




###########################################################
# Make xmodule_pragmas.h
###########################################################
#
# Do not use SAS/C's fd2pragma! What you need here is FD2Pragma 2.52 or newer.
# It can be found on Aminet in the archive "dev/misc/FD2Pragma.lha".
#

include/pragmas/xmodule_pragmas.h: xmodule_lib.fd
	$(FD2PRAGMA) FDFILE xmodule_lib.fd SPECIAL 6 TO include/pragmas/xmodule_pragmas.h
	$(FD2PRAGMA) FDFILE xmodule_lib.fd SPECIAL 10 TO include/libraries/xmodule_lib.i
	$(FD2PRAGMA) FDFILE xmodule_lib.fd SPECIAL 18 TO include/proto/xmodule.h



###########################################################
# Make AutoDocs
###########################################################
#
# autodoc is a standard Commodore developer tool.  You can
# find it in the 3.1 NDTK.
#
# ADtoHT 2.1 is an AutoDoc to AmigaGuide file conversion
# utility made by Christian Stieber.  It can be found on
# Aminet in the directory "text/hyper/".
#

autodocs: Autodocs/xmodule.doc Autodocs/songclass.doc

Autodocs/xmodule.doc Autodocs/songclass.doc: Library.c SongClass.c
	$(CP) include/libraries/xmodule.h include/libraries/songclass.h Autodocs/
	autodoc -t4 -C -I -c Library.c >Autodocs/xmodule.doc
	autodoc -t4 -C -I -c SongClass.c >Autodocs/songclass.doc
	SC:Doc/ADtoHT Autodocs/ RAM: Autodocs/ Autodocs/ VERSION 39
	$(RM) Autodocs/xmodule.h
	$(RM) Autodocs/songclass.h


###########################################################
# Bump the revision
###########################################################
#
# RevUp is a developer tool by Boris Folgmann which is similar to BumpRev.
# You can find it on Aminet in the archive "dev/misc/RevUp1_4.lha".
#

bumprev:
	RevUp 3 XModule NOASM EXTRA TINY


###########################################################
# Update dependencies
###########################################################
#
# EXPERIMENTAL - Do not use
#

depend:
	gcc -Iinclude: -Iinclude -MM *.c >depend

# other handy gcc options:
# -O2 -fomit-frame-pointer -fstrength-reduce -finline-functions -funroll-loops
# -W -Wunused -Wuninitialized -Wparentheses Wreturn-type -Wshadow -Wcast-align
# -Wstrict-prototypes

###########################################################
# Cleanup all mess
###########################################################

clean:
	-$(RM) *.pch *.map *.gst *.xref XModule XModule.doc \
	Locale.c LocaleStrings.h Players/*.player Patches/*.pch $(PROJNAME)_final.c depend
	-$(RM) $(OBJDIR)/*.o
	@$(MAKE) -w $(MAKEFLAGS) -C Hooks clean
	@$(MAKE) -w $(MAKEFLAGS) -C gadgets clean
	@$(MAKE) -w $(MAKEFLAGS) -C catalogs clean



##################################################################################
# Make patches for special executables optimized for different CPU and OS version
##################################################################################

Patches/XModule_020.pch: XModule_020
	scompare -o$@ XModule XModule_020

Patches/XModule_020_OS30.pch: XModule_020_OS30
	scompare -o$@ XModule XModule_020_OS30

Patches/pattedit.gadget_020.pch: Gadgets/pattedit.gadget_020
	scompare -o$@ Gadgets/pattedit.gadget Gadgets/pattedit.gadget_020

Patches/pattedit.gadget_020_OS30.pch: Gadgets/pattedit.gadget_020_OS30
	scompare -o$@ Gadgets/pattedit.gadget Gadgets/pattedit.gadget_020_OS30

Patches/XModule.guide_39.pch: manuals/XModule.guide_39
	scompare -o$@ manuals/XModule.guide_34 manuals/XModule.guide_39

Patches/XModule.guide_40.pch: manuals/XModule.guide_40
	scompare -o$@ manuals/XModule.guide_34 manuals/XModule.guide_40

Patches/XModule.doc.pch: manuals/XModule.txt
	scompare -o$@ manuals/XModule.doc manuals/XModule.txt



###########################################################
# Make the distribution archives
###########################################################
#
# Note: We can't use the `#?' wildcard because the `#' character
#       is also used to start a comment in a Makefile. This script
#       will work only when the dos wildstar flag is set.
#

release: distribution_archive source_archive

distribution_archive:
	Execute <<
		If NOT EXISTS $(DISTPREFIX)/XModule
			MakeDir $(DISTPREFIX)/XModule
		EndIf

		$(CP) XModule $(DISTPREFIX)/XModule/
		$(CP) manuals/XModule.doc manuals/HISTORY manuals/README $(DISTPREFIX)/XModule/
		$(CP) manuals/XModule.guide_34 $(DISTPREFIX)/XModule/XModule.guide
		$(CP) Players/* $(DISTPREFIX)/XModule/Players/
		$(CP) Hooks/*.xmhook $(DISTPREFIX)/XModule/Hooks/
		$(CP) Gadgets/pattedit.gadget $(DISTPREFIX)/XModule/Gadgets/
		$(CP) Patches/*.pch $(DISTPREFIX)/XModule/Patches/

		$(RM) ALL $(DISTPREFIX)/XModule/Catalogs/**
		$(CP) ALL Catalogs $(DISTPREFIX)/XModule/Catalogs/


		CD $(DISTPREFIX)
		If EXISTS $(ARCNAME)
			$(RM) $(ARCNAME)
		EndIf
		$(ARCHIVER) $(ARCNAME) XModule/** XModule.info
	<

source_archive:
	Execute <<
		If EXISTS $(SRCARCNAME)
			$(RM) $(SRCARCNAME)
		EndIf

		$(RM) ALL $(SRCDISTDIR)/XModuleSource/**

		$(CP) *.c $(DISTPREFIX)/XModuleSource/
		$(CP) *.h $(DISTPREFIX)/XModuleSource/
		$(CP) *.asm TO $(DISTPREFIX)/XModuleSource/
		$(CP) ALL Include $(DISTPREFIX)/XModuleSource/Include
		$(CP) XModule.texi MakeFile XModule_rev.rev LocaleStrings_h.sd Locale_c.sd TODO SCOPTIONS $(DISTPREFIX)/XModuleSource/

		$(CP) FakePlayer.asm $(DISTPREFIX)/XModuleSource/Player.asm
		$(RM) $(DISTPREFIX)XModuleSource/FakePlayer.asm

		If EXISTS $(SRCARCNAME)
			$(RM) $(SRCARCNAME)
		EndIf
		$(ARCHIVER) $(SRCARCNAME) include
		CD $(DISTPREFIX)
		$(ARCHIVER) $(SRCARCNAME) XModuleSource XModuleSource.info
	<



###########################################################
# Phony targets (targets which arn't really files to make)
###########################################################

.PHONY: all patches release autodocs distribution_archive source_archive \
	NewCTFiles bumprev depend clean subdirs $(SUBDIRS)

#end
