382 | | |
| 382 | |
| 383 | Nous allons systématiquement utiliser des Makefiles pour la compilation du code, mais aussi pour lancer le simulateur du prototype **almo1**. Pour cette première séance, les Makefiles ne permettent pas de faire des recompilations partielles de fichiers. Les Makefiles sont utilisés pour agréger toutes les actions que nous voulons faire sur les fichiers, c'est-à-dire : compiler, exécuter avec ou sans trace, nettoyer le répertoire. Nous avons recopiez le premier Makefile pour montrer sa forme et poser quelques questions, auxquels vous savez certainement répondre. |
| 384 | {{{#!make |
| 385 | # Tools and parameters definitions |
| 386 | # ------------------------------------------------------------------------------ |
| 387 | NTTY ?= 2 # default number of ttys |
| 388 | |
| 389 | CC = mipsel-unknown-elf-gcc # compiler |
| 390 | LD = mipsel-unknown-elf-ld # linker |
| 391 | OD = mipsel-unknown-elf-objdump # desassembler |
| 392 | SX = almo1.x # prototype simulator |
| 393 | |
| 394 | CFLAGS = -c # stop after compilation, then produce .o |
| 395 | CFLAGS += -Wall -Werror # gives almost all C warnings and considers them to be errors |
| 396 | CFLAGS += -mips32r2 # define of MIPS version |
| 397 | CFLAGS += -std=c99 # define of syntax version of C |
| 398 | CFLAGS += -fno-common # do not use common sections for non-static vars (only bss) |
| 399 | CFLAGS += -fno-builtin # do not use builtin functions of gcc (such as strlen) |
| 400 | CFLAGS += -fomit-frame-pointer # only use of stack pointer ($29) |
| 401 | CFLAGS += -G0 # do not use global data pointer ($28) |
| 402 | CFLAGS += -O3 # full optimisation mode of compiler |
| 403 | CFLAGS += -I. # directories where include files like <file.h> are located |
| 404 | CFLAGS += -DNTTYS=$(NTTY) # #define NTTYS with the number of ttys in the prototype |
| 405 | |
| 406 | FROM ?= 0 # first cycles to trace |
| 407 | NCYC ?= 10000 # number of cycles to execute |
| 408 | |
| 409 | # Rules (here they are used such as simple shell scripts) |
| 410 | # ------------------------------------------------------------------------------ |
| 411 | help: |
| 412 | @echo "\nUsage : make <compil|exec|trace|clean> [FROM=num] [NCYC=num]\n" |
| 413 | @echo " compil : compile all sources" |
| 414 | @echo " exec : prototype execution" |
| 415 | @echo " trace : execution with a trace for debug (trace.log)" |
| 416 | @echo " FROM is the first cycle from which the trace is made" |
| 417 | @echo " NCYC is the number of cycles to execute" |
| 418 | @echo " clean : clean all compiled files\n" |
| 419 | |
| 420 | compil: |
| 421 | $(CC) -o hcpu.o $(CFLAGS) hcpu.S |
| 422 | @$(OD) -D hcpu.o > hcpu.o.s |
| 423 | $(LD) -o kernel.x -T kernel.ld hcpu.o |
| 424 | @$(OD) -D kernel.x > kernel.x.s |
| 425 | |
| 426 | exec: compil |
| 427 | $(SX) -KERNEL kernel.x -NTTYS $(NTTY) |
| 428 | |
| 429 | trace: compil |
| 430 | $(SX) -KERNEL kernel.x -DEBUG $(FROM) -NCYCLES $(NCYC) -NTTYS $(NTTY) > details.log;\ |
| 431 | echo -e "\ngenerate trace.log, please wait... ";\ |
| 432 | tracelog -vout="trace.log.s" *.x.s details.log ;\ |
| 433 | rm details.log |
| 434 | |
| 435 | clean: |
| 436 | -rm *.o* *.x* *~ *.log.* proc?_term? 2> /dev/null || true |
| 437 | |
| 438 | }}} |
| 439 | 4. Au début du fichier se trouve la déclaration des variables du Makefile, quelle est la différence entre `=`, `?=` et `+=` ? |
| 440 | {{{#!protected ------------------------------------------------------------------------------------ |
| 441 | ''''''''''''''' |
| 442 | * |
| 443 | ''''''''''''''' |
| 444 | }}} |
| 445 | 1. Que fait `-DNTTYS=$(NTTY)` ? |
| 446 | {{{#!protected ------------------------------------------------------------------------------------ |
| 447 | ''''''''''''''' |
| 448 | * |
| 449 | ''''''''''''''' |
| 450 | }}} |