DEV Community

Deepanshu Udhwani
Deepanshu Udhwani

Posted on • Edited on

1

How to write the Simplest MAKE file

How to make a MAKE file easiest possible way

Make 3 files hellomake.c hellofunc.c hellomake.h

#include <hellomake.h>

int main() { // call a function in another file myPrintHelloMake();

return(0); }
Enter fullscreen mode Exit fullscreen mode

hellofunc.c

#include <stdio.h> #include <hellomake.h>

void myPrintHelloMake(void) {

printf("Hello makefiles!\n");

return; }
Enter fullscreen mode Exit fullscreen mode

hellomake.h

void myPrintHelloMake(void);
Enter fullscreen mode Exit fullscreen mode

After this make a file
vi makefile

CC=gcc CFLAGS=-I. DEPS = hellomake.h OBJ = hellomake.o hellofunc.o

%.o: %.c $(DEPS) 
    $(CC) -c -o $@ $< $(CFLAGS)

hellomake: $(OBJ) 
    $(CC) -o $@ $^ $(CFLAGS)
Enter fullscreen mode Exit fullscreen mode

Or
makefile as

IDIR =../include
CC=gcc
CFLAGS=-I$(IDIR)

ODIR=obj
LDIR =../lib

LIBS=-lm

_DEPS = hellomake.h
DEPS = $(patsubst %,$(IDIR)/%,$(_DEPS))

_OBJ = hellomake.o hellofunc.o 
OBJ = $(patsubst %,$(ODIR)/%,$(_OBJ))


$(ODIR)/%.o: %.c $(DEPS)
    $(CC) -c -o $@ $< $(CFLAGS)

hellomake: $(OBJ)
    $(CC) -o $@ $^ $(CFLAGS) $(LIBS)

.PHONY: clean

clean:
    rm -f $(ODIR)/*.o *~ core $(INCDIR)/*~
Enter fullscreen mode Exit fullscreen mode

Redis image

Short-term memory for faster
AI agents 🤖💨

AI agents struggle with latency and context switching. Redis fixes it with a fast, in-memory layer for short-term context—plus native support for vectors and semi-structured data to keep real-time workflows on track.

Start building

Top comments (2)

Collapse
 
pentacular profile image
pentacular

You should use

#include "hellomake.h"

Given that hellomake.h is not a system header. :)

It may fail otherwise on some systems.

Collapse
 
itsdeepanshu profile image
Deepanshu Udhwani

Yeah true, I mean create one file named hello.h! 😂😂😂

Dev Diairies image

User Feedback & The Pivot That Saved The Project ↪️

We’re following the journey of a dev team building on the Stellar Network as they go from hackathon idea to funded startup, testing their product in the real world and adapting as they go.

Watch full video 🎥

👋 Kindness is contagious

If this **helped, please leave a ❤️ or a friendly comment!

Okay