Search code examples
makefileopenwrt

strange variables and functions definition in openwrt makefile


I am reading the makefile of openwrt, original file can be found here: https://dev.openwrt.org/browser/trunk/target/linux/ramips/image/Makefile#L589

I cannot understand these lines:

BuildFirmware/Default8M/squashfs=$(call BuildFirmware/OF,$(1),$(2),$(3),$(ralink_default_fw_size_8M),$(4))
BuildFirmware/Default8M/initramfs=$(call BuildFirmware/OF/initramfs,$(1),$(2),$(3),$(4))

Image/Build/Profile/MT7620a=$(call BuildFirmware/Default8M/$(1),$(1),mt7620a,MT7620a)

Q1. $(1), $(2)..... Where do these variables come from? How can I assign values to them? Q2. If $(1) is "squashfs", does it mean the 3rd line is calling the "function" defined in the 1st line? The argument list does not match, in my opinion. Q3. the slash "/" in these variable names seem odd. Is it the good way to define a variable? I think we can change it to : Image_Build_Profile_MT7620a

Thanks in advance.


Solution

  • A1: The variables $(1), $(2) and so on are place-holders used by the call function. From the manual:

    reverse = $(2) $(1)
    
    foo = $(call reverse,a,b)
    
    Here foo will contain ‘b a’. 
    

    A2: If we invoke

    $(call Image/Build/Profile/MT7620a,squashfs)
    

    it will expand to

    $(call BuildFirmware/Default8M/squashfs,squashfs,mt7620a,MT7620a)
    

    But BuildFirmware/Default8M/squashfs does not appear in your list. The second line defines BuildFirmware/Default8M/initramfs, but BuildFirmware/Default8M/squashfs must be defined somewhere else.

    On the other hand, if we invoke

    $(call Image/Build/Profile/MT7620a,initramfs)
    

    it will expand to

    $(call BuildFirmware/Default8M/initramfs,initramfs,mt7620a,MT7620a)
    

    then

    $(call BuildFirmware/OF/initramfs,initramfs,initramfs,mt7620a,MT7620a)
    

    and then we have to go hunting for the place where BuildFirmware/OF/initramfs is defined... Which may eventually lead back to first line.

    A3: This use of the slash is hideous, but legal.