Laravel Makefiles
Author: Emad Zaamout
Sunday, Oct 24, 2022
Table of Contents
- Introduction
- What is a Makefile and how does it work?
- Installation
- Setting up project
- Create a Makefile
- Makefile PHONY & Creating targets
Introduction
Welcome back,
In this course, were going to learn how to build Makefiles.
A common problem you will always face when working on any project, is how to build and work with your project. By using Makefiles, you can forever change how you build your projects.
Stop wasting time running your commands manually. Its not efficient. Today you might remember all the commands you need to build your project. Few months down the road you will forget all of them.
For this course, we will be using docker. If you’re not using Docker, you can still follow along. The important part is for you to know how to create make commands.
If your completely new to Docker, I highly recommend you watch my other videos relating to building docker for Laravel.
What is a Makefile and how does it work?
Makefiles provide a simply way to organize code building processes.
For example, if you’re using docker, and you have all your containers up and running, then what would you do, if you wanted to delete all your containers and volumes, and recreate everything?
You would have to manually run the following commands:
# Stop Containers
docker compose -f docker-compose.yml down
# Delete Containers
docker rm -vf php
docker rm -vf node
docker rm -vf database
# Delete Volumes
docker volume rm laravel-blog_db-vol
A Makefile would make it so instead of you running each docker command manually, you run a single make command instead, that will do all that for you. For example: make destroy
The problem with running commands manually is it can be time consuming. It also opens room for errors. And anyone can easily forget or not know which command to run.
The idea of Makefiles is to pretty much to centralized and contain all your build commands.
Installation
Before you attempt to install make, make sure that you don’t already have it installed.
Open your terminal and run the following command: make
If make is installed, you should see this error:
make: *** No targets specified and no makefile found. Stop.
If your on Mac, you can use brew to install make.
brew install make
If your using ubuntu or linux you can run
sudo apt-get install build-essential
Setting up project
Inside your WSL, create a new folder for our project. Call is laravel-blog. Go ahead and pull our blog implementation project from github:
https://github.com/emad-zaamout/laravel-9-complete-course-blog-implementationFor this project, I already provided you with all the docker files and builds that you need in order to run the project. For this course, we will create a standard Makefile template that we can use for all our future projects.
Create a Makefile
Inside your project root directory, create a new file, and name it Makefile. Now in your terminal, if you run `make` you should see the following error:
make: *** No targets. Stop.
In Makefiles terminology, a target is a command. This error says there are no targets inside your makefile. By default, when you run the make command, Makefiles will always execute your first defined target.
Makefile PHONY & Creating targets
https://github.com/emad-zaamout/laravel-makefile-template/blob/master/MakefileOther Posts
GET YOUR FREE ESTIMATE
CONTACT US TODAY FOR YOUR FREE CONSULTATION!
Contact us today to discuss your goals and we will create a simple roadmap to get you there. We look forward to speaking with you!
Main Office
Phone: 1 587-834-6567
Email: support@ahtcloud.com
32 Westwinds Crescent NE #130
Calgary, AB T3J 5L3, CA
Products
TMS
Cloud Based Transportation Management System
Hours Of Operation
Monday | 8:00 am - 5:00 pm |
---|---|
Tuesday | 8:00 am - 5:00 pm |
Wednesday | 8:00 am - 5:00 pm |
Thursday | 8:00 am - 5:00 pm |
Friday | 8:00 am - 5:00 pm |
Saturday | Closed |
Sunday | Closed |