.PHONY: all all: mainapp mazegen unittest test UNAME = ${shell uname} ifeq (${UNAME},Linux) -include ~/.stem.defines STEM_SHARED_DIR ?= /usr/local/stem HOST_PLATFORM = linux else ifeq (${UNAME},Darwin) -include ~/.stem.defines STEM_SHARED_DIR ?= /usr/local/stem HOST_PLATFORM = macosx else STEM_SHARED_DIR ?= C:/stem -include ${STEM_SHARED_DIR}/stem.defines HOST_PLATFORM = windows endif include version define newline_and_tab endef iphone_sdk_version_integer = ${subst .,0,$1}${word ${words ${wordlist 2, ${words ${subst ., ,$1}}, ${subst ., ,$1}}}, 00} TARGET_PLATFORMS_macosx = macosx iphonesimulator iphoneos TARGET_PLATFORMS_linux = linux32 linux64 TARGET_PLATFORMS_windows = win32 win64 PROJECT_NAME = cubicmaze IPHONE_BUILD_SDK_VERSION ?= 4.2 IPHONE_DEPLOYMENT_TARGET_VERSION ?= 3.1 CODESIGN_IDENTITY ?= "iPhone Developer" EXECUTABLE_TARGETS = unittest mazegen APPLICATION_TARGETS = mainapp TARGETS = ${EXECUTABLE_TARGETS} ${APPLICATION_TARGETS} PLATFORMS = ${filter ${TARGET_PLATFORMS_${HOST_PLATFORM}},macosx iphonesimulator iphoneos linux32 linux64 win32 win64} ANALYZERS = splint clang TARGET_NAME_mainapp = ${PROJECT_NAME} TARGET_NAME_unittest = ${PROJECT_NAME}_unittest TARGET_NAME_mazegen = mazegen HUMAN_READABLE_TARGET_NAME_mainapp = CubicMaze #Per-target configurations CONFIGURATIONS_mainapp = debug profile release CONFIGURATIONS_unittest = debug CONFIGURATIONS_mazegen = debug profile release #Per-target platforms PLATFORMS_mainapp = ${filter ${PLATFORMS},macosx iphonesimulator iphoneos linux32 linux64 win32 win64} PLATFORMS_unittest = ${filter ${PLATFORMS},macosx iphonesimulator linux32 linux64 win32 win64} PLATFORMS_mazegen = ${filter ${PLATFORMS},macosx linux32 linux64 win32 win64} #Per-target compile/link settings CCFLAGS_mainapp = -DGLEW_STATIC #Per-target analyzer settings CLANGFLAGS_unittest = ${CCFLAGS_unittest} SPLINTFLAGS_unittest = ${CCFLAGS_unittest} #Per-configuration compile/link settings CCFLAGS_debug = -g -DDEBUG CCFLAGS_profile = -g -O3 CCFLAGS_release = -O3 #Per-platform compile/link settings CC_macosx_i386 = /usr/bin/clang -arch i386 CC_macosx_x86_64 = /usr/bin/clang -arch x86_64 AR_macosx = /usr/bin/ar RANLIB_macosx = /usr/bin/ranlib SPLINT_macosx = /usr/local/bin/splint CLANG_macosx = /usr/bin/clang STRIP_macosx_release = /usr/bin/strip -S $1 SDKROOT_macosx = /Developer/SDKs/MacOSX10.6.sdk ARCHS_macosx = i386 x86_64 CCFLAGS_macosx = -isysroot ${SDKROOT_macosx} -mmacosx-version-min=10.6 -DGLGRAPHICS_NO_GLEW LINKFLAGS_macosx = -isysroot ${SDKROOT_macosx} -mmacosx-version-min=10.6 -framework AudioUnit -framework AudioToolbox -framework CoreAudio -framework Cocoa -framework IOKit -framework OpenGL CC_iphonesimulator_i386 = /Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/gcc-4.2 -arch i386 AR_iphonesimulator = /Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/ar RANLIB_iphonesimulator = /Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/ranlib SPLINT_iphonesimulator = /usr/local/bin/splint CLANG_iphonesimulator = /usr/bin/clang STRIP_iphonesimulator_release = /Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/strip -S $1 SDKROOT_iphonesimulator = /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator${IPHONE_BUILD_SDK_VERSION}.sdk ARCHS_iphonesimulator = i386 CCFLAGS_iphonesimulator = -isysroot ${SDKROOT_iphonesimulator} -D__IPHONE_OS_VERSION_MIN_REQUIRED=${call iphone_sdk_version_integer,${IPHONE_DEPLOYMENT_TARGET_VERSION}} -DGLGRAPHICS_NO_GLEW LINKFLAGS_iphonesimulator = -isysroot ${SDKROOT_iphonesimulator} -Xlinker -objc_abi_version -Xlinker 2 -framework Foundation -framework UIKit -framework QuartzCore -framework OpenGLES -framework CoreFoundation CC_iphoneos_armv6 = /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc-4.2 -arch armv6 CC_iphoneos_armv7 = /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc-4.2 -arch armv7 AR_iphoneos = /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/ar RANLIB_iphoneos = /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/ranlib SPLINT_iphoneos = /usr/local/bin/splint CLANG_iphoneos = /usr/bin/clang STRIP_iphoneos_release = /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/strip -S $1 SDKROOT_iphoneos = /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS${IPHONE_BUILD_SDK_VERSION}.sdk ARCHS_iphoneos = armv6 armv7 CCFLAGS_iphoneos = -isysroot ${SDKROOT_iphoneos} -miphoneos-version-min=${IPHONE_DEPLOYMENT_TARGET_VERSION} -DGLGRAPHICS_NO_GLEW LINKFLAGS_iphoneos = -isysroot ${SDKROOT_iphoneos} -miphoneos-version-min=${IPHONE_DEPLOYMENT_TARGET_VERSION} -Xlinker -objc_abi_version -Xlinker 2 -framework Foundation -framework UIKit -framework QuartzCore -framework OpenGLES -framework CoreFoundation CC_linux32_i386 = /usr/bin/gcc AR_linux32 = /usr/bin/ar RANLIB_linux32 = /usr/bin/ranlib SPLINT_linux32 = /usr/local/bin/splint CLANG_linux32 = /usr/local/bin/clang STRIP_linux32_release = /usr/bin/strip -S $1 ARCHS_linux32 = i386 CCFLAGS_linux32 = -m32 -Wno-unused-result LINKFLAGS_linux32 = -m32 -lrt -lGLU -lGL -lm -ldl -lasound -Wl,-E CC_linux64_x86_64 = /usr/bin/gcc AR_linux64 = /usr/bin/ar RANLIB_linux64 = /usr/bin/ranlib SPLINT_linux64 = /usr/local/bin/splint CLANG_linux64 = /usr/local/bin/clang STRIP_linux64_release = /usr/bin/strip -S $1 ARCHS_linux64 = x86_64 CCFLAGS_linux64 = -m64 -Wno-unused-result LINKFLAGS_linux64 = -m64 -lrt -lGLU -lGL -lm -ldl -lasound -Wl,-E MINGW_W32_PATH ?= C:/MinGW MINGW_W32_VERSION ?= 4.6.2 SPLINT_WIN_PATH ?= C:/splint-3.1.1/bin/splint.exe CLANG_WIN_PATH ?= C:/llvm/bin/clang.exe CC_win32_i386 = ${MINGW_W32_PATH}/bin/gcc.exe AR_win32 = ${MINGW_W32_PATH}/bin/ar.exe RANLIB_win32 = ${MINGW_W32_PATH}/bin/ranlib.exe SPLINT_win32 = ${SPLINT_WIN_PATH} CLANG_win32 = ${CLANG_WIN_PATH} STRIP_win32_release = ${MINGW_W32_PATH}/bin/strip.exe -S $1 WINDRES_win32 = ${MINGW_W32_PATH}/bin/windres.exe ARCHS_win32 = i386 CCFLAGS_win32 = LINKFLAGS_win32 = -lopengl32 -lglu32 -lwinmm -lgdi32 -lpowrprof -mwindows LINKFLAGS_unittest_win32 = -mconsole EXECUTABLE_SUFFIX_win32 = .exe MINGW_W64_PATH ?= C:/MinGW-w64 MINGW_W64_VERSION ?= 4.7.0 CC_win64_x86_64 = ${MINGW_W64_PATH}/bin/x86_64-w64-mingw32-gcc.exe AR_win64 = ${MINGW_W64_PATH}/bin/x86_64-w64-mingw32-ar.exe RANLIB_win64 = ${MINGW_W64_PATH}/bin/x86_64-w64-mingw32-ranlib.exe SPLINT_win64 = ${SPLINT_WIN_PATH} CLANG_win64 = ${CLANG_WIN_PATH} STRIP_win64_release = ${MINGW_W64_PATH}/bin/x86_64-w64-mingw32-strip.exe -S $1 WINDRES_win64 = ${MINGW_W64_PATH}/bin/x86_64-w64-mingw32-windres.exe ARCHS_win64 = x86_64 CCFLAGS_win64 = LINKFLAGS_win64 = -lopengl32 -lglu32 -lwinmm -lgdi32 -lpowrprof -mwindows LINKFLAGS_unittest_win64 = -mconsole EXECUTABLE_SUFFIX_win64 = .exe #General compile/link settings DEFINE_CCFLAGS = -DVERSION_MAJOR=${VERSION_MAJOR}u -DVERSION_MINOR=${VERSION_MINOR}u -DVERSION_TWEAK=${VERSION_TWEAK}u WARNING_CCFLAGS = -Wall -Wextra -Wno-unused-parameter -Werror OTHER_CCFLAGS = -std=gnu99 CCFLAGS = ${DEFINE_CCFLAGS} ${WARNING_CCFLAGS} ${OTHER_CCFLAGS} FRAMEWORK_LINKFLAGS = LIBRARY_LINKFLAGS = OTHER_LINKFLAGS = LINKFLAGS = ${FRAMEWORK_LINKFLAGS} ${LIBRARY_LINKFLAGS} ${OTHER_LINKFLAGS} LINK_ORDER = \ unittest \ pngimageio \ bitmapimage \ glbitmapfont \ glfont \ glslshader \ gltexture \ jsonserialization \ serialization \ preferences \ jsonio \ statecontroller \ resourcemanager \ utilities \ vorbisaudioio \ pcmaudio \ stemobject \ glxshell \ nsopenglshell \ eaglshell \ wglshell \ stubshell \ glgraphics \ 3dmath \ libpng \ portaudio \ zlib \ glew \ libvorbis/1.3.2/libvorbisfile.a \ libvorbis/1.3.2/libvorbis.a \ libogg/1.2.2/libogg.a #Dependencies (can optionally be per-target or per-target-per-platform) STEM_LIBRARY_DEPENDENCIES = \ 3dmath/2.1.0 \ stemobject/3.1.0 \ utilities/1.8.0 STEM_LIBRARY_DEPENDENCIES_mainapp = \ bitmapimage/1.3.1 \ glbitmapfont/1.0.3 \ glfont/1.0.3 \ glslshader/1.0.0 \ gltexture/1.0.4 \ jsonio/1.2.4 \ jsonserialization/1.0.5 \ vorbisaudioio/1.0.2 \ pcmaudio/1.0.2 \ pngimageio/1.1.4 \ serialization/1.4.0 \ shell/1.2.0 \ statecontroller/1.0.2 \ preferences/1.1.3 \ resourcemanager/1.0.3 STEM_SOURCE_DEPENDENCIES = THIRDPARTY_LIBRARY_DEPENDENCIES_mainapp = \ libpng/1.4.1/libpng.a \ zlib/1.2.3/libz.a \ libvorbis/1.3.2/libvorbisfile.a \ libvorbis/1.3.2/libvorbis.a \ libogg/1.2.2/libogg.a THIRDPARTY_LIBRARY_DEPENDENCIES_mainapp_macosx = portaudio/v19_20111121/libportaudio.a THIRDPARTY_LIBRARY_DEPENDENCIES_mainapp_win32 = portaudio/v19_20111121/libportaudio.a THIRDPARTY_LIBRARY_DEPENDENCIES_mainapp_win64 = portaudio/v19_20111121/libportaudio.a THIRDPARTY_LIBRARY_DEPENDENCIES_mainapp_linux32 = portaudio/v19_20111121/libportaudio.a THIRDPARTY_LIBRARY_DEPENDENCIES_mainapp_linux64 = portaudio/v19_20111121/libportaudio.a STEM_LIBRARY_DEPENDENCIES_unittest = unittest/1.1.0 STEM_LIBRARY_DEPENDENCIES_mainapp_macosx = nsopenglshell/1.4.0 glgraphics/1.2.1_noglew STEM_LIBRARY_DEPENDENCIES_mainapp_iphonesimulator = eaglshell/2.5.1 glgraphics/1.2.1_noglew STEM_LIBRARY_DEPENDENCIES_mainapp_iphoneos = eaglshell/2.5.1 glgraphics/1.2.1_noglew STEM_LIBRARY_DEPENDENCIES_mainapp_win32 = wglshell/1.1.0 glgraphics/1.2.1 STEM_LIBRARY_DEPENDENCIES_mainapp_win64 = wglshell/1.1.0 glgraphics/1.2.1 STEM_LIBRARY_DEPENDENCIES_mainapp_linux32 = glxshell/1.0.0 glgraphics/1.2.1 STEM_LIBRARY_DEPENDENCIES_mainapp_linux64 = glxshell/1.0.0 glgraphics/1.2.1 THIRDPARTY_LIBRARY_DEPENDENCIES_mainapp_linux32 = glew/1.5.4/libglew.a THIRDPARTY_LIBRARY_DEPENDENCIES_mainapp_linux64 = glew/1.5.4/libglew.a THIRDPARTY_LIBRARY_DEPENDENCIES_mainapp_win32 = glew/1.5.4/libglew.a THIRDPARTY_LIBRARY_DEPENDENCIES_mainapp_win64 = glew/1.5.4/libglew.a #Per-target source file lists SOURCES_mainapp = \ source/${PROJECT_NAME}/CameraController.c \ source/${PROJECT_NAME}/GameplayState.c \ source/${PROJECT_NAME}/HUDView.c \ source/${PROJECT_NAME}/InstructionsState.c \ source/${PROJECT_NAME}/LogoAnimationState.c \ source/${PROJECT_NAME}/MainMenuState.c \ source/${PROJECT_NAME}/Maze.c \ source/${PROJECT_NAME}/MazeController.c \ source/${PROJECT_NAME}/MazeView.c \ source/${PROJECT_NAME}/cubicmaze_main.c \ source/${PROJECT_NAME}/RandomMazeGenerator.c \ source/${PROJECT_NAME}/ResourceWiring.c \ source/${PROJECT_NAME}/ShellStateGlobals.c SOURCES_unittest = \ build/intermediate/TestList.c \ source/${PROJECT_NAME}/Maze.c \ ${SOURCES_unittest_suites} SOURCES_unittest_suites = \ source/unittest/MazeTest.c SOURCES_mazegen = \ source/${PROJECT_NAME}/mazegen_main.c \ source/${PROJECT_NAME}/Maze.c \ source/${PROJECT_NAME}/RandomMazeGenerator.c #Target resources RESOURCES_mainapp = \ resources/font.json \ resources/font_texture.json \ resources/font_texture.png \ resources/intro_logo.json \ resources/intro_logo.png \ resources/level_complete.ogg \ resources/wall.json \ resources/wall.png RESOURCES_mainapp_macosx = \ resources/Icon.icns RESOURCES_mainapp_iphoneos = \ resources/arrow_back.json \ resources/arrow_back.png \ resources/arrow_forward.json \ resources/arrow_forward.png \ resources/arrow_return.json \ resources/arrow_return.png \ resources/arrow_up.json \ resources/arrow_up.png \ resources/icon_map.json \ resources/icon_map.png \ resources/icon_maze_exit_only.json \ resources/icon_maze_exit_only.png \ resources/icon_maze_full.json \ resources/icon_maze_full.png \ resources/icon_minus.json \ resources/icon_minus.png \ resources/icon_plus.json \ resources/icon_plus.png \ resources/Icon-72.png \ resources/Icon-72@2x.png \ resources/Icon.png \ resources/Icon@2x.png \ resources/shaders RESOURCES_mainapp_iphonesimulator = ${RESOURCES_mainapp_iphoneos} LINKFILES_mainapp_win32 = \ build/intermediate/icon_win32.coff LINKFILES_mainapp_win64 = \ build/intermediate/icon_win64.coff #General analyzer settings CLANGFLAGS = CLANGFLAGS_win32 = -I ${MINGW_W32_PATH}/include -I ${MINGW_W32_PATH}/lib/gcc/mingw32/${MINGW_W32_VERSION}/include CLANGFLAGS_win64 = -I ${MINGW_W64_PATH}/include -I ${MINGW_W64_PATH}/lib/gcc/mingw32/${MINGW_W64_VERSION}/include SPLINTFLAGS = -exportlocal #Source files excluded from static analysis ANALYZER_EXCLUDE_SOURCES_clang = ANALYZER_EXCLUDE_SOURCES_splint = \ ${SOURCES_unittest} #Additional target build prerequisites PREREQS_unittest = #TestList.c is automatically generated from ${SOURCES_unittest_suites}. It is used by the unit test framework to determine which tests to run. build/intermediate/TestList.c: build/intermediate/TestSuites.txt | build/intermediate echo 'const char * UnitTest_suiteNameList[] = {${foreach file,${SOURCES_unittest_suites},"${basename ${notdir ${file}}}",} (void *) 0};' > $@ #TestSuites.txt tracks the state of ${SOURCES_unittest_suites} so that TestList.c can be updated if and only if ${SOURCES_unittest_suites} has changed. .PHONY is abused slightly to cause the target to be conditionally remade. ifneq (${shell echo "${SOURCES_unittest_suites}" | cmp - build/intermediate/TestSuites.txt 2>&1},) .PHONY: build/intermediate/TestSuites.txt endif build/intermediate/TestSuites.txt: | build/intermediate echo "${SOURCES_unittest_suites}" > $@ build/intermediate/icon_win32.coff: resources/icon.ico resources/icon.rc ${WINDRES_win32} resources/icon.rc -o $@ -O coff build/intermediate/icon_win64.coff: resources/icon.ico resources/icon.rc ${WINDRES_win64} resources/icon.rc -o $@ -O coff define configuration_object_list_template #(target, configuration) ${foreach platform,${PLATFORMS_$1}, \ ${call platform_object_list_template,$1,$2,${platform}} \ } endef define platform_object_list_template #(target, configuration, platform) ${foreach arch,${ARCHS_$3}, \ ${call arch_object_list_template,$1,$2,$3,${arch}} \ } endef define arch_object_list_template #(target, configuration, platform, arch) ${foreach source,${SOURCES_$1} ${SOURCES_$1_$3}, \ build/intermediate/$1-$2-$3-$4/${notdir ${basename ${source}}}.o \ } endef #Produces OBJECTS_${target}_${configuration} variables for each permutation of target and configuration in that target ${foreach target,${TARGETS}, \ ${foreach configuration,${CONFIGURATIONS_${target}}, \ ${eval OBJECTS_${target}_${configuration} = ${call configuration_object_list_template,${target},${configuration}}} \ } \ } define create_directory_target_template #(dir) .LOW_RESOLUTION_TIME: $1 $1: mkdir -p $1 endef ${foreach target,${TARGETS}, \ ${foreach configuration,${CONFIGURATIONS_${target}}, \ ${foreach platform,${PLATFORMS_${target}}, \ ${eval ${call create_directory_target_template,build/${target}/${configuration}-${platform}}} \ ${foreach arch,${ARCHS_${platform}}, \ ${eval ${call create_directory_target_template,build/intermediate/${target}-${configuration}-${platform}-${arch}}} \ } \ } \ } \ } ${eval ${call create_directory_target_template,build/intermediate}} define include_ccflags_template #(target, platform) -I source \ ${foreach stem_dependency,${STEM_LIBRARY_DEPENDENCIES} ${STEM_LIBRARY_DEPENDENCIES_$1} ${STEM_LIBRARY_DEPENDENCIES_$2} ${STEM_LIBRARY_DEPENDENCIES_$1_$2},-I ${STEM_SHARED_DIR}/${stem_dependency}/include} \ ${foreach thirdparty_dependency,${THIRDPARTY_LIBRARY_DEPENDENCIES} ${THIRDPARTY_LIBRARY_DEPENDENCIES_$1} ${THIRDPARTY_LIBRARY_DEPENDENCIES_$2} ${THIRDPARTY_LIBRARY_DEPENDENCIES_$1_$2},-I ${STEM_SHARED_DIR}/${dir ${thirdparty_dependency}}include} \ ${foreach source_dependency,${STEM_SOURCE_DEPENDENCIES} ${STEM_SOURCE_DEPENDENCIES_$1} ${STEM_SOURCE_DEPENDENCIES_$2} ${STEM_SOURCE_DEPENDENCIES_$1_$2},-I dep/${word 1,${subst /, ,${source_dependency}}}/source} endef define define_ccflags_template #(target, configuration, platform, arch) -DSTEM_TARGET_$1 -DSTEM_CONFIGURATION_$2 -DSTEM_PLATFORM_$3 -DSTEM_ARCH_$4 endef define dependency_template #(target, configuration, platform, arch, source_file) build/intermediate/$1-$2-$3-$4/${notdir ${basename $5}}.d: $5 ${PREREQS_$1} | build/intermediate/$1-$2-$3-$4 @${CC_$3_$4} ${CCFLAGS} ${CCFLAGS_$1} ${CCFLAGS_$2} ${CCFLAGS_$3} ${call include_ccflags_template,$1,$3} ${call define_ccflags_template,$1,$2,$3,$4} -MM -o $$@.temp $5 @sed 's,\(${notdir ${basename $5}}\)\.o[ :]*,$${basename $$@}.o $${basename $$@}.d: ,g' < $$@.temp > $$@ @rm $$@.temp endef #Produces dependency build targets for all source files in each configuration/platform/arch ifeq ($(filter clean full_dist commit_dist analyze analyze_clang analyze_splint,${MAKECMDGOALS}),) ${foreach target,${TARGETS}, \ ${foreach configuration,${CONFIGURATIONS_${target}}, \ ${foreach platform,${PLATFORMS_${target}}, \ ${foreach arch,${ARCHS_${platform}}, \ ${foreach source,${SOURCES_${target}} ${SOURCES_${target}_${platform}}, \ ${eval ${call dependency_template,${target},${configuration},${platform},${arch},${source}}} \ ${eval -include build/intermediate/${target}-${configuration}-${platform}-${arch}/${notdir ${basename ${source}}}.d} \ } \ } \ } \ } \ } endif define compile_template #(target, configuration, platform, arch, source_file) build/intermediate/$1-$2-$3-$4/${notdir ${basename $5}}.o: $5 ${PREREQS_$1} | build/intermediate/$1-$2-$3-$4 ${CC_$3_$4} ${CCFLAGS} ${CCFLAGS_$1} ${CCFLAGS_$2} ${CCFLAGS_$3} ${call include_ccflags_template,$1,$3} ${call define_ccflags_template,$1,$2,$3,$4} -c -o $$@ $5 endef #Produces object build targets for all source files in each configuration/platform/arch ${foreach target,${TARGETS}, \ ${foreach configuration,${CONFIGURATIONS_${target}}, \ ${foreach platform,${PLATFORMS_${target}}, \ ${foreach arch,${ARCHS_${platform}}, \ ${foreach source,${SOURCES_${target}} ${SOURCES_${target}_${platform}}, \ ${eval ${call compile_template,${target},${configuration},${platform},${arch},${source}}} \ } \ } \ } \ } \ } define executable_template #(target, configuration, platform, arch, output_file, dependent_libraries) build/intermediate/$1-$2-$3-$4/$5: ${call arch_object_list_template,$1,$2,$3,$4} $6 ${LINKFILES_$1_$3} ${CC_$3_$4} -o $$@ $$^ ${LINKFLAGS} ${LINKFLAGS_$3} ${LINKFLAGS_$1_$3} ${LINKFILES_$1_$3} endef define library_dependency_template #(target, configuration, platform) ${foreach link_library,${LINK_ORDER}, \ ${foreach library,${filter ${link_library}%,${STEM_LIBRARY_DEPENDENCIES} ${STEM_LIBRARY_DEPENDENCIES_$1} ${STEM_LIBRARY_DEPENDENCIES_$3} ${STEM_LIBRARY_DEPENDENCIES_$1_$3}}, \ ${STEM_SHARED_DIR}/${library}/library/$2-$3/libstem_${word 1,${subst /, ,${library}}}.a \ } \ ${foreach library,${filter ${link_library}%,${STEM_SOURCE_DEPENDENCIES} ${STEM_SOURCE_DEPENDENCIES_$1} ${STEM_SOURCE_DEPENDENCIES_$3} ${STEM_SOURCE_DEPENDENCIES_$1_$3}}, \ dep/${word 1,${subst /, ,${library}}}/build/${word 2,${subst /, ,${library}}}/$2-$3/${word 3,${subst /, ,${library}}} \ } \ ${foreach library,${filter ${link_library}%,${THIRDPARTY_LIBRARY_DEPENDENCIES} ${THIRDPARTY_LIBRARY_DEPENDENCIES_$1} ${THIRDPARTY_LIBRARY_DEPENDENCIES_$3} ${THIRDPARTY_LIBRARY_DEPENDENCIES_$1_$3}}, \ ${STEM_SHARED_DIR}/${dir ${library}}library/$3/${notdir ${library}} \ } \ } endef #Produces executable build targets for each arch/platform/target for executable and application targets ${foreach target,${EXECUTABLE_TARGETS} ${APPLICATION_TARGETS}, \ ${foreach configuration,${CONFIGURATIONS_${target}}, \ ${foreach platform,${PLATFORMS_${target}}, \ ${foreach arch,${ARCHS_${platform}}, \ ${eval ${call executable_template,${target},${configuration},${platform},${arch},${TARGET_NAME_${target}}${EXECUTABLE_SUFFIX_${platform}},${call library_dependency_template,${target},${configuration},${platform}}}} \ } \ } \ } \ } define dependency_submake_template #(dependency) .PHONY: $1 $1: ${MAKE} -C dep/${word 1,${subst /, ,$1}} endef #Invokes make for each source dependency ${foreach dependency,${sort ${foreach target,${TARGETS},${foreach platform,${PLATFORMS_${target}},${STEM_SOURCE_DEPENDENCIES} ${STEM_SOURCE_DEPENDENCIES_${target}} ${STEM_SOURCE_DEPENDENCIES_${platform}} ${STEM_SOURCE_DEPENDENCIES_${target}_${platform}}}}}, \ ${eval ${call dependency_submake_template,${dependency}}} \ } define thin_binary_list_template #(target, configuration, platform, target_name) ${foreach arch,${ARCHS_$3}, \ build/intermediate/$1-$2-$3-${arch}/$4 \ } endef #Produces THIN_BINARIES_${target}_${configuration}_${platform} variables for each target/configuration/platform for executable targets ${foreach target,${EXECUTABLE_TARGETS}, \ ${foreach configuration,${CONFIGURATIONS_${target}}, \ ${foreach platform,${PLATFORMS_${target}}, \ ${eval THIN_BINARIES_${target}_${configuration}_${platform} = ${call thin_binary_list_template,${target},${configuration},${platform},${TARGET_NAME_${target}}${EXECUTABLE_SUFFIX_${platform}}}} \ } \ } \ } #Produces THIN_BINARIES_${target}_${configuration}_${platform} variables for each target/configuration/platform for application targets ${foreach target,${APPLICATION_TARGETS}, \ ${foreach configuration,${CONFIGURATIONS_${target}}, \ ${foreach platform,${PLATFORMS_${target}}, \ ${eval THIN_BINARIES_${target}_${configuration}_${platform} = ${call thin_binary_list_template,${target},${configuration},${platform},${TARGET_NAME_${target}}${EXECUTABLE_SUFFIX_${platform}}}} \ } \ } \ } define copy_target_resources #(target, platform, resources_dir) ${if ${strip ${RESOURCES_$1} ${RESOURCES_$1_$2}},mkdir -p $3,} ${foreach resource,${RESOURCES_$1} ${RESOURCES_$1_$2}, \ cp -r ${resource} $3${newline_and_tab} \ } ${if ${strip ${RESOURCES_$1} ${RESOURCES_$1_$2}},find $3 -name .svn -print0 -or -name .DS_Store -print0 | xargs -0 rm -rf} endef define copy_target_dynamiclibs #(target, platform, dll_dir) ${foreach dynamiclib,${DYNAMICLIBS_$1} ${DYNAMICLIBS_$1_$2}, \ cp ${dynamiclib} $3${newline_and_tab} \ } endef define assemble_executable_macosx #(target, configuration, platform) build/$1/$2-$3/${TARGET_NAME_$1}: ${THIN_BINARIES_$1_$2_$3} ${RESOURCES_$1} ${RESOURCES_$1_$3} | build/$1/$2-$3 lipo -create -output $$@ ${THIN_BINARIES_$1_$2_$3} ${call STRIP_$3_$2,$$@} ${call copy_target_resources,$1,$3,$${dir $$@}} ${call copy_target_dynamiclibs,$1,$3,$${dir $$@}} endef define assemble_executable_linux #(target, configuration, platform) build/$1/$2-$3/${TARGET_NAME_$1}: ${THIN_BINARIES_$1_$2_$3} ${RESOURCES_$1} ${RESOURCES_$1_$3} | build/$1/$2-$3 cp ${THIN_BINARIES_$1_$2_$3} $$@ ${call STRIP_$3_$2,$$@} ${call copy_target_resources,$1,$3,$${dir $$@}} ${call copy_target_dynamiclibs,$1,$3,$${dir $$@}} endef define assemble_executable_windows #(target, configuration, platform) build/$1/$2-$3/${TARGET_NAME_$1}.exe: ${THIN_BINARIES_$1_$2_$3} ${RESOURCES_$1} ${RESOURCES_$1_$3} | build/$1/$2-$3 cp ${THIN_BINARIES_$1_$2_$3} $$@ ${call STRIP_$3_$2,$$@} ${call copy_target_resources,$1,$3,$${dir $$@}} ${call copy_target_dynamiclibs,$1,$3,$${dir $$@}} endef #Produces final executable build targets ${foreach target,${EXECUTABLE_TARGETS}, \ ${foreach configuration,${CONFIGURATIONS_${target}}, \ ${foreach platform,${PLATFORMS_${target}}, \ ${eval ${call assemble_executable_${HOST_PLATFORM},${target},${configuration},${platform}}} \ } \ } \ } PLIST_FILE_mainapp_macosx = resources/Info_mainapp_macosx.plist PLIST_FILE_mainapp_iphonesimulator = resources/Info_mainapp_iphone.plist PLIST_PLATFORM_CASED_iphonesimulator = iPhoneSimulator PLIST_PLATFORM_LOWER_iphonesimulator = iphonesimulator PLIST_SDK_NAME_iphonesimulator = iphonesimulator${IPHONE_BUILD_SDK_VERSION} PLIST_FILE_mainapp_iphoneos = resources/Info_mainapp_iphone.plist PLIST_PLATFORM_CASED_iphoneos = iPhoneOS PLIST_PLATFORM_LOWER_iphoneos = iphoneos PLIST_SDK_NAME_iphoneos = iphoneos${IPHONE_BUILD_SDK_VERSION} define create_app_bundle #(target, platform, executable_dir, plist_dir, resources_dir) mkdir -p $3 $4 $5 sed -e "s/\$$$${PRODUCT_NAME}/${TARGET_NAME_$1}/g" \ -e "s/\$$$${HUMAN_READABLE_PRODUCT_NAME}/${HUMAN_READABLE_TARGET_NAME_$1}/g" \ -e "s/\$$$${VERSION}/${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_TWEAK}/g" \ -e "s/\$$$${COPYRIGHT_YEAR}/"`date +%Y`"/g" \ -e "s/\$$$${BUILD_NUMBER}/0/g" \ -e "s/\$$$${PLATFORM_CASED}/${PLIST_PLATFORM_CASED_$2}/g" \ -e "s/\$$$${PLATFORM_LOWER}/${PLIST_PLATFORM_LOWER_$2}/g" \ -e "s/\$$$${SDK}/${PLIST_SDK_NAME_$2}/g" \ ${PLIST_FILE_$1_$2} > $4/Info.plist echo "APPL????" > $4/PkgInfo ${call copy_target_resources,$1,$2,$5} endef define assemble_application_macosx #(target, configuration) build/$1/$2-macosx/$${HUMAN_READABLE_TARGET_NAME_$1}.app/Contents/MacOS/${TARGET_NAME_$1}: ${THIN_BINARIES_$1_$2_macosx} ${RESOURCES_$1} ${RESOURCES_$1_macosx} | build/$1/$2-macosx ${call create_app_bundle,$1,macosx,build/$1/$2-macosx/$${HUMAN_READABLE_TARGET_NAME_$1}.app/Contents/MacOS,build/$1/$2-macosx/$${HUMAN_READABLE_TARGET_NAME_$1}.app/Contents,build/$1/$2-macosx/$${HUMAN_READABLE_TARGET_NAME_$1}.app/Contents/Resources} lipo -create -output "$$@" ${THIN_BINARIES_$1_$2_macosx} ${call STRIP_macosx_$2,"$$@"} endef define assemble_application_iphonesimulator #(target, configuration) build/$1/$2-iphonesimulator/${TARGET_NAME_$1}.app/${TARGET_NAME_$1}: ${THIN_BINARIES_$1_$2_iphonesimulator} ${RESOURCES_$1} ${RESOURCES_$1_iphonesimulator} | build/$1/$2-iphonesimulator ${call create_app_bundle,$1,iphonesimulator,build/$1/$2-iphonesimulator/${TARGET_NAME_$1}.app,build/$1/$2-iphonesimulator/${TARGET_NAME_$1}.app,build/$1/$2-iphonesimulator/${TARGET_NAME_$1}.app} lipo -create -output "$$@" ${THIN_BINARIES_$1_$2_iphonesimulator} ${call STRIP_iphonesimulator_$2,"$$@"} endef define assemble_application_iphoneos #(target, configuration) build/$1/$2-iphoneos/${TARGET_NAME_$1}.app/${TARGET_NAME_$1}: ${THIN_BINARIES_$1_$2_iphoneos} ${RESOURCES_$1} ${RESOURCES_$1_iphoneos} | build/$1/$2-iphoneos ${call create_app_bundle,$1,iphoneos,build/$1/$2-iphoneos/${TARGET_NAME_$1}.app,build/$1/$2-iphoneos/${TARGET_NAME_$1}.app,build/$1/$2-iphoneos/${TARGET_NAME_$1}.app} lipo -create -output "$$@" ${THIN_BINARIES_$1_$2_iphoneos} ${call STRIP_iphoneos_$2,"$$@"} endef define assemble_application_linux32 #(target, configuration) build/$1/$2-linux32/${TARGET_NAME_$1}: ${THIN_BINARIES_$1_$2_linux32} ${RESOURCES_$1} ${RESOURCES_$1_linux32} | build/$1/$2-linux32 ${call copy_target_resources,$1,linux32,build/$1/$2-linux32/Resources} ${call copy_target_dynamiclibs,$1,linux32,build/$1/$2-linux32} cp ${THIN_BINARIES_$1_$2_linux32} "$$@" ${call STRIP_linux32_$2,"$$@"} endef define assemble_application_linux64 #(target, configuration) build/$1/$2-linux64/${TARGET_NAME_$1}: ${THIN_BINARIES_$1_$2_linux64} ${RESOURCES_$1} ${RESOURCES_$1_linux64} | build/$1/$2-linux64 ${call copy_target_resources,$1,linux64,build/$1/$2-linux64/Resources} ${call copy_target_dynamiclibs,$1,linux64,build/$1/$2-linux64} cp ${THIN_BINARIES_$1_$2_linux64} "$$@" ${call STRIP_linux64_$2,"$$@"} endef define assemble_application_win32 #(target, configuration) build/$1/$2-win32/${TARGET_NAME_$1}.exe: ${THIN_BINARIES_$1_$2_win32} ${RESOURCES_$1} ${RESOURCES_$1_win32} | build/$1/$2-win32 ${call copy_target_resources,$1,win32,build/$1/$2-win32/Resources} ${call copy_target_dynamiclibs,$1,win32,build/$1/$2-win32} cp ${THIN_BINARIES_$1_$2_win32} "$$@" ${call STRIP_win32_$2,"$$@"} endef define assemble_application_win64 #(target, configuration) build/$1/$2-win64/${TARGET_NAME_$1}.exe: ${THIN_BINARIES_$1_$2_win64} ${RESOURCES_$1} ${RESOURCES_$1_win64} | build/$1/$2-win64 ${call copy_target_resources,$1,win64,build/$1/$2-win64/Resources} ${call copy_target_dynamiclibs,$1,win64,build/$1/$2-win64} cp ${THIN_BINARIES_$1_$2_win64} "$$@" ${call STRIP_win64_$2,"$$@"} endef #Produces final application build targets ${foreach target,${APPLICATION_TARGETS}, \ ${foreach configuration,${CONFIGURATIONS_${target}}, \ ${foreach platform,${PLATFORMS_${target}}, \ ${eval ${call assemble_application_${platform},${target},${configuration}}} \ } \ } \ } define executable_dependency_template #(target, configuration, platform) ${STEM_SOURCE_DEPENDENCIES} ${STEM_SOURCE_DEPENDENCIES_$1} ${STEM_SOURCE_DEPENDENCIES_$1_$3} build/$1/$2-$3/${TARGET_NAME_$1}${EXECUTABLE_SUFFIX_$3} endef define application_dependency_template #(target, configuration, platform) ${STEM_SOURCE_DEPENDENCIES} ${STEM_SOURCE_DEPENDENCIES_$1} ${STEM_SOURCE_DEPENDENCIES_$1_$3} build/$1/$2-$3/${call application_file_template_$3,$1} endef define application_file_template_macosx #(target) $${HUMAN_READABLE_TARGET_NAME_$1}.app/Contents/MacOS/${TARGET_NAME_$1} endef define application_file_template_iphonesimulator #(target) ${TARGET_NAME_$1}.app/${TARGET_NAME_$1} endef define application_file_template_iphoneos #(target) ${TARGET_NAME_$1}.app/${TARGET_NAME_$1} endef define application_file_template_linux32 #(target) ${TARGET_NAME_$1} endef define application_file_template_linux64 #(target) ${TARGET_NAME_$1} endef define application_file_template_win32 #(target) ${TARGET_NAME_$1}.exe endef define application_file_template_win64 #(target) ${TARGET_NAME_$1}.exe endef define target_template #(target, target_type) .PHONY: $1 $1: ${foreach configuration,${CONFIGURATIONS_$1},${foreach platform,${PLATFORMS_$1},${call $2_dependency_template,$1,${configuration},${platform}}}} endef ${foreach target,${EXECUTABLE_TARGETS}, \ ${eval ${call target_template,${target},executable}} \ } ${foreach target,${APPLICATION_TARGETS}, \ ${eval ${call target_template,${target},application}} \ } .PHONY: test test: ${foreach platform,${PLATFORMS_unittest},run_unittests_${platform}} .PHONY: run_unittests_macosx run_unittests_macosx: unittest ./build/unittest/debug-macosx/${TARGET_NAME_unittest} "${CURDIR}/build/unittest/debug-macosx" .PHONY: run_unittests_iphonesimulator run_unittests_iphonesimulator: unittest DYLD_ROOT_PATH=${SDKROOT_iphonesimulator} \ ./build/unittest/debug-iphonesimulator/${TARGET_NAME_unittest} "${CURDIR}/build/unittest/debug-iphonesimulator" .PHONY: run_unittests_linux32 run_unittests_linux32: unittest ./build/unittest/debug-linux32/${TARGET_NAME_unittest} "${CURDIR}/build/unittest/debug-linux32" .PHONY: run_unittests_linux64 run_unittests_linux64: unittest ./build/unittest/debug-linux64/${TARGET_NAME_unittest} "${CURDIR}/build/unittest/debug-linux64" .PHONY: run_unittests_win32 run_unittests_win32: unittest ./build/unittest/debug-win32/${TARGET_NAME_unittest}.exe "${CURDIR}/build/unittest/debug-win32" .PHONY: run_unittests_win64 run_unittests_win64: unittest ./build/unittest/debug-win64/${TARGET_NAME_unittest}.exe "${CURDIR}/build/unittest/debug-win64" define analyze_file_template_clang #(target, platform, file) build/analyzer-results/clang-$1-$2/${basename ${notdir $3}}.txt: $3 ${PREREQS_$1} | build/analyzer-results/clang-$1-$2 ${CLANG_$2} --analyze ${call include_ccflags_template,$1,$2} ${call define_ccflags_template,$1,analyze,$2,none} ${CLANGFLAGS} ${CLANGFLAGS_$1} ${CLANGFLAGS_$2} -o $${basename $$@}.plist $3 > $$@ 2>&1; true @cat $$@ endef define analyze_file_template_splint #(target, platform, file) build/analyzer-results/splint-$1-$2/${basename ${notdir $3}}.txt: $3 ${PREREQS_$1} | build/analyzer-results/splint-$1-$2 ${SPLINT_$2} ${call include_ccflags_template,$1,$2} ${call define_ccflags_template,$1,analyze,$2,none} ${SPLINTFLAGS} ${SPLINTFLAGS_$1} ${SPLINTFLAGS_$2} $3 > $$@ 2>&1; true @cat $$@ endef define analyzed_sources_template #(analyzer, target, platform) ${sort ${filter-out ${ANALYZER_EXCLUDE_SOURCES_$1},${SOURCES_$2} ${SOURCES_$2_$3}}} endef define analyzer_output_template #(analyzer, target, platform) ${foreach file,${call analyzed_sources_template,$1,$2,$3}, \ build/analyzer-results/$1-$2-$3/${basename ${notdir ${file}}}.txt \ } endef define analyze_target_template #(analyzer, target, platform) .PHONY: analyze_$1_$2_$3 analyze_$1_$2_$3: ${call analyzer_output_template,$1,$2,$3} endef define analyze_template #(analyzer) .PHONY: analyze_$1 analyze_$1: ${foreach target,${TARGETS},${foreach platform,${PLATFORMS_${target}},analyze_$1_${target}_${platform}}} endef ${foreach analyzer,${ANALYZERS}, \ ${eval ${call analyze_template,${analyzer}}} \ ${foreach target,${TARGETS}, \ ${foreach platform,${PLATFORMS_${target}}, \ ${eval ${call analyze_target_template,${analyzer},${target},${platform}}} \ ${foreach file,${call analyzed_sources_template,${analyzer},${target},${platform}}, \ ${eval ${call analyze_file_template_${analyzer},${target},${platform},${file}}} \ } \ } \ } \ } ${foreach analyzer,${ANALYZERS}, \ ${foreach target,${TARGETS}, \ ${foreach platform,${PLATFORMS_${target}}, \ ${eval ${call create_directory_target_template,build/analyzer-results/${analyzer}-${target}-${platform}}} \ } \ } \ } .PHONY: analyze analyze: ${foreach analyzer,${ANALYZERS},analyze_${analyzer}} .PHONY: clean clean: rm -rf build ${foreach dependency,${sort ${foreach target,${TARGETS},${foreach platform,${PLATFORMS_${target}},${STEM_SOURCE_DEPENDENCIES} ${STEM_SOURCE_DEPENDENCIES_${target}} ${STEM_SOURCE_DEPENDENCIES_${platform}} ${STEM_SOURCE_DEPENDENCIES_${target}_${platform}}}}}, \ ${MAKE} -C dep/${word 1,${subst /, ,${dependency}}} clean${newline_and_tab} \ } TARGET_SUFFIX_ipad = _ipad TARGET_SUFFIX_iphone4 = _iphone4 IPHONE_SDK_VERSION_iphone ?= 4.2 IPHONE_SDK_VERSION_ipad ?= 3.2 IPHONE_SDK_VERSION_iphone4 ?= 4.2 IPHONESIMULATOR_APPLICATIONS_DIR_iphone ?= ${HOME}/Library/Application Support/iPhone Simulator/${IPHONE_SDK_VERSION_iphone}/Applications IPHONESIMULATOR_APPLICATIONS_DIR_ipad ?= ${HOME}/Library/Application Support/iPhone Simulator/${IPHONE_SDK_VERSION_ipad}/Applications IPHONESIMULATOR_APPLICATIONS_DIR_iphone4 ?= ${HOME}/Library/Application Support/iPhone Simulator/${IPHONE_SDK_VERSION_iphone4}/Applications SIMULATE_DEVICE_iphone = iPhone SIMULATE_DEVICE_ipad = iPad SIMULATE_DEVICE_iphone4 = iPhone 4 SIMULATE_SDKROOT_iphone = /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator${IPHONE_SDK_VERSION_iphone}.sdk SIMULATE_SDKROOT_ipad = /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator${IPHONE_SDK_VERSION_ipad}.sdk SIMULATE_SDKROOT_iphone4 = /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator${IPHONE_SDK_VERSION_iphone4}.sdk IPHONE_SIMULATOR_PATH ?= /Developer/Platforms/iPhoneSimulator.platform/Developer/Applications/iPhone Simulator.app define install_target_iphonesimulator_template #(target, simulate_device) .PHONY: install_$1_iphonesimulator${TARGET_SUFFIX_$2} install_$1_iphonesimulator${TARGET_SUFFIX_$2}: $1 killall "iPhone Simulator"; true rm -rf "${IPHONESIMULATOR_APPLICATIONS_DIR_$2}/${TARGET_NAME_$1}" mkdir -p "${IPHONESIMULATOR_APPLICATIONS_DIR_$2}/${TARGET_NAME_$1}/Documents" mkdir -p "${IPHONESIMULATOR_APPLICATIONS_DIR_$2}/${TARGET_NAME_$1}/Library/Preferences" mkdir -p "${IPHONESIMULATOR_APPLICATIONS_DIR_$2}/${TARGET_NAME_$1}/tmp" cp -r "build/$1/debug-iphonesimulator/${TARGET_NAME_$1}.app" "${IPHONESIMULATOR_APPLICATIONS_DIR_$2}/${TARGET_NAME_$1}" defaults write com.apple.iphonesimulator SimulateDevice -string "${SIMULATE_DEVICE_$2}" defaults write com.apple.iphonesimulator SimulateSDKRoot -string "${SIMULATE_SDKROOT_$2}" defaults write com.apple.iphonesimulator currentSDKRoot -string "${SIMULATE_SDKROOT_$2}" open "${IPHONE_SIMULATOR_PATH}" endef define add_blob_header #(source_file, target_file) ruby -e "contents = \"\"; File.open(\"$1\", \"r\") {|file| contents = file.read}; File.open(\"$2\", \"w\") {|file| file.write(\"\xFA\xDE\x71\x71\"); file.write([contents.length + 8].pack(\"N\")); file.write(contents)}" endef RESOURCE_RULES_PLIST = /Developer/Platforms/MacOSX.platform/ResourceRules.plist define codesign_target_iphoneos_template #(target) .PHONY: codesign_$1_iphoneos codesign_$1_iphoneos: $1 sed -e "s/\$$$${PRODUCT_NAME}/${TARGET_NAME_$1}/g" resources/Entitlements.plist > build/intermediate/Entitlements.plist ${call add_blob_header,build/intermediate/Entitlements.plist,build/intermediate/Entitlements.xcent} export CODESIGN_ALLOCATE=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/codesign_allocate ${foreach configuration,${CONFIGURATIONS_$1},\ cp "${RESOURCE_RULES_PLIST}" "build/$1/${configuration}-iphoneos/${TARGET_NAME_$1}.app"${newline_and_tab} \ /usr/bin/codesign -f -s ${CODESIGN_IDENTITY} --resource-rules=${RESOURCE_RULES_PLIST} --entitlements=build/intermediate/Entitlements.xcent "build/$1/${configuration}-iphoneos/${TARGET_NAME_$1}.app"${newline_and_tab} \ } endef ${foreach target,${APPLICATION_TARGETS}, \ ${eval ${call install_target_iphonesimulator_template,${target},iphone}} \ ${eval ${call install_target_iphonesimulator_template,${target},ipad}} \ ${eval ${call install_target_iphonesimulator_template,${target},iphone4}} \ ${eval ${call codesign_target_iphoneos_template,${target}}} \ }