#
# Additional compilation flags may be passed via CFLAGS, CXXFLAGS and CLINKFLAGS
#
# Linux:
#   make CFLAGS=-m32
#   make CFLAGS=-m64
#
# Ubuntu 9.04 64-bit
#   make CFLAGS=-m32 CXXFLAGS=-m32 CLINKFLAGS="-L/lib32 -L/usr/lib32 -Wl,-rpath-link,/lib32:/usr/lib32"
#
# OSX:
#   make 'CFLAGS=-arch ppc'    'CXXFLAGS=-arch ppc'
#   make 'CFLAGS=-arch i386'   'CXXFLAGS=-arch i386'
#   make 'CFLAGS=-arch x86_64' 'CXXFLAGS=-arch x86_64'

UNAME := $(shell uname)

C_SOURCE   := src/visualinfo.c
OBJ        := $(C_SOURCE:.c=.o) 
BIN        := visualinfo
LINKFLAGS  += -L. -lglewlib

CC         =  gcc
C_FLAGS    += -Wall
C_FLAGS    += -I"include"
C_FLAGS    += -DGLEW_STATIC

ifeq ($(UNAME), Darwin)
  LINKFLAGS  += -framework OpenGL
  LINKFLAGS  += -framework AGL
else
  ifeq ($(findstring CYGWIN, $(UNAME)), CYGWIN)
    BIN = visualinfo.exe
    C_FLAGS    += -D_WIN32
    LINKFLAGS  += -lglu32 -lopengl32 -lgdi32
  else
    ifeq ($(UNAME), SunOS)
      C_FLAGS    += -fPIC
      LINKFLAGS  += -lGLU -lGL
      LINKFLAGS  += -lX11 -lXext
    else
      LINKFLAGS  += -lGLU -lGL
      LINKFLAGS  += -lX11 -lXext
      LINKFLAGS  += -ldl
    endif
  endif
endif

override CFLAGS := $(CFLAGS) $(C_FLAGS)

all: visualinfo

visualinfo: $(OBJ)
	$(CC) $(CFLAGS) $(OBJ) -o $(BIN) $(LINKFLAGS) $(CLINKFLAGS)

test:
	./$(BIN)

run: all
	./$(BIN)

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

clobber: clean
	$(RM) *.bak *.o *~

.PHONY: all test run clean clobber
