Difference between revisions of "Makefile"

From Linuxintro
imported>ThorstenStaerk
Line 1: Line 1:
 +
Here's an example how to use a Makefile.
 +
 +
= C file =
 +
We are using a source file written in C called main.c. Here is how we create it:
 
<pre>
 
<pre>
 
cat >main.c <<EOF
 
cat >main.c <<EOF
Line 8: Line 12:
 
}
 
}
 
EOF
 
EOF
 +
</pre>
 +
 +
= Makefile =
 +
Now we create the Makefile:
 +
<pre>
 
cat >Makefile <<EOF
 
cat >Makefile <<EOF
 
all:hello
 
all:hello

Revision as of 15:43, 16 November 2013

Here's an example how to use a Makefile.

C file

We are using a source file written in C called main.c. Here is how we create it:

cat >main.c <<EOF
#include <stdio.h>

int main()
{
  printf("hello world");
}
EOF

Makefile

Now we create the Makefile:

cat >Makefile <<EOF
all:hello

hello: main.c
        gcc main.c -o hello

install: hello
        cp hello /usr/local/bin
EOF
sed -i "s/        /\t/g" Makefile 

See also


This article is a stub and needs improvement. You can help here :)