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