fastp icon indicating copy to clipboard operation
fastp copied to clipboard

Makefile enhancements

Open outpaddling opened this issue 6 years ago • 1 comments

The patch below adds DESTDIR support and an install-strip target. This will facilitate installing fastp via package managers, most of which can use these features by default.

Also suggesting a slightly cleaner way to amend CXXFLAGS, but it works for me either way.

It was pretty easy already, though - thanks for making fastp simple and portable to begin with!

--- Makefile.orig	2019-04-17 03:23:22 UTC
+++ Makefile
@@ -3,9 +3,11 @@ DIR_SRC := ./src
 DIR_OBJ := ./obj
 
 PREFIX ?= /usr/local
+DESTDIR ?=
 BINDIR ?= $(PREFIX)/bin
 INCLUDE_DIRS ?=
 LIBRARY_DIRS ?=
+STRIP_CMD ?= strip
 
 SRC := $(wildcard ${DIR_SRC}/*.cpp)
 OBJ := $(patsubst %.cpp,${DIR_OBJ}/%.o,$(notdir ${SRC}))
@@ -15,7 +17,8 @@ TARGET := fastp
 BIN_TARGET := ${TARGET}
 
 CXX ?= g++
-CXXFLAGS := -std=c++11 -g -O3 -I${DIR_INC} $(foreach includedir,$(INCLUDE_DIRS),-I$(includedir)) ${CXXFLAGS}
+CXXFLAGS ?= -g -O3
+CXXFLAGS += -std=c++11 -I${DIR_INC} $(foreach includedir,$(INCLUDE_DIRS),-I$(includedir))
 LIBS := -lz -lpthread
 LD_FLAGS := $(foreach librarydir,$(LIBRARY_DIRS),-L$(librarydir)) $(LIBS) $(LD_FLAGS)
 
@@ -38,5 +41,8 @@ make_obj_dir:
 	fi
 
 install:
-	install $(TARGET) $(BINDIR)/$(TARGET)
+	install $(TARGET) $(DESTDIR)$(BINDIR)/$(TARGET)
 	@echo "Installed."
+
+install-strip: install
+	$(STRIP_CMD) $(DESTDIR)$(BINDIR)/$(TARGET)

outpaddling avatar May 03 '19 13:05 outpaddling

Patches improved and updated for 0.23.1:

--- Makefile.orig       2021-10-19 02:19:29 UTC
+++ Makefile
@@ -2,11 +2,13 @@ DIR_INC := ./inc
 DIR_SRC := ./src
 DIR_OBJ := ./obj
 
-PREFIX ?= /usr/local
-BINDIR ?= $(PREFIX)/bin
-INCLUDE_DIRS ?=
-LIBRARY_DIRS ?=
+PREFIX ?= /usr/local
+BINDIR ?= $(PREFIX)/bin
+INCLUDE_DIRS   ?=
+LIBRARY_DIRS   ?=
 
+STRIP  ?= strip
+
 SRC := $(wildcard ${DIR_SRC}/*.cpp)
 OBJ := $(patsubst %.cpp,${DIR_OBJ}/%.o,$(notdir ${SRC}))
 
@@ -15,15 +17,19 @@ TARGET := fastp
 BIN_TARGET := ${TARGET}
 
 CXX ?= g++
-CXXFLAGS := -std=c++11 -pthread -g -O3 -I${DIR_INC} $(foreach includedir,$(INCLUDE_DIRS),-I$(includedir)) ${CXXFLAGS}
+# Optional flags that the user can override by setting CXXFLAGS in the
+# env or make argument
+CXXFLAGS ?= -g -O3
+# Required flags
+CXXFLAGS += -std=c++11 -I${DIR_INC} $(foreach includedir,$(INCLUDE_DIRS),-I$(includedir))
 LIBS := -lisal -ldeflate -lpthread
 STATIC_FLAGS := -static -Wl,--no-as-needed -pthread
-LD_FLAGS := $(foreach librarydir,$(LIBRARY_DIRS),-L$(librarydir)) $(LIBS) $(LD_FLAGS)
+# Append required flags to standard LDFLAGS from env
+LDFLAGS += $(foreach librarydir,$(LIBRARY_DIRS),-L$(librarydir)) $(LIBS)
 STATIC_LD_FLAGS := $(foreach librarydir,$(LIBRARY_DIRS),-L$(librarydir)) $(STATIC_FLAGS) $(LIBS) $(STATIC_LD_FLAGS)
 
-
 ${BIN_TARGET}:${OBJ}
-       $(CXX) $(OBJ) -o $@ $(LD_FLAGS)
+       $(CXX) $(OBJ) -o $@ $(LDFLAGS)
 
 static:${OBJ}
        $(CXX) $(OBJ) -o ${BIN_TARGET} $(STATIC_LD_FLAGS)
@@ -49,6 +55,11 @@ make_obj_dir:
                mkdir $(DIR_OBJ) ; \
        fi
 
+# Respect DESTDIR for staged installs (used by most package managers)
 install:
-       install $(TARGET) $(BINDIR)/$(TARGET)
+       install $(TARGET) $(DESTDIR)$(BINDIR)/$(TARGET)
        @echo "Installed."
+
+# Many package managers use install-strip target if debugging is not enabled
+install-strip: install
+       $(STRIP) $(DESTDIR)$(BINDIR)/$(TARGET)
--- src/main.cpp.orig   2021-10-19 02:19:29 UTC
+++ src/main.cpp
@@ -1,4 +1,5 @@
 #include <stdio.h>
+#include <sysexits.h>
 #include "fastqreader.h"
 #include "unittest.h"
 #include <time.h>
@@ -18,7 +19,7 @@ int main(int argc, char* argv[]){
     if(argc == 1) {
         cerr << "fastp: an ultra-fast all-in-one FASTQ preprocessor" << endl << "version " << FASTP_VER << endl;
         //cerr << "fastp --help to see the help"<<endl;
-        //return 0;
+        return EX_USAGE;
     }
     if (argc == 2 && strcmp(argv[1], "test")==0){
         UnitTest tester;

outpaddling avatar Oct 20 '21 18:10 outpaddling