Eye-candy bits related to subdirs
[winelib-gnu-make.git] / clock+wow32 / Winemake.include
blob545a68ca7e07ffec5c1163689e510902fa4a53a3
1 # =============================================================================
3 # Do not:
4 # o  use make's built-in rules and variables
5 #    (this increases performance and avoid hard-to-debug behavour);
6 # o  print "Entering directory ...";
7 MAKEFLAGS += -rR --no-print-directory
8 .SUFFIXES:
10 # =============================================================================
11 # Config
12 CC      := winegcc
13 CXX     := wineg++
14 RC      := wrc
16 RM      := rm -f
17 LN_S    := ln -sf
20 # quiet/verbose
21 V       ?= 0
22 ifneq ($(V),0)
23   quiet :=
24   Q     :=
25 else
26   quiet := quiet_
27   Q     := @
28 endif
31 # Main goal
32 .PHONY  : all $(SUBDIRS)
33 all     : $(SUBDIRS) $(MODULES)
35 $(SUBDIRS):
36         $(Q)$(MAKE) -C $@
38 # Rules for cleaning
39 CLEAN_FILES     = y.tab.c y.tab.h lex.yy.c core *.orig *.rej \
40                   \\\#*\\\# *~ *% .\\\#*
42 clean:: $(SUBDIRS:%=%/__clean__) $(EXTRASUBDIRS:%=%/__clean__)
43         $(call qpretty,CLEAN   $(if $(curdir),$(curdir),.))
44         $(Q)$(RM) $(CLEAN_FILES)
46 $(SUBDIRS:%=%/__clean__): FORCE
47         $(Q)$(MAKE) -C $(dir $@) clean
50 .PHONY  : FORCE
52 ifeq ($(MAKELEVEL),0)
53 export TOP := $(CURDIR)
54 endif
56 # =============================================================================
58 # canonicalize a name
59 # UC: $(call canonicalize, foo-xxx.exe)  ->  foo_xxx_exe
60 canonicalize = $(subst -,_,$(subst .,_,$1))
62 # handy canonical arguments
63 1C      = $(call canonicalize,$1)
64 *C      = $(call canonicalize,$*)
65 @C      = $(call canonicalize,$@)
67 # handy variables
68 1C_SRC  = $($(1C)_SRC)
69 @C_LDFLAGS=$($(@C)_LDFLAGS)
70 @C_DLLS = $($(@C)_DLLS)
71 @C_LIBS = $($(@C)_LIBS)
73 @C_LINK = $($(@C)_LINK)
75 # $! == eye-candy $@
76 curdir  := $(patsubst $(TOP)%,%,$(CURDIR))
77 curdir  := $(patsubst /%,%,$(curdir))
78 curdir  := $(curdir)$(if $(curdir),/)
79 !       = $(curdir)$@
80 1!      = $(curdir)$1
82 # extract X-sources from sources list
83 # UC: $(call __c-src, hello.c hi.cpp ...)  ->  hello.o
84 __src-c   = $(filter %.c,$1)
85 __src-cxx = $(strip $(foreach ext,cpp cxx cc C c++,$(filter %.$(ext),$1)))
86 __src-rc  = $(filter %.rc,$1)
87 __src-spec= $(filter %.spec,$1)
89 # extract X-sources from module
90 # UC: $(call s-src,foo.exe)
91 src-c   = $(call __src-c,$(1C_SRC))
92 src-cxx = $(call __src-cxx,$(1C_SRC))
93 src-rc  = $(call __src-rc,$(1C_SRC))
94 src-spec= $(call __src-spec,$(1C_SRC))
96 # list of unknown sources for a module
97 # it is an error when this list is not empty
98 src-unknown = $(filter-out $(foreach srctype,c cxx rc spec,$(call src-$(srctype),$1)), $(1C_SRC))
100 # OBJECTS
102 # UC: $(call __filter-ext,.cxx,hello.c abc.C arm.cxx)  ->  arm.cxx
103 __filter-ext= $(filter %$1,$2)
105 # extract X-objects from source list
106 # UC: $(call __objs-ext,.c,.o,hello.c abc.cpp)  ->  hello.o
107 __objs-ext= $(patsubst %$1,%$2,$(call __filter-ext,$1,$3))
109 __objs-c  = $(call __objs-ext,.c,.o,$1)
110 __objs-cxx= $(foreach ext,cpp cxx cc C c++,$(call __objs-ext,.$(ext),.o,$1))
111 __objs-rc = $(call __objs-ext,.rc,.res,$1)
113 # UC: objs = $(call c-objs, foo)
114 objs-c  = $(call __objs-c,$(1C_SRC))
115 objs-cxx= $(call __objs-cxx,$(1C_SRC))
116 objs-rc = $(call __objs-rc,$(1C_SRC))
119 # Autogen modules templates
120 __SRC_UNKNOWN   :=
122 define MODULE_template
123 $(1C)_SRC_C     := $$(call src-c,$1)
124 $(1C)_SRC_CXX   := $$(call src-cxx,$1)
125 $(1C)_SRC_RC    := $$(call src-rc,$1)
126 $(1C)_SRC_SPEC  := $$(call src-spec,$1)
128 $(1C)_OBJS      := $(foreach lang,c cxx rc,$$(call objs-$(lang),$1))
130 # link command (C++ programs have to be linked by C++ compiler)
131 $(1C)_LINK      := $$(if $$($(1C)_SRC_CXX),$(CXX),$(CC))
133 # explicit dependencies (to keep objects precious)
134 $1      : $$($(1C)_OBJS)
136 $(1C)_SRC_UNKNOWN:=$$(call src-unknown,$1)
137 __SRC_UNKNOWN   += $$($(1C)_SRC_UNKNOWN)
138 clean::
139         $$(call qpretty,CLEAN   $(1!))
140         $(Q)$(RM) $$($(1C)_OBJS) $1.so $1
141 endef
143 $(foreach module,$(MODULES),$(eval $(call MODULE_template,$(module))))
145 # Verify whether all sources provided are of known type
146 __SRC_UNKNOWN   := $(strip $(__SRC_UNKNOWN))
147 ifneq "$(__SRC_UNKNOWN)" ""
148 $(error E: Source(s) of unknown type: [ $(__SRC_UNKNOWN) ] )
149 endif
152 # =============================================================================
153 # Common
155 # Convenient variables
156 comma   := ,
157 squote  := '
158 empty   :=
159 space   := $(empty) $(empty)
162 # Escape single quote for use in echo statements
163 escsq = $(subst $(squote),'\$(squote)',$1)
165 # echo command.
166 # Short version is used, if $(quiet) equals `quiet_', otherwise full one.
167 echo-cmd = $(if $($(quiet)cmd_$(1)),\
168         echo '  $(call escsq,$($(quiet)cmd_$(1)))';)
170 # echo pretty string [only in quiet mode]
171 qpretty = $(if $(Q),@echo '  $1')
173 # printing commands
174 cmd     = @$(echo-cmd) $(cmd_$(1))
176 # =============================================================================
177 # Rules
179 quiet_cmd_c_c   = CC      $!
180       cmd_c_c   = $(CC) -c $(CFLAGS) $(CEXTRA) $(DEFINCL) -o $@ $<
182 quiet_cmd_cxx_c = C++     $!
183       cmd_cxx_c = $(CXX) -c $(CXXFLAGS) $(CXXEXTRA) $(DEFINCL) -o $@ $<
185 quiet_cmd_rc_x  = RC      $!
186       cmd_rc_x  = $(RC) $(RCFLAGS) $(RCEXTRA) $(DEFINCL) -fo$@ $<
189 %.o     : %.c
190         $(call cmd,c_c)
192 define rule_cxx_ext
193 %.o     : %.$1
194         $$(call cmd,cxx_c)
195 endef
196 $(foreach ext,cpp cxx cc C c++,$(eval $(call rule_cxx_ext,$(ext))))
198 %.res   : %.rc
199         $(call cmd,rc_x)
202 DEFLIB  := $(LIBRARY_PATH) $(LIBRARIES) $(DLL_PATH)
204 quiet_cmd_link_exe = EXE     $!
205 define cmd_link_exe
206         $(@C_LINK) $(@C_LDFLAGS) -o $@.so $+ $(DEFLIB) $(@C_DLLS:%=-l%) $(@C_LIBS:%=-l%) &&     \
207         echo -e '#!/bin/sh\n\nexec wine `dirname $$0`/`basename $$0`.so\n' > $@ && chmod a+x $@
208 endef
210 quiet_cmd_link_dll = DLL     $!
211 define cmd_link_dll
212         $(@C_LINK) $(@C_LDFLAGS) -shared -o $@.so $+ $(DEFLIB) $(@C_DLLS:%=-l%) $(@C_LIBS:%=-l%) &&     \
213         $(LN_S) $(@F).so $(@D)/$(@F:.so=)
214 endef
216 .SECONDEXPANSION:
217 %.exe   :
218         $(call cmd,link_exe)
219 %.dll   : $$($$(@C)_SRC_SPEC)
220         $(call cmd,link_dll)