{"id":3863,"date":"2017-01-18T11:37:57","date_gmt":"2017-01-18T11:37:57","guid":{"rendered":"https:\/\/www.milesweb.com\/blog\/?p=3863"},"modified":"2026-01-10T15:34:33","modified_gmt":"2026-01-10T10:04:33","slug":"how-to-create-our-own-makefile","status":"publish","type":"post","link":"https:\/\/www.milesweb.in\/blog\/technology-hub\/how-to-create-our-own-makefile\/","title":{"rendered":"How to create our own Makefile"},"content":{"rendered":"<p>Although this blog is not especially oriented to the area of development, but there are several concepts that are convenient to know, whether in the area of systems or development. Knowledge is always useful, and although it is impossible to know everything, there are things which are advisable to know, even if it is heard or passed. One of those concepts which, in my opinion, it is useful to bear in mind, is the creation of our own Makefile. Both to create one in the future and to understand its functioning.<\/p>\n<p><a href=\"https:\/\/www.milesweb.in\/blog\/wp-content\/uploads\/2017\/01\/makefiles-linux-1.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-16768 size-full\" src=\"https:\/\/www.milesweb.in\/blog\/wp-content\/uploads\/2017\/01\/makefiles-linux-1.jpg\" alt=\"makefiles linux\" width=\"435\" height=\"294\" srcset=\"https:\/\/www.milesweb.in\/blog\/wp-content\/uploads\/2017\/01\/makefiles-linux-1.jpg 435w, https:\/\/www.milesweb.in\/blog\/wp-content\/uploads\/2017\/01\/makefiles-linux-1-300x203.jpg 300w\" sizes=\"auto, (max-width: 435px) 100vw, 435px\" \/><\/a><\/p>\n<p>For starters, it is important to know the utility of this file, but for which the best we can do is put ourselves in a hypothetical situation. Generally, when we download a compressed package that we want to install on Linux, what we do is unzip it, enter it and execute the make and make install commands. This is not because the make command installed on the computer does &#8220;magic&#8221;, but because that command takes the reference of Makefile file that is present in the folder in question, which makes a long and complicated process, is really simple to do, but &#8230; What does this file do? What if we did not have the file? The Makefile performs the compilation tasks that normally we should execute by hand, tedious tasks that should be done one by one. In addition, the lack of a Makefile also makes that in the\u00a0case of sharing the code with another person, it would have to compile every file by file; Task that can be very uncomfortable for anyone.<\/p>\n<h5>The best is to understand this with a simple example; imagine that we have these three pieces of code:<\/h5>\n<p>A file called<strong> test.h:<\/strong><\/p>\n<pre class=\"plain:false plain-toggle:false copy:false popup:false lang:default decode:true\">#ifndef H_TEST\n#define H_TEST\nvoid\u00a0 test ( void );\n#endif<\/pre>\n<p>A file called<strong> test.c:<\/strong><\/p>\n<pre class=\"plain:false plain-toggle:false copy:false popup:false lang:default decode:true \">#include &lt;stdio.h&gt;\n#include &lt;stdlib.h&gt;\nvoid\u00a0 test ( void )\n{\n\u00a0\u00a0 \u00a0printf\u00a0 ( \"Hello World \\ n \" );\n}<\/pre>\n<p>And finally a file called <strong>main.c:<\/strong><\/p>\n<pre class=\"plain:false plain-toggle:false copy:false popup:false lang:default decode:true \">#include &lt;stdio.h&gt;\n#include &lt;stdlib.h&gt;\n#include \"test.h\"\nint\u00a0 main ( )\n{\nTest ( ) ;\nreturn\u00a0 0 ;\n}<\/pre>\n<p>These files are completely separate and are currently useless, as the code cannot be executed at this time. It is necessary that we compile it to obtain from them a binary (which in many cases is considered as a program) that executes the said code. This process would be carried out as follows if we did it by hand:<\/p>\n<pre class=\"plain:false plain-toggle:false copy:false popup:false lang:default decode:true \">gcc\u00a0 -o\u00a0 test.o\u00a0 -c\u00a0 test.c\ngcc\u00a0 -o\u00a0 main.o\u00a0 -c\u00a0 main.c\ngcc\u00a0 -o\u00a0 test\u00a0 test.o main.o<\/pre>\n<p>Then we would just have to run the file as a normal program:<\/p>\n<pre class=\"plain:false plain-toggle:false copy:false popup:false lang:default decode:true\">. \/ test\nHello World<\/pre>\n<p>This process itself has been very simple\u00a0since we only had to deal with 3 files. But let&#8217;s imagine that they are 20, or 100, or 1000. And not only that, but we also want that code to be used by more People. That is not practical, but crazy as well and that is where the Makefile becomes very important. Now&#8230; How can we create one? For example: How can we create a Makefile based on the above case? The Makefile in question would look like this (It&#8217;s very important that lines starting with gcc, start with a tab stop):<\/p>\n<pre class=\"plain:false plain-toggle:false copy:false popup:false lang:default decode:true\">Test: test.o main.o\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 gcc\u00a0 -o\u00a0 test\u00a0 test.o main.o\n\nTest.o: test.c\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 gcc\u00a0 -o\u00a0 test.o\u00a0 -c\u00a0 test.c\n\nMain.o: main.c test.h\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 gcc\u00a0 -o\u00a0 main.o\u00a0 -c\u00a0 main.c<\/pre>\n<h5>What does this little section mean? Let&#8217;s analyze the lines to have a clear perception of what they represent:<\/h5>\n<ul>\n<li>For the binary <strong>test<\/strong>, we need the\u00a0<strong>test.o<\/strong> and <strong>main.o<\/strong> files and the compilation would be performed by the\u00a0command: &#8220;gcc -o test test.o main.o&#8221;.<\/li>\n<li>For the file<strong> test.o<\/strong> it is necessary to have the file <strong>test.c<\/strong>, with which the command &#8220;gcc -o test.o -c test.c&#8221; would be executed.<\/li>\n<li>For the file <strong>main.o<\/strong>, there need to be both <strong>main.c<\/strong> as <strong>test.h<\/strong>. When these conditions are fulfilled, we would execute the command: &#8220;gcc -o main.o -c main.c&#8221;.<\/li>\n<\/ul>\n<p>The Makefile that we created is perfectly functional and if we had a directory with the three files from before and the Makefile file that we created, by simply executing the make command, we would have our binary. This file is a Simple and therefore the ideal would be to understand a more complex and real file, although with what we have seen and understood its essence. Generally, a makefile includes two special &#8220;rules&#8221; called all and clean that are executed when we write &#8220;Make clean&#8221; or &#8220;Make all&#8221;. In addition, files of a certain size usually use variables similar to those used in bash, so we will enhance the previous example so that, on the one hand, there are two new rules, and on the other Side use some variables.<\/p>\n<pre class=\"plain:false plain-toggle:false copy:false popup:false lang:default decode:true\">CC = gcc\nEXEC: test\n\nall:\u00a0 $ {EXEC}\n\n$ {EXEC} : I test.o main.o\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 $ {CC}\u00a0 -o\u00a0 test\u00a0 test.o main.o\n\nTest.o: test.c\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 $ {CC}\u00a0 -o\u00a0 test.o\u00a0 -c\u00a0 test.c\n\nMain.o: main.c test.h\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 $ {CC}\u00a0 -o\u00a0 main.o\u00a0 -c\u00a0 main.c\n\nClean:\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 rm\u00a0 -rf\u00a0 * .o<\/pre>\n<p>The variables created are simply two: One to choose the command that is used for the compilation and in the\u00a0case of making a change, it is done globally (gcc) and another to choose the name that will adopt the binary. Also, there are two new &#8220;rules&#8221;, as I said before that we would add whose function would be:<\/p>\n<p><strong>all:<\/strong> Performs all necessary actions to compile the project; Usually not necessary because make already does, but sometimes it is convenient to use it to be safe.<\/p>\n<p><strong>clean:<\/strong> Cleans all .o files are generated during the compilation process.<\/p>\n<p>With this, we would already have a much more complete and realistic Makefile, being able to not only create a Makefile\u00a0but above all to understand it so that when we present one whose behavior does not convince us, we can understand and modify their behavior.<\/p>\n<p>I hope you have found it useful.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Although this blog is not especially oriented to the area of development, but there are several concepts that are convenient to know, whether in the area of systems or development. Knowledge is always useful, and although it is impossible to know everything, there are things which are advisable to know, even if it is heard&#8230; <a class=\"read-more\" href=\"https:\/\/www.milesweb.in\/blog\/technology-hub\/how-to-create-our-own-makefile\/\">Read More<\/a><\/p>\n","protected":false},"author":1027,"featured_media":3892,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[127],"tags":[],"class_list":["post-3863","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-technology-hub"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.2 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>How to create our own Makefile | Creating your own Makefile<\/title>\n<meta name=\"description\" content=\"Want to know how create your own Makefile? Here is a step by step process that can help you in its creation and its testing for the better functionality.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.milesweb.in\/blog\/technology-hub\/how-to-create-our-own-makefile\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to create our own Makefile | Creating your own Makefile\" \/>\n<meta property=\"og:description\" content=\"Want to know how create your own Makefile? Here is a step by step process that can help you in its creation and its testing for the better functionality.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.milesweb.in\/blog\/technology-hub\/how-to-create-our-own-makefile\/\" \/>\n<meta property=\"og:site_name\" content=\"Web Hosting Blogs by MilesWeb | WordPress, Cloud &amp; SEO Tips\" \/>\n<meta property=\"article:published_time\" content=\"2017-01-18T11:37:57+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-01-10T10:04:33+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.milesweb.in\/blog\/wp-content\/uploads\/2017\/01\/linux-makefile-creation.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"844\" \/>\n\t<meta property=\"og:image:height\" content=\"475\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Rajesh Jadhav\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Rajesh Jadhav\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.milesweb.in\/blog\/technology-hub\/how-to-create-our-own-makefile\/\",\"url\":\"https:\/\/www.milesweb.in\/blog\/technology-hub\/how-to-create-our-own-makefile\/\",\"name\":\"How to create our own Makefile | Creating your own Makefile\",\"isPartOf\":{\"@id\":\"https:\/\/www.milesweb.in\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.milesweb.in\/blog\/technology-hub\/how-to-create-our-own-makefile\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.milesweb.in\/blog\/technology-hub\/how-to-create-our-own-makefile\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.milesweb.in\/blog\/wp-content\/uploads\/2017\/01\/linux-makefile-creation.jpg\",\"datePublished\":\"2017-01-18T11:37:57+00:00\",\"dateModified\":\"2026-01-10T10:04:33+00:00\",\"author\":{\"@id\":\"https:\/\/www.milesweb.in\/blog\/#\/schema\/person\/f7585120183be096ff9a96f8f2aa8194\"},\"description\":\"Want to know how create your own Makefile? Here is a step by step process that can help you in its creation and its testing for the better functionality.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.milesweb.in\/blog\/technology-hub\/how-to-create-our-own-makefile\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.milesweb.in\/blog\/technology-hub\/how-to-create-our-own-makefile\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.milesweb.in\/blog\/technology-hub\/how-to-create-our-own-makefile\/#primaryimage\",\"url\":\"https:\/\/www.milesweb.in\/blog\/wp-content\/uploads\/2017\/01\/linux-makefile-creation.jpg\",\"contentUrl\":\"https:\/\/www.milesweb.in\/blog\/wp-content\/uploads\/2017\/01\/linux-makefile-creation.jpg\",\"width\":844,\"height\":475,\"caption\":\"linux makefile creation\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.milesweb.in\/blog\/technology-hub\/how-to-create-our-own-makefile\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.milesweb.in\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to create our own Makefile\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.milesweb.in\/blog\/#website\",\"url\":\"https:\/\/www.milesweb.in\/blog\/\",\"name\":\"Web Hosting Blogs by MilesWeb | WordPress, Cloud &amp; SEO Tips\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.milesweb.in\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.milesweb.in\/blog\/#\/schema\/person\/f7585120183be096ff9a96f8f2aa8194\",\"name\":\"Rajesh Jadhav\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.milesweb.in\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/www.milesweb.in\/blog\/wp-content\/uploads\/2025\/05\/rajesh-j.png\",\"contentUrl\":\"https:\/\/www.milesweb.in\/blog\/wp-content\/uploads\/2025\/05\/rajesh-j.png\",\"caption\":\"Rajesh Jadhav\"},\"description\":\"Rajesh, a content strategist with over 9 years of experience in content creation, emphasizes writing insightful, value-driven content that connects with readers. Whether it's writing blogs, press releases, web content, or social media posts, he ensures every word serves a purpose.\",\"url\":\"https:\/\/www.milesweb.in\/blog\/author\/rajesh-jadhav\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to create our own Makefile | Creating your own Makefile","description":"Want to know how create your own Makefile? Here is a step by step process that can help you in its creation and its testing for the better functionality.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.milesweb.in\/blog\/technology-hub\/how-to-create-our-own-makefile\/","og_locale":"en_US","og_type":"article","og_title":"How to create our own Makefile | Creating your own Makefile","og_description":"Want to know how create your own Makefile? Here is a step by step process that can help you in its creation and its testing for the better functionality.","og_url":"https:\/\/www.milesweb.in\/blog\/technology-hub\/how-to-create-our-own-makefile\/","og_site_name":"Web Hosting Blogs by MilesWeb | WordPress, Cloud &amp; SEO Tips","article_published_time":"2017-01-18T11:37:57+00:00","article_modified_time":"2026-01-10T10:04:33+00:00","og_image":[{"width":844,"height":475,"url":"https:\/\/www.milesweb.in\/blog\/wp-content\/uploads\/2017\/01\/linux-makefile-creation.jpg","type":"image\/jpeg"}],"author":"Rajesh Jadhav","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Rajesh Jadhav","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.milesweb.in\/blog\/technology-hub\/how-to-create-our-own-makefile\/","url":"https:\/\/www.milesweb.in\/blog\/technology-hub\/how-to-create-our-own-makefile\/","name":"How to create our own Makefile | Creating your own Makefile","isPartOf":{"@id":"https:\/\/www.milesweb.in\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.milesweb.in\/blog\/technology-hub\/how-to-create-our-own-makefile\/#primaryimage"},"image":{"@id":"https:\/\/www.milesweb.in\/blog\/technology-hub\/how-to-create-our-own-makefile\/#primaryimage"},"thumbnailUrl":"https:\/\/www.milesweb.in\/blog\/wp-content\/uploads\/2017\/01\/linux-makefile-creation.jpg","datePublished":"2017-01-18T11:37:57+00:00","dateModified":"2026-01-10T10:04:33+00:00","author":{"@id":"https:\/\/www.milesweb.in\/blog\/#\/schema\/person\/f7585120183be096ff9a96f8f2aa8194"},"description":"Want to know how create your own Makefile? Here is a step by step process that can help you in its creation and its testing for the better functionality.","breadcrumb":{"@id":"https:\/\/www.milesweb.in\/blog\/technology-hub\/how-to-create-our-own-makefile\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.milesweb.in\/blog\/technology-hub\/how-to-create-our-own-makefile\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.milesweb.in\/blog\/technology-hub\/how-to-create-our-own-makefile\/#primaryimage","url":"https:\/\/www.milesweb.in\/blog\/wp-content\/uploads\/2017\/01\/linux-makefile-creation.jpg","contentUrl":"https:\/\/www.milesweb.in\/blog\/wp-content\/uploads\/2017\/01\/linux-makefile-creation.jpg","width":844,"height":475,"caption":"linux makefile creation"},{"@type":"BreadcrumbList","@id":"https:\/\/www.milesweb.in\/blog\/technology-hub\/how-to-create-our-own-makefile\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.milesweb.in\/blog\/"},{"@type":"ListItem","position":2,"name":"How to create our own Makefile"}]},{"@type":"WebSite","@id":"https:\/\/www.milesweb.in\/blog\/#website","url":"https:\/\/www.milesweb.in\/blog\/","name":"Web Hosting Blogs by MilesWeb | WordPress, Cloud &amp; SEO Tips","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.milesweb.in\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.milesweb.in\/blog\/#\/schema\/person\/f7585120183be096ff9a96f8f2aa8194","name":"Rajesh Jadhav","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.milesweb.in\/blog\/#\/schema\/person\/image\/","url":"https:\/\/www.milesweb.in\/blog\/wp-content\/uploads\/2025\/05\/rajesh-j.png","contentUrl":"https:\/\/www.milesweb.in\/blog\/wp-content\/uploads\/2025\/05\/rajesh-j.png","caption":"Rajesh Jadhav"},"description":"Rajesh, a content strategist with over 9 years of experience in content creation, emphasizes writing insightful, value-driven content that connects with readers. Whether it's writing blogs, press releases, web content, or social media posts, he ensures every word serves a purpose.","url":"https:\/\/www.milesweb.in\/blog\/author\/rajesh-jadhav\/"}]}},"views":4999,"_links":{"self":[{"href":"https:\/\/www.milesweb.in\/blog\/wp-json\/wp\/v2\/posts\/3863","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.milesweb.in\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.milesweb.in\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.milesweb.in\/blog\/wp-json\/wp\/v2\/users\/1027"}],"replies":[{"embeddable":true,"href":"https:\/\/www.milesweb.in\/blog\/wp-json\/wp\/v2\/comments?post=3863"}],"version-history":[{"count":4,"href":"https:\/\/www.milesweb.in\/blog\/wp-json\/wp\/v2\/posts\/3863\/revisions"}],"predecessor-version":[{"id":16769,"href":"https:\/\/www.milesweb.in\/blog\/wp-json\/wp\/v2\/posts\/3863\/revisions\/16769"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.milesweb.in\/blog\/wp-json\/wp\/v2\/media\/3892"}],"wp:attachment":[{"href":"https:\/\/www.milesweb.in\/blog\/wp-json\/wp\/v2\/media?parent=3863"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.milesweb.in\/blog\/wp-json\/wp\/v2\/categories?post=3863"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.milesweb.in\/blog\/wp-json\/wp\/v2\/tags?post=3863"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}