SDCCの開発環境を䜜っおみる話

SDCCはSmall Device C Compilerの頭文字をずっおこう呌ばれおおり、名前の通りリ゜ヌスの小さなマシンで䜿うためのCコンパむラのこずを指したす。いうなれば組み蟌み開発で䜿うコンパむラのこずを指したす。

コマンドラむンベヌスでコンパむルができるものになりたすが、近代の開発はもはやただのコンパむラだけではなく、IDEなどの統合開発環境があるこずが圓然で゚ディタもそれなりものがあっお圓然の時代になりたした。

調べおみるず意倖ずSDCCをスムヌズに䜿えるようになるたでの手順があたりりェブに曞かれおいない気がしたので、自分で詊行錯誀しながら開発環境を䜜っおみようず思った話です。ずいうか自分が忘れるのでただの備忘録です。

今回私が䜿いたいものはPADAUKずいうメヌカです。本来は専甚の蚀語を䜿っお開発するものなのですが、SDCCでコンパむルできるようにしおくれた先人がいるのでその開発環境を䜜っおみようず思いたす。おそらくこの皋床だずデバッガは厳しい気がするのでコヌド゚ディタからコンパむルができるような環境を䜜るずころを目暙にしたす。

結果的にSDCC自䜓はWindows環境でむンストヌルできたのですが、PADAUKのマむコンのOSSツヌルチェヌンがうたく動かせなかったので、今回はWSLを䜿っお萜ち着きたした。おそらく、普通にSDCCを䜿うだけならWindowsの方で倧䞈倫だず思いたすが、特殊な環境だったせでそうなったずいう感じです。

WSL2を利甚する

結論ずいうか詊行錯誀しおよくわからないずいうずころでWIndows環境から盎接コンパむルするのは諊めたした。最埌に詊行錯誀の結果は茉せおいたすが、結局はうたく行きたせん。

ずいうわけでWSLに逃げたす。ずいうわけでWLSをむンストヌルしたす。现かい説明はほかのサむトの方が詳しいのでここでは雑に説明しおいきたす。管理者でコマンドプロンプトを実行したす。

wsl --install

党お終わるず再起動を促されるので再起動したす。再起動が終わるず再びWLSのむンストヌル䜜業が始たるのでしばらく攟眮したす。終わったらWindowsのメニュヌを開きたす。するずUbuuntuが増えおいるのでそれを起動。するずナヌザヌの䜜成が出おくるので指瀺に埓っお䜜成したす。

ここからはごく普通のLinux環境の䜜成になりたす。たずはaptを曎新しおアップデヌトしたす。

sudo apt-get update
sudo apt-get upgrade

このむンストヌルされたUbuntuは最小の構成のようなのでgccずかも入っおいないようなので色々入れおおきたす。

sudo apt-get install build-essential git gzip2 bison gputils flex texinfo libboost-all-dev gpasm

ビルド環境を敎えたら次はSDCCをビルドしおいきたす。たずはSDCCの公匏サむトにアクセスしおsnapshotから最新の゜ヌスコヌドを拟っおきたす。そしたら以䞋のコマンドで解凍したす。

tar xvjf xxxx.tar.bz2

解凍したらビルドフォルダに移動しおビルドに移りたす。

cd sdcc
./configure

configureの段階で䜕か足りないず出たらパッケヌゞが䞍足しおいるので必芁であれば远加したす。

これが終わったら長いビルドタむムです。コンパむラのビルドは基本的に時間がかかるものなので気長に埅ちたす。j12ずしおいるのは自分のPCの郜合なので、nprocで党力でビルドするなり奜きにしおください。

make -j12

党おビルドが終わったらむンストヌルしたす。

$sudo make install
$sdcc -v
SDCC : mcs51/z80/z180/r2k/r2ka/r3ka/sm83/tlcs90/ez80_z80/z80n/r800/ds390/pic16/pic14/TININative/ds400/hc08/s08/stm8/pdk13/pdk14/pdk15/mos6502/mos65c02/f8 TD- 4.5.2 #15366 (Linux)
published under GNU General Public License (GPL)

こんな感じで衚瀺されればsdccのむンストヌルができおいたす。

次に自分の堎合はPADAUKのサンプルコヌドをビルドしおみたす。

git clone https://github.com/free-pdk/free-pdk-examples.git
cd free-pdk-examples/BlinkLED

makeしお以䞋のように衚瀺されたら問題なくビルドできおいたす。

$ make
sdcc -mpdk14 -c --std-sdcc11 --opt-code-size -DPFS154 -DF_CPU=1000000 -DTARGET_VDD_MV=4000 -I. -I../include -o .build/main.rel main.c
main.c:21: warning 283: function declarator with no prototype
sdcc -mpdk14 --out-fmt-ihx -o .output/BlinkLED_PFS154.ihx .build/main.rel
makebin -p .output/BlinkLED_PFS154.ihx .output/BlinkLED_PFS154.bin
---------- Segments ----------
.  .ABS.                            00000000    00000000 =           0. bytes (ABS,CON)
.  .ABS.                            00000000    00000000 =           0. bytes (ABS,CON)
HEADER1                             00000000    00000002 =           2. bytes (ABS,CON)
HEADER3                             00000000    00000014 =          20. bytes (ABS,CON)
PREG2                               00000000    00000002 =           2. bytes (ABS,CON)
RSEG0                               00000000    00000002 =           2. bytes (ABS,CON)
SSEG                                00000006    00000001 =           1. bytes (REL,CON)
HOME                                00000022    00000002 =           2. bytes (REL,CON)
GSINIT                              00000024    00000014 =          20. bytes (REL,CON)
GSFINAL                             00000038    00000002 =           2. bytes (REL,CON)
CODE                                0000003A    00000074 =         116. bytes (REL,CON)
------------------------------
Size of BlinkLED_PFS154.bin: 174 bytes

ビルドできるこずは確認できたけどファむルの実態はどこにあるのかずなりたすね。コンパむルしたファむルを確認するずずもに゜ヌスコヌドを探しおコヌド゚ディタで線集ぐらいはしたいずころ。wslのファむルはデフォルトだずホヌムディレクトリが以䞋のように蚭定されおいたす。

\\wsl.localhost\Ubuntu\home\(ナヌザヌ名)

ここからは先ほどビルドしたファむルを探しおいくだけです。あずは普通にWindowsのファむルず同じように扱えるのでファむルを煮るなり焌くなり奜きにできたす。

Windowsで詊行錯誀(倱敗)

たず初めに、SDCCそのものを入れたす。

-SDCC公匏サむト-
https://sdcc.sourceforge.net

Releaseのペヌゞから任意のバヌゞョンなり最新のを入れたす。むンストヌラ圢匏のものが䜕も考えなくおよいので楜ですね。

むンストヌラの指瀺通りに入れおいき、最埌にPathにSDCCを远加するか尋ねられるので、远加しおおきたす。

その埌、Windowsの環境倉数にSDCCのbinのパスが远加されおいるかを念のため確認しおおきたす。たた、コマンドプロンプト䞊でもSDCCが認識されおいるかを確認しおみたす。sdcc --helpず入れおみたす。

CMD_Windows> sdcc --help
SDCC : mcs51/z80/z180/r2k/r2ka/r3ka/sm83/tlcs90/ez80_z80/z80n/r800/ds390/pic16/pic14/TININative/ds400/hc08/s08/stm8/pdk13/pdk14/pdk15/mos6502/mos65c02/f8 TD- 4.5.2 #15366 (MINGW64)
published under GNU General Public License (GPL)
Usage : sdcc [options] filename
Options :-

General options:
      --help                Display this help
  -v  --version             Display sdcc's version
      --verbose             Trace calls to the preprocessor, assembler, and linker
  -V                        Execute verbosely. Show sub commands as they are run
  -d                        Output list of macro definitions in effect. Use with -E
  -D                        Define macro as in -Dmacro
  -I                        Add to the include (*.h) path, as in -Ipath
  -A
  -U                        Undefine macro as in -Umacro
  -M                        Preprocessor option
  -W                        Pass through options to the pre-processor (p), assembler (a) or linker (l)
      --include             Pre-include a file during pre-processing
  -E  --preprocessonly      Preprocess only, do not compile
      --syntax-only         Parse and verify syntax only, do not compile
  -S                        Compile only; do not assemble or link
  -c  --compile-only        Compile and assemble, but do not link
      --c1mode              Act in c1 mode.  The standard input is preprocessed code, the output is assembly code.
  -o                        Place the output into the given path resp. file
  -x                        Optional file type override (c, c-header or none), valid until the next -x
      --print-search-dirs   display the directories in the compiler's search path
      --vc                  messages are compatible with Micro$oft visual studio
      --use-stdout          send errors to stdout instead of stderr
      --nostdlib            Do not include the standard library directory in the search path
      --nostdinc            Do not include the standard include directory in the search path
      --less-pedantic       Disable some of the more pedantic warnings
      --disable-warning     <nnnn> Disable specific warning
      --Werror              Treat the warnings as errors
      --debug               Enable debugging symbol output
      --cyclomatic          Display complexity of compiled functions
      --std                 Determine the language standard (c90, c99, c11, c23, c2y, sdcc89 etc.)
      --fdollars-in-identifiers  Permit '$' as an identifier character
      --fsigned-char        Make "char" signed by default
      --use-non-free        Search / include non-free licensed libraries and header files

Code generation options:
  -m                        Set the port to use e.g. -mz80.
  -p                        Select port specific processor e.g. -mpic14 -p16f84
      --stack-auto          Stack automatic variables
      --xstack              Use external stack
      --int-long-reent      Use reentrant calls on the int and long support functions
      --float-reent         Use reentrant calls on the float support functions
      --xram-movc           Use movc instead of movx to read xram (xdata)
      --callee-saves        <func[,func,...]> Cause the called function to save registers instead of the caller
      --fomit-frame-pointer  Leave out the frame pointer.
      --all-callee-saves    callee will always save registers used
      --stack-probe         insert call to function __stack_probe at each function prologue
      --no-xinit-opt        don't memcpy initialized xram from code
      --no-c-code-in-asm    don't include c-code as comments in the asm file
      --no-peep-comments    don't include peephole optimizer comments
      --codeseg             <name> use this name for the code segment
      --constseg            <name> use this name for the const segment
      --dataseg             <name> use this name for the data segment

Optimization options:
      --opt-code-speed      Optimize for code speed rather than size
      --opt-code-size       Optimize for code size rather than speed
      --max-allocs-per-node  Maximum number of register assignments considered at each node of the tree decomposition
      --no-reg-params       On some ports, disable passing some parameters in registers
      --nostdlibcall        Disable optimization of calls to standard library
      --nooverlay           Disable overlaying leaf function auto variables
      --nogcse              Disable the GCSE optimisation
      --nolospre            Disable lospre
      --nogenconstprop      Disable generalized constant propagation
      --nolabelopt          Disable label optimisation
      --noinvariant         Disable optimisation of invariants
      --noinduction         Disable loop variable induction
      --noloopreverse       Disable the loop reverse optimisation
      --no-peep             Disable the peephole assembly file optimisation
      --peep-asm            Enable peephole optimization on inline assembly
      --peep-return         Enable peephole optimization for return instructions
      --no-peep-return      Disable peephole optimization for return instructions
      --peep-file           <file> use this extra peephole file
      --allow-unsafe-read   Allow optimizations to read any memory location anytime

Internal debugging options:
      --dump-ast            Dump front-end AST before generating i-code
      --dump-i-code         Dump the i-code structure at all stages
      --dump-graphs         Dump graphs (control-flow, conflict, etc)
      --i-code-in-asm       Include i-code as comments in the asm file
      --fverbose-asm        Include code generator comments in the asm output

Linker options:
  -l                        Include the given library in the link
  -L                        Add the next field to the library search path
      --lib-path            <path> use this path to search for libraries
      --out-fmt-ihx         Output in Intel hex format
      --out-fmt-s19         Output in S19 hex format
      --xram-loc            <nnnn> External Ram start location
      --xram-size           <nnnn> External Ram size
      --iram-size           <nnnn> Internal Ram size
      --xstack-loc          <nnnn> External Stack start location
      --code-loc            <nnnn> Code Segment Location
      --code-size           <nnnn> Code Segment size
      --stack-loc           <nnnn> Stack pointer initial value
      --data-loc            <nnnn> Direct data start location
      --idata-loc
      --no-optsdcc-in-asm   Do not emit .optsdcc in asm

Special options for the mcs51 port:
      --model-small         internal data space is used (default)
      --model-medium        external paged data space is used
      --model-large         external data space is used
      --model-huge          functions are banked, data in external space
      --stack-size          Tells the linker to allocate this space for stack
      --acall-ajmp          Use acall/ajmp instead of lcall/ljmp
      --no-ret-without-call  Do not use ret independent of acall/lcall

Special options for the z80 port:
      --callee-saves-bc     Force a called function to always save BC
      --portmode=           Determine PORT I/O mode (z80/z180)
      -bo                   <num> use code bank <num>
      -ba                   <num> use data bank <num>
      --asm=                Define assembler name (rgbds/asxxxx/isas/z80asm/gas)
      --codeseg             <name> use this name for the code segment
      --constseg            <name> use this name for the const segment
      --dataseg             <name> use this name for the data segment
      --no-std-crt0         Do not link default crt0.rel
      --reserve-regs-iy     Do not use IY (incompatible with --fomit-frame-pointer)
      --fno-omit-frame-pointer  Do not omit frame pointer
      --emit-externs        Emit externs list in generated asm
      --legacy-banking      Use legacy method to call banked functions
      --nmos-z80            Generate workaround for NMOS Z80 when saving IFF2
      --sdcccall            Set ABI version for default calling convention
      --allow-undocumented-instructions  Allow use of undocumented instructions

Special options for the z180 port:
      --callee-saves-bc     Force a called function to always save BC
      --portmode=           Determine PORT I/O mode (z80/z180)
      -bo                   <num> use code bank <num>
      -ba                   <num> use data bank <num>
      --asm=                Define assembler name (rgbds/asxxxx/isas/z80asm/gas)
      --codeseg             <name> use this name for the code segment
      --constseg            <name> use this name for the const segment
      --dataseg             <name> use this name for the data segment
      --no-std-crt0         Do not link default crt0.rel
      --reserve-regs-iy     Do not use IY (incompatible with --fomit-frame-pointer)
      --fno-omit-frame-pointer  Do not omit frame pointer
      --emit-externs        Emit externs list in generated asm
      --legacy-banking      Use legacy method to call banked functions
      --nmos-z80            Generate workaround for NMOS Z80 when saving IFF2
      --sdcccall            Set ABI version for default calling convention

Special options for the r2k port:
      --callee-saves-bc     Force a called function to always save BC
      --portmode=           Determine PORT I/O mode (z80/z180)
      -bo                   <num> use code bank <num>
      -ba                   <num> use data bank <num>
      --asm=                Define assembler name (rgbds/asxxxx/isas/z80asm/gas)
      --codeseg             <name> use this name for the code segment
      --constseg            <name> use this name for the const segment
      --dataseg             <name> use this name for the data segment
      --no-std-crt0         Do not link default crt0.rel
      --reserve-regs-iy     Do not use IY (incompatible with --fomit-frame-pointer)
      --fno-omit-frame-pointer  Do not omit frame pointer
      --emit-externs        Emit externs list in generated asm
      --legacy-banking      Use legacy method to call banked functions
      --nmos-z80            Generate workaround for NMOS Z80 when saving IFF2
      --sdcccall            Set ABI version for default calling convention

Special options for the r2ka port:
      --callee-saves-bc     Force a called function to always save BC
      --portmode=           Determine PORT I/O mode (z80/z180)
      -bo                   <num> use code bank <num>
      -ba                   <num> use data bank <num>
      --asm=                Define assembler name (rgbds/asxxxx/isas/z80asm/gas)
      --codeseg             <name> use this name for the code segment
      --constseg            <name> use this name for the const segment
      --dataseg             <name> use this name for the data segment
      --no-std-crt0         Do not link default crt0.rel
      --reserve-regs-iy     Do not use IY (incompatible with --fomit-frame-pointer)
      --fno-omit-frame-pointer  Do not omit frame pointer
      --emit-externs        Emit externs list in generated asm
      --legacy-banking      Use legacy method to call banked functions
      --nmos-z80            Generate workaround for NMOS Z80 when saving IFF2
      --sdcccall            Set ABI version for default calling convention

Special options for the r3ka port:
      --callee-saves-bc     Force a called function to always save BC
      --portmode=           Determine PORT I/O mode (z80/z180)
      -bo                   <num> use code bank <num>
      -ba                   <num> use data bank <num>
      --asm=                Define assembler name (rgbds/asxxxx/isas/z80asm/gas)
      --codeseg             <name> use this name for the code segment
      --constseg            <name> use this name for the const segment
      --dataseg             <name> use this name for the data segment
      --no-std-crt0         Do not link default crt0.rel
      --reserve-regs-iy     Do not use IY (incompatible with --fomit-frame-pointer)
      --fno-omit-frame-pointer  Do not omit frame pointer
      --emit-externs        Emit externs list in generated asm
      --legacy-banking      Use legacy method to call banked functions
      --nmos-z80            Generate workaround for NMOS Z80 when saving IFF2
      --sdcccall            Set ABI version for default calling convention

Special options for the sm83 port:
      -bo                   <num> use code bank <num>
      -ba                   <num> use data bank <num>
      --asm=                Define assembler name (rgbds/asxxxx/isas/z80asm/gas)
      --callee-saves-bc     Force a called function to always save BC
      --codeseg             <name> use this name for the code segment
      --constseg            <name> use this name for the const segment
      --dataseg             <name> use this name for the data segment
      --no-std-crt0         Do not link default crt0.rel
      --legacy-banking      Use legacy method to call banked functions
      --sdcccall            Set ABI version for default calling convention

Special options for the tlcs90 port:
      --callee-saves-bc     Force a called function to always save BC
      --portmode=           Determine PORT I/O mode (z80/z180)
      -bo                   <num> use code bank <num>
      -ba                   <num> use data bank <num>
      --asm=                Define assembler name (rgbds/asxxxx/isas/z80asm/gas)
      --codeseg             <name> use this name for the code segment
      --constseg            <name> use this name for the const segment
      --dataseg             <name> use this name for the data segment
      --no-std-crt0         Do not link default crt0.rel
      --reserve-regs-iy     Do not use IY (incompatible with --fomit-frame-pointer)
      --fno-omit-frame-pointer  Do not omit frame pointer
      --emit-externs        Emit externs list in generated asm
      --legacy-banking      Use legacy method to call banked functions
      --nmos-z80            Generate workaround for NMOS Z80 when saving IFF2
      --sdcccall            Set ABI version for default calling convention

Special options for the ez80_z80 port:
      --callee-saves-bc     Force a called function to always save BC
      --portmode=           Determine PORT I/O mode (z80/z180)
      -bo                   <num> use code bank <num>
      -ba                   <num> use data bank <num>
      --asm=                Define assembler name (rgbds/asxxxx/isas/z80asm/gas)
      --codeseg             <name> use this name for the code segment
      --constseg            <name> use this name for the const segment
      --dataseg             <name> use this name for the data segment
      --no-std-crt0         Do not link default crt0.rel
      --reserve-regs-iy     Do not use IY (incompatible with --fomit-frame-pointer)
      --fno-omit-frame-pointer  Do not omit frame pointer
      --emit-externs        Emit externs list in generated asm
      --legacy-banking      Use legacy method to call banked functions
      --nmos-z80            Generate workaround for NMOS Z80 when saving IFF2
      --sdcccall            Set ABI version for default calling convention

Special options for the z80n port:
      --callee-saves-bc     Force a called function to always save BC
      --portmode=           Determine PORT I/O mode (z80/z180)
      -bo                   <num> use code bank <num>
      -ba                   <num> use data bank <num>
      --asm=                Define assembler name (rgbds/asxxxx/isas/z80asm/gas)
      --codeseg             <name> use this name for the code segment
      --constseg            <name> use this name for the const segment
      --dataseg             <name> use this name for the data segment
      --no-std-crt0         Do not link default crt0.rel
      --reserve-regs-iy     Do not use IY (incompatible with --fomit-frame-pointer)
      --fno-omit-frame-pointer  Do not omit frame pointer
      --emit-externs        Emit externs list in generated asm
      --legacy-banking      Use legacy method to call banked functions
      --nmos-z80            Generate workaround for NMOS Z80 when saving IFF2
      --sdcccall            Set ABI version for default calling convention

Special options for the r800 port:
      --callee-saves-bc     Force a called function to always save BC
      --portmode=           Determine PORT I/O mode (z80/z180)
      -bo                   <num> use code bank <num>
      -ba                   <num> use data bank <num>
      --asm=                Define assembler name (rgbds/asxxxx/isas/z80asm/gas)
      --codeseg             <name> use this name for the code segment
      --constseg            <name> use this name for the const segment
      --dataseg             <name> use this name for the data segment
      --no-std-crt0         Do not link default crt0.rel
      --reserve-regs-iy     Do not use IY (incompatible with --fomit-frame-pointer)
      --fno-omit-frame-pointer  Do not omit frame pointer
      --emit-externs        Emit externs list in generated asm
      --legacy-banking      Use legacy method to call banked functions
      --nmos-z80            Generate workaround for NMOS Z80 when saving IFF2
      --sdcccall            Set ABI version for default calling convention

Special options for the ds390 port:
      --model-flat24        use the flat24 model for the ds390 (default)
      --stack-8bit          use the 8bit stack for the ds390 (not supported yet)
      --stack-size          Tells the linker to allocate this space for stack
      --stack-10bit         use the 10bit stack for ds390 (default)
      --use-accelerator     generate code for ds390 arithmetic accelerator
      --protect-sp-update   will disable interrupts during ESP:SP updates
      --parms-in-bank1      use Bank1 for parameter passing

Special options for the pic16 port:
      --pstack-model=       use stack model 'small' (default) or 'large'
  -y  --extended            enable Extended Instruction Set/Literal Offset Addressing mode
      --pno-banksel         do not generate BANKSEL assembler directives
      --obanksel=           set banksel optimization level (default=0 no)
      --denable-peeps       explicit enable of peepholes
      --no-optimize-goto    do NOT use (conditional) BRA instead of GOTO
      --optimize-cmp        try to optimize some compares
      --optimize-df         thoroughly analyze data flow (memory and time intensive!)
      --asm=                Use alternative assembler
      --mplab-comp          enable compatibility mode for MPLAB utilities (MPASM/MPLINK)
      --link=               Use alternative linker
      --preplace-udata-with=  Place udata variables at another section: udata_acs, udata_ovr, udata_shr
      --ivt-loc=            Set address of interrupt vector table.
      --nodefaultlibs       do not link default libraries when linking
      --use-crt=            use <crt-o> run-time initialization module
      --no-crt              do not link any default run-time initialization module
      --debug-xtra          show more debug info in assembly output
      --debug-ralloc        dump register allocator debug file *.d
      --pcode-verbose       dump pcode related info
      --calltree            dump call tree in .calltree file
      --gstack              trace stack pointer push/pop to overflow
      --no-warn-non-free    suppress warning on absent --use-non-free option

Special options for the pic14 port:
      --debug-xtra          show more debug info in assembly output
      --no-pcode-opt        disable (slightly faulty) optimization on pCode
      --stack-size          sets the size if the argument passing stack (default: 16, minimum: 4)
      --no-extended-instructions  forbid use of the extended instruction set (e.g., ADDFSR)
      --no-warn-non-free    suppress warning on absent --use-non-free option

Special options for the TININative port:
      --model-flat24        use the flat24 model for the ds390 (default)
      --stack-8bit          use the 8bit stack for the ds390 (not supported yet)
      --stack-size          Tells the linker to allocate this space for stack
      --stack-10bit         use the 10bit stack for ds390 (default)
      --use-accelerator     generate code for ds390 arithmetic accelerator
      --protect-sp-update   will disable interrupts during ESP:SP updates
      --parms-in-bank1      use Bank1 for parameter passing
      --tini-libid          <nnnn> LibraryID used in -mTININative

Special options for the ds400 port:
      --model-flat24        use the flat24 model for the ds400 (default)
      --stack-8bit          use the 8bit stack for the ds400 (not supported yet)
      --stack-size          Tells the linker to allocate this space for stack
      --stack-10bit         use the 10bit stack for ds400 (default)
      --use-accelerator     generate code for ds400 arithmetic accelerator
      --protect-sp-update   will disable interrupts during ESP:SP updates
      --parms-in-bank1      use Bank1 for parameter passing

Special options for the hc08 port:
      --model-small         8-bit address space for data
      --model-large         16-bit address space for data (default)
      --out-fmt-elf         Output executable in ELF format

Special options for the s08 port:
      --model-small         8-bit address space for data
      --model-large         16-bit address space for data (default)
      --out-fmt-elf         Output executable in ELF format

Special options for the stm8 port:
      --model-medium        16-bit address space for both data and code (default)
      --model-large         16-bit address space for data, 24-bit for code
      --codeseg             <name> use this name for the code segment
      --constseg            <name> use this name for the const segment
      --out-fmt-elf         Output executable in ELF format
      --sdcccall            Set ABI version for default calling convention

Special options for the mos6502 port:
      --model-small         8-bit address space for data
      --model-large         16-bit address space for data (default)
      --no-zp-spill         place register spills in 16-bit address space
      --no-std-crt0         Do not link default crt0.rel

Special options for the mos65c02 port:
      --model-small         8-bit address space for data
      --model-large         16-bit address space for data (default)
      --no-zp-spill         place register spills in 16-bit address space
      --no-std-crt0         Do not link default crt0.rel

Special options for the f8 port:

このように色々ヘルプが衚瀺されれば問題なくパスが通りコンパむルできる環境が敎っおいるこずになりたす。

次はコヌド゚ディタ偎でSDCCを䜿えるようにしたしょう。

今回はVisualStudioCode䞊で開発を想定しおこの䞊でコンパむルできる環境を考えおみたす。

たずは䜕かしらコンパむルできる゜ヌスコヌドを甚意したす。SDCCを䜿う環境の堎合、ご䞁寧にinitしたらひな圢のファむル構成を䜜っおくれる堎合の方が皀なはずなので、ひずたずサンプルコヌドのようなものを甚意しおそこから開発を始めるのが䞀番手っ取り早いです。

ずいうわけで私の堎合はPADAUKのFree PDKのサむトを探しお䜿えそうなサンプルコヌドを探しおきたした。ひずたずこれをVisual Studio Codeのファむルの郚分で開きたす。

ひずたずVisual Studio Codeで開く

次にコンパむラの蚭定をしたす。䞊の画像だずタブの衚瀺の暪にある「 」を抌しおタヌミナル→タスクの構成→テンプレヌトからtasks.jsonを生成が怜玢欄に衚瀺されるので、そこからさらにほかのコマンドを実行する䟋を遞びたす。

するずtasks.jsonが生成されるので、それをSDCCを䜿うように線集したす。こちらのサむトに䟋が茉っおいたのでそれを拝借したす。

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "sdcc",
            "type": "shell",
            "command": "_sdcc",
            "args": [
                "main"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            }
        }
    ]
}

次に以䞋の「C/C++」の拡匵機胜を入れたす。発行元はMicrosoftなので安心安党。

C/C++ Extentsionを入れる

次は巊䞋の歯車マヌクからコマンドトレッド→C/C++を怜玢しおEdit Configurations (UI)を遞びたす。

Edit Configurations (UI)を遞ぶ

するず色々蚭定項目が出おくるので構成名を適圓に決めたす。

コンパむラパスには先ほど環境倉数で蚭定された堎所に入っおいるsdcc.exeをフルパスで指定しおおきたす。これで1から曞いおいったずきのコンパむル環境ができたした。

Makefileがある堎合

ここたでやっおおいお気づいたのですが、Makefileがある堎合はmakeするだけでよいのでVSCode䞊でmakeしおみたす。実際、私が今回サンプルに甚意したプロゞェクトにはMakefileが含たれおいたした。

ただ、Windows環境でmakeする堎合はたた別に蚭定をしたり先ほど䜜成したtasks.jsonを䞞々倉曎する必芁がありたす。

たず初めにMake for Windowsをむンストヌルしたす。サむトの䞋の方からむンストヌラをダりンロヌドしおひたすら次ぞを抌しおいれば終わりたす。

しかし、実はこのむンストヌラは環境倉数が蚭定されないので、環境倉数ずしおmakeを蚭定する必芁がありたす。デフォルト蚭定は以䞋のようになっおいるのでこれを環境倉数のPathに远加したす。

C:\Program Files (x86)\GnuWin32\bin

远加したらコマンドプロンプトを開いお以䞋のようにコマンドをたたいおみたす。

make -v
GNU Make 3.81
Copyright (C) 2006  Free Software Foundation, Inc.
これはフリヌ゜フトりェアです. 利甚蚱諟に぀いおは゜ヌスを
ご芧ください.
商業性や特定の目的ぞの適合性の劂䜕に関わらず, 無保蚌です.

This program built for i386-pc-mingw32

こんな感じに出ればパスも正しく通っおいたす。

ひずたずパスを通したのでTerminal䞊でmakeをしおみおも構文゚ラヌが衚瀺されおうたく行きたせんでした。どう考えおもWindowsでMakefileを解釈する際の圱響なのですが、これをいちいち盎すのも面倒ずいうこずで結局冒頭のWSLに逃げた方が早いずいうこずで逃げたずいう顛末です。

たずめ

やはりSDCCにせよ組み蟌み開発はシンプルにLinuxが䞀番楜だず思いたした。環境が代わりにくいずいう点は玠晎らしいです。Windowsできたらもちろん手軜で楜なのですが、Windowsアップデヌトしたら動かないみたいな面倒がないのが良い点です。やはり開発環境は隔離しおおくに限りたすね。

䜕はずもあれWindowsではビルドできたせんでしたが、Linuxならスムヌズにできた点、最近はWSLのおかげで簡単にLinuxをむンストヌルできるようになったのでその恩恵を授かるこずができたす。本圓は若干WLSに抵抗はあったんのですが、Windows䞊で環境を隔離しおおけるのは楜だず思いたした。

以䞊です。お読みいただきありがずうございたした。

投皿日:
カテゎリヌ: Linux、雑蚘

コメントする

メヌルアドレスが公開されるこずはありたせん。 ※ が付いおいる欄は必須項目です