larmel / lacc

A simple, self-hosting C compiler
MIT License
887 stars 64 forks source link

Strip path information when creating output file name. #15

Closed ibara closed 5 years ago

ibara commented 5 years ago

Currently, lacc takes the entire path of a file and changes just its suffix to create the output file name. However, gcc and clang also strip the path from the input file name. This means that gcc and clang put the resulting file in the current working directory (unless overridden by the -o flag) whereas lacc puts the resulting file in the directory the original source file lives in.

lacc's behavior breaks make(1) assumptions about where resulting files belong.

This PR strips path information using basename(3). That function isn't in C89 but it is in POSIX.1.

With this PR, make obj && make works correctly with *BSD make. Without this PR, lacc will complain that it cannot find object files when trying to link binaries.

larmel commented 5 years ago

Thanks, never thought of this.

Is there a specific reason to use basename rather than a simple srrchr? Although I do break this in the linker module, I try to avoid any dependencies outside C89, so I rewrote this slightly before pushing. Having some trouble making github recognize this as merged now though, so might end up just closing.

ibara commented 5 years ago

strrchr is perfectly fine too. Thanks!