Skip to content

Commit

Permalink
Merge pull request #8870 from dlang/revert-8865-zlib_importc
Browse files Browse the repository at this point in the history
Revert "Makefile: Compile zlib .c files with DMD via importC"
  • Loading branch information
ibuclaw authored Jan 1, 2024
2 parents 893fb2c + 677ee33 commit 3a24b0e
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 13 deletions.
47 changes: 39 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -101,27 +101,58 @@ else
DRUNTIME = $(DRUNTIME_PATH)/../generated/$(OS)/$(BUILD)/$(MODEL)/druntime.lib
endif

# Set DMD
# Set CC and DMD
ifeq ($(OS),win32wine)
CC = wine dmc.exe
DMD = wine dmd.exe
RUN = wine
else
DMD = $(DMD_DIR)/generated/$(OS)/$(BUILD)/$(MODEL)/dmd$(DOTEXE)
ifeq ($(MODEL),32omf)
CC = dmc
else ifeq ($(OS),windows)
CC = cl.exe
else
CC = cc
endif
RUN =
endif

# Set extra CFLAGS (for DMD - the zlib .c files are compiled via importC)
# Set CFLAGS
OUTFILEFLAG = -o
NODEFAULTLIB=-defaultlib= -debuglib=
CFLAGS=-P=-Ietc/c/zlib
ifeq (,$(findstring win,$(OS)))
CFLAGS += -P=-DHAVE_UNISTD_H
CFLAGS=$(MODEL_FLAG) -fPIC -std=c11 -DHAVE_UNISTD_H
# Bundled with the system library on OSX, and doesn't work with >= MacOS 11
ifneq (osx,$(OS))
NODEFAULTLIB += -L-lpthread -L-lm
endif
ifeq ($(BUILD),debug)
CFLAGS += -g
else
CFLAGS += -O3
endif
else
ifeq ($(MODEL),32omf)
CFLAGS += -P=-DNO_snprintf
CFLAGS=-DNO_snprintf
ifeq ($(BUILD),debug)
CFLAGS += -g
else
CFLAGS += -O
endif
else # win64/win32coff
OUTFILEFLAG = /Fo
CFLAGS += /nologo /Zl /GS-
ifeq ($(BUILD),debug)
CFLAGS += /Z7
else
CFLAGS += /O2
endif
endif
endif
ifeq (osx,$(OS))
ifeq (64,$(MODEL))
CFLAGS+=--target=x86_64-darwin-apple # ARM cpu is not supported by dmd
endif
endif

Expand Down Expand Up @@ -317,9 +348,9 @@ endif
lib: $(LIB)
dll: $(ROOT)/libphobos2.so

# compile zlib .c files via importC; the druntime dependency makes sure DMD has been built
$(ROOT)/%$(DOTOBJ): %.c $(DRUNTIME)
$(DMD) -c $(DFLAGS) $(CFLAGS) -of$@ $<
$(ROOT)/%$(DOTOBJ): %.c
@[ -d $(dir $@) ] || mkdir -p $(dir $@) || [ -d $(dir $@) ]
$(CC) -c $(CFLAGS) $< $(OUTFILEFLAG)$@

$(LIB): $(OBJS) $(ALL_D_FILES) $(DRUNTIME)
$(DMD) $(DFLAGS) -lib -of$@ $(DRUNTIME) $(D_FILES) $(OBJS)
Expand Down
5 changes: 0 additions & 5 deletions etc/c/zlib/gzwrite.c
Original file line number Diff line number Diff line change
Expand Up @@ -465,12 +465,7 @@ int ZEXPORTVA gzprintf(gzFile file, const char *format, ...)
va_list va;
int ret;

// needed on Win64 - MS __va_start intrinsic not supported by importC yet
#if __IMPORTC__
__builtin_va_start(va, format);
#else
va_start(va, format);
#endif
ret = gzvprintf(file, format, va);
va_end(va);
return ret;
Expand Down

0 comments on commit 3a24b0e

Please sign in to comment.