Skip to content

Commit

Permalink
Better windows cross-compliation
Browse files Browse the repository at this point in the history
  • Loading branch information
blemasle authored and asalamon74 committed Nov 28, 2020
1 parent 5033404 commit deae2e6
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 59 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/old_releases
*.o
*.o*
*.a
/pktriggercord
/pktriggercord-cli
*~
Expand Down
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ before_script:
script:
- if [[ -n $(make astyle | grep Formatted) ]]; then echo "Code formatting error. Please check astyle"; exit 1; fi
- make android
- make localwin
- make ARCH=Win32
- make ARCH=Win32 dist
- make srczip
- make clean
- make
Expand Down
1 change: 1 addition & 0 deletions Changelog
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ version 0.85.01
remote_bulb_mode_press_press setting (thx blemasle)
Updating lens info database ( exiftool 11.99 )
Testing support for 645Z
Better windows cross-compliation (thx blemasle)

version 0.85.00 ( 2019-JAN-27 )
K-1 battery fields fix
Expand Down
3 changes: 3 additions & 0 deletions INSTALL
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,6 @@ make cli
If you'd like to debug the program you don't have to recompile
just use --debug switch

To crosscompile the Windows version:

ARCH=Win32 make dist
155 changes: 98 additions & 57 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,15 @@ LDFLAGS ?= -lm
MANDIR = $(PREFIX)/share/man
MAN1DIR = $(MANDIR)/man1

LIN_CFLAGS = $(CFLAGS)
LIN_LDFLAGS = $(LDFLAGS)
LOCAL_CFLAGS = $(CFLAGS)
LOCAL_LDFLAGS = $(LDFLAGS)

CLI_CFLAGS=$(LOCAL_CFLAGS)
CLI_LDFLAGS=$(LOCAL_LDFLAGS)

GUI_CFLAGS=$(LOCAL_CFLAGS) $(shell pkg-config --cflags gtk+-2.0 gmodule-2.0) -DGTK_DISABLE_SINGLE_INCLUDES -DGSEAL_ENABLE
#-DGDK_DISABLE_DEPRECATED -DGTK_DISABLE_DEPRECATED
GUI_LDFLAGS=$(LOCAL_LDFLAGS) $(shell pkg-config --libs gtk+-2.0 gmodule-2.0)

VERSION=0.85.01
VERSIONCODE=$(shell echo $(VERSION) | sed s/\\.//g | sed s/^0// )
Expand All @@ -24,7 +31,7 @@ DEBFULLNAME="Andras Salamon"

# variables for RPM/DEB creation
DESTDIR ?=
ARCH=$(shell uname -m)
ARCH ?= $(shell uname -m)

#variables for Android
ANDROID=android
Expand All @@ -33,13 +40,41 @@ ANDROID_PROJECT_NAME = PkTriggerCord
ANDROID_PACKAGE = info.melda.sala.pktriggercord
APK_FILE = $(PROJECT_NAME)-debug.apk

LIN_GUI_LDFLAGS=$(shell pkg-config --libs gtk+-2.0 gmodule-2.0)
LIN_GUI_CFLAGS=$(CFLAGS) $(shell pkg-config --cflags gtk+-2.0 gmodule-2.0) -DGTK_DISABLE_SINGLE_INCLUDES -DGSEAL_ENABLE
#-DGDK_DISABLE_DEPRECATED -DGTK_DISABLE_DEPRECATED

default: cli pktriggercord
CLI_TARGET=pktriggercord-cli
GUI_TARGET=pktriggercord

#variables modification for Windows cross compilation
ifeq ($(ARCH),Win32)
CC=i686-w64-mingw32-gcc
AR=i686-w64-mingw32-ar

LOCAL_CFLAGS+= -mms-bitfields

GUI_CFLAGS=$(LOCAL_CFLAGS) \
-I$(LOCALMINGW)/include/gtk-2.0/ \
-I$(LOCALMINGW)/lib/gtk-2.0/include/ \
-I$(LOCALMINGW)/include/atk-1.0/ \
-I$(LOCALMINGW)/include/cairo/ \
-I$(LOCALMINGW)/include/gdk-pixbuf-2.0/ \
-I$(LOCALMINGW)/include/pango-1.0/ \
-I$(LOCALMINGW)/include/glib-2.0 \
-I$(LOCALMINGW)/lib/glib-2.0/include
GUI_LDFLAGS=-L$(LOCALMINGW)/lib -lgtk-win32-2.0 -lgdk-win32-2.0 -lgdk_pixbuf-2.0 -lgobject-2.0 -lglib-2.0 -lgio-2.0

#some build of MinGW enforce this. Some doesn't. Ensure consistent behaviour
CLI_LDFLAGS+= -Wl,--force-exe-suffix
GUI_LDFLAGS+= -Wl,--force-exe-suffix

CLI_TARGET=pktriggercord-cli.exe
GUI_TARGET=pktriggercord.exe
endif

default: cli gui
ifneq ($(ARCH),Win32)
all: srczip rpm win pktriggercord_commandline.html
cli: pktriggercord-cli
endif
cli: $(CLI_TARGET)
gui: $(GUI_TARGET)

MANS = pktriggercord-cli.1 pktriggercord.1
SRCOBJNAMES = pslr pslr_enum pslr_scsi pslr_lens pslr_model pktriggercord-servermode
Expand All @@ -53,24 +88,52 @@ LOCALMINGW=i686-w64-mingw32
WINGCC=i686-w64-mingw32-gcc
WINMINGW=/usr/i686-w64-mingw32/sys-root/mingw
WINDIR=$(TARDIR)-win
GTK_BUNDLE=gtk+-bundle_2.24.10-20120208_win32.zip

# List of all the dll required to run the GUI on Windows
GUI_WIN_DLLS = \
$(LOCALMINGW)/bin/freetype6.dll \
$(LOCALMINGW)/bin/libfontconfig-1.dll \
$(LOCALMINGW)/bin/libgdk-win32-2.0-0.dll \
$(LOCALMINGW)/bin/libgtk-win32-2.0-0.dll \
$(LOCALMINGW)/bin/libgdk_pixbuf-2.0-0.dll \
$(LOCALMINGW)/bin/libgthread-2.0-0.dll \
$(LOCALMINGW)/bin/libpng14-14.dll \
$(LOCALMINGW)/bin/libgio-2.0-0.dll \
$(LOCALMINGW)/bin/libglib-2.0-0.dll \
$(LOCALMINGW)/bin/libgmodule-2.0-0.dll \
$(LOCALMINGW)/bin/libgobject-2.0-0.dll \
$(LOCALMINGW)/bin/libpango-1.0-0.dll \
$(LOCALMINGW)/bin/libpangowin32-1.0-0.dll \
$(LOCALMINGW)/bin/libpangocairo-1.0-0.dll \
$(LOCALMINGW)/bin/libpangoft2-1.0-0.dll \
$(LOCALMINGW)/bin/libcairo-2.dll \
$(LOCALMINGW)/bin/libatk-1.0-0.dll \
$(LOCALMINGW)/bin/zlib1.dll \
$(LOCALMINGW)/bin/intl.dll \
$(LOCALMINGW)/bin/libexpat-1.dll

pslr.o: pslr_enum.o pslr_scsi.o pslr.c pslr.h

pktriggercord-cli: pktriggercord-cli.c $(OBJS)
$(CC) $(LIN_CFLAGS) $^ -DVERSION='"$(VERSION)"' -o $@ $(LIN_LDFLAGS) -L.
$(CLI_TARGET): pktriggercord-cli.c $(OBJS)
$(CC) $(CLI_CFLAGS) $^ -DVERSION='"$(VERSION)"' -o $@ $(CLI_LDFLAGS) -L.

pslr_scsi.o: pslr_scsi_win.c pslr_scsi_linux.c pslr_scsi_openbsd.c

$(JSONDIR)/js0n.o: $(JSONDIR)/js0n.c $(JSONDIR)/js0n.h
$(CC) $(LIN_CFLAGS) -fPIC -c $< -o $@
$(CC) $(LOCAL_CFLAGS) -fPIC -c $< -o $@

external: $(JSONDIR)/js0n.o

%.o: %.c %.h external
$(CC) $(LIN_CFLAGS) -DPKTDATADIR=\"$(PKTDATADIR)\" -fPIC -c $< -o $@
$(CC) $(LOCAL_CFLAGS) -DPKTDATADIR=\"$(PKTDATADIR)\" -fPIC -c $< -o $@

ifeq ($(ARCH),Win32)
$(GUI_TARGET): $(LOCALMINGW)/include $(LOCALMINGW)/lib
endif

pktriggercord: pktriggercord.c $(OBJS)
$(CC) $(LIN_GUI_CFLAGS) -DVERSION='"$(VERSION)"' -DPKTDATADIR=\"$(PKTDATADIR)\" $^ $(LIN_LDFLAGS) -o $@ $(LIN_GUI_LDFLAGS) -L.
$(GUI_TARGET): pktriggercord.c $(OBJS)
$(CC) $(GUI_CFLAGS) -DVERSION='"$(VERSION)"' -DPKTDATADIR=\"$(PKTDATADIR)\" pktriggercord.c $(OBJS) -o $@ $(GUI_LDFLAGS) -L.

install: pktriggercord-cli pktriggercord
install -d $(DESTDIR)/$(PREFIX)/bin
Expand Down Expand Up @@ -169,54 +232,32 @@ pktriggercord_commandline.html: pktriggercord-cli.1
cat $< | sed s/\\\\-/-/g | groff -man -Thtml -mwww -P "-lr" > $@

# Windows cross-compile
windownload:
$(LOCALMINGW)/download: $(LOCALMINGW)/download/$(GTK_BUNDLE)

$(LOCALMINGW)/download/$(GTK_BUNDLE):
mkdir -p $(LOCALMINGW)/download
wget -N http://ftp.gnome.org/pub/gnome/binaries/win32/gtk+/2.24/gtk+_2.24.10-1_win32.zip -P $(LOCALMINGW)/download
wget -N http://ftp.gnome.org/pub/gnome/binaries/win32/gtk+/2.24/gtk+-dev_2.24.10-1_win32.zip -P $(LOCALMINGW)/download
wget -N http://ftp.gnome.org/pub/gnome/binaries/win32/glib/2.28/glib-dev_2.28.8-1_win32.zip -P $(LOCALMINGW)/download
wget -N http://ftp.gnome.org/pub/gnome/binaries/win32/atk/1.32/atk-dev_1.32.0-2_win32.zip -P $(LOCALMINGW)/download
wget -N http://ftp.gnome.org/pub/gnome/binaries/win32/pango/1.29/pango-dev_1.29.4-1_win32.zip -P $(LOCALMINGW)/download
wget -N http://ftp.gnome.org/pub/gnome/binaries/win32/gdk-pixbuf/2.24/gdk-pixbuf-dev_2.24.0-1_win32.zip -P $(LOCALMINGW)/download
wget -N http://ftp.gnome.org/pub/gnome/binaries/win32/gdk-pixbuf/2.24/gdk-pixbuf_2.24.0-1_win32.zip -P $(LOCALMINGW)/download
wget -N http://ftp.gnome.org/pub/gnome/binaries/win32/dependencies/cairo-dev_1.10.2-2_win32.zip -P $(LOCALMINGW)/download
unzip -o $(LOCALMINGW)/download/gtk+_2.24.10-1_win32.zip -d $(LOCALMINGW)
unzip -o $(LOCALMINGW)/download/gtk+-dev_2.24.10-1_win32.zip -d $(LOCALMINGW)
unzip -o $(LOCALMINGW)/download/glib-dev_2.28.8-1_win32.zip -d $(LOCALMINGW)
unzip -o $(LOCALMINGW)/download/atk-dev_1.32.0-2_win32.zip -d $(LOCALMINGW)
unzip -o $(LOCALMINGW)/download/pango-dev_1.29.4-1_win32.zip -d $(LOCALMINGW)
unzip -o $(LOCALMINGW)/download/gdk-pixbuf-dev_2.24.0-1_win32.zip -d $(LOCALMINGW)
unzip -o $(LOCALMINGW)/download/gdk-pixbuf_2.24.0-1_win32.zip -d $(LOCALMINGW)
unzip -o $(LOCALMINGW)/download/cairo-dev_1.10.2-2_win32.zip -d $(LOCALMINGW)
wget -N https://downloads.sourceforge.net/project/mingw-w64/Toolchains%20targetting%20Win32/Personal%20Builds/rubenvb/gcc-4.7-release/i686-w64-mingw32-gcc-4.7.4-release-linux64_rubenvb.tar.xz -P $(LOCALMINGW)/download
tar xJf $(LOCALMINGW)/download/i686-w64-mingw32-gcc-4.7.4-release-linux64_rubenvb.tar.xz -C $(LOCALMINGW)

localwin: WINMINGW=$(LOCALMINGW)
localwin: WINGCC=$(LOCALMINGW)/mingw32/bin/i686-w64-mingw32-gcc

winobjs:$(SRCOBJNAMES:=.c)
$(foreach srcfile, $(SRCOBJNAMES:=.c), $(WINGCC) -DVERSION='"$(VERSION)"' -DPKTDATADIR=\".\" $(WIN_CFLAGS) -c $(srcfile);)

winexternal: $(JSONDIR)/js0n.c $(JSONDIR)/js0n.h
$(WINGCC) $(WIN_CFLAGS) -c $< -o $(JSONDIR)/js0n.o

win-cli:winobjs winexternal pktriggercord-cli.c pktriggercord_commandline.html
$(WINGCC) -mms-bitfields -DVERSION='"$(VERSION)"' pktriggercord-cli.c $(OBJS) -o pktriggercord-cli.exe $(WIN_CFLAGS) -L.
mkdir -p $(WINDIR)
cp pktriggercord-cli.exe Changelog COPYING pktriggercord_commandline.html $(WINDIR)
cp $(WIN_DLLS_DIR)/*.dll $(WINDIR)
wget -N http://ftp.gnome.org/pub/gnome/binaries/win32/gtk+/2.24/$(GTK_BUNDLE) -P $(LOCALMINGW)/download

win-gui: winobjs
$(WINGCC) -mms-bitfields -DVERSION='"$(VERSION)"' -DPKTDATADIR=\".\" pktriggercord.c $(OBJS) -o pktriggercord.exe $(WIN_GUI_CFLAGS) $(WIN_LDFLAGS) -L.
mkdir -p $(WINDIR)
cp pktriggercord.exe pktriggercord.ui pentax_settings.json Changelog COPYING $(WINDIR)
cp $(WIN_DLLS_DIR)/*.dll $(WINDIR)
$(LOCALMINGW)/include $(LOCALMINGW)/lib: $(LOCALMINGW)/download
unzip -o $(LOCALMINGW)/download/$(GTK_BUNDLE) -d $(LOCALMINGW) $(@:$(LOCALMINGW)/%=%)/**

win: win-cli win-gui
# Extract all the required dlls at once with a grouped target
$(GUI_WIN_DLLS) &: $(LOCALMINGW)/download
unzip -o $(LOCALMINGW)/download/$(GTK_BUNDLE) -d $(LOCALMINGW) $(GUI_WIN_DLLS:$(LOCALMINGW)/%=%)
touch -r $^ $(GUI_WIN_DLLS)

ifeq ($(ARCH),Win32)
dist: pktriggercord_commandline.html $(GUI_WIN_DLLS) $(CLI_TARGET) $(GUI_TARGET)
rm -rf $(WINDIR)
mkdir -p $(WINDIR)
cp $^ $(WINDIR)
cp Changelog COPYING pktriggercord.ui pentax_settings.json $(WINDIR)
rm -f $(WINDIR).zip
zip -rj $(WINDIR).zip $(WINDIR)
rm -r $(WINDIR)

localwin: windownload win
else
dist: rpm
endif

androidclean:
cd $(ANDROID_DIR) && ./gradlew clean
Expand Down

0 comments on commit deae2e6

Please sign in to comment.