Annotation of prex/mk/Makefile.inc, Revision 1.1
1.1 ! nbrk 1: #
! 2: # Makefile.inc - common make rules to build Prex
! 3: #
! 4:
! 5: #
! 6: # Supported environment variables
! 7: #
! 8: # SRCDIR ... Root directory of source tree
! 9: # ARCH ... Architecture name
! 10: # PLATFORM ... Platform name
! 11: # NDEBUG ... 0 for debug, 1 for release (default: 0)
! 12: # LIBGCC_PATH ... Directory for libgcc.a
! 13: # CROSS_COMPILE ... Prefix of tools for cross compile
! 14: #
! 15: # Variables in local Makefile
! 16: #
! 17: # TARGET ... Target file name
! 18: # TYPE ... Traget type
! 19: # e.g. OBJECT,LIBRARY,KERNEL,BINARY,EXEC,DRIVER,OS_IMAGE
! 20: # SUBDIR ... List of subdirectories
! 21: # OBJS ... Object files
! 22: # OBJS-y ... Object files (for drivers)
! 23: # LIBS ... Libraries
! 24: # MAP ... Name of map file
! 25: # DISASM ... Disassemble list file
! 26: # SYMBOL ... Symbol files
! 27: #
! 28:
! 29: #
! 30: # Option for cross compile
! 31: #
! 32: #CROSS_COMPILE=
! 33: #CROSS_COMPILE= i386-elf-
! 34: #CROSS_COMPILE= arm-elf-
! 35: #CROSS_COMPILE= powerpc-eabi-
! 36: #CROSS_COMPILE= sh-elf-
! 37: #CROSS_COMPILE= mips-elf-
! 38:
! 39: #
! 40: # Tools
! 41: #
! 42: CC= $(CROSS_COMPILE)gcc
! 43: CPP= $(CROSS_COMPILE)cpp
! 44: AS= $(CROSS_COMPILE)as
! 45: LD= $(CROSS_COMPILE)ld
! 46: AR= $(CROSS_COMPILE)ar
! 47: OBJCOPY= $(CROSS_COMPILE)objcopy
! 48: OBJDUMP= $(CROSS_COMPILE)objdump
! 49: STRIP= $(CROSS_COMPILE)strip
! 50: LINT= splint
! 51: MAKE= make
! 52: #SHELL= /bin/sh
! 53: ifdef SHELL_PATH
! 54: SHELL= $(SHELL_PATH)
! 55: endif
! 56: ifdef DISASM
! 57: ASMGEN= $(OBJDUMP) $@ --disassemble-all > $(DISASM)
! 58: endif
! 59:
! 60: #
! 61: # System dependent options
! 62: #
! 63: include $(SRCDIR)/mk/own.mk
! 64:
! 65: #
! 66: # Flags
! 67: #
! 68: DEFS= -D__$(ARCH)__ -D__$(PLATFORM)__ \
! 69: -D__ARCH__=$(ARCH) -D__PLATFORM__=$(PLATFORM) \
! 70: -U$(ARCH) -U$(PLATFORM)
! 71:
! 72: CFLAGS+= -Os -ansi -pedantic -Wall -Wundef -fno-strict-aliasing \
! 73: -Wstrict-prototypes -Wpointer-arith \
! 74: $(CONFIG_CFLAGS) $(DEFS)
! 75:
! 76: ifeq ($(NDEBUG),1)
! 77: CFLAGS+= -fomit-frame-pointer
! 78: else
! 79: CFLAGS+= -fno-omit-frame-pointer -g
! 80: DEFS+= -DDEBUG
! 81: endif
! 82:
! 83: CPPFLAGS+= $(DEFS)
! 84: ASFLAGS+= $(DEFS) -D__ASSEMBLY__
! 85: ifdef MAP
! 86: LDFLAGS+= -Map $(MAP)
! 87: endif
! 88: LDFLAGS+=
! 89: MAKEFLAGS+= -rR --no-print-directory
! 90: LINTFLAGS+= -D__lint__ $(DEFS) -weak -nolib -retvalother -fcnuse
! 91:
! 92: #
! 93: # Specify path for libgcc.a
! 94: #
! 95: ifndef LIBGCC_PATH
! 96: LIBGCC_PATH := $(dir $(shell $(CC) $(GLOBAL_CFLAGS) -print-libgcc-file-name))
! 97: endif
! 98: LIBGCC = $(LIBGCC_PATH)libgcc.a
! 99:
! 100: #
! 101: # Inference rules
! 102: #
! 103: %.o: %.c
! 104: $(CC) $(CFLAGS) -c -o $@ $<
! 105:
! 106: %.o: %.s
! 107: $(AS) -o $@ $<
! 108:
! 109: %.o: %.S
! 110: $(CPP) $(ASFLAGS) $< $*.tmp
! 111: $(AS) -o $@ $*.tmp
! 112: rm -f $*.tmp
! 113:
! 114: #
! 115: # Target
! 116: #
! 117: all: $(SUBDIR) $(TARGET)
! 118:
! 119: #
! 120: # Check configuration
! 121: #
! 122: ifeq (0, ${MAKELEVEL})
! 123: # add dependency on config.h
! 124: $(SUBDIR):$(SRCDIR)/conf/config.h
! 125:
! 126: $(SRCDIR)/conf/config.h: dummy
! 127: @if [ ! -f $@ ]; then \
! 128: echo 'You must run `configure` before make.' ;\
! 129: exit 1 ;\
! 130: fi
! 131: endif
! 132:
! 133: #
! 134: # Rules to process sub-directory
! 135: #
! 136: ifdef SUBDIR
! 137: .PHONY: $(SUBDIR)
! 138: $(SUBDIR): dummy
! 139: $(MAKE) -C $@
! 140: endif
! 141:
! 142: #
! 143: # Rules to link a set of .o files into one .o file
! 144: #
! 145: ifeq ($(TYPE),OBJECT)
! 146: $(TARGET): $(OBJS) $(OBJS-y)
! 147: $(LD) $(LDFLAGS) -r -o $@ $^
! 148: endif
! 149:
! 150: #
! 151: # Rules to compile library
! 152: #
! 153: ifeq ($(TYPE),LIBRARY)
! 154: $(TARGET): $(OBJS) ar-target
! 155:
! 156: .PHONY: ar-target
! 157: ar-target: $(OBJS)
! 158: $(AR) rucs $(TARGET) $?
! 159: $(STRIP) -x -R .comment -R .note $(TARGET)
! 160: endif
! 161:
! 162: #
! 163: # Rules to compile kernel
! 164: #
! 165: ifeq ($(TYPE),KERNEL)
! 166: $(TARGET): $(OBJS) $(LIBS) $(LDS_SCRIPT)
! 167: $(LD) $(LDFLAGS) -T $(LD_SCRIPT) -o $@ $(OBJS) $(LIBS) $(LIBGCC)
! 168: $(ASMGEN)
! 169: ifdef SYMBOL
! 170: cp $@ $(SYMBOL)
! 171: endif
! 172: $(STRIP) -s $@
! 173: endif
! 174:
! 175: #
! 176: # Rules to compile device driver
! 177: #
! 178: ifeq ($(TYPE),DRIVER)
! 179: $(TARGET): $(OBJS) $(OBJS-y) $(LDS_SCRIPT)
! 180: $(LD) --error-unresolved-symbols $(LDFLAGS) -T $(LD_SCRIPT) -o $@.tmp $(OBJS) $(LIBS) $(LIBGCC)
! 181: rm -f $@.tmp
! 182: $(LD) -r $(LDFLAGS) -T $(LD_SCRIPT) -o $@ $(OBJS) $(LIBS) $(LIBGCC)
! 183: $(ASMGEN)
! 184: ifdef SYMBOL
! 185: cp $@ $(SYMBOL)
! 186: endif
! 187: $(STRIP) --strip-debug --strip-unneeded $@
! 188: endif
! 189:
! 190: #
! 191: # Rules to compile binary file
! 192: #
! 193: ifeq ($(TYPE),BINARY)
! 194: $(TARGET): $(OBJS) $(LDS_SCRIPT)
! 195: $(LD) $(LDFLAGS) -T $(LD_SCRIPT) -o $@ $(OBJS) $(LIBS) $(LIBGCC)
! 196: $(ASMGEN)
! 197: ifdef SYMBOL
! 198: cp $@ $(SYMBOL)
! 199: endif
! 200: $(OBJCOPY) $(OBJCOPYFLAGS) $@
! 201: endif
! 202:
! 203: #
! 204: # Rules to compile executable file
! 205: #
! 206: ifeq ($(TYPE),EXEC)
! 207: $(TARGET): $(OBJS) $(LIBS) $(LDS_SCRIPT)
! 208: $(LD) $(LDFLAGS) -T $(LD_SCRIPT) -o $@ \
! 209: $(CRT0) $(OBJS) $(LIBS) $(LIBC) $(LIBGCC)
! 210: $(ASMGEN)
! 211: ifdef SYMBOL
! 212: cp $@ $(SYMBOL)
! 213: endif
! 214: $(STRIP) --strip-debug --strip-unneeded $@
! 215: endif
! 216:
! 217: #
! 218: # Rules to create OS image
! 219: #
! 220: ifeq ($(TYPE),OS_IMAGE)
! 221: $(TARGET): dummy
! 222: ifdef BOOTFILES
! 223: $(AR) rcS ramdisk.a $(BOOTFILES)
! 224: $(AR) t ramdisk.a
! 225: $(AR) rcS tmp.a $(KERNEL) $(DRIVER) $(BOOTTASKS) ramdisk.a
! 226: rm ramdisk.a
! 227: else
! 228: $(AR) rcS tmp.a $(KERNEL) $(DRIVER) $(BOOTTASKS)
! 229: endif
! 230: $(AR) t tmp.a
! 231: cat $(LOADER) tmp.a > $@
! 232: rm tmp.a
! 233: endif
! 234:
! 235:
! 236: -include Makefile.dep
! 237:
! 238: ifndef SRCS
! 239: SRCS = $(OBJS:.o=.c)
! 240: endif
! 241:
! 242: #
! 243: # Depend
! 244: #
! 245: .PHONY: depend dep
! 246: depend dep:
! 247: ifdef SUBDIR
! 248: @(for d in $(SUBDIR) _ ; do \
! 249: if [ "$$d" != "_" ] ; then $(MAKE) -C $$d depend; fi; \
! 250: done);
! 251: endif
! 252: rm -f Makefile.dep
! 253: @(for d in $(SRCS) _ ; do \
! 254: if [ "$$d" != "_" ] ; then \
! 255: $(CPP) -M $(CPPFLAGS) $$d >> Makefile.dep; fi; \
! 256: done);
! 257: #
! 258: # Lint
! 259: #
! 260: .PHONY: lint
! 261: lint:
! 262: ifdef SUBDIR
! 263: @(for d in $(SUBDIR) _ ; do \
! 264: if [ "$$d" != "_" ] ; then $(MAKE) -C $$d lint; fi; \
! 265: done);
! 266: endif
! 267: @(for d in $(SRCS) _ ; do \
! 268: if [ "$$d" != "_" ] ; then \
! 269: echo ; \
! 270: echo "Checking $$d" ; \
! 271: $(LINT) $(LINTFLAGS) $(INCLUDE) $$d; fi; \
! 272: done);
! 273:
! 274: #
! 275: # Clean up
! 276: #
! 277: .PHONY: clean
! 278: clean:
! 279: ifdef SUBDIR
! 280: @(for d in $(SUBDIR) _ ; do \
! 281: if [ "$$d" != "_" ] ; then $(MAKE) -C $$d clean; fi; \
! 282: done);
! 283: endif
! 284: rm -f Makefile.dep $(TARGET) $(OBJS) $(OBJS-y) $(DISASM) $(MAP) $(SYMBOL) $(CLEANS)
! 285:
! 286: .PHONY: dummy
CVSweb