Makefile: Simple Makefile untuk bahasa C
Revision as of 09:12, 23 January 2021 by Onnowpurbo (talk | contribs) (Created page with "Sumber: https://www.cs.colby.edu/maxwell/courses/tutorials/maketutor/ ==Buat 3 file== hellomake.c #include <hellomake.h> int main() { // call a function in another fi...")
Sumber: https://www.cs.colby.edu/maxwell/courses/tutorials/maketutor/
Buat 3 file
hellomake.c
#include <hellomake.h> int main() { // call a function in another file myPrintHelloMake(); return(0); }
hellofunc.c
#include <stdio.h> #include <hellomake.h> void myPrintHelloMake(void) { printf("Hello makefiles!\n"); return; }
hellomake.h
/* example include file */ void myPrintHelloMake(void);
Makefile 1
hellomake: hellomake.c hellofunc.c gcc -o hellomake hellomake.c hellofunc.c -I.
Makefile 2
CC=gcc CFLAGS=-I.
hellomake: hellomake.o hellofunc.o $(CC) -o hellomake hellomake.o hellofunc.o
Makefile 3
CC=gcc CFLAGS=-I. DEPS = hellomake.h
%.o: %.c $(DEPS) $(CC) -c -o $@ $< $(CFLAGS)
hellomake: hellomake.o hellofunc.o $(CC) -o hellomake hellomake.o hellofunc.o
Makefile 4
CC=gcc CFLAGS=-I. DEPS = hellomake.h OBJ = hellomake.o hellofunc.o %.o: %.c $(DEPS) $(CC) -c -o $@ $< $(CFLAGS) hellomake: $(OBJ) $(CC) -o $@ $^ $(CFLAGS)
Makefile 5
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)/*~