Skip to content

Instantly share code, notes, and snippets.

@Jammyjamjamman
Last active December 10, 2022 07:29
Show Gist options
  • Save Jammyjamjamman/9d7097932b391733df540fd8c51ff7bd to your computer and use it in GitHub Desktop.
Save Jammyjamjamman/9d7097932b391733df540fd8c51ff7bd to your computer and use it in GitHub Desktop.
makefile example #2
# Another simple make example. Creates 2 bins which include the same c file.
# Assumes e.g. you have main.c, main2.c, mylib.c and mylib.h.
# CC = gcc # Optional. Will use system default if not given here e.g. gcc or clang.
CFLAGS = -g -Wall -fanalyzer # $(shell pkg-config --cflags openssl)
# LIBS=$(shell pkg-config --libs openssl)
# LDFLAGS = $(LIBS)
bins = myprogram1 myprogram2
all: $(bins)
test1: mylib.o main.o
$(CC) -o myprogram1 $?
test2: mylib.o main2.o
$(CC) -o myprogram2 $?
.PHONY: clean
clean:
rm -f *.o $(bins)
@andy5995
Copy link

A gtk4 example

https://gitlab.gnome.org/GNOME/gtk/-/blob/main/examples/application1/Makefile.example

CC ?= gcc
PKGCONFIG = $(shell which pkg-config)
CFLAGS = $(shell $(PKGCONFIG) --cflags gtk4)
LIBS = $(shell $(PKGCONFIG) --libs gtk4)

SRC = main.c exampleapp.c exampleappwin.c

OBJS = $(SRC:.c=.o)

all: exampleapp

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

exampleapp: $(OBJS)
	$(CC) -o $(@F) $(OBJS) $(LIBS)

clean:
	rm -f $(OBJS)
	rm -f exampleapp

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment