• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#  Top level GNUmakefile for windows builds
2#
3#  It includes makefiles/*.mk for windows buildtype rules
4#  and sources(windows style makefile). it doesn't depend on
5#  Makerules.env except to get SRCBASE if not yet defined.
6#
7#  $Id: GNUmakefile.inc,v 1.103.50.2 2009/08/18 18:42:30 Exp $
8
9SHELL=bash
10export SHELL
11unexport C_DEFINES
12HOSTNAME=$(shell hostname)
13ERRORS :=
14WARNINGS :=
15comma:= ,
16empty:=
17space:= $(empty) $(empty)
18
19ifdef ECLOUD_BUILD_ID
20  CMDSHELL := $(subst \,/,$(COMSPEC))
21  CMDSTART := $(CMDSHELL) /c start /min /separate
22else # ECLOUD_BUILD_ID
23  CMDSHELL :=
24  CMDSTART :=
25endif # ECLOUD_BUILD_ID
26
27### if SRCBASE is not defined, set it to wherever Makerules.env is found
28ifndef SRCBASE
29    ifneq ($(wildcard ../Makerules.env), )
30	SRCBASE	= ../
31    else
32	ifneq ($(wildcard ../../Makerules.env), )
33		SRCBASE	= ../..
34	else
35	    ifneq ($(wildcard ../../../Makerules.env),)
36		    SRCBASE	= ../../..
37	    else
38		ifneq ($(wildcard ../../../../Makerules.env),)
39			SRCBASE	= ../../../..
40		else
41		ifneq ($(wildcard ../../../../../Makerules.env),)
42		    SRCBASE = ../../../../..
43		else
44		    ifneq ($(wildcard ../../../../../../Makerules.env),)
45			    SRCBASE = ../../../../../..
46		    endif
47	    endif
48		endif
49	    endif
50	endif
51    endif
52endif # ifndef SRCBASE
53
54ifeq ($(strip $(SRCBASE)), )
55    ERRORS += "SRCBASE is not defined!"
56    ERRORS += "This variable must be defined in your sources or GNUsources file,"
57    ERRORS += "or it may be calculated provided you are in a CVS source repository,"
58    ERRORS += "and you are not too far below the root."
59endif
60
61### if TTYPE is not defined, reinvoke this same makefile with TTYPE defined
62###retail:free:   --> $(MAKE) -f $(SRCBASE)/GNUmakefile.inc TTYPE=OPT all
63###debug:checked: --> $(MAKE) -f $(SRCBASE)/GNUmakefile.inc TTYPE=DBG all
64###%:             --> $(MAKE) -f $(SRCBASE)/GNUmakefile.inc TTYPE=DBG MAKECMDGOALS=$@ $@
65
66ifeq ($(origin TTYPE), undefined)
67
68all : debug free
69
70release : all
71
72unexport SRCFILE
73ifndef SRCFILE
74	SRCFILE = ./sources
75endif
76include $(SRCFILE)
77
78#   In some rare instances you may want to have the makefile synthesize
79#   explicit rules for all of your source files.  You must do this if you
80#   are building a target with multiple source files of the same name,
81#   e.g. ./utils.c and ../ntddksim/utils.c.  You might also want to use
82#   this method if you don't want to use VPATHs.
83#
84ifdef USE_SRCRULES
85
86SRCRULES=$(SRCFILE).mk
87SOURCES.CPP	:= $(filter %.cpp %.CPP,$(SOURCES))
88SOURCES.C	:= $(filter %.c %.C,$(SOURCES))
89
90$(SRCRULES) : $(SRCFILE)
91	@echo "building explicit source rules..."
92	@( \
93	echo "# DO NOT EDIT!!!!  DO NOT EDIT!!!!  DO NOT EDIT!!!!"; \
94	echo "# This file is automatically generated."; \
95	echo "#"; \
96	$(foreach f,$(SOURCES.C), echo '$$(OUTDIR_$$(TTYPE))/$(patsubst %.c,%.obj,$(subst /,_,$(f))) : $(f)'; echo '	$$(c-obj-command)'; echo;) \
97	$(foreach f,$(SOURCES.CPP), echo '$$(OUTDIR_$$(TTYPE))/$(patsubst %.cpp,%.obj,$(subst /,_,$(f))) : $(f)'; echo '	$$(cpp-obj-command)'; echo;) \
98	) >$(SRCFILE).mk
99
100$(SRCFILE) :
101	echo making $@
102
103retail free :: $(SRCRULES)
104
105debug checked :: $(SRCRULES)
106
107endif # USE_SRCRULES
108
109#
110# End of rule synthesis section
111#
112
113retail free ::
114	$(MAKE) -f $(SRCBASE)/GNUmakefile.inc TTYPE=OPT all
115
116debug checked ::
117	$(MAKE) -f $(SRCBASE)/GNUmakefile.inc TTYPE=DBG all
118
119%GNUmakefile.inc :
120	echo making $@
121
122GNUmakefile :
123	echo making $@
124
125clean :
126	$(MAKE) -f $(SRCBASE)/GNUmakefile.inc TTYPE=DBG MAKECMDGOALS=$@ $@
127
128## This catch-all generic rule breaks make targets defined in module which
129## call this makefile.
130## % : FORCE
131## 	$(MAKE) -f $(SRCBASE)/GNUmakefile.inc TTYPE=DBG MAKECMDGOALS=$@ $@
132
133.PHONY: all release free checked retail debug clean FORCE
134
135
136### if TTYPE is defined,
137###   define commands, tools and compile rules
138###   include $(SRCFILE)
139###   build all :: target ::
140else # TTYPE is defined
141
142# Define default command for printing errors and warnings.  This will
143# be redefined at the end of this makefile if any errors or warnings
144# are encountered.
145#
146define print-errors
147endef
148
149define print-warnings
150endef
151
152# define the default command for compiling .c files into .obj files.
153# Some target types will redefine this command.
154#
155# %.obj :  %.c
156define c-obj-command
157    $(CC) -c $(C$(TTYPE)FLAGS) -I$(OUTDIR_$(TTYPE)) $(CPPFLAGS) $(F$(TTYPE)) -Fo$@ $<
158endef
159
160# define the default command for compiling .cpp files into .obj files.
161# Some target types will redefine this command.
162#
163# %.obj :  %.cpp
164define cpp-obj-command
165    $(CC) -c $(C$(TTYPE)FLAGS) -I$(OUTDIR_$(TTYPE)) $(CPPFLAGS) $(F$(TTYPE)) -Fo$@ $<
166endef
167
168# define the default command for compiling .asm files into .obj files.
169# Some target types will redefine this command.
170#
171# %.obj :  %.asm
172define asm-obj-command
173	$(AS) -c $(AFLAGS) $(CPPFLAGS) $(F$(TTYPE)) -Fo$@ $<
174endef
175
176# define the default command for compiling .rc files into .res files.
177# Some target types will redefine this command.
178#
179# %.res :  %.rc
180define rc-res-command
181	export INCLUDE="$(OUTDIR_$(TTYPE));$(MSINCLUDE)"; \
182	$(CMDSTART) $(RC) -r $(RCFLAGS) -fo$@ $<
183endef
184
185all ::
186	$(print-warnings)
187ifdef SHOWBUILDINFO
188	@echo " -------------------------------------------"
189	@echo " SRCFILE      = $(SRCFILE)"
190	@echo " SOURCES      = $(SOURCES)"
191	@echo " C_DEFINES    = $(C_DEFINES)"
192	@echo " WLTUNEFILE   = $(WLTUNEFILE)"
193	@echo " TARGETPATH   = $(TARGETPATH)"
194	@echo " TARGETTYPE   = $(TARGETTYPE)"
195	@echo " MAKE_VERSION = $(MAKE_VERSION)"
196	@echo " TTYPE        = $(subst OPT,OPT(free),$(subst DBG,DBG(checked),$(TTYPE)))"
197	@echo " -------------------------------------------"
198endif # SHOWBUILDINFO
199
200all ::
201	$(print-errors)
202
203include $(SRCBASE)/branding.inc
204
205ifeq ($(origin USEBCMUIO), undefined)
206#if defined(USEBCMUIO)
207USEBCMUIO=1
208#else
209# undefine USEBCMUIO
210USEBCMUIO=
211#endif
212endif
213
214BIN_OPT=retail
215BIN_DBG=debug
216BUILDENV_OPT=free
217BUILDENV_DBG=checked
218MSVSBUILDENV_OPT=Release
219MSVSBUILDENV_DBG=Debug
220OUTDIR_OPT = $(TARGETPATH)/free
221OUTDIR_DBG = $(TARGETPATH)/checked
222
223OUTDIR_FREE = $(OUTDIR_OPT)
224OUTDIR_CHECKED = $(OUTDIR_DBG)
225
226
227CC  = cl
228AS  = ml
229RC  = rc
230MC  = mc
231LD  = link
232LIBCMD = lib
233MTL = midl
234
235# Ignore any include path and lib paths that the user imports from
236# the environment.
237#
238INCLUDE =
239
240ifeq ($(origin TARGETPATH), undefined)
241    TARGETPATH=.
242endif
243TARGETPATH := $(subst \,/,$(TARGETPATH))
244
245DDKBUILDENV := $(BUILDENV_$(TTYPE))
246MSVSBUILDENV := $(MSVSBUILDENV_$(TTYPE))
247BIN         := $(BIN_$(TTYPE))
248MC_FLAGS = -v
249
250### assume sources as entry point
251ifndef SRCFILE
252	SRCFILE=./sources
253endif
254
255include $(SRCFILE)
256SRCRULES=$(SRCFILE).mk
257
258ifeq ($(findstring $(TARGETTYPE), "EXE DRIVER LIB DLL DLL16 EXE16 DYNLINK VXD DOSEXE PROGRAM DUMMY"), )
259	ERRORS += "TARGETTYPE is not defined or not recognized!"
260	ERRORS += "This variable must be defined with a recognized value"
261	ERRORS += "in your sources or GNUsources file."
262endif
263
264# include any branding defined if they exist in the environment
265ifneq ($(BRAND),)
266    C_DEFINES += -DBRAND="'$(BRAND)'"
267endif # BRAND
268
269SOURCES.IDL	:= $(filter %.idl,$(SOURCES))
270SOURCES.TLB	:= $(patsubst %.idl,%.tlb,$(SOURCES.IDL))
271SOURCES._IC     := $(patsubst %.idl,%_i.c,$(SOURCES.IDL))
272
273SOURCES.OBJ	:= $(SOURCES)
274SOURCES.OBJ	:= $(patsubst %.cpp,%.obj,$(SOURCES.OBJ))
275SOURCES.OBJ	:= $(patsubst %.CPP,%.obj,$(SOURCES.OBJ))
276SOURCES.OBJ	:= $(patsubst %.asm,%.obj,$(SOURCES.OBJ))
277SOURCES.OBJ	:= $(patsubst %.ASM,%.obj,$(SOURCES.OBJ))
278SOURCES.OBJ	:= $(patsubst %.c,%.obj,$(SOURCES.OBJ))
279SOURCES.OBJ	:= $(patsubst %.C,%.obj,$(SOURCES.OBJ))
280SOURCES.OBJ	:= $(filter %.obj,$(SOURCES.OBJ))
281# SOURCES.OBJ	:= $(notdir $(SOURCES.OBJ))
282SOURCES.OBJ	:= $(subst /,_,$(SOURCES.OBJ))
283
284SOURCES.RES	:= $(patsubst %.rc,%.res,$(filter %.rc,$(SOURCES)))
285SOURCES.MSG	:= $(patsubst %.mc,%.h,$(filter %.mc,$(SOURCES)))
286
287vpath %.rc 	.:..:../..
288
289
290ifdef USE_DEPENDENCIES
291
292# MAKECMDGOALS is not supported until gnumake version 3.76 so we hack
293# it by explicitly setting MAKECMDGOALS in the clean rule at the top
294# of this file.
295#
296ifneq ($(MAKECMDGOALS),clean)
297
298# BUG -- BUG -- BUG
299# This code assumes that files are still unique without the extension.
300# So no foo.c and foo.cpp in the same makefile.
301
302SOURCES.D       :=  $(SOURCES)
303SOURCES.D       :=  $(patsubst %.c,%.d,$(SOURCES.D))
304SOURCES.D       :=  $(patsubst %.C,%.d,$(SOURCES.D))
305SOURCES.D       :=  $(patsubst %.cpp,%.d,$(SOURCES.D))
306SOURCES.D       :=  $(patsubst %.CPP,%.d,$(SOURCES.D))
307SOURCES.D       :=  $(filter %.d,$(SOURCES.D))
308
309endif  # MAKECMDGOALS != clean
310
311endif  # ifdef USE_DEPENDENCIES
312
313SI_FLAGS = -translate:always,source,package
314
315
316
317# Target all just depends upon our target file.
318all :: target post-build-target
319
320# The target file depends upon the directory where it will reside.
321target :: $(OUTDIR_$(TTYPE))/NUL
322
323WLCFGDIR        ?= $(SRCBASE)/wl/config
324WLTUNEFILE      ?= wltunable_sample.h
325
326# Create target directory if necessary.
327$(OUTDIR_$(TTYPE))/NUL :
328	[ -d "$(@D)" ] || mkdir -p $(@D)
329ifeq ($(WLCONF_GEN),true)
330	@if [ ! -f "$(@D)/wlconf.h" ]; then \
331	    cp -v $(WLCFGDIR)/$(WLTUNEFILE) $(@D)/wlconf.h; \
332	elif ! diff -q $(WLCFGDIR)/$(WLTUNEFILE) $(@D)/wlconf.h; then \
333	    cp -v $(WLCFGDIR)/$(WLTUNEFILE) $(@D)/wlconf.h; \
334	fi
335endif
336
337#
338# If the sources file specified a NTTARGETFILE0, build that first.
339#
340target :: $(NTTARGETFILE0)
341
342
343# calculate some dynamic variables that are useful in build rules.
344#
345DEPS_OBJ = $(patsubst %,$(OUTDIR_$(TTYPE))/%,$(SOURCES.OBJ))
346DEPS_RES = $(patsubst %,$(OUTDIR_$(TTYPE))/%,$(SOURCES.RES))
347DEPS_TLB = $(patsubst %,$(OUTDIR_$(TTYPE))/%,$(SOURCES.TLB))
348DEPS_MSG = $(patsubst %,$(OUTDIR_$(TTYPE))/%,$(SOURCES.MSG))
349# Finally generate DEPENDENCIES list that are made as explicit dependencies
350# in src/makefile/<obj-type>.mk file
351DEPENDENCIES =    $(DEPS_TLB) $(DEPS_MSG) $(DEPS_OBJ) $(DEPS_RES)
352DOS_DEPS= $(shell echo $(filter-out %.tlb %.TLB %.h %.H %.def %.DEF,$^) | sed 's%//\(.\)/%\1:/%g')
353
354
355$(OUTDIR_$(TTYPE))/%.i :  %.c
356	@echo "Compiling $(notdir $<) -> $(notdir $@)"
357	$(CC) -E -P $(C$(TTYPE)FLAGS) $(CPPFLAGS) $(F$(TTYPE)) $< >$@
358
359$(OUTDIR_$(TTYPE))/%.i :  %.cpp
360	@echo "Compiling $(notdir $<) -> $(notdir $@)"
361	$(CC) -E -P $(C$(TTYPE)FLAGS) $(CPPFLAGS) $(F$(TTYPE)) $< >$@
362
363$(OUTDIR_$(TTYPE))/%.d :  %.c
364	@echo "Compiling $(notdir $<) -> $(notdir $@)"
365	$(calculate_dependencies)
366
367$(OUTDIR_$(TTYPE))/%.d :  %.C
368	@echo "Compiling $(notdir $<) -> $(notdir $@)"
369	$(calculate_dependencies)
370
371$(OUTDIR_$(TTYPE))/%.d :  %.cpp
372	@echo "Compiling $(notdir $<) -> $(notdir $@)"
373	$(calculate_dependencies)
374
375$(OUTDIR_$(TTYPE))/%.d :  %.CPP
376	@echo "Compiling $(notdir $<) -> $(notdir $@)"
377	$(calculate_dependencies)
378
379$(OUTDIR_$(TTYPE))/%.obj :  %.c
380	@echo "Compiling $(notdir $<) -> $(notdir $@)"
381	$(c-obj-command)
382
383$(OUTDIR_$(TTYPE))/%.obj :  $(OUTDIR_$(TTYPE))/%.c
384	@echo "Compiling $(notdir $<) -> $(OUTDIR_$(TTYPE))/$(notdir $@)"
385	$(c-obj-command)
386
387$(OUTDIR_$(TTYPE))/%.obj :  %.C
388	@echo "Compiling $(notdir $<) -> $(notdir $@)"
389	$(c-obj-command)
390
391$(OUTDIR_$(TTYPE))/%.obj :  %.cpp
392	@echo "Compiling $(notdir $<) -> $(notdir $@)"
393	$(cpp-obj-command)
394
395$(OUTDIR_$(TTYPE))/%.obj :  %.CPP
396	@echo "Compiling $(notdir $<) -> $(notdir $@)"
397	$(cpp-obj-command)
398
399ifdef ECLOUD_BUILD_ID
400$(OUTDIR_$(TTYPE))/%.res :  RC = rc
401endif # ECLOUD_BUILD_ID
402
403$(OUTDIR_$(TTYPE))/%.res :  %.rc
404	@echo "Compiling $(notdir $<) -> $(notdir $@)"
405	$(rc-res-command)
406
407# build rule for IDL files.
408$(OUTDIR_$(TTYPE))/%.tlb $(OUTDIR_$(TTYPE))/%.h $(OUTDIR_$(TTYPE))/%_i.c : %.idl
409	@echo "Compiling $(notdir $<) -> $(notdir $@)"
410	$(MTL) /I $(MSSDK)/include /nologo /Oicf /out $(OUTDIR_$(TTYPE)) $<
411
412# Build rule for message file
413$(OUTDIR_$(TTYPE))/%.rc $(OUTDIR_$(TTYPE))/%.h : %.mc
414	@echo "Compiling $(notdir $<) -> $(notdir $@)"
415	$(MC) -h $(OUTDIR_$(TTYPE)) -r $(OUTDIR_$(TTYPE)) $(MC_FLAGS) $<
416
417$(OUTDIR_$(TTYPE))/%.obj: %.asm
418	@echo "Compiling $(notdir $<) -> $(notdir $@)"
419	$(asm-obj-command)
420
421FORCE:
422
423clean ::
424	rm -rf $(OUTDIR_CHECKED) $(OUTDIR_FREE) $(SRCRULES)
425
426
427ifeq  ("$(TARGETTYPE)", "DRIVER")
428ifeq  ("$(DRIVERTYPE)", "WDM")
429include $(SRCBASE)/makefiles/wdm.mk
430else
431ifeq  ("$(DRIVERTYPE)", "WDM2600")
432    include $(SRCBASE)/makefiles/wdm2600.mk
433else
434    include $(SRCBASE)/makefiles/driver.mk
435endif
436endif
437endif
438
439ifeq  ("$(TARGETTYPE)", "VXD")
440include $(SRCBASE)/makefiles/vxd.mk
441endif
442
443ifneq ($(findstring x$(TARGETTYPE)x, "xDLLx xDYNLINKx"), )
444ifneq ($(findstring x$(HOSTOS)x, "xwincex"), )
445include $(SRCBASE)/makefiles/dllce.mk
446else
447include $(SRCBASE)/makefiles/dll.mk
448endif
449endif
450
451ifneq ($(findstring $(TARGETTYPE)x, "DLL16x"), )
452include $(SRCBASE)/makefiles/dll16.mk
453endif
454
455ifneq ($(findstring $(TARGETTYPE)x, "EXE16x"), )
456include $(SRCBASE)/makefiles/exe16.mk
457endif
458
459ifneq ($(findstring $(TARGETTYPE), "LIB"), )
460ifneq ($(findstring x$(HOSTOS)x, "xwincex"), )
461include $(SRCBASE)/makefiles/libce.mk
462else
463include $(SRCBASE)/makefiles/lib.mk
464endif
465endif
466
467ifneq ($(findstring $(TARGETTYPE), "xEXEx xPROGRAMx"), )
468ifneq ($(findstring x$(HOSTOS)x, "xwincex"), )
469include $(SRCBASE)/makefiles/exece.mk
470else
471include $(SRCBASE)/makefiles/exe.mk
472endif
473endif
474
475ifneq ($(findstring x$(TARGETTYPE)x, "xDOSEXEx"), )
476include $(SRCBASE)/makefiles/dosexe.mk
477endif
478
479ifneq ($(findstring $(TARGETTYPE), "DUMMY"), )
480include $(SRCBASE)/makefiles/dummy.mk
481endif
482
483# Set make variables that help find things like DDK's, SDK's, etc,
484# depending upon the requirements expressed in the individual
485# makefile(s).
486include $(SRCBASE)/makefiles/env.mk
487
488#
489# Add some rules so that our target depends on any libraries we are going
490# to link against.
491#
492#target :: $(LIBS)
493
494
495target :: $(OUTDIR_$(TTYPE))/$(TARGET)
496
497ifneq ($(wildcard ./makefile.inc), )
498include .\makefile.inc
499endif
500
501
502#
503# If the sources file specified a NTTARGETFILES, build that last.
504#
505
506target :: $(NTTARGETFILES)
507
508
509target ::
510	@echo Finished compiling $@
511	@echo ""
512
513post-build-target ::
514
515release: all
516
517.PHONY: all target release clean $(OUTDIR_$(TTYPE))/.depends
518
519ifneq ($(wildcard $(SRCRULES)), )
520include $(SRCRULES)
521endif
522
523# only try to do dependency checking if we have some dependencies to check!
524#
525# It seems counter-intiutive but it looks like the
526# include dependencies are evaluated in reverse order from their
527# appearance in the makefile.  Therefore we include the NUL file from
528# the object directory *after* we include the dependency files
529# themselves.  This results in the object directory getting created
530# before we build any of the dependency files.
531#
532ifneq ($(strip $(SOURCES.D)),)
533include $(patsubst %,$(OUTDIR_$(TTYPE))/%,$(SOURCES.D))
534include $(OUTDIR_$(TTYPE))/NUL
535endif
536
537define calculate_dependencies
538	@ echo making $@
539	$(SHELL) -ec 'gcc -MM -w -D_M_IX86=500 $(C_DEFINES) $(CPPFLAGS) $< \
540	| sed '\''s?$*\.o[ :]*?$@ &?g'\'' >$@'
541endef
542
543# OTHER_SOURCES_PROCESSED removes recursive build of OTHER_SOURCES, when that
544# switch is set from cmd line
545ifdef OTHER_SOURCES
546ifndef OTHER_SOURCES_PROCESSED
547all clean :: $(OTHER_SOURCES)
548	@echo "Go through OTHER_SOURCES: $(OTHER_SOURCES)"
549	$(foreach SRCFILE,$(OTHER_SOURCES),$(MAKE) SRCFILE=$(SRCFILE) TTYPE=$(TTYPE) OTHER_SOURCES_PROCESSED=true $@; )
550endif # OTHER_SOURCES_PROCESSED
551endif # OTHER_SOURCES
552
553vpath %.Lib $(LIBVPATH)
554vpath %.LIB $(LIBVPATH)
555vpath %.lib $(LIBVPATH)
556
557export PATH:=$(subst $(space),:,$(strip $(NEWPATH))):$(PATH)
558
559foo:
560	@echo _SDKROOT=$(_SDKROOT)
561	@echo NEWPATH=$(NEWPATH)
562
563endif
564###  end of ifeq ($(origin TTYPE), undefined)
565
566printenv:
567	env
568
569ifdef WARNING
570define print-warnings
571@echo "Warning **** Warning **** Warning **** Warning **** Warning"
572@for warn in $(WARNING) ; do echo $$warn; done
573@echo "Continuing..."
574endef
575endif # WARNING
576
577ifdef ERRORS
578define print-errors
579@echo "Error **** Error **** Error **** Error **** Error"
580@for err in $(ERRORS) ; do echo $$err; done
581@echo "Exiting makefile."
582@exit 1
583endef
584endif # ERRORS
585