From 52537aca8fef6e84e98ff104719ff2ec499bdd37 Mon Sep 17 00:00:00 2001 From: Adam Kolakowski Date: Fri, 29 May 2020 11:30:16 +0200 Subject: [PATCH] Improve Linux build Introduces several improvements to Makefiles: * BUILD=[debug|release] flag with CFLAGS consistent with vcproj * DESTDIR for staged builds * installation paths can be overridden in make arguments * `make install` makes sure install dirs are present * debug build adds GDB debug symbols --- Common/Makefile | 6 ++--- DStarRepeater/Makefile | 8 +++---- DStarRepeater/MakefileGUI | 8 +++---- DStarRepeaterConfig/Makefile | 8 +++---- Data/Makefile | 44 +++++++++++++++++++----------------- GUICommon/Makefile | 3 +-- Makefile | 35 +++++++++++++++++----------- MakefileGUI | 31 +++++++++++++++++-------- 8 files changed, 81 insertions(+), 62 deletions(-) diff --git a/Common/Makefile b/Common/Makefile index 3539288..be27c03 100644 --- a/Common/Makefile +++ b/Common/Makefile @@ -7,8 +7,9 @@ OBJECTS = AMBEFEC.o AnnouncementUnit.o ArduinoController.o BeaconUnit.o Callsign SlowDataDecoder.o SlowDataEncoder.o SoundCardController.o SoundCardReaderWriter.o SplitController.o TCPReaderWriter.o \ Timer.o UDPReaderWriter.o UDRCController.o URIUSBController.o Utils.o -.PHONY: all -all: Common.a +.PHONY: all clean + +all: Common.a Common.a: $(OBJECTS) $(AR) rcs Common.a $(OBJECTS) @@ -19,7 +20,6 @@ Common.a: $(OBJECTS) $(CXX) -DwxUSE_GUI=0 $(CFLAGS) -c -o $@ $< $(CXX) -MM -DwxUSE_GUI=0 $(CFLAGS) $< > $*.d -.PHONY: clean clean: $(RM) Common.a *.o *.d *.bak *~ diff --git a/DStarRepeater/Makefile b/DStarRepeater/Makefile index 8f65cf9..a457108 100644 --- a/DStarRepeater/Makefile +++ b/DStarRepeater/Makefile @@ -1,8 +1,9 @@ OBJECTS = DStarRepeaterApp.o DStarRepeaterLogRedirect.o DStarRepeaterRXThread.o DStarRepeaterStatusData.o \ DStarRepeaterThread.o DStarRepeaterTRXThread.o DStarRepeaterTXRXThread.o DStarRepeaterTXThread.o -.PHONY: all -all: dstarrepeaterd +.PHONY: all install clean + +all: dstarrepeaterd dstarrepeaterd: $(OBJECTS) ../Common/Common.a $(CXX) $(OBJECTS) ../Common/Common.a $(LDFLAGS) $(LIBS) -o dstarrepeaterd @@ -13,9 +14,8 @@ dstarrepeaterd: $(OBJECTS) ../Common/Common.a $(CXX) -DwxUSE_GUI=0 $(CFLAGS) -I../Common -c -o $@ $< $(CXX) -MM -DwxUSE_GUI=0 $(CFLAGS) -I../Common $< > $*.d -.PHONY: install install: - install -g bin -o root -m 0775 dstarrepeaterd $(BINDIR) + install -g root -o root -m 0755 dstarrepeaterd $(DESTDIR)$(BINDIR) clean: $(RM) dstarrepeaterd *.o *.d *.bak *~ diff --git a/DStarRepeater/MakefileGUI b/DStarRepeater/MakefileGUI index 9df8212..50494b7 100644 --- a/DStarRepeater/MakefileGUI +++ b/DStarRepeater/MakefileGUI @@ -1,7 +1,9 @@ OBJECTS = DStarRepeaterApp.o DStarRepeaterFrame.o DStarRepeaterLogRedirect.o DStarRepeaterRXThread.o DStarRepeaterStatusData.o \ DStarRepeaterThread.o DStarRepeaterTRXThread.o DStarRepeaterTXRXThread.o DStarRepeaterTXThread.o -all: dstarrepeater +.PHONY: install clean + +all: dstarrepeater dstarrepeater: $(OBJECTS) ../Common/Common.a ../GUICommon/GUICommon.a $(CXX) $(OBJECTS) ../Common/Common.a ../GUICommon/GUICommon.a $(LDFLAGS) $(GUILIBS) -o dstarrepeater @@ -10,11 +12,9 @@ dstarrepeater: $(OBJECTS) ../Common/Common.a ../GUICommon/GUICommon.a $(CXX) $(CFLAGS) -I../Common -I../GUICommon -c -o $@ $< $(CXX) -MM $(CFLAGS) -I../Common -I../GUICommon $< > $*.d -.PHONY: install install: - install -g bin -o root -m 0775 dstarrepeater $(BINDIR) + install -g root -o root -m 0755 dstarrepeater $(DESTDIR)$(BINDIR) -.PHONY: clean clean: $(RM) dstarrepeater *.o *.d *.bak *~ diff --git a/DStarRepeaterConfig/Makefile b/DStarRepeaterConfig/Makefile index b74b9e5..7b1d453 100644 --- a/DStarRepeaterConfig/Makefile +++ b/DStarRepeaterConfig/Makefile @@ -5,8 +5,8 @@ OBJECTS = DStarRepeaterConfigActiveHangSet.o DStarRepeaterConfigAnnouncementSet. DStarRepeaterConfigIcomSet.o DStarRepeaterConfigMMDVMSet.o DStarRepeaterConfigModemSet.o DStarRepeaterConfigNetworkSet.o \ DStarRepeaterConfigSoundCardSet.o DStarRepeaterConfigSplitSet.o DStarRepeaterConfigTimesSet.o -.PHONY: all -all: dstarrepeaterconfig +.PHONY: all install clean +all: dstarrepeaterconfig dstarrepeaterconfig: $(OBJECTS) ../GUICommon/GUICommon.a ../Common/Common.a $(CXX) $(OBJECTS) ../GUICommon/GUICommon.a ../Common/Common.a $(LDFLAGS) $(GUILIBS) -o dstarrepeaterconfig @@ -17,11 +17,9 @@ dstarrepeaterconfig: $(OBJECTS) ../GUICommon/GUICommon.a ../Common/Common.a $(CXX) $(CFLAGS) -I../GUICommon -I../Common -c -o $@ $< $(CXX) -MM $(CFLAGS) -I../GUICommon -I../Common $< > $*.d -.PHONY: install install: - install -g bin -o root -m 0775 dstarrepeaterconfig $(BINDIR) + install -g root -o root -m 0755 dstarrepeaterconfig $(DESTDIR)$(BINDIR) -.PHONY: install clean: $(RM) dstarrepeaterconfig *.o *.d *.bak *~ diff --git a/Data/Makefile b/Data/Makefile index 698a52a..d55feed 100644 --- a/Data/Makefile +++ b/Data/Makefile @@ -1,22 +1,24 @@ +.PHONY: install + install: - install -d -g bin -o root -m 0775 $(DATADIR) - install -g bin -o root -m 0664 de_DE.ambe $(DATADIR) - install -g bin -o root -m 0664 de_DE.indx $(DATADIR) - install -g bin -o root -m 0664 dk_DK.ambe $(DATADIR) - install -g bin -o root -m 0664 dk_DK.indx $(DATADIR) - install -g bin -o root -m 0664 en_GB.ambe $(DATADIR) - install -g bin -o root -m 0664 en_GB.indx $(DATADIR) - install -g bin -o root -m 0664 en_US.ambe $(DATADIR) - install -g bin -o root -m 0664 en_US.indx $(DATADIR) - install -g bin -o root -m 0664 es_ES.ambe $(DATADIR) - install -g bin -o root -m 0664 es_ES.indx $(DATADIR) - install -g bin -o root -m 0664 fr_FR.ambe $(DATADIR) - install -g bin -o root -m 0664 fr_FR.indx $(DATADIR) - install -g bin -o root -m 0664 it_IT.ambe $(DATADIR) - install -g bin -o root -m 0664 it_IT.indx $(DATADIR) - install -g bin -o root -m 0664 no_NO.ambe $(DATADIR) - install -g bin -o root -m 0664 no_NO.indx $(DATADIR) - install -g bin -o root -m 0664 pl_PL.ambe $(DATADIR) - install -g bin -o root -m 0664 pl_PL.indx $(DATADIR) - install -g bin -o root -m 0664 se_SE.ambe $(DATADIR) - install -g bin -o root -m 0664 se_SE.indx $(DATADIR) + install -d -g root -o root -m 0755 $(DESTDIR)$(DATADIR) + install -g root -o root -m 0644 de_DE.ambe $(DESTDIR)$(DATADIR) + install -g root -o root -m 0644 de_DE.indx $(DESTDIR)$(DATADIR) + install -g root -o root -m 0644 dk_DK.ambe $(DESTDIR)$(DATADIR) + install -g root -o root -m 0644 dk_DK.indx $(DESTDIR)$(DATADIR) + install -g root -o root -m 0644 en_GB.ambe $(DESTDIR)$(DATADIR) + install -g root -o root -m 0644 en_GB.indx $(DESTDIR)$(DATADIR) + install -g root -o root -m 0644 en_US.ambe $(DESTDIR)$(DATADIR) + install -g root -o root -m 0644 en_US.indx $(DESTDIR)$(DATADIR) + install -g root -o root -m 0644 es_ES.ambe $(DESTDIR)$(DATADIR) + install -g root -o root -m 0644 es_ES.indx $(DESTDIR)$(DATADIR) + install -g root -o root -m 0644 fr_FR.ambe $(DESTDIR)$(DATADIR) + install -g root -o root -m 0644 fr_FR.indx $(DESTDIR)$(DATADIR) + install -g root -o root -m 0644 it_IT.ambe $(DESTDIR)$(DATADIR) + install -g root -o root -m 0644 it_IT.indx $(DESTDIR)$(DATADIR) + install -g root -o root -m 0644 no_NO.ambe $(DESTDIR)$(DATADIR) + install -g root -o root -m 0644 no_NO.indx $(DESTDIR)$(DATADIR) + install -g root -o root -m 0644 pl_PL.ambe $(DESTDIR)$(DATADIR) + install -g root -o root -m 0644 pl_PL.indx $(DESTDIR)$(DATADIR) + install -g root -o root -m 0644 se_SE.ambe $(DESTDIR)$(DATADIR) + install -g root -o root -m 0644 se_SE.indx $(DESTDIR)$(DATADIR) diff --git a/GUICommon/Makefile b/GUICommon/Makefile index 7c7c0c9..6fb4eb7 100644 --- a/GUICommon/Makefile +++ b/GUICommon/Makefile @@ -1,6 +1,6 @@ OBJECTS = AddressTextCtrl.o CallsignTextCtrl.o MessageTextCtrl.o PortTextCtrl.o RestrictedTextCtrl.o -.PHONY: all +.PHONY: all clean all: GUICommon.a GUICommon.a: $(OBJECTS) @@ -12,7 +12,6 @@ GUICommon.a: $(OBJECTS) $(CXX) $(CFLAGS) -c -o $@ $< $(CXX) -MM $(CFLAGS) $< > $*.d -.PHONY: clean clean: $(RM) GUICommon.a *.o *.d *.bak *~ diff --git a/Makefile b/Makefile index f0b05bc..cdb6df6 100644 --- a/Makefile +++ b/Makefile @@ -1,20 +1,29 @@ -export DATADIR := "/usr/share/dstarrepeater" -export LOGDIR := "/var/log" -export CONFDIR := "/etc" -export BINDIR := "/usr/bin" - +.PHONY: install installdirs clean force +export BUILD ?= debug +export DATADIR ?= /usr/share/dstarrepeater +export LOGDIR ?= /var/log +export CONFDIR ?= /etc +export BINDIR ?= /usr/bin + +DEBUGFLAGS := -g -D_DEBUG +RELEASEFLAGS := -DNDEBUG -DwxDEBUG_LEVEL=0 export CXX := $(shell wx-config --cxx) -export CFLAGS := -O2 -Wall $(shell wx-config --cxxflags) -DLOG_DIR='$(LOGDIR)' -DCONF_DIR='$(CONFDIR)' -DDATA_DIR='$(DATADIR)' +export CFLAGS := -O2 -Wall $(shell wx-config --cxxflags) -DLOG_DIR='"$(LOGDIR)"' -DCONF_DIR='"$(CONFDIR)"' -DDATA_DIR='"$(DATADIR)"' +ifeq ($(BUILD), debug) + export CFLAGS := $(CFLAGS) $(DEBUGFLAGS) +else ifeq ($(BUILD), release) + export CFLAGS := $(CFLAGS) $(RELEASEFLAGS) +endif export GUILIBS := $(shell wx-config --libs adv,core,base) -lasound export LIBS := $(shell wx-config --libs base) -lasound -lusb-1.0 export LDFLAGS := -all: DStarRepeater/dstarrepeaterd DStarRepeaterConfig/dstarrepeaterconfig +all: DStarRepeater/dstarrepeaterd DStarRepeaterConfig/dstarrepeaterconfig -DStarRepeater/dstarrepeaterd: Common/Common.a force +DStarRepeater/dstarrepeaterd: Common/Common.a force $(MAKE) -C DStarRepeater -DStarRepeaterConfig/dstarrepeaterconfig: GUICommon/GUICommon.a Common/Common.a force +DStarRepeaterConfig/dstarrepeaterconfig: GUICommon/GUICommon.a Common/Common.a force $(MAKE) -C DStarRepeaterConfig GUICommon/GUICommon.a: force @@ -23,19 +32,19 @@ GUICommon/GUICommon.a: force Common/Common.a: force $(MAKE) -C Common -.PHONY: install -install: all +installdirs: + /bin/mkdir -p $(DESTDIR)$(DATADIR) $(DESTDIR)$(LOGDIR) $(DESTDIR)$(CONFDIR) $(DESTDIR)$(BINDIR) + +install: all installdirs $(MAKE) -C Data install $(MAKE) -C DStarRepeater install $(MAKE) -C DStarRepeaterConfig install -.PHONY: clean clean: $(MAKE) -C Common clean $(MAKE) -C GUICommon clean $(MAKE) -C DStarRepeater clean $(MAKE) -C DStarRepeaterConfig clean -.PHONY: force force: @true diff --git a/MakefileGUI b/MakefileGUI index 67f33ff..7e20f01 100644 --- a/MakefileGUI +++ b/MakefileGUI @@ -1,15 +1,26 @@ -export DATADIR := "/usr/share/dstarrepeater" -export LOGDIR := "/var/log" -export CONFDIR := "/etc" -export BINDIR := "/usr/bin" +export BUILD ?= debug +export DATADIR ?= /usr/share/dstarrepeater +export LOGDIR ?= /var/log +export CONFDIR ?= /etc +export BINDIR ?= /usr/bin + +DEBUGFLAGS := -g -D_DEBUG +RELEASEFLAGS := -DNDEBUG -DwxDEBUG_LEVEL=0 export CXX := $(shell wx-config --cxx) -export CFLAGS := -O2 -Wall $(shell wx-config --cxxflags) -DLOG_DIR='$(LOGDIR)' -DCONF_DIR='$(CONFDIR)' -DDATA_DIR='$(DATADIR)' +export CFLAGS := -O2 -Wall $(shell wx-config --cxxflags) -DLOG_DIR='"$(LOGDIR)"' -DCONF_DIR='"$(CONFDIR)"' -DDATA_DIR='"$(DATADIR)"' +ifeq ($(BUILD), debug) + export CFLAGS := $(CFLAGS) $(DEBUGFLAGS) +else ifeq ($(BUILD), release) + export CFLAGS := $(CFLAGS) $(RELEASEFLAGS) +endif export GUILIBS := $(shell wx-config --libs adv,core,base) -lasound -lusb-1.0 export LIBS := $(shell wx-config --libs base) -lasound -lusb-1.0 export LDFLAGS := -all: DStarRepeater/dstarrepeater DStarRepeaterConfig/dstarrepeaterconfig +.PHONY: install installdirs clean force + +all: DStarRepeater/dstarrepeater DStarRepeaterConfig/dstarrepeaterconfig DStarRepeater/dstarrepeater: GUICommon/GUICommon.a Common/Common.a force $(MAKE) -C DStarRepeater -f MakefileGUI @@ -23,19 +34,19 @@ GUICommon/GUICommon.a: force Common/Common.a: force $(MAKE) -C Common -.PHONY: install -install: all +installdirs: + /bin/mkdir -p $(DESTDIR)$(DATADIR) $(DESTDIR)$(LOGDIR) $(DESTDIR)$(CONFDIR) $(DESTDIR)$(BINDIR) + +install: all installdirs $(MAKE) -C Data install $(MAKE) -C DStarRepeater -f MakefileGUI install $(MAKE) -C DStarRepeaterConfig install -.PHONY: clean clean: $(MAKE) -C Common clean $(MAKE) -C GUICommon clean $(MAKE) -C DStarRepeater -f MakefileGUI clean $(MAKE) -C DStarRepeaterConfig clean -.PHONY: force force: @true