Changeset 1727 in kBuild for trunk/src/kmk
- Timestamp:
- Sep 5, 2008 1:45:52 AM (16 years ago)
- Location:
- trunk/src/kmk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kmk/function.c
r1716 r1727 2724 2724 if (e1 - s1 != e2 - s2) 2725 2725 return comp_vars_ne (o, s1, e1, s2, e2, argv[2], funcname); 2726 l_simple_compare:2727 2726 if (!memcmp (s1, s2, e1 - s1)) 2728 2727 return variable_buffer_output (o, "", 0); /* eq */ … … 3089 3088 return variable_buffer_output (o, "", 0); 3090 3089 } 3091 #endif 3090 #endif /* CONFIG_WITH_WHICH */ 3091 3092 #ifdef CONFIG_WITH_IF_CONDITIONALS 3093 3094 /* Evaluates the expression given in the argument using the 3095 same evaluator as for the new 'if' statements, except now 3096 we don't force the result into a boolean like for 'if' and 3097 '$(if-expr ,,)'. */ 3098 static char * 3099 func_expr (char *o, char **argv, const char *funcname UNUSED) 3100 { 3101 o = expr_eval_to_string (o, argv[0]); 3102 return o; 3103 } 3104 3105 /* Same as '$(if ,,)' except the first argument is evaluated 3106 using the same evaluator as for the new 'if' statements. */ 3107 static char * 3108 func_if_expr (char *o, char **argv, const char *funcname UNUSED) 3109 { 3110 int rc; 3111 char *to_expand; 3112 3113 /* Evaluate the condition in argv[0] and expand the 2nd or 3114 3rd argument according to the result. */ 3115 rc = expr_eval_if_conditionals (argv[0], NULL); 3116 to_expand = rc == 0 ? argv[1] : argv[2]; 3117 if (*to_expand) 3118 { 3119 char *expansion = expand_argument (to_expand, NULL); 3120 3121 o = variable_buffer_output (o, expansion, strlen (expansion)); 3122 3123 free (expansion); 3124 } 3125 3126 return o; 3127 } 3128 3129 #endif /* CONFIG_WITH_IF_CONDITIONALS */ 3092 3130 3093 3131 #ifdef CONFIG_WITH_STACK … … 3108 3146 struct variable *stack_var; 3109 3147 const char *stack = argv[0]; 3110 const int return_item = argv[0][sizeof("stack-pop") - 1] == '\0';3111 3148 3112 3149 stack_var = lookup_variable (stack, strlen (stack) ); … … 3959 3996 { STRING_SIZE_TUPLE("which"), 0, 0, 1, func_which}, 3960 3997 #endif 3998 #ifdef CONFIG_WITH_IF_CONDITIONALS 3999 { STRING_SIZE_TUPLE("expr"), 1, 1, 0, func_expr}, 4000 { STRING_SIZE_TUPLE("if-expr"), 2, 3, 0, func_if_expr}, 4001 #endif 3961 4002 #ifdef CONFIG_WITH_STACK 3962 4003 { STRING_SIZE_TUPLE("stack-push"), 2, 2, 1, func_stack_push}, -
trunk/src/kmk/testcase-ifcond.kmk
r1722 r1727 26 26 27 27 28 #DEPTH = ../..29 #include $(PATH_KBUILD)/header.kmk28 DEPTH = ../.. 29 include $(KBUILD_PATH)/header.kmk 30 30 31 31 ifeq (1,0) … … 223 223 # target() 224 224 # 225 if 0 225 226 trg_deps_only: foobar 226 227 trg_with_cmds: foobar … … 230 231 $(warning works) 231 232 else 232 $(error works)233 $(error target) 233 234 endif 234 235 235 236 if target trg_deps_only 236 $(error works)237 $(error target) 237 238 else 238 239 $(warning works) … … 240 241 241 242 if target foobar 242 $(error works) 243 else 244 $(warning works) 245 endif 243 $(error target) 244 else 245 $(warning works) 246 endif 247 endif 246 248 247 249 … … 255 257 $(warning works) 256 258 else 257 $(error works)259 $(error ) 258 260 endif 259 261 … … 261 263 $(warning works) 262 264 else 263 $(error works)265 $(error ) 264 266 endif 265 267 … … 267 269 $(warning works) 268 270 else 269 $(error works)271 $(error ) 270 272 endif 271 273 272 274 if defined (var_not_defined) 273 $(error works) 274 else 275 $(warning works) 275 $(error ) 276 else 277 $(warning works) 278 endif 279 280 281 # 282 # Quick check of $(if-expr ) and $(expr ). 283 # 284 ifeq ($(if-expr 0 || 2,42,500),42) 285 $(warning if-expr test 1 succeeded) 286 else 287 $(error ) 288 endif 289 290 ifeq ($(if-expr 5+3 == 231,42,500),42) 291 $(error ) 292 else 293 $(warning if-expr test 2 succeeded) 294 endif 295 296 ifeq ($(expr 5+3),8) 297 $(warning expr test 1 succeeded) 298 else 299 $(error expr:$(expr 5+3) expected 8) 300 endif 301 302 ifeq ($(expr 25*25),625) 303 $(warning expr test 2 succeeded) 304 else 305 $(error expr:$(expr 25*25) expected 625) 306 endif 307 308 ifeq ($(expr 100/3),3) 309 $(error ) 310 else 311 $(warning expr test 3 succeeded) 276 312 endif 277 313
Note:
See TracChangeset
for help on using the changeset viewer.