Revamped C and C++ makefiles by copying structure from another library of mine, removed shared library output from C library (from commit a3dcc36dd4
) due to problematic linkage in some enviroments.
This commit is contained in:
parent
070daf8c9e
commit
be143456be
36
c/Makefile
36
c/Makefile
|
@ -51,8 +51,9 @@ CFLAGS += -O1
|
|||
|
||||
# ---- Targets to build ----
|
||||
|
||||
LIBSRC = qrcodegen
|
||||
LIBFILE = libqrcodegen.so
|
||||
LIB = qrcodegen
|
||||
LIBFILE = lib$(LIB).a
|
||||
LIBOBJ = qrcodegen.o
|
||||
MAINS = qrcodegen-demo qrcodegen-test qrcodegen-worker
|
||||
|
||||
# Build all binaries
|
||||
|
@ -60,16 +61,29 @@ all: $(LIBFILE) $(MAINS)
|
|||
|
||||
# Delete build output
|
||||
clean:
|
||||
rm -f -- $(LIBFILE) $(MAINS)
|
||||
|
||||
# Shared library
|
||||
$(LIBFILE): $(LIBSRC:=.c) $(LIBSRC:=.h)
|
||||
$(CC) $(CFLAGS) -fPIC -shared -o $@ $(LIBSRC:=.c)
|
||||
rm -f -- $(LIBOBJ) $(LIBFILE) $(MAINS:=.o) $(MAINS)
|
||||
rm -rf .deps
|
||||
|
||||
# Executable files
|
||||
%: %.c $(LIBFILE)
|
||||
$(CC) $(CFLAGS) -o $@ $^
|
||||
%: %.o $(LIBFILE)
|
||||
$(CC) $(CFLAGS) -o $@ $< -L . -l $(LIB)
|
||||
|
||||
# Special executable
|
||||
qrcodegen-test: qrcodegen-test.c $(LIBSRC:=.c) $(LIBSRC:=.h)
|
||||
$(CC) $(CFLAGS) -DQRCODEGEN_TEST -o $@ $< $(LIBSRC:=.c)
|
||||
qrcodegen-test: qrcodegen-test.c $(LIBOBJ:%.o=%.c)
|
||||
$(CC) $(CFLAGS) -DQRCODEGEN_TEST -o $@ $^
|
||||
|
||||
# The library
|
||||
$(LIBFILE): $(LIBOBJ)
|
||||
$(AR) -crs $@ -- $^
|
||||
|
||||
# Object files
|
||||
%.o: %.c .deps/timestamp
|
||||
$(CC) $(CFLAGS) -c -o $@ -MMD -MF .deps/$*.d $<
|
||||
|
||||
# Have a place to store header dependencies automatically generated by compiler
|
||||
.deps/timestamp:
|
||||
mkdir -p .deps
|
||||
touch .deps/timestamp
|
||||
|
||||
# Make use of said dependencies if available
|
||||
-include .deps/*.d
|
||||
|
|
29
cpp/Makefile
29
cpp/Makefile
|
@ -51,16 +51,35 @@ CXXFLAGS += -O1
|
|||
|
||||
# ---- Targets to build ----
|
||||
|
||||
LIBSRC = BitBuffer QrCode QrSegment
|
||||
LIB = qrcodegen
|
||||
LIBFILE = lib$(LIB).a
|
||||
LIBOBJ = BitBuffer.o QrCode.o QrSegment.o
|
||||
MAINS = QrCodeGeneratorDemo QrCodeGeneratorWorker
|
||||
|
||||
# Build all binaries
|
||||
all: $(MAINS)
|
||||
all: $(LIBFILE) $(MAINS)
|
||||
|
||||
# Delete build output
|
||||
clean:
|
||||
rm -f -- $(MAINS)
|
||||
rm -f -- $(LIBOBJ) $(LIBFILE) $(MAINS:=.o) $(MAINS)
|
||||
rm -rf .deps
|
||||
|
||||
# Executable files
|
||||
%: %.cpp $(LIBSRC:=.cpp) $(LIBSRC:=.hpp)
|
||||
$(CXX) $(CXXFLAGS) -o $@ $< $(LIBSRC:=.cpp)
|
||||
%: %.o $(LIBFILE)
|
||||
$(CXX) $(CXXFLAGS) -o $@ $< -L . -l $(LIB)
|
||||
|
||||
# The library
|
||||
$(LIBFILE): $(LIBOBJ)
|
||||
$(AR) -crs $@ -- $^
|
||||
|
||||
# Object files
|
||||
%.o: %.cpp .deps/timestamp
|
||||
$(CXX) $(CXXFLAGS) -c -o $@ -MMD -MF .deps/$*.d $<
|
||||
|
||||
# Have a place to store header dependencies automatically generated by compiler
|
||||
.deps/timestamp:
|
||||
mkdir -p .deps
|
||||
touch .deps/timestamp
|
||||
|
||||
# Make use of said dependencies if available
|
||||
-include .deps/*.d
|
||||
|
|
Loading…
Reference in New Issue