1#!/usr/bin/env omake
2#----------------------------------------------------------------------------
3# Project: Horizon
4# File:    commondefs.gl.om
5#
6# Copyright 2007-2009 Nintendo. All rights reserved.
7#
8# These coded instructions, statements, and computer programs contain
9# proprietary information of Nintendo of America Inc. and/or Nintendo
10# Company Ltd., and are protected by Federal copyright law. They may
11# not be disclosed to third parties or copied or duplicated in any form,
12# in whole or in part, without the prior written consent of Nintendo.
13#
14# $Date:: 2011-01-28#$
15# $Rev: 33889 $
16# $Author: hatamoto_minoru $
17#----------------------------------------------------------------------------
18
19# Assembler/linker definitions
20public.VSASM            = $(ROOT_COMMANDS)$(DIRSEP)ctr_VertexShaderAssembler32.exe
21public.VSLD             = $(ROOT_COMMANDS)$(DIRSEP)ctr_VertexShaderLinker32.exe
22
23# Directory where a built shader is stored
24public.SHADER_PREBUILT_ROOT = $(ROOT_RESOURCES)$(DIRSEP)shaders
25
26# Include directory passed with -I to the assembler/linker
27public.SHADER_INCLUDES      = $(SHADER_PREBUILT_ROOT)
28
29# Generate command line to specify the include directory (delay evaluation)
30public.PREFIXED_SHADER_INCLUDES = $`(addprefix -I, $(set $(absname $(SHADER_INCLUDES))))
31
32# Extension definitions
33EXT_VSASM = .vsh
34EXT_VSOBJ = .obj
35EXT_VSBIN = .shbin
36
37# While continuing to return the storage destination for .obj/.shbin, define generation rules for the parent directory
38getShaderObjectDirectory() =
39    return $(makeDirectory $(getObjectBaseDirectory)$(DIRSEP)CTR.Shader)
40
41# Generate .obj files
42# sourcefiles - .vsh file (multiple OK)
43VertexShaderObjects(sourcefiles) =
44    # Get the directory where .obj is stored
45    obj_dir_parent = $(getShaderObjectDirectory)
46
47    OFILES =
48    export OFILES
49    # Define rules for each .vsh file
50    foreach(sourcefile, $(sourcefiles))
51        # Get the full path of the file name to output
52        OFILE = $(file $(obj_dir_parent)/$(basename $(removesuffix $(sourcefile)))$(EXT_VSOBJ))
53
54        # Add to return values
55        OFILES += $(OFILE)
56
57        # Define the assembler rules (when there are no warning or errors, cut output with grep)
58        # Make directory dependent as well and generate automatically
59        $(OFILE): $(sourcefile) $(obj_dir_parent) $(VSASM)
60            $(VSASM) $< $(PREFIXED_SHADER_INCLUDES) -O$@ | grep -v '^.*finished - 0 error, 0 warning'
61
62    # Define the clean rules
63    clean:
64        rm -rf $(obj_dir_parent)
65
66    return $(OFILES)
67
68# Generate .shbin files
69# name        - .shbin name (no extension)
70# sourcefiles - .obj file generated with OMakefile
71# sourcefiles_pre - built .obj file under resources
72VertexShaderBinary(name, sourcefiles, sourcefiles_pre) =
73    # Find the directory where .obj is stored
74    obj_dir_parent = $(getShaderObjectDirectory)
75
76    # Convert sourcefiles_pre to full path in order to correctly obtain the dependency relationship.
77    # (When relying on -I, no rebuild occurs when a built .obj is updated.)
78    sourcefiles_pre = $(addprefix $(SHADER_PREBUILT_ROOT)$(DIRSEP), $(sourcefiles_pre))
79
80    # Get the full path of the file name to output
81    OFILE = $(file $(obj_dir_parent)/$(basename $(name))$(EXT_VSBIN))
82
83    # Define the link rules (when there are no warning or errors, cut output with grep)
84    $(OFILE): $(sourcefiles) $(sourcefiles_pre) $(obj_dir_parent) $(VSLD)
85        $(VSLD) $(sourcefiles) $(sourcefiles_pre) $(PREFIXED_SHADER_INCLUDES) -M -nodebug -O$@ | grep -v '^.*finished - 0 error, 0 warning'
86
87    if $(not $(defined SHBIN_INSTALL_ROOT))
88        if $(defined ROMFS_ROOT)
89            SHBIN_INSTALL_ROOT = $(ROMFS_ROOT)
90            export
91        export
92
93    # When SHBIN_INSTALL_ROOT is defined, copy binary under SHBIN_INSTALL_ROOT
94    if $(and $(defined SHBIN_INSTALL_ROOT), $(not $(equal $(SHBIN_INSTALL_ROOT),$(EMPTY))))
95
96        # Find file name of the installation destination
97        OFILE_INSTALL = $(SHBIN_INSTALL_ROOT)$(DIRSEP)$(basename $(OFILE))
98
99        # Save to the installation destination
100        $(OFILE_INSTALL): $(OFILE) $(SHBIN_INSTALL_ROOT)
101            ln-or-cp $< $@
102        # Create directory in the installation destination
103        $(SHBIN_INSTALL_ROOT):
104            mkdir -p $@
105        #Define the clean rules
106        clean:
107            rm -f $(OFILE_INSTALL)
108
109
110        # Must prepare the file in ROMFS before MAKEROM
111        build-romfs: $(OFILE_INSTALL)
112
113    # Define the clean rules
114    clean:
115        rm -rf $(obj_dir_parent)
116
117    # Always return the binary generated in objects
118    return $(OFILE)
119