# written by Guido Socher
# to compile: run make
#
# On a mac you might need to add 
# /Applications/Xcode.app/Contents/Developer/usr/bin
# to your PATH:
# export PATH=${PATH}:/Applications/Xcode.app/Contents/Developer/usr/bin
#
# on linux you can run "make install-static" and "make exifdate-static-stdcpp" 
# if you want a binaries that are more portable to different versions of the OS
# ...static is totally static and big
# ...static-stdcpp uses just a static c++ lib and is much smaller
#
# I believe that the xcode g++ compiler for macos-X supports the flag
# -mmacosx-version-min=10.4 which could be added below to support older Macs
# but I have not tried it yet since I don't have enought Macs to test it.
#
# The makefile can be used under windows with a mingw/msys environment.
# The static binary will be able to run outside that environment too.
ifeq ($(OS),Windows_NT)
	# windows
	EXEC_EXT=.exe
	# causes the program to print at the end "press enter to contiune"
	DOPT=-DPROMPT_TO_CLOSE
	UNAME=Win
else
	# linux, mac
	EXEC_EXT=
	# does a chmod 644:
	DOPT=-DDO_CHMOD
	# mac: UNAME=Darwin, linux: UNAME=Linux
	UNAME := $(shell uname)
endif

ifeq ($(UNAME), Darwin)
all: exifdate$(EXEC_EXT)
else ifeq ($(UNAME), Win)
all: exifdate$(EXEC_EXT) exifdate-static$(EXEC_EXT)
else 
all: exifdate$(EXEC_EXT) exifdate-static-stdcpp$(EXEC_EXT) exifdate-static$(EXEC_EXT)
endif

showosname:
	echo $(OS)

# this works only under linux:
install: exifdate-static-stdcpp exifdate-prompt-to-exit
ifeq ($(UNAME), Linux)
	cp -p exifdate-static-stdcpp /usr/bin/exifdate
	cp -p exifdate-prompt-to-exit /usr/bin/exifdate-prompt-to-exit
else
	@echo "\"make install\" is only for linux"
endif
#==============================
exif.o: easyexif/exif.cpp
	g++ -O2 -pedantic -Wall -c easyexif/exif.cpp

exifdate.o: exif.o exifdate.cpp easyexif/exif.h
	g++ $(DOPT) -O2 -pedantic -Wall -c exifdate.cpp

exifdate-static$(EXEC_EXT): exif.o exifdate.o 
	g++ -static -o $@ exif.o exifdate.o
	strip $@

# the -static-libstdc++ option to gcc exists only in more
# recent versions of g++ and I want this to work a cross a
# wide range of systems. I will therefore use a different way
# to link libstdc++ static:
exifdate-static-stdcpp$(EXEC_EXT): exif.o exifdate.o 
	# copy the static version of libstdc++ to pwd (.):
	cp -p `g++ -print-file-name=libstdc++.a` .
	g++ -L. -o $@ exif.o exifdate.o
	strip $@

# Darwin is macosX and we copy the binary as well to
exifdate$(EXEC_EXT): exif.o exifdate.o 
	g++ -o $@ exif.o exifdate.o
ifeq ($(UNAME), Darwin)
	cp -p exifdate ./Applications/exifdate.app/Contents/Resources/exifdate
endif

# is  only for linux:
exifdate-prompt-to-exit: easyexif/exif.cpp exifdate.cpp easyexif/exif.h
	g++ -DPROMPT_TO_CLOSE -DDO_CHMOD -O2 -pedantic -Wall -o $@ easyexif/exif.cpp exifdate.cpp
	strip $@
#========================
clean:
	rm -f *.o *std*.a exifdate$(EXEC_EXT) exifdate-static$(EXEC_EXT) exifdate-static-stdcpp$(EXEC_EXT) exifdate-prompt-to-exit$(EXEC_EXT)
#========================
