summaryrefslogtreecommitdiff
path: root/windows/Makefile.vc
blob: afc0e3c753c7ea4dcbf32da7f17c7c1605962515 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
# To build locally get a copy of the dependancies (http://windows.php.net/downloads/php-sdk/deps/)
# These are the dependencies used by PHP and largely used and tested. These binaries are built using
# the sources available at https://github.com/winlibs
# Then run 'nmake /f windows\Makefile.vc' in MS dev console
# To build tests as well 'nmake /f windows\Makefile.vc all'
# To build tests and execute them 'nmake /f windows\Makefile.vc check'

CC=cl
LD=link
LB=lib

!IFNDEF DEBUG
DEBUG=0
!ENDIF

!IFNDEF WITH_DEVEL
WITH_DEVEL=..\deps
!ENDIF

!IFNDEF WITH_BUILD
WITH_BUILD=..\gdbuild
!ENDIF

LIBGD_SRC_DIR=src
LIBGD_OBJ_DIR=$(WITH_BUILD)
LIBGD_BIN_DIR=$(WITH_BUILD)\bin
LIBGD_TEST_DIR=test

!IFNDEF PLATFORM
PLATFORM=x86
!ENDIF
# detect x64 cross-compiler env
!IF "$(PREFERREDTOOLARCHITECTURE)" == "x64"
PLATFORM=x64
!ENDIF
PLATFORM=$(PLATFORM:X=x)

BUILD_DIR=$(WITH_BUILD)

!MESSAGE library source:  $(LIBGD_SRC_DIR)

GD_DLL=libgd.dll
GD_LIB=libgd_a.lib

SDR=$(BUILD_DIR)^\
TDR=$(BUILD_DIR)\tests^\
TARGETDLL=$(BUILD_DIR)\$(GD_DLL)
TARGETLIB=$(BUILD_DIR)\$(GD_LIB)

LIB_OBJS= \
  $(LIBGD_OBJ_DIR)\gd.obj \
  $(LIBGD_OBJ_DIR)\gdcache.obj \
  $(LIBGD_OBJ_DIR)\gd_color.obj \
  $(LIBGD_OBJ_DIR)\gd_color_match.obj \
  $(LIBGD_OBJ_DIR)\gdfontg.obj \
  $(LIBGD_OBJ_DIR)\gdfontl.obj \
  $(LIBGD_OBJ_DIR)\gdfontmb.obj \
  $(LIBGD_OBJ_DIR)\gdfonts.obj \
  $(LIBGD_OBJ_DIR)\gdfontt.obj \
  $(LIBGD_OBJ_DIR)\gdft.obj \
  $(LIBGD_OBJ_DIR)\gdfx.obj \
  $(LIBGD_OBJ_DIR)\gd_filename.obj \
  $(LIBGD_OBJ_DIR)\gd_filter.obj \
  $(LIBGD_OBJ_DIR)\gd_bmp.obj \
  $(LIBGD_OBJ_DIR)\gd_gd2.obj \
  $(LIBGD_OBJ_DIR)\gd_gd.obj \
  $(LIBGD_OBJ_DIR)\gd_gif_in.obj \
  $(LIBGD_OBJ_DIR)\gd_gif_out.obj \
  $(LIBGD_OBJ_DIR)\gdhelpers.obj \
  $(LIBGD_OBJ_DIR)\gd_io.obj \
  $(LIBGD_OBJ_DIR)\gd_io_dp.obj \
  $(LIBGD_OBJ_DIR)\gd_io_file.obj \
  $(LIBGD_OBJ_DIR)\gd_io_ss.obj \
  $(LIBGD_OBJ_DIR)\gd_jpeg.obj \
  $(LIBGD_OBJ_DIR)\gd_security.obj \
  $(LIBGD_OBJ_DIR)\gd_tga.obj \
  $(LIBGD_OBJ_DIR)\gd_tiff.obj \
  $(LIBGD_OBJ_DIR)\gd_xbm.obj \
  $(LIBGD_OBJ_DIR)\gdkanji.obj \
  $(LIBGD_OBJ_DIR)\gd_nnquant.obj \
  $(LIBGD_OBJ_DIR)\gd_png.obj \
  $(LIBGD_OBJ_DIR)\gd_ss.obj \
  $(LIBGD_OBJ_DIR)\gdtables.obj \
  $(LIBGD_OBJ_DIR)\gd_topal.obj \
  $(LIBGD_OBJ_DIR)\gd_transform.obj \
  $(LIBGD_OBJ_DIR)\gd_wbmp.obj \
  $(LIBGD_OBJ_DIR)\gdxpm.obj \
  $(LIBGD_OBJ_DIR)\wbmp.obj \
  $(LIBGD_OBJ_DIR)\gd_interpolation.obj \
  $(LIBGD_OBJ_DIR)\gd_matrix.obj \
  $(LIBGD_OBJ_DIR)\gd_rotate.obj \
  $(LIBGD_OBJ_DIR)\gd_version.obj \
  $(LIBGD_OBJ_DIR)\gd_crop.obj \
  $(LIBGD_OBJ_DIR)\gd_color_map.obj \
  $(LIBGD_OBJ_DIR)\gd_webp.obj

LIBS=kernel32.lib ole32.lib user32.lib advapi32.lib shell32.lib ws2_32.lib Dnsapi.lib Gdi32.Lib
LIBS_GD=libjpeg_a.lib freetype_a.lib libpng_a.lib libiconv_a.lib  zlib_a.lib libwebp_a.lib libxpm_a.lib

INCLUDES=/Isrc /I$(WITH_DEVEL)\include -I$(WITH_DEVEL)\include\libpng16 -I$(WITH_DEVEL)\include\freetype /Itests /Itests\gdtest -I$(WITH_DEVEL)\include\

LDFLAGS=/nologo /nodefaultlib:libcmt /libpath:$(WITH_DEVEL)\lib /MACHINE:$(PLATFORM)

!IF $(DEBUG)
CFLAGS=/nologo /Qvec-report:1 /MD /TC /Zi /Debug
!ELSE
CFLAGS=/nologo /O2 /Qvec-report:1 /MD /TC
!ENDIF

CFLAGS= $(CFLAGS) \
       /DWIN32=1\
       /D_WIN32=1\
       /DMSWIN32=1\
       /DBGDWIN32=1\
       /DHAVE_FT2BUILD_H=1\
       /DHAVE_GD_H=1\
       /DHAVE_ICONV_H=1\
       /DHAVE_GD_BUNDLED=1\
       /DHAVE_LIBFREETYPE=1\
       /DHAVE_LIBJPEG=1\
       /DHAVE_LIBPNG=1\
	   /DHAVE_LIBWEBP=1\
       /DHAVE_LIBZ=1\
	   /DHAVE_LIBXPM=1\
       $(INCLUDES)

TEST_CFLAGS=$(CFLAGS) /FItest_config.h
TEST_LDFLAGS=$(LDFLAGS) $(SDR)readdir.obj $(SDR)gdtest.obj $(BUILD_DIR)\libgd.lib
TEST_CONFIG=tests\test_config.h
TEST_LIST=$(TDR)testlist.txt
TEST_MK=$(TDR)Maketests.vc

# generate test makefile from TESTS macro
# generate test makefile from TESTS macro
!IF [if not exist $(BUILD_DIR) mkdir $(BUILD_DIR)]
!ENDIF
!IF [if not exist $(TDR) mkdir $(TDR)]
!ENDIF

!IF [$(MAKEDIR)\windows\gentest.bat tests $(BUILD_DIR) "$(TEST_CFLAGS)" "$(TEST_LDFLAGS)" $(CC) $(LD) "$(TEST_MK)" "$(TEST_LIST)"]
!ENDIF

TEST_OBJS=$(TEST_EXES:tests=obj)
TEST_OBJS=$(TEST_OBJS:exe=obj)

# pseudotargets
build_libs: make_dirs $(TARGETDLL) $(TARGETLIB)
all: build_libs build_tests
check: all run_tests

clean:
  @if exist $(SDR) rd $(SDR) /s /q
  @if exist $(TDR) rd $(TDR) /s /q
  @if exist $(BUILD_DIR)\*.exe del $(BUILD_DIR)\*.exe /q
  @if exist tests\test_config.h del tests\test_config.h /q

# helpers

make_dirs:
  @if not exist $(BUILD_DIR) mkdir $(BUILD_DIR)
  @if not exist $(SDR) mkdir $(SDR)

run_tests:
  @cd $(TDR)
  @$(MAKEDIR)\windows\run_tests

# libgd
$(LIBGD_OBJ_DIR):
	@if not exist $(LIBGD_OBJ_DIR) mkdir $(LIBGD_OBJ_DIR)

$(LIBGD_BIN_DIR):
	@if not exist $(LIBGD_BIN_DIR) mkdir $(LIBGD_BIN_DIR)

$(TARGETDLL): $(LIB_OBJS)
  @$(LD) /DLL /OUT:$@ $(LIB_OBJS) $(LIBS_GD) $(LIBS) $(LDFLAGS)

$(TARGETLIB): $(LIB_OBJS)
  @$(LB) /OUT:$@ $(LIB_OBJS) $(LDFLAGS)

{$(LIBGD_SRC_DIR)\}.c{$(LIBGD_OBJ_DIR)\}.obj:
	$(CC) $(CFLAGS) /Fo"$@"  $<

all: $(LIBGD_OBJ_DIR) $(LIBGD_BIN_DIR) $(LIB_OBJS) $(STATICLIB)

.SUFFIXES: .c .obj .res

{$(LIBGD_SRC_DIR)\}.c{$(LIBGD_OBJ_DIR)\}.obj:
	$(CC) $(CFLAGS) /Fo"$@" $<

{src\}.c{$(SDR)}.obj::
    $(CC) $(CFLAGS) /c $< /Fo$(SDR)
  
# tests

!INCLUDE $(TEST_MK)
build_tests: $(TEST_LIST) $(SDR)readdir.obj $(SDR)gdtest.obj $(TEST_EXES)

$(SDR)gdtest.obj: $(TARGETDLL) $(TEST_CONFIG) tests\gdtest\gdtest.c
  @$(CC) $(CFLAGS) /c tests\gdtest\gdtest.c /Fo$(SDR)gdtest.obj

$(SDR)readdir.obj: $(TARGETDLL) $(TEST_CONFIG) tests\gdtest\readdir.c
  @$(CC) $(CFLAGS) /c tests\gdtest\readdir.c /Fo$(SDR)readdir.obj
  
$(TEST_CONFIG):
  @echo #ifndef GD_TEST_CONFIG_H> tests\test_config.h
  @echo #define GD_TEST_CONFIG_H>> tests\test_config.h
  @echo #ifndef GDTEST_TOP_DIR>> tests\test_config.h
  @echo #define GDTEST_TOP_DIR "$(MAKEDIR:\=\\)\\tests">> tests\test_config.h
  @echo #endif>> tests\test_config.h
  @echo #ifndef _WIN32>> tests\test_config.h
  @echo #define snprintf _snprintf>> tests\test_config.h
  @echo #endif>> tests\test_config.h
  @echo #endif>> tests\test_config.h

$(TEST_LIST): $(TARGETDLL)
  if not exist $(TDR) mkdir $(TDR)
  copy $(TARGETDLL) $(TDR)$(GD_DLL)