Visit Jeremy's Blog.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 02-21-2007, 07:49 AM   #1
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, 10:36 AM   #2
Registered: Oct 2003
Location: Ohio
Distribution: Fedora 25, 26, 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.
# 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
        gunzip hello.c.gz
        mv 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 (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 back to its original name of hello.c.gz. Again we keep the timestamp of the .gz intact.


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


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

All times are GMT -5. The time now is 10:18 PM.

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