# Microwindows Non-Recursive Makefile for DOS/DJGPP and MinGW
# by Georg Potthast August 2015
# based on makefile by V. Rogachev
#

#call e.g. make -f Makefile_nr ARCH=DOS
# or       make -f Makefile_nr clean ARCH=DOS
# or       make -f Makefile_nr ARCH=EM
# or       make -f Makefile_nr ARCH=X11
# or	   make -f Makefile_nr ARCH=MIN

EMSCRIPTEN=N
DOS_DJGPP =N
X11       =N
MINGW     =N
#convert em to EM
ifeq ($(subst em,EM,$(ARCH)), EM)
EMSCRIPTEN=Y
$(info Compiling for EMSCRIPTEN)
endif

ifeq ($(subst dos,DOS,$(ARCH))), DOS)
DOS_DJGPP=Y
$(info Compiling for DOS DJGPP)
endif

ifeq ($(subst x,X,$(ARCH)), X11)
X11=Y
$(info Compiling for X11)
endif

ifeq ($(subst min,MIN,$(ARCH)), MIN)
MINGW = Y
$(info Compiling for MinGW)
endif
$(info    )

#is ARCH empty? - strip removes blanks
ifeq ($(strip $(ARCH)),) 
$(info Please enter ARCH as parameter!)
$(info e.g. make -f Makefile_nr ARCH=DOS)
$(info    )
#generate error to stop make!
$(patsubst pattern,replacement,text)
endif

# define arch: DOS/DJGPP or MINGW or EMSCRIPTEN or X11 #######################

# export variables for sublevel makefiles
export MW_DIR_SRC CC CFLAGS AS LD AR STRIP HOSTCC HOSTCFLAGS HAVEMSFONTS VESA MINGW DOS_DJGPP SDL1 SDL2 ALLEGRO4 ALLEGRO5 CLIBS EMSCRIPTEN VERBOSE HAVE_FREETYPE_2_SUPPORT SHOWSTUBS X11 

# uncomment to build microwin and/or nano-X demos and libraries
MICROWIN=1
NANOX=1

#uncomment to select just a few examples for testing
TESTPROG=1

# network libs location
NETLIBS=
#NETLIBS=-lsocket -lnsl

ifdef ALLEGRO4
LIBALLEGRO= -lalleg #.dll
endif
ifdef ALLEGRO5
LIBALLEGRO= -lallegro #.dll
endif

# for recursive makes into subdirectories
MW_DIR_SRC := $(CURDIR)
MW_DIR_BIN := $(CURDIR)/bin

# set variable to compile with gcc
CC = gcc
AS = as
LD = ld
AR = ar
STRIP = strip
HOSTCC = gcc
HOSTCFLAGS = -I$(MW_DIR_SRC)/include
OPTIMIZE = Y
OPTLEVEL = -O3

ifeq ($(EMSCRIPTEN), Y)
#SDL1 = Y
SDL2 = Y
CC = emcc
#assembler
AS = 
LD = emcc
AR = emar
STRIP = strip
HOSTCC = emcc
HOSTCFLAGS = -I$(MW_DIR_SRC)/include
OPTIMIZE = Y
OPTLEVEL = -O3
endif

#enable EPRINTF and DPRINTF statements in code
#or use fprintf(stdout,"foo\n");
DEBUG= N

#show stubs called in nx11
SHOWSTUBS= N

#add -g flag for GDB
GDB= N

#get Make to print full details
VERBOSE= Y

# DJGPP cc flags, includes
ifeq ($(DOS_DJGPP), Y)
INC = -I$(MW_DIR_SRC)/include
endif

ifeq ($(MINGW), Y)
# MINGW cc flags, includes
INC = -I$(MW_DIR_SRC)/include -I/c/MinGW/msys/1.0/local/include/freetype
INC += -I/usr/local/include
endif

ifeq ($(EMSCRIPTEN), Y)
INC += -I$(MW_DIR_SRC)/include 
endif
ifeq ($(SDL2), Y)
INC += -s USE_SDL=2 -s USE_ZLIB=1 -s USE_FREETYPE=1 -s TOTAL_MEMORY=67108864 -s ERROR_ON_UNDEFINED_SYMBOLS=0 -s WASM=0
INC +=  -s USE_LIBPNG=1
#INC +=  -s ASSERTIONS=1
#INC += -s EMTERPRETIFY_ADVISE=1
#WHITELIST  =  -s EMTERPRETIFY_WHITELIST='["_GrGetNextEventTimeout"]' -s EMTERPRETIFY_WHITELIST='["_GrPeekWaitEvent"]' -s EMTERPRETIFY_WHITELIST='["_GrCheckNextEvent"]' 
#WHITELIST +=  -s EMTERPRETIFY_WHITELIST='["_GrGetTypedEventPred"]' -s EMTERPRETIFY_WHITELIST='["_GetMessage"]' -s EMTERPRETIFY_WHITELIST='["_main"]'
EMTERPRET = -s EMTERPRETIFY=1 -s EMTERPRETIFY_ASYNC=1 
#$(WHITELIST)
#INC += EMTERPRET
#INC += -s EMTERPRETIFY=1 -s EMTERPRETIFY_ASYNC=1
NANOFONTS = --preload-file $(MW_DIR_SRC)/fonts/truetype@fonts/truetype 
#INC += --embed-file $(MW_DIR_SRC)/demos/nanox/ftdemo.txt@/bin/
#INC += -s VERBOSE=1
NX11fonts = --preload-file $(MW_DIR_SRC)/fonts/em-fonts@/usr/share/fonts/truetype
endif

ifeq ($(X11), Y)
INC = -I$(MW_DIR_SRC)/include 
#-L/usr/X11R6/lib -lX11
endif

ifeq ($(GDB), Y)
# -g - include debugging information in source code
CFLAGS += $(INC) -Wall -g
else
# -s - removes all symbol table and relocation information
CFLAGS += $(INC) 
#-s -L/c/MinGW/msys/1.0/lib
CFLAGS += -Wno-deprecated-declarations 
#-Wno-implicit-function-declaration
#CFLAGS += -L/usr/local/lib -L/local/lib
#CFLAGS += -L/c/MinGW/msys/1.0/local/lib -L/c/MinGW/lib
endif

ifeq ($(OPTIMIZE), Y)
ifneq (,$(findstring -O,$(OPTLEVEL)))
# found - comma means: compare empty string with result of findstring, 
# which is not empty if -O is found
CFLAGS += $(OPTLEVEL)
else
CFLAGS += -O3
endif
endif

ifeq ($(VERBOSE), Y)
CFLAGS += -v
else
CFLAGS += -s 
endif

#MATHLIB
#CLIBS += -lm

ifeq ($(MINGW), Y)
CFLAGS += -DMINGW 
#ALLEGRO4 = 1
ALLEGRO5 = 1
endif

ifeq ($(DOS_DJGPP), Y)
CFLAGS += -DDOS_DJGPP=1 -DMSDOS=1 
endif

ifeq ($(EMSCRIPTEN), Y)
CFLAGS += -DEMSCRIPTEN=1
endif

ifeq ($(X11), Y)
USE_EXPOSURE = Y
CFLAGS += -DX11=1 -DLINUX=1 -DUNIX=1 
endif

CFLAGS += -DHAVE_FILEIO=1 -DMW_FEATURE_IMAGES=1 -DMW_FEATURE_TIMERS=1
CFLAGS += -DHAVE_SIGNAL=0 

ifeq ($(DEBUG), Y)
#HAVE_FPRINTF=0 uses Nano-X error function and outputs to STDOUT=SCREEN
CFLAGS += -DHAVE_FPRINTF=1
else
CFLAGS += -DHAVE_FPRINTF=0
endif

#Add defines to CFLAGS variable

# this links the nano-X application
# with the server.  This is required, if no network is present,
# or for speed or debugging.  This affects the nano-X server only.
# this Makefile supports this option only!
#LINK_APP_INTO_SERVER=Y
#set to one if linking app into server
CFLAGS += -DNONETWORK=1

# Window move algorithms, change for tradeoff between cpu speed and looks
# UPDATEREGIONS paints in update clipping region only for better look and feel
# ERASEMOVE repaints only backgrounds while window dragging, quicker
# XORMOVE moves windows only after button up, quickest 

CFLAGS += -DUPDATEREGIONS=1
CFLAGS += -DERASEMOVE=1
#CFLAGS += -DXORMOVE=1

#set to 1 for MS FONTS
#CFLAGS += -DHAVEMSFONTS=1

#needed in devimage.c
CFLAGS += -DHAVE_MMAP=0

#link in window manager - decorate windows and color background
#needed for nanowm and better for nx11
CFLAGS += -DNANOWM=1

#set to 1 for BMP SUPPORT
CFLAGS += -DHAVE_BMP_SUPPORT=1
#set to 1 for GIF SUPPORT
CFLAGS += -DHAVE_GIF_SUPPORT=1
#set to 1 for PNM SUPPORT
CFLAGS += -DHAVE_PNM_SUPPORT=1
#set to 1 for XPM SUPPORT
CFLAGS += -DHAVE_XPM_SUPPORT=1

##set for JPEG support - libjpeg.a
#CFLAGS += -DHAVE_JPEG_SUPPORT=1
#CLIBS += -ljpeg
##set for PNG support - libpng.a + libz.a
CFLAGS += -DHAVE_PNG_SUPPORT=1
ifneq ($(EMSCRIPTEN), Y)
CLIBS += -lpng -lz
endif
##set for TIFF support - libtiff.a
#CFLAGS += -DHAVE_TIFF_SUPPORT=1
#CLIBS += -ltiff

#font support settings
#Do not use the FONT_DIR macros here with MinGW.
#Within the programs these are set to the
#defaults as specified below, however, the
#macros here are not used properly. Run the
#demos from the root directory e.g. bin/fontdemo
#When run from the bin directory you'll need a fonts
#directory within bin.
#With DJGPP the directory is fixed in font_fnt.c,
#font_pcf.c and font_freetype2.c

CFLAGS += -DHAVE_FNT_SUPPORT=1
#CFLAGS += -DFNT_FONT_DIR="fonts/fnt" 

#CFLAGS += -DHAVE_PCF_SUPPORT=1
#CFLAGS += -DPCF_FONT_DIR="fonts/pcf"
#need zlib for gz format
#CFLAGS += -DHAVE_PCFGZ_SUPPORT=1
#CLIBS += -lz

HAVE_FREETYPE_2_SUPPORT = Y
CFLAGS += -DHAVE_FREETYPE_2_SUPPORT=1
#CFLAGS += -DFREETYPE_FONT_DIR=\"fonts/truetype\"
CFLAGS += -I/usr/include/freetype2
ifneq ($(EMSCRIPTEN), Y)
CLIBS += -lfreetype -lz
endif

#CFLAGS += -DHAVE_T1LIB_SUPPORT=1
#T1LIB_FONT_DIR = "fonts/type1/"
#CLIBS += -lt1

# SCREEN SETTINGS #########################
# these settings are used if the environment variable NANOSCR is not used
# e.g. NANOSCR=800 600 565 for TRUECOLOR565

ifndef SCREEN_WIDTH
SCREEN_WIDTH=800
#SCREEN_WIDTH=1024
#SCREEN_WIDTH=1400
endif
ifndef SCREEN_HEIGHT
SCREEN_HEIGHT=600
#SCREEN_HEIGHT=768
#SCREEN_HEIGHT=1050
endif
ifndef SCREEN_DEPTH
SCREEN_DEPTH=8
endif

#/* pixel is packed 8 bits 1, 4 or 8 pal index*/
#SCREEN_PIXTYPE = MWPF_PALETTE       

#/* pixel is packed 32 bits byte order |B|G|R|A|*/
SCREEN_PIXTYPE = MWPF_TRUECOLORARGB 

#/* pixel is packed 32 bits byte order |R|G|B|A|*/
#SCREEN_PIXTYPE = MWPF_TRUECOLORABGR 

#/* pixel is packed 24 bits byte order |B|G|R|*/
#SCREEN_PIXTYPE = MWPF_TRUECOLORRGB

#/* pixel is packed 16 bits little endian RGB565*/
# use this making screenshots with snarf
#SCREEN_PIXTYPE = MWPF_TRUECOLOR565  

ifdef SCREEN_HEIGHT
CFLAGS += -DSCREEN_HEIGHT=$(SCREEN_HEIGHT)
endif

ifdef SCREEN_WIDTH
CFLAGS += -DSCREEN_WIDTH=$(SCREEN_WIDTH)
endif

ifdef SCREEN_DEPTH
CFLAGS += -DSCREEN_DEPTH=$(SCREEN_DEPTH)
endif

ifdef SCREEN_PIXTYPE
CFLAGS += -DSCREEN_PIXTYPE=$(SCREEN_PIXTYPE)
CFLAGS += -DMWPIXEL_FORMAT=$(SCREEN_PIXTYPE)
endif

# define ALL target ********************************

ifeq ($(DOS_DJGPP), Y)
ALL += clean init  
endif
ifeq ($(MINGW), Y)
ALL += clean init  
endif

ALL += drivers/libmwdrivers.a fonts/libfonts.a engine/libmwengine.a nanox/libnano-X.a 
ifeq ($(EMSCRIPTEN), Y)
ALL += nx11/libNX11.a
ALL += nx11/libPX11.a
else
ALL += nx11/libNX11.a
endif

ifdef MICROWIN
ALL += mwin/libmwin.a 
ifneq ($(EMSCRIPTEN), Y)
ALL += mwin/bmp/libimages.a
endif
ifndef TESTPROG
ALL += mwindemos
endif
endif

ifdef NANOX 
ifndef TESTPROG
ALL += nanoxdemos
endif
endif

ifdef TESTPROG
  ifeq ($(DOS_DJGPP), Y)
     ALL += testprog
  endif
  ifeq ($(MINGW), Y)
     ALL += testprog
  endif
  ifeq ($(EMSCRIPTEN), Y)
     ALL += emprog
  endif
  ifeq ($(X11), Y)
     ALL += X11prog
  endif
endif

#define LIBS and NANOLIBS variable - CLIBS = common libs **************

ifeq ($(MINGW), Y)
CLIBS += $(LIBALLEGRO) 
endif

#drivers/libmwdrivers.a
#CLIBS += -lmwdrivers
#fonts/libfonts.a 
#CLIBS += -lfonts
#engine/libmwengine.a
#CLIBS += -lmwengine

#mwin/bmp/libimages.a 
#CLIBS += -limages

NANOLIBS = $(CLIBS)
#nanox/libnano-X.a 
ifdef NANOX
NANOLIBS += -lnano-X 
endif

#mwin/libmwin.a 
ifdef MICROWIN
LIBS += -lmwin 
endif

LIBS += $(NETLIBS)

CFLAGS += -L$(MW_DIR_SRC)/lib
ifeq ($(X11), Y)
#CFLAGS += -L/usr/X11R6/lib -lX11
CFLAGS += -L/usr/lib -lX11
endif

#define mwin demo programs
MTARGETS1 := mwdemoalpha mwtest mwtest2 mwdemo mwstretch
#MTARGETS1 += mwterm mwmine # not working in DOS
MTARGETS2 := $(addprefix $(MW_DIR_BIN)/,$(MTARGETS1))
MTARGETS := $(addsuffix .exe,$(MTARGETS2))

#define nanox demo programs
NTARGETS1 := landmine world demo-dash hello
NTARGETS1 += snap_ppm demo-monobitmap
NTARGETS1 += demo-tilestipple demo-poly slider demo-arc demo-blit demo-ttfont demo-aafont show_font demo-font
# not working in DOS 
ifeq ($(DOS_DJGPP), N)
NTARGETS1 += nxview tux ntetris tux npanel 
# tuxchess
# snap_jpg 
endif
ifeq ($(X11), N)
NTARGETS1 += nxeyes nxclock demo-grabkey
endif

NTARGETS2 := $(addprefix $(MW_DIR_BIN)/,$(NTARGETS1))
ifeq ($(X11), N)
ifeq ($(EMSCRIPTEN), Y)
NTARGETS := $(addsuffix .html,$(NTARGETS2))
else
NTARGETS := $(addsuffix .exe,$(NTARGETS2))
endif
#X11
else
#no suffix for X11
NTARGETS := $(NTARGETS2)
endif

#####################
all: $(ALL)

# If you dont want to see every executed command ...
ifndef VERBOSE
.SILENT:
endif

.PHONY: init

#make directories for DOS and copy support files for demos to bin directory
init:  
	-$("shell md lib 2>NUL")
	-$("shell md bin 2>NUL")   
	-$("shell md obj 2>NUL")
	-cp -r \
		$(MW_DIR_SRC)/demos/nanox/launcher.cnf \
		$(MW_DIR_SRC)/images/demos/nanox/world.map \
		$(MW_DIR_SRC)/images/demos/nanox/tux.gif \
		$(MW_DIR_SRC)/images/demos/nanox/slidebmp.bmp \
		$(MW_DIR_SRC)/images/demos/nanox/uponface.ppm \
		$(MW_DIR_SRC)/images/demos/nanox/mwlogo.ppm \
		$(MW_DIR_SRC)/images/demos/nanox/icons/*.ppm \
		$(MW_DIR_SRC)/images/demos/nanox/icons/*.pgm \
		$(MW_DIR_SRC)/images/demos/nanox/ftdemo.txt\
		$(MW_DIR_SRC)/fonts\
		$(MW_DIR_BIN)

#target for mwin API demos
mwindemos: $(MTARGETS)

demos/mwin/%.o: %.c
	$(CC) $(CFLAGS) -c $<

$(MW_DIR_BIN)/%.exe: demos/mwin/%.o
	echo "compiling $@"
	$(CC) $(CFLAGS) -o $@ $< $(LIBS)

#target for nanox API demos
nanoxdemos: $(NTARGETS)

demos/nanox/%.o: %.c
	$(CC) $(CFLAGS) -c $<

ifeq ($(EMSCRIPTEN), Y)
$(MW_DIR_BIN)/%.html: demos/nanox/%.o
else
ifeq ($(X11), Y)
$(MW_DIR_BIN)/%: demos/nanox/%.o
else
$(MW_DIR_BIN)/%.exe: demos/nanox/%.o
endif
endif
	echo "compiling $@"
	$(CC) $(CFLAGS) -o $@ $< $(NANOLIBS)

#target for test programs
testprog:
	echo "Compiling testprograms"
	$(info    )
	$(info $(CFLAGS))
	$(info    )
	$(info $(LIBS))
	$(info    )	
#	$(CC) $(CFLAGS) -o bin/mwdemoalpha.exe demos/mwin/mwdemoalpha.c $(LIBS)   
#	$(CC) $(CFLAGS) -o bin/nxview.exe demos/nanox/nxview.c $(NANOLIBS) -lz
	$(CC) $(CFLAGS) -o bin/demo-arc.exe demos/nanox/demo-arc.c $(NANOLIBS)
#	$(CC) $(CFLAGS) -o bin/demo-grabkey.exe demos/nanox/demo-grabkey.c $(NANOLIBS)	

#target for emscripten test programs
emprog:
	echo "Compiling testprograms for emscripten"
	$(info CFLAGS: $(CFLAGS))
	$(info NANOLIBS: $(NANOLIBS))
	$(info **************** )
ifdef MICROWIN
	$(CC) $(CFLAGS) -o bin/mwdemo.html demos/mwin/mwdemo.c $(LIBS)  $(EMTERPRET)
	$(CC) $(CFLAGS) -o bin/mwdemo2.html demos/mwin/mwdemo2.c $(LIBS) $(EMTERPRET)
	$(CC) $(CFLAGS) -o bin/mwdvetest.html demos/mwin/mwdvetest.c $(LIBS) $(NANOFONTS) --embed-file $(MW_DIR_SRC)/images/demos/mwin/mwdvetest/dveres.res@/this.res $(EMTERPRET)
	$(CC) $(CFLAGS) -o bin/mwlistcombo.html demos/mwin/mwlistcombo.c $(LIBS)  $(EMTERPRET)
endif
ifdef NANOX
	$(CC) $(CFLAGS) -o bin/demo-ttfont.html demos/nanox/demo-ttfont.c lib/libnano-X.a $(NANOFONTS)  $(EMTERPRET)
	$(CC) $(CFLAGS) -o bin/demo-aafont.html demos/nanox/demo-aafont.c lib/libnano-X.a $(NANOFONTS) --embed-file $(MW_DIR_SRC)/images/demos/nanox/aademo.txt@/bin/  $(EMTERPRET)
	$(CC) $(CFLAGS) -o bin/demo-composite.html demos/nanox/demo-composite.c lib/libnano-X.a $(NANOFONTS) --embed-file $(MW_DIR_SRC)/images/demos/nanox/alphademo.png@images/demos/nanox/  $(EMTERPRET)
	$(CC) $(CFLAGS) -o bin/demo-agg.html demos/nanox/demo-agg.cpp demos/nanox/agglite.cpp lib/libnano-X.a  $(EMTERPRET)
	$(CC) $(CFLAGS) -o bin/demo-grabkey.html demos/nanox/demo-grabkey.c lib/libnano-X.a $(EMTERPRET)
	$(CC) $(CFLAGS) -o bin/nxeyes.html demos/nanox/nxeyes.c lib/libnano-X.a  $(EMTERPRET)
#	$(CC) $(CFLAGS) -o bin/demo-arc.html demos/nanox/demo-arc.c lib/libnano-X.a  $(EMTERPRET)
#	$(CC) $(CFLAGS) -o bin/hello.html demos/nanox/hello.c lib/libnano-X.a  $(EMTERPRET)
	$(CC) $(CFLAGS) -o bin/xdraw.html contrib/nx11-test/xdraw.c lib/libPX11.a  $(EMTERPRET)
	$(CC) $(CFLAGS) -o bin/xhello.html contrib/nx11-test/xhello.c lib/libPX11.a  $(EMTERPRET)
	$(CC) $(CFLAGS) -o bin/xgreen.html contrib/nx11-test/xgreen.c lib/libNX11.a lib/libnano-X.a $(NX11fonts) $(EMTERPRET)
#	$(CC) $(CFLAGS) -o bin/xtestarc.html contrib/nx11-test/xtestarc.c lib/libPX11.a  $(EMTERPRET)
#	$(CC) $(CFLAGS) -o bin/xmouse.html contrib/nx11-test/xmouse.c lib/libPX11.a  $(EMTERPRET)
#	$(CC) $(CFLAGS) -o bin/williams.html contrib/nx11-test/williams.c lib/libPX11.a  $(EMTERPRET)
#	strace $(CC) $(CFLAGS) -o bin/xhello.html contrib/nx11-test/xhello.c lib/libNX11.a lib/libnano-X.a >~/microwindows-em/src/strace.log  $(EMTERPRET)
endif

X11prog:
	echo "Compiling testprograms for X11"
	$(info ######### CFLAGS: )
	$(info $(CFLAGS))
	$(info ######### NANOLIBS:    )
	$(info $(NANOLIBS))
	$(info #########    )	
#	$(CC) $(CFLAGS) -o bin/arcdemo.html demos/nanox/demo-arc.c $(NANOLIBS)
	$(CC) $(CFLAGS) -o bin/arcdemo demos/nanox/demo-arc.c lib/libnano-X.a -L/usr/X11R6/lib -lX11
#	-Llib/libnano-X.a
#	$(CC) $(CFLAGS) -o bin/demo-grabkey.exe demos/nanox/demo-grabkey.c $(NANOLIBS)	
	$(CC) $(CFLAGS) -o bin/xgreen contrib/nx11-test/xgreen.c lib/libnano-X.a lib/libNX11.a -L/usr/X11R6/lib -lX11
	$(CC) $(CFLAGS) -o bin/xmouse contrib/nx11-test/xmouse.c lib/libPX11.a -L/usr/X11R6/lib -lX11
#	$(CC) -Llib -Iinclude -o bin/xmouse nxlib/test/xmouse.c -lz -lfreetype -lz -lX11 -lPX11
##################### clean ###################################
ifeq ($(MINGW), Y)
clean:
	echo "Cleaning MinGW files"
	-rm obj/mwin/*.o 2>/dev/null
	-rm obj/drivers/*.o 2>/dev/null
	-rm obj/mwin/winlib/*.o 2>/dev/null
	-rm obj/engine/*.o 2>/dev/null
	-rm obj/fonts/*.o 2>/dev/null
	-rm drivers/*.o 2>/dev/null
	-rm mwin/*.o 2>/dev/null	
	-rm mwin/bmp/*.o 2>/dev/null
	-rm mwin/winlib/*.o 2>/dev/null
	-rm nanox/*.o 2>/dev/null
	-rm fonts/*.o 2>/dev/null
	-rm engine/*.o 2>/dev/null
	-rm lib/*.a	 2>/dev/null
	-rm bin/*.exe 2>/dev/null
	-rm bin/*.ppm 2>/dev/null
	-rm bin/*.pgm 2>/dev/null
#	-rm -rf bin/fonts/ 2>/dev/null
	-rm mwin/bmp/*.exe 2>/dev/null
	-$(MAKE) -C nx11 clean
	echo "Cleaned *.o, *.a, and *.exe files"
endif

ifeq ($(DOS_DJGPP), Y)
clean:
	echo "Cleaning DOS files"
	-del mwin\*.o
	-del mwin\bmp\*.o
	-del mwin\winlib\*.o
	-del fonts\*.o
	-del nanox\*.o
	-del drivers\*.o
	-del engine\*.o
	-del lib\*.a
# or demos will not be compiled again	
	-del bin\*.exe 
	-del bin\*.ppm
	-del bin\*.pgm  
#	-rm -rf bin\fonts
	-del nx11\*.o
	-$(MAKE) -C nx11 clean
	echo "Cleaned *.o, *.a, and *.exe files"
endif

ifeq ($(EMSCRIPTEN), Y)
clean:
	echo "Cleaning EMSCRIPTEN files"
	-rm obj/mwin/*.o 2>/dev/null
	-rm obj/drivers/*.o 2>/dev/null
	-rm obj/mwin/winlib/*.o 2>/dev/null
	-rm obj/engine/*.o 2>/dev/null
	-rm obj/fonts/*.o 2>/dev/null
	-rm drivers/*.o 2>/dev/null
	-rm mwin/*.o 2>/dev/null	
	-rm mwin/bmp/*.o 2>/dev/null
	-rm mwin/winlib/*.o 2>/dev/null
	-rm nanox/*.o 2>/dev/null
	-rm fonts/*.o 2>/dev/null
	-rm engine/*.o 2>/dev/null
	-rm lib/*.a	 2>/dev/null
	-rm bin/*.html 2>/dev/null
	-rm bin/*.js 2>/dev/null
	-rm bin/*.mem 2>/dev/null
	-rm bin/*.data 2>/dev/null
	-rm bin/*.ppm 2>/dev/null
	-rm bin/*.pgm 2>/dev/null
#	-rm -rf bin/fonts/ 2>/dev/null
#	-rm mwin/bmp/*.exe 2>/dev/null
	-rm nx11/*.o 2>/dev/null
	echo "Cleaned *.o, *.a, bin/*.html, bin/*.mem and bin/*.js files"
endif

ifeq ($(X11), Y)
clean:
	echo "Cleaning X11 files"
	-rm obj/mwin/*.o 2>/dev/null
	-rm obj/drivers/*.o 2>/dev/null
	-rm obj/mwin/winlib/*.o 2>/dev/null
	-rm obj/engine/*.o 2>/dev/null
	-rm obj/fonts/*.o 2>/dev/null
	-rm drivers/*.o 2>/dev/null
	-rm mwin/*.o 2>/dev/null	
	-rm mwin/bmp/*.o 2>/dev/null
	-rm mwin/winlib/*.o 2>/dev/null
	-rm nanox/*.o 2>/dev/null
	-rm fonts/*.o 2>/dev/null
	-rm engine/*.o 2>/dev/null
	-rm lib/*.a	 2>/dev/null
	-rm bin/* 2>/dev/null
	-rm bin/*.ppm 2>/dev/null
	-rm bin/*.pgm 2>/dev/null
#	-rm -rf bin/fonts/ 2>/dev/null
#	-rm mwin/bmp/*.exe 2>/dev/null
	-rm nx11/*.o 2>/dev/null
	-$(MAKE) -C nx11 clean
	echo "Cleaned *.o, *.a, bin/*.* files"
endif

#there is a file install in the directory - so define as phony
.PHONY: install

ifeq ($(MINGW), Y)
install:
	cp lib/*.a /local/lib
	cp inc /local/include/mwin
endif

ifeq ($(DOS_DJGPP), Y)
install:
	copy lib\*.a \djgpp\lib
	copy inc \djgpp\include\mwin
endif
	
#############################################################################
#targets for libraries - engine,fonts,drivers make just object files, no libs
#using AR these will be merged into libmwin.a and libnano-X.a

nanox/libnano-X.a: 
	echo "Generating $@"
	$(MAKE) -C nanox  -f ../contrib/makefiles_nr/Makefile-nanox

#obsolete
#mwin/winlib/libwinlib.a:
#	$(MAKE) -C mwin/winlib

mwin/libmwin.a:
	echo "Generating $@"
	$(MAKE) -C mwin -f ../contrib/makefiles_nr/Makefile-mwin
	
fonts/libfonts.a:
	echo "Generating font object files"    
	$(MAKE) -C fonts -f ../contrib/makefiles_nr/Makefile-fonts

engine/libmwengine.a:
	echo "Generating engine object files"    
	$(MAKE) -C engine -f ../contrib/makefiles_nr/Makefile-engine

drivers/libmwdrivers.a:
	echo "Generating driver object files" 
	$(MAKE) -C drivers -f ../contrib/makefiles_nr/Makefile-drivers

mwin/bmp/libimages.a:
	echo "Generating $@"  
	$(MAKE) -C mwin/bmp -f ../../contrib/makefiles_nr/Makefile-bmp

nx11/libNX11.a:
	echo "Generating $@"
ifeq ($(EMSCRIPTEN), N)	
	$(MAKE) -C nx11
else	
	$(MAKE) -C nx11 -f ../contrib/makefiles_nr/Makefile-nx11
endif	
#also set nonetwork=0 above - does not work yet
#	$(MAKE) -C nanox -f ../contrib/makefiles_nr/Makefile-nanox-bin
	
nx11/libPX11.a:	
	echo "Generating $@"
	$(MAKE) -C nx11 -f ../contrib/makefiles_nr/Makefile-px11
