LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 12-04-2009, 03:18 AM   #1
mayankmehta83
LQ Newbie
 
Registered: Dec 2009
Posts: 7

Rep: Reputation: 0
Question 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.
 
Old 12-04-2009, 07:56 PM   #2
lupusarcanus
Senior Member
 
Registered: Mar 2009
Location: USA
Distribution: Arch
Posts: 1,022
Blog Entries: 19

Rep: Reputation: 146Reputation: 146
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.

Last edited by lupusarcanus; 12-04-2009 at 08:00 PM.
 
0 members found this post helpful.
Old 12-05-2009, 02:06 AM   #3
Valery Reznic
ELF Statifier author
 
Registered: Oct 2007
Posts: 676

Rep: Reputation: 137Reputation: 137
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
 
Old 12-06-2009, 11:57 PM   #4
mayankmehta83
LQ Newbie
 
Registered: Dec 2009
Posts: 7

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by Valery Reznic View Post
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 ??

Last edited by mayankmehta83; 12-07-2009 at 12:07 AM. Reason: missed ")"...
 
Old 12-07-2009, 12:45 AM   #5
Valery Reznic
ELF Statifier author
 
Registered: Oct 2007
Posts: 676

Rep: Reputation: 137Reputation: 137
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
 
Old 12-07-2009, 01:08 AM   #6
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
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

Last edited by paulsm4; 12-07-2009 at 01:12 AM.
 
Old 12-07-2009, 05:33 AM   #7
Valery Reznic
ELF Statifier author
 
Registered: Oct 2007
Posts: 676

Rep: Reputation: 137Reputation: 137
Quote:
Originally Posted by paulsm4 View Post
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Makefile: including a subdirectory filled with headers and srcs chris24300 Linux - Newbie 7 09-11-2009 02:00 PM
Need to extract name of C variable from C declaration. judgex Programming 3 09-22-2007 01:46 PM
Problem with variable in inline assembler DavidW567 Programming 0 05-17-2005 12:21 PM
How to write Makefile in 2.6 for including header files in another dir ? ashbalu Programming 0 10-19-2004 04:45 PM
Difference between including a header file and 'class' declaration in C++ scoTtkIm Programming 1 09-09-2004 05:23 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 01:49 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration