separate build and config
This commit is contained in:
parent
016ed8ff6c
commit
891b51b67f
43
Makefile
43
Makefile
|
@ -1,52 +1,37 @@
|
||||||
CC = cc
|
include config.mk
|
||||||
MACROS = -DNDEBUG
|
|
||||||
CFLAGS = $(MACROS) --std=c99 -O2 -g -Wall -Wextra -Wpedantic -fPIC
|
|
||||||
|
|
||||||
PREFIX = /usr/local/
|
SOURCE = readopt.c
|
||||||
LIB = $(PREFIX)/lib/
|
OBJECT = readopt.o
|
||||||
INCLUDE = $(PREFIX)/include/
|
|
||||||
|
|
||||||
SOURCES = $(wildcard ./*.c)
|
all: $(STATIC) $(SHARED)
|
||||||
OBJECTS = $(SOURCES:.c=.o)
|
|
||||||
HEADERS = $(wildcard ./*.h)
|
|
||||||
|
|
||||||
STATICTARGET = libreadopt.a
|
|
||||||
SHAREDTARGET = libreadopt.so
|
|
||||||
|
|
||||||
AR = ar -rcs --
|
|
||||||
RM = rm -f --
|
|
||||||
CP = cp --
|
|
||||||
MKDIR = mkdir -p --
|
|
||||||
|
|
||||||
all: $(STATICTARGET) $(SHAREDTARGET)
|
|
||||||
|
|
||||||
%.o: %.c
|
%.o: %.c
|
||||||
$(CC) -c $(CFLAGS) $<
|
$(CC) -c $(CFLAGS) $<
|
||||||
|
|
||||||
$(STATICTARGET): $(OBJECTS)
|
$(STATIC): $(OBJECT)
|
||||||
$(AR) $@ $^
|
$(AR) $@ $^
|
||||||
|
|
||||||
$(SHAREDTARGET): $(OBJECTS)
|
$(SHARED): $(OBJECT)
|
||||||
$(CC) --shared $^ -o $@
|
$(CC) --shared $^ -o $@
|
||||||
|
|
||||||
install: staticinstall sharedinstall
|
install: staticinstall sharedinstall
|
||||||
|
|
||||||
staticinstall: $(STATICTARGET)
|
staticinstall: $(STATIC)
|
||||||
$(MKDIR) $(DESTDIR)$(LIB)
|
$(MKDIR) $(DESTDIR)$(LIB)
|
||||||
$(CP) $^ $(DESTDIR)$(LIB)
|
$(CP) $^ $(DESTDIR)$(LIB)
|
||||||
$(MKDIR) $(DESTDIR)$(INCLUDE)
|
$(MKDIR) $(DESTDIR)$(INCL)
|
||||||
$(CP) $(HEADERS) $(DESTDIR)$(INCLUDE)
|
$(CP) $(HEADER) $(DESTDIR)$(INCL)
|
||||||
|
|
||||||
sharedinstall: $(SHAREDTARGET)
|
sharedinstall: $(SHARED)
|
||||||
$(MKDIR) $(DESTDIR)$(LIB)
|
$(MKDIR) $(DESTDIR)$(LIB)
|
||||||
$(CP) $^ $(DESTDIR)$(LIB)
|
$(CP) $^ $(DESTDIR)$(LIB)
|
||||||
$(MKDIR) $(DESTDIR)$(INCLUDE)
|
$(MKDIR) $(DESTDIR)$(INCL)
|
||||||
$(CP) $(HEADERS) $(DESTDIR)$(INCLUDE)
|
$(CP) $(HEADER) $(DESTDIR)$(INCL)
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
$(RM) $(OBJECTS) $(STATICTARGET) $(SHAREDTARGET)
|
$(RM) $(OBJECT) $(STATIC) $(SHARED)
|
||||||
|
|
||||||
format:
|
format:
|
||||||
clang-format -i -- $(SOURCES) $(HEADERS)
|
clang-format -i -- $(SOURCE) $(HEADER)
|
||||||
|
|
||||||
.PHONY: clean install staticinstall sharedinstall format
|
.PHONY: clean install staticinstall sharedinstall format
|
||||||
|
|
17
config.mk
Normal file
17
config.mk
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
DESTDIR =
|
||||||
|
PREFIX = /usr/local/
|
||||||
|
LIB = $(PREFIX)/lib/
|
||||||
|
INCL = $(PREFIX)/include/
|
||||||
|
|
||||||
|
CC = cc
|
||||||
|
MACROS = -D _POSIX_C_SOURCE=200809L -D NDEBUG
|
||||||
|
CFLAGS = --std=c99 -Wall -Wextra -Wpedantic -g $(MACROS) -O2
|
||||||
|
|
||||||
|
AR = ar -rcs --
|
||||||
|
RM = rm -f --
|
||||||
|
CP = cp --
|
||||||
|
MKDIR = mkdir -p --
|
||||||
|
|
||||||
|
HEADER = ./readopt.h
|
||||||
|
STATIC = ./libreadopt.a
|
||||||
|
SHARED = ./libreadopt.so
|
Loading…
Reference in a new issue