source: branches/libc-0.6/src/emx/Makefile.gmk@ 3842

Last change on this file since 3842 was 3842, checked in by bird, 11 years ago

update

  • Property cvs2svn:cvs-rev set to 1.8
  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 12.9 KB
Line 
1# Central makefile for building the OS2/GCC C runtime
2#
3# InnoTek Systemberatung GmbH
4#
5# Copyright (c) 1994-1995 by Eberhard Mattes
6# Copyright (c) 2003 InnoTek Systemberatung GmbH
7#
8# Author: Andrew Zabolotny <zap@cobra.ru>
9# $Id: Makefile.gmk 3842 2014-03-16 19:46:21Z bird $
10#
11# All Rights Reserved
12#
13# Requires GNU Make.
14# In fact, this build system could be entitled "GNU Make Unleashed"
15#
16# For a brief description of how build system works please read build.txt
17#
18# Bootstrapping sequence using EMX gcc compiler:
19#
20# 1. Backup include/ctype.h and rename include/ctype.h-bootstrap to
21# include/ctype.h
22# 2. Run 'make os2', put the resulting library os2.a to emx/lib as _os2.a,
23# and convert it to .lib with emxomf: 'emxomf _os2.a'
24# 3. Now compile everything you wish this way: 'make LIBS=-l_os2'
25#
26
27# Build type control variables. You can set them right from command line,
28# e.g "make MODE=dbg"
29
30# Build mode: opt (optimization), dbg (debug)
31MODE = dbg
32# Base output directory
33OUT = out/
34# Base installation directory
35INS = out/$(MODE)/install/
36# CPU type (pretend we are portable ;-)
37CPU = 386
38# Name of this makefile
39ifndef MAKEFILE
40MAKEFILE = Makefile.gmk
41endif
42
43# Actual output directory (referenced with $.)
44. = $(OUT)$(MODE)/
45
46# overrides from the environment.
47ifdef PATH_OBJ
48ifndef PATH_OBJD
49PATH_OBJD := $(shell echo $(PATH_OBJ)|sed 's/^[a-zA-Z]://')
50endif
51OUT = $(PATH_OBJD)/emx/
52INS = $(PATH_OBJD)/builtunix/usr/
53. = $(OUT)
54endif
55
56ifdef BUILD_MODE
57ifeq ($(BUILD_MODE),RELEASE)
58MODE = opt
59endif
60endif
61
62# Check if MODE has a valid value
63ifneq ($(filter-out /opt/ /dbg/ /prf/,/$(MODE)/),)
64$(error MODE should have one of the following values: opt, dbg, prf)
65endif
66
67# The object file format to use for tools (emxomf, ld and friends)
68TOOLFMT.dbg = omf
69TOOLFMT.opt = omf
70TOOLFMT.prf = omf
71TOOLFMT = $(TOOLFMT.$(MODE))
72
73# Use ash.exe which is quite fast (comparable to cmd.exe) but has more features
74SHELL := ash.exe
75
76# Source base directory.
77srcdir := $(shell pwd)
78
79# File name extensions
80# Executable files -- xxx$E
81E = .exe
82# DLL files --- xxx$D
83D = .dll
84# Library files --- xxx$A
85A = .$(if $(findstring omf,$(.TKIND)),lib,a)
86
87# Use the tool we built.
88GETTOOL ?= $.$(TOOLFMT)/$1$E
89# Use the tool we built if present
90GETTOOL2 ?= `test -f '$.$(TOOLFMT)/$1$E' && echo '$.$(TOOLFMT)/'`$1$E
91
92# The C compiler
93CC = gcc -c -Zmt -fmessage-length=0
94# The C compiler flags
95ifndef NO_LOCAL_HEADERS
96CFLAGS.INC += -Iinclude
97endif
98CFLAGS.INC += -Isrc/include
99CFLAGS.INC += -Isrc/lib/bsd/include
100CFLAGS = -Wall -Wundef -Wmissing-prototypes -mstack-arg-probe $(CFLAGS.INC) $(CFLAGS.$(MODE)) $(CFLAGS.KIND)
101# The additional C compiler flags for different build modes
102CFLAGS.opt = -g -O3 -mcpu=pentium -mpreferred-stack-boundary=4 -malign-strings=2 -falign-loops=2 -falign-jumps=2 -falign-functions=3
103CFLAGS.dbg = -g -DDEBUG
104CFLAGS.prf = $(CFLAGS.opt) -pg
105CFLAGS.aout = -Zaout
106CFLAGS.omf = -Zomf
107CFLAGS.prof = -pg
108CFLAGS.log = -DDEBUG_LOGGING -D__LIBC_STRICT
109# The object files are put in subdirectory objectformat-targetkind,
110# we decompose object file name back and pick appropiate $CFLAGS
111CFLAGS.KIND = $(foreach x,$(subst -, ,$(firstword $(subst /, ,$(subst $.,,$@)))),$(CFLAGS.$x))
112# How to compile a .c file
113DO.COMPILE.c = $(CC) -std=gnu99 $(strip $(CFLAGS) $1) -o $@ $(srcdir)/$< -I$(dir $<)
114# '-std=gnu99' doesn't work with '-x assembler-with-cpp', therefor no $(call DO.COMPILE.c).
115DO.COMPILE.s = $(CC) -x assembler-with-cpp $(strip $(CFLAGS) $1) -o $@ $(srcdir)/$< -I$(dir $<)
116
117# The linker
118LD = gcc
119# Linker flags
120LDFLAGS = $(LDFLAGS.$(MODE)) $(LDFLAGS.KIND) -Zmap -Zstack 1024 -Zhigh-mem $(LIBS)
121LDFLAGS.DLL = $(LDFLAGS) -Zdll -Zfork
122# Linker flags for different build modes
123LDFLAGS.opt = -g -Zcrtdll=c_dll
124LDFLAGS.prf = -g -Zcrtdll=c_dll -lkProfile -LG:/kTaskMgr/Tree/lib/debug
125LDFLAGS.dbg = -g
126LDFLAGS.aout = -Zaout
127ifeq ($(EMXOMFLD_TYPE),wlink)
128LDFLAGS.omf = -Zomf
129else
130LDFLAGS.omf = -Zomf -Zlinker /PM:VIO -Zlinker /LINENUMBERS
131endif
132LDFLAGS.prof = -pg
133# Linker flags for different kinds of target
134LDFLAGS.KIND = $(foreach x,$(subst -, ,$(firstword $(subst /, ,$(subst $.,,$@)))),$(LDFLAGS.$x))
135# How to link a .exe file
136DO.LINK.exe = $(LD) $(strip $(LDFLAGS) $(filter-out -l%,$1)) -o $@ $(^O) $(^DEF) $(^LIB) $(filter -l%,$1)
137# How to link a .dll file
138DO.LINK.dll = $(LD) $(strip $(LDFLAGS.DLL) $(filter-out -l%,$1)) -o $@ $(^O) $(^DEF) $(^LIB) $(filter -l%,$1)
139
140# Pack executables and DLLs right after they are linked
141# bird: I don't care about space, only performance. So, we will only use
142# lxlite for stripping and sector aligning.
143# <rant> My explanation is that anything which is used frequently
144# enough will be in one of the caches, so unpacking the datasegment
145# for each new process is a waste of time. The code segment is
146# shared, data segment is not shared, but must be reloaded page by page
147# from the executable in new processes.
148# For further optimzations, we align pages on 4kb boundaries since this
149# is the JFS block size and thus should be most the efficient unit to read. </rant>
150# URG! we must not do this for ldstub.bin!
151ifeq ($(MODE),opt)
152LXLITE.FLAGS = /F+ /AP:4096 /MRN /MLN /MF1
153DO.LINK.exe += $(if $(findstring .exe,$@), $(NL)cp $@ $(basename $@).dbg $(NL)lxlite /X /AS $(subst /,\\,$@))
154DO.LINK.dll += $(NL)cp $@ $(basename $@).dbg $(NL)lxlite $(LXLITE.FLAGS) $(subst /,\\,$@)
155endif
156
157# emxbind tool
158EMXBIND = $(call GETTOOL2,emxbind)
159# emxbind flags
160EMXBINDFLAGS = -bq $(EMXBINDFLAGS.$(MODE))
161EMXBINDFLAGS.opt = -s
162EMXBINDFLAGS.prf =
163EMXBINDFLAGS.dbg =
164# Flags for emxbind
165DO.EMXBIND = $(EMXBIND) $(EMXBINDFLAGS) -o $@ $1
166
167# The macro assembler
168ifdef PATH_TOP
169ASM = $(PATH_TOP)/tools/x86.os2/masm/v6.0/binp/ml.exe -c
170else
171ASM = ml -c
172endif
173ASMFLAGS = -Cp -W3 -WX -VM -nologo
174# How to compile an .asm file
175DO.COMPILE.asm = $(ASM) $(ASMFLAGS) $1 -Fo$@ $<
176
177# The tool to create an archive
178AR = $(if $(findstring .lib,$@), $(call GETTOOL2,emxomfar),ar)
179ARFLAGS = crs
180DO.LIBRARY = $(call RM_SHELL,$@); $(AR) $(ARFLAGS)$1 $@ $(^O)
181
182# The tool to extract exports from object files and archives,
183# removing unused stuff (like empty lines and comments)
184# and sorting alphabetically (looks nicer).
185EMXEXP = $(call GETTOOL2,emxexp)
186EMXEXPFLAGS = -u
187DO.EMXEXP = $(EMXEXP) $(strip $(EMXEXPFLAGS) $1) | sed -e "/^$$/d" -e "/^ *;/d" | sort -d >>$2
188
189# The tool to create import libraries
190IMPLIB = $(call GETTOOL2,emximp)
191IMPLIBFLAGS.prof = -m
192IMPLIBFLAGS.lazy = -l
193IMPLIBFLAGS.KIND = $(foreach x,$(subst -, ,$(firstword $(subst /, ,$(subst $.,,$@)))),$(IMPLIBFLAGS.$x))
194DO.IMPLIB = $(IMPLIB) -o $@ $(strip $1 $(IMPLIBFLAGS.KIND)) $(^IC)\
195 $(if $(^ID),\
196 $(NL)$(IMPLIB) -o $@.data$(suffix $@) $(strip $1) $(^ID)\
197 $(NL)$(call RMDIR,$@.tmpdir)\
198 $(NL)$(call MKDIR,$@.tmpdir)\
199 $(NL)cd $@.tmpdir && $(AR) x ../$(notdir $@.data$(suffix $@))\
200 $(NL)$(call RM,$@.tmpdir/*.log*)\
201 $(NL)$(AR) rs $@ $@.tmpdir/* )\
202 $(if $(^O)$(^LIB),$(NL)$(AR) rs $@ $(^O) $(^LIB))
203
204# How to create dependencies
205MAKEDEP = makedep
206MAKEDEPFLAGS = $(CFLAGS.INC)
207DO.DEPS = $(MAKEDEP) $(MAKEDEPFLAGS) \
208 -I$(subst $(SPACE), -I,$(sort $(dir $^))) -I$. -p$(@D)/ -c -S -f$@ $^
209
210# How to convert an a.out file to the OMF format
211# Emxomf depends on two libs, we have to detect wethere or not emxomf is built
212# or not. Unfortunately make isn't up to the job of figuring this out, so we
213# must use the shell.
214EMXOMF = $(call GETTOOL2,emxomf)
215DO.EMXOMF = $(EMXOMF) $(strip $1 -o) $@ $(if $<,$<, $(subst /omf-prof/,/aout-prof/,$(subst /omf-log/,/aout-log/,$(subst /omf/,/aout/,$(@:.obj=.o)))) )
216
217# How to copy some file to installation directory
218# In optimize mode we have to strip the libraries after copying
219INSTALL=$(call CP,$1,$2)
220ifeq ($(MODE),opt)
221INSTALL += $(if $(filter-out %.a,$2),$(NL)strip --strip-debug $2)
222INSTALL += $(if $(filter-out %.lib,$2),$(NL)emxomf -s $2)
223endif
224
225# How to filter just the object files from $^
226^O = $(filter %.o,$^)
227# Just the .imp files from $^ excluing -data.imp files.
228^IC = $(filter-out %-data.imp,$(filter %.imp,$^))
229# Just the -data.imp files from $^
230^ID = $(filter %-data.imp,$^)
231# How to filter just the .def files from $^
232^DEF = $(filter %.def,$^)
233# How to filter the libraries from $^
234^LIB = $(strip $(filter %.a,$^) $(filter %.lib,$^))
235
236# A newline
237define NL
238
239
240endef
241# Opening and closing brackets (for use inside variable expansions)
242OB := (
243CB := )
244COMMA := ,
245SPACE := $(EMPTY) $(EMPTY)
246# Text output separator (cannot begin with '-', echo thinks its a switch)
247SEP := ==========================================================================
248
249# How to remove one or more files without questions
250ifdef KMK_VERSION
251RM = kmk_builtin_rm -f $1
252else
253RM = rm -f $1
254endif
255RM_SHELL = rm -f $1
256# How to remove one or more directories without questions
257RMDIR = rm -rf $1
258# How to copy several files to a directory
259ifdef KMK_VERSION
260CP = kmk_builtin_cp $1 $2
261else
262CP = cp $1 $2
263endif
264# Miscelaneous tools
265ifdef KMK_VERSION
266MKDIR = kmk_builtin_mkdir -p $1
267else
268MKDIR = mkdir.exe -p $1
269endif
270# How to update a file only if it has been changed
271UPDATE = (cmp -s $1 $2 || mv -f $1 $2) && rm -f $1
272# How to touch a file
273TOUCH = touch $1
274# Re-build the original string including the ',' between args. Also escape
275# dollars since otherwise ash would expand them.
276ECHOIZE = $(subst $$,\$$,$1$(strip $(subst $(SPACE)$(COMMA),$(COMMA),$(foreach x,2 3 4 5 6 7 8 9,$(if $($x),$(COMMA) $($x))))))
277# How to output a text string (with appended newline)
278ifdef KMK_VERSION
279ECHO = kmk_builtin_echo "$(call ECHOIZE,$1,$2,$3,$4,$5,$6,$7,$8,$9)"
280else
281ECHO = echo "$(call ECHOIZE,$1,$2,$3,$4,$5,$6,$7,$8,$9)"
282endif
283# Same but append the text to a file (given with first argument)
284FECHO = echo "$(call ECHOIZE,$2,$3,$4,$5,$6,$7,$8,$9)" >> "$1"
285# How to replace the source file extension with a .o extension
286OBJEXT = $(patsubst %.S,%.o,$(patsubst %.s,%.o,$(patsubst %.asm,%.o,$(patsubst %.c,%.o,$1))))
287# Compute object file path given source file path (except the $. prefix)
288OBJFILE = $(addprefix $(.TKIND.DIR),$(call OBJEXT,$1))
289
290#------------ Variables appended by submakefiles ------------
291# The list of available modules
292MODULES :=
293# The help text for module list
294DO.HELP.MODULES :=
295# The help about public makefile variables
296DO.HELP.VARS := $(call ECHO, MODE={dbg|opt|prf} - choose between debug, optimized and profiled build modes.)$(NL)
297DO.HELP.VARS += $(call ECHO, OBJF={omf|aout} - build object files in omf or a.out format.)$(NL)
298# The list of work directories needeed for building all targets
299TARGDIRS :=
300# Build rules (_@_ replaced by name of generated makefile)
301RULES :=
302# The list of dependency files
303TARGDEPEND :=
304# The list of installed files
305INS.FILES :=
306
307.PHONY: default help all libs tools clean install install cleandep \
308 cleandepend dep depend depdone
309.SUFFIXES:
310.SUFFIXES: .c .cpp .asm .s .S .o .exe .dll .a .lib .obj
311
312# Default target
313default: help
314
315#------------ Submakefiles ------------
316ifndef SUBMAK
317SUBMAK := version.smak $(wildcard src/*/*.smak) include/include.smak $(wildcard bsd/*/*.smak) $(wildcard gnu/*/*.smak)
318endif
319
320# include template rules
321include templates.smak
322
323# Include all submakefiles
324-include $(SUBMAK)
325
326ifdef OFFICIAL_BIRD_VERSION
327ifneq ($(filter-out eniac delirium os2bld, $(HOSTNAME)),)
328$(error yea, nice try! Now go be ashamed of yourself!)
329endif
330endif
331
332# Sort and remove duplicate directories
333TARGDIRS := $(sort $(TARGDIRS))
334# Find out which directories are needed for installation
335INSDIRS := $(sort $(dir $(INS.FILES)))
336
337#------------ Global targets ------------
338help:
339 @$(call ECHO,$(SEP))
340 @$(call ECHO,Welcome to $(PACKAGE) version $(VERSION) build system!)
341 @$(call ECHO,$(COPYRIGHT))
342 @$(call ECHO,To build something, type 'make {target} {vars}', where {target} is one of:)
343 @$(call ECHO, all - build all available modules)
344 @$(call ECHO, {module-name} - build just a particular module)
345 @$(call ECHO, tools - build just the tools)
346 @$(call ECHO, libs - build all libraries)
347 @$(call ECHO, clean - remove all generated files (remove all built files))
348 @$(call ECHO, install - generate a installation tree in $(INS))
349 @$(call ECHO, dep - generate dependency files for all changed targets)
350 @$(call ECHO, cleandep - remove all dependency file)
351 @$(call ECHO,$(SEP))
352 @$(call ECHO,There are a number of variables than can be set in the make)
353 @$(call ECHO,command line to control various aspects of compilation:)
354 @$(DO.HELP.VARS)
355 @$(call ECHO,$(SEP))
356 @$(call ECHO,The following modules are included in this package:)
357 @$(DO.HELP.MODULES)
358 @$(call ECHO,$(SEP))
359
360all: $(MODULES)
361
362clean:
363 $(call RMDIR,$(OUT))
364
365cleandep cleandepend:
366 $(call RM,$(TARGDEPEND))
367
368dep depend:
369 @$(MAKE) -f $(MAKEFILE) --no-print-directory BUILD_DEPS=1 depdone
370
371depdone:
372 @$(call ECHO,Dependency files succesfully updated)
373
374install: all $(INSDIRS) $(INS.FILES)
375
376$. $(INSDIRS) $(TARGDIRS):
377 $(call MKDIR,$@)
378
379# bird: add rule for forcibly re-generating the rules.
380rules:
381 @$(call ECHO,smak don't generate rules anylonger!)
382
383# The general a.out -> OMF conversion rules for object files
384$.omf/%.obj:
385 $(call DO.EMXOMF)
386$.omf-log/%.obj:
387 $(call DO.EMXOMF)
388$.omf-prof/%.obj:
389 $(call DO.EMXOMF)
390
391# The general a.out -> OMF conversion rule for libraries
392$.omf%.lib:
393 $(call MKDIR, $(dir $@))
394 $(call DO.EMXOMF)
395
396#
397# Checkout rule
398#
399checkout update up:
400 cvs -q update -d -P 2>&1 | tee up.log
401
402
Note: See TracBrowser for help on using the repository browser.