2016-07-21 8 views
1

그래서 QuestaSim 및 systemverilog 파일과 함께 사용할 Makefile을 작성하려고합니다. 그것이 무엇인지 (그리고 대부분의 사람들은 그렇지 않다는 것을) 모른다면 걱정하지 마십시오. 그것은 제 문제와 관련이 없습니다. SRC/일/메이크컴파일 된 오브젝트 파일이 다른 이름의 다른 디렉토리에있는 경우 makefile을 작성하는 방법은 무엇입니까?

SRC에/디렉토리가 각 소스 파일이 포함 된 여러 디렉토리를 포함합니다

나는이 포함 된 프로젝트 디렉터 있습니다.

작업/디렉토리는 처음에는 존재하지 않으며 메이크 파일에 의해 생성됩니다.

"vlog"라고하는 "컴파일러"를 호출 할 때 .sv 파일에서 .sv 파일과 동일한 이름의 작업 폴더에 접미사가없는 디렉토리가 만들어집니다. 그 디렉토리에 내가 "객체"파일로 사용하는 파일 세 개가 _primary.dat입니다.

예를 들어 "vlog src/interface/my_interface.sv"를 호출하면 (성공하면) 작업이 생성됩니다

/my_interface/_primary.dat 내 .sv 파일은 특정 순서로 컴파일해야하고, 난 단지 소스 파일 또는 종속성 중 하나가 변경된 경우를 컴파일합니다.

내가 설정할 수 있습니다 "$ (addsuffix /_primary.dat, $ (addprefix $ (VLIB_DIR) /, $ (basename $ (notdir $ (SRC)))))))를 사용하여 관련 _primary.dat 파일의 경로로 .sv 파일 경로 "그러나 디렉토리 구조가 느슨해지면서 그 반대가 불가능합니다.

그래서 제가 생각하기에 객체 -> src의 일종의지도가 있다고 생각합니다. 그래서 내 $ (OBJ) 타겟 : "vlog $ (getsrc $ @)"할 수 있습니다.

그런 다음에 컴파일 순서와 의존성을 처리해야하지만, 아마도 그것을 해결할 수 있습니다.

제안 사항?

+0

1) 소스 이름 충돌의 위험이 있습니까? 즉,'src/interface/foo.sv'가 있다면'src/engine/foo.sv'도있을 수 있습니까? 2)'src /'가 2 단계 이상 깊이있을 수 있습니까? 즉,'src/foo/bar/baz.sv'가있을 수 있습니까? – Beta

+0

패키지/인터페이스/모듈의 이름이 파일과 동일해야합니다. 따라서 어떤 충돌이라도 컴파일 오류가 발생합니다. 현재 디렉토리는 두 단계로 구성되어 있지만 나중에 더 많은 단계를 추가 할 것을 고려할 수 있습니다. –

+0

Questa와 함께 제공되는'vmake' 유틸리티를 보셨습니까? –

답변

0

나는 해결책을 찾았습니다. 나는 그것이 가장 깨끗한지는 모르지만이 문제가있는 다른 사람들을 돕기 위해 여기에 게시 할 것입니다.

기본적으로 .sv 원본 파일 경로 및 이름과 종속성 목록의 두 인수를 사용하는 매크로를 만듭니다. 그러면 소스 파일 경로가 오브젝트 파일 경로로 바뀌고 대상으로 생성됩니다. 소스 파일과 의존성에 대한 의존성. 그런 다음 모든 소스를 포함하는 변수를 만듭니다. 마지막으로 다음과 같이합니다 : 모든 타겟을 만드는 $ (foreach src, $ (SRCS), $ (eval $ (call create_target_for, $ (src)))).

또한 각 하위 디렉토리는 관련된 종속성을 가지고 있으며, 디렉토리에서 올바른 컴파일 순서를 얻을 수 있습니다.

유일한 단점은 단일 디렉토리의 파일이 올바른 컴파일 순서를 갖춰야한다는 것입니다.

내 메이크 :

# Makefile for use in building all my UVM components 
# ---------------------------------------------------------------------------------- 
# Requirements: 
# QuestaSim - We use the vlog compiler packaged with QuestaSim. 
#  ModelSim also comes with vlog, but doesn't really support UVM. 
# UVM_INCLUDE_DIR environment var - This should point to the UVM src directory. 
#  For me this is: C:\questasim_10.0b\verilog_src\uvm-1.0p1\src 
# ---------------------------------------------------------------------------------- 
# Notes: 
# The vlog compiler creates an output folder in the VLIB_DIR directors 
# per package/module/interface with the same name as the entity 
# Any capitals are replace with @ followed by the lower case letter 
# IE. FooBar -> @[email protected] 
# This makefile requires that: 
#  All interfaces end in _if 
#  All packages end in _pkg 
#  Each file can only contain a single interface, package or module 
#  No capitals in package/module/interface naems 
#  The package/module/interface has the same name as the file 

# some variabls to use later 
VLIB_DIR = ./work 
VLOG_FLAGS = +incdir+$(UVM_INCLUDE_DIR) 

# src files - per directory for use with compile orders 
#    ie. transactions have to be compiled before drivers 
INTERFACE_SRCS  = $(wildcard src/interfaces/*.sv) 
CONFIG_SRCS   = $(wildcard src/configs/*.sv) 
TRANSACTION_SRCS = $(wildcard src/transactions/*.sv) 
SEQUENCE_SRCS  = $(wildcard src/sequences/*.sv) 
DRIVER_SRCS   = $(wildcard src/drivers/*.sv) 
MONITOR_SRCS  = $(wildcard src/monitors/*.sv) 
AGENT_SRCS   = $(wildcard src/agents/*.sv) 
SCOREBOARD_SRCS  = $(wildcard src/scoreboards/*.sv) 

# all source files - for use with creating makefile targets 
SRCS    = $(INTERFACE_SRCS) \ 
         $(CONFIG_SRCS) \ 
         $(TRANSACTION_SRCS) \ 
         $(SEQUENCE_SRCS) \ 
         $(DRIVER_SRCS) \ 
         $(MONITOR_SRCS) \ 
         $(AGENT_SRCS) \ 
         $(SCOREBOARD_SRCS) 

# list of all the components 
COMPONENTS = interfaces \ 
       configs \ 
       transactions \ 
       sequences \ 
       drivers \ 
       monitors \ 
       agents \ 
       scoreboards 

# colours for use in echo commands for highlighting 
COLOUR_NONE  = \x1b[0m 
COLOUR_RED  = \x1b[31;01m 
COLOUR_BLUE  = \x1b[34;01m 
COLOUR_GREEN = \x1b[32;01m 

# macros to turn a .sv file into the compiled file in the relevant VLIB_DIR subdirectory 
# src/abc/def.sv -> $(VLIB_DIR)/def/_primary.dat 
src2obj  = $(addsuffix /_primary.dat, $(addprefix $(VLIB_DIR)/, $(basename $(notdir $(1))))) 

# macro to create a target for a given source file 
# it takes two arguments: 
# 1) the path and name of the source file 
# 2) any dependencies 
# It then creates a traget on the relevant _primary.dat (questaSim created object) 
# with a dependency on the source file, and any other passed in dependencies 
define create_target_for 

$$(info $COLOUR_GREEN create_target_for called on $(1)) 
$$(info creating target $(call src2obj, $(1))) 
$$(info with dependencies $(VLIB_DIR) $(1) $(2)) 
$$(info) 
$(call src2obj, $(1)): $(1) $(2) 
    @echo -e "$(COLOUR_BLUE)compiling $(1) because of changes in: $$? $(COLOUR_NONE)\n" 
    vlog $(VLOG_FLAGS) $(1) 

endef 

# default rule is to create the library, compile the UVM pkg and all the components 
all: $(VLIB_DIR) UVM $(COMPONENTS) 

# create the questaSim library if it's not already there 
$(VLIB_DIR): 
    vlib $(VLIB_DIR) 
    @echo -e "$(COLOUR_GREEN)Created the $(VLIB_DIR) library$(COLOUR_NONE)\n" 

# compile the UVM library 
$(VLIB_DIR)/uvm_pkg/_primary.dat: 
    vlog +incdir+$(UVM_INCLUDE_DIR) $(UVM_INCLUDE_DIR)/uvm.sv 
    @echo -e "$(COLOUR_GREEN)Compiled the UVM package$(COLOUR_NONE)\n" 

# simple alias 
UVM: $(VLIB_DIR) $(VLIB_DIR)/uvm_pkg/_primary.dat 

# create targets for all our sources 
# note with this method we can't set dependencies within a single directory 
$(foreach src,$(SRCS),$(eval $(call create_target_for, $(src)))) 

# define a phony target per directory so we can specify compile order 
interfaces: $(VLIB_DIR) UVM \ 
      $(call src2obj, $(INTERFACE_SRCS)) 
    @echo -e "$(COLOUR_GREEN)Compiled all [email protected]$(COLOUR_NONE)\n" 

configs: $(VLIB_DIR) UVM \ 
     $(call src2obj, $(CONFIG_SRCS)) 
    @echo -e "$(COLOUR_GREEN)Compiled all [email protected]$(COLOUR_NONE)\n" 

transactions: $(VLIB_DIR) UVM \ 
       $(call src2obj, $(TRANSACTION_SRCS)) 
    @echo -e "$(COLOUR_GREEN)Compiled all [email protected]$(COLOUR_NONE)\n" 

sequences: $(VLIB_DIR) UVM \ 
      transactions \ 
      $(call src2obj, $(SEQUENCE_SRCS)) 
    @echo -e "$(COLOUR_GREEN)Compiled all [email protected]$(COLOUR_NONE)\n" 

drivers: $(VLIB_DIR) UVM \ 
     transactions interfaces \ 
     $(call src2obj, $(DRIVER_SRCS)) 
    @echo -e "$(COLOUR_GREEN)Compiled all [email protected]$(COLOUR_NONE)\n" 

monitors: $(VLIB_DIR) UVM \ 
      transactions interfaces \ 
      $(call src2obj, $(MONITOR_SRCS)) 
    @echo -e "$(COLOUR_GREEN)Compiled all [email protected]$(COLOUR_NONE)\n" 

agents: $(VLIB_DIR) UVM \ 
     drivers monitors transactions configs interfaces \ 
     $(call src2obj, $(AGENT_SRCS)) 
    @echo -e "$(COLOUR_GREEN)Compiled all [email protected]$(COLOUR_NONE)\n" 

scoreboards: $(call src2obj, $(SCOREBOARD_SRCS)) 
    @echo -e "$(COLOUR_GREEN)Compiled all [email protected]$(COLOUR_NONE)\n" 

# delete the library and all compiled files 
clean: 
    if [ -d $(VLIB_DIR) ]; then vdel -lib $(VLIB_DIR) -all; fi; 

.PHONY: clean UVM $(COMPONENTS)