#-------------------------------------------------------------------------
# Copyright 2006 Kyle Turner.
#
# License is hereby granted to use this software and distribute it
# freely, as long as this copyright notice is retained and modifications 
# are clearly marked.
#
# ALL WARRANTIES ARE HEREBY DISCLAIMED.
#
# $Id: //guest/kyle_turner/perforce/resolve/Makefile#1 $
#-------------------------------------------------------------------------
#
# GNUMakefile to build P4 API based applications on Linux and Windows.
#
# Usage:  make P4API=<p4dir>
#
# Common modifications:
#
#      P4API    - Set to path where you have extracted the p4api for
#                 the platform.
#
#      OS       - Currently this file supports Linux/g++ and Windows/.Net
#                 with a very simplistic use of "uname".  This may need
#                 some modifications depending on the operating system
#                 you are running.
#
#      CPP      - Modify for you compiler.  On windows you will need to
#                 add several directories to your PATH environment
#                 variable so the linker finds the correct libraries.
#
#-------------------------------------------------------------------------

TARGET          := resolve
SOURCES         := \
        help.cpp \
        p4api.cpp \
        resolve.cpp

P4API           := ../p4api
P4LIBS          := libclient librpc libsupp
OS              := $(shell uname)

#-------------------------------------------------------------------------
# LINUX
#-------------------------------------------------------------------------

ifeq ($(OS), Linux)

OBJS            := $(SOURCES:.cpp=.o)
CPP             := $(shell if [ -e /usr/bin/g++32 ]; then echo g++32; else echo g++; fi)
CPPFLAGS        := -pedantic -W -Wall \
                   -Winline -Wformat -Wshadow -Wno-long-long \
                   -Dconst_char="const char"
P4LIBS          := $(foreach L,$(P4LIBS),$(P4API)/$L.a)
SYSLIBS         :=
LINK             = $(CPP) -o $@ $(OBJS) $(P4LIBS) $(SYSLIBS)

%.o: %.cpp
	$(CPP) -c $(CPPFLAGS) -I $(P4API) $<
	
#-------------------------------------------------------------------------
# WINDOWS
#-------------------------------------------------------------------------

else

TARGET          := $(TARGET).exe
OBJS            := $(SOURCES:.cpp=.obj)
CPP             := cl.exe
CPPFLAGS        := /DOS_NT /MT /DCASE_INSENSITIVE /nologo
P4API           := $(subst /,\\,$(P4API))
P4LIBS          := $(foreach L,$(P4LIBS),$(P4API)\\$L.lib)
SYSLIBS         := oldnames.lib \
                   kernel32.lib \
                   wsock32.lib \
                   advapi32.lib

LINK             = $(CPP) -o $@ $(OBJS) /link $(P4LIBS) $(SYSLIBS)

%.obj: %.cpp
	$(CPP) -c $(CPPFLAGS) /I$(P4API) $<
	
endif

#-------------------------------------------------------------------------
# TARGETS
#-------------------------------------------------------------------------

.PHONY: default clean

default: $(TARGET)

$(TARGET): $(OBJS)
	$(LINK)

clean:
	-$(RM) $(TARGET) $(OBJS)