| 1 |
# |
| 2 |
# Makefile for QR Code generator (C) |
| 3 |
# |
| 4 |
# Copyright (c) Project Nayuki. (MIT License) |
| 5 |
# https://www.nayuki.io/page/qr-code-generator-library |
| 6 |
# |
| 7 |
# Permission is hereby granted, free of charge, to any person obtaining a copy of |
| 8 |
# this software and associated documentation files (the "Software"), to deal in |
| 9 |
# the Software without restriction, including without limitation the rights to |
| 10 |
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of |
| 11 |
# the Software, and to permit persons to whom the Software is furnished to do so, |
| 12 |
# subject to the following conditions: |
| 13 |
# - The above copyright notice and this permission notice shall be included in |
| 14 |
# all copies or substantial portions of the Software. |
| 15 |
# - The Software is provided "as is", without warranty of any kind, express or |
| 16 |
# implied, including but not limited to the warranties of merchantability, |
| 17 |
# fitness for a particular purpose and noninfringement. In no event shall the |
| 18 |
# authors or copyright holders be liable for any claim, damages or other |
| 19 |
# liability, whether in an action of contract, tort or otherwise, arising from, |
| 20 |
# out of or in connection with the Software or the use or other dealings in the |
| 21 |
# Software. |
| 22 |
# |
| 23 |
|
| 24 |
|
| 25 |
# ---- Configuration options ---- |
| 26 |
|
| 27 |
# External/implicit variables: |
| 28 |
# - CC: The C compiler, such as gcc or clang. |
| 29 |
# - CFLAGS: Any extra user-specified compiler flags (can be blank). |
| 30 |
|
| 31 |
# Recommended compiler flags: |
| 32 |
CFLAGS += -std=c99 -O |
| 33 |
|
| 34 |
# Extra flags for diagnostics: |
| 35 |
# CFLAGS += -g -Wall -Wextra -Wpedantic -Wconversion -Wsign-conversion -fsanitize=undefined,address |
| 36 |
|
| 37 |
|
| 38 |
# ---- Controlling make ---- |
| 39 |
|
| 40 |
# Clear default suffix rules |
| 41 |
.SUFFIXES: |
| 42 |
|
| 43 |
# Don't delete object files |
| 44 |
.SECONDARY: |
| 45 |
|
| 46 |
# Stuff concerning goals |
| 47 |
.DEFAULT_GOAL = all |
| 48 |
.PHONY: all clean |
| 49 |
|
| 50 |
|
| 51 |
# ---- Targets to build ---- |
| 52 |
|
| 53 |
LIB = qrcodegen |
| 54 |
LIBFILE = lib$(LIB).a |
| 55 |
LIBOBJ = qrcodegen.o |
| 56 |
MAINS = qrcodegen-demo qrcodegen-test |
| 57 |
|
| 58 |
# Build all binaries |
| 59 |
all: $(LIBFILE) $(MAINS) |
| 60 |
|
| 61 |
# Delete build output |
| 62 |
clean: |
| 63 |
rm -f -- $(LIBOBJ) $(LIBFILE) $(MAINS:=.o) $(MAINS) |
| 64 |
rm -rf .deps |
| 65 |
|
| 66 |
# Executable files |
| 67 |
%: %.o $(LIBFILE) |
| 68 |
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< -L . -l $(LIB) |
| 69 |
|
| 70 |
# Special executable |
| 71 |
qrcodegen-test: qrcodegen-test.c $(LIBOBJ:%.o=%.c) |
| 72 |
$(CC) $(CFLAGS) $(LDFLAGS) -DQRCODEGEN_TEST -o $@ $^ |
| 73 |
|
| 74 |
# The library |
| 75 |
$(LIBFILE): $(LIBOBJ) |
| 76 |
$(AR) -crs $@ -- $^ |
| 77 |
|
| 78 |
# Object files |
| 79 |
%.o: %.c .deps/timestamp |
| 80 |
$(CC) $(CFLAGS) -c -o $@ -MMD -MF .deps/$*.d $< |
| 81 |
|
| 82 |
# Have a place to store header dependencies automatically generated by compiler |
| 83 |
.deps/timestamp: |
| 84 |
mkdir -p .deps |
| 85 |
touch .deps/timestamp |
| 86 |
|
| 87 |
# Make use of said dependencies if available |
| 88 |
-include .deps/*.d |