Why that "Perfect" Makefile Doesn't Work.

Поделиться
HTML-код
  • Опубликовано: 22 июл 2020
  • Patreon ➤ / jacobsorber
    Courses ➤ jacobsorber.thinkific.com
    Website ➤ www.jacobsorber.com
    ---
    Why that "Perfect" Makefile Doesn't Work. \\ Makefiles are notorious for giving students headaches, when they look right, but don't act right. The problem is often whitespace. This video explains this issue and shows you how to find and fix these errors quickly so you can get back to developing software.
    Related Video:
    Simulator example: • How to write your own ...
    ***
    Welcome! I post videos that help you learn to program and become a more confident software developer. I cover beginner-to-advanced systems topics ranging from network programming, threads, processes, operating systems, embedded systems and others. My goal is to help you get under-the-hood and better understand how computers work and how you can use them to become stronger students and more capable professional developers.
    About me: I'm a computer scientist, electrical engineer, researcher, and teacher. I specialize in embedded systems, mobile computing, sensor networks, and the Internet of Things. I teach systems and networking courses at Clemson University, where I also lead the PERSIST research lab.
    More about me and what I do:
    www.jacobsorber.com
    people.cs.clemson.edu/~jsorber/
    persist.cs.clemson.edu/
    To Support the Channel:
    + like, subscribe, spread the word
    + contribute via Patreon --- [ / jacobsorber ]
    + rep the channel with nerdy merch --- [teespring.com/stores/jacob-so...]
    Source code is also available to Patreon supporters. --- [jsorber-youtube-source.heroku...]

Комментарии • 146

  • @bas7650
    @bas7650 8 месяцев назад +3

    2:09 "If it's still giving you errors, think about whitespaces" this helped me fix an issue!

  • @eladi99
    @eladi99 3 года назад +57

    You're actually touching the tip of a bigger iceberg -- unattended trailing whitespaces in source code. This is something that can raise conflicts in source controls. The best advice would be to configure your editor to remove them on save, because they should *never* stay around toward your commit.

    • @JacobSorber
      @JacobSorber  3 года назад +10

      Very true. Thanks for mentioning that.

    • @Trezker
      @Trezker 3 года назад +2

      Ah, good tip. I wonder what other annoyances we live with that editors have a setting for but we never think to look for it.

    • @smrtfasizmu6161
      @smrtfasizmu6161 2 года назад +2

      That doesn't matter for source code of programming languages. C, Java don't care about white space.

    • @meiowalot7570
      @meiowalot7570 2 года назад +3

      I fanatically use git diff before committing as it highlights trailing white space.

    • @tildessmoo
      @tildessmoo Год назад +3

      @@smrtfasizmu6161 Yes, I know, two years late, but... While whitespace doesn't matter for most source files, Elad Galili was talking about source control, things like git, mercurial, and subversion. They don't check how your files compile, just if they're different, and having a single stray whitespace from, say, accidentally hitting the spacebar while reading through a section of code to make sure what you're writing in a different file or even compilation unit won't cause problems, can cause unnecessary merge conflicts and automatic version changes that you then have to go back and fix manually. It's not a huge deal to fix most of the time anyway; most text editors it's a pretty easy bit of scripting to automatically strip trailing whitespace.

  • @anupkodlekere8604
    @anupkodlekere8604 3 года назад +65

    "You spend hours pulling your hair out if you have hair" lol

    • @khoavo5758
      @khoavo5758 3 года назад

      @Loraine Longworth Google for what? You being a terrible boyfriend?

  • @axalius572
    @axalius572 3 года назад +27

    I think I saw it! Tabs vs spaces. This gave me a headache in the past.

    • @JacobSorber
      @JacobSorber  3 года назад +1

      Me too.

    • @benjaminshinar9509
      @benjaminshinar9509 3 года назад +1

      same.
      it's like restarting the computer, before you try anything with a makefile, check the tabs.

  • @jenselstner5527
    @jenselstner5527 3 года назад +33

    You could enable the trimming of trailing white-spaces when saving the file in the preferences of VS Code.

  • @mrcrackerist
    @mrcrackerist 3 года назад +19

    I have actually never encountered this, but interesting thank you.

    • @JacobSorber
      @JacobSorber  3 года назад +4

      You're welcome. Sometimes people encounter this, but don't realize it because they manage to fix it without realizing what they did. I know my first few run-ins with it back in ---a long time ago--- I ended up just retyping part of my makefile and it worked, and I just moved on, not realizing what I did wrong in the first place.

  • @BottleOfCoke
    @BottleOfCoke 2 года назад +3

    This is a really high production-value to a students question!! I wish all of my professors would answer my emails like this!

  • @supernovaw39
    @supernovaw39 Год назад +4

    Oh, some of my most memorable experiences programming were when I almost went crazy trying to solve a silly problem :) Like when I split a file with CRLF endings with "
    " and my strings ended with
    . It absolutely messed up my output and I didn't even know that carriage return is a thing.

  • @matiascoarasa7503
    @matiascoarasa7503 3 года назад +3

    Great work man! Love your channel topics and vibes!

  • @meiowalot7570
    @meiowalot7570 2 года назад

    Thanks for another really good video. When you showed the make files I immediately guessed “I bet the indents aren’t tabbed in, but spaces were used”. I was wrong but it looks like another way whitespace can cause trouble. :)

  • @rishithaminol15
    @rishithaminol15 3 года назад +3

    Hi Jacob. I really like your videos. It guides me to lots of sections of computer science. This is really helpful please never give up, keep it up.

  • @yash1152
    @yash1152 2 года назад

    Tip: also, many editors have this option of remove trailing whitespaces on saving file or exiting or smth like that. Be sure to look into that too (:

  • @enderger5308
    @enderger5308 2 года назад +1

    Tip: highlight the whole file in your editor and look line-by-line for that one bit of whitespace.

  • @marshalstewart7776
    @marshalstewart7776 3 года назад

    Had a problem with a make file yesterday that I copied online to learn about Linux kernel modules. This was the issue. Thank you!

  • @adamtuft
    @adamtuft 3 года назад +4

    Thank you for your videos Jacob, they are really informative! Would you consider making a brief video on the "inline" keyword in C - what it's for, how it works, and how it should be used? Or can you recommend a source for a clear explanation? I've been reading up on it but I can't get a clear understanding myself 😕😕😕

    • @JacobSorber
      @JacobSorber  3 года назад +3

      I've added *inline* to my list. Can't promise when it will come out. Hopefully, in time to be useful to you.

    • @adamtuft
      @adamtuft 3 года назад +1

      ​@@JacobSorber Thank you so much!

  • @kathiravankathir3089
    @kathiravankathir3089 3 года назад

    Experienced a similar issue ,when setting tab = 4 spaces in the vim editor. we can differentiate the whitespaces and tabs by executing "set list" command in the vim.

  • @lsatenstein
    @lsatenstein 2 года назад +1

    Thank you Dr J. for this topic.
    Makefile whitespace has transferred to my scalp. I am a Makefile user who has struggled for hours to get one specific one working well and I failed.
    I will review my irritant Makefile. The fault: By changing one source file, of a dozen, the Makefile causes all sources to be recompiled. Fortunately, the code is stable.
    It is not your problem. But you incentivize me to revisit it again. Hopefully, my buglet will be discovered in a short time-span.

  • @papasmurf9146
    @papasmurf9146 2 года назад +1

    I would use a utility to build the Makefile versus hand coding it. That way you also get the appropriate .h dependencies into the Makefile. I wrote a utility to create the Makefile back in the 90s and have been dragging it around with me since then.

  • @sghsghdk
    @sghsghdk 3 года назад +1

    Many editors have and option to remove tailing whitespace from files when saving.

  • @RMG0785
    @RMG0785 3 года назад

    Unrelated - What is your camera and lighting setup Jacob? Looks really good. Sharp + well-lit

  • @OpenGL4ever
    @OpenGL4ever 2 года назад +1

    A better way to avoid a problem like this is to simply configure your editor in a way so that it removes all white spaces at the line ending automatically when saving the file.
    Theoretically this reduces also the file size. You usually won't notice the latter on a typical file system that is using whole blocks to store data, but when packaging the file with tools like tar or zip and transfering to another machine via network this can save some bytes.

  • @prakhargupta2960
    @prakhargupta2960 3 года назад +2

    Jacob you're the CS teacher I never had! Thanks for being yourself!

    • @JacobSorber
      @JacobSorber  3 года назад

      You're welcome. Glad I can help.

  • @samplesandtests
    @samplesandtests Год назад

    three things, first thanks for the video, this may have been a issue i had with make and decided to just make bash build scripts instead. second while on the topic of bash i just came across a whitespace issue with bash ( not putting spaces around brackets in conditions). third i believe newer versions of nano will highlight trailing spaces on a line by default (at least most of mine do).

  • @artemiocabrillosjr.244
    @artemiocabrillosjr.244 3 года назад

    Hi Jacob,
    You really did gave a lot of people gold (coz u save them a lot of time 😂).
    I also encountered this in my project which had a makefile untouched for almost 3 years and suddenly becoming erroneous. I spent many hours debugging and the solution is, white spaces.
    One thing to take note also is when update packages, make utility might also behave different. In my case GNU make 3.81 is OK and for some reason i performed a yum update which updated GNU make to 3.82 which causes the error.
    Anyway, more power in making these videos.
    Best Regards!

  • @Saturate0806
    @Saturate0806 3 года назад +1

    Before staging you can run git diff and the whitespaces are shown with red background

  • @dannyhunn6025
    @dannyhunn6025 3 года назад

    Just a note on Vim you can use :syntax on :set syntax=whitespace

  • @ravishankarnolastname1917
    @ravishankarnolastname1917 Год назад

    This really saved me money from a visit to the therapist! Thanks Jacob!

  • @abarocio80
    @abarocio80 Год назад

    You could also use Emacs, which by default trims all white spaces in Makefiles on save.

  • @JonitoFischer
    @JonitoFischer 2 года назад

    I've used python Invoke for task automation and build scripts, and recently I'm giving a try to xmake (Lua)... I always felt like writing makefiles was harder than trying to write in Klingon... And any python programmer knows to set it's ide or text editor to show whitespace all the time.

  • @glowiever
    @glowiever 3 года назад

    I've never been able to follow some of those bigger project's makefiles. theirs seem to try to cover all edge cases.

  • @victorocampo5263
    @victorocampo5263 3 года назад +6

    What do you think about make alternatives, like premake or CMake?

    • @lordadamson
      @lordadamson 3 года назад

      CMake is a joke that went too far. Sort of like JS. You will probably have to learn it one day if you do C/C++ professionally. It's a defacto. I sad defacto.
      My experience with premake is good. As long as you don't do crazy things with lua.

    • @JacobSorber
      @JacobSorber  3 года назад +2

      I'll have to try out premake. I'm also not in love with cmake. I use Rake sometimes. Build systems are like friends. Most have both lovable things and annoying quirks. I guess who you invite to the party, depends on the kind of party you want to have. 🤔

    • @Orionus83
      @Orionus83 3 года назад +5

      I don't like make but really like CMake. It looks a little messy the first time, but in the end it's pretty cool.

    • @TranscendentBen
      @TranscendentBen 2 года назад

      I can only wonder if these other make utilities have the same "features" as the original make in order to 'maintain compatibility'.

    • @fededevi1985
      @fededevi1985 Год назад +1

      I don't understand the hate on cmake especially considering people still use make instead. It might not have the best syntax ever but it works well and it is super easy to learn. It is so much better than make (even without taking into account that it is the de-facto standard) that it doesn't make any sense not to use it over make even for the simplest single file projects.

  • @kaushikjames5623
    @kaushikjames5623 Год назад

    advanced information thanks again

  • @jon-sw5yw
    @jon-sw5yw 3 года назад

    This happened to me as well. The "same" makefile didn't work on my friends PC and I had to email him my file and only then it worked

  • @nosheenarif1920
    @nosheenarif1920 Месяц назад

    Hello there,
    Kindly tell me what does makefile. Win has changed mean?
    And how to fix it?

  • @AtomToast
    @AtomToast 3 года назад

    I just have my editor (neovim) set up to both display whitspaces aswell as auto trim trailing spaces in any file I edit. I didn't know about this issue with make but that might be because I never had to encounter it

    • @humm535
      @humm535 3 года назад +1

      It’s not easy to encounter imho. How would one come into a situation where one doesn’t know what whitespace is used? o_O

  • @kashinathchillal9867
    @kashinathchillal9867 2 месяца назад

    I use vimdiff to see the difference between 2 files. Will that help?

  • @shawnmichaels5484
    @shawnmichaels5484 Год назад

    Hey jacob, can you share your shell theme? Thanks in advance :)

  • @MECHANISMUS
    @MECHANISMUS 2 года назад

    In Geany there is 'Strip Trailing Spaces' command.

  • @kushagrakumar9576
    @kushagrakumar9576 3 года назад

    :set list , in case you are using vim editor. Encountered it multiple times. Trivial yet good to know for anyone working with make files.

  • @victornoagbodji
    @victornoagbodji 3 года назад

    😊 🙏 😊
    thanks for explaining the issue. make should have a built-in linter...

    • @JacobSorber
      @JacobSorber  3 года назад +1

      Agreed. It definitely seems like there are some easy things that make could check for us automatically.

  • @wjrasmussen666
    @wjrasmussen666 4 месяца назад

    Used to show all whitespace characters in vi or emacs

  • @samsawesomeminecraft
    @samsawesomeminecraft 3 года назад +1

    what if I downloaded some source code from the internet and try to use the Makefile there and it produces an error?

    • @JacobSorber
      @JacobSorber  3 года назад +1

      Well, that depends on the error (and the Makefile).

    • @samsawesomeminecraft
      @samsawesomeminecraft 3 года назад

      @@JacobSorber so there's no easy fix?

    • @JacobSorber
      @JacobSorber  3 года назад +1

      @@samsawesomeminecraft Sadly, there isn't. There are a lot of different ways that a Makefile can be broken. If you point me to the online resource, I might be able to address it in a future video, though.

    • @samsawesomeminecraft
      @samsawesomeminecraft 3 года назад +1

      @@JacobSorber I had trouble compiling this from source github.com/nigels-com/glew

  • @Golden_builds
    @Golden_builds Год назад

    how can i open a makefile to see the codes!

  •  3 года назад

    Good practice is to pass your 'configuration' variables (variables which are changed more often, or for each project) through $(strip) function. You will never have similar problem anymore.

  • @michaelclift6849
    @michaelclift6849 Год назад

    I learned makefiles from what I consider to be a great sample. The makefile written by Eric Weddington for WinAVR2010. Actually, instead of learned, maybe I should say I hacked it do do what I want...

  • @chair547
    @chair547 Год назад

    every time i have to drop back down into c i become exponentially more thankful for cargo

  • @kermitdafrog8
    @kermitdafrog8 3 года назад

    Does this happen with CMake?

  • @AnimeGIFfy
    @AnimeGIFfy 2 года назад

    Vscode has a setting that clears trailing whitespaces on save

  • @hemanshu877
    @hemanshu877 3 года назад +4

    That's why I use CMake

  • @aidenpearce5701
    @aidenpearce5701 3 года назад

    I dont understand where src and obj value came from that assign into SRC and OBJ

    • @JacobSorber
      @JacobSorber  3 года назад +1

      Those are just the names of the subdirectories that I'm using to build my project. SRC and OBJ are the variable names, the lowercase "src" and "obj" are just string literals.

    • @aidenpearce5701
      @aidenpearce5701 3 года назад

      @@JacobSorber i see, i thought src and obj are special string 😅

  • @carlh8256
    @carlh8256 3 года назад +1

    Is it necessary for Make to work in this way? If not why dont they change Make for such an agonizing problem?

    • @TranscendentBen
      @TranscendentBen 2 года назад

      Likely because it's a "legacy" thing and they're afraid to change it out of fear of somehow breaking something. There's no reason not to make Make more reasonable, it's not like it's part of any language spec, or part of Posix or anything, at least I don't think so.

  • @ghalebevaldo4416
    @ghalebevaldo4416 10 месяцев назад

    Great!

  • @metalpunk
    @metalpunk 3 года назад

    Man, I was so sure it was that the broken version used spaces instead of tabs. :(

  • @TranscendentBen
    @TranscendentBen 2 года назад

    This sort of thing gets me riled up. I SWEAR i thought this was going to be the spaces-instead-of-a-tab thing that Make looks for in indented lines. (RANT incoming)
    The ASCII TAB character should be outlawed. As far as I know, MAKE is the only thing that requires it.
    TAB has an awful history. TAB originally meant "go to the next TAB position which is every 8 character positions from the start" which is 1, 9, 17, 25, 34, ... Every ASCII device (well, maybe not the ASR-33, I don't remember what it did) followed this standard, so any series of characters, spaces and tabs showed as the same thing on every CRT terminal and the DECwriter followed that convention.
    But then the microcompter came along, and then the word processors probably Wordstar, which took TAB to mean whatever the programmer(s) wanted it to mean, some odd predefined tabstop or four spaces or whatever This was in the word processor's own proprietary file format, which was almost forgivable, but it was surely not properly converted when the file was saved as ASCII. Nowadays even "straight text" programming editors let you tell it how far to move with the tab character. At least most can be configured to insert the appropriate number of spaces into the file instead of the tab, so it's possible to ... write Python with good formatting. No one uses tab to mean 8 spaces anymore anyway. Modern indenting is four, or maybe 3 or 2 spaces.
    So really the thing has lost all usefulness, and causes more problems than it solves. I can see where it originally saved extra space characters, but source code size in memory or on a hard disk is no longer a problem, and version control systems do data compression anyway.
    So I have Notepad++ set to insert spaces to get to the next four-space "tab stop" and I'm happy that my code will look the same in any text editor. But then in recent years I have this growing program I was splitting up into several source files, and I go back and look at the Make documentation for the first time in a few decades, and it REQUIRES a tab character ...
    If I had a dollar for every "you can fix ThisEditor to strip trailing spaces" comment I could invent a time machine and pay whoever first wrote Make to have it accept "one or more tabs or spaces" for an indented line, and always ignore trailing spaces.

  • @humanontheinternet6510
    @humanontheinternet6510 3 года назад

    yah i face the same in docker-compose file

  • @FernandoBasso
    @FernandoBasso 10 месяцев назад

    I have seen problems with whitespaces after \ escape, which was supposed to be escaping a the newline, but there it was actually escaping a whitespace.
    It is a good practice to configure editors to display and optionally clean whitespace, potentially making use of plugins like editorconfig.
    It is not uncommon for me to open a file and get mad of the carelessness with trailing whitespace, to which I usually respond with a :%s/\s\+$::g 😅

  • @arnaudparan1419
    @arnaudparan1419 2 года назад

    that's why my Vim is always configured to rendre whitespace characters

  • @catorials444
    @catorials444 3 года назад

    damn, somebody has to rework the makefile parser

  • @funhuninjastudio
    @funhuninjastudio 3 года назад

    Can you make a video for fasm?
    Nice vid tho ;)

    • @JacobSorber
      @JacobSorber  3 года назад +1

      I'll add it to the list and see what I can do.

  • @AndreasWilfer
    @AndreasWilfer 3 года назад

    Ah, that explains a lot..

  • @nandanvasudevan
    @nandanvasudevan 2 года назад

    Teach us CMake!

  • @MegaJehanzaib
    @MegaJehanzaib 3 года назад +1

    Notepad++ -> view -> Show Symbol -> Show all symbols

  • @perfectionbox
    @perfectionbox 3 года назад

    surely someone has written a program or script to "lint" makefiles for things like this?

  • @activelivingchallenger4298
    @activelivingchallenger4298 3 года назад

    Reminds me of bashrc file. Alias and path issues and figured out it was just a white space issue. Frustrating

  • @lmlizwpfhsjmcyt7545
    @lmlizwpfhsjmcyt7545 2 года назад

    I don't understand. How long has Make existed for? Why does Make still have a whitespace issue.

  • @mgcmsn
    @mgcmsn 8 месяцев назад

    This is why I try to use Taskfile instead of a Makefile if possible.

  • @skaruts
    @skaruts 2 года назад

    The only reason I don't code in C is because compiling it always feels like a can of worms, and at this point I have no patience to try to solve the issues... :(
    EDIT: lol I just revisited a broken python script for compiling C that I made a while ago, and made it work. I am now able to compile C. To paraphrase a portuguese saying: when you don't have a dog, you hunt with a python. :D

  • @tosemusername
    @tosemusername 3 года назад

    Editors nowadays also have the option to remove pointless whitespace characters when you save the file.

  • @UseQPixinDune
    @UseQPixinDune 3 года назад

    You should really start a subreddit or a discord server

  • @ronwellman
    @ronwellman 3 года назад

    See whitespace characters in vim. :set list

  • @the_allucinator
    @the_allucinator 3 года назад

    This reminds me of the aircraft disasters that resulted from loose screws.

  • @hameedyousfi2779
    @hameedyousfi2779 3 года назад +1

    Sir plz start embbeded programming on c language create own header files create own function on c plz sir start that tutorial i am waiting for this tutorial quite while

  • @sajjadjawadkadhim303
    @sajjadjawadkadhim303 2 года назад

    I just make vim remove whitespace at the end of every line if it exists when i save the file automatically

  • @afiqzx
    @afiqzx 3 года назад

    got it right on first try lol because i had this problem

  • @venkybabu8140
    @venkybabu8140 Год назад

    Invisible control character.

  • @ivankryvosheia446
    @ivankryvosheia446 2 года назад

    Love american humour.
    And..good tips!
    I should have known it earlier

  • @harshwardhanshetty4683
    @harshwardhanshetty4683 5 месяцев назад

    "if you have hair" 😥😥

  • @leonardocaetano9771
    @leonardocaetano9771 3 года назад

    The truth is that for the most of time, build tools aren't even needed. You can compile just fine using shell scripts. I don't know why people love complicating things.

  • @sababugs1125
    @sababugs1125 2 года назад

    I had this bug once then promptly wen full on monke

  • @aladinsafi2967
    @aladinsafi2967 3 года назад

    use vpath it better or -I in gcc

  • @freitas-renato
    @freitas-renato 3 года назад +1

    You can toggle "render whitespace" on VSCode to see all spaces/tabs on the file, it is really useful to trace bugs like this.
    Great video btw

  • @danmerillat
    @danmerillat 3 года назад +1

    make -r
    turn off builtin rules then your debug isn't full of 1970s era version control rules.

  • @abanoubsameh6608
    @abanoubsameh6608 3 года назад

    Just vim or grep.

  • @max_ishere
    @max_ishere 3 года назад +1

    WHAT?

  • @humm535
    @humm535 3 года назад

    not POSIX compliant Makefile, REEEEEE

  • @XenoTravis
    @XenoTravis 3 года назад

    I would be very happy to never hear the word 'makefile' again.

  • @retroenergy
    @retroenergy 2 года назад

    The perfect Makefiles are the ones you make along the way

  • @nutelhere
    @nutelhere 4 месяца назад

    I just hope one day make stops existing

  • @edwardmacnab354
    @edwardmacnab354 2 года назад

    Why couldn't you just diff the two versions ? because the two files obviously mismatch !

  • @jenselstner5527
    @jenselstner5527 3 года назад

    make and python, (almost) same shit with white-spaces

  • @JohnHollowell
    @JohnHollowell 3 года назад

    I feel like you are probably not a yaml kinda guy... whitespace dependence even more picky than Python

    • @JacobSorber
      @JacobSorber  3 года назад

      Yeah, I know. I do use YAML when it makes sense (just like I use python and make). But, their whitespace-based issues feel like unnecessary self-inflicted wounds.

  • @TheMoazin
    @TheMoazin 3 года назад +2

    First Viewer!

  • @tobiaskarl4939
    @tobiaskarl4939 3 года назад

    I hate these tabs and these LFCR from microsofts textfiles .... grrrrrr
    dos2unix is my friend and cat file.txt | tr -d "\t"

  • @juri4729
    @juri4729 2 года назад

    "... i know years of experience"
    ***proceeds to make rocket science out of white space***
    isn't one of the first things you learn about make that it's white space sensitive

  • @yash1152
    @yash1152 2 года назад

    5:24 wow, how come you dont mention 'cat --vet' 😂😂
    oh wait, it doesnt shows whitespaces, rather just the tabs and newlines

  • @nathanflett6427
    @nathanflett6427 3 года назад

    Personally I see this as a newbie issue. You shouldn't be leaving whitespace at the end of the line unless you mean to anyway.

    • @JacobSorber
      @JacobSorber  3 года назад +1

      Sure, but to be fair, I could say the same thing about seg faults, memory corruption, memory leaks, and just about any kind of programming mistake out there. Most everything is easy once you understand it.

    • @nathanflett6427
      @nathanflett6427 3 года назад

      @@JacobSorber True. Keep making the videos. I wish I had had videos like this back in the day.

  • @wah704
    @wah704 7 месяцев назад

    Would cat -e Makefile work?