1*57696d54SAkhilesh Sanikop# Makefile for GPT fdisk 2*57696d54SAkhilesh Sanikop 3*57696d54SAkhilesh Sanikop# Copyright (c) 2022 by Rod Smith 4*57696d54SAkhilesh Sanikop# This program is licensed under the terms of the GNU GPL, version 2, 5*57696d54SAkhilesh Sanikop# or (at your option) any later version. 6*57696d54SAkhilesh Sanikop# You should have received a copy of the GNU General Public License 7*57696d54SAkhilesh Sanikop# along with this program. If not, see <http://www.gnu.org/licenses/>. 8*57696d54SAkhilesh Sanikop 9*57696d54SAkhilesh Sanikop# This is a consolidated Makefile for Linux, FreeBSD, Solaris (untested), 10*57696d54SAkhilesh Sanikop# macOS, and Windows (x86_64 and i686). 11*57696d54SAkhilesh Sanikop 12*57696d54SAkhilesh Sanikop# Builds for host OS by default; pass TARGET={target_os} to cross-compile, 13*57696d54SAkhilesh Sanikop# where {target_os} is one of linux, freebsd, solaris, macos, win32, or win64. 14*57696d54SAkhilesh Sanikop# Appropriate cross-compiler support must be installed, of course, and build 15*57696d54SAkhilesh Sanikop# options below may need to be changed. 16*57696d54SAkhilesh Sanikop 17*57696d54SAkhilesh Sanikop# DETECTED_OS is used both to set certain options for the build 18*57696d54SAkhilesh Sanikop# environment and to determine the default TARGET if it's not 19*57696d54SAkhilesh Sanikop# otherwise specified. 20*57696d54SAkhilesh SanikopDETECTED_OS := $(shell uname -s) 21*57696d54SAkhilesh Sanikop 22*57696d54SAkhilesh Sanikopifeq ($(origin TARGET),undefined) 23*57696d54SAkhilesh Sanikop $(info TARGET is not set; trying to determine target based on host OS....) 24*57696d54SAkhilesh Sanikop $(info Detected OS is $(DETECTED_OS)) 25*57696d54SAkhilesh Sanikop ifeq ($(DETECTED_OS),Linux) 26*57696d54SAkhilesh Sanikop # Note: TARGET is set to "linux", but this is never tested, since it's 27*57696d54SAkhilesh Sanikop # the default. 28*57696d54SAkhilesh Sanikop TARGET=linux 29*57696d54SAkhilesh Sanikop else ifeq ($(DETECTED_OS),Darwin) 30*57696d54SAkhilesh Sanikop TARGET=macos 31*57696d54SAkhilesh Sanikop else ifeq ($(DETECTED_OS),MINGW64_NT-10.0-19042) 32*57696d54SAkhilesh Sanikop # Works for my MSYS2 installation, but seems awfully version-specific 33*57696d54SAkhilesh Sanikop # Also, uname may not exist in some Windows environments. 34*57696d54SAkhilesh Sanikop TARGET=windows 35*57696d54SAkhilesh Sanikop else ifeq ($(DETECTED_OS),FreeBSD) 36*57696d54SAkhilesh Sanikop TARGET=freebsd 37*57696d54SAkhilesh Sanikop else ifeq ($(DETECTED_OS),SunOS) 38*57696d54SAkhilesh Sanikop TARGET=solaris 39*57696d54SAkhilesh Sanikop endif 40*57696d54SAkhilesh Sanikopendif 41*57696d54SAkhilesh Sanikop 42*57696d54SAkhilesh Sanikop# A second way to detect Windows.... 43*57696d54SAkhilesh Sanikopifeq ($(origin TARGET),undefined) 44*57696d54SAkhilesh Sanikop ifeq ($(OS),Windows_NT) 45*57696d54SAkhilesh Sanikop TARGET=windows 46*57696d54SAkhilesh Sanikop endif 47*57696d54SAkhilesh Sanikopendif 48*57696d54SAkhilesh Sanikop 49*57696d54SAkhilesh Sanikop# For Windows, we need to know the bit depth, too 50*57696d54SAkhilesh Sanikopifeq ($(TARGET),windows) 51*57696d54SAkhilesh Sanikop ARCH=$(shell uname -m) 52*57696d54SAkhilesh Sanikop $(info ARCH is $(ARCH)) 53*57696d54SAkhilesh Sanikop ifeq ($(ARCH),x86_64) 54*57696d54SAkhilesh Sanikop TARGET=win64 55*57696d54SAkhilesh Sanikop else ifeq ($(ARCH),i686) 56*57696d54SAkhilesh Sanikop TARGET=win32 57*57696d54SAkhilesh Sanikop else 58*57696d54SAkhilesh Sanikop # In theory, there could be ARM versions, but we aren't set up for them yet; 59*57696d54SAkhilesh Sanikop # also, default to win64 in case uname doesn't exist on the system 60*57696d54SAkhilesh Sanikop TARGET=win64 61*57696d54SAkhilesh Sanikop endif 62*57696d54SAkhilesh Sanikopendif 63*57696d54SAkhilesh Sanikop 64*57696d54SAkhilesh Sanikop$(info Build target is $(TARGET)) 65*57696d54SAkhilesh Sanikop 66*57696d54SAkhilesh Sanikop# Default/Linux settings.... 67*57696d54SAkhilesh SanikopSTRIP?=strip 68*57696d54SAkhilesh Sanikop#CXXFLAGS+=-O2 -Wall -D_FILE_OFFSET_BITS=64 -D USE_UTF16 69*57696d54SAkhilesh SanikopCXXFLAGS+=-O2 -Wall -D_FILE_OFFSET_BITS=64 70*57696d54SAkhilesh SanikopLDFLAGS+= 71*57696d54SAkhilesh SanikopLDLIBS+=-luuid #-licuio -licuuc 72*57696d54SAkhilesh SanikopFATBINFLAGS= 73*57696d54SAkhilesh SanikopTHINBINFLAGS= 74*57696d54SAkhilesh SanikopSGDISK_LDLIBS=-lpopt 75*57696d54SAkhilesh SanikopCGDISK_LDLIBS=-lncursesw 76*57696d54SAkhilesh SanikopLIB_NAMES=crc32 support guid gptpart mbrpart basicmbr mbr gpt bsd parttypes attributes diskio diskio-unix 77*57696d54SAkhilesh SanikopMBR_LIBS=support diskio diskio-unix basicmbr mbrpart 78*57696d54SAkhilesh SanikopALL=gdisk cgdisk sgdisk fixparts 79*57696d54SAkhilesh SanikopFN_EXTENSION= 80*57696d54SAkhilesh Sanikop 81*57696d54SAkhilesh Sanikop# Settings for non-Linux OSes.... 82*57696d54SAkhilesh Sanikopifeq ($(TARGET),win64) 83*57696d54SAkhilesh Sanikop CXX=x86_64-w64-mingw32-g++ 84*57696d54SAkhilesh Sanikop ifeq ($(DETECTED_OS),Linux) 85*57696d54SAkhilesh Sanikop STRIP=x86_64-w64-mingw32-strip 86*57696d54SAkhilesh Sanikop else 87*57696d54SAkhilesh Sanikop STRIP=strip 88*57696d54SAkhilesh Sanikop endif 89*57696d54SAkhilesh Sanikop CXXFLAGS=-O2 -Wall -D_FILE_OFFSET_BITS=64 -static -static-libgcc -static-libstdc++ 90*57696d54SAkhilesh Sanikop #CXXFLAGS=-O2 -Wall -D_FILE_OFFSET_BITS=64 -I /usr/local/include -I/opt/local/include -g 91*57696d54SAkhilesh Sanikop LDFLAGS+=-static -static-libgcc -static-libstdc++ 92*57696d54SAkhilesh Sanikop LDLIBS+=-lrpcrt4 93*57696d54SAkhilesh Sanikop SGDISK_LDLIBS=-lpopt -lintl -liconv 94*57696d54SAkhilesh Sanikop LIB_NAMES=guid gptpart bsd parttypes attributes crc32 mbrpart basicmbr mbr gpt support diskio diskio-windows 95*57696d54SAkhilesh Sanikop MBR_LIBS=support diskio diskio-windows basicmbr mbrpart 96*57696d54SAkhilesh Sanikop FN_EXTENSION=64.exe 97*57696d54SAkhilesh Sanikop ifeq ($(DETECTED_OS),Linux) 98*57696d54SAkhilesh Sanikop # Omit cgdisk when building under Linux for Windows because it doesn't 99*57696d54SAkhilesh Sanikop # work on my system 100*57696d54SAkhilesh Sanikop ALL=gdisk sgdisk fixparts 101*57696d54SAkhilesh Sanikop endif 102*57696d54SAkhilesh Sanikopelse ifeq ($(TARGET),win32) 103*57696d54SAkhilesh Sanikop CXX=i686-w64-mingw32-g++ 104*57696d54SAkhilesh Sanikop ifeq ($(DETECTED_OS),Linux) 105*57696d54SAkhilesh Sanikop STRIP=i686-w64-mingw32-strip 106*57696d54SAkhilesh Sanikop else 107*57696d54SAkhilesh Sanikop STRIP=strip 108*57696d54SAkhilesh Sanikop endif 109*57696d54SAkhilesh Sanikop CXXFLAGS=-O2 -Wall -D_FILE_OFFSET_BITS=64 -static -static-libgcc -static-libstdc++ 110*57696d54SAkhilesh Sanikop #CXXFLAGS=-O2 -Wall -D_FILE_OFFSET_BITS=64 -I /usr/local/include -I/opt/local/include 111*57696d54SAkhilesh Sanikop LDFLAGS+=-static -static-libgcc -static-libstdc++ 112*57696d54SAkhilesh Sanikop LDLIBS+=-lrpcrt4 113*57696d54SAkhilesh Sanikop SGDISK_LDLIBS=-lpopt -lintl -liconv 114*57696d54SAkhilesh Sanikop LIB_NAMES=guid gptpart bsd parttypes attributes crc32 mbrpart basicmbr mbr gpt support diskio diskio-windows 115*57696d54SAkhilesh Sanikop MBR_LIBS=support diskio diskio-windows basicmbr mbrpart 116*57696d54SAkhilesh Sanikop FN_EXTENSION=32.exe 117*57696d54SAkhilesh Sanikop ifeq ($(DETECTED_OS),Linux) 118*57696d54SAkhilesh Sanikop # Omit cgdisk when building for Windows under Linux because it doesn't 119*57696d54SAkhilesh Sanikop # work on my system 120*57696d54SAkhilesh Sanikop ALL=gdisk sgdisk fixparts 121*57696d54SAkhilesh Sanikop endif 122*57696d54SAkhilesh Sanikopelse ifeq ($(TARGET),freebsd) 123*57696d54SAkhilesh Sanikop CXX=clang++ 124*57696d54SAkhilesh Sanikop CXXFLAGS+=-O2 -Wall -D_FILE_OFFSET_BITS=64 -I /usr/local/include 125*57696d54SAkhilesh Sanikop LDFLAGS+=-L/usr/local/lib 126*57696d54SAkhilesh Sanikop LDLIBS+=-luuid #-licuio 127*57696d54SAkhilesh Sanikopelse ifeq ($(TARGET),macos) 128*57696d54SAkhilesh Sanikop FATBINFLAGS=-arch x86_64 -arch arm64 -mmacosx-version-min=10.9 129*57696d54SAkhilesh Sanikop THINBINFLAGS=-arch x86_64 -mmacosx-version-min=10.9 130*57696d54SAkhilesh Sanikop CXXFLAGS=$(FATBINFLAGS) -O2 -Wall -D_FILE_OFFSET_BITS=64 -stdlib=libc++ -I/opt/local/include -I /usr/local/include -I/opt/local/include 131*57696d54SAkhilesh Sanikop LDLIBS= #-licucore 132*57696d54SAkhilesh Sanikop CGDISK_LDLIBS=/usr/local/Cellar/ncurses/6.2/lib/libncurses.dylib 133*57696d54SAkhilesh Sanikopelse ifeq ($(TARGET),solaris) 134*57696d54SAkhilesh Sanikop CXXFLAGS+=-Wall -D_FILE_OFFSET_BITS=64 -I/usr/include/ncurses 135*57696d54SAkhilesh Sanikop LDFLAGS+=-L/lib -licuio -licuuc -luuid 136*57696d54SAkhilesh Sanikopendif 137*57696d54SAkhilesh Sanikop 138*57696d54SAkhilesh Sanikop# More default settings, for all OSes.... 139*57696d54SAkhilesh SanikopLIB_OBJS=$(LIB_NAMES:=.o) 140*57696d54SAkhilesh SanikopMBR_LIB_OBJS=$(MBR_LIBS:=.o) 141*57696d54SAkhilesh SanikopLIB_HEADERS=$(LIB_NAMES:=.h) 142*57696d54SAkhilesh SanikopDEPEND= makedepend $(CXXFLAGS) 143*57696d54SAkhilesh SanikopALL_EXE=$(ALL:=$(FN_EXTENSION)) 144*57696d54SAkhilesh Sanikop 145*57696d54SAkhilesh Sanikopall: $(ALL) 146*57696d54SAkhilesh Sanikop 147*57696d54SAkhilesh Sanikopgdisk: $(LIB_OBJS) gdisk.o gpttext.o 148*57696d54SAkhilesh Sanikop $(CXX) $(LIB_OBJS) gdisk.o gpttext.o $(LDFLAGS) $(LDLIBS) $(FATBINFLAGS) -o gdisk$(FN_EXTENSION) 149*57696d54SAkhilesh Sanikop 150*57696d54SAkhilesh Sanikopcgdisk: $(LIB_OBJS) cgdisk.o gptcurses.o 151*57696d54SAkhilesh Sanikop $(CXX) $(LIB_OBJS) cgdisk.o gptcurses.o $(LDFLAGS) $(LDLIBS) $(CGDISK_LDLIBS) -o cgdisk$(FN_EXTENSION) 152*57696d54SAkhilesh Sanikop 153*57696d54SAkhilesh Sanikopsgdisk: $(LIB_OBJS) sgdisk.o gptcl.o 154*57696d54SAkhilesh Sanikop $(CXX) $(LIB_OBJS) sgdisk.o gptcl.o $(LDFLAGS) $(LDLIBS) $(SGDISK_LDLIBS) $(THINBINFLAGS) -o sgdisk$(FN_EXTENSION) 155*57696d54SAkhilesh Sanikop 156*57696d54SAkhilesh Sanikopfixparts: $(MBR_LIB_OBJS) fixparts.o 157*57696d54SAkhilesh Sanikop $(CXX) $(MBR_LIB_OBJS) fixparts.o $(LDFLAGS) $(FATBINFLAGS) -o fixparts$(FN_EXTENSION) 158*57696d54SAkhilesh Sanikop 159*57696d54SAkhilesh Sanikoptest: 160*57696d54SAkhilesh Sanikop ./gdisk_test.sh 161*57696d54SAkhilesh Sanikop 162*57696d54SAkhilesh Sanikoplint: #no pre-reqs 163*57696d54SAkhilesh Sanikop lint $(SRCS) 164*57696d54SAkhilesh Sanikop 165*57696d54SAkhilesh Sanikopclean: #no pre-reqs 166*57696d54SAkhilesh Sanikop rm -f core *.o *~ $(ALL_EXE) 167*57696d54SAkhilesh Sanikop 168*57696d54SAkhilesh Sanikopstrip: #no pre-reqs 169*57696d54SAkhilesh Sanikop $(STRIP) $(ALL_EXE) 170*57696d54SAkhilesh Sanikop 171*57696d54SAkhilesh Sanikop# what are the source dependencies 172*57696d54SAkhilesh Sanikopdepend: $(SRCS) 173*57696d54SAkhilesh Sanikop $(DEPEND) $(SRCS) 174*57696d54SAkhilesh Sanikop 175*57696d54SAkhilesh Sanikop$(OBJS): 176*57696d54SAkhilesh Sanikop $(CRITICAL_CXX_FLAGS) 177*57696d54SAkhilesh Sanikop 178*57696d54SAkhilesh Sanikop# makedepend dependencies below -- type "makedepend *.cc" to regenerate.... 179*57696d54SAkhilesh Sanikop# DO NOT DELETE 180