# This simple makefile is used to prep for the RPM build
# It can glide2x and glide3x for all supported hardware
# It sets up the environment and makes sure that swlibs is placed properly
# It supports the GLIDE_BUILD_COMPAT env honored by the RPM spec and
# if set it doesn't build glide3x

default:
	@echo "Valid targets are: V3_DRI V3_NODIR V2 VG clean_V3 clean_V2 clean_VG"

V3_NODRI:
	rm -f glide2x/swlibs
	ln -sf ../swlibs glide2x/swlibs
	export FX_GLIDE_HW=h3
	make -C glide2x -f makefile.linux
	if [ "$(GLIDE_BUILD_COMPAT)" != "GO" ]; then \
		ln -sf linhwc.c.save glide3x/h3/minihwc/linhwc.c;\
		ln -sf gglide.c.save glide3x/h3/glide3/src/gglide.c;\
		ln -sf glfb.c.save glide3x/h3/glide3/src/glfb.c;\
		ln -sf gsst.c.save glide3x/h3/glide3/src/gsst.c;\
		ln -sf ../swlibs glide3x/swlibs; \
		make -C glide3x -f makefile.linux; \
	fi

V3_DRI: 
	rm -f glide2x/swlibs
	ln -s ../swlibs glide2x/swlibs
	export FX_GLIDE_HW=h3
	make -C glide2x -f makefile.linux
	if [ "$(GLIDE_BUILD_COMPAT)" != "GO" ]; then \
		ln -sf linhwc.c.dri glide3x/h3/minihwc/linhwc.c;\
		ln -sf gglide.c.dri glide3x/h3/glide3/src/gglide.c;\
		ln -sf glfb.c.dri glide3x/h3/glide3/src/glfb.c;\
		ln -sf gsst.c.dri glide3x/h3/glide3/src/gsst.c;\
		ln -sf ../swlibs glide3x/swlibs; \
		make -C glide3x -f makefile.linux; \
	fi

V2:
	rm -f glide2x/swlibs
	ln -s ../swlibs glide2x/swlibs
	export FX_GLIDE_HW=cvg
	make -C glide2x -f makefile.linux
	if [ "$(GLIDE_BUILD_COMPAT)" != "GO" ]; then \
		rm -f glide3x/swlibs; \
		ln -s ../swlibs glide3x/swlibs; \
		make -C glide3x -f makefile.linux; \
	fi
VG:
	rm -f glide2x/swlibs
	ln -s ../swlibs glide2x/swlibs
	export FX_GLIDE_HW=sst1
	make -C glide2x -f makefile.linux


# This also removes the dri/nodri symlinks
clean_V3:
	ln -sf ../swlibs glide2x/swlibs
	ln -sf ../swlibs glide3x/swlibs
	export FX_GLIDE_HW=h3
	make -C glide2x -f makefile.linux clean
	make -C glide3x -f makefile.linux clean
	rm -f glide3x/h3/minihwc/linhwc.c
	rm -f glide3x/h3/glide3/src/gglide.c
	rm -f glide3x/h3/glide3/src/glfb.c
	rm -f glide3x/h3/glide3/src/gsst.c


clean_V2:
	ln -sf ../swlibs glide2x/swlibs
	ln -sf ../swlibs glide3x/swlibs
	export FX_GLIDE_HW=cvg
	make -C glide2x -f makefile.linux clean
	make -C glide3x -f makefile.linux clean

clean_VG:
	ln -sf ../swlibs glide2x/swlibs
	ln -sf ../swlibs glide3x/swlibs
	export FX_GLIDE_HW=sst1
	make -C glide2x -f makefile.linux clean
