为什么$ *或%在这个makefile中不起作用?

时间:2018-03-21 11:03:32

标签: makefile gnu-make

考虑以下简单的makefile:

- (void)pushRegistry:(PKPushRegistry *)registry didReceiveIncomingPushWithPayload:(PKPushPayload *)payload forType:(NSString *)type {

     // Process the received push

    NSString *uuidString = payload.dictionaryPayload[@"UUID"];
    NSUUID *uuid = [[NSUUID alloc] initWithUUIDString:uuidString];

    NSString *handle = payload.dictionaryPayload[@"handle"];
    bool hasVideo = payload.dictionaryPayload[@"hasVideo"];



    if (uuid) {
        UIApplication *app = [UIApplication sharedApplication];

        UIBackgroundTaskIdentifier task = [app beginBackgroundTaskWithExpirationHandler:^{
            [app endBackgroundTask:task];
        }];

        [self displayIncomingCall:uuid handle:handle hasVideo:false withCompletion:^(NSError *error) {
            [[UIApplication sharedApplication] endBackgroundTask:task];
        }];
    }

}


- (void)pushRegistry:(PKPushRegistry *)registry didUpdatePushCredentials:(PKPushCredentials *)credentials forType:(NSString *)type {

    // Register VoIP push token (a property of PKPushCredentials) with server

    if([credentials.token length] == 0) {
        NSLog(@"voip token NULL");
        return;
    }

}

define cat_deps $(shell cat $(1).dep) endef TARGET := main.o all:$(TARGET) @echo Done...! %.o:$(call cat_deps,$*) @echo $* 中的目标main.o变量$(1)必须为cat_desp 但它是空字符串。 main也不起作用 在这种情况下,变量$(call cat_deps,%)变为$(1)。注意 该文件%存在。请帮帮我。

1 个答案:

答案 0 :(得分:1)

  

main.o中的目标$(1)变量cat_desp必须为main,但它是空字符串。

如果您将$1传递给函数cat_depsmain中的

main实际会扩展为cat_deps。但是,您传递的是一个空字符串。在你的规则中:

%.o: $(call cat_deps,$*)
    @echo $*

上面的$*在匹配规则之前展开,在匹配该规则之前,自动变量$*实际上是空的。

匹配规则后,您需要使用secondary expansion以扩展对cat_deps的函数调用和自动变量$* ,即:

.SECONDEXPANSION:
%.o: $$(call cat_deps,$$*)
    @echo $*

请注意$call的其他$*

请注意,您还需要以下没有食谱的规则:

%: %.o

为了压制隐含规则。否则,上面的新%.o规则的先决条件可以匹配那个(未抑制的)隐式规则,该规则具有.o文件作为先决条件,并且将依次与新{{1}匹配再次统治。