LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-05-2005, 04:48 AM   #1
alix123
Member
 
Registered: Nov 2004
Posts: 63

Rep: Reputation: 15
Linux shell command for makefile.in to create a text file and write to it


Iam writing a makefile.in for my prgram .My make file is complete and is building the program well but
now i have to write a shell command in the above make file so that the shell command can extract the current working directory and create a file in "tmp" directroy and write the current directory to the text file.
iam using C as my development langauage.
i have never used and shell command can somebody help me in that

Last edited by alix123; 01-05-2005 at 04:51 AM.
 
Old 01-05-2005, 05:19 AM   #2
rjlee
Senior Member
 
Registered: Jul 2004
Distribution: Ubuntu 7.04
Posts: 1,994

Rep: Reputation: 76
To indicate a BASH script, the first line should be
Code:
#!/bin/bash
First, you need to create the tmp directory. I assume that you want this created under the current directory; in which case you just do:
Code:
mkdir tmp
The current working directory is held in the CWD environment variable; you just need to output this to a file:
Code:
echo $CWD > tmp/cwd.txt
Make sure to set the executable bit on the script or it won't work.
 
Old 01-05-2005, 05:33 AM   #3
alix123
Member
 
Registered: Nov 2004
Posts: 63

Original Poster
Rep: Reputation: 15
How will i specify the commands in Makefile.in

how will i speicfy this commad in Makefile.in

echo $CWD > tmp/cwd.txt or can i use

pwd > cat >/tmp/tc.txt


but how will i specify both of the commnads in a makefile.in

should i write as it is as mentioned above
 
Old 01-05-2005, 05:47 AM   #4
rjlee
Senior Member
 
Registered: Jul 2004
Distribution: Ubuntu 7.04
Posts: 1,994

Rep: Reputation: 76
Code:
pwd > cat > /tmp/tc.txt
will work, although it relies on the external pwd command (which should always be present in theory). The > cat is irrelevant; cat just takes its input(s) and outputs them, so this command is the same as
Code:
pwd > /tmp/tc.txt
Note that /tmp is the tmp subdirectory of the / top-level directory. It's better to use $TMP to refer to this location, because it may concevably differ across platforms.

You need to make a rule to perform the command:

Code:
gettmp : prerequisites
        mkdir tmp && echo $CWD > tmp/cwd.txt
This will run the commands without the need for an external script; the && means to run the echo command only if the mkdir command succeeds.

At least, that's how you'd do it in a Makefile. You'll need to look at the autoconf documentation for more details.
 
Old 01-05-2005, 06:00 AM   #5
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,516

Rep: Reputation: 240Reputation: 240Reputation: 240
how about something like:

Code:
tmp:
      mkdir $@

tmp/pwd.txt: tmp
        pwd > $@
 
Old 01-06-2005, 02:48 AM   #6
alix123
Member
 
Registered: Nov 2004
Posts: 63

Original Poster
Rep: Reputation: 15
will this code work in Makefile.in

will this code work in makefile.in

iam new to makefiles also
if I write code as it in my makefile.in will it work
 
Old 01-06-2005, 03:51 AM   #7
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,516

Rep: Reputation: 240Reputation: 240Reputation: 240
should do.
but this is a very simple example.
it won't re-make the file each time.
but i assume the pwd won't change much!
I suppose properly we should use variables:
Code:
TMPDIR=./tmp
PWDFILE=${TMPDIR}/pwd.txt

${PWDFILE}: ${TMPDIR}
        pwd > $@

${TMPDIR}:
        mkdir $@
 
Old 01-07-2005, 04:38 AM   #8
alix123
Member
 
Registered: Nov 2004
Posts: 63

Original Poster
Rep: Reputation: 15
as such it will not change

as such it will not change but everytime .when the build goes on different machine again you have to do

./configure
make
make install

there the command should write into the file and tmp directroy

I where is the tmp directory and pwd.txt created i am not able to find that

the code given will go in tmp directory of the system or it will create the directroy there only i want it should go tmp directory of the system because i know the path and file name in this directory and during the run time my program will read the file created in the tmp directroy of the system

i will be very thankfull if you can tell me that
 
Old 01-07-2005, 08:18 AM   #9
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,516

Rep: Reputation: 240Reputation: 240Reputation: 240
as it stands, in the same directory as the Makefile probably.
to change it to the absolute /tmp
directory just make it:

TMPDIR=/tmp

(that's the beauty of using variables!)
 
  


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
create text file from terminal acidjuice Linux - Software 8 09-03-2010 03:46 AM
How to find and change a specific text in a text file by using shell script Bassam Programming 1 07-18-2005 07:15 PM
How to write makefile to create shared library in 2.6 kernel yogeshwar_s Linux - Software 1 12-29-2004 12:39 AM
Create text file with a script zael Programming 3 06-02-2004 03:27 AM
"how do I extract a number from a text file using shell command?" sdandeker Linux - Networking 3 02-12-2004 08:54 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:36 AM.

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
Open Source Consulting | Domain Registration