LinuxQuestions.org
Review your favorite Linux distribution.
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 02-21-2007, 08:49 AM   #1
saintt
LQ Newbie
 
Registered: Aug 2001
Location: London
Distribution: SuSE 7.1/7.3
Posts: 25

Rep: Reputation: 15
Question Help with makefile


Hello, I am having trouble with a makefile command that I would like to perform.

At the very start of a compilation, I would like my makefile to check for a file.gz and if it exists, to gunzip it, before continuing with the compile. If it doesn't exist, then it should carry on compiling as normal.

What commands can I use to achieve this? I can't find the answer anywhere!
 
Old 02-21-2007, 11:36 AM   #2
wmakowski
Member
 
Registered: Oct 2003
Location: Ohio
Distribution: Fedora 23, 24, RHL 5.2
Posts: 560

Rep: Reputation: 56
One way would be to build a script to check for the .gz and uncompress it if present, and then run make. However, I'm thinking you want to just use make.

As you may know make is very much keyed to the timestamp of files when determining what it needs to do. So by making a dependency on a file that is contained in the .gz and keeping the .gz around after gunzip we can setup a solution. I'm guessing that the .gz will contain source code. Here is what I came up with.
Code:
#
# Makefile with a dependency on a .gz file
#

CC = gcc

hello: hello.c
        ${CC} -o ${@:.c=} $@.c 

hello.c: hello.c.gz
        cp -a hello.c.gz hello.c.kz
        gunzip hello.c.gz
        mv hello.c.kz hello.c.gz
The first target is hello and it has a dependency or prerequisite of hello.c. The second target of hello.c has a prerequisite of hello.c.gz. The commands will run only if the timestamp of hello.c.gz is > hello.c or hello.c does not exist. For this to work hello.c must be in the .gz file.

The first command, cp -a copies hello.c.gz to hello.c.kz (my notation, k for keep). The -a (archive) option will keep our timestamp intact. We have to make a copy because there isn't an option that I know of on gunzip to keep around the .gz file after unzipping. The -c option will keep the file, but sends the output to stdout. The second step is to unzip our file. The last step is to mv hello.c.kz back to its original name of hello.c.gz. Again we keep the timestamp of the .gz intact.

Bill

Last edited by wmakowski; 02-21-2007 at 11:40 AM.
 
  


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
automake, makefile, makefile.in and makefile.am Fond_of_Opensource Linux - Newbie 1 09-12-2006 09:35 PM
what is the meaning of Makefile,Makefile.am,Makefile.in cynthia_thomas Linux - General 3 12-08-2005 06:00 AM
How to modify makefile.in or makefile.am QiangWan Linux - Newbie 1 05-17-2005 12:07 PM
how to get (makefile -f makefile )output into the textview widget in Pygtk sailu_mvn Programming 3 02-28-2005 04:57 AM
generate Makefile from Makefile.in without calling ./configure ? chris78 Programming 2 05-02-2004 01:23 PM


All times are GMT -5. The time now is 04:24 PM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration