Difference between revisions of "Makefile"
From Linuxintro
imported>ThorstenStaerk (Created page with "<pre> duffman:~/hello # cat main.c #include <stdio.h> int main() { printf("hello world"); } duffman:~/hello # cat Makefile all:hello hello: main.c gcc main.c -o hel...") |
imported>ThorstenStaerk m (Reverted edits by 82.229.22.166 (talk) to last revision by 95.113.217.92) |
||
(10 intermediate revisions by 3 users not shown) | |||
Line 1: | Line 1: | ||
+ | Makefiles help you to [[build]] a program from source without you having to issue every compiler call. They are interpreted by the [[command]] [[make]] and manage [[dependencies]] meaning they online issue the compile steps needed to save you time. Here is 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 | |
#include <stdio.h> | #include <stdio.h> | ||
Line 7: | Line 11: | ||
printf("hello world"); | printf("hello world"); | ||
} | } | ||
− | + | EOF | |
+ | </pre> | ||
+ | |||
+ | = Makefile = | ||
+ | Now we create the Makefile: | ||
+ | <pre> | ||
+ | cat >Makefile <<EOF | ||
all:hello | all:hello | ||
hello: main.c | hello: main.c | ||
gcc main.c -o hello | gcc main.c -o hello | ||
+ | |||
+ | install: hello | ||
+ | cp hello /usr/local/bin | ||
+ | EOF | ||
+ | sed -i "s/ /\t/g" Makefile | ||
</pre> | </pre> | ||
+ | |||
+ | = Use it = | ||
+ | To use the Makefile to [[build]] the executable binary file hello from the C source main.c, just call the [[command]] [[make]] and it will look like this: | ||
+ | <abbr title="Computer prompt">tweedleburg:~/tuturial # </abbr><abbr title="Your input">make</abbr> | ||
+ | <abbr title="Computer output">gcc main.c -o hello</abbr> | ||
= See also = | = See also = | ||
* [[SPEC file]] | * [[SPEC file]] | ||
− | + | ||
+ | {{stub}} |
Latest revision as of 12:06, 25 January 2014
Makefiles help you to build a program from source without you having to issue every compiler call. They are interpreted by the command make and manage dependencies meaning they online issue the compile steps needed to save you time. Here is an example how to use a Makefile.
Contents
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
Use it
To use the Makefile to build the executable binary file hello from the C source main.c, just call the command make and it will look like this:
tweedleburg:~/tuturial # make gcc main.c -o hello
See also
This article is a stub and needs improvement. You can help here :)