Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I know this is a silly question, but since I am trying so hard to learn linux by myself, I need some help from you fellows.

I found this task on the internet and I am trying to solve it but I don't understand exactly how can I use makefiles in linux and how can I create them.

Let's suppose my print working directory is /home/george/Documents

I want to create a makefile which does the following:

  1. Displays a message as follows "hello work, today is Sun". Sun comes from Sunday. So I must use date command in this make file to display just first three letters.
  2. compress /etc/hosts in /tmp using gzip (probably here should be something like

    gzip -c SOURCE DESTINATION # ?? 
    

Cheers

share|improve this question
    
Makefiles are there to selectively build outdated object files from source files, in a software development activity. It has nothing to do to what you would do. –  enzotib Aug 17 '13 at 14:21
add comment

2 Answers 2

up vote 3 down vote accepted

to answer your question I cant give you a one line / paragraph answer because it deals with every thing.Read the first link it have everything you need with examples too.

Good tutorial that can explain everything about make

share|improve this answer
add comment

A Makefile is used as a "map" for C programs compilation. They work with the make utility, an describe how a program has to be compiled/linked in order to work correctly once turned into a executable file. For global UNIX/shell tasks, you're looking for shell scripts, not makefiles :)

See http://en.wikipedia.org/wiki/Make_(software)#Makefiles for more information about makefiles, and http://en.wikipedia.org/wiki/Shell_script to discover shell scripts.

A basic shell script for what you're trying to do could be :

#!/bin/bash
echo "Hello world, today is $(date +%a)"
gzip -c SOURCE DESTINATION

Store this in a file, and execute it using your shell prompt (bash myscript.sh, sh myscript.sh, ...). You can also make the script executable using :

chmod +x myscript.sh

And then execute it with your default interpretor with :

./myscript.sh
share|improve this answer
    
I am trying to create a makefile which does this not a shell script. –  Adrian George Aug 17 '13 at 14:27
    
Then you have to develop a C program which does this, and compile it using a Makefile, if you want. Makefiles do not execute Linux tasks, they guide C programs compilation, it is a completely different thing. –  John WH Smith Aug 17 '13 at 14:30
1  
@JohnWHSmith There is nothing special about compiling C programs. Makefiles can be used to perform a variety of tasks. (With that said, many tasks are poorly suited for the use of makefiles.) –  Eliah Kagan Aug 17 '13 at 15:06
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.