Introduction of unified (multi-OS) Makefile

Forgot something!
This commit is contained in:
Rod Smith
2022-04-12 18:11:23 -04:00
parent b056f3860a
commit 122b58ad82
5 changed files with 233 additions and 36 deletions

147
Makefile
View File

@@ -1,27 +1,159 @@
# Makefile for GPT fdisk
# This program is licensed under the terms of the GNU GPL, version 2,
# or (at your option) any later version.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# This is a consolidated Makefile for Linux, FreeBSD, Solaris (untested),
# macOS, and Windows (x86_64 and i686).
# Builds for host OS by default; pass TARGET={target_os} to cross-compile,
# where {target_os} is one of linux, freebsd, solaris, macos, win32, or win64.
# Appropriate cross-compiler support must be installed, of course, and build
# options below may need to be changed.
# DETECTED_OS is used both to set certain options for the build
# environment and to determine the default TARGET if it's not
# otherwise specified.
DETECTED_OS := $(shell uname -s)
ifeq ($(origin TARGET),undefined)
$(info TARGET is not set; trying to determine target based on host OS....)
$(info Detected OS is $(DETECTED_OS))
ifeq ($(DETECTED_OS),Linux)
# Note: TARGET is set to "linux", but this is never tested, since it's
# the default.
TARGET=linux
else ifeq ($(DETECTED_OS),Darwin)
TARGET=macos
else ifeq ($(DETECTED_OS),MINGW64_NT-10.0-19042)
# Works for my MSYS2 installation, but seems awfully version-specific
# Also, uname may not exist in some Windows environments.
TARGET=windows
else ifeq ($(DETECTED_OS),FreeBSD)
TARGET=freebsd
else ifeq ($(DETECTED_OS),SunOS)
TARGET=solaris
endif
endif
# A second way to detect Windows....
ifeq ($(origin TARGET),undefined)
ifeq ($(OS),Windows_NT)
TARGET=windows
endif
endif
# For Windows, we need to know the bit depth, too
ifeq ($(TARGET),windows)
ARCH=$(shell uname -m)
$(info ARCH is $(ARCH))
ifeq ($(ARCH),x86_64)
TARGET=win64
else ifeq ($(ARCH),i686)
TARGET=win32
else
# In theory, there could be ARM versions, but we aren't set up for them yet;
# also, default to win64 in case uname doesn't exist on the system
TARGET=win64
endif
endif
$(info Build target is $(TARGET))
# Default/Linux settings....
#CXXFLAGS+=-O2 -Wall -D_FILE_OFFSET_BITS=64 -D USE_UTF16
STRIP?=strip
CXXFLAGS+=-O2 -Wall -D_FILE_OFFSET_BITS=64
LDFLAGS+=
LDLIBS+=-luuid #-licuio -licuuc
FATBINFLAGS=
THINBINFLAGS=
SGDISK_LDLIBS=-lpopt
CGDISK_LDLIBS=-lncursesw
LIB_NAMES=crc32 support guid gptpart mbrpart basicmbr mbr gpt bsd parttypes attributes diskio diskio-unix
MBR_LIBS=support diskio diskio-unix basicmbr mbrpart
ALL=gdisk cgdisk sgdisk fixparts
FN_EXTENSION=
# Settings for non-Linux OSes....
ifeq ($(TARGET),win64)
CXX=x86_64-w64-mingw32-g++
ifeq ($(DETECTED_OS),Linux)
STRIP=x86_64-w64-mingw32-strip
else
STRIP=strip
endif
CXXFLAGS=-O2 -Wall -D_FILE_OFFSET_BITS=64 -static -static-libgcc -static-libstdc++
#CXXFLAGS=-O2 -Wall -D_FILE_OFFSET_BITS=64 -I /usr/local/include -I/opt/local/include -g
LDFLAGS+=-static -static-libgcc -static-libstdc++
LDLIBS+=-lrpcrt4
SGDISK_LDLIBS=-lpopt -lintl -liconv
LIB_NAMES=guid gptpart bsd parttypes attributes crc32 mbrpart basicmbr mbr gpt support diskio diskio-windows
MBR_LIBS=support diskio diskio-windows basicmbr mbrpart
FN_EXTENSION=64.exe
ifeq ($(DETECTED_OS),Linux)
# Omit cgdisk when building under Linux for Windows because it doesn't
# work on my system
ALL=gdisk sgdisk fixparts
endif
else ifeq ($(TARGET),win32)
CXX=i686-w64-mingw32-g++
ifeq ($(DETECTED_OS),Linux)
STRIP=i686-w64-mingw32-strip
else
STRIP=strip
endif
CXXFLAGS=-O2 -Wall -D_FILE_OFFSET_BITS=64 -static -static-libgcc -static-libstdc++
#CXXFLAGS=-O2 -Wall -D_FILE_OFFSET_BITS=64 -I /usr/local/include -I/opt/local/include
LDFLAGS+=-static -static-libgcc -static-libstdc++
LDLIBS+=-lrpcrt4
SGDISK_LDLIBS=-lpopt -lintl -liconv
LIB_NAMES=guid gptpart bsd parttypes attributes crc32 mbrpart basicmbr mbr gpt support diskio diskio-windows
MBR_LIBS=support diskio diskio-windows basicmbr mbrpart
FN_EXTENSION=32.exe
ifeq ($(DETECTED_OS),Linux)
# Omit cgdisk when building for Windows under Linux because it doesn't
# work on my system
ALL=gdisk sgdisk fixparts
endif
else ifeq ($(TARGET),freebsd)
CXX=clang++
CXXFLAGS+=-O2 -Wall -D_FILE_OFFSET_BITS=64 -I /usr/local/include
LDFLAGS+=-L/usr/local/lib
LDLIBS+=-luuid #-licuio
else ifeq ($(TARGET),macos)
FATBINFLAGS=-arch x86_64 -arch arm64 -mmacosx-version-min=10.9
THINBINFLAGS=-arch x86_64 -mmacosx-version-min=10.9
CXXFLAGS=$(FATBINFLAGS) -O2 -Wall -D_FILE_OFFSET_BITS=64 -stdlib=libc++ -I/opt/local/include -I /usr/local/include -I/opt/local/include
LDLIBS= #-licucore
CGDISK_LDLIBS=/usr/local/Cellar/ncurses/6.2/lib/libncurses.dylib
else ifeq ($(TARGET),solaris)
CXXFLAGS+=-Wall -D_FILE_OFFSET_BITS=64 -I/usr/include/ncurses
LDFLAGS+=-L/lib -licuio -licuuc -luuid
endif
# More default settings, for all OSes....
LIB_OBJS=$(LIB_NAMES:=.o)
MBR_LIB_OBJS=$(MBR_LIBS:=.o)
LIB_HEADERS=$(LIB_NAMES:=.h)
DEPEND= makedepend $(CXXFLAGS)
ALL_EXE=$(ALL:=$(FN_EXTENSION))
all: cgdisk gdisk sgdisk fixparts
all: $(ALL)
gdisk: $(LIB_OBJS) gdisk.o gpttext.o
$(CXX) $(LIB_OBJS) gdisk.o gpttext.o $(LDFLAGS) $(LDLIBS) -o gdisk
$(CXX) $(LIB_OBJS) gdisk.o gpttext.o $(LDFLAGS) $(LDLIBS) $(FATBINFLAGS) -o gdisk$(FN_EXTENSION)
cgdisk: $(LIB_OBJS) cgdisk.o gptcurses.o
$(CXX) $(LIB_OBJS) cgdisk.o gptcurses.o $(LDFLAGS) $(LDLIBS) -lncursesw -o cgdisk
$(CXX) $(LIB_OBJS) cgdisk.o gptcurses.o $(LDFLAGS) $(LDLIBS) $(CGDISK_LDLIBS) -o cgdisk$(FN_EXTENSION)
sgdisk: $(LIB_OBJS) sgdisk.o gptcl.o
$(CXX) $(LIB_OBJS) sgdisk.o gptcl.o $(LDFLAGS) $(LDLIBS) -lpopt -o sgdisk
$(CXX) $(LIB_OBJS) sgdisk.o gptcl.o $(LDFLAGS) $(LDLIBS) $(SGDISK_LDLIBS) $(THINBINFLAGS) -o sgdisk$(FN_EXTENSION)
fixparts: $(MBR_LIB_OBJS) fixparts.o
$(CXX) $(MBR_LIB_OBJS) fixparts.o $(LDFLAGS) -o fixparts
$(CXX) $(MBR_LIB_OBJS) fixparts.o $(LDFLAGS) $(FATBINFLAGS) -o fixparts$(FN_EXTENSION)
test:
./gdisk_test.sh
@@ -30,7 +162,10 @@ lint: #no pre-reqs
lint $(SRCS)
clean: #no pre-reqs
rm -f core *.o *~ gdisk sgdisk cgdisk fixparts
rm -f core *.o *~ $(ALL_EXE)
strip: #no pre-reqs
$(STRIP) $(ALL_EXE)
# what are the source dependencies
depend: $(SRCS)

46
Makefile.linux Normal file
View File

@@ -0,0 +1,46 @@
CFLAGS+=-D_FILE_OFFSET_BITS=64
#CXXFLAGS+=-Wall -D_FILE_OFFSET_BITS=64 -D USE_UTF16
CXXFLAGS+=-Wall -D_FILE_OFFSET_BITS=64
LDFLAGS+=
LIB_NAMES=crc32 support guid gptpart mbrpart basicmbr mbr gpt bsd parttypes attributes diskio diskio-unix
MBR_LIBS=support diskio diskio-unix basicmbr mbrpart
LIB_OBJS=$(LIB_NAMES:=.o)
MBR_LIB_OBJS=$(MBR_LIBS:=.o)
LIB_HEADERS=$(LIB_NAMES:=.h)
DEPEND= makedepend $(CXXFLAGS)
all: cgdisk gdisk sgdisk fixparts
gdisk: $(LIB_OBJS) gdisk.o gpttext.o
$(CXX) $(LIB_OBJS) gdisk.o gpttext.o $(LDFLAGS) -luuid $(LDLIBS) -o gdisk
# $(CXX) $(LIB_OBJS) gdisk.o gpttext.o $(LDFLAGS) -licuio -licuuc -luuid -o gdisk
cgdisk: $(LIB_OBJS) cgdisk.o gptcurses.o
$(CXX) $(LIB_OBJS) cgdisk.o gptcurses.o $(LDFLAGS) -luuid -lncursesw $(LDLIBS) -o cgdisk
# $(CXX) $(LIB_OBJS) cgdisk.o gptcurses.o $(LDFLAGS) -licuio -licuuc -luuid -lncurses -o cgdisk
sgdisk: $(LIB_OBJS) sgdisk.o gptcl.o
$(CXX) $(LIB_OBJS) sgdisk.o gptcl.o $(LDFLAGS) -luuid -lpopt $(LDLIBS) -o sgdisk
# $(CXX) $(LIB_OBJS) sgdisk.o gptcl.o $(LDFLAGS) -licuio -licuuc -luuid -lpopt -o sgdisk
fixparts: $(MBR_LIB_OBJS) fixparts.o
$(CXX) $(MBR_LIB_OBJS) fixparts.o $(LDFLAGS) $(LDLIBS) -o fixparts
test:
./gdisk_test.sh
lint: #no pre-reqs
lint $(SRCS)
clean: #no pre-reqs
rm -f core *.o *~ gdisk sgdisk cgdisk fixparts
# what are the source dependencies
depend: $(SRCS)
$(DEPEND) $(SRCS)
$(OBJS):
$(CRITICAL_CXX_FLAGS)
# makedepend dependencies below -- type "makedepend *.cc" to regenerate....
# DO NOT DELETE

5
NEWS
View File

@@ -21,6 +21,11 @@
- Fixed bug that caused cgdisk to report incorrect partition attributes.
- Consolidated Makefiles for Linux, FreeBSD, Solaris, macOS, and Windows
(32- and 64-bit). The old OS-specific Makefiles remain in case the new
consolidated Makefile has problems, but the old ones are deprecated.
(The Solaris support in the new Makefile is untested.)
1.0.8 (6/9/2021):
-----------------

44
README
View File

@@ -161,12 +161,12 @@ features of FixParts require elaboration:
Installing
----------
To compile GPT fdisk, you must have appropriate development tools
installed, most notably the GNU Compiler Collection (GCC) and its g++
compiler for C++. I've also tested compilation with Clang, which seems to
work; however, I've not done extensive testing of the resulting binaries,
beyond checking a few basics. Under Windows, Microsoft Visual C++ 2008 can
be used instead. In addition, note these requirements:
To compile GPT fdisk, you must have appropriate development tools installed,
most notably the GNU Compiler Collection (GCC) and its g++ compiler for C++.
I've also tested compilation with Clang, which seems to work; however, I've
not done extensive testing of the resulting binaries, beyond checking a few
basics. See the README.Windows files for additional notes on compiling the
software for Windows. In addition, note these requirements:
* On Linux, FreeBSD, macOS, and Solaris, libuuid must be installed. This is
the standard for Linux and macOS, although you may need to install a
@@ -214,17 +214,27 @@ be used instead. In addition, note these requirements:
When all the necessary development tools and libraries are installed, you
can uncompress the package and type "make" at the command prompt in the
resulting directory. (You must type "make -f Makefile.mac" on macOS, "make
-f Makefile.freebsd" on FreeBSD, "make -f Makefile.solaris" on Solaris, or
"make -f Makefile.mingw" to compile using MinGW for Windows.) You may also
need to add header (include) directories or library directories by setting
the CXXFLAGS environment variable or by editing the Makefile. The result
should be program files called gdisk, cgdisk, sgdisk, and fixparts. Typing
"make gdisk", "make cgdisk", "make sgdisk", or "make fixparts" will compile
only the requested programs. You can use these programs in place or copy the
files to a suitable directory, such as /usr/local/sbin. You can copy the man
pages (gdisk.8, cgdisk.8, sgdisk.8, and fixparts.8) to /usr/local/man/man8
to make them available.
resulting directory. (Beginning with version 1.0.9, GPT fdisk provides a
consolidated Makefile for all supported OSes. Earlier versions used
OS-specific Makefiles, such as Makefile.mac and Makefile.freebsd, which are
still provided, but are deprecated.) You must use GNU make (gmake on
FreeBSD) with this Makefile. You may also need to add header (include)
directories or library directories by setting the CXXFLAGS environment
variable or by editing the Makefile. The result should be program files
called gdisk, cgdisk, sgdisk, and fixparts (or variants with "32.exe" or
"64.exe" added for Windows binaries). Typing "make gdisk", "make cgdisk",
"make sgdisk", or "make fixparts" will compile only the requested programs.
You can use these programs in place or copy the files to a suitable
directory, such as /usr/local/sbin. You can copy the man pages (gdisk.8,
cgdisk.8, sgdisk.8, and fixparts.8) to /usr/local/man/man8 to make them
available.
Cross-compiling is possible, but is not well-tested, except for compiling
Windows binaries on Linux. (See README.Windows for details.) To
cross-compile, specify the TARGET environment variable when launching make,
as in "TARGET=win64 make" to compile for 64-bit (x86-64, X64, AMD64) Windows
on a non-Windows platform. Supported TARGET values are linux, freebsd,
solaris, macos, win32, and win64.
Caveats
-------

View File

@@ -132,8 +132,12 @@ My primary development environment is Ubuntu Linux, using the MinGW
cross-compiler. This system can compile the gdisk and fixparts binaries with
no need for additional libraries; after installing MinGW (via the
g++-mingw-w64 package in Ubuntu, or the equivalent in another distribution),
you can type "make -f Makefile.mingw" to compile 32-bit binaries, and "make
-f Makefile.mingw64" to compile 64-bit binaries.
you can type "TARGET=win32 make" to compile 32-bit binaries, and
"TARGET=win64 make" to compile 64-bit binaries. This will attempt to build
gdisk, sgdisk, and fixparts; but the sgdisk build will fail until you
install the popt libraries, as described shortly. You can build the other
binaries by specifying them, as in "TARGET=win64 make gdisk" to build the
64-bit gdisk binary alone.
If you use Windows, your best bet is likely to be to install the MSYS2
package (https://www.msys2.org). This package provides MinGW and a package
@@ -145,7 +149,11 @@ mingw-w64-x86_64-ncurses" if you want to compile 64-bit binaries; change
library needed by sgdisk and the ncurses library needed by cgdisk, along
with gettext, which is needed by popt. With these libraries installed, you
should be able to compile all four Linux programs -- gdisk, cgdisk, sgdisk,
and fixparts.
and fixparts. Typing "make" alone in the MSYS2 shell should build all four
programs for the host architecture (x86-64 or i686); to compile for the
other architecture, you must specify it with a "TARGET=" specification, as
under Linux. (The Makefile does not currently support ARM64 targets for
Windows.)
If you want to compile sgdisk for Windows under Linux, you can do so;
however, you must copy the relevant header and library files from a Windows
@@ -178,14 +186,7 @@ ncurses version installed in Windows is too new to work with the MinGW
libraries in Ubuntu (20.04 or 22.04). It's conceivable it would work with
another distribution, though.
In any event, the Makefile.mingw and Makefile.mingw64 files contain targets
for all four programs; however, because of the problem building cgdisk in
Linux, that program is omitted from the "all" target. It can still be built
explicitly, though, as in:
make -f Makefile.mingw64 cgdisk
The Makefiles are configured to create statically-linked binaries so as to
The Makefile is configured to create statically-linked binaries so as to
simplify installation of the binaries. If you want smaller binaries, you can
remove the various static options from the relevant Makefile. You can also
strip the binaries ("make -f Makefile.mingw64 strip") to remove unused code.
remove the various static options from the Makefile. You can also strip the
binaries ("make strip") to remove unused code.