莊雲凱
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Versions and GitHub Sync Note Insights Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       owned this note    owned this note      
    Published Linked with GitHub
    Subscribed
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    Subscribe
    2017q3 Homework1 (clz) --- contributed by <`amikai`> ###### tags: `sysprog2017` # Makefile 研讀 ## makefile option - `-d` 印出 debug 訊息 - `-f file` 當你的 makefile 是隨便取名的時候, 則可以使用此選項, 舉例 make -f my_makefilename ## gcc option TODO - `-MMD` - `-MF` Q: prequest 不都自己寫好了嗎, 為啥要透過 gcc 產生呢 參考資料: - https://gcc.gnu.org/onlinedocs/gcc/Preprocessor-Options.html#Preprocessor-Options - https://www.gnu.org/software/make/manual/html_node/Automatic-Prerequisites.html#Automatic-Prerequisites ## strip string 將前輟 (leading) 和後輟 (trialing) 的空白字元 (whitespace) 刪除, 並字串裡 (不包含前啜後輟) 的一串空白字元替換成空白字元. 因為 `$(strip a b c )` 的結果為 `a b c` 原文: > Removes leading and trailing whitespace from string and replaces each internal sequence of one or more whitespace characters with a single space. Thus, ‘$(strip a b c )’ results in ‘a b c’. 參考資料: [Functions for String Substitution and Analysis](https://www.gnu.org/software/make/manual/html_node/Text-Functions.html) ## Recipe Echoing ``` ``` 參考資料: https://www.gnu.org/software/make/manual/html_node/Echoing.html ## pattern rule 首先先看看一個簡單的: ``` %.o : %.c $(CC) -c $(CFLAGS) $(CPPFLAGS) $< -o $@ $(SRCS_common) ``` 這裡定義一個 rule 可以讓所有的 x.o 藉由 x.c 創造出來. 當這個 rule 符合時, 此 recipe 會使用 `$@` 和 `$<` 兩個 automatic 變數, 分別替換來源和目的 原文: > defines a rule that can make any file x.o from x.c. The recipe uses the automatic variables `$@` and `$<` to substitute the names of the target file and the source file in each case where the rule applies 在看老師寫的: ``` %: $(SRCS_common) %.c clz.h $(CC) $(CFLAGS_common) -o $@ \ -MMD -MF .$@.d \ -D$(shell echo $(subst .o,,$@)) $(SRCS_common) ``` 在這並沒有寫 file extension 所以下 `make xxx` (xxx 代表任何字) 則會調用到此條 rule 參考資料: [pattern-examples](https://www.gnu.org/software/make/manual/html_node/Pattern-Examples.html#Pattern-Examples) ## PHONY target TODO 參考資料: [PHONY target - gnu make manual](https://www.gnu.org/software/make/manual/html_node/Phony-Targets.html) ## Substitution Reference 看到老師寫的一個, 有天書的感覺, 我就開了 gnu manual 用 % 字元慢慢搜尋, 原來這招叫做 `Substitution Reference` ``` deps := $(EXEC:%=.%.o.d) ``` substitution reference 會將變數得值替換成你指定的值. 而它的形式為 `$(var:a=b)` (或 `${var:a=b}`), 而 `$(var:a=b)` 把 var 裡的值拿出來, 將每個字尾有 a 這個字地替換成字尾有 b 字, 並塞回 var 裡. 原文: > A substitution reference substitutes the value of a variable with alterations that you specify. It has the form `$(var:a=b)` (or ‘${var:a=b}’) and its meaning is to take the value of the variable var, replace every a at the end of a word with b in that value, and substitute the resulting string. 舉例: ``` foo := a.o b.o c.o bar := $(foo:.o=.c) ``` 則 `bar` 為 `a.c b.c c.c` 接下來我們在看這個 ``` EXEC = \ iteration \ binary \ byte \ recursive \ harley deps := $(EXEC:%=.%.o.d) ``` 則 `deps` 會被設為 `.iteration.o.d .binary.o.d .byte.o.d .recursive.o.d .harley.o.d` 參考資料: - [Substitution Reference - gnu make manual](https://www.gnu.org/software/make/manual/html_node/Substitution-Refs.html) - https://stackoverflow.com/questions/23919200/what-does-the-percent-symbol-mean-in-android-mk ## include include 這個 directive 告訴 make 先暫時不要繼續讀現在這個 makefile 而是先讀其他的 makefile. 這個 directive 像是以下這樣: ``` include filenames… ``` filenames 可以包含 shell filename pattern (這句不是很懂), 如果 filenames 是空的話, 什麼都不會被 include 而且不會有錯誤發生. 原文如下: The include directive tells make to suspend reading the current makefile and read one or more other makefiles before continuing. The directive is a line in the makefile that looks like this: ``` include filenames… ``` filenames can contain shell file name patterns. If filenames is empty, nothing is included and no error is printed. 參考資料: https://www.gnu.org/software/make/manual/html_node/Include.html # 程式研讀 # 補強工作 - 用機率觀點解釋圖

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully