Makefiles and "Dynamic" Rules


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Makefiles and "Dynamic" Rules
# 1  
Old 06-27-2011
Makefiles and "Dynamic" Rules

I have a configuration file, foo.cfg, and a script, bar.sh. bar.sh generates .cc and .h files based on foo.cfg.

To exemplify, let's say it creates apple.cc, apple.h, banana.cc, banana.h, carrot.cc, carrot.h, and so on.

How do I write a Makefile that runs bar.sh if and only if foo.cfg has been modified, and then builds the resulting files? apple.cc and apple.h are guaranteed to exist, but the rest are entirely dependent on the configuration.

I wrote the following rule, which runs bar.sh if foo.cfg changes. However, I don't know how to make a second rule whose targets are apple.o, banana.o, carrot.o, ...

Code:
apple.h: foo.cfg
    bar.sh

Thanks in advance. I've spent 20 hours already reading about macros and experimenting to figure this out, but to no avail. I can't seem to just echo *.cc *.h via macros because, unless I'm doing it wrong (and I hope someone can tell me that I am!), shell statements are executed before the rules are processed, and those .cc and .h files don't exist until the first rule is processed to generate said .cc and .h files.

Miscellaneous details. I'm on Solaris. And I must use a Makefile, or be prepared to explain to my managers why there is absolutely no way that we can use a Makefile for this purpose.

Last edited by acheong87; 06-27-2011 at 11:50 AM.. Reason: Cut out unnecessary details.
# 2  
Old 06-27-2011
How is this command used to generate these files?

If you don't know what files it's going to generate at Make-time, you'd need to generate your own makefile out of the cfg file somehow.
# 3  
Old 06-27-2011
That's doable: I can't modify the script (it's part of our infrastructure) but I can easily write and call a new script that generates a Makefile. But then, how do I include this new Makefile in the main Makefile?
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. AIX

Apache 2.4 directory cannot display "Last modified" "Size" "Description"

Hi 2 all, i have had AIX 7.2 :/# /usr/IBMAHS/bin/apachectl -v Server version: Apache/2.4.12 (Unix) Server built: May 25 2015 04:58:27 :/#:/# /usr/IBMAHS/bin/apachectl -M Loaded Modules: core_module (static) so_module (static) http_module (static) mpm_worker_module (static) ... (3 Replies)
Discussion started by: penchev
3 Replies

2. Shell Programming and Scripting

Bash script - Print an ascii file using specific font "Latin Modern Mono 12" "regular" "9"

Hello. System : opensuse leap 42.3 I have a bash script that build a text file. I would like the last command doing : print_cmd -o page-left=43 -o page-right=22 -o page-top=28 -o page-bottom=43 -o font=LatinModernMono12:regular:9 some_file.txt where : print_cmd ::= some printing... (1 Reply)
Discussion started by: jcdole
1 Replies

3. UNIX for Dummies Questions & Answers

Using "mailx" command to read "to" and "cc" email addreses from input file

How to use "mailx" command to do e-mail reading the input file containing email address, where column 1 has name and column 2 containing “To” e-mail address and column 3 contains “cc” e-mail address to include with same email. Sample input file, email.txt Below is an sample code where... (2 Replies)
Discussion started by: asjaiswal
2 Replies

4. Shell Programming and Scripting

Dynamic variables and our friend "if"

Hi guys, Sorry if it is somewhere in the forum, I've checked for an hour or so with my google friend and can't figure this one out. Not counting the 2 hours I spent yelling at it. Welcome to BASH + AIX $LSLV -l $LV | $GREP -v $LV | $GREP -v "IN BAND" | $AWK '{print $1}' | while read PV;... (1 Reply)
Discussion started by: plmachiavel
1 Replies

5. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

6. Red Hat

"Dynamic" Group Permissions?

Hi all, Apologies if the answer is out there somewhere, I did have a search about..... In my environment of a RHEL 4 machine and users all listed out in LDAP (say, userA in a deptZ primary group; userB in same deptZ primary group, plus deptY secondary group), I am trying to find a mechanism... (1 Reply)
Discussion started by: en7smb
1 Replies

7. UNIX for Dummies Questions & Answers

Explain the line "mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'`"

Hi Friends, Can any of you explain me about the below line of code? mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'` Im not able to understand, what exactly it is doing :confused: Any help would be useful for me. Lokesha (4 Replies)
Discussion started by: Lokesha
4 Replies

8. Shell Programming and Scripting

passing a list of dynamic names to a "PS" command in shell script?

Hi, I am new to shell script. This is my first post .I have written a small script which returns list of names starts with "ram" in /etc/passwd .Here is that:- #!/bin/ksh NAME_LIST="name_list.txt" cat /dev/null > $NAME_LIST evalcmd="cat /etc/passwd | grep "^ram?*" | cut -d: -f1" eval... (3 Replies)
Discussion started by: sachin.tendulka
3 Replies

9. UNIX for Advanced & Expert Users

pf not working properly even with only "pass in all" and "pass out all" rules

i have two rules in my pf.conf file, "pass in all" and "pass out all" i was having issues with getting pf working to begin with, so i went with starting from nothing and working on up. i have an ultrasparc ultra1 200e, with an added 4-port fast ethernet sbus card, running "3.4 GENERIC#85... (4 Replies)
Discussion started by: xyyz
4 Replies
Login or Register to Ask a Question