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