source: trunk/src/emx/Makefile@ 1567

Last change on this file since 1567 was 1565, checked in by bird, 21 years ago

profiling and lazy fixing.

  • Property cvs2svn:cvs-rev set to 1.53
  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 12.3 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 1565 2004-10-10 02:53:14Z 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
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)/builttools/
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 -DTIMEBOMB=1
94# The C compiler flags
95ifndef NO_LOCAL_HEADERS
96CFLAGS.INC += -Iinclude
97endif
98CFLAGS.INC += -Isrc/include
99CFLAGS = -Wall -Wundef -Wmissing-prototypes -mstack-arg-probe $(CFLAGS.INC) $(CFLAGS.$(MODE)) $(CFLAGS.KIND)
100# The additional C compiler flags for different build modes
101CFLAGS.opt = -g -O3 -mcpu=pentium -mpreferred-stack-boundary=2 -malign-strings=2 -falign-loops=2 -falign-jumps=2 -falign-functions=3
102CFLAGS.dbg = -g -DDEBUG
103CFLAGS.prf = $(CFLAGS.opt) -pg
104CFLAGS.aout = -Zaout
105CFLAGS.omf = -Zomf
106CFLAGS.prof = -pg
107CFLAGS.log = -DDEBUG_LOGGING -D__LIBC_STRICT
108# The object files are put in subdirectory objectformat-targetkind,
109# we decompose object file name back and pick appropiate $CFLAGS
110CFLAGS.KIND = $(foreach x,$(subst -, ,$(firstword $(subst /, ,$(subst $.,,$@)))),$(CFLAGS.$x))
111# How to compile a .c file
112DO.COMPILE.c = $(CC) -std=gnu99 $(strip $(CFLAGS) $1) -o $@ $(srcdir)/$< -I$(dir $<)
113# '-std=gnu99' doesn't work with '-x assembler-with-cpp', therefor no $(call DO.COMPILE.c).
114DO.COMPILE.s = $(CC) -x assembler-with-cpp $(strip $(CFLAGS) $1) -o $@ $(srcdir)/$< -I$(dir $<)
115
116# The linker
117LD = gcc
118# Linker flags
119LDFLAGS = $(LDFLAGS.$(MODE)) $(LDFLAGS.KIND) -Zmap -Zstack 1024 -Zhigh-mem $(LIBS)
120LDFLAGS.DLL = $(LDFLAGS) -Zdll -Zfork
121# Linker flags for different build modes
122LDFLAGS.opt = -g -Zcrtdll=c_dll
123LDFLAGS.prf = -g -Zcrtdll=c_dll -lkProfile -LG:/kTaskMgr/Tree/lib/debug
124LDFLAGS.dbg = -g
125LDFLAGS.aout = -Zaout
126LDFLAGS.omf = -Zomf -Zlinker /PM:VIO -Zlinker /LINENUMBERS
127LDFLAGS.prof = -pg
128# Linker flags for different kinds of target
129LDFLAGS.KIND = $(foreach x,$(subst -, ,$(firstword $(subst /, ,$(subst $.,,$@)))),$(LDFLAGS.$x))
130# How to link a .exe file
131DO.LINK.exe = $(LD) $(strip $(LDFLAGS) $(filter-out -l%,$1)) -o $@ $(^O) $(^DEF) $(^LIB) $(filter -l%,$1)
132# How to link a .dll file
133DO.LINK.dll = $(LD) $(strip $(LDFLAGS.DLL) $(filter-out -l%,$1)) -o $@ $(^O) $(^DEF) $(^LIB) $(filter -l%,$1)
134
135# Pack executables and DLLs right after they are linked
136# bird: I don't care about space, only performance. So, we will only use
137# lxlite for stripping and sector aligning.
138# <rant> My explanation is that anything which is used frequently
139# enough will be in one of the caches, so unpacking the datasegment
140# for each new process is a waste of time. The code segment is
141# shared, data segment is not shared, but must be reloaded page by page
142# from the executable in new processes.
143# For further optimzations, we align pages on 4kb boundaries since this
144# is the JFS block size and thus should be most the efficient unit to read. </rant>
145# URG! we must not do this for ldstub.bin!
146ifeq ($(MODE),opt)
147LXLITE.FLAGS = /F+ /AP:4096 /MRN /MLN /MF1
148DO.LINK.exe += $(if $(findstring .exe,$@), $(NL)cp $@ $(basename $@).dbg $(NL)lxlite /X /AS $(subst /,\\,$@))
149DO.LINK.dll += $(NL)cp $@ $(basename $@).dbg $(NL)lxlite $(LXLITE.FLAGS) $(subst /,\\,$@)
150endif
151
152# emxbind tool
153EMXBIND = $(call GETTOOL2,emxbind)
154# emxbind flags
155EMXBINDFLAGS = -bq $(EMXBINDFLAGS.$(MODE))
156EMXBINDFLAGS.opt = -s
157EMXBINDFLAGS.prf =
158EMXBINDFLAGS.dbg =
159# Flags for emxbind
160DO.EMXBIND = $(EMXBIND) $(EMXBINDFLAGS) -o $@ $1
161
162# The macro assembler
163ifdef PATH_TOP
164ASM = $(PATH_TOP)/tools/x86.os2/masm/v6.0/binp/ml.exe -c
165else
166ASM = ml -c
167endif
168ASMFLAGS = -Cp -W3 -WX -VM -nologo
169# How to compile an .asm file
170DO.COMPILE.asm = $(ASM) $(ASMFLAGS) $1 -Fo$@ $<
171
172# The tool to create an archive
173AR = $(if $(findstring .lib,$@), $(call GETTOOL2,emxomfar),ar)
174ARFLAGS = crs
175DO.LIBRARY = $(call RM,$@); $(AR) $(ARFLAGS)$1 $@ $(^O)
176
177# The tool to extract exports from object files and archives,
178# removing unused stuff (like empty lines and comments)
179# and sorting alphabetically (looks nicer).
180EMXEXP = $(call GETTOOL2,emxexp)
181EMXEXPFLAGS = -u
182DO.EMXEXP = $(EMXEXP) $(strip $(EMXEXPFLAGS) $1) | sed -e "/^$$/d" -e "/^ *;/d" | sort -d >>$2
183
184# The tool to create import libraries
185IMPLIB = $(call GETTOOL2,emximp)
186IMPLIBFLAGS.prof = -m
187IMPLIBFLAGS.lazy = -l
188IMPLIBFLAGS.KIND = $(foreach x,$(subst -, ,$(firstword $(subst /, ,$(subst $.,,$@)))),$(IMPLIBFLAGS.$x))
189DO.IMPLIB = $(IMPLIB) -o $@ $(strip $1 $(IMPLIBFLAGS.KIND)) $(^IC)\
190 $(if $(^ID),\
191 $(NL)$(IMPLIB) -o $@.data$(suffix $@) $(strip $1) $(^ID)\
192 $(NL)$(call RMDIR,$@.tmpdir)\
193 $(NL)$(call MKDIR,$@.tmpdir)\
194 $(NL)cd $@.tmpdir && $(AR) x ../$(notdir $@.data$(suffix $@))\
195 $(NL)$(AR) rs $@ $@.tmpdir/* )\
196 $(if $(^O)$(^LIB),$(NL)$(AR) rs $@ $(^O) $(^LIB))
197
198# How to create dependencies
199MAKEDEP = makedep
200MAKEDEPFLAGS = $(CFLAGS.INC)
201DO.DEPS = $(MAKEDEP) $(MAKEDEPFLAGS) \
202 -I$(subst $(SPACE), -I,$(sort $(dir $^))) -I$. -p$(@D)/ -c -S -f$@ $^
203
204# How to convert an a.out file to the OMF format
205# Emxomf depends on two libs, we have to detect wethere or not emxomf is built
206# or not. Unfortunately make isn't up to the job of figuring this out, so we
207# must use the shell.
208EMXOMF = $(call GETTOOL2,emxomf)
209DO.EMXOMF = $(EMXOMF) $(strip $1 -o) $@ $(if $<,$<, $(subst /omf-prof/,/aout-prof/,$(subst /omf-log/,/aout-log/,$(subst /omf/,/aout/,$(@:.obj=.o)))) )
210
211# How to copy some file to installation directory
212# In optimize mode we have to strip the libraries after copying
213INSTALL=$(call CP,$1,$2)
214ifeq ($(MODE),opt)
215INSTALL += $(if $(filter-out %.a,$2),$(NL)strip --strip-debug $2)
216INSTALL += $(if $(filter-out %.lib,$2),$(NL)emxomf -s $2)
217endif
218
219# How to filter just the object files from $^
220^O = $(filter %.o,$^)
221# Just the .imp files from $^ excluing -data.imp files.
222^IC = $(filter-out %-data.imp,$(filter %.imp,$^))
223# Just the -data.imp files from $^
224^ID = $(filter %-data.imp,$^)
225# How to filter just the .def files from $^
226^DEF = $(filter %.def,$^)
227# How to filter the libraries from $^
228^LIB = $(strip $(filter %.a,$^) $(filter %.lib,$^))
229
230# A newline
231define NL
232
233
234endef
235# Opening and closing brackets (for use inside variable expansions)
236OB := (
237CB := )
238COMMA := ,
239SPACE := $(EMPTY) $(EMPTY)
240# Text output separator (cannot begin with '-', echo thinks its a switch)
241SEP := ==========================================================================
242
243# How to remove one or more files without questions
244RM = rm -f $1
245# How to remove one or more directories without questions
246RMDIR = rm -rf $1
247# How to copy several files to a directory
248CP = cp $1 $2
249# Miscelaneous tools
250MKDIR = mkdir.exe -p $1
251# How to update a file only if it has been changed
252UPDATE = (cmp -s $1 $2 || mv -f $1 $2) && rm -f $1
253# How to touch a file
254TOUCH = touch $1
255# Re-build the original string including the ',' between args. Also escape
256# dollars since otherwise ash would expand them.
257ECHOIZE = $(subst $$,\$$,$1$(strip $(subst $(SPACE)$(COMMA),$(COMMA),$(foreach x,2 3 4 5 6 7 8 9,$(if $($x),$(COMMA) $($x))))))
258# How to output a text string (with appended newline)
259ECHO = echo "$(call ECHOIZE,$1,$2,$3,$4,$5,$6,$7,$8,$9)"
260# Same but append the text to a file (given with first argument)
261FECHO = echo "$(call ECHOIZE,$2,$3,$4,$5,$6,$7,$8,$9)" >> "$1"
262# How to replace the source file extension with a .o extension
263OBJEXT = $(patsubst %.s,%.o,$(patsubst %.asm,%.o,$(patsubst %.c,%.o,$1)))
264# Compute object file path given source file path (except the $. prefix)
265OBJFILE = $(addprefix $(.TKIND.DIR),$(call OBJEXT,$1))
266
267#------------ Variables appended by submakefiles ------------
268# The list of available modules
269MODULES :=
270# The help text for module list
271DO.HELP.MODULES :=
272# The help about public makefile variables
273DO.HELP.VARS := $(call ECHO, MODE={dbg|opt|prf} - choose between debug, optimized and profiled build modes.)$(NL)
274DO.HELP.VARS += $(call ECHO, OBJF={omf|aout} - build object files in omf or a.out format.)$(NL)
275# The list of work directories needeed for building all targets
276TARGDIRS :=
277# Build rules (_@_ replaced by name of generated makefile)
278RULES :=
279# The list of dependency files
280TARGDEPEND :=
281# The list of installed files
282INS.FILES :=
283
284.PHONY: default help all libs tools clean install install cleandep \
285 cleandepend dep depend depdone
286.SUFFIXES:
287.SUFFIXES: .c .cpp .asm .s .o .exe .dll .a .lib .obj
288
289# Default target
290default: help
291
292#------------ Submakefiles ------------
293ifndef SUBMAK
294SUBMAK := version.smak $(wildcard src/*/*.smak) include/include.smak $(wildcard bsd/*/*.smak) $(wildcard gnu/*/*.smak)
295endif
296
297# include template rules
298include templates.smak
299
300# Include all submakefiles
301-include $(SUBMAK)
302
303# Sort and remove duplicate directories
304TARGDIRS := $(sort $(TARGDIRS))
305# Find out which directories are needed for installation
306INSDIRS := $(sort $(dir $(INS.FILES)))
307
308#------------ Global targets ------------
309help:
310 @$(call ECHO,$(SEP))
311 @$(call ECHO,Welcome to $(PACKAGE) version $(VERSION) build system!)
312 @$(call ECHO,$(COPYRIGHT))
313 @$(call ECHO,To build something, type 'make {target} {vars}', where {target} is one of:)
314 @$(call ECHO, all - build all available modules)
315 @$(call ECHO, {module-name} - build just a particular module)
316 @$(call ECHO, tools - build just the tools)
317 @$(call ECHO, libs - build all libraries)
318 @$(call ECHO, clean - remove all generated files (remove all built files))
319 @$(call ECHO, install - generate a installation tree in $(INS))
320 @$(call ECHO, dep - generate dependency files for all changed targets)
321 @$(call ECHO, cleandep - remove all dependency file)
322 @$(call ECHO,$(SEP))
323 @$(call ECHO,There are a number of variables than can be set in the make)
324 @$(call ECHO,command line to control various aspects of compilation:)
325 @$(DO.HELP.VARS)
326 @$(call ECHO,$(SEP))
327 @$(call ECHO,The following modules are included in this package:)
328 @$(DO.HELP.MODULES)
329 @$(call ECHO,$(SEP))
330
331all: $(MODULES)
332
333clean:
334 $(call RMDIR,$(OUT))
335
336cleandep cleandepend:
337 $(call RM,$(TARGDEPEND))
338
339dep depend:
340 @$(MAKE) -f $(MAKEFILE) --no-print-directory BUILD_DEPS=1 depdone
341
342depdone:
343 @$(call ECHO,Dependency files succesfully updated)
344
345install: all $(INSDIRS) $(INS.FILES)
346
347$. $(INSDIRS) $(TARGDIRS):
348 $(call MKDIR,$@)
349
350# bird: add rule for forcibly re-generating the rules.
351rules:
352 @$(call ECHO,smak don't generate rules anylonger!)
353
354# The general a.out -> OMF conversion rules for object files
355$.omf/%.obj:
356 $(call DO.EMXOMF)
357$.omf-log/%.obj:
358 $(call DO.EMXOMF)
359$.omf-prof/%.obj:
360 $(call DO.EMXOMF)
361
362# The general a.out -> OMF conversion rule for libraries
363$.omf%.lib:
364 $(call DO.EMXOMF)
365
Note: See TracBrowser for help on using the repository browser.