################################################################
# $Id: makefile,v 2.4 2012/06/17 01:22:06 shinkuro Exp $
#
# :ts=4
#
# Makefile for NoWinED using either gcc or vbcc and for targets:
#   gcc: AmigaOS4, MorphOS, AmigaOS3, AROS
#  vbcc: AmigaOS4, MorphOS, AmigaOS3
#
# Basing on the initial makefiles ShInKurO created.
#
# Calling convention:
# make os=[os4/morphos/os3/aros] comp=[gcc/vbcc] [debug=1]
# Defaults: AmigaOS4 and gcc compiler, no debug information.
#
# NOTEZ BIEN:
# Upon calling 'clean' choose also the right OS:
#  make clean os=[os4/morphos/os3/aros]
#
# NOTES: vbcc will use very much RAM upon using -O3, hence I
# limited optimisations to -O2, which helps to save some RAM.
#
# BTW.: IMHO it doesn't make much difference if we use -O1 or
#       -O3 because the main work is done by the MCC classes.
#
# Upon using gcc (any target) you should invoke the STRIP(ping)
# process for non debug builds:
# make os=<target> strip
#
# NOTE: In order to increase stack size for OS3 and by using gcc
#       we have to link against 'swapstack.o' of 'libnix'.
#       Unfortunately, we have to deal then with an absolute
#       path, 'gg:lib/libnix/swapstack.o'.
################################################################

OBJ		  = nowined.o			\
			win.o				\
			about.o				\
			findBar.o				\
			minMaxGrp.o			\
			listED.o				\
			loc.o				\
			grpED.o				\
			mgroup.o			\
			paged.o				\
			ed.o					\
			rootbar.o			\
			titleBut.o			\
			buTitleGrp.o			\
			counter.o			\
			utils.o				\
			app.o				\
			manageArgs.o		\
			listButGrp.o		\
			winPrefs.o			\
			winToolbarPrefs.o	\
			prefsSupport.o		\
			profilesSupport.o	\
			toolBarPrefsSupport.o	\
			gotoline.o			\
			customStr.o			\
			requesterFormat.o	\
			encoding_support.o	\
			wrapCustom.o		\
			infoEOL.o			\
			infoEncod.o			\
			littleGrp.o			\
			infoBar.o			\
			tabBut.o			\
			printWin.o			\
			findIntoFilesBar.o		\
			subNListtree.o		\
			subTheButtonDropable.o		\
			subTheButtonNOTDropable.o		\
			subTheButtonRecents.o		\
			subTheBar.o			\
			subVirtGrpDD.o		\
			pointers.o			\
			MemDemand.o

#
## Default, AmigaOS4 gcc part
#
BIN	   = NoWinED_OS4

ifeq ($(debug),)
  CFLAGS	= -s -O1 -I./include -I../include -mcrt=newlib -fomit-frame-pointer -funroll-loops -mcpu=powerpc -mstring -mmultiple \
			  -fstrict-aliasing -D__USE_INLINE__ -D__USE_BASETYPE__ -D__USE_OLD_TIMEVAL__ -Wall \
			  -Wno-pointer-sign -mregnames
  LDFLAGS   =
else
  CFLAGS	= -I./include -I../include -mcpu=powerpc  -fomit-frame-pointer  -Wno-pointer-sign  -D__USE_INLINE__ \
			  -D__USE_BASETYPE__ -D__USE_OLD_TIMEVAL__ -D_DBUG -DDEBUG -D__TRACK_DOWN_ALLOCATION__ -Wall -ggdb
  LDFLAGS   = -gstabs
endif

LIBS	= 

RM		= rm -f

LINK	= ppc-amigaos-gcc

CC		= ppc-amigaos-gcc

STRIP	= ppc-amigaos-strip


#
## Set the defaults we'll use in case nothing was chosen
#
ifeq ($(comp),)
 comp = gcc
endif

ifeq ($(os),)
  os = os4
endif

#
## For AmigaOS4 we have to specify an additional file: appDockClass.o
#
ifeq ($(os), os4)
  OBJ := $(OBJ) appDockClass.o
endif


#
## Default-strip invocation: OS3, MorphOS, OS4.
## AROS needs an other call to avoid that the executable is corrupted.
#
ifneq ($(os), aros)
  STRIPINV = --strip-debug --strip-unneeded -R.comment
else
  STRIPINV = --strip-unneeded -R.comment
endif


#
## Choose macros accordingly to parameters given on the command line
## NOTE: Do not use tabs here - use ordinary spaces, otherwise commands will
## be delivered to the console and not interpreted by 'make'.
#
ifeq ($(comp), vbcc)
  #
  ## Default, OS4 (vbcc setup)
  #
  BIN  = NoWinED_OS4
  CC   = vc +aosppc
  LINK = vc +aosppc
  ifeq ($(debug),)
    CFLAGS = -O1 -Iinclude -I/include -D__USE_INLINE__ -D__USE_BASETYPE__ -D__USE_OLD_TIMEVAL__
    LDFLAGS =
  else
    CFLAGS = -Iinclude -I/include -D__USE_INLINE__ -D__USE_BASETYPE__ -D__USE_OLD_TIMEVAL__ -D_DBUG -DDEBUG -D__TRACK_DOWN_ALLOCATION__ -gstabs
    LDFLAGS = -gstabs
  endif  # <~debug>

  ifeq ($(os), morphos)
    # vbcc & MorphOS
    BIN  = NoWinED_MOS
    CC   = vc +morphos
    LINK = vc +morphos
    ifeq ($(debug),)
      CFLAGS = -O1 -Iinclude -I/include -O1
      LDFLAGS =
      LIBS   = -lvc
    else
      CFLAGS = -Iinclude -I/include -D_DBUG -DDEBUG -D__TRACK_DOWN_ALLOCATION__ -gstabs
      LDFLAGS = -gstabs
      LIBS   = -lvc  -ldebug
    endif  # <~debug>
  else # <~morphos>
    ifeq ($(os), os3)
      # vbcc & AmigaOS3
      # [NOTE: Disable optimisations when using the initial 0.9 version of vbcc (only 68k version)
      # Ask Frank Wille for the updated vbcc 0.9 version where several bugs were fixed (compiler AND assembler)
      BIN  = NoWinED_OS3
      CC   = vc +aos68k
      LINK = vc +aos68k
      ifeq ($(debug),)
        CFLAGS = -O1 -Iinclude -I/include  -D__AMIGA__ -c99 -const-in-data -cpu=68020 -c
        LDFLAGS =
        LIBS   = -lvc -lmieee -lamiga
      else
        CFLAGS = -Iinclude -I/include -D__AMIGA__ -c99 -const-in-data -cpu=68020 -c -D_DBUG -DDEBUG -D__TRACK_DOWN_ALLOCATION__ -g -hunkdebug
        LDFLAGS = -g -hunkdebug
        LIBS   = -lvc -lmieee -lamiga -ldebug
      endif  # <~debug>
    endif  # <~vbcc, os3>
  endif  # <~vbcc, morphos>
else # <~vbcc>
  # Can only be gcc
  # Since the OS4 gcc setup is already complete, do it for other targets
  ifeq ($(os), morphos)
    # gcc & MorphOS
    BIN   = NoWinED_MOS
    CC    = ppc-morphos-gcc
    LINK  = ppc-morphos-gcc
    STRIP = ppc-morphos-strip
    LIBS = 
      ifeq ($(debug),)
        CFLAGS = -noixemul -I./include -I../include  -s -O1
        LDFLAGS = -noixemul
      else
        CFLAGS = -noixemul -I./include -I../include -D_DBUG -DEBUG -D__TRACK_DOWN_ALLOCATION__
        LDFLAGS = -gstabs -noixemul -ldebug
      endif  # <~debug>
  else
    ifeq ($(os), os3)
      # gcc & AmigaOS3
      BIN   = NoWinED_OS3
      CC    = m68k-amigaos-gcc
      LINK  = m68k-amigaos-gcc
      STRIP = strip
      ifeq ($(debug),)
        CFLAGS = -noixemul -I./include -I../include -O1 -s -m68020-60 -fomit-frame-pointer -funroll-loops -fstrict-aliasing -Wall
        LDFLAGS = -noixemul
        LIBS   = -lm -lmui gg:lib/libnix/swapstack.o
      else
        CFLAGS =  -noixemul -I./include -I../include -fstrict-aliasing -Wall -D_DBUG -DDEBUG -D__TRACK_DOWN_ALLOCATION__
        LDFLAGS = -g -noixemul
        LIBS   = -lm -lmui -ldebug gg:lib/libnix/swapstack.o
      endif  # <~debug>
    else
      ifeq ($(os), aros)
        # gcc & AROS
        BIN   = NoWinED_AROS
        CC    = i386-aros-gcc
        LINK  = i386-aros-gcc
        STRIP = i386-aros-gcc
        ifeq ($(debug),)
          CFLAGS = -I./include -I../include -s -O1
          LDFLAGS =
          LIBS   = -larossupport -lmui -lamiga
        else
          CFLAGS = -I./include -I../include -D_DBUG -DDEBUG -D__TRACK_DOWN_ALLOCATION__
          LDFLAGS = -gstabs
          LIBS   = -larossupport -lmui -lamiga
        endif  # <~debug>
      endif  # <~aros>
    endif  # <~os3>
  endif  # <~morphos>
endif  # <~gcc> 



#
## Normal stuff takes place
#

.PHONY: all all-before all-after clean clean-custom
all: all-before $(BIN) all-after


clean: clean-custom
	$(RM) $(OBJ) $(BIN)

strip: $(BIN)
ifneq ($(comp), vbcc)
  ifeq ($(debug),)
	@$(STRIP) $(STRIPINV) $(BIN)
  else
	@echo " - Are you sure you want to have debug-information"
	@echo "   stripped from an executable program explicitly"
	@echo "   compiled using debug information???"
  endif
else
	@echo "vbcc needs no STRIP command."
endif

$(BIN): $(OBJ)
	$(LINK) $(LDFLAGS) $(OBJ) -o $(BIN) $(LIBS)

app.o:  app.c nowined.h macros.h nowined_protos.h loc.h
	$(CC) -c app.c -o app.o $(CFLAGS)

win.o:  win.c nowined.h macros.h nowined_protos.h loc.h
	$(CC) -c win.c -o win.o $(CFLAGS)

#
## AmigaOS4 only:
#
ifeq ($(os), os4)
appDockClass.o:  appDockClass.c nowined.h macros.h nowined_protos.h loc.h
	$(CC) -c appDockClass.c -o appDockClass.o $(CFLAGS)
endif

about.o: about.c nowined.h macros.h nowined_protos.h nowined_rev.h loc.h
	$(CC) -c about.c -o about.o $(CFLAGS)

findBar.o:  findBar.c nowined.h macros.h nowined_protos.h loc.h
	$(CC) -c findBar.c -o findBar.o $(CFLAGS)

listED.o:  listED.c nowined.h macros.h nowined_protos.h loc.h
	$(CC) -c listED.c -o listED.o $(CFLAGS)

loc.o:  loc.c nowined.h macros.h nowined_protos.h loc.h
	$(CC) -c loc.c -o loc.o $(CFLAGS)

minMaxGrp.o:  minMaxGrp.c nowined.h macros.h nowined_protos.h loc.h
	$(CC) -c minMaxGrp.c -o minMaxGrp.o $(CFLAGS)

grpED.o:  grpED.c nowined.h macros.h nowined_protos.h loc.h
	$(CC) -c grpED.c -o grpED.o $(CFLAGS)

mgroup.o:  mgroup.c nowined.h macros.h nowined_protos.h loc.h
	$(CC) -c mgroup.c -o mgroup.o $(CFLAGS)

nowined.o:  nowined.c nowined.h macros.h nowined_protos.h loc.h nowined_rev.h
	$(CC) -c nowined.c -o nowined.o $(CFLAGS)

paged.o: paged.c nowined.h macros.h nowined_protos.h loc.h
	$(CC) -c paged.c -o paged.o $(CFLAGS)

ed.o: ed.c nowined.h macros.h nowined_protos.h loc.h
	$(CC) -c ed.c -o ed.o $(CFLAGS)

rootbar.o:  rootbar.c nowined.h macros.h nowined_protos.h loc.h
	$(CC) -c rootbar.c -o rootbar.o $(CFLAGS)

titleBut.o:  titleBut.c nowined.h macros.h nowined_protos.h loc.h
	$(CC) -c titleBut.c -o titlebut.o $(CFLAGS)

buTitleGrp.o:  buTitleGrp.c nowined.h macros.h nowined_protos.h loc.h
	$(CC) -c buTitleGrp.c -o buTitleGrp.o $(CFLAGS)

utils.o:  utils.c nowined.h macros.h nowined_protos.h
	$(CC) -c utils.c -o utils.o $(CFLAGS)

counter.o:  counter.c nowined.h macros.h nowined_protos.h
	$(CC) -c counter.c -o counter.o $(CFLAGS)

manageArgs.o:  manageArgs.c nowined.h macros.h nowined_protos.h
	$(CC) -c manageArgs.c -o manageArgs.o $(CFLAGS)

listButGrp.o:  listButGrp.c nowined.h macros.h nowined_protos.h
	$(CC) -c listButGrp.c -o listButGrp.o $(CFLAGS)

winPrefs.o:  winPrefs.c nowined.h macros.h nowined_protos.h
	$(CC) -c winPrefs.c -o winPrefs.o $(CFLAGS)

winToolbarPrefs.o:  winToolbarPrefs.c nowined.h macros.h nowined_protos.h
	$(CC) -c winToolbarPrefs.c -o winToolbarPrefs.o $(CFLAGS)

prefsSupport.o:  prefsSupport.c nowined.h macros.h nowined_protos.h
	$(CC) -c prefsSupport.c -o prefsSupport.o $(CFLAGS)

profilesSupport.o:  profilesSupport.c nowined.h macros.h nowined_protos.h
	$(CC) -c profilesSupport.c -o profilesSupport.o $(CFLAGS)


toolBarPrefsSupport.o:  toolBarPrefsSupport.c nowined.h macros.h nowined_protos.h
	$(CC) -c toolBarPrefsSupport.c -o toolBarPrefsSupport.o $(CFLAGS)

gotoline.o:  gotoline.c nowined.h macros.h nowined_protos.h
	$(CC) -c gotoline.c -o gotoline.o $(CFLAGS)

customStr.o:  customStr.c nowined.h nowined_protos.h
	$(CC) -c customStr.c -o customStr.o $(CFLAGS)

requesterFormat.o:  requesterFormat.c nowined.h nowined_protos.h
	$(CC) -c requesterFormat.c -o requesterFormat.o $(CFLAGS)

wrapCustom.o:  wrapCustom.c nowined.h nowined_protos.h
	$(CC) -c wrapCustom.c -o wrapCustom.o $(CFLAGS)

infoEOL.o:  infoEOL.c nowined.h nowined_protos.h
	$(CC) -c infoEOL.c -o infoEOL.o $(CFLAGS)

infoEncod.o:  infoEncod.c nowined.h nowined_protos.h
	$(CC) -c infoEncod.c -o infoEncod.o $(CFLAGS)

littleGrp.o:  littleGrp.c nowined.h nowined_protos.h
	$(CC) -c littleGrp.c -o littleGrp.o $(CFLAGS)

infoBar.o:  infoBar.c nowined.h nowined_protos.h
	$(CC) -c infoBar.c -o infoBar.o $(CFLAGS)

tabBut.o: tabBut.c nowined.h nowined_protos.h
	$(CC) -c tabBut.c -o tabBut.o $(CFLAGS)

printWin.o: printWin.c nowined.h nowined_protos.h
	$(CC) -c printWin.c -o printWin.o $(CFLAGS)

findIntoFilesBar.o:  findIntoFilesBar.c nowined.h macros.h nowined_protos.h loc.h
	$(CC) -c findIntoFilesBar.c -o findIntoFilesBar.o $(CFLAGS)

subNListtree.o:  subNListtree.c nowined.h macros.h nowined_protos.h loc.h
	$(CC) -c subNListtree.c -o subNListtree.o $(CFLAGS)

subTheButtonDropable.o:  subTheButtonDropable.c nowined.h macros.h nowined_protos.h loc.h
	$(CC) -c subTheButtonDropable.c -o subTheButtonDropable.o $(CFLAGS)

subTheButtonNOTDropable.o:  subTheButtonNOTDropable.c nowined.h macros.h nowined_protos.h loc.h
	$(CC) -c subTheButtonNOTDropable.c -o subTheButtonNOTDropable.o $(CFLAGS)

subTheBar.o:  subTheBar.c nowined.h macros.h nowined_protos.h loc.h
	$(CC) -c subTheBar.c -o subTheBar.o $(CFLAGS)

subVirtGrpDD.o:  subVirtGrpDD.c nowined.h macros.h nowined_protos.h loc.h
	$(CC) -c subVirtGrpDD.c -o subVirtGrpDD.o $(CFLAGS)

pointers.o:  pointers.c nowined.h macros.h nowined_protos.h loc.h
	$(CC) -c pointers.c -o pointers.o $(CFLAGS)

encoding_support.o:  encoding_support.c mapping_tables.c  nowined_protos.h
	$(CC) -c encoding_support.c -o encoding_support.o $(CFLAGS)

MemDemand.o:  MemDemand.c nowined.h
	$(CC) -c MemDemand.c -o MemDemand.o $(CFLAGS)
