GithubHelp home page GithubHelp logo

hereforlearning / makefile-tutorial Goto Github PK

View Code? Open in Web Editor NEW

This project forked from lifeissweetgood/makefile-tutorial

0.0 0.0 0.0 144 KB

A tutorial on learning Makefiles

C 78.07% C++ 21.93%

makefile-tutorial's Introduction

makefile-tutorial

A tutorial on Makefiles (Based on tutorial written here)

Let's Demystify Makefiles!

This tutorial explains what Makefiles are, how they are useful and shows how to write your own from scratch. To see how Makefiles work "in action," clone the source code on the master branch and compile the simple C project. There are different versions of the same Makefile with varying degrees of complexity. To compile each, run the following commands:

make build-v1
make

To run the simple C program, do:

./hellomake

To run a different version of the Makefile, do:

make clean
make build-v2
make

Substitute build-v2 with either build-v1, build-v3 or build-v4 to run make with each of the other corresponding Makefile versions.

What is a makefile?

A makefile is a special file that lists a set of rules for compiling a project. These rules include targets, which can be an action make needs to take (eg. "clean" or "build") or the files/objects make will need to build (eg. .o files or an executable), and the commands that need to be run in order to build that target. When you call the program make, it runs through each of these targets in your Makefile and executes them.

Rules usually take the form of:

target: dependencies
       steps to build target with dependencies

What is the syntax of a Makefile?

Makefiles incorporate bash scripting with its own special syntax to indicate targets and variables.

You can run bash commands like

all:
    echo Hello

Makefiles also have special macros for indicating variables:

CC --> Tells make which C compiler to use

CFLAGS --> Specifies command line flags to pass to compiler

DEPS --> File dependencies

You can also introduce your own macros like:

TARGETS --> Indicates a list of targets to build

Resources

The ultimate make and Makefile resource: GNU make docs

The tutorial upon which this one is based: cs.colby.edu

makefile-tutorial's People

Contributors

lifeissweetgood avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.