Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
khalid
radsex
Commits
632ae061
Commit
632ae061
authored
Feb 24, 2020
by
RomainFeron
Browse files
Better makefile
parent
c8b7db83
Changes
1
Hide whitespace changes
Inline
Side-by-side
makefile
View file @
632ae061
...
...
@@ -2,58 +2,87 @@
CC
=
g++
OPTCFLAGS
=
-O2
CFLAGS
=
-Wall
-Wno-maybe-uninitialized
-std
=
c++11
$(OPTCFLAGS)
LDFLAGS
=
-pthread
-
static-libstdc
++
-lz
LDFLAGS
=
-pthread
-
lstdc
++
-lz
-L
$(INCLUDE)
/bwa
-lbwa
# Directory organisation
BASEDIR
=
.
BIN
=
$(BASEDIR)
/bin
BUILD
=
$(BASEDIR)
/build
LIBBUILD
=
$(BASEDIR)
/build
INCLUDE
=
$(BASEDIR)
/include
SRC
=
$(BASEDIR)
/src
CPP
=
$(
wildcard
$(SRC)
/
*
.cpp
)
$(
wildcard
$(SRC)
/
*
/
*
.cpp
)
LIBCPP
=
$(
wildcard
$(INCLUDE)
/
*
/
*
.cpp
)
BWAC
=
$(
wildcard
$(INCLUDE)
/bwa/
*
.c
)
CPP
=
$(
wildcard
$(SRC)
/
*
.cpp
)
# Target
TARGET
=
radsex
# Get number of parallel jobs
MAKE_PID
:=
$(
shell
echo
$$
PPID
)
JOBS
:=
$(
shell
ps T |
sed
-n
's/.*
$(MAKE_PID)
.*
$(MAKE)
.* \(-j\|--jobs\) *\([0-9][0-9]*\).*/\2/p'
)
ifeq
($(JOBS),)
JOBS
:=
1
endif
#
Variab
les
#
Object files inferred from cpp fi
les
OBJS
=
$(
addprefix
$(BUILD)
/,
$(
notdir
$(CPP:.cpp=.o)
))
LIBOBJS
=
$(LIBCPP:.cpp=.o)
BWAOBJS
=
$(BWAC:.c=.o)
# Rules
# Target
TARGETS
=
$(BIN)
/radsex
# Declare phony targets (i.e. targets which are not files)
.PHONY
:
all clean clean-bwa clean-kfun clean-all rebuild rebuild-all
all
:
init BWA $(TARGET)
# Main rule
all
:
$(BUILD) $(BIN) $(TARGETS)
print-%
:
; @echo $* = $($*)
# Build directory
$(BUILD)
:
if
[
!
-e
$@
]
;
then
\
mkdir
$@
;
\
fi
;
BWA
:
@
cd
$(INCLUDE)
/bwa
&&
$(MAKE)
# Bin directory
$(BIN)
:
if
[
!
-e
$@
]
;
then
\
mkdir
$@
;
\
fi
;
$(TARGET)
:
$(OBJS) $(LIBOBJS) $(BWAOBJS) $(INCLUDE)/bwa/libbwa.a
$(CC)
$(CFLAGS)
-I
$(INCLUDE)
-L
$(INCLUDE)
/bwa
-lbwa
-o
$(BIN)
/
$(TARGET)
$^
$(LDFLAGS)
# Build BWA
$(INCLUDE)/bwa/libbwa.a
:
(
cd
$(INCLUDE)
/bwa
&&
$(MAKE)
-j
$(JOBS)
)
$(BUILD)/%.o
:
$(SRC)/%.cpp
$(CC)
$(CFLAGS)
-I
$(INCLUDE)
-c
-o
$@
$^
# Clean BWA
clean-bwa
:
(
cd
$(INCLUDE)
/bwa
&&
$(MAKE)
clean
)
$(LIBBUILD)/%.o
:
$(INCLUDE)/*/%.cpp
# Build kfun
$(INCLUDE)/kfun/kfun.o
:
$(INCLUDE)/kfun/kfun.cpp
$(CC)
$(CFLAGS)
-I
$(INCLUDE)
-c
-o
$@
$^
# Clean BWA
clean-kfun
:
(
rm
$(INCLUDE)
/kfun/kfun.o
)
# Clean RADSex files
clean
:
@
rm
-rf
$(BUILD)
/
*
.o
@
rm
-rf
$(BIN)
/
$(TARGET)
rm
-rf
$(BUILD)
/
*
.o
rm
-rf
$(BIN)
/
*
# Clean all files
clean-all
:
clean clean-bwa clean-kfun
# Rebuild RADSex only
rebuild
:
$(MAKE)
clean
$(MAKE)
-j
$(JOBS)
clean-all
:
clean
@
rm
-rf
$(INCLUDE)
/
*
/
*
.o
@
cd
$(INCLUDE)
/bwa
&&
$(MAKE)
clean
# Rebuild RADSex and dependencies
rebuild-all
:
$(MAKE)
clean-all
$(MAKE)
-j
$(JOBS)
rebuild
:
clean $(TARGET)
# Linking
$(BIN)/radsex
:
$(OBJS) $(INCLUDE)/kfun/kfun.o
$(CC)
$(CFLAGS)
-I
$(INCLUDE)
-o
$(BIN)
/radsex
$^
$(LDFLAGS)
rebuild-all
:
clean-all BWA $(TARGET)
# Build a single object file. Added libs as dependency so they are built before object files
$(BUILD)/%.o
:
$(SRC)/%.cpp $(INCLUDE)/bwa/libbwa.a
$(CC)
$(CFLAGS)
-I
$(INCLUDE)
-c
-o
$@
$<
init
:
@
mkdir
-p
$(BUILD)
$(BUILD)
@
mkdir
-p
$(BIN)
$(BIN)
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment