1SHELL = /bin/sh 2 3PREFIX=/usr/local 4INSTDIR=$(DESTDIR)/$(PREFIX)/bin 5MANDIR=$(DESTDIR)/$(PREFIX)/man 6 7EXECS = sg_sense_test sg_queue_tst bsg_queue_tst sg_chk_asc sg_tst_nvme \ 8 sg_tst_ioctl sg_tst_bidi tst_sg_lib sgs_dd sg_tst_excl \ 9 sg_tst_excl2 sg_tst_excl3 sg_tst_context sg_tst_async sgh_dd \ 10 sg_mrq_dd sg_iovec_tst sg_take_snap sg_tst_json_builder 11 12EXTRAS = 13 14BSG_EXTRAS = 15 16 17MAN_PGS = 18MAN_PREF = man8 19 20LARGE_FILE_FLAGS = -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 21 22# For C++/clang testing 23## CC = gcc 24## CXX = g++ 25## CC = clang 26## CXX = clang++ 27 28LD = $(CXX) 29CXXLD = $(CXX) 30 31CPPFLAGS = -iquote ../include -iquote .. -D_REENTRANT $(LARGE_FILE_FLAGS) -DHAVE_CONFIG_H -DHAVE_NVME 32CXXFLAGS = -std=c++11 -pthread -ggdb -O2 -W -Wall -iquote ../include -D_REENTRANT $(LARGE_FILE_FLAGS) 33## CXXFLAGS = -std=c++14 -pthread -ggdb -O2 -W -Wall -iquote ../include -D_REENTRANT $(LARGE_FILE_FLAGS) 34## CXXFLAGS = -std=c++17 -pthread -ggdb -O2 -W -Wall -iquote ../include -D_REENTRANT $(LARGE_FILE_FLAGS) 35## CXXFLAGS = -std=c++20 -pthread -ggdb -O2 -W -Wall -iquote ../include -D_REENTRANT $(LARGE_FILE_FLAGS) 36## CXXFLAGS = -std=c++2a -pthread -ggdb -O2 -W -Wall -iquote ../include -D_REENTRANT $(LARGE_FILE_FLAGS) 37# CPPFLAGS = -iquote ../include -iquote .. -D_REENTRANT $(LARGE_FILE_FLAGS) -DHAVE_CONFIG_H -DHAVE_NVME -DDEBUG 38CFLAGS = -g -O2 -W -Wall 39# CFLAGS = -ggdb -O2 -W -Wall -DDEBUG 40# CFLAGS = -g -O2 -Wall -DSG_KERNEL_INCLUDES 41# CFLAGS = -g -O2 -Wall -pedantic 42# CFLAGS = -Wall -W -pedantic -std=c11 --analyze 43# CFLAGS = -Wall -W -pedantic -std=c++14 -fPIC 44# CFLAGS = -Wall -W -pedantic -std=c++20 45 46LDFLAGS = 47 48LIBFILESOLD = ../lib/sg_lib.o ../lib/sg_lib_data.o ../lib/sg_io_linux.o \ 49 ../lib/sg_json_builder.o ../lib/sg_pr2serr.o 50 51LIBFILESNEW = ../lib/sg_pt_linux_nvme.o ../lib/sg_lib.o ../lib/sg_lib_data.o \ 52 ../lib/sg_pt_linux.o ../lib/sg_io_linux.o \ 53 ../lib/sg_pt_common.o ../lib/sg_cmds_basic.o \ 54 ../lib/sg_cmds_basic2.o ../lib/sg_lib_names.o \ 55 ../lib/sg_json_builder.o ../lib/sg_pr2serr.o 56 57all: $(EXECS) 58 59extras: $(EXTRAS) 60 61bsg: $(BSG_EXTRAS) 62 63 64depend dep: 65 for i in *.c; do $(CC) $(CPPFLAGS) $(INCLUDES) $(CFLAGS) -M $$i; \ 66 done > .depend 67 68clean: 69 /bin/rm -f *.o $(EXECS) $(EXTRAS) $(BSG_EXTRAS) json_writer core .depend 70 71sg_sense_test: sg_sense_test.o $(LIBFILESOLD) 72 $(LD) -o $@ $(LDFLAGS) $^ 73 74sg_queue_tst: sg_queue_tst.o $(LIBFILESOLD) 75 $(LD) -o $@ $(LDFLAGS) $^ 76 77bsg_queue_tst: bsg_queue_tst.o $(LIBFILESOLD) 78 $(LD) -o $@ $(LDFLAGS) $^ 79 80sg_tst_ioctl: sg_tst_ioctl.o $(LIBFILESOLD) 81 $(LD) -o $@ $(LDFLAGS) $^ 82 83# building sg_chk_asc depends on a prior successful make in ../lib 84sg_chk_asc: sg_chk_asc.o ../lib/sg_lib.o ../lib/sg_lib_data.o 85 $(LD) -o $@ $(LDFLAGS) $^ 86 87sg_tst_nvme: sg_tst_nvme.o $(LIBFILESNEW) 88 $(LD) -o $@ $(LDFLAGS) $^ 89 90tst_sg_lib: tst_sg_lib.o $(LIBFILESNEW) 91 $(LD) -o $@ $(LDFLAGS) $^ 92 93sgs_dd: sgs_dd.o $(LIBFILESOLD) 94 $(LD) -o $@ $(LDFLAGS) $^ 95 96sg_tst_bidi: sg_tst_bidi.o $(LIBFILESNEW) 97 $(LD) -o $@ $(LDFLAGS) $^ 98 99sg_tst_excl: sg_tst_excl.o $(LIBFILESNEW) 100 $(CXXLD) -o $@ $(LDFLAGS) -pthread $^ 101 102sg_tst_excl2: sg_tst_excl2.o $(LIBFILESNEW) 103 $(CXXLD) -o $@ $(LDFLAGS) -pthread $^ 104 105sg_tst_excl3: sg_tst_excl3.o $(LIBFILESNEW) 106 $(CXXLD) -o $@ $(LDFLAGS) -pthread $^ 107 108sg_tst_context: sg_tst_context.o $(LIBFILESNEW) 109 $(CXXLD) -o $@ $(LDFLAGS) -pthread $^ 110 111sg_tst_async: sg_tst_async.o $(LIBFILESNEW) 112 $(CXXLD) -o $@ $(LDFLAGS) -pthread $^ 113 114# Next three used to require '-latomic', may not anymore 115sgh_dd: sgh_dd.o $(LIBFILESNEW) 116 $(CXXLD) -o $@ $(LDFLAGS) -pthread $^ 117 118sg_mrq_dd: sg_mrq_dd.o sg_scat_gath.o $(LIBFILESNEW) 119 $(CXXLD) -o $@ $(LDFLAGS) -pthread $^ 120 121sg_iovec_tst: sg_iovec_tst.o sg_scat_gath.o $(LIBFILESNEW) 122 $(CXXLD) -o $@ $(LDFLAGS) -pthread $^ 123 124sg_take_snap: sg_take_snap.o $(LIBFILESNEW) 125 $(LD) -o $@ $(LDFLAGS) $^ 126 127sg_tst_json_builder: sg_tst_json_builder.o $(LIBFILESNEW) 128 $(LD) -o $@ $(LDFLAGS) $^ 129 130 131install: $(EXECS) 132 install -d $(INSTDIR) 133 for name in $^; \ 134 do install -s -o root -g root -m 755 $$name $(INSTDIR); \ 135 done 136 install -d $(MANDIR)/$(MAN_PREF) 137 for mp in $(MAN_PGS); \ 138 do install -o root -g root -m 644 $$mp $(MANDIR)/$(MAN_PREF); \ 139 gzip -9f $(MANDIR)/$(MAN_PREF)/$$mp; \ 140 done 141 142uninstall: 143 dists="$(EXECS)"; \ 144 for name in $$dists; do \ 145 rm -f $(INSTDIR)/$$name; \ 146 done 147 for mp in $(MAN_PGS); do \ 148 rm -f $(MANDIR)/$(MAN_PREF)/$$mp.gz; \ 149 done 150 151# Linux uses GNU make and FreeBSD uses Berkely make. The following lines 152# only work in Linux. Possible solutions in FreeBSD: 153# a) use 'gmake'; b) comment out the next 3 lines, starting with 'ifeq' 154# c) build with 'make -f Makefile.freebsd' 155# In Linux one can install bmake (but that won't help here). 156ifeq (.depend,$(wildcard .depend)) 157include .depend 158endif 159