VirtualBox

source: kBuild/trunk/src/kmk/testcase-kBuild-define.kmk@ 3387

Last change on this file since 3387 was 2720, checked in by bird, 10 years ago

kBuild objects: Implemented the special variable accessor [@super] and [@self].

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 5.0 KB
RevLine 
[2548]1# $Id: testcase-kBuild-define.kmk 2720 2014-01-01 22:59:50Z bird $
2## @file
3# kBuild - testcase for the kBuild-define-* directives.
4#
5
6#
[2717]7# Copyright (c) 2011-2013 knut st. osmundsen <bird-kBuild-spamx@anduin.net>
[2548]8#
9# This file is part of kBuild.
10#
11# kBuild is free software; you can redistribute it and/or modify
12# it under the terms of the GNU General Public License as published by
13# the Free Software Foundation; either version 3 of the License, or
14# (at your option) any later version.
15#
16# kBuild is distributed in the hope that it will be useful,
17# but WITHOUT ANY WARRANTY; without even the implied warranty of
18# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19# GNU General Public License for more details.
20#
21# You should have received a copy of the GNU General Public License
22# along with kBuild. If not, see <http://www.gnu.org/licenses/>
23#
24#
25
[2717]26#DEPTH = ../..
[2548]27#include $(PATH_KBUILD)/header.kmk
28
[2720]29##
30# Test if $($1) == $2 and raises an error if it isn't.
31#
32# @param 1 Something to apply '$' to.
33# @param 2 The expected value.
34TEST_EQ = $(if-expr "$($1)" == "$2",,$(error $1 is '$($1)' not '$2'))
35
[2717]36if 0
[2655]37# object definition syntax:
[2717]38# kobject <type> <name> [extends <object> [by <||>]] [object specific args...]
39# kendobj [<type> [name]]
[2655]40kobject kb-target MyTarget
[2658]41.TOOL = GCC
[2655]42.SOURCES = file.c
[2717]43kendobj
44else
45# Target definition.
46# kBuild-define-target <name> [extends <target> [by <||>]] [using <template>]
47# kBuild-endef-target [name]
48kBuild-define-target MyTarget
49_TOOL = GCC
50_SOURCES = file.c
51kBuild-endef-target
52endif
[2548]53
[2717]54if 0
[2655]55# accesses an already defined object.
56# syntax:
57# kaccess <type> <name>
[2717]58# kendacc [<type> [name]]
[2655]59kaccess kb-target MyTarget
60.SOURCES += file2.c
[2717]61kendacc
62else
63#kBuild-access-target MyTarget
64#_SOURCES += file2.c
65#kBuild-endacc-target
66endif
[2548]67
68
[2655]69# Referencing an object variable, the object must exist.
70# syntax: [<type>@<name>].<property>
[2717]71[target@MyTarget]_SOURCES += file3.c
72$(info [target@MyTarget]_SOURCES is $([target@MyTarget]_SOURCES))
[2548]73
74
[2655]75# Test #1
[2717]76kBuild-define-target BaseTarget using DUMMY
77_SOURCES = BaseTargetSource.c
78kBuild-endef-target BaseTarget
79$(if-expr "$([target@BaseTarget]_SOURCES)" == "BaseTargetSource.c",,$(error [target@BaseTarget]_SOURCES is '$([target@BaseTarget]_SOURCES)' not 'BaseTargetSource.c'))
80$(if-expr "$(BaseTarget_SOURCES)" == "BaseTargetSource.c",,$(error BaseTarget's _SOURCES wasn't set correctly in the global space))
[2548]81
[2717]82$(if-expr "$([target@BaseTarget]_TEMPLATE)" == "DUMMY",,$(error [target@BaseTarget]_TEMPLATE is '$([target@BaseTarget]_TEMPLATE)' not 'DUMMY'))
83$(if-expr "$(BaseTarget_TEMPLATE)" == "DUMMY",,$(error BaseTarget's _TEMPLATE wasn't set correctly in the global space))
[2548]84
[2655]85# Test #2
[2717]86kBuild-define-target TargetWithLocals
87local _LOCAL_PROP = no global alias
88kBuild-endef-target
89$(if-expr "$([target@TargetWithLocals]_LOCAL_PROP)" == "no global alias",,$(error [target@TargetWithLocals]_LOCAL_PROP is '$([target@TargetWithLocals]_LOCAL_PROP)' not 'no global alias'))
90$(if-expr "$(TargetWithLocals_LOCAL_PROP)" == "",,$(error TargetWithLocals_LOCAL_PROP's local property 'LOCAL_PROP' was exposed globally.))
[2548]91
[2717]92# Test #3
93kBuild-define-target OutsideMod
94_SOURCES = file3.c
95_OTHER = inside-value
96kBuild-endef-target
97[target@OutsideMod]_SOURCES += file4.c
98[target@OutsideMod]_SOURCES <= file2.c
99[target@OutsideMod]_OTHER = outside-value
100$(if-expr "$([target@OutsideMod]_SOURCES)" == "file2.c file3.c file4.c",,$(error [target@OutsideMod]_SOURCES is '$([target@OutsideMod]_SOURCES)' not 'file2.c file3.c file4.c'))
[2718]101$(if-expr "$(OutsideMod_SOURCES)" == "file2.c file3.c file4.c",,$(error OutsideMod_SOURCES is '$(OutsideMod_SOURCES)' not 'file2.c file3.c file4.c'))
[2548]102
[2717]103$(if-expr "$([target@OutsideMod]_OTHER)" == "outside-value",,$(error [target@OutsideMod]_OTHER is '$([target@OutsideMod]_OTHER)' not 'outside-value'))
104$(if-expr "$(OutsideMod_OTHER)" == "outside-value",,$(error OutsideMod_OTHER is '$(OutsideMod_OTHER)' not 'outside-value'))
105
[2720]106# Test #4
107kBuild-define-target SpecialBase
108_SOURCES = file1.c file2.c
109_DEFS.win.x86 = XXX YYY
110_DEFS.win.amd64 = $(filter-out YYY,$([@self]_DEFS.win.x86))
111# Unnecessary use of [@self].
112[@self]_LIBS = MyLib
113kBuild-endef-target
114
115kBuild-define-target SpecialChild extending SpecialBase
116_SOURCES = file1-child.c $(filter-out file1.c,$([@super]_SOURCES))
117# Rare use of [@super].
118[@super]_SET_BY_CHILD = 42
119kBuild-endef-target
120
121$(call TEST_EQ,[target@SpecialBase]_LIBS,MyLib)
122$(call TEST_EQ,SpecialBase_LIBS,MyLib)
123
124$(call TEST_EQ,[target@SpecialBase]_SET_BY_CHILD,42)
125$(call TEST_EQ,SpecialBase_SET_BY_CHILD,42)
126$(call TEST_EQ,[target@SpecialChild]_SET_BY_CHILD,42)
127#$(call TEST_EQ,SpecialChild_SET_BY_CHILD,42) ## @todo
128
129$(call TEST_EQ,[target@SpecialBase]_DEFS.win.x86,XXX YYY)
130$(call TEST_EQ,[target@SpecialBase]_DEFS.win.amd64,XXX)
131$(call TEST_EQ,SpecialBase_DEFS.win.amd64,XXX)
132$(call TEST_EQ,[target@SpecialChild]_DEFS.win.x86,XXX YYY)
133$(call TEST_EQ,[target@SpecialChild]_DEFS.win.amd64,XXX)
134#$(call TEST_EQ,SpecialChild_DEFS.win.amd64,XXX) ## @todo
135
136$(call TEST_EQ,[target@SpecialChild]_SOURCES,file1-child.c file2.c)
137$(call TEST_EQ,SpecialChild_SOURCES,file1-child.c file2.c)
138
[2548]139all_recursive:
[2717]140 @kmk_echo "kBuild-define-xxxx works fine"
[2548]141
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use