Makefile -> pc precedence over c


 
Thread Tools Search this Thread
Top Forums Programming Makefile -> pc precedence over c
# 1  
Old 08-13-2008
Makefile -> pc precedence over c

Hi All,

I have created a common makefile that compiles both pc and c files.

i have created the dependency between the files as

.pc.o:
-----------
.c.o:
-----------

I will be deleting the .c files created from the .pc files, once the object file is created. ( better storage maintenance)

so when i have a rule like

foo: foo.o
-----

for building foo.o the precedence always goes for .c.o, i mean the make file checks for foo.c first and builds it.

What i want is to change the precedence to .pc, i.e

when i build foo, the precedence should first go to
.pc.o rule and then to .c.o.

how can i achieve that?
# 2  
Old 08-17-2008
It means dependency that .c files are created from .pc files.

So it's bellow description you should write.

---------------
.pc.c:
---------------

Regards.
# 3  
Old 08-17-2008
hey thank you.. but i dont what that as i wud be removing the generated c files for better space maintenance.

so that option wont suit me.. so is it possible to make the target condition

.o to check .pc first and then .c??
# 4  
Old 08-17-2008
I think it's better that you write your task in Makefile.

Code:
RM=rm -f
PC2C_FILE=`find -name '*.pc' -exec echo {} \; | sed -e 's/.pc$$/.c/' `
.SUFFIXES:
.SUFFIXES: .c .o .obj .pc

all:    test.exe

test.exe:       test.o test2.o test3.o
        echo $^ > $@
.c.o:
        echo $^ > $@

.pc.c:
        echo $^ > $@

clean:
        $(RM) test.exe *.o
        make better_storage_maintenance

better_storage_maintenance:
        $(RM) $(PC2C_FILE)

ls result:
Code:
4 Makefile
0 test.pc
0 test2.c
0 test3.pc

case 1: Compile
$ make
Code:
echo test.pc > test.c
echo test.c > test.o
echo test2.c > test2.o
echo test3.pc > test3.c
echo test3.c > test3.o
echo test.o test2.o test3.o > test.exe
rm test3.c test.c

(red letter is automaticaly added. So do nothing.)

The version of make program I use:
Code:
GNU Make 3.80
Copyright (C) 2002  Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.

case 2: Better storage maintenance
$ make better_storage_maintenance
Code:
rm -f `find -name '*.pc' -exec echo {} \; | sed -e 's/.pc$/.c/' `

case 3: Cleaning
$ make clean
Code:
rm -f test.exe *.o
make better_storage_maintenance

case 4: look up .c file from .pc file
$ make test.c
Code:
echo test.pc > test.c

(You need to execute "make better_storage_maintenance" at later)

Last edited by p50p100; 08-17-2008 at 08:40 AM..
# 5  
Old 08-17-2008
For GNU make you can also simply mark .c files as .PRECIOUS: so they won't be removed automatically.
# 6  
Old 08-17-2008
I don't know details.

But, do .PRECIOUS option only keep .c file except for temp file ?

My result is it that I really execute it. (And I'm surprized!)

I am not sure that reason why it works.
# 7  
Old 08-17-2008
I'm not sure I understand the question. .PRECIOUS marks a file as one which Make should not remove even if it was created as a temporary step and not as an end goal.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

Makefile for g++

Hi All, We have moved our OS from Sun Solaris to Linux and also some of the compilers. Our old makefile used to be as below: CC=cc FLAGS=-G -KPIC -DLG_SOLARIS_OS DEFINES=-DSunOS SYSLIBS=-lc .SUFFIXES : .c .c.o : ;$(CC) -c $(FLAGS) $(DEFINES) $*.c -o $*.o ... (3 Replies)
Discussion started by: shash
3 Replies

2. UNIX for Dummies Questions & Answers

What should be precedence of using awk, sed, head and tail in UNIX?

Hi All, I am new to unix. In this forum some days back, I have read something like below: 1) Do not use perl if awk can do your work. 2) Do not use awk if sed can do your work. . . . I do not re-collect the whole thing. I think it is good to know the precedence of using these... (2 Replies)
Discussion started by: Prathmesh
2 Replies

3. Shell Programming and Scripting

Precedence in operators issue

Hello, I am trying to write a small acript to change directory to $HOME depending on the user logged in. However when i provide this command say, ABC_USER=myself cd ~${ABC_USER} i am getting the following error, ksh: ~myself: not found I know i am doing something really silly but... (4 Replies)
Discussion started by: arvindspr06
4 Replies

4. Homework & Coursework Questions

Help with Simple Multi-Level Makefile (Extremely New at Makefile)

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: Basically, the prompt is make a makefile with various sub makefiles in their respective subdirectories. All code... (1 Reply)
Discussion started by: Tatl
1 Replies

5. UNIX for Advanced & Expert Users

Makefile executing another Makefile first?

I have 2 libraries in 2 different directories that I build with Makefiles. library B depends on library A. If I modify a .cpp file in library A and run lib B's Makefile can I have B's makefile to automatically rebuild library A? I am now rebuilding A, followed by B... but I'd like B to... (0 Replies)
Discussion started by: wwuster
0 Replies

6. UNIX for Advanced & Expert Users

Makefile problem - How to run module load in a Makefile

Hi, I'm trying to run the module load command in a Makefile and i'm getting the following error: make: module: command not found Why is this? Is there any way to run this command in a Makefile? NOTE: command - module load msjava/sunjdk/1.5.0 works fine outside of the Makefile (2 Replies)
Discussion started by: hernandinho
2 Replies

7. High Performance Computing

help with makefile

I am new to creating makefiles. I have several fortran programs in a folder called as "test" and also have several subroutines in another folder (which is inside this test folder) called as libry My makefile is in the folder "test" I want to create a makefile which can access the files in... (2 Replies)
Discussion started by: explorer
2 Replies

8. Shell Programming and Scripting

setting precedence with getopts

Hi, I am re-writing a script I wrote which emulated the "rm" command, in my orginal script I had problems with precedence, I did find a way round it by creating a seperate case statements which checked the options and performed the actions accordingly, does anyone know if I can use getopts... (1 Reply)
Discussion started by: jack1981
1 Replies

9. Shell Programming and Scripting

precedence of stderr and stdout

#!/usr/bin/perl open(STDOUT, ">>$Textfile") open(STDERR, ">>$Textfile") print "program running\n"; $final = join("+", $initial,$final) #5 close (STDOUT); close (STDERR);Hi all, above is my perl code. Notice i have captured the stdout and stderr to the same textfile. my code is expected to... (1 Reply)
Discussion started by: new2ss
1 Replies

10. Programming

EOF & precedence of !=

Gurus, I am teaching myself C and have a question. I wrote a small prog that reads characters as entered at the prompt and checks the value for EOF. Unless I am 100% wrong, the value will be '1' until getchar() has anything to read in my stream. /* PROG 1 */ #include <stdio.h> ... (4 Replies)
Discussion started by: alan
4 Replies
Login or Register to Ask a Question