From be8a957689df312556c97c102a793f4744314771 Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Sun, 29 May 2016 18:35:06 -0400 Subject: [PATCH] Fixed static linking on Windows. --- README.md | 3 ++- build/GNUbasemsvc.mk | 17 +++++++++++++++-- build/GNUmakefile.example | 5 ++++- build/GNUmakefile.test | 14 ++++++++++++-- darwin/spinbox.m | 2 +- doc/static | 1 + examples/example.static.manifest | 32 ++++++++++++++++++++++++++++++++ examples/resources.rc | 4 ++++ test/resources.rc | 4 ++++ test/test.static.manifest | 32 ++++++++++++++++++++++++++++++++ 10 files changed, 107 insertions(+), 7 deletions(-) create mode 100644 doc/static create mode 100644 examples/example.static.manifest create mode 100644 test/test.static.manifest diff --git a/README.md b/README.md index aab21e47..fedc1cc1 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,8 @@ This README is being written.
*Note that today's entry may be updated later today.* * **29 May 2016** - * Thanks to @pcwalton, we can now statically link libui! Simply do `make STATIC=1` instead of just `make`. Right now it only works on GTK+ and OS X. + * Thanks to @pcwalton, we can now statically link libui! Simply do `make STATIC=1` instead of just `make`. + * On Windows you must provide a Common Controls 6 manifest for output static libraries to work properly. * **28 May 2016** * As promised, **the minimum system requirements are now OS X 10.8 and GTK+ 3.10 for OS X and Unix, respectively**. diff --git a/build/GNUbasemsvc.mk b/build/GNUbasemsvc.mk index 0fc5daba..5078ac7c 100644 --- a/build/GNUbasemsvc.mk +++ b/build/GNUbasemsvc.mk @@ -59,16 +59,26 @@ endif OFILES = \ $(subst /,_,$(CFILES)) \ $(subst /,_,$(CXXFILES)) \ - $(subst /,_,$(MFILES)) \ + $(subst /,_,$(MFILES)) +ifeq (,$(STATIC)) +OFILES += \ $(subst /,_,$(RCFILES)) +else +RESFILES = \ + $(subst /,_,$(RCFILES)) +endif OFILES := $(OFILES:%=$(OBJDIR)/%.o) OUT = $(OUTDIR)/$(NAME)$(SUFFIX) +ifneq (,$(STATIC)) +RESOUT = $(OUTDIR)/$(NAME).res +endif +# otherwise keep $(RESOUT) empty # TODO use $(CC), $(CXX), $(LD), and s$(RC) -$(OUT): $(OFILES) | $(OUTDIR) +$(OUT): $(OFILES) $(RESOUT) | $(OUTDIR) ifeq (,$(STATICLIB)) @link -out:$(OUT) $(OFILES) $(LDFLAGS) else @@ -99,6 +109,9 @@ endif $(OBJDIR)/%.rc.o: $$(subst _,/,%).rc $(HFILES) | $(OBJDIR) @rc -nologo -v -fo $@ $(RCFLAGS) $< @echo ====== Compiled $< +$(RESOUT): $$(RCFILES) $(HFILES) | $(OUTDIR) + @rc -nologo -v -fo $@ $(RCFLAGS) $< + @echo ====== Compiled $< $(OBJDIR) $(OUTDIR): @mkdir $@ diff --git a/build/GNUmakefile.example b/build/GNUmakefile.example index e4d14272..83932910 100644 --- a/build/GNUmakefile.example +++ b/build/GNUmakefile.example @@ -23,6 +23,9 @@ HFILES += \ ifeq ($(OS),windows) RCFILES += \ examples/resources.rc +ifneq (,$(STATIC)) +RCFLAGS += -D _UI_STATIC +endif endif NAME = $(EXAMPLE) @@ -49,7 +52,7 @@ else # TODO is there an equivalent to -L? LDFLAGS += $(OUTDIR)/libui.lib else - LDFLAGS += $(OUTDIR)/libui.lib $(NATIVE_UI_LDFLAGS) + LDFLAGS += $(OUTDIR)/libui.lib $(OUTDIR)/libui.res $(OUTDIR)/$(NAME).res $(NATIVE_UI_LDFLAGS) endif endif diff --git a/build/GNUmakefile.test b/build/GNUmakefile.test index c0bc0001..9e123977 100644 --- a/build/GNUmakefile.test +++ b/build/GNUmakefile.test @@ -13,6 +13,12 @@ HFILES += \ NAME = test SUFFIX = $(EXESUFFIX) +ifeq ($(OS),windows) +ifneq (,$(STATIC)) +RCFLAGS += -D _UI_STATIC +endif +endif + ifeq ($(TOOLCHAIN),gcc) ifeq (,$(STATIC)) LDFLAGS += -L$(OUTDIR) -lui @@ -29,8 +35,12 @@ ifeq ($(TOOLCHAIN),gcc) LDFLAGS += -Wl,-rpath,'$$ORIGIN' endif else - # TODO is there an equivalent to -L? - LDFLAGS += $(OUTDIR)/libui.lib + ifeq (,$(STATIC)) + # TODO is there an equivalent to -L? + LDFLAGS += $(OUTDIR)/libui.lib + else + LDFLAGS += $(OUTDIR)/libui.lib $(OUTDIR)/libui.res $(OUTDIR)/$(NAME).res $(NATIVE_UI_LDFLAGS) + endif endif # executables are not shared libraries diff --git a/darwin/spinbox.m b/darwin/spinbox.m index 218d1530..7347ef91 100644 --- a/darwin/spinbox.m +++ b/darwin/spinbox.m @@ -34,7 +34,7 @@ static CGFloat stepperYDelta(void) { // 10.8 - 0 // 10.9 - 0 - // 10.10 - xxx + // 10.10 - -1 // 10.11 - -1 return -1; } diff --git a/doc/static b/doc/static new file mode 100644 index 00000000..de039670 --- /dev/null +++ b/doc/static @@ -0,0 +1 @@ +comctl6 diff --git a/examples/example.static.manifest b/examples/example.static.manifest new file mode 100644 index 00000000..d8e83a83 --- /dev/null +++ b/examples/example.static.manifest @@ -0,0 +1,32 @@ + + + +Your application description here. + + + + + + + + + + + + + + + + diff --git a/examples/resources.rc b/examples/resources.rc index b55e24ec..49f486c1 100644 --- a/examples/resources.rc +++ b/examples/resources.rc @@ -6,4 +6,8 @@ // this is the Common Controls 6 manifest // TODO set up the string values here // 1 is the value of CREATEPROCESS_MANIFEST_RESOURCE_ID and 24 is the value of RT_MANIFEST; we use it directly to avoid needing to share winapi.h with the tests and examples +#ifndef _UI_STATIC 1 24 "example.manifest" +#else +1 24 "example.static.manifest" +#endif diff --git a/test/resources.rc b/test/resources.rc index 11c78a76..ebc5d6e6 100644 --- a/test/resources.rc +++ b/test/resources.rc @@ -6,4 +6,8 @@ // this is the Common Controls 6 manifest // TODO set up the string values here // 1 is the value of CREATEPROCESS_MANIFEST_RESOURCE_ID and 24 is the value of RT_MANIFEST; we use it directly to avoid needing to share winapi.h with the tests and examples +#ifndef _UI_STATIC 1 24 "test.manifest" +#else +1 24 "test.static.manifest" +#endif diff --git a/test/test.static.manifest b/test/test.static.manifest new file mode 100644 index 00000000..d8e83a83 --- /dev/null +++ b/test/test.static.manifest @@ -0,0 +1,32 @@ + + + +Your application description here. + + + + + + + + + + + + + + + +