Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add patches to make C and Cpp packages installable #72

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
45 changes: 39 additions & 6 deletions c/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,13 @@
# - CFLAGS: Any extra user-specified compiler flags (can be blank).

# Recommended compiler flags:
CFLAGS += -std=c99 -O
CFLAGS += -std=c99

# Extra flags for diagnostics:
# CFLAGS += -g -Wall -Wextra -Wpedantic -Wconversion -Wsign-conversion -fsanitize=undefined,address

# Version information
VERSION = 1.6.0

# ---- Controlling make ----

Expand All @@ -51,18 +53,46 @@ CFLAGS += -std=c99 -O
# ---- Targets to build ----

LIB = qrcodegen
LIBFILE = lib$(LIB).a
ARFILE = lib$(LIB).a
LIBFILE = lib$(LIB).so
# Bump the soname number when the ABI changes and gets incompatible
SO_NAME = $(LIBFILE).1
REAL_NAME = $(LIBFILE).$(VERSION)
HEADERS = qrcodegen.h
LIBOBJ = qrcodegen.o
MAINS = qrcodegen-demo qrcodegen-test qrcodegen-worker

# define paths to install
PREFIX ?= /usr/local
INCLUDEDIR ?= $(DESTDIR)$(PREFIX)/include/qrcodegen
LIBDIR ?= $(DESTDIR)$(PREFIX)/lib

# Build all binaries
all: $(LIBFILE) $(MAINS)
all: $(LIBFILE) $(ARFILE) $(MAINS)

# Delete build output
clean:
rm -f -- $(LIBOBJ) $(LIBFILE) $(MAINS:=.o) $(MAINS)
rm -f -- $(LIBOBJ) $(LIBFILE) $(ARFILE) $(MAINS:=.o) $(MAINS)
rm -rf .deps

install-shared: $(LIBFILE)
install -d $(LIBDIR) || true
install -m 0755 $(LIBFILE) $(LIBDIR)/$(REAL_NAME)
rm -f $(LIBDIR)/$(SO_NAME)
ln -s $(REAL_NAME) $(LIBDIR)/$(SO_NAME)
rm -f $(LIBDIR)/$(LIBFILE)
ln -s $(SO_NAME) $(LIBDIR)/$(LIBFILE)

install-static: $(ARFILE)
install -d $(LIBDIR) || true
install -m 0755 $(ARFILE) $(LIBDIR)/$(ARFILE)

install-header: $(HEADERS)
install -d $(INCLUDEDIR) || true
install -m 0644 $(HEADERS) $(INCLUDEDIR)/

install: install-shared install-static install-header

# Executable files
%: %.o $(LIBFILE)
$(CC) $(CFLAGS) -o $@ $< -L . -l $(LIB)
Expand All @@ -72,12 +102,15 @@ qrcodegen-test: qrcodegen-test.c $(LIBOBJ:%.o=%.c)
$(CC) $(CFLAGS) -DQRCODEGEN_TEST -o $@ $^

# The library
$(LIBFILE): $(LIBOBJ)
$(ARFILE): $(LIBOBJ)
$(AR) -crs $@ -- $^

$(LIBFILE): $(LIBOBJ)
$(CC) $(CFLAGS) -shared -Wl,-soname,$(SO_NAME) $(LDFLAGS) -o $@ $^

# Object files
%.o: %.c .deps/timestamp
$(CC) $(CFLAGS) -c -o $@ -MMD -MF .deps/$*.d $<
$(CC) $(CFLAGS) -fPIC -c -o $@ -MMD -MF .deps/$*.d $<

# Have a place to store header dependencies automatically generated by compiler
.deps/timestamp:
Expand Down
48 changes: 41 additions & 7 deletions cpp/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,13 @@
# - CXXFLAGS: Any extra user-specified compiler flags (can be blank).

# Recommended compiler flags:
CXXFLAGS += -std=c++11 -O
CXXFLAGS += -std=c++11

# Extra flags for diagnostics:
# CXXFLAGS += -g -Wall -Wextra -Wpedantic -Wconversion -Wsign-conversion -fsanitize=undefined,address

# Version information
VERSION = 1.6.0

# ---- Controlling make ----

Expand All @@ -50,30 +52,62 @@ CXXFLAGS += -std=c++11 -O

# ---- Targets to build ----

LIB = qrcodegen
LIBFILE = lib$(LIB).a
LIB = qrcodegencpp
ARFILE = lib$(LIB).a
LIBFILE = lib$(LIB).so
# Bump the soname number when the ABI changes and gets incompatible
SO_NAME = $(LIBFILE).1
REAL_NAME = $(LIBFILE).$(VERSION)
HEADERS = QrCode.hpp
LIBOBJ = QrCode.o
MAINS = QrCodeGeneratorDemo QrCodeGeneratorWorker

# define paths to install
PREFIX ?= /usr/local
INCLUDEDIR ?= $(DESTDIR)$(PREFIX)/include/qrcodegen
LIBDIR ?= $(DESTDIR)$(PREFIX)/lib

scarabeusiv marked this conversation as resolved.
Show resolved Hide resolved

# Build all binaries
all: $(LIBFILE) $(MAINS)
all: $(LIBFILE) $(ARFILE) $(MAINS)

# Delete build output
clean:
rm -f -- $(LIBOBJ) $(LIBFILE) $(MAINS:=.o) $(MAINS)
rm -f -- $(LIBOBJ) $(LIBFILE) $(ARFILE) $(MAINS:=.o) $(MAINS)
rm -rf .deps

install-shared: $(LIBFILE)
install -d $(LIBDIR) || true
install -m 0755 $(LIBFILE) $(LIBDIR)/$(REAL_NAME)
rm -f $(LIBDIR)/$(SO_NAME)
ln -s $(REAL_NAME) $(LIBDIR)/$(SO_NAME)
rm -f $(LIBDIR)/$(LIBFILE)
ln -s $(SO_NAME) $(LIBDIR)/$(LIBFILE)

install-static: $(ARFILE)
install -d $(LIBDIR) || true
install -m 0755 $(ARFILE) $(LIBDIR)/$(ARFILE)

install-header: $(HEADERS)
install -d $(INCLUDEDIR) || true
install -m 0644 $(HEADERS) $(INCLUDEDIR)/

install: install-shared install-static install-header

# Executable files
%: %.o $(LIBFILE)
$(CXX) $(CXXFLAGS) -o $@ $< -L . -l $(LIB)

# The library
$(LIBFILE): $(LIBOBJ)
$(ARFILE): $(LIBOBJ)
$(AR) -crs $@ -- $^

$(LIBFILE): $(LIBOBJ)
$(CXX) $(CXXFLAGS) -shared -Wl,-soname,$(SO_NAME) $(LDFLAGS) -o $@ $^

# Object files
%.o: %.cpp .deps/timestamp
$(CXX) $(CXXFLAGS) -c -o $@ -MMD -MF .deps/$*.d $<
$(CXX) $(CXXFLAGS) -fPIC -c -o $@ -MMD -MF .deps/$*.d $<

# Have a place to store header dependencies automatically generated by compiler
.deps/timestamp:
Expand Down