MAKE and its macros and variables


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers MAKE and its macros and variables
# 1  
Old 04-18-2008
Question MAKE and its macros and variables

I want to build a Makefile that simply takes a template file and modifies it (sed or perl, probably) before installing the result in the right place - my problem is creating the variable for substitution...

So I have

SYSTEM = SYS1 SYS2

SYS1_CHANNELS = CHANNEL1 CHANNEL2 CHANNEL4
SYS2_CHANNELS = CHANNEL3 CHANNEL5

SYS1_FTP_HOST = server1
SYS2_FTP_HOST = server2


I want to build a rule that loops through the $(SYSTEM) values and substitutes in the CHANNELS and FTP_HOST values before modding the template.

I already have...
for system in $(SYSTEM) ;\
do \
ftp_host="$$system"_FTP_HOST ;\
done;

ftp_host is correctly created (SYS1_FTP_HOST) but how do I then use the macro value associated with ftp_host ie 'server1'. It'll get more complicated still looping through the CHANNELS!

Any ideas appreciated.
# 2  
Old 04-19-2008
I don't think you can mix shell and make like that. You can use Make's own constructs for referring to Make's own variables, but by the time the shell actually parses and executes the for loop, things are handled by the shell, and there's no way for that to refer back to Make's internal variables.

Some makes will allow you to export variables to the shell, but this is still going to be rather hard to read, understand, and debug.

Or, you could invoke Make recursively with yet more variables assigned to tell Make which actual variables to use on this invocation. Still more complexity.

Code:
target:
	for system in $(SYSTEM); do $(MAKE) SYS=$$system subtarget; done
subtarget:
	ftp_host=$($(SYS)_FTP_HOST); ... etc

For GNU Make, I could suggest some alternate approaches, but for standard make, I'd just break down and code the whole thing as a shell script, or copy+paste for each SYSTEM.

PS. Please use code tags for legibility.

Last edited by era; 04-19-2008 at 11:30 AM.. Reason: Post brief example; point out [CODE] tags
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Macros how-to?

Hi, all I just came to new system with RH, and it has alot of macros I was told to use, but I can't find how to open it for display or for edit, can you help me please, is it all about make/makefile? let say I have macro <trx> like this, that does a lot of things: >$ trx ... creating new... (1 Reply)
Discussion started by: trento17
1 Replies

2. UNIX for Advanced & Expert Users

Script to make a table from Named Variables.

I need a shell script to make a table from Named Variables Input File(Can have multiple lines): a=1,b=2,d=4,e=5 a=11,b=12,c=13,d=14 Output file: a,b,c,d,e 1,2,,4,5 11,12,13,14, Thanks in advance (7 Replies)
Discussion started by: shariramani
7 Replies

3. UNIX for Dummies Questions & Answers

I need to make a constant variables to the root

Hello every body, I need to make a constant variable to the root such as #PS1="I am Amer" and so on. I know if i am a user,I can make it fixed from #vi .profile HOW to make it fixed for the root? Thanks in advance BR Ahmed Amer Cairo,Egypt (7 Replies)
Discussion started by: ahmedamer12
7 Replies

4. Programming

help with atoi and macros in C

I have a PORT_NUM macro (10 digits long number) in a server file, if i do htons(PORT_NUM) i get warning: this decimal constant is unsigned only in ISO C90 warning: large integer implicitly truncated to unsigned type whats wrong with this? (2 Replies)
Discussion started by: omega666
2 Replies

5. UNIX for Advanced & Expert Users

How to make the variables of one script available for the other scripts?

Hello Everyone, I want to know how can we make the variables of one script available for the other script? for example i have three scripts variable_availability.sh,first.sh,second.sh and a file containing variables called common ---------------------------------- cat variable_availability.sh... (2 Replies)
Discussion started by: Kesavan
2 Replies

6. Linux

What are the meaning of these macros..

Masters, I am trying to learn the serial mouse driver for linux kernel. On the kernel source tree I find out these macros and I am unable to find out the meaning of these macros. Please anyone help me to understand these. These macros are defined in linux/serio.h... (2 Replies)
Discussion started by: iamjayanth
2 Replies

7. Shell Programming and Scripting

How to make variables in script function local?

Is it possible to make function variables local? I mean for example, I have a script variable 'name' and in function I have declared variable 'name' I need to have script's 'name' have the same value as it was before calling the function with the same declaration. The way to preserve a... (5 Replies)
Discussion started by: alex_5161
5 Replies

8. Shell Programming and Scripting

Expect Terminal Macros

Hey people! I just started out working at an ISP as tech support and thought that I should ease the work load by scripting some small macros. I create different commands with Alias through .bashrc which are all directed to the same script file. Here I planned on using Expect to run different... (0 Replies)
Discussion started by: GhettoFish
0 Replies

9. UNIX for Dummies Questions & Answers

saving macros for VIM

The question is , as the topic says, how does one save macros for VIM in the .vimrc. I had a look on web and it gave all this ****** about how to build turing machines in vim code or something but i just want to store a macro to like : if(){ } I know how to do it IN vim but .vimrc??????!?!?!... (3 Replies)
Discussion started by: yngwie
3 Replies

10. UNIX for Dummies Questions & Answers

troff macros

Hi, I'm going write a small handbook. The typesetting software I'm going to use is troff. There are -ms -me -mm macros for troff. Which one is the most suitable? Thanks! -Tony (2 Replies)
Discussion started by: tonyt
2 Replies
Login or Register to Ask a Question