#
# Modification History
#
# 2004-November-19    Jason Rohrer
# Copied from Primrose source.
#
# 2004-November-21    Jason Rohrer
# Added multi-source downloader.
#
# 2004-December-13    Jason Rohrer
# Added socket manager.
#
# 2005-February-4    Jason Rohrer
# Added ScreenGL.
#
# 2005-February-21    Jason Rohrer
# Added SingleTextureGL.
#
# 2006-April-24    Jason Rohrer
# Added conditional compilation of files that depend on OpenGL/GLUT.
#
# 2006-November-21    Jason Rohrer
# Added PNGImageConverter.
#
# 2007-April-23    Jason Rohrer
# Changed to make compilation of all objects individually conditional using
# NEEDED_MINOR_GEMS_OBJECTS variable.
#



##
# The common portion of Makefiles for all targets that use minorGems,
# supplying target dependencies for minorGems targets.
#
#
# Should not be made manually---used by project-specific configure scripts to 
# build Makefiles.
##


# Makefile Usage (these must be in your Makefile in the following order):
# -- Include Makefile.minorGems
# -- List the desired minorGems objects in NEEDED_MINOR_GEMS_OBJECTS
#    Example:
#      NEEDED_MINOR_GEMS_OBJECTS = \
#       ${SOCKET_O} \
#       ${SOCKET_CLIENT_O} \
#       ${SOCKET_SERVER_O} \
#       ${HOST_ADDRESS_O}
# -- Define your project-specific targets and rules
# -- Include this file





##
# Dependencies for minorGems objects.
##


# first, take the object list and turn it into a source list
MINOR_GEMS_SOURCE = ${NEEDED_MINOR_GEMS_OBJECTS:.o=.cpp}


# Here is what the old, manual list looked like, for reference:
#
# MINOR_GEMS_SOURCE = \
#  ${HOST_ADDRESS_CPP} \
#  ${SOCKET_CPP} \
#  ${SOCKET_SERVER_CPP} \
#  ${SOCKET_CLIENT_CPP} \
#  ${SOCKET_UDP_CPP} \
#  ${NETWORK_FUNCTION_LOCKS_CPP} \
#  ${SOCKET_MANAGER_CPP} \
#  ${PATH_CPP} \
#  ${DIRECTORY_CPP} \
#  ${TYPE_IO_CPP} \
#  ${TIME_CPP} \
#  ${THREAD_CPP} \
#  ${MUTEX_LOCK_CPP} \
#  ${BINARY_SEMAPHORE_CPP} \
#  ${APP_LOG_CPP} \
#  ${PRINT_LOG_CPP} \
#  ${FILE_LOG_CPP} \
#  ${LOG_CPP} \
#  ${PRINT_UTILS_CPP} \
#  ${WEB_CLIENT_CPP} \
#  ${URL_UTILS_CPP} \
#  ${MIME_TYPER_CPP} \
#  ${STRING_BUFFER_OUTPUT_STREAM_CPP} \
#  ${XML_UTILS_CPP} \
#  ${HTML_UTILS_CPP} \
#  ${SETTINGS_MANAGER_CPP} \
#  ${TRANSLATION_MANAGER_CPP} \
#  ${STRING_UTILS_CPP} \
#  ${SHA1_CPP} \
#  ${MEMORY_TRACK_CPP} \
#  ${DEBUG_MEMORY_CPP} \
#  ${HOST_CATCHER_CPP} \
#  ${OUTBOUND_CHANNEL_CPP} \
#  ${DUPLICATE_MESSAGE_DETECTOR_CPP} \
#  ${PROTOCOL_UTILS_CPP} \
#  ${MESSAGE_PER_SECOND_LIMITER_CPP} \
#  ${MULTI_SOURCE_DOWNLOADER_CPP} \
#  ${ENCODING_UTILS_CPP} \
#  ${WEB_SERVER_CPP} \
#  ${REQUEST_HANDLING_THREAD_CPP} \
#  ${THREAD_HANDLING_THREAD_CPP} \
#  ${CONNECTION_PERMISSION_HANDLER_CPP} \
#  ${STOP_SIGNAL_THREAD_CPP} \
#  ${FINISHED_SIGNAL_THREAD_CPP} \
#  ${FINISHED_SIGNAL_THREAD_MANAGER_CPP} \
#  ${OPEN_GL_CPP_FILES} \
#  ${PNG_IMAGE_CONVERTER_CPP}
#  ${PORT_MAPPING_CPP}



# next, generate dependencies using g++


# sed command for fixing up the dependencies generated by g++
# g++ (pre-3.0) leaves the path off of the .o target
# look for a .o file at the beginning of a line (in other words, one
# without a path), and replace it with the full-path version.
# This should be compatible with g++ 3.0, since we only replace .o names
# that occur at the beginning of a line (using the "^" modifier)

# Split into two parts because sed (on certain platforms) cannot process
# a string of commands as one long argument

MINOR_GEMS_SED_FIX_COMMAND_A = sed ' \
s/^HostAddress.*\.o/$${HOST_ADDRESS_O}/; \
s/^SocketServer.*\.o/$${SOCKET_SERVER_O}/; \
s/^SocketClient.*\.o/$${SOCKET_CLIENT_O}/; \
s/^SocketUDP.*\.o/$${SOCKET_UDP_O}/; \
s/^SocketManager.*\.o/$${SOCKET_MANAGER_O}/; \
s/^Socket.*\.o/$${SOCKET_O}/; \
s/^NetworkFunctionLocks.*\.o/$${NETWORK_FUNCTION_LOCKS_O}/; \
s/^LookupThread.*\.o/$${LOOKUP_THREAD_O}/; \
s/^Path.*\.o/$${PATH_O}/; \
s/^Directory.*\.o/$${DIRECTORY_O}/; \
s/^TypeIO.*\.o/$${TYPE_IO_O}/; \
s/^Time.*\.o/$${TIME_O}/; \
s/^MutexLock.*\.o/$${MUTEX_LOCK_O}/; \
s/^BinarySemaphore.*\.o/$${BINARY_SEMAPHORE_O}/; \
s/^AppLog.*\.o/$${APP_LOG_O}/; \
s/^PrintLog.*\.o/$${PRINT_LOG_O}/; \
s/^FileLog.*\.o/$${FILE_LOG_O}/; \
s/^Log.*\.o/$${LOG_O}/; \
s/^PrintUtils.*\.o/$${PRINT_UTILS_O}/; \
s/^WebClient.*\.o/$${WEB_CLIENT_O}/; \
s/^URLUtils.*\.o/$${URL_UTILS_O}/; \
s/^MimeTyper.*\.o/$${MIME_TYPER_O}/; \
s/^WebRequest.*\.o/$${WEB_REQUEST_O}/; \
s/^StringBufferOutputStream.*\.o/$${STRING_BUFFER_OUTPUT_STREAM_O}/; \
s/^XMLUtils.*\.o/$${XML_UTILS_O}/; \
s/^HTMLUtils.*\.o/$${HTML_UTILS_O}/; \
s/^SettingsManager.*\.o/$${SETTINGS_MANAGER_O}/; \
s/^TranslationManager.*\.o/$${TRANSLATION_MANAGER_O}/; \
s/^stringUtils.*\.o/$${STRING_UTILS_O}/; \
s/^sha1.*\.o/$${SHA1_O}/; \
'

MINOR_GEMS_SED_FIX_COMMAND_B = sed ' \
s/^MemoryTrack.*\.o/$${MEMORY_TRACK_O}/; \
s/^DebugMemory.*\.o/$${DEBUG_MEMORY_O}/; \
s/^HostCatcher.*\.o/$${HOST_CATCHER_O}/; \
s/^OutboundChannel.*\.o/$${OUTBOUND_CHANNEL_O}/; \
s/^DuplicateMessageDetector.*\.o/$${DUPLICATE_MESSAGE_DETECTOR_O}/; \
s/^protocolUtils.*\.o/$${PROTOCOL_UTILS_O}/; \
s/^MessagePerSecondLimiter.*\.o/$${MESSAGE_PER_SECOND_LIMITER_O}/; \
s/^MultiSourceDownloader.*\.o/$${MULTI_SOURCE_DOWNLOADER_O}/; \
s/^encodingUtils.*\.o/$${ENCODING_UTILS_O}/; \
s/^WebServer.*\.o/$${WEB_SERVER_O }/; \
s/^RequestHandlingThread.*\.o/$${REQUEST_HANDLING_THREAD_O}/; \
s/^ThreadHandlingThread.*\.o/$${THREAD_HANDLING_THREAD_O}/; \
s/^Thread.*\.o/$${THREAD_O}/; \
s/^ConnectionPermissionHandler.*\.o/$${CONNECTION_PERMISSION_HANDLER_O}/; \
s/^StopSignalThread.*\.o/$${STOP_SIGNAL_THREAD_O}/; \
s/^FinishedSignalThreadManager.*\.o/$${FINISHED_SIGNAL_THREAD_MANAGER_O}/; \
s/^FinishedSignalThread.*\.o/$${FINISHED_SIGNAL_THREAD_O}/; \
s/^ScreenGL.*\.o/$${SCREEN_GL_O}/; \
s/^ScreenGLSDL.*\.o/$${SCREEN_GL_SDL_O}/; \
s/^SingleTextureGL.*\.o/$${SINGLE_TEXTURE_GL_O}/; \
s/^PNGImageConverter.*\.o/$${PNG_IMAGE_CONVERTER_O}/; \
s/^portMapping.*\.o/$${PORT_MAPPING_O}/; \
'



MINOR_GEMS_DEPENDENCY_FILE = Makefile.minorGems_dependencies


# build the dependency file 

${MINOR_GEMS_DEPENDENCY_FILE}: ${MINOR_GEMS_SOURCE}
	rm -f ${MINOR_GEMS_DEPENDENCY_FILE}
	${COMPILE} -I${ROOT_PATH} -MM ${MINOR_GEMS_SOURCE} >> ${MINOR_GEMS_DEPENDENCY_FILE}.temp
	cat ${MINOR_GEMS_DEPENDENCY_FILE}.temp | ${MINOR_GEMS_SED_FIX_COMMAND_A} | ${MINOR_GEMS_SED_FIX_COMMAND_B} >> ${MINOR_GEMS_DEPENDENCY_FILE}
	rm -f ${MINOR_GEMS_DEPENDENCY_FILE}.temp

include ${MINOR_GEMS_DEPENDENCY_FILE}






