Skip to content

Commit

Permalink
Update to add shlib build
Browse files Browse the repository at this point in the history
  • Loading branch information
kikuchan committed Jan 19, 2024
1 parent 57f7333 commit 7938c61
Show file tree
Hide file tree
Showing 10 changed files with 95 additions and 55 deletions.
7 changes: 4 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,18 @@ cli:
@BUILDDIR=$(BUILDDIR) $(MAKE) -C cli

install: cli
@BUILDDIR=$(BUILDDIR) $(MAKE) -C src install
@BUILDDIR=$(BUILDDIR) $(MAKE) -C cli install

clean:
@BUILDDIR=$(BUILDDIR) $(MAKE) -C cli clean
-rmdir $(BUILDDIR)

wasm:
@BUILDDIR=$(abspath ./build/wasm) $(MAKE) -C wasm clean all
@BUILDDIR=$(abspath ./build/wasm) NO_SHLIB=1 $(MAKE) -C wasm clean all

win32:
@BUILDDIR=$(abspath ./build/win32) CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar $(MAKE) clean cli
@BUILDDIR=$(abspath ./build/win32) CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar NO_SHLIB=1 DLL=1 $(MAKE) clean cli

mac: cli
cp build/system/qrean build/system/qrean-detect ./dist/
Expand All @@ -28,4 +29,4 @@ dist: wasm win32
cp build/wasm/Qrean.* build/win32/*exe ./dist/

test: cli
@BUILDDIR=$(BUILDDIR) $(MAKE) -C tests
@LD_LIBRARY_PATH=$(BUILDDIR) BUILDDIR=$(BUILDDIR) $(MAKE) -C tests
31 changes: 31 additions & 0 deletions cli/Makefile.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
PREFIX?=/usr/bin
BUILDDIR?=$(abspath ../../build/system)
QREAN?=$(abspath ../../src)

CFLAGS+=-I$(QREAN)
LDFLAGS += -L$(BUILDDIR) -lqrean -lm

NAME=libqrean

ifdef DLL
LIBSUFFIX := .dll
else
LIBSUFFIX := .so
endif

all: $(BUILDDIR)/$(MAIN)

$(BUILDDIR)/$(MAIN): Makefile $(SRCS) $(BUILDDIR)/$(NAME)$(LIBSUFFIX)
$(CC) -o $(BUILDDIR)/$(MAIN) $(CFLAGS) $(SRCS) $(LDFLAGS)

$(BUILDDIR)/$(NAME)$(LIBSUFFIX): $(QREAN)
@$(MAKE) -C $(QREAN)

format:
clang-format -i $(MAIN).c

clean:
rm -f $(BUILDDIR)/$(MAIN) $(BUILDDIR)/$(MAIN).exe $(BUILDDIR)/*.[do] $(BUILDDIR)/libqrean.*

install: $(BUILDDIR)/$(MAIN)
install -m 0755 $(BUILDDIR)/$(MAIN) $(PREFIX)
24 changes: 1 addition & 23 deletions cli/qrean-detect/Makefile
Original file line number Diff line number Diff line change
@@ -1,29 +1,7 @@
PREFIX ?= /usr/bin
BUILDDIR?=$(abspath ../../build/system)
QREAN?=$(abspath ../../src)

MAIN=qrean-detect

SRCS += $(MAIN).c
SRCS += pngle.c
SRCS += miniz.c

CFLAGS+=-I$(QREAN)
LDFLAGS += $(BUILDDIR)/libqrean.a -lm

all: $(BUILDDIR)/$(MAIN)

$(BUILDDIR)/$(MAIN): $(SRCS) $(BUILDDIR)/libqrean.a
$(CC) -o $(BUILDDIR)/$(MAIN) $(CFLAGS) $(SRCS) $(LDFLAGS)

$(BUILDDIR)/libqrean.a: $(QREAN)
@$(MAKE) -C $(QREAN)

format:
clang-format -i $(MAIN).c

clean:
rm -f $(BUILDDIR)/$(MAIN) $(BUILDDIR)/$(MAIN).exe $(BUILDDIR)/*.[do] $(BUILDDIR)/libqrean.a

install: $(BUILDDIR)/$(MAIN)
install -m 0755 $(BUILDDIR)/$(MAIN) $(PREFIX)
include ../Makefile.inc
6 changes: 5 additions & 1 deletion cli/qrean-detect/qrean-detect.c
Original file line number Diff line number Diff line change
Expand Up @@ -215,11 +215,15 @@ int main(int argc, char *argv[])
int len;
int ch;

while ((ch = getopt(argc, argv, "ho:g:DO:vBUSE:")) != -1) {
while ((ch = getopt(argc, argv, "hVo:g:DO:vBUSE:")) != -1) {
switch (ch) {
case 'h':
return usage(stdout);

case 'V':
printf("qrean-detect version %s\n", qrean_version());
return 0;

case 'o':
out = fopen(optarg, "w+t");
if (out == NULL) {
Expand Down
24 changes: 1 addition & 23 deletions cli/qrean/Makefile
Original file line number Diff line number Diff line change
@@ -1,29 +1,7 @@
PREFIX ?= /usr/bin
BUILDDIR?=$(abspath ../../build/system)
QREAN?=$(abspath ../../src)

MAIN=qrean

SRCS += $(MAIN).c
#SRCS += pngle.c
SRCS += miniz.c

CFLAGS+=-I$(QREAN)
LDFLAGS += $(BUILDDIR)/libqrean.a -lm

all: $(BUILDDIR)/$(MAIN)

$(BUILDDIR)/$(MAIN): $(SRCS) $(BUILDDIR)/libqrean.a
$(CC) -o $(BUILDDIR)/$(MAIN) $(CFLAGS) $(SRCS) $(LDFLAGS)

$(BUILDDIR)/libqrean.a: $(QREAN)
@$(MAKE) -C ../../src

format:
clang-format -i $(MAIN).c

clean:
rm -f $(BUILDDIR)/$(MAIN) $(BUILDDIR)/$(MAIN).exe $(BUILDDIR)/*.[do] $(BUILDDIR)/libqrean.a

install: $(BUILDDIR)/$(MAIN)
install -m 0755 $(BUILDDIR)/$(MAIN) $(PREFIX)
include ../Makefile.inc
6 changes: 5 additions & 1 deletion cli/qrean/qrean.c
Original file line number Diff line number Diff line change
Expand Up @@ -148,12 +148,16 @@ int main(int argc, char *argv[])
qrean_data_type_t data_type = QREAN_DATA_TYPE_AUTO;
int eci_code = QR_ECI_CODE_LATIN1;

while ((ch = getopt(argc, argv, "hi:o:s:f:t:v:l:m:p:8KANUSE:")) != -1) {
while ((ch = getopt(argc, argv, "hVi:o:s:f:t:v:l:m:p:8KANUSE:")) != -1) {
int n;
switch (ch) {
case 'h':
return usage(stdout);

case 'V':
printf("qrean version %s\n", qrean_version());
return 0;

case 'i':
in = fopen(optarg, "rb");
if (in == NULL) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "qrean",
"type": "module",
"version": "0.0.1-alpha.4",
"version": "0.0.1",
"description": "A portable QR and Barcode generation / manipulation library written in C",
"module": "./dist/Qrean.js",
"types": "./dist/Qrean.d.ts",
Expand Down
43 changes: 40 additions & 3 deletions src/Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
BUILDDIR ?= $(abspath ../build/system)
DESTDIR ?= /usr

SRCS += bitstream.c
SRCS += utils.c
Expand Down Expand Up @@ -43,6 +44,7 @@ SIZE = size
CFLAGS += -Wall # -Werror

CFLAGS += -Wno-misleading-indentation
CFLAGS += -fPIC

#CFLAGS += -D USE_MALLOC_BUFFER
#CFLAGS += -D NO_MALLOC
Expand All @@ -62,13 +64,41 @@ LDFLAGS += -lm
OBJS = $(addprefix $(BUILDDIR)/,$(SRCS:.c=.o))
DEPS = $(OBJS:.o=.d)

TARGET = $(BUILDDIR)/libqrean.a
VERSION := $(shell jq -r .version $(abspath ../package.json))
MAJORVERSION := $(shell echo "$(VERSION)" | sed 's,\..*,,')
LIBRARY = libqrean
TARGET = $(BUILDDIR)/$(LIBRARY)

all: $(TARGET)
CFLAGS += -DQREAN_VERSION=\"$(VERSION)\"

$(TARGET): $(OBJS) Makefile
all: libs

libs:
@$(MAKE) $(TARGET).a
ifndef NO_SHLIB
@$(MAKE) $(TARGET).so.$(VERSION)
endif
ifdef DLL
@$(MAKE) $(TARGET)-$(VERSION).dll
endif

$(TARGET).a: $(OBJS) Makefile
$(AR) rcs $@ $^

$(TARGET).so.$(VERSION): $(OBJS) Makefile
ifndef NO_SHLIB
$(CC) -shared -Wl,-soname,$(LIBRARY).so.$(MAJORVERSION) -o $@ $(OBJS)
-ln -sf $(LIBRARY).so.$(VERSION) $(TARGET).so.$(MAJORVERSION)
-ln -sf $(LIBRARY).so.$(VERSION) $(TARGET).so
endif

ifdef DLL
$(TARGET)-$(VERSION).dll: $(OBJS) Makefile
$(CC) -shared -o $@ $(OBJS)
-ln -sf $(LIBRARY)-$(VERSION).dll $(TARGET)-$(MAJORVERSION).dll
-ln -sf $(LIBRARY)-$(VERSION).dll $(TARGET).dll
endif

-include $(DEPS)

$(BUILDDIR)/%.o: %.c Makefile
Expand All @@ -78,5 +108,12 @@ $(BUILDDIR)/%.o: %.c Makefile
clean:
rm -f $(BUILDDIR)/*.[do] $(TARGET)

install: libs
install -s $(TARGET).so.$(VERSION) $(DESTDIR)/lib/
install -m 644 $(TARGET).a $(DESTDIR)/lib/
-ln -sf $(LIBRARY).so.$(VERSION) $(DESTDIR)/lib/$(LIBRARY).so.$(MAJORVERSION)
-ln -sf $(LIBRARY).so.$(VERSION) $(DESTDIR)/lib/$(LIBRARY).so
mkdir -p $(DESTDIR)/include/qrean/ && install -m 644 *.h $(DESTDIR)/include/qrean/

format:
clang-format -i *.[ch]
5 changes: 5 additions & 0 deletions src/qrean.c
Original file line number Diff line number Diff line change
Expand Up @@ -707,3 +707,8 @@ qr_eci_code_t qrean_get_eci_code(qrean_t *qrean)
{
return qrean->eci_code;
}

const char *qrean_version()
{
return QREAN_VERSION;
}
2 changes: 2 additions & 0 deletions src/qrean.h
Original file line number Diff line number Diff line change
Expand Up @@ -235,4 +235,6 @@ const char *qrean_get_code_type_string(qrean_code_type_t code);
bit_t qrean_set_eci_code(qrean_t *qrean, qr_eci_code_t code);
qr_eci_code_t qrean_get_eci_code(qrean_t *qrean);

const char *qrean_version();

#endif /* __QR_QREAN_H__ */

0 comments on commit 7938c61

Please sign in to comment.