Skip to content

Commit

Permalink
buildsystem refacor & added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Michał Szymaniak committed Jun 10, 2017
1 parent 6073c9c commit ccd3cbd
Show file tree
Hide file tree
Showing 55 changed files with 529 additions and 118 deletions.
9 changes: 5 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
*.bak
*.vim
.grip
grip
egrip
fgrip
gripgen
/src/grip/grip
/src/grip/egrip
/src/grip/fgrip
/src/gripgen/gripgen
/src/test/test
tags
2 changes: 1 addition & 1 deletion doc/INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ You may need to add `-pthread` to `BOOST_LDFLAGS` if you are linking against mul
### Configuration
Makefile accepts several configuration variables:
* `STATIC=yes` - static linking with libraries;
* `USE_BOOST=yes/mt/manual` - use boost library instead of POSIX functions, `mt` should be used against multi-threaded boost build, `manual` allows to configure compiler and linker flags manualli with `BOOST_CXXFLAGS` and `BOOST_LDFLAGS`;
* `USE_BOOST=yes/manual` - use boost library instead of POSIX functions, `manual` allows to configure compiler and linker flags manualli with `BOOST_CXXFLAGS` and `BOOST_LDFLAGS`;
* `CXX` - override compiler program;
* `CXXFLAGS` and `LDFLAGS` - override compiler and linker flags.

Expand Down
145 changes: 32 additions & 113 deletions src/Makefile
Original file line number Diff line number Diff line change
@@ -1,52 +1,49 @@
PREFIX ?= /usr/local
OBJDIR ?= obj

ifeq ($(OS),Windows_NT)
SUFFIX ?= .exe
RM = cmd /C del /Q
RM = scripts\rm.cmd
MKDIR = scripts\mkdir.cmd
INSTALL = scripts\install.cmd
else
MKDIR = mkdir -p
INSTALL = install -m 0755
endif

CXXFLAGS ?= \
--std=c++11 \
-Wall \
-Wextra \
-pedantic \
-pthread \
-I. \

LDFLAGS ?= \
--std=c++11 \
-pthread \

ifdef STATIC
LDFLAGS += \
-static \
-static-libgcc \
-static-libstdc++ \
LDFLAGS += \
-static \
-static-libgcc \
-static-libstdc++ \

endif

ifdef USE_BOOST
CXXFLAGS += -DUSE_BOOST
CXXFLAGS += -DUSE_BOOST
endif

ifeq ($(USE_BOOST),yes)
LDFLAGS += \
-lboost_regex \
-lboost_system \
-lboost_filesystem \

endif

ifeq ($(USE_BOOST),mt)
LDFLAGS += \
-lboost_regex \
-lboost_system \
-lboost_filesystem \
LDFLAGS += \
-lboost_regex \
-lboost_system \
-lboost_filesystem \

endif

ifeq ($(USE_BOOST),manual)
CXXFLAGS += $(BOOST_CXXFLAGS)
LDFLAGS += $(BOOST_LDFLAGS)
CXXFLAGS += $(BOOST_CXXFLAGS)
LDFLAGS += $(BOOST_LDFLAGS)
endif

VERSION ?= $(shell git describe --tags)
Expand All @@ -55,104 +52,26 @@ ifneq ($(VERSION), )
endif


TARGETS = \
grip \
egrip \
fgrip \
gripgen \

SOURCES = \
indexer.cpp \
dbreader.cpp \
sortdb.cpp \
filelist.cpp \
ids.cpp \
compressedids.cpp \
grep.cpp \
file.cpp \
fileline.cpp \
print.cpp \
dir.cpp \
dir-posix.cpp \
dir-boost.cpp \
glob.cpp \
pattern.cpp \
node.cpp \
error.cpp \

HEADERS = \
indexer.h \
dbreader.h \
filelist.h \
ids.h \
compressedids.h \
grep.h \
index.h \
file.h \
fileline.h \
print.h \
dir.h \
glob.h \
pattern.h \
globfilters.def \
node.h \
case.h \
queue.h \
sem.h \
config.h \
error.h \

EXTERNAL = \
external/fnmatch.c \
external/fnmatch.h \
external/ansidecl.h \
external/getopt.c \
external/getopt.h \
external/getopt1.c \

OBJECTS = $(SOURCES:.cpp=.o)

TOBJECTS = $(TARGETS:=.o)

TFILES = $(TARGETS:=$(SUFFIX))

all: release

debug: CXXFLAGS += -O0 -g
debug: $(TFILES)

release: CXXFLAGS += -O3 -DNDEBUG
release: $(TFILES)

clean:
$(RM) $(TFILES)
$(RM) $(TOBJECTS)
$(RM) $(OBJECTS)
include general/general.mk
include grip/grip.mk
include gripgen/gripgen.mk
include test/test.mk


$(TFILES): %: $(OBJECTS)
$(CXX) -o $@ $^ $(LDFLAGS)

grip$(SUFFIX): grip.o

egrip$(SUFFIX): egrip.o
egrip.o: grip.cpp

fgrip$(SUFFIX): fgrip.o
fgrip.o: grip.cpp

gripgen$(SUFFIX): gripgen.o

%.o: %.cpp $(HEADERS) $(EXTERNAL)
$(CXX) -c -o $@ $< $(CXXFLAGS)
release: $(TARGETS)
release: CXXFLAGS += -O3 -DNDEBUG

debug: $(TARGETS)
debug: CXXFLAGS += -O0 -g

install: $(TFILES)
install -m 0755 $^ $(PREFIX)/bin
install: $(TARGETS)
$(MKDIR) $(PREFIX)/bin
$(INSTALL) $^ $(PREFIX)/bin

uninstall:
$(RM) $(addprefix $(PREFIX)/bin/, $(TFILES))

$(RM) $(addprefix $(PREFIX)/bin/, $(notdir $(TARGETS)))

.PHONY: all clean debug release install uninstall
.PHONY: all release debug clean install uninstall

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
40 changes: 40 additions & 0 deletions src/general/general.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
GENERAL_SOURCES = \
general/compressedids.cpp \
general/dbreader.cpp \
general/dir-boost.cpp \
general/dir.cpp \
general/dir-posix.cpp \
general/error.cpp \
general/file.cpp \
general/fileline.cpp \
general/filelist.cpp \
general/ids.cpp \
general/node.cpp \
general/print.cpp \

GENERAL_HEADERS = \
general/case.h \
general/compressedids.h \
general/config.h \
general/dbreader.h \
general/dir.h \
general/error.h \
general/file.h \
general/fileline.h \
general/filelist.h \
general/ids.h \
general/index.h \
general/node.h \
general/print.h \
general/queue.h \
general/sem.h \
external/catch.hpp \
external/fnmatch.c \
external/fnmatch.h \
external/ansidecl.h \
external/getopt.c \
external/getopt.h \
external/getopt1.c \

CXXFLAGS += -Igeneral

3 changes: 3 additions & 0 deletions src/ids.cpp → src/general/ids.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,9 @@ uint32_t *Ids::setData(size_t size)
return m_ids.data();
}

void Ids::validate() const
{}

Ids::iterator Ids::begin()
{
return m_ids.begin();
Expand Down
1 change: 1 addition & 0 deletions src/ids.h → src/general/ids.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class Ids
const_iterator begin() const;
const_iterator end() const;

void validate() const;
private:
std::vector<uint32_t> m_ids;
};
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
48 changes: 48 additions & 0 deletions src/grip/grip.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
GRIP_DIR = grip

GRIP_TARGETS = \
$(GRIP_DIR)/grip$(SUFFIX) \
$(GRIP_DIR)/egrip$(SUFFIX) \
$(GRIP_DIR)/fgrip$(SUFFIX) \

TARGETS += $(GRIP_TARGETS)

GRIP_SOURCES = \
$(GRIP_DIR)/glob.cpp \
$(GRIP_DIR)/grep.cpp \
$(GRIP_DIR)/pattern.cpp \
$(GENERAL_SOURCES) \

GRIP_HEADERS = \
$(GRIP_DIR)/glob.h \
$(GRIP_DIR)/grep.h \
$(GRIP_DIR)/pattern.h \
$(GENERAL_HEADERS) \

GRIP_CXXFLAGS = \
$(CXXFLAGS) \

GRIP_OBJDIR = $(OBJDIR)/$(GRIP_DIR)
GRIP_OBJDIRS = $(sort $(dir $(GRIP_OBJECTS) $(GRIP_TOBJECTS)))
GRIP_OBJECTS = $(addprefix $(GRIP_OBJDIR)/, $(GRIP_SOURCES:.cpp=.o))
GRIP_TOBJECTS = $(addprefix $(GRIP_OBJDIR)/, $(GRIP_TARGETS:$(SUFFIX)=.o))


$(GRIP_TARGETS): %$(SUFFIX): $(GRIP_OBJDIR)/%.o $(GRIP_OBJECTS)
$(CXX) -o $@ $^ $(LDFLAGS)

$(GRIP_OBJECTS) $(GRIP_TOBJECTS): $(GRIP_OBJDIR)/%.o: %.cpp $(GRIP_HEADERS) | $(GRIP_OBJDIRS)
$(CXX) -c -o $@ $< $(GRIP_CXXFLAGS)

$(GRIP_OBJDIRS):
$(MKDIR) $@

grip-clean:
$(RM) $(GRIP_TARGETS)
$(RM) $(GRIP_TOBJECTS)
$(RM) $(GRIP_OBJECTS)

clean: grip-clean

.PHONY: grip-clean

File renamed without changes.
File renamed without changes.
File renamed without changes.
45 changes: 45 additions & 0 deletions src/gripgen/gripgen.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
GEN_DIR = gripgen
GEN_TARGET = $(GEN_DIR)/gripgen$(SUFFIX)
TARGETS += $(GEN_TARGET)

GEN_SOURCES = \
$(GEN_DIR)/gripgen.cpp \
$(GEN_DIR)/indexer.cpp \
$(GEN_DIR)/sortdb.cpp \
$(GENERAL_SOURCES) \

GEN_HEADERS = \
$(GEN_DIR)/indexer.h \
$(GENERAL_HEADERS) \

GEN_CXXFLAGS = \
$(CXXFLAGS) \
-pthread \

GEN_LDFLAGS = \
$(LDFLAGS) \
-pthread \


GEN_OBJDIR = $(OBJDIR)/$(GEN_DIR)
GEN_OBJDIRS = $(sort $(dir $(GEN_OBJECTS)))
GEN_OBJECTS = $(addprefix $(GEN_OBJDIR)/, $(GEN_SOURCES:.cpp=.o))


$(GEN_TARGET): $(GEN_OBJECTS)
$(CXX) -o $@ $^ $(GEN_LDFLAGS)

$(GEN_OBJECTS): $(GEN_OBJDIR)/%.o: %.cpp $(GEN_HEADERS) | $(GEN_OBJDIRS)
$(CXX) -c -o $@ $< $(GEN_CXXFLAGS)

$(GEN_OBJDIRS):
$(MKDIR) $@

gripgen-clean:
$(RM) $(GEN_TARGET)
$(RM) $(GEN_OBJECTS)

clean: gripgen-clean

.PHONY: gripgen-clean

File renamed without changes.
File renamed without changes.
File renamed without changes.
10 changes: 10 additions & 0 deletions src/scripts/install.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
@echo off
for %%a in (%*) do set "dst=%%a"
set "dst=%dst:/=\%"

:loop
set "src=%1"
set "src=%src:/=\%"
copy "%src%" %dst%"
shift
if not "%~2"=="" goto loop
7 changes: 7 additions & 0 deletions src/scripts/mkdir.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
@echo off
:loop
set "p=%1"
set "p=%p:/=\%"
if not exist "%p%" mkdir "%p%"
shift
if not "%~1"=="" goto loop
7 changes: 7 additions & 0 deletions src/scripts/rm.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
@echo off
:loop
set "p=%1"
set "p=%p:/=\%"
if exist "%p%" del /Q "%p%"
shift
if not "%~1"=="" goto loop
Loading

0 comments on commit ccd3cbd

Please sign in to comment.