Skip to content

Commit d7eb7ae

Browse files
author
Your Name
committed
Updated Makefile, got help from the electrobrain
1 parent 5bbf604 commit d7eb7ae

1 file changed

Lines changed: 81 additions & 103 deletions

File tree

Makefile

Lines changed: 81 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -1,144 +1,122 @@
1-
# make FLAGS=-D__REGRESSION__
21
#c++ -I /opt/homebrew/Cellar/eigen/3.4.0_1/include/ -c -I/Users/fvr124/metaDMG-cpp/htslib regression.cpp -std=c++14 -D__REGRESSION__
32

3+
4+
FLAGS := -O2 -lgsl
5+
CFLAGS := $(FLAGS)
6+
CXXFLAGS := $(FLAGS) -std=c++14
7+
CPPFLAGS := $(CPPFLAGS) -Wall -Wextra
8+
LDFLAGS := $(LDFLAGS)
9+
410
CC ?= gcc
511
CXX ?= g++
612

7-
LIBS = -lz -lm -lbz2 -llzma -lpthread -lcurl -lgsl -lgslcblas
13+
CXXSRC := $(wildcard *.cpp)
14+
CSRC := $(wildcard *.c)
15+
OBJ := $(CSRC:.c=.o) $(CXXSRC:.cpp=.o)
816

9-
CRYPTO_TRY=$(shell echo 'int main(){}'|$(CXX) -x c++ - -lcrypto 2>/dev/null -o /dev/null; echo $$?)
10-
ifeq "$(CRYPTO_TRY)" "0"
11-
$(info Crypto library is available to link; adding -lcrypto to LIBS)
12-
LIBS += -lcrypto
13-
else
14-
$(info Crypto library is not available to link; will not use -lcrypto)
17+
# --- Brugervalgte paths og biblioteker ---
18+
ifdef PREFIX
19+
CPPFLAGS += -I$(PREFIX)/include
20+
LDFLAGS += -L$(PREFIX)/lib
1521
endif
1622

23+
ifdef EXTRA_INC
24+
CPPFLAGS += $(addprefix -I,$(EXTRA_INC))
25+
endif
1726

18-
#if htslib source is defined
19-
ifdef HTSSRC
20-
21-
#if hts source is set to systemwide
22-
ifeq ($(HTSSRC),systemwide)
23-
$(info HTSSRC set to systemwide; assuming systemwide installation)
24-
LIBS += -lhts
27+
ifdef EXTRA_LIB
28+
LDFLAGS += $(addprefix -L,$(EXTRA_LIB))
29+
endif
2530

26-
else
31+
ifdef EXTRA_LIBS
32+
LIBS += $(EXTRA_LIBS)
33+
endif
2734

28-
#if hts source path is given
29-
# Adjust $(HTSSRC) to point to your top-level htslib directory
30-
$(info HTSSRC defined: $(HTSSRC))
31-
CPPFLAGS += -I"$(realpath $(HTSSRC))"
32-
LIBHTS := $(HTSSRC)/libhts.a
33-
LIBS := $(LIBHTS) $(LIBS)
35+
# --- Crypto-detektion ---
36+
HAVE_CRYPTO := $(shell echo 'int main(){}'|$(CXX) -x c++ - -lcrypto -o /dev/null 2>/dev/null && echo 0 || echo 1)
37+
LIBS := -lz -lm -lbz2 -llzma -lpthread -lcurl
3438

39+
ifeq ($(HAVE_CRYPTO),0)
40+
$(info Crypto library is available to link; adding -lcrypto)
41+
LIBS += -lcrypto
42+
else
43+
$(info Crypto library is not available to link; skipping -lcrypto)
3544
endif
3645

37-
#if htssrc not defined
46+
# --- HTSSRC håndtering ---
47+
ifdef HTSSRC
48+
ifeq ($(HTSSRC),systemwide)
49+
$(info HTSSRC set to systemwide; using systemwide installation)
50+
LIBS += -lhts
51+
else
52+
$(info HTSSRC defined: $(HTSSRC))
53+
CPPFLAGS += -I"$(realpath $(HTSSRC))"
54+
LIBHTS := $(HTSSRC)/libhts.a
55+
LIBS := $(LIBHTS) $(LIBS)
56+
endif
3857
else
39-
40-
$(info HTSSRC not defined; using htslib submodule)
41-
$(info Use `make HTSSRC=/path/to/htslib` to build metadamage using a local htslib installation)
42-
$(info Use `make HTSSRC=systemwide` to build metadamage using the systemwide htslib installation)
43-
44-
45-
HTSSRC := $(CURDIR)/htslib
46-
CPPFLAGS += -I$(HTSSRC)
47-
LIBHTS := $(HTSSRC)/libhts.a
48-
LIBS := $(LIBHTS) $(LIBS)
49-
50-
all: .activate_module
51-
58+
$(info HTSSRC not defined; using htslib submodule)
59+
$(info ================================)
60+
$(info Use `make HTSSRC=/path/to/htslib` for custom)
61+
$(info Use `make HTSSRC=systemwide` for system install)
62+
$(info ================================)
63+
HTSSRC := $(CURDIR)/htslib
64+
CPPFLAGS += -I$(HTSSRC)
65+
LIBHTS := $(HTSSRC)/libhts.a
66+
LIBS := $(LIBHTS) $(LIBS)
67+
68+
.PHONY: .activate_module
69+
all: .activate_module
70+
.activate_module:
71+
@git submodule update --init --recursive
72+
@$(MAKE) -C $(HTSSRC)
5273
endif
5374

54-
.PHONY: .activate_module
55-
56-
.activate_module:
57-
git submodule update --init --recursive
58-
$(MAKE) -C $(HTSSRC)
59-
60-
61-
62-
#modied from htslib makefile
63-
FLAGS = -O3
64-
CPPFLAGS := $(filter-out -DNDEBUG,$(CPPFLAGS))
65-
FLAGS2 = $(CPPFLAGS) $(FLAGS) $(LDFLAGS)
66-
67-
CFLAGS := $(FLAGS2) $(CFLAGS)
68-
CXXFLAGS := $(FLAGS2) $(CXXFLAGS)
69-
70-
OPT=-Wl,-O2
71-
# filter -O2 optimization flag CXXFLAGS
72-
CXXFLAGS := $(filter-out -O2,$(CXXFLAGS))
73-
CXXFLAGS := $(subst $(OPT),,$(CXXFLAGS))
74-
75-
CSRC = $(wildcard *.c)
76-
CXXSRC = $(wildcard *.cpp)
77-
OBJ = $(CSRC:.c=.o) $(CXXSRC:.cpp=.o)
78-
79-
prefix = /usr/local
80-
exec_prefix = $(prefix)
81-
bindir = $(exec_prefix)/bin
82-
83-
INSTALL = install
84-
INSTALL_DIR = $(INSTALL) -dm0755
85-
INSTALL_PROGRAM = $(INSTALL) -m0755
86-
87-
PROGRAMS = metaDMG-cpp
88-
89-
all: $(PROGRAMS) misc
90-
91-
PACKAGE_VERSION = 0.4
92-
93-
ifneq "$(wildcard .git)" ""
94-
PACKAGE_VERSION := $(shell git describe --always --dirty)
95-
version.h: $(if $(wildcard version.h),$(if $(findstring "$(PACKAGE_VERSION)",$(shell cat version.h)),,force))
75+
# --- Versionsnummer og version.h ---
76+
PACKAGE_VERSION := 0.4
77+
ifneq ("$(wildcard .git)","")
78+
PACKAGE_VERSION := $(shell git describe --always --dirty)
9679
endif
9780

9881
version.h:
9982
echo '#define METADAMAGE_VERSION "$(PACKAGE_VERSION)"' > $@
10083

101-
.PHONY: all clean install install-all install-misc misc test
84+
# --- Mål og bygning ---
85+
PROGRAM = metaDMG-cpp
86+
87+
all: $(PROGRAM) misc
10288

89+
$(PROGRAM): version.h $(OBJ)
90+
$(CXX) $(CXXFLAGS) $(LDFLAGS) -o $@ $(OBJ) $(LIBS)
91+
92+
.PHONY: misc
10393
misc:
10494
$(MAKE) -C misc HTSSRC="$(realpath $(HTSSRC))"
10595

96+
# --- Automatisk afhængighedshåndtering ---
10697
-include $(OBJ:.o=.d)
10798

10899
%.o: %.c
109-
$(CC) -c $(CFLAGS) $*.c
110-
$(CC) -MM $(CFLAGS) $*.c >$*.d
100+
$(CC) -c $(CPPFLAGS) $(CFLAGS) $< -o $@
101+
$(CC) -MM $(CPPFLAGS) $(CFLAGS) $< > $*.d
111102

112103
%.o: %.cpp
113-
$(CXX) -c $(CXXFLAGS) $*.cpp
114-
$(CXX) -MM $(CXXFLAGS) $*.cpp >$*.d
115-
104+
$(CXX) -c $(CPPFLAGS) $(CXXFLAGS) $< -o $@
105+
$(CXX) -MM $(CPPFLAGS) $(CXXFLAGS) $< > $*.d
116106

117-
metaDMG-cpp: version.h $(OBJ)
118-
$(CXX) $(FLAGS) -o metaDMG-cpp *.o $(LIBS)
107+
# --- Rens og tests ---
108+
.PHONY: clean test testclean force
119109

110+
clean: testclean
111+
rm -f *.o *.d $(PROGRAM) version.h *~
112+
$(MAKE) -C misc clean
120113

121114
testclean:
122-
rm -f test/acc2taxid.map.gzf570b1db7c.dedup.filtered.rname.bam.bin
123-
rm -f test/data/f570b1db7c.dedup.filtered.rname.bam
115+
rm -f test/*.bam.bin test/data/*.bam
124116
rm -rf test/output test/logfile version.h
125117

126-
clean: testclean
127-
rm -f *.o *.d $(PROGRAMS) version.h *~
128-
$(MAKE) -C misc clean
129-
130118
test:
131119
echo "Running unit tests for metaDMG"
132-
cd test;./testAll.sh
120+
cd test && ./testAll.sh
133121

134122
force:
135-
136-
install: all
137-
$(INSTALL_DIR) $(DESTDIR)$(bindir)
138-
$(INSTALL_PROGRAM) $(PROGRAMS) $(DESTDIR)$(bindir)
139-
$(MAKE) -C misc HTSSRC="$(realpath $(HTSSRC))" install
140-
141-
install-misc: misc
142-
$(MAKE) -C misc HTSSRC="$(realpath $(HTSSRC))" install-misc
143-
144-
install-all: install install-misc

0 commit comments

Comments
 (0)