From c36d11381c8bed94721ff305df34ff59a78544fb Mon Sep 17 00:00:00 2001 From: Martin Kinkelin Date: Sat, 16 Dec 2023 20:52:22 +0100 Subject: [PATCH] Makefile: Compile zlib .c files with DMD via importC --- Makefile | 44 +++--------------- etc/c/zlib/linux.mak | 95 --------------------------------------- etc/c/zlib/osx.mak | 99 ---------------------------------------- etc/c/zlib/win32.mak | 97 ---------------------------------------- etc/c/zlib/win64.mak | 104 ------------------------------------------- 5 files changed, 6 insertions(+), 433 deletions(-) delete mode 100644 etc/c/zlib/linux.mak delete mode 100644 etc/c/zlib/osx.mak delete mode 100644 etc/c/zlib/win32.mak delete mode 100644 etc/c/zlib/win64.mak diff --git a/Makefile b/Makefile index fc4fe510f59..62df9e62770 100644 --- a/Makefile +++ b/Makefile @@ -101,58 +101,27 @@ else DRUNTIME = $(DRUNTIME_PATH)/../generated/$(OS)/$(BUILD)/$(MODEL)/druntime.lib endif -# Set CC and DMD +# Set 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 CFLAGS -OUTFILEFLAG = -o +# Set extra CFLAGS (for DMD - the zlib .c files are compiled via importC) NODEFAULTLIB=-defaultlib= -debuglib= +CFLAGS=-O -P=-Ietc/c/zlib ifeq (,$(findstring win,$(OS))) - CFLAGS=$(MODEL_FLAG) -fPIC -std=c11 -DHAVE_UNISTD_H + CFLAGS += -P=-DHAVE_UNISTD_H -P=-DHAVE_STDARG_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=-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 + CFLAGS += -P=-DNO_snprintf endif endif @@ -351,8 +320,7 @@ lib: $(LIB) dll: $(ROOT)/libphobos2.so $(ROOT)/%$(DOTOBJ): %.c - @[ -d $(dir $@) ] || mkdir -p $(dir $@) || [ -d $(dir $@) ] - $(CC) -c $(CFLAGS) $< $(OUTFILEFLAG)$@ + $(DMD) -c $(DFLAGS) $(CFLAGS) -of$@ $< $(LIB): $(OBJS) $(ALL_D_FILES) $(DRUNTIME) $(DMD) $(DFLAGS) -lib -of$@ $(DRUNTIME) $(D_FILES) $(OBJS) diff --git a/etc/c/zlib/linux.mak b/etc/c/zlib/linux.mak deleted file mode 100644 index d6d5a77d0db..00000000000 --- a/etc/c/zlib/linux.mak +++ /dev/null @@ -1,95 +0,0 @@ -# Makefile for zlib - -CC=gcc -LD=link -CFLAGS=-I. -O -g -DHAVE_UNISTD_H -DHAVE_STDARG_H -LDFLAGS= -O=.o - -.c.o: - "$(CC)" -c $(CFLAGS) $* - -.d.o: - "$(DMD)" -c $(DFLAGS) $* - -# variables -OBJS = adler32$(O) compress$(O) crc32$(O) deflate$(O) gzclose$(O) gzlib$(O) gzread$(O) \ - gzwrite$(O) infback$(O) inffast$(O) inflate$(O) inftrees$(O) trees$(O) uncompr$(O) zutil$(O) - -all: zlib.a example infcover minigzip - -adler32.o: zutil.h zlib.h zconf.h - "$(CC)" -c $(CFLAGS) $*.c - -zutil.o: zutil.h zlib.h zconf.h - "$(CC)" -c $(CFLAGS) $*.c - -gzclose.o: zlib.h zconf.h gzguts.h - "$(CC)" -c $(CFLAGS) $*.c - -gzlib.o: zlib.h zconf.h gzguts.h - "$(CC)" -c $(CFLAGS) $*.c - -gzread.o: zlib.h zconf.h gzguts.h - "$(CC)" -c $(CFLAGS) $*.c - -gzwrite.o: zlib.h zconf.h gzguts.h - "$(CC)" -c $(CFLAGS) $*.c - -compress.o: zlib.h zconf.h - "$(CC)" -c $(CFLAGS) $*.c - -uncompr.o: zlib.h zconf.h - "$(CC)" -c $(CFLAGS) $*.c - -crc32.o: zutil.h zlib.h zconf.h crc32.h - "$(CC)" -c $(CFLAGS) $*.c - -deflate.o: deflate.h zutil.h zlib.h zconf.h - "$(CC)" -c $(CFLAGS) $*.c - -infback.o: zutil.h zlib.h zconf.h inftrees.h inflate.h inffast.h inffixed.h - "$(CC)" -c $(CFLAGS) $*.c - -inflate.o: zutil.h zlib.h zconf.h inftrees.h inflate.h inffast.h inffixed.h - "$(CC)" -c $(CFLAGS) $*.c - -inffast.o: zutil.h zlib.h zconf.h inftrees.h inflate.h inffast.h - "$(CC)" -c $(CFLAGS) $*.c - -inftrees.o: zutil.h zlib.h zconf.h inftrees.h - "$(CC)" -c $(CFLAGS) $*.c - -trees.o: deflate.h zutil.h zlib.h zconf.h trees.h - "$(CC)" -c $(CFLAGS) $*.c - - -example.o: test/example.c zlib.h zconf.h - "$(CC)" -c $(cvarsdll) $(CFLAGS) test/$*.c - -infcover.o: test/infcover.c zlib.h zconf.h - "$(CC)" -c $(cvarsdll) $(CFLAGS) test/$*.c - -minigzip.o: test/minigzip.c zlib.h zconf.h - "$(CC)" -c $(cvarsdll) $(CFLAGS) test/$*.c - -zlib.a: $(OBJS) - ar -r $@ $(OBJS) - -example: example.o zlib.a - "$(CC)" $(LDFLAGS) -o $@ example.o zlib.a - -infcover: infcover.o zlib.a - "$(CC)" $(LDFLAGS) -o $@ infcover.o zlib.a - -minigzip: minigzip.o zlib.a - "$(CC)" $(LDFLAGS) -o $@ minigzip.o zlib.a - -test: example infcover minigzip - ./example - ./infcover - echo hello world | ./minigzip | ./minigzip -d - -clean: - $(RM) $(OBJS) zlib.a example.o example infcover.o infcover minigzip.o minigzip foo.gz - diff --git a/etc/c/zlib/osx.mak b/etc/c/zlib/osx.mak deleted file mode 100644 index cee494754a6..00000000000 --- a/etc/c/zlib/osx.mak +++ /dev/null @@ -1,99 +0,0 @@ -# Makefile for zlib - -CC=gcc -LD=link -CFLAGS=-I. -O -g -DHAVE_UNISTD_H -DHAVE_STDARG_H -ifeq (64,$(MODEL)) - CFLAGS+=--target=x86_64-darwin-apple # ARM cpu is not supported by dmd -endif - -LDFLAGS= -O=.o - -.c.o: - "$(CC)" -c $(CFLAGS) $* - -.d.o: - "$(DMD)" -c $(DFLAGS) $* - -# variables -OBJS = adler32$(O) compress$(O) crc32$(O) deflate$(O) gzclose$(O) gzlib$(O) gzread$(O) \ - gzwrite$(O) infback$(O) inffast$(O) inflate$(O) inftrees$(O) trees$(O) uncompr$(O) zutil$(O) - -all: zlib.a example infcover minigzip - -adler32.o: zutil.h zlib.h zconf.h - "$(CC)" -c $(CFLAGS) $*.c - -zutil.o: zutil.h zlib.h zconf.h - "$(CC)" -c $(CFLAGS) $*.c - -gzclose.o: zlib.h zconf.h gzguts.h - "$(CC)" -c $(CFLAGS) $*.c - -gzlib.o: zlib.h zconf.h gzguts.h - "$(CC)" -c $(CFLAGS) $*.c - -gzread.o: zlib.h zconf.h gzguts.h - "$(CC)" -c $(CFLAGS) $*.c - -gzwrite.o: zlib.h zconf.h gzguts.h - "$(CC)" -c $(CFLAGS) $*.c - -compress.o: zlib.h zconf.h - "$(CC)" -c $(CFLAGS) $*.c - -uncompr.o: zlib.h zconf.h - "$(CC)" -c $(CFLAGS) $*.c - -crc32.o: zutil.h zlib.h zconf.h crc32.h - "$(CC)" -c $(CFLAGS) $*.c - -deflate.o: deflate.h zutil.h zlib.h zconf.h - "$(CC)" -c $(CFLAGS) $*.c - -infback.o: zutil.h zlib.h zconf.h inftrees.h inflate.h inffast.h inffixed.h - "$(CC)" -c $(CFLAGS) $*.c - -inflate.o: zutil.h zlib.h zconf.h inftrees.h inflate.h inffast.h inffixed.h - "$(CC)" -c $(CFLAGS) $*.c - -inffast.o: zutil.h zlib.h zconf.h inftrees.h inflate.h inffast.h - "$(CC)" -c $(CFLAGS) $*.c - -inftrees.o: zutil.h zlib.h zconf.h inftrees.h - "$(CC)" -c $(CFLAGS) $*.c - -trees.o: deflate.h zutil.h zlib.h zconf.h trees.h - "$(CC)" -c $(CFLAGS) $*.c - - -example.o: test/example.c zlib.h zconf.h - "$(CC)" -c $(cvarsdll) $(CFLAGS) test/$*.c - -infcover.o: test/infcover.c zlib.h zconf.h - "$(CC)" -c $(cvarsdll) $(CFLAGS) test/$*.c - -minigzip.o: test/minigzip.c zlib.h zconf.h - "$(CC)" -c $(cvarsdll) $(CFLAGS) test/$*.c - -zlib.a: $(OBJS) - ar -r $@ $(OBJS) - -example: example.o zlib.a - "$(CC)" $(LDFLAGS) -o $@ example.o zlib.a - -infcover: infcover.o zlib.a - "$(CC)" $(LDFLAGS) -o $@ infcover.o zlib.a - -minigzip: minigzip.o zlib.a - "$(CC)" $(LDFLAGS) -o $@ minigzip.o zlib.a - -test: example infcover minigzip - ./example - ./infcover - echo hello world | ./minigzip | ./minigzip -d - -clean: - $(RM) $(OBJS) zlib.a example.o example infcover.o infcover minigzip.o minigzip foo.gz - diff --git a/etc/c/zlib/win32.mak b/etc/c/zlib/win32.mak deleted file mode 100644 index 60dbe1c3dbf..00000000000 --- a/etc/c/zlib/win32.mak +++ /dev/null @@ -1,97 +0,0 @@ -# Makefile for zlib - -CC=dmc -LD=link -LIB=lib -CFLAGS=-I. -o -DNO_snprintf -LDFLAGS= -O=.obj - -# variables - -OBJS = adler32$(O) compress$(O) crc32$(O) deflate$(O) gzclose$(O) gzlib$(O) gzread$(O) \ - gzwrite$(O) infback$(O) inffast$(O) inflate$(O) inftrees$(O) trees$(O) uncompr$(O) zutil$(O) - - -all: zlib.lib example.exe infcover.exe minigzip.exe - -adler32.obj: zutil.h zlib.h zconf.h - "$(CC)" -c $(CFLAGS) $*.c - -zutil.obj: zutil.h zlib.h zconf.h - "$(CC)" -c $(CFLAGS) $*.c - -gzclose.obj: zlib.h zconf.h gzguts.h - "$(CC)" -c $(CFLAGS) $*.c - -gzlib.obj: zlib.h zconf.h gzguts.h - "$(CC)" -c $(CFLAGS) $*.c - -gzread.obj: zlib.h zconf.h gzguts.h - "$(CC)" -c $(CFLAGS) $*.c - -gzwrite.obj: zlib.h zconf.h gzguts.h - "$(CC)" -c $(CFLAGS) $*.c - -compress.obj: zlib.h zconf.h - "$(CC)" -c $(CFLAGS) $*.c - -uncompr.obj: zlib.h zconf.h - "$(CC)" -c $(CFLAGS) $*.c - -crc32.obj: zutil.h zlib.h zconf.h crc32.h - "$(CC)" -c $(CFLAGS) $*.c - -deflate.obj: deflate.h zutil.h zlib.h zconf.h - "$(CC)" -c $(CFLAGS) $*.c - -infback.obj: zutil.h zlib.h zconf.h inftrees.h inflate.h inffast.h inffixed.h - "$(CC)" -c $(CFLAGS) $*.c - -inflate.obj: zutil.h zlib.h zconf.h inftrees.h inflate.h inffast.h inffixed.h - "$(CC)" -c $(CFLAGS) $*.c - -inffast.obj: zutil.h zlib.h zconf.h inftrees.h inflate.h inffast.h - "$(CC)" -c $(CFLAGS) $*.c - -inftrees.obj: zutil.h zlib.h zconf.h inftrees.h - "$(CC)" -c $(CFLAGS) $*.c - -trees.obj: deflate.h zutil.h zlib.h zconf.h trees.h - "$(CC)" -c $(CFLAGS) $*.c - - - -example.obj: test\example.c zlib.h zconf.h - "$(CC)" -c $(cvarsdll) $(CFLAGS) test\$*.c - -infcover.obj: test\infcover.c zlib.h zconf.h - "$(CC)" -c $(cvarsdll) $(CFLAGS) test\$*.c - -minigzip.obj: test\minigzip.c zlib.h zconf.h - "$(CC)" -c $(cvarsdll) $(CFLAGS) test\$*.c - -zlib.lib: $(OBJS) - "$(LIB)" -c zlib.lib $(OBJS) - -example.exe: example.obj zlib.lib - "$(LD)" $(LDFLAGS) example.obj zlib.lib - -infcover.exe: infcover.obj zlib.lib - "$(LD)" $(LDFLAGS) infcover.obj zlib.lib - -minigzip.exe: minigzip.obj zlib.lib - "$(LD)" $(LDFLAGS) minigzip.obj zlib.lib - -test: example.exe infcover.exe minigzip.exe - example - infcover - echo hello world | minigzip | minigzip -d - -clean: - del *.obj - del *.exe - del *.dll - del *.lib - del *.lst - del foo.gz diff --git a/etc/c/zlib/win64.mak b/etc/c/zlib/win64.mak deleted file mode 100644 index 4c19d3d0553..00000000000 --- a/etc/c/zlib/win64.mak +++ /dev/null @@ -1,104 +0,0 @@ -# Makefile for zlib64 - -MODEL=64 - -CC=cl -LD=link -AR=lib - -CFLAGS=/O2 /nologo -LIBFLAGS=/nologo -LDFLAGS=/nologo -O=.obj - -# do not preselect a C runtime (extracted from the line above to make the auto tester happy) -CFLAGS=$(CFLAGS) /Zl /GS- - -# variables - -OBJS = adler32$(O) compress$(O) crc32$(O) deflate$(O) gzclose$(O) gzlib$(O) gzread$(O) \ - gzwrite$(O) infback$(O) inffast$(O) inflate$(O) inftrees$(O) trees$(O) uncompr$(O) zutil$(O) - - -all: zlib$(MODEL).lib example.exe infcover.exe minigzip.exe - -adler32.obj: zutil.h zlib.h zconf.h - "$(CC)" /c $(CFLAGS) $*.c - -zutil.obj: zutil.h zlib.h zconf.h - "$(CC)" /c $(CFLAGS) $*.c - -gzclose.obj: zlib.h zconf.h gzguts.h - "$(CC)" /c $(CFLAGS) $*.c - -gzlib.obj: zlib.h zconf.h gzguts.h - "$(CC)" /c $(CFLAGS) $*.c - -gzread.obj: zlib.h zconf.h gzguts.h - "$(CC)" /c $(CFLAGS) $*.c - -gzwrite.obj: zlib.h zconf.h gzguts.h - "$(CC)" /c $(CFLAGS) $*.c - -compress.obj: zlib.h zconf.h - "$(CC)" /c $(CFLAGS) $*.c - -uncompr.obj: zlib.h zconf.h - "$(CC)" /c $(CFLAGS) $*.c - -crc32.obj: zutil.h zlib.h zconf.h crc32.h - "$(CC)" /c $(CFLAGS) $*.c - -deflate.obj: deflate.h zutil.h zlib.h zconf.h - "$(CC)" /c $(CFLAGS) $*.c - -infback.obj: zutil.h zlib.h zconf.h inftrees.h inflate.h inffast.h inffixed.h - "$(CC)" /c $(CFLAGS) $*.c - -inflate.obj: zutil.h zlib.h zconf.h inftrees.h inflate.h inffast.h inffixed.h - "$(CC)" /c $(CFLAGS) $*.c - -inffast.obj: zutil.h zlib.h zconf.h inftrees.h inflate.h inffast.h - "$(CC)" /c $(CFLAGS) $*.c - -inftrees.obj: zutil.h zlib.h zconf.h inftrees.h - "$(CC)" /c $(CFLAGS) $*.c - -trees.obj: deflate.h zutil.h zlib.h zconf.h trees.h - "$(CC)" /c $(CFLAGS) $*.c - - - -example.obj: test\example.c zlib.h zconf.h - "$(CC)" /c $(cvarsdll) $(CFLAGS) test\$*.c - -infcover.obj: test\infcover.c zlib.h zconf.h - "$(CC)" /c $(cvarsdll) $(CFLAGS) test\$*.c - -minigzip.obj: test\minigzip.c zlib.h zconf.h - "$(CC)" /c $(cvarsdll) $(CFLAGS) test\$*.c - -zlib$(MODEL).lib: $(OBJS) - "$(AR)" $(LIBFLAGS) /OUT:zlib$(MODEL).lib $(OBJS) - -example.exe: example.obj zlib$(MODEL).lib - "$(LD)" $(LDFLAGS) example.obj zlib$(MODEL).lib - -infcover.exe: infcover.obj zlib$(MODEL).lib - "$(LD)" $(LDFLAGS) infcover.obj zlib$(MODEL).lib - -minigzip.exe: minigzip.obj zlib$(MODEL).lib - "$(LD)" $(LDFLAGS) minigzip.obj zlib$(MODEL).lib - -test: example.exe infcover.exe minigzip.exe - example - infcover - echo hello world | minigzip | minigzip -d - -clean: - del *.obj - del *.exe - del *.dll - del *.lib - del *.lst - del foo.gz