LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (http://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   how to give inline comment at variable declaration in Makefile w/o including space..? (http://www.linuxquestions.org/questions/linux-newbie-8/how-to-give-inline-comment-at-variable-declaration-in-makefile-w-o-including-space-773395/)

mayankmehta83 12-04-2009 02:18 AM

how to give inline comment at variable declaration in Makefile w/o including space..?
 
Makefile -->
VAR1 = first # comment 1
VAR2 = first# comment 2
VAR3 = $(VAR1)_last
VAR4 = $(VAR2)_last
default:
@echo $(VAR3)
@echo $(VAR4)

output (unexpected) :( -->
first _last
first_last

output (expected) :) -->
first_last
first_last

Thanks in advance.

lupusarcanus 12-04-2009 06:56 PM

VAR1 = first # comment 1 <--------> VAR1 = first# comment 1
VAR2 = first# comment 2
...
I know nothing about this subject.
But please take note that in VAR1, you have a space before the #.
In VAR2, this space is not present.

Sorry if I wasted your time. Just trying to help.

Valery Reznic 12-05-2009 01:06 AM

You can use strip function. It will guard not just against (visible) spaces before comment, but also against invisible spaces before EOL

Code:

VAR1 = first        # comment 1
VAR2 = first# comment 2
VAR3 = $(strip($(VAR1))_last
VAR4 = $(strip($(VAR2))_last


mayankmehta83 12-06-2009 10:57 PM

Quote:

Originally Posted by Valery Reznic (Post 3780567)
You can use strip function. It will guard not just against (visible) spaces before comment, but also against invisible spaces before EOL

Code:

VAR1 = first        # comment 1
VAR2 = first# comment 2
VAR3 = $(strip($(VAR1))_last
VAR4 = $(strip($(VAR2))_last


Makefile -->
VAR1 = first # comment 1
VAR2 = first# comment 2
VAR3 = $(strip($(VAR1)))_last
VAR4 = $(strip($(VAR2)))_last

default:
@echo $(VAR3)
@echo $(VAR4)

Output :( -->
_last
_last

Version -->
GNU Make 3.80

Can you look again if usage is correct ??

Valery Reznic 12-06-2009 11:45 PM

Ooops

Instead of

Code:

VAR1 = first    # comment 1
VAR2 = first# comment 2
VAR3 = $(strip($(VAR1)))_last
VAR4 = $(strip($(VAR2)))_last

Should be
Code:

VAR1 = first    # comment 1
VAR2 = first# comment 2
VAR3 = $(strip $(VAR1)))_last
VAR4 = $(strip $(VAR2)))_last


paulsm4 12-07-2009 12:08 AM

Very simply:
Code:

VAR1 = first # correct - valid comment
VAR2 = second# Might work on some platforms - but not necessarily portable
VAR3 = $(VAR1)_last  # OK: will always work
VAR4 = $(VAR2)_last  # Might work, might not work
default:
        @echo $(VAR3)
        @echo $(VAR4)

For example, it works fine with MSVS "nmake":
Quote:

C:\temp>nmake

Microsoft (R) Program Maintenance Utility Version 6.00.8168.0
Copyright (C) Microsoft Corp 1988-1998. All rights reserved.

first_last
second_last
But your mileage may vary from platform to platform.

That's even MORE true of "special" (and completely non-standard) functions like "strip()".

Unless you're very, very sure you really WANT to render your makefile non-portable, you should use standard "make" syntax whenever/wherever possible.

IMHO .. PSM

Valery Reznic 12-07-2009 04:33 AM

Quote:

Originally Posted by paulsm4 (Post 3782322)
Very simply:
Code:

VAR1 = first # correct - valid comment
VAR2 = second# Might work on some platforms - but not necessarily portable
VAR3 = $(VAR1)_last  # OK: will always work
VAR4 = $(VAR2)_last  # Might work, might not work
default:
        @echo $(VAR3)
        @echo $(VAR4)

For example, it works fine with MSVS "nmake":


But your mileage may vary from platform to platform.

That's even MORE true of "special" (and completely non-standard) functions like "strip()".

Unless you're very, very sure you really WANT to render your makefile non-portable, you should use standard "make" syntax whenever/wherever possible.

IMHO .. PSM

Yes, there a re a lot of make flavors around (the most strange one IMO is BSD's)

Trying to be portable have its cost.
Ages ago I saw advice: "Don't write portable Makefile, use portable make instead". i.e gmake.


All times are GMT -5. The time now is 07:43 AM.