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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
01-05-2005, 04:48 AM
|
#1
|
Member
Registered: Nov 2004
Posts: 63
Rep:
|
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.
|
|
|
01-05-2005, 05:19 AM
|
#2
|
Senior Member
Registered: Jul 2004
Distribution: Ubuntu 7.04
Posts: 1,994
Rep:
|
To indicate a BASH script, the first line should be 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: 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.
|
|
|
01-05-2005, 05:33 AM
|
#3
|
Member
Registered: Nov 2004
Posts: 63
Original Poster
Rep:
|
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
|
|
|
01-05-2005, 05:47 AM
|
#4
|
Senior Member
Registered: Jul 2004
Distribution: Ubuntu 7.04
Posts: 1,994
Rep:
|
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 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.
|
|
|
01-05-2005, 06:00 AM
|
#5
|
Senior Member
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,516
|
how about something like:
Code:
tmp:
mkdir $@
tmp/pwd.txt: tmp
pwd > $@
|
|
|
01-06-2005, 02:48 AM
|
#6
|
Member
Registered: Nov 2004
Posts: 63
Original Poster
Rep:
|
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
|
|
|
01-06-2005, 03:51 AM
|
#7
|
Senior Member
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,516
|
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 $@
|
|
|
01-07-2005, 04:38 AM
|
#8
|
Member
Registered: Nov 2004
Posts: 63
Original Poster
Rep:
|
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
|
|
|
01-07-2005, 08:18 AM
|
#9
|
Senior Member
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,516
|
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!)
|
|
|
All times are GMT -5. The time now is 06:36 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|