#
#  Makefile for PCC II
#
#  This defines the non-standard parts of the Unix build (standard rules
#  are in Rules-unix.mak).
#
#  Regarding flags, we let autoconf provide CXXFLAGS and LDFLAGS as
#  AC_CXXFLAGS and AC_LDFLAGS. The flags we ultimately use for compilation
#  consist of those plus some others we make ourselves.
#

## Installer
INSTALL_FLAGS =
INSTALL_CMD   = $(PERL) scripts/install.pl -L$(INSTLOG) -t'$(program_transform_name)' -s -d $(INSTALL_FLAGS)
INSTALL_DATA  = $(PERL) scripts/install.pl -L$(INSTLOG) -d -m 644 $(INSTALL_FLAGS)
INSTLOG       = INSTALL.log
MAIN_VARS += INSTALL_FLAGS INSTLOG

LIBEXTRA_pdk :=

.PHONY: install
install: $(OUTPUT_$(PROJECTS_app))
        $(RM) $(INSTLOG)
        $(INSTALL_CMD) $(PROJECTS_app) $(bindir)
        $(MAKE) install-sdl-$(HAVE_SDL)
        $(MAKE) install-pdk-$(HAVE_PDK)
        $(INSTALL_DATA) -Rresource $(pdatadir)/resource
        $(INSTALL_DATA) -Rspecs $(pdatadir)
        $(INSTALL_DATA) doc/*.6 $(mandir)/man6

.PHONY: install-sdl-yes
install-sdl-yes: $(OUTPUT_$(PROJECTS_sdlapp)) 
        $(INSTALL_CMD) -v $(PROJECTS_sdlapp) $(bindir)

.PHONY: install-pdk-yes
install-pdk-yes: $(OUTPUT_$(PROJECTS_pdkapp)) 
        $(INSTALL_CMD) -v $(PROJECTS_pdkapp) $(bindir)

.PHONY: install-pdk-no install-sdl-no
install-pdk-no:
install-sdl-no:

.PHONY: deb
deb:
	make prefix=$$(pwd)/packaging/$(prefix) install
	$(INSTALL_DATA) -Rdebian $$(pwd)/packaging/DEBIAN
	dpkg-deb -b packaging .
	$(RM) -rf packaging

uninstall:
	xargs rm -f < $(INSTLOG)

## Convenience routine
acdefs.mak:
	@echo "*** You should have called configure before trying to"
	@echo "*** build PCC v2. I'll do that for you."
	./configure

## Dependency generator needs $(OBJEXT)
OBJEXT = o

## Platform Library
FILES_platf = arch/unix/cmdargs.cc arch/unix/dir-arit.cc arch/unix/dirs.cc \
        arch/unix/file.cc arch/unix/platform.cc arch/unix/platform.h
TYPE_platf = lib
TARGETS += platf

## Optimisation
CXXFLAGS_cpluslib/cstring.cc := $(CXXFLAGS) -fno-exceptions

## Configuration for cpluslib. Should go in 01_cpluslib someday, but currently
## it must be here because it references an operating system command which,
## under Windows, means the shell is too stupid to deal with a generic version
## using forward slashes.
cpluslib/cpluslib/config.h: cpluslib/cpluslib/config.in
        cat cpluslib/cpluslib/config.in > cpluslib/cpluslib/config.h
