Refactor makefiles to use some common options

This commit is contained in:
Kamil Shakirov 2020-05-13 16:23:07 +06:00
parent 8261b361e0
commit 2ad471a5e3
12 changed files with 124 additions and 208 deletions

View File

@ -1,36 +1,4 @@
##### Options which a user might set before building go here #####
export PREFIX ?= ${HOME}/.idris2
# Add any optimisation/profiling flags for C here (e.g. -O2)
export OPT=
export CC=clang # clang compiles the output much faster than gcc!
##################################################################
export MACHINE := $(shell $(CC) -dumpmachine)
ifneq (, $(findstring darwin, $(MACHINE)))
OS := darwin
else ifneq (, $(findstring cygwin, $(MACHINE)))
OS := windows
else ifneq (, $(findstring mingw, $(MACHINE)))
OS := windows
else ifneq (, $(findstring windows, $(MACHINE)))
OS := windows
else ifneq (, $(findstring bsd, $(MACHINE)))
OS := bsd
else
OS := linux
endif
export OS
ifeq ($(OS),bsd)
MAKE := gmake
else
MAKE := make
endif
export MAKE
include config.mk
# current Idris2 version components
MAJOR=0
@ -51,9 +19,10 @@ endif
export IDRIS2_VERSION := ${MAJOR}.${MINOR}.${PATCH}
IDRIS2_VERSION_TAG := ${IDRIS2_VERSION}${VER_TAG}
export IDRIS2_PATH = ${CURDIR}/libs/prelude/build/ttc:${CURDIR}/libs/base/build/ttc:${CURDIR}/libs/network/build/ttc
export IDRIS2_LIBS = ${CURDIR}/libs/network
export IDRIS2_DATA = ${CURDIR}/support
export IDRIS2_CURDIR = $(CURDIR)
export IDRIS2_PATH = ${IDRIS2_CURDIR}/libs/prelude/build/ttc:${IDRIS2_CURDIR}/libs/base/build/ttc:${IDRIS2_CURDIR}/libs/network/build/ttc
export IDRIS2_LIBS = ${IDRIS2_CURDIR}/libs/network
export IDRIS2_DATA = ${IDRIS2_CURDIR}/support
IDRIS_VERSION := $(shell idris --version)
VALID_IDRIS_VERSION_REGEXP = "1.3.2.*"

View File

@ -10,4 +10,4 @@ PDFS=$(patsubst %.md,%.pdf,$(DOCS))
all: $(PDFS)
clean:
rm $(PDFS)
rm -f $(PDFS)

47
config.mk Normal file
View File

@ -0,0 +1,47 @@
##### Options which a user might set before building go here #####
PREFIX ?= $(HOME)/.idris2
# Add any optimisation/profiling flags for C here (e.g. -O2)
OPT =
# clang compiles the output much faster than gcc!
CC ?= clang
##################################################################
RANLIB ?= ranlib
AR ?= ar
CFLAGS := -Wall $(CFLAGS) $(OPT)
LDFLAGS := $(LDFLAGS)
MACHINE := $(shell $(CC) -dumpmachine)
ifneq (,$(findstring cygwin, $(MACHINE)))
OS := windows
SHLIB_SUFFIX := .dll
else ifneq (,$(findstring mingw, $(MACHINE)))
OS := windows
SHLIB_SUFFIX := .dll
else ifneq (,$(findstring windows, $(MACHINE)))
OS := windows
SHLIB_SUFFIX := .dll
else ifneq (,$(findstring darwin, $(MACHINE)))
OS := darwin
SHLIB_SUFFIX := .dylib
CFLAGS += -fPIC
else ifneq (, $(findstring bsd, $(MACHINE)))
OS := bsd
SHLIB_SUFFIX := .so
CFLAGS += -fPIC
else
OS := linux
SHLIB_SUFFIX := .so
CFLAGS += -fPIC
endif
ifeq ($(OS),bsd)
MAKE := gmake
else
MAKE := make
endif

4
dist/Makefile vendored
View File

@ -6,8 +6,8 @@ all: idris2
idris2: idris2.c
$(MAKE) -C rts
$(CC) $(OPT) idris2.c -o idris2 -I rts -L rts -lidris_rts $(GMP_LIB_DIR) -lgmp -lm
$(CC) $(CFLAGS) idris2.c -o idris2 -I rts -L rts -lidris_rts $(GMP_LIB_DIR) -lgmp -lm
clean:
${MAKE} -C rts clean
$(MAKE) -C rts clean
rm -f idris2

13
dist/config.mk vendored
View File

@ -1,20 +1,17 @@
RANLIB ?=ranlib
CFLAGS :=-O2 -Wall -std=c99 -pipe -fdata-sections -ffunction-sections -D_POSIX_C_SOURCE=200809L $(CFLAGS)
include $(IDRIS2_CURDIR)/config.mk
CFLAGS += -O2 -std=c99 -pipe -fdata-sections -ffunction-sections -D_POSIX_C_SOURCE=200809L
ifeq ($(OS),bsd)
GMP_INCLUDE_DIR =-I/usr/local/include
GMP_LIB_DIR =-L/usr/local/lib
SHLIB_SUFFIX =.so
GMP_INCLUDE_DIR = -I/usr/local/include
GMP_LIB_DIR = -L/usr/local/lib
else ifeq ($(OS),darwin)
GMP_INCLUDE_DIR =
GMP_LIB_DIR =
SHLIB_SUFFIX =.dylib
else ifeq ($(OS),windows)
GMP_INCLUDE_DIR =
GMP_LIB_DIR =
SHLIB_SUFFIX =.DLL
else
GMP_INCLUDE_DIR =
GMP_LIB_DIR =
SHLIB_SUFFIX =.so
endif

12
dist/rts/Makefile vendored
View File

@ -6,14 +6,12 @@ OBJS =idris_rts.o idris_heap.o idris_gc.o idris_gmp.o idris_bitstring.o \
HDRS =idris_rts.h idris_heap.h idris_gc.h idris_gmp.h idris_bitstring.h \
idris_opts.h idris_stats.h idris_stdfgn.h idris_net.h \
idris_buffer.h idris_utf8.h getline.h
CFLAGS :=$(CFLAGS)
CFLAGS +=$(GMP_INCLUDE_DIR) $(GMP) -DIDRIS_TARGET_OS="\"$(OS)\""
CFLAGS +=-DIDRIS_TARGET_TRIPLE="\"$(MACHINE)\""
CFLAGS += $(GMP_INCLUDE_DIR) -DIDRIS_TARGET_OS="\"$(OS)\""
CFLAGS += -DIDRIS_TARGET_TRIPLE="\"$(MACHINE)\""
ifeq ($(OS), windows)
OBJS += windows/win_utils.o
else
CFLAGS += -fPIC
endif
ifndef IDRIS_GMP
@ -27,6 +25,8 @@ LIBTARGET = libidris_rts.a
build: $(LIBTARGET)
$(OBJS): $(HDRS)
$(LIBTARGET) : $(OBJS)
$(AR) rc $(LIBTARGET) $(OBJS)
$(RANLIB) $(LIBTARGET)
@ -37,5 +37,3 @@ install :
clean :
rm -f $(OBJS) $(LIBTARGET) $(DYLIBTARGET)
$(OBJS): $(HDRS)

View File

@ -1,62 +1,54 @@
RANLIB ?=ranlib
AR ?=ar
include $(IDRIS2_CURDIR)/config.mk
MACHINE := $(shell $(CC) -dumpmachine)
ifneq (,$(findstring cygwin, $(MACHINE)))
OS := windows
SHLIB_SUFFIX := .dll
else ifneq (,$(findstring mingw, $(MACHINE)))
OS := windows
SHLIB_SUFFIX := .dll
else ifneq (,$(findstring windows, $(MACHINE)))
OS := windows
SHLIB_SUFFIX := .dll
else ifneq (,$(findstring darwin, $(MACHINE)))
OS := darwin
SHLIB_SUFFIX := .dylib
CFLAGS += -fPIC
else
OS := unix
SHLIB_SUFFIX := .so
CFLAGS += -fPIC
endif
INSTALLDIR = `${IDRIS2} --libdir`/network/lib
LIBNAME=idris_net
OBJS = $(LIBNAME).o
HDRS = $(LIBNAME).h
CFLAGS := $(CFLAGS)
IDRIS_SRCS = Network/Socket.idr Network/Socket/Data.idr Network/Socket/Raw.idr
DYLIBTARGET = $(LIBNAME)$(SHLIB_SUFFIX)
LIBTARGET = $(LIBNAME).a
TARGET=`${IDRIS2} --libdir`
TARGET = idris_net
build: $(DYLIBTARGET) $(IDRIS_SRCS)
SRCS = $(wildcard *.c)
OBJS = $(SRCS:.c=.o)
DEPS = $(OBJS:.o=.d)
all: $(TARGET)$(SHLIB_SUFFIX)
${IDRIS2} --build network.ipkg
build: $(TARGET)$(SHLIB_SUFFIX) $(IDRIS_SRCS)
@if [ -z "${IDRIS2}" ]; then echo 'variable $$IDRIS2 is not set, aborting'; exit 1; fi
${IDRIS2} --build network.ipkg
$(DYLIBTARGET) : $(OBJS)
$(CC) -o $(DYLIBTARGET) $(LIBFLAGS) -shared $(OBJS)
$(TARGET)$(SHLIB_SUFFIX): $(OBJS)
$(CC) -shared $(LDFLAGS) -o $@ $^
-include $(DEPS)
%.d: %.c
@$(CPP) $(CFLAGS) $< -MM -MT $(@:.d=.o) >$@
.PHONY: clean
clean :
rm -f $(OBJS) $(TARGET)$(SHLIB_SUFFIX)
rm -rf build
cleandep: clean
rm -f $(DEPS)
.PHONY: install
install:
@if [ -z "${IDRIS2}" ]; then echo 'variable $$IDRIS2 is not set, aborting'; exit 1; fi
${IDRIS2} --install network.ipkg
@if ! [ -d $(TARGET)/network/lib ]; then mkdir $(TARGET)/network/lib; fi
install $(DYLIBTARGET) $(HDRS) $(TARGET)/network/lib
@if ! [ -d $(INSTALLDIR) ]; then mkdir -p $(INSTALLDIR); fi
install $(TARGET)$(SHLIB_SUFFIX) $(wildcard *.h) $(INSTALLDIR)
clean :
rm -rf $(OBJS) $(LIBTARGET) $(DYLIBTARGET) build
test: build test.c
$(CC) -o network-tests -L. -I. test.c $(DYLIBTARGET)
$(CC) -o network-tests -L. -I. test.c $(TARGET)$(SHLIB_SUFFIX)
LD_LIBRARY_PATH=. ./network-tests
@rm -f ./network-tests
$(OBJS): $(HDRS)
all: $(DYLIBTARGET) $(LIBTARGET)
${IDRIS2} --build network.ipkg
.PHONY: install clean
@rm -f ./network-tests test.o

View File

@ -46,7 +46,7 @@ void test_peek_and_poke_buffer() {
}
int main(int argc, char**argv) {
int main(void) {
test_sockaddr_port_returns_explicitly_assigned_port();
test_sockaddr_port_returns_random_port_when_bind_port_is_0();
test_peek_and_poke_buffer();

View File

@ -1,42 +1,21 @@
include ../../../config.mk
IDRIS := idris2
INSTALLDIR = `${IDRIS} --libdir`/readline/lib
TARGET = libidrisreadline
MACHINE := $(shell $(CC) -dumpmachine)
ifneq (,$(findstring cygwin, $(MACHINE)))
OS := windows
SHLIB_SUFFIX := .dll
else ifneq (,$(findstring mingw, $(MACHINE)))
OS := windows
SHLIB_SUFFIX := .dll
else ifneq (,$(findstring windows, $(MACHINE)))
OS := windows
SHLIB_SUFFIX := .dll
else ifneq (,$(findstring darwin, $(MACHINE)))
OS := darwin
SHLIB_SUFFIX := .dylib
CFLAGS += -fPIC
else
OS := unix
SHLIB_SUFFIX := .so
CFLAGS += -fPIC
endif
CFLAGS := -Wall -Wextra $(CFLAGS)
LDFLAGS := $(LDFLAGS) -lreadline
LDFLAGS += -lreadline
SRCS = $(wildcard *.c)
OBJS = $(SRCS:.c=.o)
DEPS = $(OBJS:.o=.d)
all: ${TARGET}$(SHLIB_SUFFIX)
all: $(TARGET)$(SHLIB_SUFFIX)
$(TARGET)$(SHLIB_SUFFIX): $(OBJS)
$(CC) -shared ${LDFLAGS} -o $@ $^
$(CC) -shared $(LDFLAGS) -o $@ $^
-include $(DEPS)
@ -51,7 +30,7 @@ clean :
rm -f $(OBJS) $(TARGET)$(SHLIB_SUFFIX)
cleandep: clean
rm -f ${DEPS}
rm -f $(DEPS)
.PHONY: install

View File

@ -1,31 +1,11 @@
include $(IDRIS2_CURDIR)/config.mk
TARGET = libidris2_support
MACHINE := $(shell $(CC) -dumpmachine)
ifneq (,$(findstring cygwin, $(MACHINE)))
OS := windows
SHLIB_SUFFIX := .dll
else ifneq (,$(findstring mingw, $(MACHINE)))
OS := windows
SHLIB_SUFFIX := .dll
else ifneq (,$(findstring windows, $(MACHINE)))
OS := windows
SHLIB_SUFFIX := .dll
else ifneq (,$(findstring darwin, $(MACHINE)))
OS := darwin
SHLIB_SUFFIX := .dylib
CFLAGS += -fPIC
else
OS := unix
SHLIB_SUFFIX := .so
CFLAGS += -fPIC
endif
LIBTARGET = $(TARGET).a
DYLIBTARGET = ${TARGET}$(SHLIB_SUFFIX)
DYLIBTARGET = $(TARGET)$(SHLIB_SUFFIX)
CFLAGS := -O2 -Wall -Wextra $(CFLAGS)
LDFLAGS := $(LDFLAGS)
CFLAGS += -O2
SRCS = $(wildcard *.c)
OBJS = $(SRCS:.c=.o)
@ -37,11 +17,11 @@ DEPS = $(OBJS:.o=.d)
build : $(LIBTARGET) $(DYLIBTARGET)
$(LIBTARGET) : $(OBJS)
ar rc $@ $^
ranlib $@
$(AR) rc $@ $^
$(RANLIB) $@
$(DYLIBTARGET) : $(OBJS)
$(CC) -shared ${LDFLAGS} -o $@ $^
$(CC) -shared $(LDFLAGS) -o $@ $^
-include $(DEPS)
@ -56,7 +36,7 @@ clean:
rm -f $(OBJS) $(DYLIBTARGET) $(LIBTARGET)
cleandep: clean
rm -f ${DEPS}
rm -f $(DEPS)
.PHONY: install

View File

@ -1,39 +1,16 @@
include $(IDRIS2_CURDIR)/config.mk
TARGET = libcb
MACHINE := $(shell $(CC) -dumpmachine)
ifneq (,$(findstring cygwin, $(MACHINE)))
OS := windows
SHLIB_SUFFIX := .dll
else ifneq (,$(findstring mingw, $(MACHINE)))
OS := windows
SHLIB_SUFFIX := .dll
else ifneq (,$(findstring windows, $(MACHINE)))
OS := windows
SHLIB_SUFFIX := .dll
else ifneq (,$(findstring darwin, $(MACHINE)))
OS := darwin
SHLIB_SUFFIX := .dylib
CFLAGS += -fPIC
else
OS := unix
SHLIB_SUFFIX := .so
CFLAGS += -fPIC
endif
CFLAGS := -Wall -Wextra $(CFLAGS)
LDFLAGS := $(LDFLAGS)
SRCS = $(wildcard *.c)
OBJS = $(SRCS:.c=.o)
DEPS = $(OBJS:.o=.d)
all: ${TARGET}$(SHLIB_SUFFIX)
all: $(TARGET)$(SHLIB_SUFFIX)
$(TARGET)$(SHLIB_SUFFIX): $(OBJS)
$(CC) -shared ${LDFLAGS} -o $@ $^
$(CC) -shared $(LDFLAGS) -o $@ $^
-include $(DEPS)
@ -48,4 +25,4 @@ clean :
rm -f $(OBJS) $(TARGET)$(SHLIB_SUFFIX)
cleandep: clean
rm -f ${DEPS}
rm -f $(DEPS)

View File

@ -1,39 +1,16 @@
include $(IDRIS2_CURDIR)/config.mk
TARGET = libstruct
MACHINE := $(shell $(CC) -dumpmachine)
ifneq (,$(findstring cygwin, $(MACHINE)))
OS := windows
SHLIB_SUFFIX := .dll
else ifneq (,$(findstring mingw, $(MACHINE)))
OS := windows
SHLIB_SUFFIX := .dll
else ifneq (,$(findstring windows, $(MACHINE)))
OS := windows
SHLIB_SUFFIX := .dll
else ifneq (,$(findstring darwin, $(MACHINE)))
OS := darwin
SHLIB_SUFFIX := .dylib
CFLAGS += -fPIC
else
OS := unix
SHLIB_SUFFIX := .so
CFLAGS += -fPIC
endif
CFLAGS := -Wall -Wextra $(CFLAGS)
LDFLAGS := $(LDFLAGS)
SRCS = $(wildcard *.c)
OBJS = $(SRCS:.c=.o)
DEPS = $(OBJS:.o=.d)
all: ${TARGET}$(SHLIB_SUFFIX)
all: $(TARGET)$(SHLIB_SUFFIX)
$(TARGET)$(SHLIB_SUFFIX): $(OBJS)
$(CC) -shared ${LDFLAGS} -o $@ $^
$(CC) -shared $(LDFLAGS) -o $@ $^
-include $(DEPS)
@ -48,4 +25,4 @@ clean :
rm -f $(OBJS) $(TARGET)$(SHLIB_SUFFIX)
cleandep: clean
rm -f ${DEPS}
rm -f $(DEPS)